Ajv and openapi spec use different versions of typescript json schema??????

This commit is contained in:
Madeline 2023-03-25 19:24:00 +11:00
parent 59c0dd0731
commit b272c56d1a
No known key found for this signature in database
GPG Key ID: 1958E017C36F2E47
4 changed files with 73 additions and 37 deletions

View File

@ -20,15 +20,13 @@
} }
}, },
"components": { "components": {
"securitySchemes": [ "securitySchemes": {
{
"bearer": { "bearer": {
"type": "http", "type": "http",
"scheme": "bearer", "scheme": "bearer",
"description": "Bearer/Bot prefixes are not required." "description": "Bearer/Bot prefixes are not required."
} }
} },
],
"schemas": { "schemas": {
"SelectProtocolSchema": { "SelectProtocolSchema": {
"type": "object", "type": "object",

View File

@ -26292,9 +26292,15 @@
"type": "boolean" "type": "boolean"
}, },
"mute_config": { "mute_config": {
"nullable": true, "anyOf": [
{
"$ref": "#/definitions/MuteConfig" "$ref": "#/definitions/MuteConfig"
}, },
{
"type": "null"
}
]
},
"muted": { "muted": {
"type": "boolean" "type": "boolean"
}, },
@ -28417,9 +28423,15 @@
"type": "boolean" "type": "boolean"
}, },
"custom_status": { "custom_status": {
"nullable": true, "anyOf": [
{
"$ref": "#/definitions/CustomStatus" "$ref": "#/definitions/CustomStatus"
}, },
{
"type": "null"
}
]
},
"default_guilds_restricted": { "default_guilds_restricted": {
"type": "boolean" "type": "boolean"
}, },

View File

@ -16,6 +16,8 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/* eslint-env node */
require("module-alias/register"); require("module-alias/register");
const getRouteDescriptions = require("./util/getRouteDescriptions"); const getRouteDescriptions = require("./util/getRouteDescriptions");
const path = require("path"); const path = require("path");
@ -27,7 +29,31 @@ require("missing-native-js-functions");
const openapiPath = path.join(__dirname, "..", "assets", "openapi.json"); const openapiPath = path.join(__dirname, "..", "assets", "openapi.json");
const SchemaPath = path.join(__dirname, "..", "assets", "schemas.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( const specification = JSON.parse(
fs.readFileSync(openapiPath, { encoding: "utf8" }), fs.readFileSync(openapiPath, { encoding: "utf8" }),
); );
@ -85,15 +111,13 @@ function apiRoutes() {
.map((x) => ({ name: x })); .map((x) => ({ name: x }));
specification.components = specification.components || {}; specification.components = specification.components || {};
specification.components.securitySchemes = [ specification.components.securitySchemes = {
{
bearer: { bearer: {
type: "http", type: "http",
scheme: "bearer", scheme: "bearer",
description: "Bearer/Bot prefixes are not required.", description: "Bearer/Bot prefixes are not required.",
}, },
}, };
];
routes.forEach((route, pathAndMethod) => { routes.forEach((route, pathAndMethod) => {
const [p, method] = pathAndMethod.split("|"); const [p, method] = pathAndMethod.split("|");

View File

@ -20,6 +20,8 @@
Regenerates the `fosscord-server/assets/schemas.json` file, used for API/Gateway input validation. Regenerates the `fosscord-server/assets/schemas.json` file, used for API/Gateway input validation.
*/ */
/* eslint-env node */
const path = require("path"); const path = require("path");
const fs = require("fs"); const fs = require("fs");
const TJS = require("typescript-json-schema"); const TJS = require("typescript-json-schema");
@ -110,23 +112,23 @@ function main() {
continue; continue;
} }
if (part.properties[key].anyOf) { // if (part.properties[key].anyOf) {
const nullIndex = part.properties[key].anyOf.findIndex( // const nullIndex = part.properties[key].anyOf.findIndex(
(x) => x.type == "null", // (x) => x.type == "null",
); // );
if (nullIndex != -1) { // if (nullIndex != -1) {
part.properties[key].nullable = true; // part.properties[key].nullable = true;
part.properties[key].anyOf.splice(nullIndex, 1); // part.properties[key].anyOf.splice(nullIndex, 1);
if (part.properties[key].anyOf.length == 1) { // if (part.properties[key].anyOf.length == 1) {
Object.assign( // Object.assign(
part.properties[key], // part.properties[key],
part.properties[key].anyOf[0], // part.properties[key].anyOf[0],
); // );
delete part.properties[key].anyOf; // delete part.properties[key].anyOf;
} // }
} // }
} // }
} }
} }