summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-11-29 23:33:25 +0100
committerRory& <root@rory.gay>2025-11-29 23:33:25 +0100
commitf10ec7b80f73b49097900b4a04af3a075d94511e (patch)
tree10b0aa60ae23a5ed32c7ed64342e42cbcd958de8
parentHandle case where session is an object, merges #1412 (diff)
downloadserver-ts-f10ec7b80f73b49097900b4a04af3a075d94511e.tar.xz
Maybe catch functions in the future in schemas?
-rw-r--r--.idea/workspace.xml2
-rw-r--r--scripts/schema.js15
2 files changed, 11 insertions, 6 deletions
diff --git a/.idea/workspace.xml b/.idea/workspace.xml

index b92252c6..4b0adf53 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml
@@ -161,7 +161,7 @@ <workItem from="1760044946282" duration="43683000" /> <workItem from="1760402350251" duration="49898000" /> <workItem from="1760538864442" duration="1330000" /> - <workItem from="1764432507485" duration="18048000" /> + <workItem from="1764432507485" duration="21512000" /> </task> <servers /> </component> diff --git a/scripts/schema.js b/scripts/schema.js
index d5cea3a4..d123ad8b 100644 --- a/scripts/schema.js +++ b/scripts/schema.js
@@ -39,6 +39,7 @@ const { redBright, yellowBright, bgRedBright, yellow, greenBright, green, cyanBr const schemaPath = path.join(__dirname, "..", "assets", "schemas.json"); const exclusionList = JSON.parse(fs.readFileSync(path.join(__dirname, "schemaExclusions.json"), { encoding: "utf8" })); +// @type {TJS.PartialArgs} const settings = { required: true, ignoreErrors: true, @@ -46,6 +47,7 @@ const settings = { defaultNumberType: "integer", noExtraProps: true, defaultProps: false, + useTypeOfKeyword: true, // should help catch functions? }; const baseClassProperties = [ @@ -190,8 +192,6 @@ async function main() { const part = TJS.generateSchema(program, name, settings, [], generator); if (!part) continue; - filterSchema(part); - if (definitions[name]) { process.stdout.write(yellow(` [ERROR] Duplicate schema name detected: ${name}. Overwriting previous schema.`)); } @@ -200,7 +200,7 @@ async function main() { continue; } - if (process.env.WRITE_SCHEMA_DIR === "true") writePromises.push(fsp.writeFile(path.join("schemas_orig", `${name}.json`), JSON.stringify(part, null, 4))); + if (process.env.WRITE_SCHEMA_DIR === "true") writePromises.push(async () => await fsp.writeFile(path.join("schemas_orig", `${name}.json`), JSON.stringify(part, null, 4))); // testing: function mergeDefs(schemaName, schema) { @@ -285,6 +285,9 @@ async function main() { } deleteOneOfKindUndefinedRecursive(definitions, "$"); + for (const defKey in definitions) { + filterSchema(definitions[defKey]); + } if (process.env.WRITE_SCHEMA_DIR === "true") { await Promise.all(writePromises); @@ -333,10 +336,12 @@ function filterSchema(schema) { if (schema.required) schema.required = schema.required.filter((x) => !baseClassProperties.includes(x)); // recurse into own definitions - if (schema.definitions) + if (schema.definitions) { + console.log(redBright("WARNING"), "Schema has own definitions, recursing into them to filter base class properties:", Object.keys(schema.definitions)); for (const defKey in schema.definitions) { filterSchema(schema.definitions[defKey]); } + } } function deepEqual(a, b) { @@ -352,7 +357,7 @@ function deepEqual(a, b) { if (keysA.length !== keysB.length) return false; for (const key of keysA) { - if (!keysB.includes(key) || !deepEqual(a[key], b[key])) { + if (!keysB.includes(key) || (typeof a[key] === typeof b[key] && !deepEqual(a[key], b[key]))) { return false; } }