diff --git a/assets/openapi.json b/assets/openapi.json index 325e3c4b..80f78818 100644 Binary files a/assets/openapi.json and b/assets/openapi.json differ diff --git a/assets/schemas.json b/assets/schemas.json index 995f2236..c4e09d07 100755 Binary files a/assets/schemas.json and b/assets/schemas.json differ diff --git a/package.json b/package.json index 9ac3fbd1..ba28e18c 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "start:api": "node dist/api/start.js", "start:cdn": "node dist/cdn/start.js", "start:gateway": "node dist/gateway/start.js", - "build": "tsc -b .", + "build": "npm run build:src && npm run generate:schema && npm run generate:openapi", + "build:src": "tsc -b -v", "watch": "tsc -w -b .", "test": "node scripts/test.js", "lint": "eslint .", diff --git a/scripts/openapi.js b/scripts/openapi.js index ca3e7b21..6d4d6366 100644 --- a/scripts/openapi.js +++ b/scripts/openapi.js @@ -23,7 +23,7 @@ const fs = require("fs"); const { NO_AUTHORIZATION_ROUTES, } = require("../dist/api/middlewares/Authentication"); -require("missing-native-js-functions"); +require("../dist/util/util/extensions"); const openapiPath = path.join(__dirname, "..", "assets", "openapi.json"); const SchemaPath = path.join(__dirname, "..", "assets", "schemas.json"); @@ -84,7 +84,7 @@ function combineSchemas(schemas) { for (const key in definitions) { if (!schemaRegEx.test(key)) { - console.error(`Invalid schema name: ${key}`); + console.error(`Invalid schema name: ${key}, context:`, definitions[key]); continue; } specification.components = specification.components || {}; @@ -121,7 +121,7 @@ function apiRoutes(missingRoutes) { const tags = Array.from(routes.keys()) .map((x) => getTag(x)) .sort((a, b) => a.localeCompare(b)); - specification.tags = tags.unique().map((x) => ({ name: x })); + specification.tags = tags.distinct().map((x) => ({ name: x })); routes.forEach((route, pathAndMethod) => { const [p, method] = pathAndMethod.split("|"); @@ -213,7 +213,7 @@ function apiRoutes(missingRoutes) { obj.parameters = [...(obj.parameters || []), ...query]; } - obj.tags = [...(obj.tags || []), getTag(p)].unique(); + obj.tags = [...(obj.tags || []), getTag(p)].distinct(); if (missingRoutes.additional.includes(path.replace(/\/$/, ""))) { obj["x-badges"] = [ @@ -255,6 +255,14 @@ async function main() { .replaceAll("#/definitions", "#/components/schemas") .replaceAll("bigint", "number"), ); + console.log("Wrote OpenAPI specification to", openapiPath); + console.log( + "Specification contains", + Object.keys(specification.paths).length, + "paths and", + Object.keys(specification.components.schemas).length, + "schemas.", + ); } main(); diff --git a/scripts/schema.js b/scripts/schema.js index b39948e7..11faefba 100644 --- a/scripts/schema.js +++ b/scripts/schema.js @@ -115,6 +115,7 @@ function main() { deleteOneOfKindUndefinedRecursive(definitions, "$"); fs.writeFileSync(schemaPath, JSON.stringify(definitions, null, 4)); + console.log("Successfully wrote", Object.keys(definitions).length, "schemas to", schemaPath); } function deleteOneOfKindUndefinedRecursive(obj, path) { diff --git a/scripts/util/getRouteDescriptions.js b/scripts/util/getRouteDescriptions.js index a79dac96..54b5e1bc 100644 --- a/scripts/util/getRouteDescriptions.js +++ b/scripts/util/getRouteDescriptions.js @@ -13,17 +13,24 @@ let currentPath = ""; If someone could fix that I'd really appreciate it, but for now just, don't do that :p */ -const proxy = (file, method, prefix, path, ...args) => { +/** + * @param {string} file + * @param {string} method + * @param {string} prefix + * @param {string} path + * @param args + */ +function proxy(file, method, prefix, path, ...args) { const opts = args.find((x) => x?.prototype?.OPTS_MARKER == true); if (!opts) return console.error( `${file} has route without route() description middleware`, ); - console.log(prefix + path + " - " + method); + console.log(`${method.toUpperCase().padStart("OPTIONS".length)} ${prefix + path}`); opts.file = file.replace("/dist/", "/src/").replace(".js", ".ts"); routes.set(prefix + path + "|" + method, opts()); -}; +} express.Router = () => { return Object.fromEntries(