From b272c56d1a3dd84fcbbd27db1bf61a03c3b3ca5d Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Sat, 25 Mar 2023 19:24:00 +1100 Subject: [PATCH] Ajv and openapi spec use different versions of typescript json schema?????? --- assets/openapi.json | Bin 240160 -> 240112 bytes assets/schemas.json | Bin 1426718 -> 1427012 bytes scripts/openapi.js | 42 +++++++++++++++++++++++++++++++++--------- scripts/schema.js | 34 ++++++++++++++++++---------------- 4 files changed, 51 insertions(+), 25 deletions(-) diff --git a/assets/openapi.json b/assets/openapi.json index 069eacedaad4c5477b7c1188eb27cc7ea4dcc2ee..7e1f3cac579e54face9b52e03e0a2447447ca5f6 100644 GIT binary patch delta 70 zcmV-M0J;C5)DG~|4zQR4lXevjm(7s@3X=xs5|e;H36tRh7nd;Q0S1!-10I*~?*R~# cGy^l2{>lLsgO3A;j{^aRj{^d?j{^gdrsD1zbpQYW delta 92 zcmexxnQy@rz6~>&n4-C+H*8~+o8GXOk!$h>CZXv83mI7_Kak{@e40sonluyFDCNj!RZ|LA|)oO9Kb6uecdj0sp$@$Y;w~d>|_>b&+Fjbp4Y**PYj!`$px+A(`)AQ oNluOz7n)vhikYola{(U^^8>K}5DNma5D*IkvB-AK1)|bw05hmIVgLXD diff --git a/scripts/openapi.js b/scripts/openapi.js index 86297967..889a68cb 100644 --- a/scripts/openapi.js +++ b/scripts/openapi.js @@ -16,6 +16,8 @@ along with this program. If not, see . */ +/* eslint-env node */ + require("module-alias/register"); const getRouteDescriptions = require("./util/getRouteDescriptions"); const path = require("path"); @@ -27,7 +29,31 @@ require("missing-native-js-functions"); const openapiPath = path.join(__dirname, "..", "assets", "openapi.json"); const SchemaPath = path.join(__dirname, "..", "assets", "schemas.json"); -const schemas = JSON.parse(fs.readFileSync(SchemaPath, { encoding: "utf8" })); +let schemas = JSON.parse(fs.readFileSync(SchemaPath, { encoding: "utf8" })); + +for (var schema in schemas) { + const part = schemas[schema]; + for (var key in part.properties) { + if (part.properties[key].anyOf) { + const nullIndex = part.properties[key].anyOf.findIndex( + (x) => x.type == "null", + ); + if (nullIndex != -1) { + part.properties[key].nullable = true; + part.properties[key].anyOf.splice(nullIndex, 1); + + if (part.properties[key].anyOf.length == 1) { + Object.assign( + part.properties[key], + part.properties[key].anyOf[0], + ); + delete part.properties[key].anyOf; + } + } + } + } +} + const specification = JSON.parse( fs.readFileSync(openapiPath, { encoding: "utf8" }), ); @@ -85,15 +111,13 @@ function apiRoutes() { .map((x) => ({ name: x })); specification.components = specification.components || {}; - specification.components.securitySchemes = [ - { - bearer: { - type: "http", - scheme: "bearer", - description: "Bearer/Bot prefixes are not required.", - }, + specification.components.securitySchemes = { + bearer: { + type: "http", + scheme: "bearer", + description: "Bearer/Bot prefixes are not required.", }, - ]; + }; routes.forEach((route, pathAndMethod) => { const [p, method] = pathAndMethod.split("|"); diff --git a/scripts/schema.js b/scripts/schema.js index bd0f73d3..ae4b525a 100644 --- a/scripts/schema.js +++ b/scripts/schema.js @@ -20,6 +20,8 @@ Regenerates the `fosscord-server/assets/schemas.json` file, used for API/Gateway input validation. */ +/* eslint-env node */ + const path = require("path"); const fs = require("fs"); const TJS = require("typescript-json-schema"); @@ -110,23 +112,23 @@ function main() { continue; } - if (part.properties[key].anyOf) { - const nullIndex = part.properties[key].anyOf.findIndex( - (x) => x.type == "null", - ); - if (nullIndex != -1) { - part.properties[key].nullable = true; - part.properties[key].anyOf.splice(nullIndex, 1); + // if (part.properties[key].anyOf) { + // const nullIndex = part.properties[key].anyOf.findIndex( + // (x) => x.type == "null", + // ); + // if (nullIndex != -1) { + // part.properties[key].nullable = true; + // part.properties[key].anyOf.splice(nullIndex, 1); - if (part.properties[key].anyOf.length == 1) { - Object.assign( - part.properties[key], - part.properties[key].anyOf[0], - ); - delete part.properties[key].anyOf; - } - } - } + // if (part.properties[key].anyOf.length == 1) { + // Object.assign( + // part.properties[key], + // part.properties[key].anyOf[0], + // ); + // delete part.properties[key].anyOf; + // } + // } + // } } }