summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2025-11-29 09:39:02 +1100
committerGitHub <noreply@github.com>2025-11-29 09:39:02 +1100
commita5b5a33c762d6e22b9e596ea18567362639aa146 (patch)
treea8bf888b95cbcdd1f6cbb166d6c6003208671c1b /scripts
parentMerge pull request #1409 from MathMan05/removeLog (diff)
parentremove string proto fake polyfill (diff)
downloadserver-ts-a5b5a33c762d6e22b9e596ea18567362639aa146.tar.xz
Merge pull request #1408 from MathMan05/removeStupidPolies
Diffstat (limited to 'scripts')
-rw-r--r--scripts/openapi.js53
1 files changed, 15 insertions, 38 deletions
diff --git a/scripts/openapi.js b/scripts/openapi.js

index 589614cc..a1188c54 100644 --- a/scripts/openapi.js +++ b/scripts/openapi.js
@@ -20,9 +20,7 @@ require("module-alias/register"); const getRouteDescriptions = require("./util/getRouteDescriptions"); const path = require("path"); const fs = require("fs"); -const { - NO_AUTHORIZATION_ROUTES, -} = require("../dist/api/middlewares/Authentication"); +const { NO_AUTHORIZATION_ROUTES } = require("../dist/api/middlewares/Authentication"); require("../dist/util/util/extensions"); const { bgRedBright } = require("picocolors"); @@ -89,8 +87,7 @@ function combineSchemas(schemas) { continue; } specification.components = specification.components || {}; - specification.components.schemas = - specification.components.schemas || {}; + specification.components.schemas = specification.components.schemas || {}; specification.components.schemas[key] = definitions[key]; delete definitions[key].additionalProperties; delete definitions[key].$schema; @@ -122,7 +119,7 @@ function apiRoutes(missingRoutes) { const tags = Array.from(routes.keys()) .map((x) => getTag(x)) .sort((a, b) => a.localeCompare(b)); - specification.tags = tags.distinct().map((x) => ({ name: x })); + specification.tags = [...new Set(tags)].map((x) => ({ name: x })); routes.forEach((route, pathAndMethod) => { const [p, method] = pathAndMethod.split("|"); @@ -135,8 +132,7 @@ function apiRoutes(missingRoutes) { if ( !NO_AUTHORIZATION_ROUTES.some((x) => { - if (typeof x === "string") - return (method.toUpperCase() + " " + path).startsWith(x); + if (typeof x === "string") return (method.toUpperCase() + " " + path).startsWith(x); return x.test(method.toUpperCase() + " " + path); }) ) { @@ -177,9 +173,7 @@ function apiRoutes(missingRoutes) { }; else obj.responses[k] = { - description: - obj?.responses?.[k]?.description || - "No description available", + description: obj?.responses?.[k]?.description || "No description available", }; } } else { @@ -214,7 +208,7 @@ function apiRoutes(missingRoutes) { obj.parameters = [...(obj.parameters || []), ...query]; } - obj.tags = [...(obj.tags || []), getTag(p)].distinct(); + obj.tags = [...new Set([...(obj.tags || []), getTag(p)])]; if (missingRoutes.additional.includes(path.replace(/\/$/, ""))) { obj["x-badges"] = [ @@ -225,45 +219,28 @@ function apiRoutes(missingRoutes) { ]; } - specification.paths[path] = Object.assign( - specification.paths[path] || {}, - { - [method]: obj, - }, - ); + specification.paths[path] = Object.assign(specification.paths[path] || {}, { + [method]: obj, + }); }); } async function main() { console.log("Generating OpenAPI Specification..."); - const routesRes = await fetch( - "https://github.com/spacebarchat/missing-routes/raw/main/missing.json", - { - headers: { - Accept: "application/json", - }, + const routesRes = await fetch("https://github.com/spacebarchat/missing-routes/raw/main/missing.json", { + headers: { + Accept: "application/json", }, - ); + }); const missingRoutes = await routesRes.json(); combineSchemas(schemas); apiRoutes(missingRoutes); - fs.writeFileSync( - openapiPath, - JSON.stringify(specification, null, 4) - .replaceAll("#/definitions", "#/components/schemas") - .replaceAll("bigint", "number"), - ); + fs.writeFileSync(openapiPath, JSON.stringify(specification, null, 4).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.", - ); + console.log("Specification contains", Object.keys(specification.paths).length, "paths and", Object.keys(specification.components.schemas).length, "schemas."); } main();