full site update
This commit is contained in:
27
node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js
generated
vendored
27
node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js
generated
vendored
@@ -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
|
||||
? {
|
||||
|
Reference in New Issue
Block a user