summary refs log tree commit diff
path: root/api/jest
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-21 22:52:30 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-21 22:52:30 +0200
commitabdce76df4b6aa3a063b496e6c0575c54e9fa397 (patch)
treec135233da7c327eeb52f143a2632f5d5bd4b65b5 /api/jest
parent:bug: fix unittests (diff)
downloadserver-abdce76df4b6aa3a063b496e6c0575c54e9fa397.tar.xz
:sparkles: generate openapi documentation
Diffstat (limited to 'api/jest')
-rw-r--r--api/jest/getRouteDescriptions.js (renamed from api/jest/getRouteDescriptions.ts)30
1 files changed, 19 insertions, 11 deletions
diff --git a/api/jest/getRouteDescriptions.ts b/api/jest/getRouteDescriptions.js

index 33922899..4f8d2e75 100644 --- a/api/jest/getRouteDescriptions.ts +++ b/api/jest/getRouteDescriptions.js
@@ -1,11 +1,15 @@ -import { traverseDirectory } from "lambert-server"; -import path from "path"; -import express from "express"; -import * as RouteUtility from "../dist/util/route"; -import { RouteOptions } from "../dist/util/route"; +const { traverseDirectory } = require("lambert-server"); +const path = require("path"); +const express = require("express"); +const RouteUtility = require("../dist/util/route"); const Router = express.Router; -const routes = new Map<string, RouteUtility.RouteOptions>(); +/** + * Some documentation. + * + * @type {Map<string, RouteUtility.RouteOptions>} + */ +const routes = new Map(); let currentPath = ""; let currentFile = ""; const methods = ["get", "post", "put", "delete", "patch"]; @@ -13,13 +17,13 @@ const methods = ["get", "post", "put", "delete", "patch"]; function registerPath(file, method, prefix, path, ...args) { const urlPath = prefix + path; const sourceFile = file.replace("/dist/", "/src/").replace(".js", ".ts"); - const opts: RouteOptions = args.find((x) => typeof x === "object"); + const opts = args.find((x) => typeof x === "object"); if (opts) { routes.set(urlPath + "|" + method, opts); // @ts-ignore opts.file = sourceFile; // console.log(method, urlPath, opts); } else { - console.log(`${sourceFile}\nrouter.${method}("${path}") is missing the "route()" description middleware\n`, args); + console.log(`${sourceFile}\nrouter.${method}("${path}") is missing the "route()" description middleware\n`); } } @@ -42,7 +46,7 @@ express.Router = (opts) => { return router; }; -export default function getRouteDescriptions() { +module.exports = function getRouteDescriptions() { const root = path.join(__dirname, "..", "dist", "routes", "/"); traverseDirectory({ dirname: root, recursive: true }, (file) => { currentFile = file; @@ -52,7 +56,11 @@ export default function getRouteDescriptions() { if (path.endsWith("/index")) path = path.slice(0, "/index".length * -1); // delete index from path currentPath = path; - require(file); + try { + require(file); + } catch (error) { + console.error("error loading file " + file, error); + } }); return routes; -} +};