optional.js 553 B

1234567891011121314151617181920
  1. import { parseDef } from "../parseDef.js";
  2. export const parseOptionalDef = (def, refs) => {
  3. if (refs.currentPath.toString() === refs.propertyPath?.toString()) {
  4. return parseDef(def.innerType._def, refs);
  5. }
  6. const innerSchema = parseDef(def.innerType._def, {
  7. ...refs,
  8. currentPath: [...refs.currentPath, "anyOf", "1"],
  9. });
  10. return innerSchema
  11. ? {
  12. anyOf: [
  13. {
  14. not: {},
  15. },
  16. innerSchema,
  17. ],
  18. }
  19. : {};
  20. };