full site update

This commit is contained in:
2025-07-24 18:46:24 +02:00
parent bfe2b90d8d
commit 37a6e0ab31
6912 changed files with 540482 additions and 361712 deletions

View File

@@ -1,14 +1,15 @@
import { parseDef } from "./parseDef.js";
import { getRefs } from "./Refs.js";
import { parseAnyDef } from "./parsers/any.js";
const zodToJsonSchema = (schema, options) => {
const refs = getRefs(options);
const definitions = typeof options === "object" && options.definitions
let definitions = typeof options === "object" && options.definitions
? Object.entries(options.definitions).reduce((acc, [name, schema]) => ({
...acc,
[name]: parseDef(schema._def, {
...refs,
currentPath: [...refs.basePath, refs.definitionPath, name],
}, true) ?? {},
}, true) ?? parseAnyDef(refs),
}), {})
: undefined;
const name = typeof options === "string"
@@ -21,7 +22,7 @@ const zodToJsonSchema = (schema, options) => {
: {
...refs,
currentPath: [...refs.basePath, refs.definitionPath, name],
}, false) ?? {};
}, false) ?? parseAnyDef(refs);
const title = typeof options === "object" &&
options.name !== undefined &&
options.nameStrategy === "title"
@@ -30,6 +31,26 @@ const zodToJsonSchema = (schema, options) => {
if (title !== undefined) {
main.title = title;
}
if (refs.flags.hasReferencedOpenAiAnyType) {
if (!definitions) {
definitions = {};
}
if (!definitions[refs.openAiAnyTypeName]) {
definitions[refs.openAiAnyTypeName] = {
// Skipping "object" as no properties can be defined and additionalProperties must be "false"
type: ["string", "number", "integer", "boolean", "array", "null"],
items: {
$ref: refs.$refStrategy === "relative"
? "1"
: [
...refs.basePath,
refs.definitionPath,
refs.openAiAnyTypeName,
].join("/"),
},
};
}
}
const combined = name === undefined
? definitions
? {