diff --git a/assets/openapi.json b/assets/openapi.json index e7126eb0f..813a68633 100644 Binary files a/assets/openapi.json and b/assets/openapi.json differ diff --git a/assets/schemas.json b/assets/schemas.json index 3c70ca90c..eaae42682 100644 Binary files a/assets/schemas.json and b/assets/schemas.json differ diff --git a/src/schemas/HelperTypes.ts b/src/schemas/HelperTypes.ts index ef43f97b2..470b0f10c 100644 --- a/src/schemas/HelperTypes.ts +++ b/src/schemas/HelperTypes.ts @@ -21,13 +21,13 @@ export type StringStringDictionary = { }; /** - * @TJS-type: number - * @TJS-format: float + * @TJS-type number + * @TJS-format float */ export type float = number; /** - * @TJS-type: string - * @TJS-format: byte + * @TJS-type string + * @TJS-format byte */ export type base64str = string; diff --git a/src/schemas/Validator.ts b/src/schemas/Validator.ts index 8b1c855f5..610f827c7 100644 --- a/src/schemas/Validator.ts +++ b/src/schemas/Validator.ts @@ -16,7 +16,7 @@ along with this program. If not, see . */ -import Ajv from "ajv"; +import Ajv, { SchemaObject } from "ajv"; import addFormats from "ajv-formats"; import fs from "node:fs"; import path from "node:path"; @@ -39,20 +39,25 @@ const schemas = JSON.parse(fs.readFileSync(SchemaPath, { encoding: "utf8" }).rep // } // } -export const ajv = new Ajv({ - allErrors: true, - parseDate: true, - allowDate: true, - // schemas: schemas, - coerceTypes: true, - messages: true, - strict: true, - strictRequired: true, - allowUnionTypes: true, -}); +export const ajv = (function () { + console.log("[Validation] Initializing Ajv with", Object.entries(schemas).length, "schemas..."); + const _ajv = new Ajv({ + allErrors: true, + parseDate: true, + allowDate: true, + // schemas: schemas, + coerceTypes: true, + messages: true, + strict: true, + strictRequired: true, + allowUnionTypes: true, + }); -addFormats(ajv); -ajv.addSchema(schemas); + addFormats(_ajv); + Object.entries(schemas).forEach((s) => _ajv.addSchema(s[1] as SchemaObject, s[0])); + + return _ajv; +})(); export function validateSchema(schema: string, data: G): G { const valid = ajv.validate(schema, data);