agsamantha/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js

21 lines
553 B
JavaScript
Raw Normal View History

2024-10-02 15:15:21 -05:00
import { parseDef } from "../parseDef.js";
export const parseOptionalDef = (def, refs) => {
if (refs.currentPath.toString() === refs.propertyPath?.toString()) {
return parseDef(def.innerType._def, refs);
}
const innerSchema = parseDef(def.innerType._def, {
...refs,
currentPath: [...refs.currentPath, "anyOf", "1"],
});
return innerSchema
? {
anyOf: [
{
not: {},
},
innerSchema,
],
}
: {};
};