Options.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. export const ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
  2. export const jsonDescription = (jsonSchema, def) => {
  3. if (def.description) {
  4. try {
  5. return {
  6. ...jsonSchema,
  7. ...JSON.parse(def.description),
  8. };
  9. }
  10. catch { }
  11. }
  12. return jsonSchema;
  13. };
  14. export const defaultOptions = {
  15. name: undefined,
  16. $refStrategy: "root",
  17. basePath: ["#"],
  18. effectStrategy: "input",
  19. pipeStrategy: "all",
  20. dateStrategy: "format:date-time",
  21. mapStrategy: "entries",
  22. removeAdditionalStrategy: "passthrough",
  23. allowedAdditionalProperties: true,
  24. rejectedAdditionalProperties: false,
  25. definitionPath: "definitions",
  26. target: "jsonSchema7",
  27. strictUnions: false,
  28. definitions: {},
  29. errorMessages: false,
  30. markdownDescription: false,
  31. patternStrategy: "escape",
  32. applyRegexFlags: false,
  33. emailStrategy: "format:email",
  34. base64Strategy: "contentEncoding:base64",
  35. nameStrategy: "ref",
  36. };
  37. export const getDefaultOptions = (options) => (typeof options === "string"
  38. ? {
  39. ...defaultOptions,
  40. name: options,
  41. }
  42. : {
  43. ...defaultOptions,
  44. ...options,
  45. });