@salesforce/b2c-dx-mcp 2.1.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -129
- package/content/guidance/b2c/b2c-business-manager-extensions/SKILL.md +361 -0
- package/content/guidance/b2c/b2c-business-manager-extensions/references/EXTENSIONS-XML.md +458 -0
- package/content/guidance/b2c/b2c-controllers/SKILL.md +301 -0
- package/content/guidance/b2c/b2c-controllers/references/CLASSIC-PATTERNS.md +335 -0
- package/content/guidance/b2c/b2c-controllers/references/SFRA-PATTERNS.md +400 -0
- package/content/guidance/b2c/b2c-custom-api-development/SKILL.md +281 -0
- package/content/guidance/b2c/b2c-custom-api-development/references/CONTRACT.md +142 -0
- package/content/guidance/b2c/b2c-custom-api-development/references/IMPLEMENTATION.md +153 -0
- package/content/guidance/b2c/b2c-custom-api-development/references/TESTING.md +118 -0
- package/content/guidance/b2c/b2c-custom-caches/SKILL.md +279 -0
- package/content/guidance/b2c/b2c-custom-job-steps/SKILL.md +520 -0
- package/content/guidance/b2c/b2c-custom-job-steps/references/CHUNK-ORIENTED.md +377 -0
- package/content/guidance/b2c/b2c-custom-job-steps/references/JOBS-XML.md +212 -0
- package/content/guidance/b2c/b2c-custom-job-steps/references/STEPTYPES-JSON.md +373 -0
- package/content/guidance/b2c/b2c-custom-job-steps/references/TASK-ORIENTED.md +344 -0
- package/content/guidance/b2c/b2c-custom-objects/SKILL.md +327 -0
- package/content/guidance/b2c/b2c-custom-objects/references/OCAPI-SEARCH.md +298 -0
- package/content/guidance/b2c/b2c-forms/SKILL.md +242 -0
- package/content/guidance/b2c/b2c-forms/references/FORM-XML.md +409 -0
- package/content/guidance/b2c/b2c-hooks/SKILL.md +500 -0
- package/content/guidance/b2c/b2c-hooks/references/OCAPI-SCAPI-HOOKS.md +403 -0
- package/content/guidance/b2c/b2c-hooks/references/ORDER-HOOK-LIFECYCLE.md +169 -0
- package/content/guidance/b2c/b2c-hooks/references/SYSTEM-HOOKS.md +433 -0
- package/content/guidance/b2c/b2c-isml/SKILL.md +320 -0
- package/content/guidance/b2c/b2c-isml/references/EXPRESSIONS.md +366 -0
- package/content/guidance/b2c/b2c-isml/references/TAGS.md +443 -0
- package/content/guidance/b2c/b2c-localization/SKILL.md +344 -0
- package/content/guidance/b2c/b2c-localization/references/PATTERNS.md +407 -0
- package/content/guidance/b2c/b2c-logging/SKILL.md +352 -0
- package/content/guidance/b2c/b2c-logging/references/LOG-FILES.md +282 -0
- package/content/guidance/b2c/b2c-metadata/SKILL.md +406 -0
- package/content/guidance/b2c/b2c-metadata/references/SYSTEM-OBJECTS.md +320 -0
- package/content/guidance/b2c/b2c-metadata/references/XML-EXAMPLES.md +366 -0
- package/content/guidance/b2c/b2c-onboarding/SKILL.md +154 -0
- package/content/guidance/b2c/b2c-ordering/SKILL.md +391 -0
- package/content/guidance/b2c/b2c-page-designer/SKILL.md +410 -0
- package/content/guidance/b2c/b2c-page-designer/references/ATTRIBUTE-TYPES.md +436 -0
- package/content/guidance/b2c/b2c-page-designer/references/META-DEFINITIONS.md +340 -0
- package/content/guidance/b2c/b2c-querying-data/SKILL.md +289 -0
- package/content/guidance/b2c/b2c-querying-data/references/PERFORMANCE-APIS.md +74 -0
- package/content/guidance/b2c/b2c-scapi-admin/SKILL.md +53 -0
- package/content/guidance/b2c/b2c-scapi-admin/references/CLIENT-EXAMPLES.md +440 -0
- package/content/guidance/b2c/b2c-scapi-admin/references/INTEGRATION-PATTERNS.md +518 -0
- package/content/guidance/b2c/b2c-scapi-admin/references/OAUTH-SCOPES.md +337 -0
- package/content/guidance/b2c/b2c-scapi-shopper/SKILL.md +56 -0
- package/content/guidance/b2c/b2c-scapi-shopper/references/CHECKOUT-FLOW.md +466 -0
- package/content/guidance/b2c/b2c-scapi-shopper/references/CLIENT-EXAMPLES.md +352 -0
- package/content/guidance/b2c/b2c-scapi-shopper/references/COMMON-PATTERNS.md +390 -0
- package/content/guidance/b2c/b2c-scapi-shopper/references/SCOPES.md +290 -0
- package/content/guidance/b2c/b2c-slas-auth-patterns/SKILL.md +420 -0
- package/content/guidance/b2c/b2c-slas-auth-patterns/references/PASSKEYS.md +126 -0
- package/content/guidance/b2c/b2c-slas-auth-patterns/references/SESSION-BRIDGE.md +267 -0
- package/content/guidance/b2c/b2c-slas-auth-patterns/references/TOKEN-LIFECYCLE.md +367 -0
- package/content/guidance/b2c/b2c-webservices/SKILL.md +318 -0
- package/content/guidance/b2c/b2c-webservices/references/FTP-SERVICES.md +524 -0
- package/content/guidance/b2c/b2c-webservices/references/HTTP-SERVICES.md +578 -0
- package/content/guidance/b2c/b2c-webservices/references/SERVICES-XML.md +351 -0
- package/content/guidance/b2c/b2c-webservices/references/SOAP-SERVICES.md +587 -0
- package/content/guidance/b2c-cli/b2c-am/SKILL.md +277 -0
- package/content/guidance/b2c-cli/b2c-bm-users-roles/SKILL.md +210 -0
- package/content/guidance/b2c-cli/b2c-cap/SKILL.md +131 -0
- package/content/guidance/b2c-cli/b2c-cip/SKILL.md +116 -0
- package/content/guidance/b2c-cli/b2c-cip/references/KNOWN_TABLES.md +105 -0
- package/content/guidance/b2c-cli/b2c-cip/references/SALES_ANALYSIS.md +50 -0
- package/content/guidance/b2c-cli/b2c-cip/references/STARTER_QUERIES.md +147 -0
- package/content/guidance/b2c-cli/b2c-code/SKILL.md +146 -0
- package/content/guidance/b2c-cli/b2c-config/SKILL.md +412 -0
- package/content/guidance/b2c-cli/b2c-content/SKILL.md +176 -0
- package/content/guidance/b2c-cli/b2c-debug/SKILL.md +138 -0
- package/content/guidance/b2c-cli/b2c-docs/SKILL.md +274 -0
- package/content/guidance/b2c-cli/b2c-ecdn/SKILL.md +135 -0
- package/content/guidance/b2c-cli/b2c-ecdn/references/ADVANCED.md +82 -0
- package/content/guidance/b2c-cli/b2c-ecdn/references/SECURITY.md +75 -0
- package/content/guidance/b2c-cli/b2c-import-set-migrations/SKILL.md +265 -0
- package/content/guidance/b2c-cli/b2c-job/SKILL.md +62 -0
- package/content/guidance/b2c-cli/b2c-job/references/EXPORT.md +115 -0
- package/content/guidance/b2c-cli/b2c-job/references/IMPORT.md +43 -0
- package/content/guidance/b2c-cli/b2c-job/references/RUN-AND-MONITOR.md +119 -0
- package/content/guidance/b2c-cli/b2c-logs/SKILL.md +249 -0
- package/content/guidance/b2c-cli/b2c-metrics/SKILL.md +315 -0
- package/content/guidance/b2c-cli/b2c-mrt/SKILL.md +206 -0
- package/content/guidance/b2c-cli/b2c-mrt/references/BUNDLE-COMMANDS.md +185 -0
- package/content/guidance/b2c-cli/b2c-mrt/references/ENVIRONMENT-COMMANDS.md +195 -0
- package/content/guidance/b2c-cli/b2c-mrt/references/PROJECT-COMMANDS.md +154 -0
- package/content/guidance/b2c-cli/b2c-sandbox/SKILL.md +112 -0
- package/content/guidance/b2c-cli/b2c-scapi-custom/SKILL.md +126 -0
- package/content/guidance/b2c-cli/b2c-scapi-schemas/SKILL.md +64 -0
- package/content/guidance/b2c-cli/b2c-scapi-schemas/references/CLI-EXAMPLES.md +108 -0
- package/content/guidance/b2c-cli/b2c-site-import-export/SKILL.md +57 -0
- package/content/guidance/b2c-cli/b2c-site-import-export/references/IMPORT-OPTIONS.md +118 -0
- package/content/guidance/b2c-cli/b2c-site-import-export/references/METADATA-XML.md +381 -0
- package/content/guidance/b2c-cli/b2c-site-import-export/references/WORKFLOWS.md +182 -0
- package/content/guidance/b2c-cli/b2c-sites/SKILL.md +112 -0
- package/content/guidance/b2c-cli/b2c-slas/SKILL.md +182 -0
- package/content/guidance/b2c-cli/b2c-webdav/SKILL.md +169 -0
- package/content/guidance/b2c-ops/b2c-checkout-triage/SKILL.md +68 -0
- package/content/guidance/b2c-ops/b2c-job-health/SKILL.md +75 -0
- package/content/guidance/b2c-ops/b2c-job-health/references/job-logs.md +21 -0
- package/content/guidance/b2c-ops/b2c-order-failure-triage/SKILL.md +66 -0
- package/content/guidance/b2c-ops/b2c-order-failure-triage/references/order-evidence.md +87 -0
- package/content/guidance/b2c-ops/b2c-production-triage/SKILL.md +87 -0
- package/content/guidance/b2c-ops/b2c-production-triage/references/escalation.md +57 -0
- package/content/guidance/index.json +1427 -0
- package/content/guidance/mcp/b2c-config/SKILL.md +86 -0
- package/content/guidance/mcp/cip/SKILL.md +86 -0
- package/content/guidance/mcp/debugger/SKILL.md +71 -0
- package/content/guidance/mcp/scapi/SKILL.md +153 -0
- package/content/guidance/mcp/scapi/references/custom-apis.md +51 -0
- package/content/guidance/mcp/scapi/references/custom-properties.md +43 -0
- package/content/guidance/mcp/scapi/references/jobs.md +30 -0
- package/content/guidance/mcp/scapi/references/products.md +37 -0
- package/content/guidance/mcp/scapi/references/promotions.md +19 -0
- package/content/guidance/mcp/scapi/references/saving.md +12 -0
- package/content/guidance/mcp/scapi/references/snippets.md +89 -0
- package/content/guidance/mcp/scapi/references/tokens.md +56 -0
- package/content/guidance/mcp/server/SKILL.md +99 -0
- package/content/guidance/mcp/server/references/files.md +37 -0
- package/content/guidance/storefront-next/sfnext-authentication/SKILL.md +120 -0
- package/content/guidance/storefront-next/sfnext-components/SKILL.md +191 -0
- package/content/guidance/storefront-next/sfnext-configuration/SKILL.md +160 -0
- package/content/guidance/storefront-next/sfnext-create-component/SKILL.md +195 -0
- package/content/guidance/storefront-next/sfnext-create-component/references/COMPONENT-AUTHORING.md +206 -0
- package/content/guidance/storefront-next/sfnext-create-component/references/PROJECT-STRUCTURE.md +43 -0
- package/content/guidance/storefront-next/sfnext-create-component/references/TOKEN-SYSTEM.md +130 -0
- package/content/guidance/storefront-next/sfnext-create-component/references/TROUBLESHOOTING.md +34 -0
- package/content/guidance/storefront-next/sfnext-create-vertical/SKILL.md +135 -0
- package/content/guidance/storefront-next/sfnext-create-vertical/references/COMPONENT-AUTHORING.md +206 -0
- package/content/guidance/storefront-next/sfnext-create-vertical/references/PROJECT-STRUCTURE.md +43 -0
- package/content/guidance/storefront-next/sfnext-create-vertical/references/TOKEN-SYSTEM.md +130 -0
- package/content/guidance/storefront-next/sfnext-create-vertical/references/TROUBLESHOOTING.md +34 -0
- package/content/guidance/storefront-next/sfnext-custom-apis/SKILL.md +221 -0
- package/content/guidance/storefront-next/sfnext-custom-apis/references/WORKFLOW-EXAMPLES.md +294 -0
- package/content/guidance/storefront-next/sfnext-data-fetching/SKILL.md +190 -0
- package/content/guidance/storefront-next/sfnext-data-fetching/references/LOADER-PATTERNS.md +102 -0
- package/content/guidance/storefront-next/sfnext-data-fetching/references/SCAPI-FETCHER.md +93 -0
- package/content/guidance/storefront-next/sfnext-deployment/SKILL.md +141 -0
- package/content/guidance/storefront-next/sfnext-deployment/references/MRT-DEPLOYMENT.md +90 -0
- package/content/guidance/storefront-next/sfnext-extensions/SKILL.md +142 -0
- package/content/guidance/storefront-next/sfnext-extensions/references/BASE-AUDIT.md +65 -0
- package/content/guidance/storefront-next/sfnext-extensions/references/EXTENSION-EXAMPLES.md +116 -0
- package/content/guidance/storefront-next/sfnext-hybrid-storefronts/SKILL.md +148 -0
- package/content/guidance/storefront-next/sfnext-hybrid-storefronts/references/HYBRID-PROXY-CONFIG.md +123 -0
- package/content/guidance/storefront-next/sfnext-i18n/SKILL.md +187 -0
- package/content/guidance/storefront-next/sfnext-page-designer/SKILL.md +181 -0
- package/content/guidance/storefront-next/sfnext-page-designer/references/COMPONENT-REGISTRY.md +78 -0
- package/content/guidance/storefront-next/sfnext-page-designer/references/DECORATOR-PATTERNS.md +180 -0
- package/content/guidance/storefront-next/sfnext-performance/SKILL.md +132 -0
- package/content/guidance/storefront-next/sfnext-project-setup/SKILL.md +160 -0
- package/content/guidance/storefront-next/sfnext-project-setup/references/ENV-VARIABLES.md +82 -0
- package/content/guidance/storefront-next/sfnext-project-setup/references/PROJECT-STRUCTURE.md +99 -0
- package/content/guidance/storefront-next/sfnext-routing/SKILL.md +180 -0
- package/content/guidance/storefront-next/sfnext-routing/references/ROUTE-CONVENTIONS.md +65 -0
- package/content/guidance/storefront-next/sfnext-scapi-management/SKILL.md +203 -0
- package/content/guidance/storefront-next/sfnext-scapi-management/references/CLI-COMMANDS.md +122 -0
- package/content/guidance/storefront-next/sfnext-state-management/SKILL.md +123 -0
- package/content/guidance/storefront-next/sfnext-testing/SKILL.md +184 -0
- package/content/guidance/storefront-next/sfnext-testing/references/STORYBOOK-PATTERNS.md +118 -0
- package/dist/commands/mcp.d.ts +2 -3
- package/dist/commands/mcp.js +53 -48
- package/dist/guidance.d.ts +6 -0
- package/dist/guidance.js +157 -0
- package/dist/registry.d.ts +2 -1
- package/dist/registry.js +22 -170
- package/dist/server.d.ts +19 -5
- package/dist/server.js +65 -8
- package/dist/skill-references.d.ts +28 -0
- package/dist/skill-references.js +14 -0
- package/dist/tools/adapter.d.ts +8 -5
- package/dist/tools/adapter.js +19 -7
- package/dist/tools/cartridges/index.js +38 -15
- package/dist/tools/cartridges/selected-files.d.ts +11 -0
- package/dist/tools/cartridges/selected-files.js +61 -0
- package/dist/tools/cip/client.d.ts +9 -0
- package/dist/tools/cip/client.js +44 -0
- package/dist/tools/cip/index.d.ts +6 -0
- package/dist/tools/cip/index.js +209 -0
- package/dist/tools/diagnostics/config-inspect.js +8 -4
- package/dist/tools/diagnostics/debug-capture-at-breakpoint.js +37 -11
- package/dist/tools/diagnostics/{debug-step.d.ts → debug-control.d.ts} +1 -1
- package/dist/tools/diagnostics/debug-control.js +36 -0
- package/dist/tools/diagnostics/debug-end-session.js +6 -7
- package/dist/tools/diagnostics/debug-evaluate.js +8 -6
- package/dist/tools/diagnostics/{debug-continue.d.ts → debug-inspect.d.ts} +1 -1
- package/dist/tools/diagnostics/debug-inspect.js +70 -0
- package/dist/tools/diagnostics/debug-list-sessions.js +4 -2
- package/dist/tools/diagnostics/debug-set-breakpoints.js +16 -15
- package/dist/tools/diagnostics/debug-start-session.js +5 -2
- package/dist/tools/diagnostics/debug-wait-for-stop.js +5 -2
- package/dist/tools/diagnostics/index.d.ts +2 -2
- package/dist/tools/diagnostics/index.js +8 -20
- package/dist/tools/diagnostics/log-watch-registry.d.ts +1 -1
- package/dist/tools/diagnostics/log-watch-registry.js +2 -2
- package/dist/tools/diagnostics/logs-get-recent.js +4 -1
- package/dist/tools/diagnostics/logs-list-files.js +4 -2
- package/dist/tools/diagnostics/logs-watch-poll.js +7 -11
- package/dist/tools/diagnostics/{logs-watch-start.d.ts → logs-watch.d.ts} +1 -1
- package/dist/tools/diagnostics/{logs-watch-start.js → logs-watch.js} +45 -12
- package/dist/tools/diagnostics/mrt-log-watch-registry.js +2 -2
- package/dist/tools/diagnostics/mrt-logs-watch-poll.js +6 -8
- package/dist/tools/diagnostics/{mrt-logs-watch-start.d.ts → mrt-logs-watch.d.ts} +1 -1
- package/dist/tools/diagnostics/{mrt-logs-watch-start.js → mrt-logs-watch.js} +44 -11
- package/dist/tools/diagnostics/watch-lifecycle.d.ts +3 -0
- package/dist/tools/diagnostics/watch-lifecycle.js +47 -0
- package/dist/tools/docs/docs-list.js +12 -8
- package/dist/tools/docs/docs-read.js +8 -2
- package/dist/tools/docs/docs-schema-list.js +5 -1
- package/dist/tools/docs/docs-schema-read.js +5 -1
- package/dist/tools/docs/docs-schema-search.js +5 -1
- package/dist/tools/docs/docs-search.js +8 -7
- package/dist/tools/docs/storefront.d.ts +21 -1
- package/dist/tools/docs/storefront.js +25 -0
- package/dist/tools/index.d.ts +2 -2
- package/dist/tools/index.js +2 -2
- package/dist/tools/mrt/index.js +3 -1
- package/dist/tools/project-context.d.ts +5 -3
- package/dist/tools/project-context.js +1 -1
- package/dist/tools/scapi/index.d.ts +1 -1
- package/dist/tools/scapi/index.js +2 -2
- package/dist/tools/scapi/metrics-get.js +3 -1
- package/dist/tools/scapi/scapi-code.d.ts +3 -0
- package/dist/tools/scapi/scapi-code.js +237 -0
- package/dist/tools/scapi/scapi-custom-apis-get-status.js +3 -1
- package/dist/tools/scapi/scapi-schemas-list.js +8 -1
- package/dist/tools/webdav/files.d.ts +14 -0
- package/dist/tools/webdav/files.js +118 -0
- package/dist/tools/webdav/index.d.ts +3 -0
- package/dist/tools/webdav/index.js +160 -0
- package/dist/utils/constants.d.ts +2 -2
- package/dist/utils/constants.js +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/tool-effects.d.ts +4 -0
- package/dist/utils/tool-effects.js +15 -0
- package/dist/utils/types.d.ts +17 -8
- package/dist/utils/types.js +0 -5
- package/node_modules/@modelcontextprotocol/core/LICENSE +216 -0
- package/node_modules/@modelcontextprotocol/core/README.md +40 -0
- package/node_modules/@modelcontextprotocol/core/dist/auth-BWdKR39I.d.mts +8501 -0
- package/node_modules/@modelcontextprotocol/core/dist/auth-BWdKR39I.d.mts.map +1 -0
- package/node_modules/@modelcontextprotocol/core/dist/auth-CUe6YdwF.mjs +1678 -0
- package/node_modules/@modelcontextprotocol/core/dist/auth-CUe6YdwF.mjs.map +1 -0
- package/node_modules/@modelcontextprotocol/core/dist/auth-CfDMXiII.cjs +2899 -0
- package/node_modules/@modelcontextprotocol/core/dist/auth-CfDMXiII.cjs.map +1 -0
- package/node_modules/@modelcontextprotocol/core/dist/auth-hYtaIUZm.d.cts +8501 -0
- package/node_modules/@modelcontextprotocol/core/dist/auth-hYtaIUZm.d.cts.map +1 -0
- package/node_modules/@modelcontextprotocol/core/dist/index.cjs +175 -0
- package/node_modules/@modelcontextprotocol/core/dist/index.d.cts +2 -0
- package/node_modules/@modelcontextprotocol/core/dist/index.d.mts +2 -0
- package/node_modules/@modelcontextprotocol/core/dist/index.mjs +3 -0
- package/node_modules/@modelcontextprotocol/core/dist/internal.cjs +201 -0
- package/node_modules/@modelcontextprotocol/core/dist/internal.d.cts +99 -0
- package/node_modules/@modelcontextprotocol/core/dist/internal.d.cts.map +1 -0
- package/node_modules/@modelcontextprotocol/core/dist/internal.d.mts +99 -0
- package/node_modules/@modelcontextprotocol/core/dist/internal.d.mts.map +1 -0
- package/node_modules/@modelcontextprotocol/core/dist/internal.mjs +3 -0
- package/node_modules/@modelcontextprotocol/core/package.json +85 -0
- package/node_modules/@modelcontextprotocol/server/LICENSE +216 -0
- package/node_modules/@modelcontextprotocol/server/README.md +30 -0
- package/node_modules/@modelcontextprotocol/server/dist/ajvProvider-CEoC__sr.mjs +7514 -0
- package/node_modules/@modelcontextprotocol/server/dist/ajvProvider-CEoC__sr.mjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/ajvProvider-CgI-5L6O.d.mts +1071 -0
- package/node_modules/@modelcontextprotocol/server/dist/ajvProvider-CgI-5L6O.d.mts.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/ajvProvider-FOQRM7up.d.cts +1071 -0
- package/node_modules/@modelcontextprotocol/server/dist/ajvProvider-FOQRM7up.d.cts.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/ajvProvider-ZaoO9afR.cjs +7531 -0
- package/node_modules/@modelcontextprotocol/server/dist/ajvProvider-ZaoO9afR.cjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/cfWorkerProvider-BwbPzsdI.cjs +986 -0
- package/node_modules/@modelcontextprotocol/server/dist/cfWorkerProvider-BwbPzsdI.cjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/cfWorkerProvider-C03CSigr.d.mts +74 -0
- package/node_modules/@modelcontextprotocol/server/dist/cfWorkerProvider-C03CSigr.d.mts.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/cfWorkerProvider-doTkZbTr.d.cts +74 -0
- package/node_modules/@modelcontextprotocol/server/dist/cfWorkerProvider-doTkZbTr.d.cts.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/cfWorkerProvider-p3WaZPqB.mjs +981 -0
- package/node_modules/@modelcontextprotocol/server/dist/cfWorkerProvider-p3WaZPqB.mjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/chunk-Bnu9O96Y.cjs +60 -0
- package/node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs +42 -0
- package/node_modules/@modelcontextprotocol/server/dist/createMcpHandler-CLhGwQTn.d.mts +4043 -0
- package/node_modules/@modelcontextprotocol/server/dist/createMcpHandler-CLhGwQTn.d.mts.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/createMcpHandler-dBHMsxwf.d.cts +4045 -0
- package/node_modules/@modelcontextprotocol/server/dist/createMcpHandler-dBHMsxwf.d.cts.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/dialects-D8eXzoGv.cjs +46 -0
- package/node_modules/@modelcontextprotocol/server/dist/dialects-D8eXzoGv.cjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/dialects-DoSzNhcb.mjs +34 -0
- package/node_modules/@modelcontextprotocol/server/dist/dialects-DoSzNhcb.mjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/index.cjs +2055 -0
- package/node_modules/@modelcontextprotocol/server/dist/index.cjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/index.d.cts +739 -0
- package/node_modules/@modelcontextprotocol/server/dist/index.d.cts.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/index.d.mts +739 -0
- package/node_modules/@modelcontextprotocol/server/dist/index.d.mts.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/index.mjs +1870 -0
- package/node_modules/@modelcontextprotocol/server/dist/index.mjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/mcp-D7GmuPnv.cjs +2022 -0
- package/node_modules/@modelcontextprotocol/server/dist/mcp-D7GmuPnv.cjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/mcp-DXXb3Vv3.mjs +1931 -0
- package/node_modules/@modelcontextprotocol/server/dist/mcp-DXXb3Vv3.mjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsBrowser.cjs +23 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsBrowser.cjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsBrowser.d.cts +11 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsBrowser.d.cts.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsBrowser.d.mts +11 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsBrowser.d.mts.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsBrowser.mjs +22 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsBrowser.mjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsNode.cjs +12 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsNode.d.cts +3 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsNode.d.mts +3 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsNode.mjs +4 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsWorkerd.cjs +30 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsWorkerd.cjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsWorkerd.d.cts +10 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsWorkerd.d.cts.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsWorkerd.d.mts +10 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsWorkerd.d.mts.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsWorkerd.mjs +29 -0
- package/node_modules/@modelcontextprotocol/server/dist/shimsWorkerd.mjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/src-CX2iR2pK.mjs +7606 -0
- package/node_modules/@modelcontextprotocol/server/dist/src-CX2iR2pK.mjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/src-STyD_Vvf.cjs +8104 -0
- package/node_modules/@modelcontextprotocol/server/dist/src-STyD_Vvf.cjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/stdio.cjs +564 -0
- package/node_modules/@modelcontextprotocol/server/dist/stdio.cjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/stdio.d.cts +107 -0
- package/node_modules/@modelcontextprotocol/server/dist/stdio.d.cts.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/stdio.d.mts +107 -0
- package/node_modules/@modelcontextprotocol/server/dist/stdio.d.mts.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/stdio.mjs +562 -0
- package/node_modules/@modelcontextprotocol/server/dist/stdio.mjs.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/types-DUs7mGBv.d.mts +1099 -0
- package/node_modules/@modelcontextprotocol/server/dist/types-DUs7mGBv.d.mts.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/types-DsbMXNFL.d.cts +1099 -0
- package/node_modules/@modelcontextprotocol/server/dist/types-DsbMXNFL.d.cts.map +1 -0
- package/node_modules/@modelcontextprotocol/server/dist/validators/ajv.cjs +5 -0
- package/node_modules/@modelcontextprotocol/server/dist/validators/ajv.d.cts +2 -0
- package/node_modules/@modelcontextprotocol/server/dist/validators/ajv.d.mts +2 -0
- package/node_modules/@modelcontextprotocol/server/dist/validators/ajv.mjs +3 -0
- package/node_modules/@modelcontextprotocol/server/dist/validators/cfWorker.cjs +3 -0
- package/node_modules/@modelcontextprotocol/server/dist/validators/cfWorker.d.cts +2 -0
- package/node_modules/@modelcontextprotocol/server/dist/validators/cfWorker.d.mts +2 -0
- package/node_modules/@modelcontextprotocol/server/dist/validators/cfWorker.mjs +3 -0
- package/node_modules/@modelcontextprotocol/server/package.json +160 -0
- package/node_modules/@salesforce/b2c-agent-plugins/CHANGELOG.md +351 -0
- package/node_modules/@salesforce/b2c-agent-plugins/README.md +84 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/.codex-plugin/plugin.json +40 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/README.md +42 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/assets/logo.svg +31 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/plugin.json +44 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-business-manager-extensions/SKILL.md +361 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-business-manager-extensions/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-business-manager-extensions/references/EXTENSIONS-XML.md +458 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-controllers/SKILL.md +301 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-controllers/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-controllers/references/CLASSIC-PATTERNS.md +335 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-controllers/references/SFRA-PATTERNS.md +400 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-custom-api-development/SKILL.md +281 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-custom-api-development/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-custom-api-development/references/CONTRACT.md +142 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-custom-api-development/references/IMPLEMENTATION.md +153 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-custom-api-development/references/TESTING.md +118 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-custom-caches/SKILL.md +279 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-custom-caches/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-custom-job-steps/SKILL.md +520 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-custom-job-steps/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-custom-job-steps/references/CHUNK-ORIENTED.md +377 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-custom-job-steps/references/JOBS-XML.md +212 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-custom-job-steps/references/STEPTYPES-JSON.md +373 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-custom-job-steps/references/TASK-ORIENTED.md +344 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-custom-objects/SKILL.md +327 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-custom-objects/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-custom-objects/references/OCAPI-SEARCH.md +298 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-forms/SKILL.md +242 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-forms/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-forms/references/FORM-XML.md +409 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-hooks/SKILL.md +500 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-hooks/evals/trigger-evals.json +14 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-hooks/references/OCAPI-SCAPI-HOOKS.md +403 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-hooks/references/ORDER-HOOK-LIFECYCLE.md +169 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-hooks/references/SYSTEM-HOOKS.md +433 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-isml/SKILL.md +320 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-isml/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-isml/references/EXPRESSIONS.md +366 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-isml/references/TAGS.md +443 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-localization/SKILL.md +344 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-localization/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-localization/references/PATTERNS.md +407 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-logging/SKILL.md +352 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-logging/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-logging/references/LOG-FILES.md +282 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-metadata/SKILL.md +406 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-metadata/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-metadata/references/SYSTEM-OBJECTS.md +320 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-metadata/references/XML-EXAMPLES.md +366 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-onboarding/SKILL.md +154 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-ordering/SKILL.md +391 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-ordering/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-page-designer/SKILL.md +410 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-page-designer/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-page-designer/references/ATTRIBUTE-TYPES.md +436 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-page-designer/references/META-DEFINITIONS.md +340 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-querying-data/SKILL.md +289 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-querying-data/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-querying-data/references/PERFORMANCE-APIS.md +74 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-scapi-admin/SKILL.md +53 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-scapi-admin/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-scapi-admin/references/CLIENT-EXAMPLES.md +440 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-scapi-admin/references/INTEGRATION-PATTERNS.md +518 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-scapi-admin/references/OAUTH-SCOPES.md +337 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-scapi-shopper/SKILL.md +56 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-scapi-shopper/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-scapi-shopper/references/CHECKOUT-FLOW.md +466 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-scapi-shopper/references/CLIENT-EXAMPLES.md +352 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-scapi-shopper/references/COMMON-PATTERNS.md +390 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-scapi-shopper/references/SCOPES.md +290 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-slas-auth-patterns/SKILL.md +420 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-slas-auth-patterns/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-slas-auth-patterns/references/PASSKEYS.md +126 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-slas-auth-patterns/references/SESSION-BRIDGE.md +267 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-slas-auth-patterns/references/TOKEN-LIFECYCLE.md +367 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-webservices/SKILL.md +318 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-webservices/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-webservices/references/FTP-SERVICES.md +524 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-webservices/references/HTTP-SERVICES.md +578 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-webservices/references/SERVICES-XML.md +351 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c/skills/b2c-webservices/references/SOAP-SERVICES.md +587 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/.codex-plugin/plugin.json +40 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/README.md +42 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/assets/logo.svg +31 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/plugin.json +44 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-am/SKILL.md +277 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-am/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-bm-users-roles/SKILL.md +210 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-cap/SKILL.md +131 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-cip/SKILL.md +116 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-cip/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-cip/references/KNOWN_TABLES.md +105 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-cip/references/SALES_ANALYSIS.md +50 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-cip/references/STARTER_QUERIES.md +147 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-code/SKILL.md +146 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-code/evals/trigger-evals.json +14 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-config/SKILL.md +412 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-config/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-content/SKILL.md +176 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-content/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-debug/SKILL.md +138 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-debug/evals/trigger-evals.json +16 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-docs/SKILL.md +274 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-docs/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-ecdn/SKILL.md +135 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-ecdn/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-ecdn/references/ADVANCED.md +82 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-ecdn/references/SECURITY.md +75 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-import-set-migrations/SKILL.md +265 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-import-set-migrations/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-job/SKILL.md +62 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-job/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-job/references/EXPORT.md +115 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-job/references/IMPORT.md +43 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-job/references/RUN-AND-MONITOR.md +119 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-logs/SKILL.md +249 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-logs/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-metrics/SKILL.md +315 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-mrt/SKILL.md +206 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-mrt/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-mrt/references/BUNDLE-COMMANDS.md +185 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-mrt/references/ENVIRONMENT-COMMANDS.md +195 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-mrt/references/PROJECT-COMMANDS.md +154 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-sandbox/SKILL.md +112 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-sandbox/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-scapi-custom/SKILL.md +126 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-scapi-custom/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-scapi-schemas/SKILL.md +64 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-scapi-schemas/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-scapi-schemas/references/CLI-EXAMPLES.md +108 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-site-import-export/SKILL.md +57 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-site-import-export/evals/trigger-evals.json +14 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-site-import-export/references/IMPORT-OPTIONS.md +118 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-site-import-export/references/METADATA-XML.md +381 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-site-import-export/references/WORKFLOWS.md +182 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-sites/SKILL.md +112 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-sites/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-slas/SKILL.md +182 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-slas/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-webdav/SKILL.md +169 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-cli/skills/b2c-webdav/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-experimental/skills/b2c-scaffold/SKILL.md +168 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-experimental/skills/b2c-scaffold/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-ops/.codex-plugin/plugin.json +39 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-ops/README.md +31 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-ops/assets/logo.svg +31 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-ops/plugin.json +43 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-ops/skills/b2c-checkout-triage/SKILL.md +68 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-ops/skills/b2c-job-health/SKILL.md +75 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-ops/skills/b2c-job-health/references/job-logs.md +21 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-ops/skills/b2c-order-failure-triage/SKILL.md +66 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-ops/skills/b2c-order-failure-triage/references/order-evidence.md +87 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-ops/skills/b2c-production-triage/SKILL.md +87 -0
- package/node_modules/@salesforce/b2c-agent-plugins/b2c-ops/skills/b2c-production-triage/references/escalation.md +57 -0
- package/node_modules/@salesforce/b2c-agent-plugins/eval/README.md +160 -0
- package/node_modules/@salesforce/b2c-agent-plugins/eval/eval_lib.py +705 -0
- package/node_modules/@salesforce/b2c-agent-plugins/eval/project/CLAUDE.md +10 -0
- package/node_modules/@salesforce/b2c-agent-plugins/eval/project/README.md +24 -0
- package/node_modules/@salesforce/b2c-agent-plugins/eval/project/cartridges/app_storefront_custom/cartridge/controllers/Loyalty.js +16 -0
- package/node_modules/@salesforce/b2c-agent-plugins/eval/project/cartridges/app_storefront_custom/cartridge/models/loyalty.js +13 -0
- package/node_modules/@salesforce/b2c-agent-plugins/eval/project/cartridges/app_storefront_custom/cartridge/templates/default/loyalty/dashboard.isml +22 -0
- package/node_modules/@salesforce/b2c-agent-plugins/eval/project/dw.json +5 -0
- package/node_modules/@salesforce/b2c-agent-plugins/eval/run_eval.py +187 -0
- package/node_modules/@salesforce/b2c-agent-plugins/eval/run_loop.py +467 -0
- package/node_modules/@salesforce/b2c-agent-plugins/figma-to-sfnext-pagedesigner/.codex-plugin/plugin.json +40 -0
- package/node_modules/@salesforce/b2c-agent-plugins/figma-to-sfnext-pagedesigner/README.md +55 -0
- package/node_modules/@salesforce/b2c-agent-plugins/figma-to-sfnext-pagedesigner/assets/logo.svg +31 -0
- package/node_modules/@salesforce/b2c-agent-plugins/figma-to-sfnext-pagedesigner/plugin.json +44 -0
- package/node_modules/@salesforce/b2c-agent-plugins/figma-to-sfnext-pagedesigner/skills/figma-to-sfnext-pagedesigner/SKILL.md +444 -0
- package/node_modules/@salesforce/b2c-agent-plugins/figma-to-sfnext-pagedesigner/skills/figma-to-sfnext-pagedesigner/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/figma-to-sfnext-pagedesigner/skills/figma-to-sfnext-pagedesigner/references/PAGE-DESIGNER-SFN.md +120 -0
- package/node_modules/@salesforce/b2c-agent-plugins/package.json +6 -0
- package/node_modules/@salesforce/b2c-agent-plugins/plugins.json +23 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/.codex-plugin/plugin.json +39 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/README.md +56 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/assets/logo.svg +31 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/plugin.json +43 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-authentication/SKILL.md +120 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-components/SKILL.md +191 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-configuration/SKILL.md +160 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-create-component/SKILL.md +195 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-create-component/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-create-component/references/COMPONENT-AUTHORING.md +206 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-create-component/references/PROJECT-STRUCTURE.md +43 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-create-component/references/TOKEN-SYSTEM.md +130 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-create-component/references/TROUBLESHOOTING.md +34 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-create-vertical/SKILL.md +135 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-create-vertical/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-create-vertical/references/COMPONENT-AUTHORING.md +206 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-create-vertical/references/PROJECT-STRUCTURE.md +43 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-create-vertical/references/TOKEN-SYSTEM.md +130 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-create-vertical/references/TROUBLESHOOTING.md +34 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-custom-apis/SKILL.md +221 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-custom-apis/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-custom-apis/references/WORKFLOW-EXAMPLES.md +294 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-data-fetching/SKILL.md +190 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-data-fetching/references/LOADER-PATTERNS.md +102 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-data-fetching/references/SCAPI-FETCHER.md +93 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-deployment/SKILL.md +141 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-deployment/references/MRT-DEPLOYMENT.md +90 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-extensions/SKILL.md +142 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-extensions/references/BASE-AUDIT.md +65 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-extensions/references/EXTENSION-EXAMPLES.md +116 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-hybrid-storefronts/SKILL.md +148 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-hybrid-storefronts/references/HYBRID-PROXY-CONFIG.md +123 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-i18n/SKILL.md +187 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-page-designer/SKILL.md +181 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-page-designer/references/COMPONENT-REGISTRY.md +78 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-page-designer/references/DECORATOR-PATTERNS.md +180 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-performance/SKILL.md +132 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-project-setup/SKILL.md +160 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-project-setup/references/ENV-VARIABLES.md +82 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-project-setup/references/PROJECT-STRUCTURE.md +99 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-routing/SKILL.md +180 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-routing/references/ROUTE-CONVENTIONS.md +65 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-scapi-management/SKILL.md +203 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-scapi-management/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-scapi-management/references/CLI-COMMANDS.md +122 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-state-management/SKILL.md +123 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-testing/SKILL.md +184 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next/skills/sfnext-testing/references/STORYBOOK-PATTERNS.md +118 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next-figma/.codex-plugin/plugin.json +40 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next-figma/README.md +45 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next-figma/assets/logo.svg +31 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next-figma/plugin.json +44 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next-figma/skills/sfnext-create-figma-kit/SKILL.md +133 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next-figma/skills/sfnext-create-figma-kit/evals/trigger-evals.json +12 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next-figma/skills/sfnext-create-figma-kit/references/FIGMA-COMPONENT-EDITING.md +92 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next-figma/skills/sfnext-create-figma-kit/references/PROJECT-STRUCTURE.md +43 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next-figma/skills/sfnext-create-figma-kit/references/TOKEN-SYSTEM.md +130 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next-figma/skills/sfnext-create-figma-kit/references/TROUBLESHOOTING.md +34 -0
- package/node_modules/@salesforce/b2c-agent-plugins/storefront-next-figma/skills/sfnext-create-figma-kit/references/VERTICAL-FIGMA-SYNC.md +45 -0
- package/node_modules/zod/LICENSE +21 -0
- package/node_modules/zod/README.md +218 -0
- package/node_modules/zod/compile.cjs +77 -0
- package/node_modules/zod/compile.d.cts +1 -0
- package/node_modules/zod/compile.d.ts +1 -0
- package/node_modules/zod/compile.js +52 -0
- package/node_modules/zod/index.cjs +33 -0
- package/node_modules/zod/index.d.cts +3 -0
- package/node_modules/zod/index.d.ts +3 -0
- package/node_modules/zod/index.js +7 -0
- package/node_modules/zod/locales/index.cjs +17 -0
- package/node_modules/zod/locales/index.d.cts +1 -0
- package/node_modules/zod/locales/index.d.ts +1 -0
- package/node_modules/zod/locales/index.js +1 -0
- package/node_modules/zod/locales/package.json +7 -0
- package/node_modules/zod/mini/index.cjs +32 -0
- package/node_modules/zod/mini/index.d.cts +3 -0
- package/node_modules/zod/mini/index.d.ts +3 -0
- package/node_modules/zod/mini/index.js +3 -0
- package/node_modules/zod/mini/package.json +7 -0
- package/node_modules/zod/package.json +146 -0
- package/node_modules/zod/src/compile.ts +56 -0
- package/node_modules/zod/src/index.ts +7 -0
- package/node_modules/zod/src/locales/index.ts +1 -0
- package/node_modules/zod/src/mini/index.ts +3 -0
- package/node_modules/zod/src/v3/ZodError.ts +340 -0
- package/node_modules/zod/src/v3/benchmarks/datetime.ts +58 -0
- package/node_modules/zod/src/v3/benchmarks/discriminatedUnion.ts +80 -0
- package/node_modules/zod/src/v3/benchmarks/index.ts +59 -0
- package/node_modules/zod/src/v3/benchmarks/ipv4.ts +57 -0
- package/node_modules/zod/src/v3/benchmarks/object.ts +69 -0
- package/node_modules/zod/src/v3/benchmarks/primitives.ts +162 -0
- package/node_modules/zod/src/v3/benchmarks/realworld.ts +63 -0
- package/node_modules/zod/src/v3/benchmarks/string.ts +55 -0
- package/node_modules/zod/src/v3/benchmarks/union.ts +80 -0
- package/node_modules/zod/src/v3/errors.ts +13 -0
- package/node_modules/zod/src/v3/external.ts +6 -0
- package/node_modules/zod/src/v3/helpers/enumUtil.ts +17 -0
- package/node_modules/zod/src/v3/helpers/errorUtil.ts +8 -0
- package/node_modules/zod/src/v3/helpers/parseUtil.ts +176 -0
- package/node_modules/zod/src/v3/helpers/partialUtil.ts +34 -0
- package/node_modules/zod/src/v3/helpers/typeAliases.ts +2 -0
- package/node_modules/zod/src/v3/helpers/util.ts +224 -0
- package/node_modules/zod/src/v3/index.ts +4 -0
- package/node_modules/zod/src/v3/locales/en.ts +124 -0
- package/node_modules/zod/src/v3/standard-schema.ts +113 -0
- package/node_modules/zod/src/v3/tests/Mocker.ts +54 -0
- package/node_modules/zod/src/v3/tests/all-errors.test.ts +157 -0
- package/node_modules/zod/src/v3/tests/anyunknown.test.ts +28 -0
- package/node_modules/zod/src/v3/tests/array.test.ts +71 -0
- package/node_modules/zod/src/v3/tests/async-parsing.test.ts +388 -0
- package/node_modules/zod/src/v3/tests/async-refinements.test.ts +46 -0
- package/node_modules/zod/src/v3/tests/base.test.ts +29 -0
- package/node_modules/zod/src/v3/tests/bigint.test.ts +55 -0
- package/node_modules/zod/src/v3/tests/branded.test.ts +53 -0
- package/node_modules/zod/src/v3/tests/catch.test.ts +220 -0
- package/node_modules/zod/src/v3/tests/coerce.test.ts +133 -0
- package/node_modules/zod/src/v3/tests/complex.test.ts +70 -0
- package/node_modules/zod/src/v3/tests/custom.test.ts +31 -0
- package/node_modules/zod/src/v3/tests/date.test.ts +32 -0
- package/node_modules/zod/src/v3/tests/deepmasking.test.ts +186 -0
- package/node_modules/zod/src/v3/tests/default.test.ts +112 -0
- package/node_modules/zod/src/v3/tests/description.test.ts +33 -0
- package/node_modules/zod/src/v3/tests/discriminated-unions.test.ts +315 -0
- package/node_modules/zod/src/v3/tests/enum.test.ts +80 -0
- package/node_modules/zod/src/v3/tests/error.test.ts +586 -0
- package/node_modules/zod/src/v3/tests/firstparty.test.ts +87 -0
- package/node_modules/zod/src/v3/tests/firstpartyschematypes.test.ts +21 -0
- package/node_modules/zod/src/v3/tests/function.test.ts +261 -0
- package/node_modules/zod/src/v3/tests/generics.test.ts +48 -0
- package/node_modules/zod/src/v3/tests/instanceof.test.ts +37 -0
- package/node_modules/zod/src/v3/tests/intersection.test.ts +128 -0
- package/node_modules/zod/src/v3/tests/language-server.source.ts +76 -0
- package/node_modules/zod/src/v3/tests/language-server.test.ts +206 -0
- package/node_modules/zod/src/v3/tests/literal.test.ts +36 -0
- package/node_modules/zod/src/v3/tests/map.test.ts +110 -0
- package/node_modules/zod/src/v3/tests/masking.test.ts +4 -0
- package/node_modules/zod/src/v3/tests/mocker.test.ts +19 -0
- package/node_modules/zod/src/v3/tests/nan.test.ts +24 -0
- package/node_modules/zod/src/v3/tests/nativeEnum.test.ts +87 -0
- package/node_modules/zod/src/v3/tests/nullable.test.ts +42 -0
- package/node_modules/zod/src/v3/tests/number.test.ts +176 -0
- package/node_modules/zod/src/v3/tests/object-augmentation.test.ts +29 -0
- package/node_modules/zod/src/v3/tests/object-in-es5-env.test.ts +29 -0
- package/node_modules/zod/src/v3/tests/object.test.ts +431 -0
- package/node_modules/zod/src/v3/tests/optional.test.ts +42 -0
- package/node_modules/zod/src/v3/tests/parseUtil.test.ts +23 -0
- package/node_modules/zod/src/v3/tests/parser.test.ts +41 -0
- package/node_modules/zod/src/v3/tests/partials.test.ts +243 -0
- package/node_modules/zod/src/v3/tests/pickomit.test.ts +111 -0
- package/node_modules/zod/src/v3/tests/pipeline.test.ts +29 -0
- package/node_modules/zod/src/v3/tests/preprocess.test.ts +186 -0
- package/node_modules/zod/src/v3/tests/primitive.test.ts +440 -0
- package/node_modules/zod/src/v3/tests/promise.test.ts +90 -0
- package/node_modules/zod/src/v3/tests/readonly.test.ts +114 -0
- package/node_modules/zod/src/v3/tests/record.test.ts +171 -0
- package/node_modules/zod/src/v3/tests/recursive.test.ts +197 -0
- package/node_modules/zod/src/v3/tests/refine.test.ts +313 -0
- package/node_modules/zod/src/v3/tests/safeparse.test.ts +27 -0
- package/node_modules/zod/src/v3/tests/set.test.ts +142 -0
- package/node_modules/zod/src/v3/tests/standard-schema.test.ts +83 -0
- package/node_modules/zod/src/v3/tests/string.test.ts +922 -0
- package/node_modules/zod/src/v3/tests/transformer.test.ts +233 -0
- package/node_modules/zod/src/v3/tests/tuple.test.ts +90 -0
- package/node_modules/zod/src/v3/tests/unions.test.ts +57 -0
- package/node_modules/zod/src/v3/tests/validations.test.ts +133 -0
- package/node_modules/zod/src/v3/tests/void.test.ts +15 -0
- package/node_modules/zod/src/v3/types.ts +5138 -0
- package/node_modules/zod/src/v4/classic/checks.ts +33 -0
- package/node_modules/zod/src/v4/classic/coerce.ts +27 -0
- package/node_modules/zod/src/v4/classic/compat.ts +78 -0
- package/node_modules/zod/src/v4/classic/deep-partial.ts +76 -0
- package/node_modules/zod/src/v4/classic/errors.ts +97 -0
- package/node_modules/zod/src/v4/classic/external.ts +55 -0
- package/node_modules/zod/src/v4/classic/from-json-schema.ts +721 -0
- package/node_modules/zod/src/v4/classic/in-out.ts +45 -0
- package/node_modules/zod/src/v4/classic/index.ts +5 -0
- package/node_modules/zod/src/v4/classic/iso.ts +20 -0
- package/node_modules/zod/src/v4/classic/parse.ts +88 -0
- package/node_modules/zod/src/v4/classic/schemas.ts +2862 -0
- package/node_modules/zod/src/v4/classic/tests/anyunknown.test.ts +26 -0
- package/node_modules/zod/src/v4/classic/tests/apply.test.ts +86 -0
- package/node_modules/zod/src/v4/classic/tests/array.test.ts +264 -0
- package/node_modules/zod/src/v4/classic/tests/assignability.test.ts +351 -0
- package/node_modules/zod/src/v4/classic/tests/async-parsing.test.ts +381 -0
- package/node_modules/zod/src/v4/classic/tests/async-refinements.test.ts +68 -0
- package/node_modules/zod/src/v4/classic/tests/base.test.ts +7 -0
- package/node_modules/zod/src/v4/classic/tests/bigint.test.ts +83 -0
- package/node_modules/zod/src/v4/classic/tests/brand.test.ts +106 -0
- package/node_modules/zod/src/v4/classic/tests/catch.test.ts +604 -0
- package/node_modules/zod/src/v4/classic/tests/coalesce.test.ts +20 -0
- package/node_modules/zod/src/v4/classic/tests/codec-examples.test.ts +572 -0
- package/node_modules/zod/src/v4/classic/tests/codec.test.ts +704 -0
- package/node_modules/zod/src/v4/classic/tests/coerce.test.ts +160 -0
- package/node_modules/zod/src/v4/classic/tests/continuability.test.ts +374 -0
- package/node_modules/zod/src/v4/classic/tests/credit-card.test.ts +76 -0
- package/node_modules/zod/src/v4/classic/tests/custom.test.ts +40 -0
- package/node_modules/zod/src/v4/classic/tests/cyclic-data.test.ts +720 -0
- package/node_modules/zod/src/v4/classic/tests/date.test.ts +92 -0
- package/node_modules/zod/src/v4/classic/tests/datetime.test.ts +316 -0
- package/node_modules/zod/src/v4/classic/tests/deep-partial.test.ts +380 -0
- package/node_modules/zod/src/v4/classic/tests/default-locale.test.ts +32 -0
- package/node_modules/zod/src/v4/classic/tests/default.test.ts +455 -0
- package/node_modules/zod/src/v4/classic/tests/describe-meta-checks.test.ts +27 -0
- package/node_modules/zod/src/v4/classic/tests/description.test.ts +32 -0
- package/node_modules/zod/src/v4/classic/tests/detached-methods.test.ts +221 -0
- package/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +836 -0
- package/node_modules/zod/src/v4/classic/tests/enum.test.ts +296 -0
- package/node_modules/zod/src/v4/classic/tests/error-utils.test.ts +917 -0
- package/node_modules/zod/src/v4/classic/tests/error.test.ts +979 -0
- package/node_modules/zod/src/v4/classic/tests/file.test.ts +96 -0
- package/node_modules/zod/src/v4/classic/tests/firstparty.test.ts +179 -0
- package/node_modules/zod/src/v4/classic/tests/fix-json-issue.test.ts +26 -0
- package/node_modules/zod/src/v4/classic/tests/from-json-schema.test.ts +1310 -0
- package/node_modules/zod/src/v4/classic/tests/function.test.ts +391 -0
- package/node_modules/zod/src/v4/classic/tests/generics.test.ts +72 -0
- package/node_modules/zod/src/v4/classic/tests/global-config.test.ts +32 -0
- package/node_modules/zod/src/v4/classic/tests/hash.test.ts +67 -0
- package/node_modules/zod/src/v4/classic/tests/in-out.test.ts +159 -0
- package/node_modules/zod/src/v4/classic/tests/index.test.ts +958 -0
- package/node_modules/zod/src/v4/classic/tests/instance-footprint.test.ts +281 -0
- package/node_modules/zod/src/v4/classic/tests/instanceof.test.ts +107 -0
- package/node_modules/zod/src/v4/classic/tests/intersection.test.ts +334 -0
- package/node_modules/zod/src/v4/classic/tests/issue-schema.test.ts +183 -0
- package/node_modules/zod/src/v4/classic/tests/jitless-allows-eval.test.ts +39 -0
- package/node_modules/zod/src/v4/classic/tests/json.test.ts +109 -0
- package/node_modules/zod/src/v4/classic/tests/lazy.test.ts +262 -0
- package/node_modules/zod/src/v4/classic/tests/literal.test.ts +128 -0
- package/node_modules/zod/src/v4/classic/tests/locales_ka.test.ts +29 -0
- package/node_modules/zod/src/v4/classic/tests/locales_ro.test.ts +24 -0
- package/node_modules/zod/src/v4/classic/tests/map.test.ts +342 -0
- package/node_modules/zod/src/v4/classic/tests/nan.test.ts +21 -0
- package/node_modules/zod/src/v4/classic/tests/nested-refine.test.ts +168 -0
- package/node_modules/zod/src/v4/classic/tests/nonoptional.test.ts +101 -0
- package/node_modules/zod/src/v4/classic/tests/nullable.test.ts +22 -0
- package/node_modules/zod/src/v4/classic/tests/number.test.ts +362 -0
- package/node_modules/zod/src/v4/classic/tests/object.test.ts +950 -0
- package/node_modules/zod/src/v4/classic/tests/optin-ladder.test.ts +234 -0
- package/node_modules/zod/src/v4/classic/tests/optional.test.ts +366 -0
- package/node_modules/zod/src/v4/classic/tests/partial.test.ts +497 -0
- package/node_modules/zod/src/v4/classic/tests/pickomit.test.ts +211 -0
- package/node_modules/zod/src/v4/classic/tests/pipe.test.ts +101 -0
- package/node_modules/zod/src/v4/classic/tests/prefault.test.ts +74 -0
- package/node_modules/zod/src/v4/classic/tests/preprocess-types.test.ts +44 -0
- package/node_modules/zod/src/v4/classic/tests/preprocess.test.ts +351 -0
- package/node_modules/zod/src/v4/classic/tests/primitive.test.ts +175 -0
- package/node_modules/zod/src/v4/classic/tests/promise.test.ts +81 -0
- package/node_modules/zod/src/v4/classic/tests/prototypes.test.ts +23 -0
- package/node_modules/zod/src/v4/classic/tests/readonly.test.ts +184 -0
- package/node_modules/zod/src/v4/classic/tests/record.test.ts +885 -0
- package/node_modules/zod/src/v4/classic/tests/recursive-types.test.ts +662 -0
- package/node_modules/zod/src/v4/classic/tests/redos.test.ts +68 -0
- package/node_modules/zod/src/v4/classic/tests/refine.test.ts +693 -0
- package/node_modules/zod/src/v4/classic/tests/registries.test.ts +243 -0
- package/node_modules/zod/src/v4/classic/tests/set.test.ts +190 -0
- package/node_modules/zod/src/v4/classic/tests/standard-schema.test.ts +134 -0
- package/node_modules/zod/src/v4/classic/tests/string-formats.test.ts +125 -0
- package/node_modules/zod/src/v4/classic/tests/string.test.ts +1346 -0
- package/node_modules/zod/src/v4/classic/tests/stringbool.test.ts +124 -0
- package/node_modules/zod/src/v4/classic/tests/template-literal.test.ts +780 -0
- package/node_modules/zod/src/v4/classic/tests/to-json-schema-methods.test.ts +438 -0
- package/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts +4537 -0
- package/node_modules/zod/src/v4/classic/tests/transform.test.ts +378 -0
- package/node_modules/zod/src/v4/classic/tests/tuple.test.ts +511 -0
- package/node_modules/zod/src/v4/classic/tests/union.test.ts +310 -0
- package/node_modules/zod/src/v4/classic/tests/url.test.ts +13 -0
- package/node_modules/zod/src/v4/classic/tests/validate.test.ts +76 -0
- package/node_modules/zod/src/v4/classic/tests/validations.test.ts +283 -0
- package/node_modules/zod/src/v4/classic/tests/void.test.ts +12 -0
- package/node_modules/zod/src/v4/core/api.ts +1859 -0
- package/node_modules/zod/src/v4/core/checks.ts +1306 -0
- package/node_modules/zod/src/v4/core/compile.ts +2188 -0
- package/node_modules/zod/src/v4/core/core.ts +232 -0
- package/node_modules/zod/src/v4/core/doc.ts +48 -0
- package/node_modules/zod/src/v4/core/errors.ts +546 -0
- package/node_modules/zod/src/v4/core/index.ts +19 -0
- package/node_modules/zod/src/v4/core/json-schema-generator.ts +131 -0
- package/node_modules/zod/src/v4/core/json-schema-processors.ts +830 -0
- package/node_modules/zod/src/v4/core/json-schema.ts +148 -0
- package/node_modules/zod/src/v4/core/memoizer.ts +284 -0
- package/node_modules/zod/src/v4/core/parse.ts +288 -0
- package/node_modules/zod/src/v4/core/regexes.ts +207 -0
- package/node_modules/zod/src/v4/core/registries.ts +105 -0
- package/node_modules/zod/src/v4/core/schemas.ts +5028 -0
- package/node_modules/zod/src/v4/core/standard-schema.ts +159 -0
- package/node_modules/zod/src/v4/core/tests/compile-differential.test.ts +969 -0
- package/node_modules/zod/src/v4/core/tests/compile-global.test.ts +89 -0
- package/node_modules/zod/src/v4/core/tests/compile-off-by-default.test.ts +26 -0
- package/node_modules/zod/src/v4/core/tests/compile-stats.test.ts +34 -0
- package/node_modules/zod/src/v4/core/tests/compile.test.ts +1639 -0
- package/node_modules/zod/src/v4/core/tests/extend.test.ts +59 -0
- package/node_modules/zod/src/v4/core/tests/index.test.ts +46 -0
- package/node_modules/zod/src/v4/core/tests/locales/be.test.ts +124 -0
- package/node_modules/zod/src/v4/core/tests/locales/el.test.ts +214 -0
- package/node_modules/zod/src/v4/core/tests/locales/en.test.ts +22 -0
- package/node_modules/zod/src/v4/core/tests/locales/es.test.ts +180 -0
- package/node_modules/zod/src/v4/core/tests/locales/fr.test.ts +72 -0
- package/node_modules/zod/src/v4/core/tests/locales/he.test.ts +379 -0
- package/node_modules/zod/src/v4/core/tests/locales/hr.test.ts +163 -0
- package/node_modules/zod/src/v4/core/tests/locales/nl.test.ts +46 -0
- package/node_modules/zod/src/v4/core/tests/locales/parity.test.ts +42 -0
- package/node_modules/zod/src/v4/core/tests/locales/ru.test.ts +128 -0
- package/node_modules/zod/src/v4/core/tests/locales/tk.test.ts +69 -0
- package/node_modules/zod/src/v4/core/tests/locales/tr.test.ts +69 -0
- package/node_modules/zod/src/v4/core/tests/locales/uz.test.ts +105 -0
- package/node_modules/zod/src/v4/core/tests/record-constructor.test.ts +125 -0
- package/node_modules/zod/src/v4/core/tests/recursive-tuples.test.ts +45 -0
- package/node_modules/zod/src/v4/core/tests/treeshake.test.ts +51 -0
- package/node_modules/zod/src/v4/core/tests/url-no-canparse.test.ts +31 -0
- package/node_modules/zod/src/v4/core/to-json-schema.ts +855 -0
- package/node_modules/zod/src/v4/core/util.ts +1209 -0
- package/node_modules/zod/src/v4/core/versions.ts +5 -0
- package/node_modules/zod/src/v4/core/visit.ts +193 -0
- package/node_modules/zod/src/v4/core/zsf.ts +323 -0
- package/node_modules/zod/src/v4/index.ts +4 -0
- package/node_modules/zod/src/v4/locales/ar.ts +118 -0
- package/node_modules/zod/src/v4/locales/az.ts +114 -0
- package/node_modules/zod/src/v4/locales/be.ts +186 -0
- package/node_modules/zod/src/v4/locales/bg.ts +131 -0
- package/node_modules/zod/src/v4/locales/bn.ts +121 -0
- package/node_modules/zod/src/v4/locales/ca.ts +119 -0
- package/node_modules/zod/src/v4/locales/ckb.ts +138 -0
- package/node_modules/zod/src/v4/locales/cs.ts +121 -0
- package/node_modules/zod/src/v4/locales/da.ts +126 -0
- package/node_modules/zod/src/v4/locales/de.ts +119 -0
- package/node_modules/zod/src/v4/locales/el.ts +122 -0
- package/node_modules/zod/src/v4/locales/en.ts +134 -0
- package/node_modules/zod/src/v4/locales/eo.ts +121 -0
- package/node_modules/zod/src/v4/locales/es.ts +143 -0
- package/node_modules/zod/src/v4/locales/fa.ts +129 -0
- package/node_modules/zod/src/v4/locales/fi.ts +124 -0
- package/node_modules/zod/src/v4/locales/fr-CA.ts +119 -0
- package/node_modules/zod/src/v4/locales/fr.ts +137 -0
- package/node_modules/zod/src/v4/locales/gu.ts +121 -0
- package/node_modules/zod/src/v4/locales/he.ts +251 -0
- package/node_modules/zod/src/v4/locales/hi.ts +124 -0
- package/node_modules/zod/src/v4/locales/hr.ts +133 -0
- package/node_modules/zod/src/v4/locales/hu.ts +120 -0
- package/node_modules/zod/src/v4/locales/hy.ts +173 -0
- package/node_modules/zod/src/v4/locales/id.ts +118 -0
- package/node_modules/zod/src/v4/locales/index.ts +62 -0
- package/node_modules/zod/src/v4/locales/is.ts +122 -0
- package/node_modules/zod/src/v4/locales/it.ts +119 -0
- package/node_modules/zod/src/v4/locales/ja.ts +117 -0
- package/node_modules/zod/src/v4/locales/ka.ts +126 -0
- package/node_modules/zod/src/v4/locales/kh.ts +7 -0
- package/node_modules/zod/src/v4/locales/km.ts +122 -0
- package/node_modules/zod/src/v4/locales/kn.ts +124 -0
- package/node_modules/zod/src/v4/locales/ko.ts +124 -0
- package/node_modules/zod/src/v4/locales/lt.ts +241 -0
- package/node_modules/zod/src/v4/locales/mk.ts +121 -0
- package/node_modules/zod/src/v4/locales/ms.ts +118 -0
- package/node_modules/zod/src/v4/locales/ne.ts +126 -0
- package/node_modules/zod/src/v4/locales/nl.ts +124 -0
- package/node_modules/zod/src/v4/locales/nn.ts +119 -0
- package/node_modules/zod/src/v4/locales/no.ts +119 -0
- package/node_modules/zod/src/v4/locales/ota.ts +120 -0
- package/node_modules/zod/src/v4/locales/pl.ts +121 -0
- package/node_modules/zod/src/v4/locales/ps.ts +129 -0
- package/node_modules/zod/src/v4/locales/pt-BR.ts +159 -0
- package/node_modules/zod/src/v4/locales/pt.ts +157 -0
- package/node_modules/zod/src/v4/locales/ro.ts +130 -0
- package/node_modules/zod/src/v4/locales/ru.ts +186 -0
- package/node_modules/zod/src/v4/locales/sk.ts +121 -0
- package/node_modules/zod/src/v4/locales/sl.ts +121 -0
- package/node_modules/zod/src/v4/locales/sv.ts +122 -0
- package/node_modules/zod/src/v4/locales/ta.ts +121 -0
- package/node_modules/zod/src/v4/locales/th.ts +122 -0
- package/node_modules/zod/src/v4/locales/tk.ts +111 -0
- package/node_modules/zod/src/v4/locales/tr.ts +114 -0
- package/node_modules/zod/src/v4/locales/ua.ts +7 -0
- package/node_modules/zod/src/v4/locales/uk.ts +120 -0
- package/node_modules/zod/src/v4/locales/ur.ts +122 -0
- package/node_modules/zod/src/v4/locales/uz.ts +118 -0
- package/node_modules/zod/src/v4/locales/vi.ts +120 -0
- package/node_modules/zod/src/v4/locales/yo.ts +127 -0
- package/node_modules/zod/src/v4/locales/zh-CN.ts +119 -0
- package/node_modules/zod/src/v4/locales/zh-TW.ts +118 -0
- package/node_modules/zod/src/v4/mini/checks.ts +33 -0
- package/node_modules/zod/src/v4/mini/coerce.ts +27 -0
- package/node_modules/zod/src/v4/mini/deep-partial.ts +73 -0
- package/node_modules/zod/src/v4/mini/external.ts +50 -0
- package/node_modules/zod/src/v4/mini/in-out.ts +45 -0
- package/node_modules/zod/src/v4/mini/index.ts +3 -0
- package/node_modules/zod/src/v4/mini/iso.ts +66 -0
- package/node_modules/zod/src/v4/mini/parse.ts +16 -0
- package/node_modules/zod/src/v4/mini/schemas.ts +2026 -0
- package/node_modules/zod/src/v4/mini/tests/apply.test.ts +57 -0
- package/node_modules/zod/src/v4/mini/tests/assignability.test.ts +190 -0
- package/node_modules/zod/src/v4/mini/tests/brand.test.ts +94 -0
- package/node_modules/zod/src/v4/mini/tests/checks.test.ts +158 -0
- package/node_modules/zod/src/v4/mini/tests/codec.test.ts +582 -0
- package/node_modules/zod/src/v4/mini/tests/computed.test.ts +36 -0
- package/node_modules/zod/src/v4/mini/tests/cyclic-data.test.ts +84 -0
- package/node_modules/zod/src/v4/mini/tests/deep-partial.test.ts +54 -0
- package/node_modules/zod/src/v4/mini/tests/error.test.ts +41 -0
- package/node_modules/zod/src/v4/mini/tests/functions.test.ts +14 -0
- package/node_modules/zod/src/v4/mini/tests/index.test.ts +1060 -0
- package/node_modules/zod/src/v4/mini/tests/number.test.ts +109 -0
- package/node_modules/zod/src/v4/mini/tests/object.test.ts +292 -0
- package/node_modules/zod/src/v4/mini/tests/prototypes.test.ts +43 -0
- package/node_modules/zod/src/v4/mini/tests/recursive-types.test.ts +325 -0
- package/node_modules/zod/src/v4/mini/tests/standard-schema.test.ts +50 -0
- package/node_modules/zod/src/v4/mini/tests/string.test.ts +373 -0
- package/node_modules/zod/src/v4-mini/index.ts +3 -0
- package/node_modules/zod/v3/ZodError.cjs +148 -0
- package/node_modules/zod/v3/ZodError.d.cts +164 -0
- package/node_modules/zod/v3/ZodError.d.ts +164 -0
- package/node_modules/zod/v3/ZodError.js +143 -0
- package/node_modules/zod/v3/errors.cjs +17 -0
- package/node_modules/zod/v3/errors.d.cts +5 -0
- package/node_modules/zod/v3/errors.d.ts +5 -0
- package/node_modules/zod/v3/errors.js +9 -0
- package/node_modules/zod/v3/external.cjs +22 -0
- package/node_modules/zod/v3/external.d.cts +6 -0
- package/node_modules/zod/v3/external.d.ts +6 -0
- package/node_modules/zod/v3/external.js +6 -0
- package/node_modules/zod/v3/helpers/enumUtil.cjs +2 -0
- package/node_modules/zod/v3/helpers/enumUtil.d.cts +8 -0
- package/node_modules/zod/v3/helpers/enumUtil.d.ts +8 -0
- package/node_modules/zod/v3/helpers/enumUtil.js +1 -0
- package/node_modules/zod/v3/helpers/errorUtil.cjs +9 -0
- package/node_modules/zod/v3/helpers/errorUtil.d.cts +9 -0
- package/node_modules/zod/v3/helpers/errorUtil.d.ts +9 -0
- package/node_modules/zod/v3/helpers/errorUtil.js +6 -0
- package/node_modules/zod/v3/helpers/parseUtil.cjs +124 -0
- package/node_modules/zod/v3/helpers/parseUtil.d.cts +78 -0
- package/node_modules/zod/v3/helpers/parseUtil.d.ts +78 -0
- package/node_modules/zod/v3/helpers/parseUtil.js +109 -0
- package/node_modules/zod/v3/helpers/partialUtil.cjs +2 -0
- package/node_modules/zod/v3/helpers/partialUtil.d.cts +8 -0
- package/node_modules/zod/v3/helpers/partialUtil.d.ts +8 -0
- package/node_modules/zod/v3/helpers/partialUtil.js +1 -0
- package/node_modules/zod/v3/helpers/typeAliases.cjs +2 -0
- package/node_modules/zod/v3/helpers/typeAliases.d.cts +2 -0
- package/node_modules/zod/v3/helpers/typeAliases.d.ts +2 -0
- package/node_modules/zod/v3/helpers/typeAliases.js +1 -0
- package/node_modules/zod/v3/helpers/util.cjs +137 -0
- package/node_modules/zod/v3/helpers/util.d.cts +85 -0
- package/node_modules/zod/v3/helpers/util.d.ts +85 -0
- package/node_modules/zod/v3/helpers/util.js +133 -0
- package/node_modules/zod/v3/index.cjs +33 -0
- package/node_modules/zod/v3/index.d.cts +4 -0
- package/node_modules/zod/v3/index.d.ts +4 -0
- package/node_modules/zod/v3/index.js +4 -0
- package/node_modules/zod/v3/locales/en.cjs +112 -0
- package/node_modules/zod/v3/locales/en.d.cts +3 -0
- package/node_modules/zod/v3/locales/en.d.ts +3 -0
- package/node_modules/zod/v3/locales/en.js +109 -0
- package/node_modules/zod/v3/package.json +7 -0
- package/node_modules/zod/v3/standard-schema.cjs +2 -0
- package/node_modules/zod/v3/standard-schema.d.cts +102 -0
- package/node_modules/zod/v3/standard-schema.d.ts +102 -0
- package/node_modules/zod/v3/standard-schema.js +1 -0
- package/node_modules/zod/v3/types.cjs +3779 -0
- package/node_modules/zod/v3/types.d.cts +1034 -0
- package/node_modules/zod/v3/types.d.ts +1034 -0
- package/node_modules/zod/v3/types.js +3697 -0
- package/node_modules/zod/v4/classic/checks.cjs +34 -0
- package/node_modules/zod/v4/classic/checks.d.cts +1 -0
- package/node_modules/zod/v4/classic/checks.d.ts +1 -0
- package/node_modules/zod/v4/classic/checks.js +1 -0
- package/node_modules/zod/v4/classic/coerce.cjs +47 -0
- package/node_modules/zod/v4/classic/coerce.d.cts +17 -0
- package/node_modules/zod/v4/classic/coerce.d.ts +17 -0
- package/node_modules/zod/v4/classic/coerce.js +17 -0
- package/node_modules/zod/v4/classic/compat.cjs +61 -0
- package/node_modules/zod/v4/classic/compat.d.cts +48 -0
- package/node_modules/zod/v4/classic/compat.d.ts +48 -0
- package/node_modules/zod/v4/classic/compat.js +31 -0
- package/node_modules/zod/v4/classic/deep-partial.cjs +39 -0
- package/node_modules/zod/v4/classic/deep-partial.d.cts +14 -0
- package/node_modules/zod/v4/classic/deep-partial.d.ts +14 -0
- package/node_modules/zod/v4/classic/deep-partial.js +13 -0
- package/node_modules/zod/v4/classic/errors.cjs +83 -0
- package/node_modules/zod/v4/classic/errors.d.cts +29 -0
- package/node_modules/zod/v4/classic/errors.d.ts +29 -0
- package/node_modules/zod/v4/classic/errors.js +57 -0
- package/node_modules/zod/v4/classic/external.cjs +76 -0
- package/node_modules/zod/v4/classic/external.d.cts +19 -0
- package/node_modules/zod/v4/classic/external.d.ts +19 -0
- package/node_modules/zod/v4/classic/external.js +17 -0
- package/node_modules/zod/v4/classic/from-json-schema.cjs +686 -0
- package/node_modules/zod/v4/classic/from-json-schema.d.cts +12 -0
- package/node_modules/zod/v4/classic/from-json-schema.d.ts +12 -0
- package/node_modules/zod/v4/classic/from-json-schema.js +660 -0
- package/node_modules/zod/v4/classic/in-out.cjs +63 -0
- package/node_modules/zod/v4/classic/in-out.d.cts +8 -0
- package/node_modules/zod/v4/classic/in-out.d.ts +8 -0
- package/node_modules/zod/v4/classic/in-out.js +36 -0
- package/node_modules/zod/v4/classic/index.cjs +33 -0
- package/node_modules/zod/v4/classic/index.d.cts +3 -0
- package/node_modules/zod/v4/classic/index.d.ts +3 -0
- package/node_modules/zod/v4/classic/index.js +4 -0
- package/node_modules/zod/v4/classic/iso.cjs +49 -0
- package/node_modules/zod/v4/classic/iso.d.cts +7 -0
- package/node_modules/zod/v4/classic/iso.d.ts +7 -0
- package/node_modules/zod/v4/classic/iso.js +15 -0
- package/node_modules/zod/v4/classic/package.json +7 -0
- package/node_modules/zod/v4/classic/parse.cjs +44 -0
- package/node_modules/zod/v4/classic/parse.d.cts +44 -0
- package/node_modules/zod/v4/classic/parse.d.ts +44 -0
- package/node_modules/zod/v4/classic/parse.js +16 -0
- package/node_modules/zod/v4/classic/schemas.cjs +1611 -0
- package/node_modules/zod/v4/classic/schemas.d.cts +802 -0
- package/node_modules/zod/v4/classic/schemas.d.ts +802 -0
- package/node_modules/zod/v4/classic/schemas.js +1491 -0
- package/node_modules/zod/v4/core/api.cjs +1246 -0
- package/node_modules/zod/v4/core/api.d.cts +329 -0
- package/node_modules/zod/v4/core/api.d.ts +329 -0
- package/node_modules/zod/v4/core/api.js +1104 -0
- package/node_modules/zod/v4/core/checks.cjs +607 -0
- package/node_modules/zod/v4/core/checks.d.cts +278 -0
- package/node_modules/zod/v4/core/checks.d.ts +278 -0
- package/node_modules/zod/v4/core/checks.js +581 -0
- package/node_modules/zod/v4/core/compile.cjs +1813 -0
- package/node_modules/zod/v4/core/compile.d.cts +51 -0
- package/node_modules/zod/v4/core/compile.d.ts +51 -0
- package/node_modules/zod/v4/core/compile.js +1783 -0
- package/node_modules/zod/v4/core/core.cjs +148 -0
- package/node_modules/zod/v4/core/core.d.cts +82 -0
- package/node_modules/zod/v4/core/core.d.ts +82 -0
- package/node_modules/zod/v4/core/core.js +141 -0
- package/node_modules/zod/v4/core/doc.cjs +37 -0
- package/node_modules/zod/v4/core/doc.d.cts +16 -0
- package/node_modules/zod/v4/core/doc.d.ts +16 -0
- package/node_modules/zod/v4/core/doc.js +33 -0
- package/node_modules/zod/v4/core/errors.cjs +301 -0
- package/node_modules/zod/v4/core/errors.d.cts +225 -0
- package/node_modules/zod/v4/core/errors.d.ts +225 -0
- package/node_modules/zod/v4/core/errors.js +270 -0
- package/node_modules/zod/v4/core/index.cjs +51 -0
- package/node_modules/zod/v4/core/index.d.cts +19 -0
- package/node_modules/zod/v4/core/index.d.ts +19 -0
- package/node_modules/zod/v4/core/index.js +19 -0
- package/node_modules/zod/v4/core/json-schema-generator.cjs +103 -0
- package/node_modules/zod/v4/core/json-schema-generator.d.cts +65 -0
- package/node_modules/zod/v4/core/json-schema-generator.d.ts +65 -0
- package/node_modules/zod/v4/core/json-schema-generator.js +99 -0
- package/node_modules/zod/v4/core/json-schema-processors.cjs +813 -0
- package/node_modules/zod/v4/core/json-schema-processors.d.cts +49 -0
- package/node_modules/zod/v4/core/json-schema-processors.d.ts +49 -0
- package/node_modules/zod/v4/core/json-schema-processors.js +747 -0
- package/node_modules/zod/v4/core/json-schema.cjs +2 -0
- package/node_modules/zod/v4/core/json-schema.d.cts +89 -0
- package/node_modules/zod/v4/core/json-schema.d.ts +89 -0
- package/node_modules/zod/v4/core/json-schema.js +1 -0
- package/node_modules/zod/v4/core/memoizer.cjs +272 -0
- package/node_modules/zod/v4/core/memoizer.d.cts +15 -0
- package/node_modules/zod/v4/core/memoizer.d.ts +15 -0
- package/node_modules/zod/v4/core/memoizer.js +265 -0
- package/node_modules/zod/v4/core/package.json +7 -0
- package/node_modules/zod/v4/core/parse.cjs +193 -0
- package/node_modules/zod/v4/core/parse.d.cts +52 -0
- package/node_modules/zod/v4/core/parse.d.ts +52 -0
- package/node_modules/zod/v4/core/parse.js +154 -0
- package/node_modules/zod/v4/core/regexes.cjs +184 -0
- package/node_modules/zod/v4/core/regexes.d.cts +87 -0
- package/node_modules/zod/v4/core/regexes.d.ts +87 -0
- package/node_modules/zod/v4/core/regexes.js +150 -0
- package/node_modules/zod/v4/core/registries.cjs +56 -0
- package/node_modules/zod/v4/core/registries.d.cts +35 -0
- package/node_modules/zod/v4/core/registries.d.ts +35 -0
- package/node_modules/zod/v4/core/registries.js +51 -0
- package/node_modules/zod/v4/core/schemas.cjs +2481 -0
- package/node_modules/zod/v4/core/schemas.d.cts +1253 -0
- package/node_modules/zod/v4/core/schemas.d.ts +1253 -0
- package/node_modules/zod/v4/core/schemas.js +2440 -0
- package/node_modules/zod/v4/core/standard-schema.cjs +2 -0
- package/node_modules/zod/v4/core/standard-schema.d.cts +126 -0
- package/node_modules/zod/v4/core/standard-schema.d.ts +126 -0
- package/node_modules/zod/v4/core/standard-schema.js +1 -0
- package/node_modules/zod/v4/core/to-json-schema.cjs +660 -0
- package/node_modules/zod/v4/core/to-json-schema.d.cts +153 -0
- package/node_modules/zod/v4/core/to-json-schema.d.ts +153 -0
- package/node_modules/zod/v4/core/to-json-schema.js +650 -0
- package/node_modules/zod/v4/core/util.cjs +915 -0
- package/node_modules/zod/v4/core/util.d.cts +257 -0
- package/node_modules/zod/v4/core/util.d.ts +257 -0
- package/node_modules/zod/v4/core/util.js +846 -0
- package/node_modules/zod/v4/core/versions.cjs +8 -0
- package/node_modules/zod/v4/core/versions.d.cts +5 -0
- package/node_modules/zod/v4/core/versions.d.ts +5 -0
- package/node_modules/zod/v4/core/versions.js +5 -0
- package/node_modules/zod/v4/core/visit.cjs +195 -0
- package/node_modules/zod/v4/core/visit.d.cts +30 -0
- package/node_modules/zod/v4/core/visit.d.ts +30 -0
- package/node_modules/zod/v4/core/visit.js +169 -0
- package/node_modules/zod/v4/index.cjs +32 -0
- package/node_modules/zod/v4/index.d.cts +3 -0
- package/node_modules/zod/v4/index.d.ts +3 -0
- package/node_modules/zod/v4/index.js +4 -0
- package/node_modules/zod/v4/locales/ar.cjs +136 -0
- package/node_modules/zod/v4/locales/ar.d.cts +5 -0
- package/node_modules/zod/v4/locales/ar.d.ts +4 -0
- package/node_modules/zod/v4/locales/ar.js +109 -0
- package/node_modules/zod/v4/locales/az.cjs +135 -0
- package/node_modules/zod/v4/locales/az.d.cts +5 -0
- package/node_modules/zod/v4/locales/az.d.ts +4 -0
- package/node_modules/zod/v4/locales/az.js +108 -0
- package/node_modules/zod/v4/locales/be.cjs +193 -0
- package/node_modules/zod/v4/locales/be.d.cts +5 -0
- package/node_modules/zod/v4/locales/be.d.ts +4 -0
- package/node_modules/zod/v4/locales/be.js +166 -0
- package/node_modules/zod/v4/locales/bg.cjs +150 -0
- package/node_modules/zod/v4/locales/bg.d.cts +5 -0
- package/node_modules/zod/v4/locales/bg.d.ts +4 -0
- package/node_modules/zod/v4/locales/bg.js +123 -0
- package/node_modules/zod/v4/locales/bn.cjs +138 -0
- package/node_modules/zod/v4/locales/bn.d.cts +5 -0
- package/node_modules/zod/v4/locales/bn.d.ts +4 -0
- package/node_modules/zod/v4/locales/bn.js +111 -0
- package/node_modules/zod/v4/locales/ca.cjs +137 -0
- package/node_modules/zod/v4/locales/ca.d.cts +5 -0
- package/node_modules/zod/v4/locales/ca.d.ts +4 -0
- package/node_modules/zod/v4/locales/ca.js +110 -0
- package/node_modules/zod/v4/locales/ckb.cjs +158 -0
- package/node_modules/zod/v4/locales/ckb.d.cts +5 -0
- package/node_modules/zod/v4/locales/ckb.d.ts +4 -0
- package/node_modules/zod/v4/locales/ckb.js +131 -0
- package/node_modules/zod/v4/locales/cs.cjs +141 -0
- package/node_modules/zod/v4/locales/cs.d.cts +5 -0
- package/node_modules/zod/v4/locales/cs.d.ts +4 -0
- package/node_modules/zod/v4/locales/cs.js +114 -0
- package/node_modules/zod/v4/locales/da.cjs +145 -0
- package/node_modules/zod/v4/locales/da.d.cts +5 -0
- package/node_modules/zod/v4/locales/da.d.ts +4 -0
- package/node_modules/zod/v4/locales/da.js +118 -0
- package/node_modules/zod/v4/locales/de.cjs +138 -0
- package/node_modules/zod/v4/locales/de.d.cts +5 -0
- package/node_modules/zod/v4/locales/de.d.ts +4 -0
- package/node_modules/zod/v4/locales/de.js +111 -0
- package/node_modules/zod/v4/locales/el.cjs +137 -0
- package/node_modules/zod/v4/locales/el.d.cts +5 -0
- package/node_modules/zod/v4/locales/el.d.ts +4 -0
- package/node_modules/zod/v4/locales/el.js +110 -0
- package/node_modules/zod/v4/locales/en.cjs +150 -0
- package/node_modules/zod/v4/locales/en.d.cts +5 -0
- package/node_modules/zod/v4/locales/en.d.ts +4 -0
- package/node_modules/zod/v4/locales/en.js +123 -0
- package/node_modules/zod/v4/locales/eo.cjs +139 -0
- package/node_modules/zod/v4/locales/eo.d.cts +5 -0
- package/node_modules/zod/v4/locales/eo.d.ts +4 -0
- package/node_modules/zod/v4/locales/eo.js +112 -0
- package/node_modules/zod/v4/locales/es.cjs +161 -0
- package/node_modules/zod/v4/locales/es.d.cts +5 -0
- package/node_modules/zod/v4/locales/es.d.ts +4 -0
- package/node_modules/zod/v4/locales/es.js +134 -0
- package/node_modules/zod/v4/locales/fa.cjs +144 -0
- package/node_modules/zod/v4/locales/fa.d.cts +5 -0
- package/node_modules/zod/v4/locales/fa.d.ts +4 -0
- package/node_modules/zod/v4/locales/fa.js +117 -0
- package/node_modules/zod/v4/locales/fi.cjs +142 -0
- package/node_modules/zod/v4/locales/fi.d.cts +5 -0
- package/node_modules/zod/v4/locales/fi.d.ts +4 -0
- package/node_modules/zod/v4/locales/fi.js +115 -0
- package/node_modules/zod/v4/locales/fr-CA.cjs +137 -0
- package/node_modules/zod/v4/locales/fr-CA.d.cts +5 -0
- package/node_modules/zod/v4/locales/fr-CA.d.ts +4 -0
- package/node_modules/zod/v4/locales/fr-CA.js +110 -0
- package/node_modules/zod/v4/locales/fr.cjs +154 -0
- package/node_modules/zod/v4/locales/fr.d.cts +5 -0
- package/node_modules/zod/v4/locales/fr.d.ts +4 -0
- package/node_modules/zod/v4/locales/fr.js +127 -0
- package/node_modules/zod/v4/locales/gu.cjs +138 -0
- package/node_modules/zod/v4/locales/gu.d.cts +5 -0
- package/node_modules/zod/v4/locales/gu.d.ts +4 -0
- package/node_modules/zod/v4/locales/gu.js +111 -0
- package/node_modules/zod/v4/locales/he.cjs +246 -0
- package/node_modules/zod/v4/locales/he.d.cts +5 -0
- package/node_modules/zod/v4/locales/he.d.ts +4 -0
- package/node_modules/zod/v4/locales/he.js +219 -0
- package/node_modules/zod/v4/locales/hi.cjs +136 -0
- package/node_modules/zod/v4/locales/hi.d.cts +5 -0
- package/node_modules/zod/v4/locales/hi.d.ts +4 -0
- package/node_modules/zod/v4/locales/hi.js +109 -0
- package/node_modules/zod/v4/locales/hr.cjs +151 -0
- package/node_modules/zod/v4/locales/hr.d.cts +5 -0
- package/node_modules/zod/v4/locales/hr.d.ts +4 -0
- package/node_modules/zod/v4/locales/hr.js +124 -0
- package/node_modules/zod/v4/locales/hu.cjs +138 -0
- package/node_modules/zod/v4/locales/hu.d.cts +5 -0
- package/node_modules/zod/v4/locales/hu.d.ts +4 -0
- package/node_modules/zod/v4/locales/hu.js +111 -0
- package/node_modules/zod/v4/locales/hy.cjs +183 -0
- package/node_modules/zod/v4/locales/hy.d.cts +5 -0
- package/node_modules/zod/v4/locales/hy.d.ts +4 -0
- package/node_modules/zod/v4/locales/hy.js +156 -0
- package/node_modules/zod/v4/locales/id.cjs +136 -0
- package/node_modules/zod/v4/locales/id.d.cts +5 -0
- package/node_modules/zod/v4/locales/id.d.ts +4 -0
- package/node_modules/zod/v4/locales/id.js +109 -0
- package/node_modules/zod/v4/locales/index.cjs +131 -0
- package/node_modules/zod/v4/locales/index.d.cts +62 -0
- package/node_modules/zod/v4/locales/index.d.ts +62 -0
- package/node_modules/zod/v4/locales/index.js +62 -0
- package/node_modules/zod/v4/locales/is.cjs +139 -0
- package/node_modules/zod/v4/locales/is.d.cts +5 -0
- package/node_modules/zod/v4/locales/is.d.ts +4 -0
- package/node_modules/zod/v4/locales/is.js +112 -0
- package/node_modules/zod/v4/locales/it.cjs +138 -0
- package/node_modules/zod/v4/locales/it.d.cts +5 -0
- package/node_modules/zod/v4/locales/it.d.ts +4 -0
- package/node_modules/zod/v4/locales/it.js +111 -0
- package/node_modules/zod/v4/locales/ja.cjs +137 -0
- package/node_modules/zod/v4/locales/ja.d.cts +5 -0
- package/node_modules/zod/v4/locales/ja.d.ts +4 -0
- package/node_modules/zod/v4/locales/ja.js +110 -0
- package/node_modules/zod/v4/locales/ka.cjs +142 -0
- package/node_modules/zod/v4/locales/ka.d.cts +5 -0
- package/node_modules/zod/v4/locales/ka.d.ts +4 -0
- package/node_modules/zod/v4/locales/ka.js +115 -0
- package/node_modules/zod/v4/locales/kh.cjs +12 -0
- package/node_modules/zod/v4/locales/kh.d.cts +5 -0
- package/node_modules/zod/v4/locales/kh.d.ts +5 -0
- package/node_modules/zod/v4/locales/kh.js +5 -0
- package/node_modules/zod/v4/locales/km.cjs +140 -0
- package/node_modules/zod/v4/locales/km.d.cts +5 -0
- package/node_modules/zod/v4/locales/km.d.ts +4 -0
- package/node_modules/zod/v4/locales/km.js +113 -0
- package/node_modules/zod/v4/locales/kn.cjs +141 -0
- package/node_modules/zod/v4/locales/kn.d.cts +5 -0
- package/node_modules/zod/v4/locales/kn.d.ts +4 -0
- package/node_modules/zod/v4/locales/kn.js +114 -0
- package/node_modules/zod/v4/locales/ko.cjs +141 -0
- package/node_modules/zod/v4/locales/ko.d.cts +5 -0
- package/node_modules/zod/v4/locales/ko.d.ts +4 -0
- package/node_modules/zod/v4/locales/ko.js +114 -0
- package/node_modules/zod/v4/locales/lt.cjs +232 -0
- package/node_modules/zod/v4/locales/lt.d.cts +5 -0
- package/node_modules/zod/v4/locales/lt.d.ts +4 -0
- package/node_modules/zod/v4/locales/lt.js +205 -0
- package/node_modules/zod/v4/locales/mk.cjs +139 -0
- package/node_modules/zod/v4/locales/mk.d.cts +5 -0
- package/node_modules/zod/v4/locales/mk.d.ts +4 -0
- package/node_modules/zod/v4/locales/mk.js +112 -0
- package/node_modules/zod/v4/locales/ms.cjs +137 -0
- package/node_modules/zod/v4/locales/ms.d.cts +5 -0
- package/node_modules/zod/v4/locales/ms.d.ts +4 -0
- package/node_modules/zod/v4/locales/ms.js +110 -0
- package/node_modules/zod/v4/locales/ne.cjs +136 -0
- package/node_modules/zod/v4/locales/ne.d.cts +5 -0
- package/node_modules/zod/v4/locales/ne.d.ts +4 -0
- package/node_modules/zod/v4/locales/ne.js +109 -0
- package/node_modules/zod/v4/locales/nl.cjs +140 -0
- package/node_modules/zod/v4/locales/nl.d.cts +5 -0
- package/node_modules/zod/v4/locales/nl.d.ts +4 -0
- package/node_modules/zod/v4/locales/nl.js +113 -0
- package/node_modules/zod/v4/locales/nn.cjs +138 -0
- package/node_modules/zod/v4/locales/nn.d.cts +5 -0
- package/node_modules/zod/v4/locales/nn.d.ts +4 -0
- package/node_modules/zod/v4/locales/nn.js +111 -0
- package/node_modules/zod/v4/locales/no.cjs +138 -0
- package/node_modules/zod/v4/locales/no.d.cts +5 -0
- package/node_modules/zod/v4/locales/no.d.ts +4 -0
- package/node_modules/zod/v4/locales/no.js +111 -0
- package/node_modules/zod/v4/locales/ota.cjs +139 -0
- package/node_modules/zod/v4/locales/ota.d.cts +5 -0
- package/node_modules/zod/v4/locales/ota.d.ts +4 -0
- package/node_modules/zod/v4/locales/ota.js +112 -0
- package/node_modules/zod/v4/locales/package.json +7 -0
- package/node_modules/zod/v4/locales/pl.cjs +139 -0
- package/node_modules/zod/v4/locales/pl.d.cts +5 -0
- package/node_modules/zod/v4/locales/pl.d.ts +4 -0
- package/node_modules/zod/v4/locales/pl.js +112 -0
- package/node_modules/zod/v4/locales/ps.cjs +144 -0
- package/node_modules/zod/v4/locales/ps.d.cts +5 -0
- package/node_modules/zod/v4/locales/ps.d.ts +4 -0
- package/node_modules/zod/v4/locales/ps.js +117 -0
- package/node_modules/zod/v4/locales/pt-BR.cjs +168 -0
- package/node_modules/zod/v4/locales/pt-BR.d.cts +5 -0
- package/node_modules/zod/v4/locales/pt-BR.d.ts +4 -0
- package/node_modules/zod/v4/locales/pt-BR.js +141 -0
- package/node_modules/zod/v4/locales/pt.cjs +167 -0
- package/node_modules/zod/v4/locales/pt.d.cts +5 -0
- package/node_modules/zod/v4/locales/pt.d.ts +4 -0
- package/node_modules/zod/v4/locales/pt.js +140 -0
- package/node_modules/zod/v4/locales/ro.cjs +147 -0
- package/node_modules/zod/v4/locales/ro.d.cts +5 -0
- package/node_modules/zod/v4/locales/ro.d.ts +4 -0
- package/node_modules/zod/v4/locales/ro.js +120 -0
- package/node_modules/zod/v4/locales/ru.cjs +193 -0
- package/node_modules/zod/v4/locales/ru.d.cts +5 -0
- package/node_modules/zod/v4/locales/ru.d.ts +4 -0
- package/node_modules/zod/v4/locales/ru.js +166 -0
- package/node_modules/zod/v4/locales/sk.cjs +141 -0
- package/node_modules/zod/v4/locales/sk.d.cts +5 -0
- package/node_modules/zod/v4/locales/sk.d.ts +4 -0
- package/node_modules/zod/v4/locales/sk.js +114 -0
- package/node_modules/zod/v4/locales/sl.cjs +139 -0
- package/node_modules/zod/v4/locales/sl.d.cts +5 -0
- package/node_modules/zod/v4/locales/sl.d.ts +4 -0
- package/node_modules/zod/v4/locales/sl.js +112 -0
- package/node_modules/zod/v4/locales/sv.cjs +140 -0
- package/node_modules/zod/v4/locales/sv.d.cts +5 -0
- package/node_modules/zod/v4/locales/sv.d.ts +4 -0
- package/node_modules/zod/v4/locales/sv.js +113 -0
- package/node_modules/zod/v4/locales/ta.cjs +140 -0
- package/node_modules/zod/v4/locales/ta.d.cts +5 -0
- package/node_modules/zod/v4/locales/ta.d.ts +4 -0
- package/node_modules/zod/v4/locales/ta.js +113 -0
- package/node_modules/zod/v4/locales/th.cjs +140 -0
- package/node_modules/zod/v4/locales/th.d.cts +5 -0
- package/node_modules/zod/v4/locales/th.d.ts +4 -0
- package/node_modules/zod/v4/locales/th.js +113 -0
- package/node_modules/zod/v4/locales/tk.cjs +132 -0
- package/node_modules/zod/v4/locales/tk.d.cts +5 -0
- package/node_modules/zod/v4/locales/tk.d.ts +4 -0
- package/node_modules/zod/v4/locales/tk.js +105 -0
- package/node_modules/zod/v4/locales/tr.cjs +135 -0
- package/node_modules/zod/v4/locales/tr.d.cts +5 -0
- package/node_modules/zod/v4/locales/tr.d.ts +4 -0
- package/node_modules/zod/v4/locales/tr.js +108 -0
- package/node_modules/zod/v4/locales/ua.cjs +12 -0
- package/node_modules/zod/v4/locales/ua.d.cts +5 -0
- package/node_modules/zod/v4/locales/ua.d.ts +5 -0
- package/node_modules/zod/v4/locales/ua.js +5 -0
- package/node_modules/zod/v4/locales/uk.cjs +138 -0
- package/node_modules/zod/v4/locales/uk.d.cts +5 -0
- package/node_modules/zod/v4/locales/uk.d.ts +4 -0
- package/node_modules/zod/v4/locales/uk.js +111 -0
- package/node_modules/zod/v4/locales/ur.cjs +140 -0
- package/node_modules/zod/v4/locales/ur.d.cts +5 -0
- package/node_modules/zod/v4/locales/ur.d.ts +4 -0
- package/node_modules/zod/v4/locales/ur.js +113 -0
- package/node_modules/zod/v4/locales/uz.cjs +138 -0
- package/node_modules/zod/v4/locales/uz.d.cts +5 -0
- package/node_modules/zod/v4/locales/uz.d.ts +4 -0
- package/node_modules/zod/v4/locales/uz.js +111 -0
- package/node_modules/zod/v4/locales/vi.cjs +138 -0
- package/node_modules/zod/v4/locales/vi.d.cts +5 -0
- package/node_modules/zod/v4/locales/vi.d.ts +4 -0
- package/node_modules/zod/v4/locales/vi.js +111 -0
- package/node_modules/zod/v4/locales/yo.cjs +137 -0
- package/node_modules/zod/v4/locales/yo.d.cts +5 -0
- package/node_modules/zod/v4/locales/yo.d.ts +4 -0
- package/node_modules/zod/v4/locales/yo.js +110 -0
- package/node_modules/zod/v4/locales/zh-CN.cjs +139 -0
- package/node_modules/zod/v4/locales/zh-CN.d.cts +5 -0
- package/node_modules/zod/v4/locales/zh-CN.d.ts +4 -0
- package/node_modules/zod/v4/locales/zh-CN.js +112 -0
- package/node_modules/zod/v4/locales/zh-TW.cjs +137 -0
- package/node_modules/zod/v4/locales/zh-TW.d.cts +5 -0
- package/node_modules/zod/v4/locales/zh-TW.d.ts +4 -0
- package/node_modules/zod/v4/locales/zh-TW.js +110 -0
- package/node_modules/zod/v4/mini/checks.cjs +35 -0
- package/node_modules/zod/v4/mini/checks.d.cts +1 -0
- package/node_modules/zod/v4/mini/checks.d.ts +1 -0
- package/node_modules/zod/v4/mini/checks.js +1 -0
- package/node_modules/zod/v4/mini/coerce.cjs +52 -0
- package/node_modules/zod/v4/mini/coerce.d.cts +7 -0
- package/node_modules/zod/v4/mini/coerce.d.ts +7 -0
- package/node_modules/zod/v4/mini/coerce.js +22 -0
- package/node_modules/zod/v4/mini/deep-partial.cjs +39 -0
- package/node_modules/zod/v4/mini/deep-partial.d.cts +14 -0
- package/node_modules/zod/v4/mini/deep-partial.d.ts +14 -0
- package/node_modules/zod/v4/mini/deep-partial.js +13 -0
- package/node_modules/zod/v4/mini/external.cjs +74 -0
- package/node_modules/zod/v4/mini/external.d.cts +16 -0
- package/node_modules/zod/v4/mini/external.d.ts +16 -0
- package/node_modules/zod/v4/mini/external.js +16 -0
- package/node_modules/zod/v4/mini/in-out.cjs +63 -0
- package/node_modules/zod/v4/mini/in-out.d.cts +8 -0
- package/node_modules/zod/v4/mini/in-out.d.ts +8 -0
- package/node_modules/zod/v4/mini/in-out.js +36 -0
- package/node_modules/zod/v4/mini/index.cjs +32 -0
- package/node_modules/zod/v4/mini/index.d.cts +3 -0
- package/node_modules/zod/v4/mini/index.d.ts +3 -0
- package/node_modules/zod/v4/mini/index.js +3 -0
- package/node_modules/zod/v4/mini/iso.cjs +64 -0
- package/node_modules/zod/v4/mini/iso.d.cts +22 -0
- package/node_modules/zod/v4/mini/iso.d.ts +22 -0
- package/node_modules/zod/v4/mini/iso.js +34 -0
- package/node_modules/zod/v4/mini/package.json +7 -0
- package/node_modules/zod/v4/mini/parse.cjs +18 -0
- package/node_modules/zod/v4/mini/parse.d.cts +1 -0
- package/node_modules/zod/v4/mini/parse.d.ts +1 -0
- package/node_modules/zod/v4/mini/parse.js +1 -0
- package/node_modules/zod/v4/mini/schemas.cjs +1111 -0
- package/node_modules/zod/v4/mini/schemas.d.cts +475 -0
- package/node_modules/zod/v4/mini/schemas.d.ts +475 -0
- package/node_modules/zod/v4/mini/schemas.js +987 -0
- package/node_modules/zod/v4/package.json +7 -0
- package/node_modules/zod/v4-mini/index.cjs +32 -0
- package/node_modules/zod/v4-mini/index.d.cts +3 -0
- package/node_modules/zod/v4-mini/index.d.ts +3 -0
- package/node_modules/zod/v4-mini/index.js +3 -0
- package/node_modules/zod/v4-mini/package.json +7 -0
- package/oclif.manifest.json +88 -62
- package/package.json +17 -9
- package/content/pwav3/components.md +0 -400
- package/content/pwav3/config.md +0 -124
- package/content/pwav3/data-fetching.md +0 -213
- package/content/pwav3/extensibility.md +0 -167
- package/content/pwav3/i18n.md +0 -214
- package/content/pwav3/quick-reference.md +0 -169
- package/content/pwav3/routing.md +0 -107
- package/content/pwav3/state-management.md +0 -193
- package/content/pwav3/styling.md +0 -248
- package/content/pwav3/testing.md +0 -124
- package/content/site-theming/theming-accessibility.md +0 -126
- package/content/site-theming/theming-questions.md +0 -208
- package/content/site-theming/theming-validation.md +0 -174
- package/dist/tools/diagnostics/debug-continue.js +0 -27
- package/dist/tools/diagnostics/debug-get-stack.d.ts +0 -4
- package/dist/tools/diagnostics/debug-get-stack.js +0 -31
- package/dist/tools/diagnostics/debug-get-variables.d.ts +0 -4
- package/dist/tools/diagnostics/debug-get-variables.js +0 -45
- package/dist/tools/diagnostics/debug-step.js +0 -38
- package/dist/tools/diagnostics/logs-watch-list.d.ts +0 -4
- package/dist/tools/diagnostics/logs-watch-list.js +0 -37
- package/dist/tools/diagnostics/logs-watch-stop.d.ts +0 -4
- package/dist/tools/diagnostics/logs-watch-stop.js +0 -36
- package/dist/tools/diagnostics/mrt-logs-watch-list.d.ts +0 -4
- package/dist/tools/diagnostics/mrt-logs-watch-list.js +0 -37
- package/dist/tools/diagnostics/mrt-logs-watch-stop.d.ts +0 -4
- package/dist/tools/diagnostics/mrt-logs-watch-stop.js +0 -37
- package/dist/tools/pwav3/index.d.ts +0 -22
- package/dist/tools/pwav3/index.js +0 -20
- package/dist/tools/pwav3/pwa-kit-development-guidelines.d.ts +0 -9
- package/dist/tools/pwav3/pwa-kit-development-guidelines.js +0 -111
- package/dist/tools/scapi/scapi-custom-api-generate-scaffold.d.ts +0 -67
- package/dist/tools/scapi/scapi-custom-api-generate-scaffold.js +0 -204
|
@@ -0,0 +1,4537 @@
|
|
|
1
|
+
import { Validator } from "@seriousme/openapi-schema-validator";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
// import * as zCore from "zod/v4/core";
|
|
5
|
+
|
|
6
|
+
const openAPI30Validator = new Validator();
|
|
7
|
+
/** @see https://github.com/colinhacks/zod/issues/5147 */
|
|
8
|
+
const validateOpenAPI30Schema = async (zodJSONSchema: Record<string, unknown>): Promise<true> => {
|
|
9
|
+
const res = await openAPI30Validator.validate({
|
|
10
|
+
openapi: "3.0.0",
|
|
11
|
+
info: {
|
|
12
|
+
title: "SampleApi",
|
|
13
|
+
description: "Sample backend service",
|
|
14
|
+
version: "1.0.0",
|
|
15
|
+
},
|
|
16
|
+
components: { schemas: { test: zodJSONSchema } },
|
|
17
|
+
paths: {},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
if (!res.valid) {
|
|
21
|
+
// `console.error` should make `vitest` trow an unhandled error printing the validation messages in consoles
|
|
22
|
+
console.error(
|
|
23
|
+
`OpenAPI schema is not valid against ${openAPI30Validator.version}`,
|
|
24
|
+
JSON.stringify(res.errors, null, 2)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return true;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
describe("toJSONSchema", () => {
|
|
32
|
+
test("primitive types", () => {
|
|
33
|
+
expect(z.toJSONSchema(z.string())).toMatchInlineSnapshot(`
|
|
34
|
+
{
|
|
35
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
36
|
+
"type": "string",
|
|
37
|
+
}
|
|
38
|
+
`);
|
|
39
|
+
expect(z.toJSONSchema(z.number())).toMatchInlineSnapshot(`
|
|
40
|
+
{
|
|
41
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
42
|
+
"type": "number",
|
|
43
|
+
}
|
|
44
|
+
`);
|
|
45
|
+
expect(z.toJSONSchema(z.boolean())).toMatchInlineSnapshot(`
|
|
46
|
+
{
|
|
47
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
48
|
+
"type": "boolean",
|
|
49
|
+
}
|
|
50
|
+
`);
|
|
51
|
+
expect(z.toJSONSchema(z.null())).toMatchInlineSnapshot(`
|
|
52
|
+
{
|
|
53
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
54
|
+
"type": "null",
|
|
55
|
+
}
|
|
56
|
+
`);
|
|
57
|
+
expect(z.toJSONSchema(z.undefined(), { unrepresentable: "any" })).toMatchInlineSnapshot(`
|
|
58
|
+
{
|
|
59
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
60
|
+
}
|
|
61
|
+
`);
|
|
62
|
+
expect(z.toJSONSchema(z.any())).toMatchInlineSnapshot(`
|
|
63
|
+
{
|
|
64
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
65
|
+
}
|
|
66
|
+
`);
|
|
67
|
+
expect(z.toJSONSchema(z.unknown())).toMatchInlineSnapshot(`
|
|
68
|
+
{
|
|
69
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
70
|
+
}
|
|
71
|
+
`);
|
|
72
|
+
expect(z.toJSONSchema(z.never())).toMatchInlineSnapshot(`
|
|
73
|
+
{
|
|
74
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
75
|
+
"not": {},
|
|
76
|
+
}
|
|
77
|
+
`);
|
|
78
|
+
expect(z.toJSONSchema(z.email())).toMatchInlineSnapshot(`
|
|
79
|
+
{
|
|
80
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
81
|
+
"format": "email",
|
|
82
|
+
"pattern": "^(?!\\.)(?!.*\\.\\.)([A-Za-z0-9_'+\\-\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$",
|
|
83
|
+
"type": "string",
|
|
84
|
+
}
|
|
85
|
+
`);
|
|
86
|
+
expect(z.toJSONSchema(z.iso.datetime())).toMatchInlineSnapshot(`
|
|
87
|
+
{
|
|
88
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
89
|
+
"format": "date-time",
|
|
90
|
+
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$",
|
|
91
|
+
"type": "string",
|
|
92
|
+
}
|
|
93
|
+
`);
|
|
94
|
+
expect(z.toJSONSchema(z.iso.date())).toMatchInlineSnapshot(`
|
|
95
|
+
{
|
|
96
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
97
|
+
"format": "date",
|
|
98
|
+
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$",
|
|
99
|
+
"type": "string",
|
|
100
|
+
}
|
|
101
|
+
`);
|
|
102
|
+
// only shapes keeping both an offset and seconds may advertise `date-time`, composed onto a string as well as constructed
|
|
103
|
+
expect(z.toJSONSchema(z.iso.datetime()).format).toEqual("date-time");
|
|
104
|
+
expect(z.toJSONSchema(z.iso.datetime({ offset: true })).format).toEqual("date-time");
|
|
105
|
+
expect(z.toJSONSchema(z.iso.datetime({ precision: 0 })).format).toEqual("date-time");
|
|
106
|
+
expect(z.toJSONSchema(z.iso.datetime({ local: true })).format).toEqual(undefined);
|
|
107
|
+
expect(z.toJSONSchema(z.iso.datetime({ precision: -1 })).format).toEqual(undefined);
|
|
108
|
+
expect(z.toJSONSchema(z.string().check(z.iso.datetime({ local: true }))).format).toEqual(undefined);
|
|
109
|
+
expect(z.toJSONSchema(z.string().check(z.iso.datetime())).format).toEqual("date-time");
|
|
110
|
+
// the pattern still describes what the schema accepts
|
|
111
|
+
expect(z.toJSONSchema(z.iso.datetime({ local: true })).pattern).toBeDefined();
|
|
112
|
+
|
|
113
|
+
expect(z.toJSONSchema(z.iso.time())).toMatchInlineSnapshot(`
|
|
114
|
+
{
|
|
115
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
116
|
+
"pattern": "^(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?$",
|
|
117
|
+
"type": "string",
|
|
118
|
+
}
|
|
119
|
+
`);
|
|
120
|
+
expect(z.toJSONSchema(z.iso.time({ precision: -1 }))).toMatchInlineSnapshot(`
|
|
121
|
+
{
|
|
122
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
123
|
+
"pattern": "^(?:[01]\\d|2[0-3]):[0-5]\\d$",
|
|
124
|
+
"type": "string",
|
|
125
|
+
}
|
|
126
|
+
`);
|
|
127
|
+
expect(z.toJSONSchema(z.iso.time({ precision: 0 }))).toMatchInlineSnapshot(`
|
|
128
|
+
{
|
|
129
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
130
|
+
"pattern": "^(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d$",
|
|
131
|
+
"type": "string",
|
|
132
|
+
}
|
|
133
|
+
`);
|
|
134
|
+
expect(z.toJSONSchema(z.iso.time({ precision: 3 }))).toMatchInlineSnapshot(`
|
|
135
|
+
{
|
|
136
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
137
|
+
"pattern": "^(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d\\.\\d{3}$",
|
|
138
|
+
"type": "string",
|
|
139
|
+
}
|
|
140
|
+
`);
|
|
141
|
+
expect(z.toJSONSchema(z.iso.duration())).toMatchInlineSnapshot(`
|
|
142
|
+
{
|
|
143
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
144
|
+
"format": "duration",
|
|
145
|
+
"pattern": "^P(?:(\\d+W)|(?!.*W)(?=\\d|T\\d)(\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+([.,]\\d+)?S)?)?)$",
|
|
146
|
+
"type": "string",
|
|
147
|
+
}
|
|
148
|
+
`);
|
|
149
|
+
expect(z.toJSONSchema(z.ipv4())).toMatchInlineSnapshot(`
|
|
150
|
+
{
|
|
151
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
152
|
+
"format": "ipv4",
|
|
153
|
+
"pattern": "^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$",
|
|
154
|
+
"type": "string",
|
|
155
|
+
}
|
|
156
|
+
`);
|
|
157
|
+
expect(z.toJSONSchema(z.ipv6())).toMatchInlineSnapshot(`
|
|
158
|
+
{
|
|
159
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
160
|
+
"format": "ipv6",
|
|
161
|
+
"pattern": "^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$",
|
|
162
|
+
"type": "string",
|
|
163
|
+
}
|
|
164
|
+
`);
|
|
165
|
+
expect(z.toJSONSchema(z.mac())).toMatchInlineSnapshot(`
|
|
166
|
+
{
|
|
167
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
168
|
+
"format": "mac",
|
|
169
|
+
"pattern": "^(?:[0-9A-F]{2}:){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$",
|
|
170
|
+
"type": "string",
|
|
171
|
+
}
|
|
172
|
+
`);
|
|
173
|
+
expect(z.toJSONSchema(z.mac({ delimiter: ":" }))).toMatchInlineSnapshot(`
|
|
174
|
+
{
|
|
175
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
176
|
+
"format": "mac",
|
|
177
|
+
"pattern": "^(?:[0-9A-F]{2}:){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$",
|
|
178
|
+
"type": "string",
|
|
179
|
+
}
|
|
180
|
+
`);
|
|
181
|
+
expect(z.toJSONSchema(z.mac({ delimiter: "-" }))).toMatchInlineSnapshot(`
|
|
182
|
+
{
|
|
183
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
184
|
+
"format": "mac",
|
|
185
|
+
"pattern": "^(?:[0-9A-F]{2}-){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}-){5}[0-9a-f]{2}$",
|
|
186
|
+
"type": "string",
|
|
187
|
+
}
|
|
188
|
+
`);
|
|
189
|
+
expect(z.toJSONSchema(z.uuid())).toMatchInlineSnapshot(`
|
|
190
|
+
{
|
|
191
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
192
|
+
"format": "uuid",
|
|
193
|
+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$",
|
|
194
|
+
"type": "string",
|
|
195
|
+
}
|
|
196
|
+
`);
|
|
197
|
+
expect(z.toJSONSchema(z.guid())).toMatchInlineSnapshot(`
|
|
198
|
+
{
|
|
199
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
200
|
+
"format": "uuid",
|
|
201
|
+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$",
|
|
202
|
+
"type": "string",
|
|
203
|
+
}
|
|
204
|
+
`);
|
|
205
|
+
expect(z.toJSONSchema(z.url())).toMatchInlineSnapshot(`
|
|
206
|
+
{
|
|
207
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
208
|
+
"format": "uri",
|
|
209
|
+
"type": "string",
|
|
210
|
+
}
|
|
211
|
+
`);
|
|
212
|
+
expect(z.toJSONSchema(z.base64())).toMatchInlineSnapshot(`
|
|
213
|
+
{
|
|
214
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
215
|
+
"contentEncoding": "base64",
|
|
216
|
+
"format": "base64",
|
|
217
|
+
"pattern": "^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$",
|
|
218
|
+
"type": "string",
|
|
219
|
+
}
|
|
220
|
+
`);
|
|
221
|
+
expect(z.toJSONSchema(z.cuid())).toMatchInlineSnapshot(`
|
|
222
|
+
{
|
|
223
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
224
|
+
"format": "cuid",
|
|
225
|
+
"pattern": "^[cC][0-9a-z]{6,}$",
|
|
226
|
+
"type": "string",
|
|
227
|
+
}
|
|
228
|
+
`);
|
|
229
|
+
// expect(z.toJSONSchema(z.regex(/asdf/))).toMatchInlineSnapshot();
|
|
230
|
+
expect(z.toJSONSchema(z.emoji())).toMatchInlineSnapshot(`
|
|
231
|
+
{
|
|
232
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
233
|
+
"format": "emoji",
|
|
234
|
+
"pattern": "^[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$",
|
|
235
|
+
"type": "string",
|
|
236
|
+
}
|
|
237
|
+
`);
|
|
238
|
+
expect(z.toJSONSchema(z.nanoid())).toMatchInlineSnapshot(`
|
|
239
|
+
{
|
|
240
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
241
|
+
"format": "nanoid",
|
|
242
|
+
"pattern": "^[a-zA-Z0-9_-]{21}$",
|
|
243
|
+
"type": "string",
|
|
244
|
+
}
|
|
245
|
+
`);
|
|
246
|
+
expect(z.toJSONSchema(z.nanoid({ length: 64 }))).toMatchInlineSnapshot(`
|
|
247
|
+
{
|
|
248
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
249
|
+
"format": "nanoid",
|
|
250
|
+
"pattern": "^[a-zA-Z0-9_-]{64}$",
|
|
251
|
+
"type": "string",
|
|
252
|
+
}
|
|
253
|
+
`);
|
|
254
|
+
expect(z.toJSONSchema(z.cuid2())).toMatchInlineSnapshot(`
|
|
255
|
+
{
|
|
256
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
257
|
+
"format": "cuid2",
|
|
258
|
+
"pattern": "^[0-9a-z]+$",
|
|
259
|
+
"type": "string",
|
|
260
|
+
}
|
|
261
|
+
`);
|
|
262
|
+
expect(z.toJSONSchema(z.ulid())).toMatchInlineSnapshot(`
|
|
263
|
+
{
|
|
264
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
265
|
+
"format": "ulid",
|
|
266
|
+
"pattern": "^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$",
|
|
267
|
+
"type": "string",
|
|
268
|
+
}
|
|
269
|
+
`);
|
|
270
|
+
// expect(z.toJSONSchema(z.cidr())).toMatchInlineSnapshot();
|
|
271
|
+
expect(z.toJSONSchema(z.number())).toMatchInlineSnapshot(`
|
|
272
|
+
{
|
|
273
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
274
|
+
"type": "number",
|
|
275
|
+
}
|
|
276
|
+
`);
|
|
277
|
+
expect(z.toJSONSchema(z.int())).toMatchInlineSnapshot(`
|
|
278
|
+
{
|
|
279
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
280
|
+
"maximum": 9007199254740991,
|
|
281
|
+
"minimum": -9007199254740991,
|
|
282
|
+
"type": "integer",
|
|
283
|
+
}
|
|
284
|
+
`);
|
|
285
|
+
expect(z.toJSONSchema(z.int32())).toMatchInlineSnapshot(`
|
|
286
|
+
{
|
|
287
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
288
|
+
"maximum": 2147483647,
|
|
289
|
+
"minimum": -2147483648,
|
|
290
|
+
"type": "integer",
|
|
291
|
+
}
|
|
292
|
+
`);
|
|
293
|
+
expect(z.toJSONSchema(z.float32())).toMatchInlineSnapshot(`
|
|
294
|
+
{
|
|
295
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
296
|
+
"maximum": 3.4028234663852886e+38,
|
|
297
|
+
"minimum": -3.4028234663852886e+38,
|
|
298
|
+
"type": "number",
|
|
299
|
+
}
|
|
300
|
+
`);
|
|
301
|
+
expect(z.toJSONSchema(z.float64())).toMatchInlineSnapshot(`
|
|
302
|
+
{
|
|
303
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
304
|
+
"maximum": 1.7976931348623157e+308,
|
|
305
|
+
"minimum": -1.7976931348623157e+308,
|
|
306
|
+
"type": "number",
|
|
307
|
+
}
|
|
308
|
+
`);
|
|
309
|
+
expect(z.toJSONSchema(z.jwt())).toMatchInlineSnapshot(`
|
|
310
|
+
{
|
|
311
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
312
|
+
"format": "jwt",
|
|
313
|
+
"type": "string",
|
|
314
|
+
}
|
|
315
|
+
`);
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
test("unsupported schema types", () => {
|
|
319
|
+
expect(() => z.toJSONSchema(z.bigint())).toThrow("BigInt cannot be represented in JSON Schema");
|
|
320
|
+
expect(() => z.toJSONSchema(z.int64())).toThrow("BigInt cannot be represented in JSON Schema");
|
|
321
|
+
expect(() => z.toJSONSchema(z.symbol())).toThrow("Symbols cannot be represented in JSON Schema");
|
|
322
|
+
expect(() => z.toJSONSchema(z.void())).toThrow("Void cannot be represented in JSON Schema");
|
|
323
|
+
expect(() => z.toJSONSchema(z.undefined())).toThrow("Undefined cannot be represented in JSON Schema");
|
|
324
|
+
expect(() => z.toJSONSchema(z.date())).toThrow("Date cannot be represented in JSON Schema");
|
|
325
|
+
expect(() => z.toJSONSchema(z.map(z.string(), z.number()))).toThrow("Map cannot be represented in JSON Schema");
|
|
326
|
+
expect(() => z.toJSONSchema(z.set(z.string()))).toThrow("Set cannot be represented in JSON Schema");
|
|
327
|
+
expect(() => z.toJSONSchema(z.custom(() => true))).toThrow("Custom types cannot be represented in JSON Schema");
|
|
328
|
+
|
|
329
|
+
// Transform
|
|
330
|
+
const transformSchema = z.string().transform((val) => Number.parseInt(val));
|
|
331
|
+
expect(() => z.toJSONSchema(transformSchema)).toThrow("Transforms cannot be represented in JSON Schema");
|
|
332
|
+
|
|
333
|
+
// Static catch values
|
|
334
|
+
const staticCatchSchema = z.string().catch(() => "sup");
|
|
335
|
+
expect(z.toJSONSchema(staticCatchSchema)).toMatchInlineSnapshot(`
|
|
336
|
+
{
|
|
337
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
338
|
+
"default": "sup",
|
|
339
|
+
"type": "string",
|
|
340
|
+
}
|
|
341
|
+
`);
|
|
342
|
+
|
|
343
|
+
// Dynamic catch values
|
|
344
|
+
const dynamicCatchSchema = z.string().catch((ctx) => `${ctx.issues.length}`);
|
|
345
|
+
expect(() => z.toJSONSchema(dynamicCatchSchema)).toThrow("Dynamic catch values are not supported in JSON Schema");
|
|
346
|
+
expect(z.toJSONSchema(dynamicCatchSchema, { unrepresentable: "any" })).toMatchInlineSnapshot(`
|
|
347
|
+
{
|
|
348
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
349
|
+
"type": "string",
|
|
350
|
+
}
|
|
351
|
+
`);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
test("string formats", () => {
|
|
355
|
+
expect(z.toJSONSchema(z.string().email())).toMatchInlineSnapshot(`
|
|
356
|
+
{
|
|
357
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
358
|
+
"format": "email",
|
|
359
|
+
"pattern": "^(?!\\.)(?!.*\\.\\.)([A-Za-z0-9_'+\\-\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$",
|
|
360
|
+
"type": "string",
|
|
361
|
+
}
|
|
362
|
+
`);
|
|
363
|
+
expect(z.toJSONSchema(z.string().uuid())).toMatchInlineSnapshot(`
|
|
364
|
+
{
|
|
365
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
366
|
+
"format": "uuid",
|
|
367
|
+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$",
|
|
368
|
+
"type": "string",
|
|
369
|
+
}
|
|
370
|
+
`);
|
|
371
|
+
expect(z.toJSONSchema(z.iso.datetime())).toMatchInlineSnapshot(`
|
|
372
|
+
{
|
|
373
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
374
|
+
"format": "date-time",
|
|
375
|
+
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$",
|
|
376
|
+
"type": "string",
|
|
377
|
+
}
|
|
378
|
+
`);
|
|
379
|
+
|
|
380
|
+
expect(z.toJSONSchema(z.iso.date())).toMatchInlineSnapshot(`
|
|
381
|
+
{
|
|
382
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
383
|
+
"format": "date",
|
|
384
|
+
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$",
|
|
385
|
+
"type": "string",
|
|
386
|
+
}
|
|
387
|
+
`);
|
|
388
|
+
expect(z.toJSONSchema(z.iso.time())).toMatchInlineSnapshot(`
|
|
389
|
+
{
|
|
390
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
391
|
+
"pattern": "^(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?$",
|
|
392
|
+
"type": "string",
|
|
393
|
+
}
|
|
394
|
+
`);
|
|
395
|
+
expect(z.toJSONSchema(z.iso.duration())).toMatchInlineSnapshot(`
|
|
396
|
+
{
|
|
397
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
398
|
+
"format": "duration",
|
|
399
|
+
"pattern": "^P(?:(\\d+W)|(?!.*W)(?=\\d|T\\d)(\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+([.,]\\d+)?S)?)?)$",
|
|
400
|
+
"type": "string",
|
|
401
|
+
}
|
|
402
|
+
`);
|
|
403
|
+
// expect(z.toJSONSchema(z.string().ip())).toMatchInlineSnapshot(`
|
|
404
|
+
// {
|
|
405
|
+
// "pattern": /\\(\\^\\(\\?:\\(\\?:25\\[0-5\\]\\|2\\[0-4\\]\\[0-9\\]\\|1\\[0-9\\]\\[0-9\\]\\|\\[1-9\\]\\[0-9\\]\\|\\[0-9\\]\\)\\\\\\.\\)\\{3\\}\\(\\?:25\\[0-5\\]\\|2\\[0-4\\]\\[0-9\\]\\|1\\[0-9\\]\\[0-9\\]\\|\\[1-9\\]\\[0-9\\]\\|\\[0-9\\]\\)\\$\\)\\|\\(\\^\\(\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{7\\}\\|::\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{0,6\\}\\|\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{1\\}:\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{0,5\\}\\|\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{2\\}:\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{0,4\\}\\|\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{3\\}:\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{0,3\\}\\|\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{4\\}:\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{0,2\\}\\|\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{5\\}:\\(\\[a-fA-F0-9\\]\\{1,4\\}:\\)\\{0,1\\}\\)\\(\\[a-fA-F0-9\\]\\{1,4\\}\\|\\(\\(\\(25\\[0-5\\]\\)\\|\\(2\\[0-4\\]\\[0-9\\]\\)\\|\\(1\\[0-9\\]\\{2\\}\\)\\|\\(\\[0-9\\]\\{1,2\\}\\)\\)\\\\\\.\\)\\{3\\}\\(\\(25\\[0-5\\]\\)\\|\\(2\\[0-4\\]\\[0-9\\]\\)\\|\\(1\\[0-9\\]\\{2\\}\\)\\|\\(\\[0-9\\]\\{1,2\\}\\)\\)\\)\\$\\)/,
|
|
406
|
+
// "type": "string",
|
|
407
|
+
// }
|
|
408
|
+
// `);
|
|
409
|
+
expect(z.toJSONSchema(z.ipv4())).toMatchInlineSnapshot(`
|
|
410
|
+
{
|
|
411
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
412
|
+
"format": "ipv4",
|
|
413
|
+
"pattern": "^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$",
|
|
414
|
+
"type": "string",
|
|
415
|
+
}
|
|
416
|
+
`);
|
|
417
|
+
|
|
418
|
+
expect(z.toJSONSchema(z.ipv6())).toMatchInlineSnapshot(`
|
|
419
|
+
{
|
|
420
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
421
|
+
"format": "ipv6",
|
|
422
|
+
"pattern": "^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$",
|
|
423
|
+
"type": "string",
|
|
424
|
+
}
|
|
425
|
+
`);
|
|
426
|
+
|
|
427
|
+
expect(z.toJSONSchema(z.mac())).toMatchInlineSnapshot(`
|
|
428
|
+
{
|
|
429
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
430
|
+
"format": "mac",
|
|
431
|
+
"pattern": "^(?:[0-9A-F]{2}:){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$",
|
|
432
|
+
"type": "string",
|
|
433
|
+
}
|
|
434
|
+
`);
|
|
435
|
+
expect(z.toJSONSchema(z.mac({ delimiter: ":" }))).toMatchInlineSnapshot(`
|
|
436
|
+
{
|
|
437
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
438
|
+
"format": "mac",
|
|
439
|
+
"pattern": "^(?:[0-9A-F]{2}:){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$",
|
|
440
|
+
"type": "string",
|
|
441
|
+
}
|
|
442
|
+
`);
|
|
443
|
+
expect(z.toJSONSchema(z.mac({ delimiter: "-" }))).toMatchInlineSnapshot(`
|
|
444
|
+
{
|
|
445
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
446
|
+
"format": "mac",
|
|
447
|
+
"pattern": "^(?:[0-9A-F]{2}-){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}-){5}[0-9a-f]{2}$",
|
|
448
|
+
"type": "string",
|
|
449
|
+
}
|
|
450
|
+
`);
|
|
451
|
+
|
|
452
|
+
expect(z.toJSONSchema(z.base64())).toMatchInlineSnapshot(`
|
|
453
|
+
{
|
|
454
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
455
|
+
"contentEncoding": "base64",
|
|
456
|
+
"format": "base64",
|
|
457
|
+
"pattern": "^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$",
|
|
458
|
+
"type": "string",
|
|
459
|
+
}
|
|
460
|
+
`);
|
|
461
|
+
expect(z.toJSONSchema(z.url())).toMatchInlineSnapshot(`
|
|
462
|
+
{
|
|
463
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
464
|
+
"format": "uri",
|
|
465
|
+
"type": "string",
|
|
466
|
+
}
|
|
467
|
+
`);
|
|
468
|
+
expect(z.toJSONSchema(z.guid())).toMatchInlineSnapshot(`
|
|
469
|
+
{
|
|
470
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
471
|
+
"format": "uuid",
|
|
472
|
+
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$",
|
|
473
|
+
"type": "string",
|
|
474
|
+
}
|
|
475
|
+
`);
|
|
476
|
+
expect(z.toJSONSchema(z.string().regex(/asdf/))).toMatchInlineSnapshot(`
|
|
477
|
+
{
|
|
478
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
479
|
+
"pattern": "asdf",
|
|
480
|
+
"type": "string",
|
|
481
|
+
}
|
|
482
|
+
`);
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
test("string patterns", () => {
|
|
486
|
+
expect(
|
|
487
|
+
z.toJSONSchema(
|
|
488
|
+
z
|
|
489
|
+
.string()
|
|
490
|
+
.startsWith("hello")
|
|
491
|
+
.includes("cruel")
|
|
492
|
+
.includes("dark", { position: 10 })
|
|
493
|
+
.endsWith("world")
|
|
494
|
+
.regex(/stuff/)
|
|
495
|
+
)
|
|
496
|
+
).toMatchInlineSnapshot(`
|
|
497
|
+
{
|
|
498
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
499
|
+
"allOf": [
|
|
500
|
+
{
|
|
501
|
+
"pattern": "^hello.*",
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
"pattern": "cruel",
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
"pattern": "^.{10,}dark",
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
"pattern": ".*world$",
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
"pattern": "stuff",
|
|
514
|
+
},
|
|
515
|
+
],
|
|
516
|
+
"type": "string",
|
|
517
|
+
}
|
|
518
|
+
`);
|
|
519
|
+
|
|
520
|
+
expect(
|
|
521
|
+
z.toJSONSchema(
|
|
522
|
+
z
|
|
523
|
+
.string()
|
|
524
|
+
.startsWith("hello")
|
|
525
|
+
.includes("cruel")
|
|
526
|
+
.includes("dark", { position: 10 })
|
|
527
|
+
.endsWith("world")
|
|
528
|
+
.regex(/stuff/),
|
|
529
|
+
{
|
|
530
|
+
target: "draft-7",
|
|
531
|
+
}
|
|
532
|
+
)
|
|
533
|
+
).toMatchInlineSnapshot(`
|
|
534
|
+
{
|
|
535
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
536
|
+
"allOf": [
|
|
537
|
+
{
|
|
538
|
+
"pattern": "^hello.*",
|
|
539
|
+
"type": "string",
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
"pattern": "cruel",
|
|
543
|
+
"type": "string",
|
|
544
|
+
},
|
|
545
|
+
{
|
|
546
|
+
"pattern": "^.{10,}dark",
|
|
547
|
+
"type": "string",
|
|
548
|
+
},
|
|
549
|
+
{
|
|
550
|
+
"pattern": ".*world$",
|
|
551
|
+
"type": "string",
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
"pattern": "stuff",
|
|
555
|
+
"type": "string",
|
|
556
|
+
},
|
|
557
|
+
],
|
|
558
|
+
"type": "string",
|
|
559
|
+
}
|
|
560
|
+
`);
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
test("includes with position emits a pattern matching runtime semantics", () => {
|
|
564
|
+
// String.prototype.includes(sub, position) matches `sub` at `position` OR
|
|
565
|
+
// LATER, so the JSON Schema pattern must allow >= position leading chars.
|
|
566
|
+
const schema = z.string().includes("foo", { position: 2 });
|
|
567
|
+
const json = z.toJSONSchema(schema) as { pattern?: string };
|
|
568
|
+
expect(json.pattern).toBe("^.{2,}foo");
|
|
569
|
+
|
|
570
|
+
const re = new RegExp(json.pattern!);
|
|
571
|
+
for (const input of ["xxfoo", "xxxfoo", "xfoo", "ab"]) {
|
|
572
|
+
expect(re.test(input)).toBe(schema.safeParse(input).success);
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
test("number constraints", () => {
|
|
577
|
+
expect(z.toJSONSchema(z.number().min(5).max(10))).toMatchInlineSnapshot(
|
|
578
|
+
`
|
|
579
|
+
{
|
|
580
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
581
|
+
"maximum": 10,
|
|
582
|
+
"minimum": 5,
|
|
583
|
+
"type": "number",
|
|
584
|
+
}
|
|
585
|
+
`
|
|
586
|
+
);
|
|
587
|
+
|
|
588
|
+
expect(z.toJSONSchema(z.number().gt(5).gt(10))).toMatchInlineSnapshot(`
|
|
589
|
+
{
|
|
590
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
591
|
+
"exclusiveMinimum": 10,
|
|
592
|
+
"type": "number",
|
|
593
|
+
}
|
|
594
|
+
`);
|
|
595
|
+
|
|
596
|
+
expect(z.toJSONSchema(z.number().gt(5).gte(10))).toMatchInlineSnapshot(`
|
|
597
|
+
{
|
|
598
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
599
|
+
"minimum": 10,
|
|
600
|
+
"type": "number",
|
|
601
|
+
}
|
|
602
|
+
`);
|
|
603
|
+
|
|
604
|
+
expect(z.toJSONSchema(z.number().lt(5).lt(3))).toMatchInlineSnapshot(`
|
|
605
|
+
{
|
|
606
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
607
|
+
"exclusiveMaximum": 3,
|
|
608
|
+
"type": "number",
|
|
609
|
+
}
|
|
610
|
+
`);
|
|
611
|
+
|
|
612
|
+
expect(z.toJSONSchema(z.number().lt(5).lt(3).lte(2))).toMatchInlineSnapshot(`
|
|
613
|
+
{
|
|
614
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
615
|
+
"maximum": 2,
|
|
616
|
+
"type": "number",
|
|
617
|
+
}
|
|
618
|
+
`);
|
|
619
|
+
|
|
620
|
+
expect(z.toJSONSchema(z.number().lt(5).lte(3))).toMatchInlineSnapshot(`
|
|
621
|
+
{
|
|
622
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
623
|
+
"maximum": 3,
|
|
624
|
+
"type": "number",
|
|
625
|
+
}
|
|
626
|
+
`);
|
|
627
|
+
|
|
628
|
+
expect(z.toJSONSchema(z.number().gt(5).lt(10))).toMatchInlineSnapshot(`
|
|
629
|
+
{
|
|
630
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
631
|
+
"exclusiveMaximum": 10,
|
|
632
|
+
"exclusiveMinimum": 5,
|
|
633
|
+
"type": "number",
|
|
634
|
+
}
|
|
635
|
+
`);
|
|
636
|
+
expect(z.toJSONSchema(z.number().gte(5).lte(10))).toMatchInlineSnapshot(`
|
|
637
|
+
{
|
|
638
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
639
|
+
"maximum": 10,
|
|
640
|
+
"minimum": 5,
|
|
641
|
+
"type": "number",
|
|
642
|
+
}
|
|
643
|
+
`);
|
|
644
|
+
expect(z.toJSONSchema(z.number().positive())).toMatchInlineSnapshot(`
|
|
645
|
+
{
|
|
646
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
647
|
+
"exclusiveMinimum": 0,
|
|
648
|
+
"type": "number",
|
|
649
|
+
}
|
|
650
|
+
`);
|
|
651
|
+
expect(z.toJSONSchema(z.number().negative())).toMatchInlineSnapshot(`
|
|
652
|
+
{
|
|
653
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
654
|
+
"exclusiveMaximum": 0,
|
|
655
|
+
"type": "number",
|
|
656
|
+
}
|
|
657
|
+
`);
|
|
658
|
+
expect(z.toJSONSchema(z.number().nonpositive())).toMatchInlineSnapshot(`
|
|
659
|
+
{
|
|
660
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
661
|
+
"maximum": 0,
|
|
662
|
+
"type": "number",
|
|
663
|
+
}
|
|
664
|
+
`);
|
|
665
|
+
expect(z.toJSONSchema(z.number().nonnegative())).toMatchInlineSnapshot(`
|
|
666
|
+
{
|
|
667
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
668
|
+
"minimum": 0,
|
|
669
|
+
"type": "number",
|
|
670
|
+
}
|
|
671
|
+
`);
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
test("number constraints draft-4", () => {
|
|
675
|
+
expect(z.toJSONSchema(z.number().gt(5).lt(10), { target: "draft-4" })).toMatchInlineSnapshot(`
|
|
676
|
+
{
|
|
677
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
678
|
+
"exclusiveMaximum": true,
|
|
679
|
+
"exclusiveMinimum": true,
|
|
680
|
+
"maximum": 10,
|
|
681
|
+
"minimum": 5,
|
|
682
|
+
"type": "number",
|
|
683
|
+
}
|
|
684
|
+
`);
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
test("number constraints intersection draft-04", () => {
|
|
688
|
+
// When both minimum (from .int()) and exclusiveMinimum (from .positive()) exist, the more restrictive constraint should be used
|
|
689
|
+
expect(z.toJSONSchema(z.number().int().positive().lte(65535), { target: "draft-04" })).toMatchInlineSnapshot(`
|
|
690
|
+
{
|
|
691
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
692
|
+
"exclusiveMinimum": true,
|
|
693
|
+
"maximum": 65535,
|
|
694
|
+
"minimum": 0,
|
|
695
|
+
"type": "integer",
|
|
696
|
+
}
|
|
697
|
+
`);
|
|
698
|
+
// Same for openapi-3.0
|
|
699
|
+
expect(z.toJSONSchema(z.number().int().positive().lte(65535), { target: "openapi-3.0" })).toMatchInlineSnapshot(`
|
|
700
|
+
{
|
|
701
|
+
"exclusiveMinimum": true,
|
|
702
|
+
"maximum": 65535,
|
|
703
|
+
"minimum": 0,
|
|
704
|
+
"type": "integer",
|
|
705
|
+
}
|
|
706
|
+
`);
|
|
707
|
+
// When inclusive minimum is more restrictive than exclusive minimum
|
|
708
|
+
expect(z.toJSONSchema(z.number().gt(3).gte(10), { target: "draft-04" })).toMatchInlineSnapshot(`
|
|
709
|
+
{
|
|
710
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
711
|
+
"minimum": 10,
|
|
712
|
+
"type": "number",
|
|
713
|
+
}
|
|
714
|
+
`);
|
|
715
|
+
// Same logic for maximum constraints
|
|
716
|
+
expect(z.toJSONSchema(z.number().int().negative(), { target: "draft-04" })).toMatchInlineSnapshot(`
|
|
717
|
+
{
|
|
718
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
719
|
+
"exclusiveMaximum": true,
|
|
720
|
+
"maximum": 0,
|
|
721
|
+
"minimum": -9007199254740991,
|
|
722
|
+
"type": "integer",
|
|
723
|
+
}
|
|
724
|
+
`);
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
test("target normalization draft-04 and draft-07", () => {
|
|
728
|
+
// Test that both old (draft-4, draft-7) and new (draft-04, draft-07) target formats work
|
|
729
|
+
|
|
730
|
+
// Test draft-04 / draft-4
|
|
731
|
+
expect(z.toJSONSchema(z.number().gt(5), { target: "draft-04" })).toMatchInlineSnapshot(`
|
|
732
|
+
{
|
|
733
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
734
|
+
"exclusiveMinimum": true,
|
|
735
|
+
"minimum": 5,
|
|
736
|
+
"type": "number",
|
|
737
|
+
}
|
|
738
|
+
`);
|
|
739
|
+
expect(z.toJSONSchema(z.number().gt(5), { target: "draft-4" })).toMatchInlineSnapshot(`
|
|
740
|
+
{
|
|
741
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
742
|
+
"exclusiveMinimum": true,
|
|
743
|
+
"minimum": 5,
|
|
744
|
+
"type": "number",
|
|
745
|
+
}
|
|
746
|
+
`);
|
|
747
|
+
// Test draft-07 / draft-7
|
|
748
|
+
expect(z.toJSONSchema(z.number().gt(5), { target: "draft-07" })).toMatchInlineSnapshot(`
|
|
749
|
+
{
|
|
750
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
751
|
+
"exclusiveMinimum": 5,
|
|
752
|
+
"type": "number",
|
|
753
|
+
}
|
|
754
|
+
`);
|
|
755
|
+
expect(z.toJSONSchema(z.number().gt(5), { target: "draft-7" })).toMatchInlineSnapshot(`
|
|
756
|
+
{
|
|
757
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
758
|
+
"exclusiveMinimum": 5,
|
|
759
|
+
"type": "number",
|
|
760
|
+
}
|
|
761
|
+
`);
|
|
762
|
+
});
|
|
763
|
+
|
|
764
|
+
test("nullable openapi-3.0", () => {
|
|
765
|
+
const schema = z.string().nullable();
|
|
766
|
+
const jsonSchema = z.toJSONSchema(schema, { target: "openapi-3.0" });
|
|
767
|
+
validateOpenAPI30Schema(jsonSchema);
|
|
768
|
+
expect(jsonSchema).toMatchInlineSnapshot(`
|
|
769
|
+
{
|
|
770
|
+
"nullable": true,
|
|
771
|
+
"type": "string",
|
|
772
|
+
}
|
|
773
|
+
`);
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
test("union with null openapi-3.0", () => {
|
|
777
|
+
const schema = z.union([z.string(), z.null()]);
|
|
778
|
+
const jsonSchema = z.toJSONSchema(schema, { target: "openapi-3.0" });
|
|
779
|
+
validateOpenAPI30Schema(jsonSchema);
|
|
780
|
+
expect(jsonSchema).toMatchInlineSnapshot(`
|
|
781
|
+
{
|
|
782
|
+
"anyOf": [
|
|
783
|
+
{
|
|
784
|
+
"type": "string",
|
|
785
|
+
},
|
|
786
|
+
{
|
|
787
|
+
"enum": [
|
|
788
|
+
null,
|
|
789
|
+
],
|
|
790
|
+
"nullable": true,
|
|
791
|
+
"type": "string",
|
|
792
|
+
},
|
|
793
|
+
],
|
|
794
|
+
}
|
|
795
|
+
`);
|
|
796
|
+
});
|
|
797
|
+
|
|
798
|
+
test("number with exclusive min-max openapi-3.0", () => {
|
|
799
|
+
const schema = z.number().lt(100).gt(1);
|
|
800
|
+
const jsonSchema = z.toJSONSchema(schema, { target: "openapi-3.0" });
|
|
801
|
+
validateOpenAPI30Schema(jsonSchema);
|
|
802
|
+
expect(jsonSchema).toMatchInlineSnapshot(`
|
|
803
|
+
{
|
|
804
|
+
"exclusiveMaximum": true,
|
|
805
|
+
"exclusiveMinimum": true,
|
|
806
|
+
"maximum": 100,
|
|
807
|
+
"minimum": 1,
|
|
808
|
+
"type": "number",
|
|
809
|
+
}
|
|
810
|
+
`);
|
|
811
|
+
});
|
|
812
|
+
|
|
813
|
+
test("arrays", () => {
|
|
814
|
+
expect(z.toJSONSchema(z.array(z.string()))).toMatchInlineSnapshot(`
|
|
815
|
+
{
|
|
816
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
817
|
+
"items": {
|
|
818
|
+
"type": "string",
|
|
819
|
+
},
|
|
820
|
+
"type": "array",
|
|
821
|
+
}
|
|
822
|
+
`);
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
test("unions", () => {
|
|
826
|
+
const schema = z.union([z.string(), z.number()]);
|
|
827
|
+
expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
|
|
828
|
+
{
|
|
829
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
830
|
+
"type": [
|
|
831
|
+
"string",
|
|
832
|
+
"number",
|
|
833
|
+
],
|
|
834
|
+
}
|
|
835
|
+
`);
|
|
836
|
+
});
|
|
837
|
+
|
|
838
|
+
test("nullable compacts to a type array", () => {
|
|
839
|
+
expect(z.toJSONSchema(z.string().nullable())).toMatchInlineSnapshot(`
|
|
840
|
+
{
|
|
841
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
842
|
+
"type": [
|
|
843
|
+
"string",
|
|
844
|
+
"null",
|
|
845
|
+
],
|
|
846
|
+
}
|
|
847
|
+
`);
|
|
848
|
+
|
|
849
|
+
// a nested union folds into the outer type array rather than leaving a mixed shape
|
|
850
|
+
expect(z.toJSONSchema(z.union([z.string(), z.number()]).nullable())).toMatchInlineSnapshot(`
|
|
851
|
+
{
|
|
852
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
853
|
+
"type": [
|
|
854
|
+
"string",
|
|
855
|
+
"number",
|
|
856
|
+
"null",
|
|
857
|
+
],
|
|
858
|
+
}
|
|
859
|
+
`);
|
|
860
|
+
|
|
861
|
+
// the null branch is bare but the object branch is not, so this stays an anyOf
|
|
862
|
+
expect(z.toJSONSchema(z.object({ a: z.string() }).nullable())).toMatchInlineSnapshot(`
|
|
863
|
+
{
|
|
864
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
865
|
+
"anyOf": [
|
|
866
|
+
{
|
|
867
|
+
"additionalProperties": false,
|
|
868
|
+
"properties": {
|
|
869
|
+
"a": {
|
|
870
|
+
"type": "string",
|
|
871
|
+
},
|
|
872
|
+
},
|
|
873
|
+
"required": [
|
|
874
|
+
"a",
|
|
875
|
+
],
|
|
876
|
+
"type": "object",
|
|
877
|
+
},
|
|
878
|
+
{
|
|
879
|
+
"type": "null",
|
|
880
|
+
},
|
|
881
|
+
],
|
|
882
|
+
}
|
|
883
|
+
`);
|
|
884
|
+
});
|
|
885
|
+
|
|
886
|
+
test("duplicate branches dedupe, single branch stays a bare type", () => {
|
|
887
|
+
// a `type` array must have unique members, so two branches that erase to the same bare type collapse
|
|
888
|
+
const refined = z.union([z.string().refine((s) => s.length > 2), z.string().refine((s) => s.length < 9)]);
|
|
889
|
+
expect(z.toJSONSchema(refined)).toMatchInlineSnapshot(`
|
|
890
|
+
{
|
|
891
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
892
|
+
"type": "string",
|
|
893
|
+
}
|
|
894
|
+
`);
|
|
895
|
+
expect(z.toJSONSchema(z.union([z.string()]))).toMatchInlineSnapshot(`
|
|
896
|
+
{
|
|
897
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
898
|
+
"type": "string",
|
|
899
|
+
}
|
|
900
|
+
`);
|
|
901
|
+
});
|
|
902
|
+
|
|
903
|
+
test("compaction runs after overrides and ref extraction", () => {
|
|
904
|
+
// an override decorates the string branch, so it is no longer a bare type and must survive in anyOf
|
|
905
|
+
const decorated = z.toJSONSchema(z.union([z.string(), z.number()]), {
|
|
906
|
+
override(ctx) {
|
|
907
|
+
if (ctx.zodSchema._zod.def.type === "string") ctx.jsonSchema.whatever = "sup";
|
|
908
|
+
},
|
|
909
|
+
});
|
|
910
|
+
expect(decorated).toMatchInlineSnapshot(`
|
|
911
|
+
{
|
|
912
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
913
|
+
"anyOf": [
|
|
914
|
+
{
|
|
915
|
+
"type": "string",
|
|
916
|
+
"whatever": "sup",
|
|
917
|
+
},
|
|
918
|
+
{
|
|
919
|
+
"type": "number",
|
|
920
|
+
},
|
|
921
|
+
],
|
|
922
|
+
}
|
|
923
|
+
`);
|
|
924
|
+
|
|
925
|
+
// a branch extracted into $defs is a $ref, not a bare type, so `reused` is not silently bypassed
|
|
926
|
+
const shared = z.string();
|
|
927
|
+
expect(
|
|
928
|
+
z.toJSONSchema(z.object({ a: shared, b: z.union([shared, z.null()]) }), { reused: "ref" })
|
|
929
|
+
).toMatchInlineSnapshot(`
|
|
930
|
+
{
|
|
931
|
+
"$defs": {
|
|
932
|
+
"__schema0": {
|
|
933
|
+
"type": "string",
|
|
934
|
+
},
|
|
935
|
+
},
|
|
936
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
937
|
+
"additionalProperties": false,
|
|
938
|
+
"properties": {
|
|
939
|
+
"a": {
|
|
940
|
+
"$ref": "#/$defs/__schema0",
|
|
941
|
+
},
|
|
942
|
+
"b": {
|
|
943
|
+
"anyOf": [
|
|
944
|
+
{
|
|
945
|
+
"$ref": "#/$defs/__schema0",
|
|
946
|
+
},
|
|
947
|
+
{
|
|
948
|
+
"type": "null",
|
|
949
|
+
},
|
|
950
|
+
],
|
|
951
|
+
},
|
|
952
|
+
},
|
|
953
|
+
"required": [
|
|
954
|
+
"a",
|
|
955
|
+
"b",
|
|
956
|
+
],
|
|
957
|
+
"type": "object",
|
|
958
|
+
}
|
|
959
|
+
`);
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
test("openapi-3.0 keeps a single-string type", () => {
|
|
963
|
+
// OpenAPI 3.0 has no type arrays; nullability is spelled with `nullable`
|
|
964
|
+
expect(z.toJSONSchema(z.string().nullable(), { target: "openapi-3.0" })).toMatchInlineSnapshot(`
|
|
965
|
+
{
|
|
966
|
+
"nullable": true,
|
|
967
|
+
"type": "string",
|
|
968
|
+
}
|
|
969
|
+
`);
|
|
970
|
+
});
|
|
971
|
+
|
|
972
|
+
test("union with constrained branch is not compacted", () => {
|
|
973
|
+
const schema = z.union([z.string().min(1), z.number()]);
|
|
974
|
+
expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
|
|
975
|
+
{
|
|
976
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
977
|
+
"anyOf": [
|
|
978
|
+
{
|
|
979
|
+
"minLength": 1,
|
|
980
|
+
"type": "string",
|
|
981
|
+
},
|
|
982
|
+
{
|
|
983
|
+
"type": "number",
|
|
984
|
+
},
|
|
985
|
+
],
|
|
986
|
+
}
|
|
987
|
+
`);
|
|
988
|
+
});
|
|
989
|
+
|
|
990
|
+
test("union of literals is not compacted", () => {
|
|
991
|
+
const schema = z.union([z.literal("a"), z.literal("b")]);
|
|
992
|
+
expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
|
|
993
|
+
{
|
|
994
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
995
|
+
"anyOf": [
|
|
996
|
+
{
|
|
997
|
+
"const": "a",
|
|
998
|
+
"type": "string",
|
|
999
|
+
},
|
|
1000
|
+
{
|
|
1001
|
+
"const": "b",
|
|
1002
|
+
"type": "string",
|
|
1003
|
+
},
|
|
1004
|
+
],
|
|
1005
|
+
}
|
|
1006
|
+
`);
|
|
1007
|
+
});
|
|
1008
|
+
|
|
1009
|
+
test("discriminated unions", () => {
|
|
1010
|
+
const schema = z.discriminatedUnion("type", [
|
|
1011
|
+
z.object({ type: z.literal("success"), data: z.string() }),
|
|
1012
|
+
z.object({ type: z.literal("error"), message: z.string() }),
|
|
1013
|
+
]);
|
|
1014
|
+
expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
|
|
1015
|
+
{
|
|
1016
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1017
|
+
"oneOf": [
|
|
1018
|
+
{
|
|
1019
|
+
"additionalProperties": false,
|
|
1020
|
+
"properties": {
|
|
1021
|
+
"data": {
|
|
1022
|
+
"type": "string",
|
|
1023
|
+
},
|
|
1024
|
+
"type": {
|
|
1025
|
+
"const": "success",
|
|
1026
|
+
"type": "string",
|
|
1027
|
+
},
|
|
1028
|
+
},
|
|
1029
|
+
"required": [
|
|
1030
|
+
"type",
|
|
1031
|
+
"data",
|
|
1032
|
+
],
|
|
1033
|
+
"type": "object",
|
|
1034
|
+
},
|
|
1035
|
+
{
|
|
1036
|
+
"additionalProperties": false,
|
|
1037
|
+
"properties": {
|
|
1038
|
+
"message": {
|
|
1039
|
+
"type": "string",
|
|
1040
|
+
},
|
|
1041
|
+
"type": {
|
|
1042
|
+
"const": "error",
|
|
1043
|
+
"type": "string",
|
|
1044
|
+
},
|
|
1045
|
+
},
|
|
1046
|
+
"required": [
|
|
1047
|
+
"type",
|
|
1048
|
+
"message",
|
|
1049
|
+
],
|
|
1050
|
+
"type": "object",
|
|
1051
|
+
},
|
|
1052
|
+
],
|
|
1053
|
+
}
|
|
1054
|
+
`);
|
|
1055
|
+
});
|
|
1056
|
+
|
|
1057
|
+
test("intersections", () => {
|
|
1058
|
+
const schema = z.intersection(z.object({ name: z.string() }), z.object({ age: z.number() }));
|
|
1059
|
+
|
|
1060
|
+
expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
|
|
1061
|
+
{
|
|
1062
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1063
|
+
"additionalProperties": false,
|
|
1064
|
+
"properties": {
|
|
1065
|
+
"age": {
|
|
1066
|
+
"type": "number",
|
|
1067
|
+
},
|
|
1068
|
+
"name": {
|
|
1069
|
+
"type": "string",
|
|
1070
|
+
},
|
|
1071
|
+
},
|
|
1072
|
+
"required": [
|
|
1073
|
+
"name",
|
|
1074
|
+
"age",
|
|
1075
|
+
],
|
|
1076
|
+
"type": "object",
|
|
1077
|
+
}
|
|
1078
|
+
`);
|
|
1079
|
+
});
|
|
1080
|
+
|
|
1081
|
+
test("record", () => {
|
|
1082
|
+
const schema = z.record(z.string(), z.boolean());
|
|
1083
|
+
expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
|
|
1084
|
+
{
|
|
1085
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1086
|
+
"additionalProperties": {
|
|
1087
|
+
"type": "boolean",
|
|
1088
|
+
},
|
|
1089
|
+
"propertyNames": {
|
|
1090
|
+
"type": "string",
|
|
1091
|
+
},
|
|
1092
|
+
"type": "object",
|
|
1093
|
+
}
|
|
1094
|
+
`);
|
|
1095
|
+
});
|
|
1096
|
+
|
|
1097
|
+
test("record openapi-3.0", () => {
|
|
1098
|
+
const schema = z.record(z.string(), z.boolean());
|
|
1099
|
+
const jsonSchema = z.toJSONSchema(schema, { target: "openapi-3.0" });
|
|
1100
|
+
validateOpenAPI30Schema(jsonSchema);
|
|
1101
|
+
expect(jsonSchema).toMatchInlineSnapshot(`
|
|
1102
|
+
{
|
|
1103
|
+
"additionalProperties": {
|
|
1104
|
+
"type": "boolean",
|
|
1105
|
+
},
|
|
1106
|
+
"type": "object",
|
|
1107
|
+
}
|
|
1108
|
+
`);
|
|
1109
|
+
});
|
|
1110
|
+
|
|
1111
|
+
test("record with enum keys adds required", () => {
|
|
1112
|
+
const schema = z.record(z.enum(["key1", "key2"]), z.number());
|
|
1113
|
+
|
|
1114
|
+
expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
|
|
1115
|
+
{
|
|
1116
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1117
|
+
"additionalProperties": {
|
|
1118
|
+
"type": "number",
|
|
1119
|
+
},
|
|
1120
|
+
"propertyNames": {
|
|
1121
|
+
"enum": [
|
|
1122
|
+
"key1",
|
|
1123
|
+
"key2",
|
|
1124
|
+
],
|
|
1125
|
+
"type": "string",
|
|
1126
|
+
},
|
|
1127
|
+
"required": [
|
|
1128
|
+
"key1",
|
|
1129
|
+
"key2",
|
|
1130
|
+
],
|
|
1131
|
+
"type": "object",
|
|
1132
|
+
}
|
|
1133
|
+
`);
|
|
1134
|
+
});
|
|
1135
|
+
|
|
1136
|
+
test("record with enum keys drops required for an optional-in value under io: input", () => {
|
|
1137
|
+
const schema = z.record(z.enum(["key1", "key2"]), z.number().default(0));
|
|
1138
|
+
|
|
1139
|
+
expect(z.toJSONSchema(schema, { io: "input" }).required).toBeUndefined();
|
|
1140
|
+
expect(z.toJSONSchema(schema).required).toEqual(["key1", "key2"]);
|
|
1141
|
+
expect(z.toJSONSchema(z.record(z.enum(["key1", "key2"]), z.number()), { io: "input" }).required).toEqual([
|
|
1142
|
+
"key1",
|
|
1143
|
+
"key2",
|
|
1144
|
+
]);
|
|
1145
|
+
// A caught value keeps required, matching the input type and z.object().
|
|
1146
|
+
expect(z.toJSONSchema(z.record(z.enum(["key1", "key2"]), z.number().catch(0)), { io: "input" }).required).toEqual([
|
|
1147
|
+
"key1",
|
|
1148
|
+
"key2",
|
|
1149
|
+
]);
|
|
1150
|
+
});
|
|
1151
|
+
|
|
1152
|
+
test("record stringifies numeric enum keys for propertyNames and required", () => {
|
|
1153
|
+
enum NumberEnum {
|
|
1154
|
+
Zero = 0,
|
|
1155
|
+
One = 1,
|
|
1156
|
+
}
|
|
1157
|
+
const schema = z.record(z.enum(NumberEnum), z.string());
|
|
1158
|
+
|
|
1159
|
+
expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
|
|
1160
|
+
{
|
|
1161
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1162
|
+
"additionalProperties": {
|
|
1163
|
+
"type": "string",
|
|
1164
|
+
},
|
|
1165
|
+
"propertyNames": {
|
|
1166
|
+
"enum": [
|
|
1167
|
+
"0",
|
|
1168
|
+
"1",
|
|
1169
|
+
],
|
|
1170
|
+
"type": "string",
|
|
1171
|
+
},
|
|
1172
|
+
"required": [
|
|
1173
|
+
"0",
|
|
1174
|
+
"1",
|
|
1175
|
+
],
|
|
1176
|
+
"type": "object",
|
|
1177
|
+
}
|
|
1178
|
+
`);
|
|
1179
|
+
});
|
|
1180
|
+
|
|
1181
|
+
test("record with a numeric key emits propertyNames over the numeric-string form", () => {
|
|
1182
|
+
expect(z.toJSONSchema(z.record(z.number(), z.boolean())).propertyNames).toEqual({
|
|
1183
|
+
type: "string",
|
|
1184
|
+
pattern: "^-?\\d+(?:\\.\\d+)?$",
|
|
1185
|
+
});
|
|
1186
|
+
// range checks can't apply to a key, so only the integer shape survives
|
|
1187
|
+
expect(z.toJSONSchema(z.record(z.int32(), z.boolean())).propertyNames).toEqual({
|
|
1188
|
+
type: "string",
|
|
1189
|
+
pattern: "^-?\\d+$",
|
|
1190
|
+
});
|
|
1191
|
+
expect(z.toJSONSchema(z.record(z.literal([1, 2]), z.boolean()))).toMatchObject({
|
|
1192
|
+
propertyNames: { type: "string", enum: ["1", "2"] },
|
|
1193
|
+
required: ["1", "2"],
|
|
1194
|
+
});
|
|
1195
|
+
expect(z.toJSONSchema(z.record(z.literal(1), z.boolean())).propertyNames).toEqual({
|
|
1196
|
+
type: "string",
|
|
1197
|
+
const: "1",
|
|
1198
|
+
});
|
|
1199
|
+
});
|
|
1200
|
+
|
|
1201
|
+
test("record key rewrite reaches through wrappers and union branches", () => {
|
|
1202
|
+
const numericString = { type: "string", pattern: "^-?\\d+(?:\\.\\d+)?$" };
|
|
1203
|
+
// a wrapper only carries its inner type once the refs are flattened, so this is decided after the record itself is emitted
|
|
1204
|
+
expect(
|
|
1205
|
+
z.toJSONSchema(
|
|
1206
|
+
z.record(
|
|
1207
|
+
z.lazy(() => z.number()),
|
|
1208
|
+
z.boolean()
|
|
1209
|
+
)
|
|
1210
|
+
).propertyNames
|
|
1211
|
+
).toEqual(numericString);
|
|
1212
|
+
expect(z.toJSONSchema(z.record(z.number().pipe(z.number()), z.boolean())).propertyNames).toEqual(numericString);
|
|
1213
|
+
expect(z.toJSONSchema(z.record(z.number().readonly(), z.boolean())).propertyNames).toMatchObject(numericString);
|
|
1214
|
+
expect(z.toJSONSchema(z.record(z.union([z.literal("Tuna"), z.literal(21)]), z.string()))).toMatchObject({
|
|
1215
|
+
propertyNames: {
|
|
1216
|
+
anyOf: [
|
|
1217
|
+
{ type: "string", const: "Tuna" },
|
|
1218
|
+
{ type: "string", const: "21" },
|
|
1219
|
+
],
|
|
1220
|
+
},
|
|
1221
|
+
required: ["Tuna", "21"],
|
|
1222
|
+
});
|
|
1223
|
+
});
|
|
1224
|
+
|
|
1225
|
+
test("record with a numeric key inlines an extracted key, and leaves a string one referenced", () => {
|
|
1226
|
+
expect(z.toJSONSchema(z.record(z.number().meta({ id: "Num" }), z.boolean())).propertyNames).toEqual({
|
|
1227
|
+
type: "string",
|
|
1228
|
+
pattern: "^-?\\d+(?:\\.\\d+)?$",
|
|
1229
|
+
});
|
|
1230
|
+
expect(z.toJSONSchema(z.record(z.string().meta({ id: "Str" }), z.boolean())).propertyNames).toEqual({
|
|
1231
|
+
$ref: "#/$defs/Str",
|
|
1232
|
+
});
|
|
1233
|
+
// the value position still wants the number form, so the two cannot share one def
|
|
1234
|
+
const key = z.number().meta({ id: "Shared" });
|
|
1235
|
+
expect(z.toJSONSchema(z.object({ a: key, b: z.record(key, z.string()) }))).toMatchObject({
|
|
1236
|
+
properties: { a: { $ref: "#/$defs/Shared" }, b: { propertyNames: { type: "string" } } },
|
|
1237
|
+
$defs: { Shared: { type: "number" } },
|
|
1238
|
+
});
|
|
1239
|
+
});
|
|
1240
|
+
|
|
1241
|
+
test("record key rewrite reaches a wrapped record", () => {
|
|
1242
|
+
// the flatten copies a record's properties onto its wrapper by reference, so the rewrite has to find every copy
|
|
1243
|
+
expect(z.toJSONSchema(z.record(z.number(), z.boolean()).optional()).propertyNames).toEqual({
|
|
1244
|
+
type: "string",
|
|
1245
|
+
pattern: "^-?\\d+(?:\\.\\d+)?$",
|
|
1246
|
+
});
|
|
1247
|
+
expect(z.toJSONSchema(z.object({ a: z.record(z.literal([1, 2]), z.boolean()).optional() }))).toMatchObject({
|
|
1248
|
+
properties: { a: { propertyNames: { type: "string", enum: ["1", "2"] }, required: ["1", "2"] } },
|
|
1249
|
+
});
|
|
1250
|
+
});
|
|
1251
|
+
|
|
1252
|
+
test("record with a recursive key converts without looping", () => {
|
|
1253
|
+
const numeric: any = z.lazy(() => z.union([z.number(), numeric]));
|
|
1254
|
+
expect(z.toJSONSchema(z.record(numeric, z.boolean())).propertyNames).toMatchObject({
|
|
1255
|
+
anyOf: [{ type: "string", pattern: "^-?\\d+(?:\\.\\d+)?$" }, { $ref: "#/$defs/__schema0" }],
|
|
1256
|
+
});
|
|
1257
|
+
// a key with nothing to re-express keeps the reference it had
|
|
1258
|
+
const stringy: any = z.lazy(() => z.union([z.string(), stringy]));
|
|
1259
|
+
expect(z.toJSONSchema(z.record(stringy, z.boolean())).propertyNames).toEqual({ $ref: "#/$defs/__schema0" });
|
|
1260
|
+
expect(
|
|
1261
|
+
z.toJSONSchema(z.record(z.union([z.literal("a"), z.literal("b")]).meta({ id: "Keys" }), z.boolean()))
|
|
1262
|
+
.propertyNames
|
|
1263
|
+
).toEqual({ $ref: "#/$defs/Keys" });
|
|
1264
|
+
});
|
|
1265
|
+
|
|
1266
|
+
test("record with a heterogeneous key stringifies only its numeric members", () => {
|
|
1267
|
+
// a mixed key carries no `type`, so the numeric members are caught by value rather than by type
|
|
1268
|
+
expect(z.toJSONSchema(z.record(z.literal(["a", 1]), z.boolean()))).toMatchObject({
|
|
1269
|
+
propertyNames: { enum: ["a", "1"] },
|
|
1270
|
+
required: ["a", "1"],
|
|
1271
|
+
});
|
|
1272
|
+
// a member no key can spell is left as it was, since the parser only ever retries a key as a number
|
|
1273
|
+
expect(z.toJSONSchema(z.record(z.literal(["a", true]) as any, z.boolean())).propertyNames).toEqual({
|
|
1274
|
+
enum: ["a", true],
|
|
1275
|
+
});
|
|
1276
|
+
});
|
|
1277
|
+
|
|
1278
|
+
test("record stringifies required for every target", () => {
|
|
1279
|
+
const schema = z.record(z.literal([1, 2]), z.boolean());
|
|
1280
|
+
for (const target of ["draft-2020-12", "draft-7", "draft-4", "openapi-3.0"] as const) {
|
|
1281
|
+
expect(z.toJSONSchema(schema, { target }).required).toEqual(["1", "2"]);
|
|
1282
|
+
}
|
|
1283
|
+
});
|
|
1284
|
+
|
|
1285
|
+
test("strict record with regex key uses propertyNames", () => {
|
|
1286
|
+
const schema = z.record(z.string().regex(/^label:[a-z]{2}$/), z.string());
|
|
1287
|
+
|
|
1288
|
+
expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
|
|
1289
|
+
{
|
|
1290
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1291
|
+
"additionalProperties": {
|
|
1292
|
+
"type": "string",
|
|
1293
|
+
},
|
|
1294
|
+
"propertyNames": {
|
|
1295
|
+
"pattern": "^label:[a-z]{2}$",
|
|
1296
|
+
"type": "string",
|
|
1297
|
+
},
|
|
1298
|
+
"type": "object",
|
|
1299
|
+
}
|
|
1300
|
+
`);
|
|
1301
|
+
});
|
|
1302
|
+
|
|
1303
|
+
test("looseRecord with regex key uses patternProperties", () => {
|
|
1304
|
+
const schema = z.looseRecord(z.string().regex(/^label:[a-z]{2}$/), z.string());
|
|
1305
|
+
|
|
1306
|
+
expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
|
|
1307
|
+
{
|
|
1308
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1309
|
+
"patternProperties": {
|
|
1310
|
+
"^label:[a-z]{2}$": {
|
|
1311
|
+
"type": "string",
|
|
1312
|
+
},
|
|
1313
|
+
},
|
|
1314
|
+
"type": "object",
|
|
1315
|
+
}
|
|
1316
|
+
`);
|
|
1317
|
+
});
|
|
1318
|
+
|
|
1319
|
+
test("looseRecord with multiple regex patterns uses patternProperties", () => {
|
|
1320
|
+
const schema = z.looseRecord(
|
|
1321
|
+
z
|
|
1322
|
+
.string()
|
|
1323
|
+
.regex(/^prefix_/)
|
|
1324
|
+
.regex(/_suffix$/),
|
|
1325
|
+
z.number()
|
|
1326
|
+
);
|
|
1327
|
+
|
|
1328
|
+
expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
|
|
1329
|
+
{
|
|
1330
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1331
|
+
"patternProperties": {
|
|
1332
|
+
"^prefix_": {
|
|
1333
|
+
"type": "number",
|
|
1334
|
+
},
|
|
1335
|
+
"_suffix$": {
|
|
1336
|
+
"type": "number",
|
|
1337
|
+
},
|
|
1338
|
+
},
|
|
1339
|
+
"type": "object",
|
|
1340
|
+
}
|
|
1341
|
+
`);
|
|
1342
|
+
});
|
|
1343
|
+
|
|
1344
|
+
test("looseRecord without regex key uses propertyNames", () => {
|
|
1345
|
+
// looseRecord with plain string key should still use propertyNames
|
|
1346
|
+
const schema = z.looseRecord(z.string(), z.boolean());
|
|
1347
|
+
|
|
1348
|
+
expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
|
|
1349
|
+
{
|
|
1350
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1351
|
+
"additionalProperties": {
|
|
1352
|
+
"type": "boolean",
|
|
1353
|
+
},
|
|
1354
|
+
"propertyNames": {
|
|
1355
|
+
"type": "string",
|
|
1356
|
+
},
|
|
1357
|
+
"type": "object",
|
|
1358
|
+
}
|
|
1359
|
+
`);
|
|
1360
|
+
});
|
|
1361
|
+
|
|
1362
|
+
test("intersection of object with looseRecord uses patternProperties", () => {
|
|
1363
|
+
const zLabeled = z.object({ label: z.string() });
|
|
1364
|
+
const zLocalizedLabeled = z.looseRecord(z.string().regex(/^label:[a-z]{2}$/), z.string());
|
|
1365
|
+
const schema = zLabeled.and(zLocalizedLabeled);
|
|
1366
|
+
|
|
1367
|
+
expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
|
|
1368
|
+
{
|
|
1369
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1370
|
+
"allOf": [
|
|
1371
|
+
{
|
|
1372
|
+
"additionalProperties": false,
|
|
1373
|
+
"properties": {
|
|
1374
|
+
"label": {
|
|
1375
|
+
"type": "string",
|
|
1376
|
+
},
|
|
1377
|
+
},
|
|
1378
|
+
"required": [
|
|
1379
|
+
"label",
|
|
1380
|
+
],
|
|
1381
|
+
"type": "object",
|
|
1382
|
+
},
|
|
1383
|
+
{
|
|
1384
|
+
"patternProperties": {
|
|
1385
|
+
"^label:[a-z]{2}$": {
|
|
1386
|
+
"type": "string",
|
|
1387
|
+
},
|
|
1388
|
+
},
|
|
1389
|
+
"type": "object",
|
|
1390
|
+
},
|
|
1391
|
+
],
|
|
1392
|
+
}
|
|
1393
|
+
`);
|
|
1394
|
+
});
|
|
1395
|
+
|
|
1396
|
+
test("tuple", () => {
|
|
1397
|
+
const schema = z.tuple([z.string(), z.number()]);
|
|
1398
|
+
expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
|
|
1399
|
+
{
|
|
1400
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1401
|
+
"items": false,
|
|
1402
|
+
"maxItems": 2,
|
|
1403
|
+
"minItems": 2,
|
|
1404
|
+
"prefixItems": [
|
|
1405
|
+
{
|
|
1406
|
+
"type": "string",
|
|
1407
|
+
},
|
|
1408
|
+
{
|
|
1409
|
+
"type": "number",
|
|
1410
|
+
},
|
|
1411
|
+
],
|
|
1412
|
+
"type": "array",
|
|
1413
|
+
}
|
|
1414
|
+
`);
|
|
1415
|
+
});
|
|
1416
|
+
|
|
1417
|
+
test("tuple with rest", () => {
|
|
1418
|
+
const schema = z.tuple([z.string(), z.number()]).rest(z.boolean());
|
|
1419
|
+
expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
|
|
1420
|
+
{
|
|
1421
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1422
|
+
"items": {
|
|
1423
|
+
"type": "boolean",
|
|
1424
|
+
},
|
|
1425
|
+
"minItems": 2,
|
|
1426
|
+
"prefixItems": [
|
|
1427
|
+
{
|
|
1428
|
+
"type": "string",
|
|
1429
|
+
},
|
|
1430
|
+
{
|
|
1431
|
+
"type": "number",
|
|
1432
|
+
},
|
|
1433
|
+
],
|
|
1434
|
+
"type": "array",
|
|
1435
|
+
}
|
|
1436
|
+
`);
|
|
1437
|
+
});
|
|
1438
|
+
|
|
1439
|
+
test("tuple openapi-3.0", () => {
|
|
1440
|
+
const schema = z.tuple([z.string(), z.number()]);
|
|
1441
|
+
const jsonSchema = z.toJSONSchema(schema, { target: "openapi-3.0" });
|
|
1442
|
+
validateOpenAPI30Schema(jsonSchema);
|
|
1443
|
+
expect(jsonSchema).toMatchInlineSnapshot(`
|
|
1444
|
+
{
|
|
1445
|
+
"items": {
|
|
1446
|
+
"anyOf": [
|
|
1447
|
+
{
|
|
1448
|
+
"type": "string",
|
|
1449
|
+
},
|
|
1450
|
+
{
|
|
1451
|
+
"type": "number",
|
|
1452
|
+
},
|
|
1453
|
+
],
|
|
1454
|
+
},
|
|
1455
|
+
"maxItems": 2,
|
|
1456
|
+
"minItems": 2,
|
|
1457
|
+
"type": "array",
|
|
1458
|
+
}
|
|
1459
|
+
`);
|
|
1460
|
+
});
|
|
1461
|
+
|
|
1462
|
+
test("tuple with rest openapi-3.0", () => {
|
|
1463
|
+
const schema = z.tuple([z.string(), z.number()]).rest(z.boolean());
|
|
1464
|
+
const jsonSchema = z.toJSONSchema(schema, { target: "openapi-3.0" });
|
|
1465
|
+
validateOpenAPI30Schema(jsonSchema);
|
|
1466
|
+
expect(jsonSchema).toMatchInlineSnapshot(`
|
|
1467
|
+
{
|
|
1468
|
+
"items": {
|
|
1469
|
+
"anyOf": [
|
|
1470
|
+
{
|
|
1471
|
+
"type": "string",
|
|
1472
|
+
},
|
|
1473
|
+
{
|
|
1474
|
+
"type": "number",
|
|
1475
|
+
},
|
|
1476
|
+
{
|
|
1477
|
+
"type": "boolean",
|
|
1478
|
+
},
|
|
1479
|
+
],
|
|
1480
|
+
},
|
|
1481
|
+
"minItems": 2,
|
|
1482
|
+
"type": "array",
|
|
1483
|
+
}
|
|
1484
|
+
`);
|
|
1485
|
+
});
|
|
1486
|
+
|
|
1487
|
+
test("tuple with null openapi-3.0", () => {
|
|
1488
|
+
const schema = z.tuple([z.string(), z.number(), z.null()]);
|
|
1489
|
+
const jsonSchema = z.toJSONSchema(schema, { target: "openapi-3.0" });
|
|
1490
|
+
validateOpenAPI30Schema(jsonSchema);
|
|
1491
|
+
expect(jsonSchema).toMatchInlineSnapshot(`
|
|
1492
|
+
{
|
|
1493
|
+
"items": {
|
|
1494
|
+
"anyOf": [
|
|
1495
|
+
{
|
|
1496
|
+
"type": "string",
|
|
1497
|
+
},
|
|
1498
|
+
{
|
|
1499
|
+
"type": "number",
|
|
1500
|
+
},
|
|
1501
|
+
{
|
|
1502
|
+
"enum": [
|
|
1503
|
+
null,
|
|
1504
|
+
],
|
|
1505
|
+
"nullable": true,
|
|
1506
|
+
"type": "string",
|
|
1507
|
+
},
|
|
1508
|
+
],
|
|
1509
|
+
},
|
|
1510
|
+
"maxItems": 3,
|
|
1511
|
+
"minItems": 3,
|
|
1512
|
+
"type": "array",
|
|
1513
|
+
}
|
|
1514
|
+
`);
|
|
1515
|
+
});
|
|
1516
|
+
|
|
1517
|
+
test("tuple draft-7", () => {
|
|
1518
|
+
const schema = z.tuple([z.string(), z.number()]);
|
|
1519
|
+
expect(z.toJSONSchema(schema, { target: "draft-7", io: "input" })).toMatchInlineSnapshot(`
|
|
1520
|
+
{
|
|
1521
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
1522
|
+
"additionalItems": false,
|
|
1523
|
+
"items": [
|
|
1524
|
+
{
|
|
1525
|
+
"type": "string",
|
|
1526
|
+
},
|
|
1527
|
+
{
|
|
1528
|
+
"type": "number",
|
|
1529
|
+
},
|
|
1530
|
+
],
|
|
1531
|
+
"maxItems": 2,
|
|
1532
|
+
"minItems": 2,
|
|
1533
|
+
"type": "array",
|
|
1534
|
+
}
|
|
1535
|
+
`);
|
|
1536
|
+
});
|
|
1537
|
+
|
|
1538
|
+
test("tuple with rest draft-7", () => {
|
|
1539
|
+
const schema = z.tuple([z.string(), z.number()]).rest(z.boolean());
|
|
1540
|
+
expect(z.toJSONSchema(schema, { target: "draft-7", io: "input" })).toMatchInlineSnapshot(`
|
|
1541
|
+
{
|
|
1542
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
1543
|
+
"additionalItems": {
|
|
1544
|
+
"type": "boolean",
|
|
1545
|
+
},
|
|
1546
|
+
"items": [
|
|
1547
|
+
{
|
|
1548
|
+
"type": "string",
|
|
1549
|
+
},
|
|
1550
|
+
{
|
|
1551
|
+
"type": "number",
|
|
1552
|
+
},
|
|
1553
|
+
],
|
|
1554
|
+
"minItems": 2,
|
|
1555
|
+
"type": "array",
|
|
1556
|
+
}
|
|
1557
|
+
`);
|
|
1558
|
+
});
|
|
1559
|
+
|
|
1560
|
+
test("tuple with rest draft-7 - issue #5151 regression test", () => {
|
|
1561
|
+
// This test addresses issue #5151: tuple with rest elements and ids in draft-7 had incorrect internal path handling affecting complex scenarios
|
|
1562
|
+
const primarySchema = z.string().meta({ id: "primary" });
|
|
1563
|
+
const restSchema = z.number().meta({ id: "rest" });
|
|
1564
|
+
const testSchema = z.tuple([primarySchema], restSchema);
|
|
1565
|
+
|
|
1566
|
+
// Test both final output structure AND internal path handling
|
|
1567
|
+
const capturedPaths: string[] = [];
|
|
1568
|
+
const result = z.toJSONSchema(testSchema, {
|
|
1569
|
+
target: "draft-7",
|
|
1570
|
+
override: (ctx) => capturedPaths.push(ctx.path.join("/")),
|
|
1571
|
+
});
|
|
1572
|
+
|
|
1573
|
+
// Verify correct draft-7 structure with metadata extraction
|
|
1574
|
+
expect(result).toMatchInlineSnapshot(`
|
|
1575
|
+
{
|
|
1576
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
1577
|
+
"additionalItems": {
|
|
1578
|
+
"$ref": "#/definitions/rest",
|
|
1579
|
+
},
|
|
1580
|
+
"definitions": {
|
|
1581
|
+
"primary": {
|
|
1582
|
+
"type": "string",
|
|
1583
|
+
},
|
|
1584
|
+
"rest": {
|
|
1585
|
+
"type": "number",
|
|
1586
|
+
},
|
|
1587
|
+
},
|
|
1588
|
+
"items": [
|
|
1589
|
+
{
|
|
1590
|
+
"$ref": "#/definitions/primary",
|
|
1591
|
+
},
|
|
1592
|
+
],
|
|
1593
|
+
"minItems": 1,
|
|
1594
|
+
"type": "array",
|
|
1595
|
+
}
|
|
1596
|
+
`);
|
|
1597
|
+
|
|
1598
|
+
// Verify internal paths are correct (this was the actual bug)
|
|
1599
|
+
expect(capturedPaths).toContain("items/0"); // prefix items should use "items" path
|
|
1600
|
+
expect(capturedPaths).toContain("additionalItems"); // rest should use "additionalItems" path
|
|
1601
|
+
expect(capturedPaths).not.toContain("prefixItems/0"); // should not use draft-2020-12 paths
|
|
1602
|
+
|
|
1603
|
+
// Structural validations
|
|
1604
|
+
expect(Array.isArray(result.items)).toBe(true);
|
|
1605
|
+
expect(result.additionalItems).toBeDefined();
|
|
1606
|
+
});
|
|
1607
|
+
|
|
1608
|
+
test("closed tuple length constraints - issue #6193", () => {
|
|
1609
|
+
const schema = z.tuple([z.string(), z.string(), z.object({ lang: z.string() })]);
|
|
1610
|
+
|
|
1611
|
+
expect(schema.safeParse(["a", "b", { lang: "en" }, "extra"]).success).toBe(false);
|
|
1612
|
+
|
|
1613
|
+
const draft2020 = z.toJSONSchema(schema, { target: "draft-2020-12" });
|
|
1614
|
+
expect(draft2020.items).toBe(false);
|
|
1615
|
+
expect(draft2020.minItems).toBe(3);
|
|
1616
|
+
expect(draft2020.maxItems).toBe(3);
|
|
1617
|
+
|
|
1618
|
+
const draft7 = z.toJSONSchema(schema, { target: "draft-7", io: "input" });
|
|
1619
|
+
expect(draft7.additionalItems).toBe(false);
|
|
1620
|
+
expect(draft7.minItems).toBe(3);
|
|
1621
|
+
expect(draft7.maxItems).toBe(3);
|
|
1622
|
+
|
|
1623
|
+
const openapi = z.toJSONSchema(schema, { target: "openapi-3.0" });
|
|
1624
|
+
validateOpenAPI30Schema(openapi);
|
|
1625
|
+
expect(openapi.minItems).toBe(3);
|
|
1626
|
+
expect(openapi.maxItems).toBe(3);
|
|
1627
|
+
});
|
|
1628
|
+
|
|
1629
|
+
test("closed tuple with optional trailing items", () => {
|
|
1630
|
+
const schema = z.tuple([z.string(), z.number().optional()]);
|
|
1631
|
+
|
|
1632
|
+
const draft2020 = z.toJSONSchema(schema, { target: "draft-2020-12" });
|
|
1633
|
+
expect(draft2020.items).toBe(false);
|
|
1634
|
+
expect(draft2020.minItems).toBe(1);
|
|
1635
|
+
expect(draft2020.maxItems).toBe(2);
|
|
1636
|
+
|
|
1637
|
+
const draft7 = z.toJSONSchema(schema, { target: "draft-7", io: "input" });
|
|
1638
|
+
expect(draft7.additionalItems).toBe(false);
|
|
1639
|
+
expect(draft7.minItems).toBe(1);
|
|
1640
|
+
expect(draft7.maxItems).toBe(2);
|
|
1641
|
+
});
|
|
1642
|
+
|
|
1643
|
+
test("empty closed tuple rejects extra elements", () => {
|
|
1644
|
+
const schema = z.tuple([]);
|
|
1645
|
+
|
|
1646
|
+
const draft2020 = z.toJSONSchema(schema, { target: "draft-2020-12" });
|
|
1647
|
+
expect(draft2020.items).toBe(false);
|
|
1648
|
+
expect(draft2020.maxItems).toBe(0);
|
|
1649
|
+
|
|
1650
|
+
const draft7 = z.toJSONSchema(schema, { target: "draft-7", io: "input" });
|
|
1651
|
+
expect(draft7.additionalItems).toBe(false);
|
|
1652
|
+
expect(draft7.maxItems).toBe(0);
|
|
1653
|
+
|
|
1654
|
+
const openapi = z.toJSONSchema(schema, { target: "openapi-3.0" });
|
|
1655
|
+
validateOpenAPI30Schema(openapi);
|
|
1656
|
+
expect(openapi.maxItems).toBe(0);
|
|
1657
|
+
});
|
|
1658
|
+
|
|
1659
|
+
test("closed tuple length respects io direction with defaults", () => {
|
|
1660
|
+
const schema = z.tuple([z.string(), z.string().default("x")]);
|
|
1661
|
+
|
|
1662
|
+
const input = z.toJSONSchema(schema, { target: "draft-2020-12", io: "input" });
|
|
1663
|
+
expect(input.items).toBe(false);
|
|
1664
|
+
expect(input.minItems).toBe(1);
|
|
1665
|
+
expect(input.maxItems).toBe(2);
|
|
1666
|
+
|
|
1667
|
+
const output = z.toJSONSchema(schema, { target: "draft-2020-12", io: "output" });
|
|
1668
|
+
expect(output.items).toBe(false);
|
|
1669
|
+
expect(output.minItems).toBe(2);
|
|
1670
|
+
expect(output.maxItems).toBe(2);
|
|
1671
|
+
});
|
|
1672
|
+
|
|
1673
|
+
test("closed tuple length resolves input optionality past transform and catch", () => {
|
|
1674
|
+
const minItems = (schema: z.core.$ZodType, io: "input" | "output") =>
|
|
1675
|
+
z.toJSONSchema(schema, { target: "draft-2020-12", io }).minItems;
|
|
1676
|
+
|
|
1677
|
+
// Both let the parser observe an absent slot, but declare a required input.
|
|
1678
|
+
const pre = z.tuple([z.string(), z.preprocess((v) => v, z.string())]);
|
|
1679
|
+
expect(minItems(pre, "input")).toBe(2);
|
|
1680
|
+
expect(minItems(pre, "output")).toBe(2);
|
|
1681
|
+
|
|
1682
|
+
const caught = z.tuple([z.string(), z.string().catch("x")]);
|
|
1683
|
+
expect(minItems(caught, "input")).toBe(2);
|
|
1684
|
+
expect(minItems(caught, "output")).toBe(2);
|
|
1685
|
+
|
|
1686
|
+
// Resolution passes through the wrapper rather than stopping at it.
|
|
1687
|
+
expect(minItems(z.tuple([z.string(), z.string().optional().catch("x")]), "input")).toBe(1);
|
|
1688
|
+
});
|
|
1689
|
+
|
|
1690
|
+
test("promise", () => {
|
|
1691
|
+
const schema = z.promise(z.string());
|
|
1692
|
+
expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
|
|
1693
|
+
{
|
|
1694
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1695
|
+
"type": "string",
|
|
1696
|
+
}
|
|
1697
|
+
`);
|
|
1698
|
+
});
|
|
1699
|
+
|
|
1700
|
+
test("lazy", () => {
|
|
1701
|
+
const schema = z.lazy(() => z.string());
|
|
1702
|
+
expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
|
|
1703
|
+
{
|
|
1704
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1705
|
+
"type": "string",
|
|
1706
|
+
}
|
|
1707
|
+
`);
|
|
1708
|
+
});
|
|
1709
|
+
|
|
1710
|
+
// enum
|
|
1711
|
+
test("enum", () => {
|
|
1712
|
+
const a = z.enum(["a", "b", "c"]);
|
|
1713
|
+
expect(z.toJSONSchema(a)).toMatchInlineSnapshot(`
|
|
1714
|
+
{
|
|
1715
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1716
|
+
"enum": [
|
|
1717
|
+
"a",
|
|
1718
|
+
"b",
|
|
1719
|
+
"c",
|
|
1720
|
+
],
|
|
1721
|
+
"type": "string",
|
|
1722
|
+
}
|
|
1723
|
+
`);
|
|
1724
|
+
|
|
1725
|
+
enum B {
|
|
1726
|
+
A = 0,
|
|
1727
|
+
B = 1,
|
|
1728
|
+
C = 2,
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
const b = z.enum(B);
|
|
1732
|
+
expect(z.toJSONSchema(b)).toMatchInlineSnapshot(`
|
|
1733
|
+
{
|
|
1734
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1735
|
+
"enum": [
|
|
1736
|
+
0,
|
|
1737
|
+
1,
|
|
1738
|
+
2,
|
|
1739
|
+
],
|
|
1740
|
+
"type": "number",
|
|
1741
|
+
}
|
|
1742
|
+
`);
|
|
1743
|
+
});
|
|
1744
|
+
|
|
1745
|
+
// literal
|
|
1746
|
+
test("literal", () => {
|
|
1747
|
+
const a = z.literal("hello");
|
|
1748
|
+
expect(z.toJSONSchema(a)).toMatchInlineSnapshot(`
|
|
1749
|
+
{
|
|
1750
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1751
|
+
"const": "hello",
|
|
1752
|
+
"type": "string",
|
|
1753
|
+
}
|
|
1754
|
+
`);
|
|
1755
|
+
|
|
1756
|
+
const b = z.literal(7);
|
|
1757
|
+
expect(z.toJSONSchema(b)).toMatchInlineSnapshot(`
|
|
1758
|
+
{
|
|
1759
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1760
|
+
"const": 7,
|
|
1761
|
+
"type": "number",
|
|
1762
|
+
}
|
|
1763
|
+
`);
|
|
1764
|
+
|
|
1765
|
+
const c = z.literal(["hello", undefined, null, 5, BigInt(1324)]);
|
|
1766
|
+
expect(() => z.toJSONSchema(c)).toThrow();
|
|
1767
|
+
|
|
1768
|
+
const d = z.literal(["hello", null, 5]);
|
|
1769
|
+
expect(z.toJSONSchema(d)).toMatchInlineSnapshot(`
|
|
1770
|
+
{
|
|
1771
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1772
|
+
"enum": [
|
|
1773
|
+
"hello",
|
|
1774
|
+
null,
|
|
1775
|
+
5,
|
|
1776
|
+
],
|
|
1777
|
+
}
|
|
1778
|
+
`);
|
|
1779
|
+
|
|
1780
|
+
const e = z.literal(["hello", "zod", "v4"]);
|
|
1781
|
+
expect(z.toJSONSchema(e)).toMatchInlineSnapshot(`
|
|
1782
|
+
{
|
|
1783
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1784
|
+
"enum": [
|
|
1785
|
+
"hello",
|
|
1786
|
+
"zod",
|
|
1787
|
+
"v4",
|
|
1788
|
+
],
|
|
1789
|
+
"type": "string",
|
|
1790
|
+
}
|
|
1791
|
+
`);
|
|
1792
|
+
});
|
|
1793
|
+
|
|
1794
|
+
test("literal draft-4", () => {
|
|
1795
|
+
const a = z.literal("hello");
|
|
1796
|
+
expect(z.toJSONSchema(a, { target: "draft-4" })).toMatchInlineSnapshot(`
|
|
1797
|
+
{
|
|
1798
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
|
1799
|
+
"enum": [
|
|
1800
|
+
"hello",
|
|
1801
|
+
],
|
|
1802
|
+
"type": "string",
|
|
1803
|
+
}
|
|
1804
|
+
`);
|
|
1805
|
+
});
|
|
1806
|
+
|
|
1807
|
+
// pipe
|
|
1808
|
+
test("pipe", () => {
|
|
1809
|
+
const schema = z
|
|
1810
|
+
.string()
|
|
1811
|
+
.transform((val) => Number.parseInt(val))
|
|
1812
|
+
.pipe(z.number());
|
|
1813
|
+
expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
|
|
1814
|
+
{
|
|
1815
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1816
|
+
"type": "number",
|
|
1817
|
+
}
|
|
1818
|
+
`);
|
|
1819
|
+
});
|
|
1820
|
+
|
|
1821
|
+
test("simple objects", () => {
|
|
1822
|
+
const schema = z.object({
|
|
1823
|
+
name: z.string(),
|
|
1824
|
+
age: z.number(),
|
|
1825
|
+
});
|
|
1826
|
+
|
|
1827
|
+
expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(
|
|
1828
|
+
`
|
|
1829
|
+
{
|
|
1830
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1831
|
+
"additionalProperties": false,
|
|
1832
|
+
"properties": {
|
|
1833
|
+
"age": {
|
|
1834
|
+
"type": "number",
|
|
1835
|
+
},
|
|
1836
|
+
"name": {
|
|
1837
|
+
"type": "string",
|
|
1838
|
+
},
|
|
1839
|
+
},
|
|
1840
|
+
"required": [
|
|
1841
|
+
"name",
|
|
1842
|
+
"age",
|
|
1843
|
+
],
|
|
1844
|
+
"type": "object",
|
|
1845
|
+
}
|
|
1846
|
+
`
|
|
1847
|
+
);
|
|
1848
|
+
});
|
|
1849
|
+
|
|
1850
|
+
test("additionalproperties in z.object", () => {
|
|
1851
|
+
const a = z.object({
|
|
1852
|
+
name: z.string(),
|
|
1853
|
+
});
|
|
1854
|
+
expect(z.toJSONSchema(a)).toMatchInlineSnapshot(`
|
|
1855
|
+
{
|
|
1856
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1857
|
+
"additionalProperties": false,
|
|
1858
|
+
"properties": {
|
|
1859
|
+
"name": {
|
|
1860
|
+
"type": "string",
|
|
1861
|
+
},
|
|
1862
|
+
},
|
|
1863
|
+
"required": [
|
|
1864
|
+
"name",
|
|
1865
|
+
],
|
|
1866
|
+
"type": "object",
|
|
1867
|
+
}
|
|
1868
|
+
`);
|
|
1869
|
+
expect(z.toJSONSchema(a, { io: "input" })).toMatchInlineSnapshot(`
|
|
1870
|
+
{
|
|
1871
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1872
|
+
"properties": {
|
|
1873
|
+
"name": {
|
|
1874
|
+
"type": "string",
|
|
1875
|
+
},
|
|
1876
|
+
},
|
|
1877
|
+
"required": [
|
|
1878
|
+
"name",
|
|
1879
|
+
],
|
|
1880
|
+
"type": "object",
|
|
1881
|
+
}
|
|
1882
|
+
`);
|
|
1883
|
+
expect(
|
|
1884
|
+
z.toJSONSchema(a, {
|
|
1885
|
+
io: "input",
|
|
1886
|
+
override(ctx) {
|
|
1887
|
+
const def = ctx.zodSchema._zod.def;
|
|
1888
|
+
if (def.type === "object" && !def.catchall) {
|
|
1889
|
+
(ctx.jsonSchema as z.core.JSONSchema.ObjectSchema).additionalProperties = false;
|
|
1890
|
+
}
|
|
1891
|
+
},
|
|
1892
|
+
})
|
|
1893
|
+
).toMatchInlineSnapshot(`
|
|
1894
|
+
{
|
|
1895
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1896
|
+
"additionalProperties": false,
|
|
1897
|
+
"properties": {
|
|
1898
|
+
"name": {
|
|
1899
|
+
"type": "string",
|
|
1900
|
+
},
|
|
1901
|
+
},
|
|
1902
|
+
"required": [
|
|
1903
|
+
"name",
|
|
1904
|
+
],
|
|
1905
|
+
"type": "object",
|
|
1906
|
+
}
|
|
1907
|
+
`);
|
|
1908
|
+
});
|
|
1909
|
+
|
|
1910
|
+
test("catchall objects", () => {
|
|
1911
|
+
const a = z.strictObject({
|
|
1912
|
+
name: z.string(),
|
|
1913
|
+
age: z.number(),
|
|
1914
|
+
});
|
|
1915
|
+
|
|
1916
|
+
expect(z.toJSONSchema(a)).toMatchInlineSnapshot(`
|
|
1917
|
+
{
|
|
1918
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1919
|
+
"additionalProperties": false,
|
|
1920
|
+
"properties": {
|
|
1921
|
+
"age": {
|
|
1922
|
+
"type": "number",
|
|
1923
|
+
},
|
|
1924
|
+
"name": {
|
|
1925
|
+
"type": "string",
|
|
1926
|
+
},
|
|
1927
|
+
},
|
|
1928
|
+
"required": [
|
|
1929
|
+
"name",
|
|
1930
|
+
"age",
|
|
1931
|
+
],
|
|
1932
|
+
"type": "object",
|
|
1933
|
+
}
|
|
1934
|
+
`);
|
|
1935
|
+
|
|
1936
|
+
const b = z
|
|
1937
|
+
.object({
|
|
1938
|
+
name: z.string(),
|
|
1939
|
+
})
|
|
1940
|
+
.catchall(z.string());
|
|
1941
|
+
|
|
1942
|
+
expect(z.toJSONSchema(b)).toMatchInlineSnapshot(`
|
|
1943
|
+
{
|
|
1944
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1945
|
+
"additionalProperties": {
|
|
1946
|
+
"type": "string",
|
|
1947
|
+
},
|
|
1948
|
+
"properties": {
|
|
1949
|
+
"name": {
|
|
1950
|
+
"type": "string",
|
|
1951
|
+
},
|
|
1952
|
+
},
|
|
1953
|
+
"required": [
|
|
1954
|
+
"name",
|
|
1955
|
+
],
|
|
1956
|
+
"type": "object",
|
|
1957
|
+
}
|
|
1958
|
+
`);
|
|
1959
|
+
|
|
1960
|
+
const c = z.looseObject({
|
|
1961
|
+
name: z.string(),
|
|
1962
|
+
});
|
|
1963
|
+
|
|
1964
|
+
expect(z.toJSONSchema(c)).toMatchInlineSnapshot(`
|
|
1965
|
+
{
|
|
1966
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1967
|
+
"additionalProperties": {},
|
|
1968
|
+
"properties": {
|
|
1969
|
+
"name": {
|
|
1970
|
+
"type": "string",
|
|
1971
|
+
},
|
|
1972
|
+
},
|
|
1973
|
+
"required": [
|
|
1974
|
+
"name",
|
|
1975
|
+
],
|
|
1976
|
+
"type": "object",
|
|
1977
|
+
}
|
|
1978
|
+
`);
|
|
1979
|
+
});
|
|
1980
|
+
|
|
1981
|
+
test("optional fields - object", () => {
|
|
1982
|
+
const schema = z.object({
|
|
1983
|
+
required: z.string(),
|
|
1984
|
+
optional: z.string().optional(),
|
|
1985
|
+
nonoptional: z.string().optional().nonoptional(),
|
|
1986
|
+
});
|
|
1987
|
+
|
|
1988
|
+
const result = z.toJSONSchema(schema);
|
|
1989
|
+
|
|
1990
|
+
expect(result).toMatchInlineSnapshot(`
|
|
1991
|
+
{
|
|
1992
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
1993
|
+
"additionalProperties": false,
|
|
1994
|
+
"properties": {
|
|
1995
|
+
"nonoptional": {
|
|
1996
|
+
"type": "string",
|
|
1997
|
+
},
|
|
1998
|
+
"optional": {
|
|
1999
|
+
"type": "string",
|
|
2000
|
+
},
|
|
2001
|
+
"required": {
|
|
2002
|
+
"type": "string",
|
|
2003
|
+
},
|
|
2004
|
+
},
|
|
2005
|
+
"required": [
|
|
2006
|
+
"required",
|
|
2007
|
+
"nonoptional",
|
|
2008
|
+
],
|
|
2009
|
+
"type": "object",
|
|
2010
|
+
}
|
|
2011
|
+
`);
|
|
2012
|
+
});
|
|
2013
|
+
|
|
2014
|
+
test("recursive object", () => {
|
|
2015
|
+
interface Category {
|
|
2016
|
+
name: string;
|
|
2017
|
+
subcategories: Category[];
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
const categorySchema: z.ZodType<Category> = z.object({
|
|
2021
|
+
name: z.string(),
|
|
2022
|
+
subcategories: z.array(z.lazy(() => categorySchema)),
|
|
2023
|
+
});
|
|
2024
|
+
|
|
2025
|
+
const result = z.toJSONSchema(categorySchema);
|
|
2026
|
+
expect(result).toMatchInlineSnapshot(`
|
|
2027
|
+
{
|
|
2028
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2029
|
+
"additionalProperties": false,
|
|
2030
|
+
"properties": {
|
|
2031
|
+
"name": {
|
|
2032
|
+
"type": "string",
|
|
2033
|
+
},
|
|
2034
|
+
"subcategories": {
|
|
2035
|
+
"items": {
|
|
2036
|
+
"$ref": "#",
|
|
2037
|
+
},
|
|
2038
|
+
"type": "array",
|
|
2039
|
+
},
|
|
2040
|
+
},
|
|
2041
|
+
"required": [
|
|
2042
|
+
"name",
|
|
2043
|
+
"subcategories",
|
|
2044
|
+
],
|
|
2045
|
+
"type": "object",
|
|
2046
|
+
}
|
|
2047
|
+
`);
|
|
2048
|
+
});
|
|
2049
|
+
|
|
2050
|
+
test("simple interface", () => {
|
|
2051
|
+
const userSchema = z.object({
|
|
2052
|
+
name: z.string(),
|
|
2053
|
+
age: z.number().optional(),
|
|
2054
|
+
});
|
|
2055
|
+
|
|
2056
|
+
const result = z.toJSONSchema(userSchema);
|
|
2057
|
+
expect(result).toMatchInlineSnapshot(`
|
|
2058
|
+
{
|
|
2059
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2060
|
+
"additionalProperties": false,
|
|
2061
|
+
"properties": {
|
|
2062
|
+
"age": {
|
|
2063
|
+
"type": "number",
|
|
2064
|
+
},
|
|
2065
|
+
"name": {
|
|
2066
|
+
"type": "string",
|
|
2067
|
+
},
|
|
2068
|
+
},
|
|
2069
|
+
"required": [
|
|
2070
|
+
"name",
|
|
2071
|
+
],
|
|
2072
|
+
"type": "object",
|
|
2073
|
+
}
|
|
2074
|
+
`);
|
|
2075
|
+
});
|
|
2076
|
+
|
|
2077
|
+
test("catchall interface", () => {
|
|
2078
|
+
const a = z.strictObject({
|
|
2079
|
+
name: z.string(),
|
|
2080
|
+
age: z.number(),
|
|
2081
|
+
});
|
|
2082
|
+
|
|
2083
|
+
expect(z.toJSONSchema(a)).toMatchInlineSnapshot(`
|
|
2084
|
+
{
|
|
2085
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2086
|
+
"additionalProperties": false,
|
|
2087
|
+
"properties": {
|
|
2088
|
+
"age": {
|
|
2089
|
+
"type": "number",
|
|
2090
|
+
},
|
|
2091
|
+
"name": {
|
|
2092
|
+
"type": "string",
|
|
2093
|
+
},
|
|
2094
|
+
},
|
|
2095
|
+
"required": [
|
|
2096
|
+
"name",
|
|
2097
|
+
"age",
|
|
2098
|
+
],
|
|
2099
|
+
"type": "object",
|
|
2100
|
+
}
|
|
2101
|
+
`);
|
|
2102
|
+
|
|
2103
|
+
const b = z
|
|
2104
|
+
.object({
|
|
2105
|
+
name: z.string(),
|
|
2106
|
+
})
|
|
2107
|
+
.catchall(z.string());
|
|
2108
|
+
|
|
2109
|
+
expect(z.toJSONSchema(b)).toMatchInlineSnapshot(`
|
|
2110
|
+
{
|
|
2111
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2112
|
+
"additionalProperties": {
|
|
2113
|
+
"type": "string",
|
|
2114
|
+
},
|
|
2115
|
+
"properties": {
|
|
2116
|
+
"name": {
|
|
2117
|
+
"type": "string",
|
|
2118
|
+
},
|
|
2119
|
+
},
|
|
2120
|
+
"required": [
|
|
2121
|
+
"name",
|
|
2122
|
+
],
|
|
2123
|
+
"type": "object",
|
|
2124
|
+
}
|
|
2125
|
+
`);
|
|
2126
|
+
|
|
2127
|
+
const c = z.looseObject({
|
|
2128
|
+
name: z.string(),
|
|
2129
|
+
});
|
|
2130
|
+
|
|
2131
|
+
expect(z.toJSONSchema(c)).toMatchInlineSnapshot(`
|
|
2132
|
+
{
|
|
2133
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2134
|
+
"additionalProperties": {},
|
|
2135
|
+
"properties": {
|
|
2136
|
+
"name": {
|
|
2137
|
+
"type": "string",
|
|
2138
|
+
},
|
|
2139
|
+
},
|
|
2140
|
+
"required": [
|
|
2141
|
+
"name",
|
|
2142
|
+
],
|
|
2143
|
+
"type": "object",
|
|
2144
|
+
}
|
|
2145
|
+
`);
|
|
2146
|
+
});
|
|
2147
|
+
|
|
2148
|
+
test("recursive interface schemas", () => {
|
|
2149
|
+
const TreeNodeSchema = z.object({
|
|
2150
|
+
id: z.string(),
|
|
2151
|
+
get children() {
|
|
2152
|
+
return TreeNodeSchema;
|
|
2153
|
+
},
|
|
2154
|
+
});
|
|
2155
|
+
|
|
2156
|
+
const result = z.toJSONSchema(TreeNodeSchema);
|
|
2157
|
+
|
|
2158
|
+
// Should have definitions for recursive schema
|
|
2159
|
+
expect(JSON.stringify(result, null, 2)).toMatchInlineSnapshot(
|
|
2160
|
+
`
|
|
2161
|
+
"{
|
|
2162
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2163
|
+
"type": "object",
|
|
2164
|
+
"properties": {
|
|
2165
|
+
"id": {
|
|
2166
|
+
"type": "string"
|
|
2167
|
+
},
|
|
2168
|
+
"children": {
|
|
2169
|
+
"$ref": "#"
|
|
2170
|
+
}
|
|
2171
|
+
},
|
|
2172
|
+
"required": [
|
|
2173
|
+
"id",
|
|
2174
|
+
"children"
|
|
2175
|
+
],
|
|
2176
|
+
"additionalProperties": false
|
|
2177
|
+
}"
|
|
2178
|
+
`
|
|
2179
|
+
);
|
|
2180
|
+
});
|
|
2181
|
+
|
|
2182
|
+
test("mutually recursive interface schemas", () => {
|
|
2183
|
+
const FolderSchema = z.object({
|
|
2184
|
+
name: z.string(),
|
|
2185
|
+
get files() {
|
|
2186
|
+
return z.array(FileSchema);
|
|
2187
|
+
},
|
|
2188
|
+
});
|
|
2189
|
+
|
|
2190
|
+
const FileSchema = z.object({
|
|
2191
|
+
name: z.string(),
|
|
2192
|
+
get parent() {
|
|
2193
|
+
return FolderSchema;
|
|
2194
|
+
},
|
|
2195
|
+
});
|
|
2196
|
+
|
|
2197
|
+
const result = z.toJSONSchema(FolderSchema);
|
|
2198
|
+
|
|
2199
|
+
// Should have definitions for both schemas
|
|
2200
|
+
expect(JSON.stringify(result, null, 2)).toMatchInlineSnapshot(
|
|
2201
|
+
`
|
|
2202
|
+
"{
|
|
2203
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2204
|
+
"type": "object",
|
|
2205
|
+
"properties": {
|
|
2206
|
+
"name": {
|
|
2207
|
+
"type": "string"
|
|
2208
|
+
},
|
|
2209
|
+
"files": {
|
|
2210
|
+
"type": "array",
|
|
2211
|
+
"items": {
|
|
2212
|
+
"type": "object",
|
|
2213
|
+
"properties": {
|
|
2214
|
+
"name": {
|
|
2215
|
+
"type": "string"
|
|
2216
|
+
},
|
|
2217
|
+
"parent": {
|
|
2218
|
+
"$ref": "#"
|
|
2219
|
+
}
|
|
2220
|
+
},
|
|
2221
|
+
"required": [
|
|
2222
|
+
"name",
|
|
2223
|
+
"parent"
|
|
2224
|
+
],
|
|
2225
|
+
"additionalProperties": false
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
},
|
|
2229
|
+
"required": [
|
|
2230
|
+
"name",
|
|
2231
|
+
"files"
|
|
2232
|
+
],
|
|
2233
|
+
"additionalProperties": false
|
|
2234
|
+
}"
|
|
2235
|
+
`
|
|
2236
|
+
);
|
|
2237
|
+
});
|
|
2238
|
+
});
|
|
2239
|
+
|
|
2240
|
+
test("override", () => {
|
|
2241
|
+
const schema = z.toJSONSchema(z.string(), {
|
|
2242
|
+
override: (ctx) => {
|
|
2243
|
+
ctx.zodSchema;
|
|
2244
|
+
ctx.jsonSchema;
|
|
2245
|
+
ctx.jsonSchema.whatever = "sup";
|
|
2246
|
+
},
|
|
2247
|
+
});
|
|
2248
|
+
expect(schema).toMatchInlineSnapshot(`
|
|
2249
|
+
{
|
|
2250
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2251
|
+
"type": "string",
|
|
2252
|
+
"whatever": "sup",
|
|
2253
|
+
}
|
|
2254
|
+
`);
|
|
2255
|
+
});
|
|
2256
|
+
|
|
2257
|
+
test("override: do not run on references", () => {
|
|
2258
|
+
let overrideCount = 0;
|
|
2259
|
+
const schema = z
|
|
2260
|
+
.union([z.string().date(), z.string().datetime(), z.string().datetime({ local: true })])
|
|
2261
|
+
.meta({ a: true })
|
|
2262
|
+
.transform((str) => new Date(str))
|
|
2263
|
+
.meta({ b: true })
|
|
2264
|
+
.pipe(z.date())
|
|
2265
|
+
.meta({ c: true })
|
|
2266
|
+
.brand("dateIn");
|
|
2267
|
+
z.toJSONSchema(schema, {
|
|
2268
|
+
unrepresentable: "any",
|
|
2269
|
+
io: "input",
|
|
2270
|
+
override(_) {
|
|
2271
|
+
overrideCount++;
|
|
2272
|
+
},
|
|
2273
|
+
});
|
|
2274
|
+
|
|
2275
|
+
expect(overrideCount).toBe(12);
|
|
2276
|
+
});
|
|
2277
|
+
|
|
2278
|
+
test("override with refs", () => {
|
|
2279
|
+
const a = z.string().optional();
|
|
2280
|
+
const result = z.toJSONSchema(a, {
|
|
2281
|
+
override(ctx) {
|
|
2282
|
+
if (ctx.zodSchema._zod.def.type === "string") {
|
|
2283
|
+
ctx.jsonSchema.type = "STRING" as "string";
|
|
2284
|
+
}
|
|
2285
|
+
},
|
|
2286
|
+
});
|
|
2287
|
+
|
|
2288
|
+
expect(result).toMatchInlineSnapshot(`
|
|
2289
|
+
{
|
|
2290
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2291
|
+
"type": "STRING",
|
|
2292
|
+
}
|
|
2293
|
+
`);
|
|
2294
|
+
});
|
|
2295
|
+
|
|
2296
|
+
test("override execution order", () => {
|
|
2297
|
+
const schema = z.union([z.string(), z.number()]);
|
|
2298
|
+
let unionSchema!: any;
|
|
2299
|
+
z.toJSONSchema(schema, {
|
|
2300
|
+
override(ctx) {
|
|
2301
|
+
if (ctx.zodSchema._zod.def.type === "union") {
|
|
2302
|
+
unionSchema = ctx.jsonSchema;
|
|
2303
|
+
}
|
|
2304
|
+
},
|
|
2305
|
+
});
|
|
2306
|
+
|
|
2307
|
+
expect(unionSchema).toMatchInlineSnapshot(`
|
|
2308
|
+
{
|
|
2309
|
+
"type": [
|
|
2310
|
+
"string",
|
|
2311
|
+
"number",
|
|
2312
|
+
],
|
|
2313
|
+
}
|
|
2314
|
+
`);
|
|
2315
|
+
});
|
|
2316
|
+
|
|
2317
|
+
test("override with path", () => {
|
|
2318
|
+
const userSchema = z.object({
|
|
2319
|
+
name: z.string(),
|
|
2320
|
+
age: z.number(),
|
|
2321
|
+
});
|
|
2322
|
+
|
|
2323
|
+
const capturedPaths: (string | number)[][] = [];
|
|
2324
|
+
|
|
2325
|
+
z.toJSONSchema(userSchema, {
|
|
2326
|
+
override(ctx) {
|
|
2327
|
+
capturedPaths.push(ctx.path);
|
|
2328
|
+
},
|
|
2329
|
+
});
|
|
2330
|
+
|
|
2331
|
+
expect(capturedPaths).toMatchInlineSnapshot(`
|
|
2332
|
+
[
|
|
2333
|
+
[
|
|
2334
|
+
"properties",
|
|
2335
|
+
"age",
|
|
2336
|
+
],
|
|
2337
|
+
[
|
|
2338
|
+
"properties",
|
|
2339
|
+
"name",
|
|
2340
|
+
],
|
|
2341
|
+
[],
|
|
2342
|
+
]
|
|
2343
|
+
`);
|
|
2344
|
+
});
|
|
2345
|
+
|
|
2346
|
+
test("pipe", () => {
|
|
2347
|
+
const mySchema = z
|
|
2348
|
+
.string()
|
|
2349
|
+
.transform((val) => val.length)
|
|
2350
|
+
.pipe(z.number());
|
|
2351
|
+
// ZodPipe
|
|
2352
|
+
|
|
2353
|
+
const a = z.toJSONSchema(mySchema);
|
|
2354
|
+
expect(a).toMatchInlineSnapshot(`
|
|
2355
|
+
{
|
|
2356
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2357
|
+
"type": "number",
|
|
2358
|
+
}
|
|
2359
|
+
`);
|
|
2360
|
+
// => { type: "number" }
|
|
2361
|
+
|
|
2362
|
+
const b = z.toJSONSchema(mySchema, { io: "input" });
|
|
2363
|
+
expect(b).toMatchInlineSnapshot(`
|
|
2364
|
+
{
|
|
2365
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2366
|
+
"type": "string",
|
|
2367
|
+
}
|
|
2368
|
+
`);
|
|
2369
|
+
// => { type: "string" }
|
|
2370
|
+
});
|
|
2371
|
+
|
|
2372
|
+
test("passthrough schemas", () => {
|
|
2373
|
+
const Internal = z.object({
|
|
2374
|
+
num: z.number(),
|
|
2375
|
+
str: z.string(),
|
|
2376
|
+
});
|
|
2377
|
+
//.meta({ id: "Internal" });
|
|
2378
|
+
|
|
2379
|
+
const External = z.object({
|
|
2380
|
+
a: Internal,
|
|
2381
|
+
b: Internal.optional(),
|
|
2382
|
+
c: z.lazy(() => Internal),
|
|
2383
|
+
d: z.promise(Internal),
|
|
2384
|
+
e: z.pipe(Internal, Internal),
|
|
2385
|
+
});
|
|
2386
|
+
|
|
2387
|
+
const result = z.toJSONSchema(External, {
|
|
2388
|
+
reused: "ref",
|
|
2389
|
+
});
|
|
2390
|
+
expect(result).toMatchInlineSnapshot(`
|
|
2391
|
+
{
|
|
2392
|
+
"$defs": {
|
|
2393
|
+
"__schema0": {
|
|
2394
|
+
"additionalProperties": false,
|
|
2395
|
+
"properties": {
|
|
2396
|
+
"num": {
|
|
2397
|
+
"type": "number",
|
|
2398
|
+
},
|
|
2399
|
+
"str": {
|
|
2400
|
+
"type": "string",
|
|
2401
|
+
},
|
|
2402
|
+
},
|
|
2403
|
+
"required": [
|
|
2404
|
+
"num",
|
|
2405
|
+
"str",
|
|
2406
|
+
],
|
|
2407
|
+
"type": "object",
|
|
2408
|
+
},
|
|
2409
|
+
},
|
|
2410
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2411
|
+
"additionalProperties": false,
|
|
2412
|
+
"properties": {
|
|
2413
|
+
"a": {
|
|
2414
|
+
"$ref": "#/$defs/__schema0",
|
|
2415
|
+
},
|
|
2416
|
+
"b": {
|
|
2417
|
+
"$ref": "#/$defs/__schema0",
|
|
2418
|
+
},
|
|
2419
|
+
"c": {
|
|
2420
|
+
"$ref": "#/$defs/__schema0",
|
|
2421
|
+
},
|
|
2422
|
+
"d": {
|
|
2423
|
+
"$ref": "#/$defs/__schema0",
|
|
2424
|
+
},
|
|
2425
|
+
"e": {
|
|
2426
|
+
"$ref": "#/$defs/__schema0",
|
|
2427
|
+
},
|
|
2428
|
+
},
|
|
2429
|
+
"required": [
|
|
2430
|
+
"a",
|
|
2431
|
+
"c",
|
|
2432
|
+
"d",
|
|
2433
|
+
"e",
|
|
2434
|
+
],
|
|
2435
|
+
"type": "object",
|
|
2436
|
+
}
|
|
2437
|
+
`);
|
|
2438
|
+
});
|
|
2439
|
+
|
|
2440
|
+
test("extract schemas with id", () => {
|
|
2441
|
+
const name = z.string().meta({ id: "name" });
|
|
2442
|
+
const result = z.toJSONSchema(
|
|
2443
|
+
z.object({
|
|
2444
|
+
first_name: name,
|
|
2445
|
+
last_name: name.nullable(),
|
|
2446
|
+
middle_name: name.optional(),
|
|
2447
|
+
age: z.number().meta({ id: "age" }),
|
|
2448
|
+
})
|
|
2449
|
+
);
|
|
2450
|
+
expect(result).toMatchInlineSnapshot(`
|
|
2451
|
+
{
|
|
2452
|
+
"$defs": {
|
|
2453
|
+
"age": {
|
|
2454
|
+
"type": "number",
|
|
2455
|
+
},
|
|
2456
|
+
"name": {
|
|
2457
|
+
"type": "string",
|
|
2458
|
+
},
|
|
2459
|
+
},
|
|
2460
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2461
|
+
"additionalProperties": false,
|
|
2462
|
+
"properties": {
|
|
2463
|
+
"age": {
|
|
2464
|
+
"$ref": "#/$defs/age",
|
|
2465
|
+
},
|
|
2466
|
+
"first_name": {
|
|
2467
|
+
"$ref": "#/$defs/name",
|
|
2468
|
+
},
|
|
2469
|
+
"last_name": {
|
|
2470
|
+
"anyOf": [
|
|
2471
|
+
{
|
|
2472
|
+
"$ref": "#/$defs/name",
|
|
2473
|
+
},
|
|
2474
|
+
{
|
|
2475
|
+
"type": "null",
|
|
2476
|
+
},
|
|
2477
|
+
],
|
|
2478
|
+
},
|
|
2479
|
+
"middle_name": {
|
|
2480
|
+
"$ref": "#/$defs/name",
|
|
2481
|
+
},
|
|
2482
|
+
},
|
|
2483
|
+
"required": [
|
|
2484
|
+
"first_name",
|
|
2485
|
+
"last_name",
|
|
2486
|
+
"age",
|
|
2487
|
+
],
|
|
2488
|
+
"type": "object",
|
|
2489
|
+
}
|
|
2490
|
+
`);
|
|
2491
|
+
});
|
|
2492
|
+
|
|
2493
|
+
test("escapes JSON Pointer reserved characters in $ref but not in $defs key", () => {
|
|
2494
|
+
const User = z.object({ name: z.string() }).meta({ id: "Shared/User~" });
|
|
2495
|
+
const result = z.toJSONSchema(z.object({ User }));
|
|
2496
|
+
// the $ref pointer escapes `/` -> `~1` and `~` -> `~0` (RFC 6901),
|
|
2497
|
+
// while the $defs key keeps the original id
|
|
2498
|
+
expect((result.properties!.User as any).$ref).toBe("#/$defs/Shared~1User~0");
|
|
2499
|
+
expect(Object.keys(result.$defs!)).toEqual(["Shared/User~"]);
|
|
2500
|
+
});
|
|
2501
|
+
|
|
2502
|
+
test("escapes JSON Pointer reserved characters in the root $ref", () => {
|
|
2503
|
+
const User = z.object({ name: z.string() }).meta({ id: "Shared/User~" });
|
|
2504
|
+
const result = z.toJSONSchema(User);
|
|
2505
|
+
expect(result.$ref).toBe("#/$defs/Shared~1User~0");
|
|
2506
|
+
expect(Object.keys(result.$defs!)).toEqual(["Shared/User~"]);
|
|
2507
|
+
});
|
|
2508
|
+
|
|
2509
|
+
test("a multipleOf divisor JSON Schema cannot express goes through `unrepresentable`", () => {
|
|
2510
|
+
// the keyword must be strictly greater than zero, and NaN/Infinity do not survive JSON at all
|
|
2511
|
+
for (const divisor of [0, Number.NaN, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY]) {
|
|
2512
|
+
expect(() => z.toJSONSchema(z.number().multipleOf(divisor))).toThrow(/cannot be represented in JSON Schema/);
|
|
2513
|
+
expect(z.toJSONSchema(z.number().multipleOf(divisor), { unrepresentable: "any" })).toMatchObject({
|
|
2514
|
+
type: "number",
|
|
2515
|
+
});
|
|
2516
|
+
expect(z.toJSONSchema(z.number().multipleOf(divisor), { unrepresentable: "any" })).not.toHaveProperty("multipleOf");
|
|
2517
|
+
}
|
|
2518
|
+
|
|
2519
|
+
// a negative divisor accepts exactly what its absolute value accepts, so it still maps
|
|
2520
|
+
expect(z.number().multipleOf(-5).safeParse(10).success).toEqual(true);
|
|
2521
|
+
expect(z.number().multipleOf(-5).safeParse(13).success).toEqual(false);
|
|
2522
|
+
expect(z.toJSONSchema(z.number().multipleOf(-5))).toMatchObject({ multipleOf: 5 });
|
|
2523
|
+
expect(z.toJSONSchema(z.number().multipleOf(0.1))).toMatchObject({ multipleOf: 0.1 });
|
|
2524
|
+
});
|
|
2525
|
+
|
|
2526
|
+
test("unrepresentable default values go through `unrepresentable`", () => {
|
|
2527
|
+
// a bigint default has no reliable JSON encoding, so it is dropped rather than approximated
|
|
2528
|
+
expect(z.toJSONSchema(z.bigint().default(0n), { unrepresentable: "any" })).toMatchInlineSnapshot(`
|
|
2529
|
+
{
|
|
2530
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2531
|
+
}
|
|
2532
|
+
`);
|
|
2533
|
+
expect(z.toJSONSchema(z.bigint().prefault(2n), { io: "input", unrepresentable: "any" })).toMatchInlineSnapshot(`
|
|
2534
|
+
{
|
|
2535
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2536
|
+
}
|
|
2537
|
+
`);
|
|
2538
|
+
// including when nested inside an otherwise representable default
|
|
2539
|
+
expect(
|
|
2540
|
+
z.toJSONSchema(z.object({ a: z.bigint() }).default({ a: 1n }), { unrepresentable: "any" })
|
|
2541
|
+
).toMatchInlineSnapshot(`
|
|
2542
|
+
{
|
|
2543
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2544
|
+
"additionalProperties": false,
|
|
2545
|
+
"properties": {
|
|
2546
|
+
"a": {},
|
|
2547
|
+
},
|
|
2548
|
+
"required": [
|
|
2549
|
+
"a",
|
|
2550
|
+
],
|
|
2551
|
+
"type": "object",
|
|
2552
|
+
}
|
|
2553
|
+
`);
|
|
2554
|
+
|
|
2555
|
+
// under the default strict mode the inner type throws first; a representable inner type surfaces the default's own error rather than a raw `JSON.stringify` TypeError
|
|
2556
|
+
expect(() => z.toJSONSchema(z.bigint().default(0n))).toThrow("BigInt cannot be represented in JSON Schema");
|
|
2557
|
+
expect(() => z.toJSONSchema(z.unknown().default(1n))).toThrow("BigInt defaults cannot be represented in JSON Schema");
|
|
2558
|
+
|
|
2559
|
+
// representable defaults are untouched
|
|
2560
|
+
expect(z.toJSONSchema(z.object({ a: z.number() }).default({ a: 2 }))).toMatchInlineSnapshot(`
|
|
2561
|
+
{
|
|
2562
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2563
|
+
"additionalProperties": false,
|
|
2564
|
+
"default": {
|
|
2565
|
+
"a": 2,
|
|
2566
|
+
},
|
|
2567
|
+
"properties": {
|
|
2568
|
+
"a": {
|
|
2569
|
+
"type": "number",
|
|
2570
|
+
},
|
|
2571
|
+
},
|
|
2572
|
+
"required": [
|
|
2573
|
+
"a",
|
|
2574
|
+
],
|
|
2575
|
+
"type": "object",
|
|
2576
|
+
}
|
|
2577
|
+
`);
|
|
2578
|
+
});
|
|
2579
|
+
|
|
2580
|
+
test("an `unrepresentable` handler can represent a bigint default", () => {
|
|
2581
|
+
// one handler covers both the type and its default, so no `unrepresentable: "any"` is needed and every other unrepresentable type still throws
|
|
2582
|
+
expect(
|
|
2583
|
+
z.toJSONSchema(z.object({ startAt: z.coerce.bigint().optional().default(0n) }), {
|
|
2584
|
+
io: "input",
|
|
2585
|
+
unrepresentable: ({ zodSchema }) => {
|
|
2586
|
+
const def = zodSchema._zod.def;
|
|
2587
|
+
if (def.type === "bigint") return { type: "integer", format: "int64" };
|
|
2588
|
+
if (def.type === "default") return { default: String(def.defaultValue) };
|
|
2589
|
+
return "throw";
|
|
2590
|
+
},
|
|
2591
|
+
})
|
|
2592
|
+
).toMatchInlineSnapshot(`
|
|
2593
|
+
{
|
|
2594
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2595
|
+
"properties": {
|
|
2596
|
+
"startAt": {
|
|
2597
|
+
"default": "0",
|
|
2598
|
+
"format": "int64",
|
|
2599
|
+
"type": "integer",
|
|
2600
|
+
},
|
|
2601
|
+
},
|
|
2602
|
+
"type": "object",
|
|
2603
|
+
}
|
|
2604
|
+
`);
|
|
2605
|
+
|
|
2606
|
+
// a handler may also drop just the default while still representing the type
|
|
2607
|
+
expect(
|
|
2608
|
+
z.toJSONSchema(z.bigint().default(0n), {
|
|
2609
|
+
unrepresentable: ({ zodSchema }) =>
|
|
2610
|
+
zodSchema._zod.def.type === "bigint" ? { type: "integer", format: "int64" } : "any",
|
|
2611
|
+
})
|
|
2612
|
+
).toMatchInlineSnapshot(`
|
|
2613
|
+
{
|
|
2614
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2615
|
+
"format": "int64",
|
|
2616
|
+
"type": "integer",
|
|
2617
|
+
}
|
|
2618
|
+
`);
|
|
2619
|
+
});
|
|
2620
|
+
|
|
2621
|
+
test("unrepresentable literal values are ignored", () => {
|
|
2622
|
+
const a = z.toJSONSchema(z.literal(["hello", null, 5, BigInt(1324), undefined]), { unrepresentable: "any" });
|
|
2623
|
+
expect(a).toMatchInlineSnapshot(`
|
|
2624
|
+
{
|
|
2625
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2626
|
+
"enum": [
|
|
2627
|
+
"hello",
|
|
2628
|
+
null,
|
|
2629
|
+
5,
|
|
2630
|
+
1324,
|
|
2631
|
+
],
|
|
2632
|
+
}
|
|
2633
|
+
`);
|
|
2634
|
+
|
|
2635
|
+
const b = z.toJSONSchema(z.literal([undefined, null, 5, BigInt(1324)]), {
|
|
2636
|
+
unrepresentable: "any",
|
|
2637
|
+
});
|
|
2638
|
+
expect(b).toMatchInlineSnapshot(`
|
|
2639
|
+
{
|
|
2640
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2641
|
+
"enum": [
|
|
2642
|
+
null,
|
|
2643
|
+
5,
|
|
2644
|
+
1324,
|
|
2645
|
+
],
|
|
2646
|
+
}
|
|
2647
|
+
`);
|
|
2648
|
+
|
|
2649
|
+
const c = z.toJSONSchema(z.literal([undefined]), {
|
|
2650
|
+
unrepresentable: "any",
|
|
2651
|
+
});
|
|
2652
|
+
expect(c).toMatchInlineSnapshot(`
|
|
2653
|
+
{
|
|
2654
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2655
|
+
}
|
|
2656
|
+
`);
|
|
2657
|
+
});
|
|
2658
|
+
|
|
2659
|
+
test("describe with id", () => {
|
|
2660
|
+
const jobId = z.string().meta({ id: "jobId" });
|
|
2661
|
+
|
|
2662
|
+
const a = z.toJSONSchema(
|
|
2663
|
+
z.object({
|
|
2664
|
+
current: jobId.describe("Current job"),
|
|
2665
|
+
previous: jobId.describe("Previous job"),
|
|
2666
|
+
})
|
|
2667
|
+
);
|
|
2668
|
+
expect(a).toMatchInlineSnapshot(`
|
|
2669
|
+
{
|
|
2670
|
+
"$defs": {
|
|
2671
|
+
"jobId": {
|
|
2672
|
+
"type": "string",
|
|
2673
|
+
},
|
|
2674
|
+
},
|
|
2675
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2676
|
+
"additionalProperties": false,
|
|
2677
|
+
"properties": {
|
|
2678
|
+
"current": {
|
|
2679
|
+
"$ref": "#/$defs/jobId",
|
|
2680
|
+
"description": "Current job",
|
|
2681
|
+
},
|
|
2682
|
+
"previous": {
|
|
2683
|
+
"$ref": "#/$defs/jobId",
|
|
2684
|
+
"description": "Previous job",
|
|
2685
|
+
},
|
|
2686
|
+
},
|
|
2687
|
+
"required": [
|
|
2688
|
+
"current",
|
|
2689
|
+
"previous",
|
|
2690
|
+
],
|
|
2691
|
+
"type": "object",
|
|
2692
|
+
}
|
|
2693
|
+
`);
|
|
2694
|
+
});
|
|
2695
|
+
|
|
2696
|
+
test("id is stripped from $defs entries (draft-2020-12)", () => {
|
|
2697
|
+
// The `id` in `.meta()` is a registration tag — it determines the $defs key but should not leak into the definition body, where it is redundant.
|
|
2698
|
+
const inner = z.string().meta({ id: "Inner" });
|
|
2699
|
+
const result = z.toJSONSchema(z.object({ a: inner, b: inner }));
|
|
2700
|
+
expect(result.$defs?.Inner).toEqual({ type: "string" });
|
|
2701
|
+
expect((result.$defs?.Inner as any).id).toBeUndefined();
|
|
2702
|
+
});
|
|
2703
|
+
|
|
2704
|
+
test("id is stripped from definitions entries (draft-04)", () => {
|
|
2705
|
+
// In draft-04, `id` is a reserved keyword that sets a base URI for the subschema. Leaking Zod's registration tag here is semantically wrong, so ensure it is stripped.
|
|
2706
|
+
const inner = z.string().meta({ id: "Inner" });
|
|
2707
|
+
const result = z.toJSONSchema(z.object({ a: inner, b: inner }), { target: "draft-04" }) as any;
|
|
2708
|
+
expect(result.definitions?.Inner).toEqual({ type: "string" });
|
|
2709
|
+
expect(result.definitions?.Inner?.id).toBeUndefined();
|
|
2710
|
+
});
|
|
2711
|
+
|
|
2712
|
+
test("id is stripped from root schema", () => {
|
|
2713
|
+
// The registration tag should not appear on the root either.
|
|
2714
|
+
const A = z.object({ name: z.string() }).meta({ id: "A" });
|
|
2715
|
+
const result = z.toJSONSchema(A);
|
|
2716
|
+
expect((result as any).id).toBeUndefined();
|
|
2717
|
+
});
|
|
2718
|
+
|
|
2719
|
+
test("root schema with id is hoisted into $defs", () => {
|
|
2720
|
+
const A = z.object({ name: z.string() }).meta({ id: "A" });
|
|
2721
|
+
const result = z.toJSONSchema(A);
|
|
2722
|
+
|
|
2723
|
+
expect(result).toEqual({
|
|
2724
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
2725
|
+
$ref: "#/$defs/A",
|
|
2726
|
+
$defs: {
|
|
2727
|
+
A: {
|
|
2728
|
+
type: "object",
|
|
2729
|
+
properties: {
|
|
2730
|
+
name: {
|
|
2731
|
+
type: "string",
|
|
2732
|
+
},
|
|
2733
|
+
},
|
|
2734
|
+
required: ["name"],
|
|
2735
|
+
additionalProperties: false,
|
|
2736
|
+
},
|
|
2737
|
+
},
|
|
2738
|
+
});
|
|
2739
|
+
});
|
|
2740
|
+
|
|
2741
|
+
test("root schema with id uses definitions on legacy targets", () => {
|
|
2742
|
+
const A = z.object({ name: z.string() }).meta({ id: "A" });
|
|
2743
|
+
const result = z.toJSONSchema(A, { target: "draft-07" });
|
|
2744
|
+
|
|
2745
|
+
expect(result).toEqual({
|
|
2746
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
2747
|
+
$ref: "#/definitions/A",
|
|
2748
|
+
definitions: {
|
|
2749
|
+
A: {
|
|
2750
|
+
type: "object",
|
|
2751
|
+
properties: {
|
|
2752
|
+
name: {
|
|
2753
|
+
type: "string",
|
|
2754
|
+
},
|
|
2755
|
+
},
|
|
2756
|
+
required: ["name"],
|
|
2757
|
+
additionalProperties: false,
|
|
2758
|
+
},
|
|
2759
|
+
},
|
|
2760
|
+
});
|
|
2761
|
+
});
|
|
2762
|
+
|
|
2763
|
+
test("id is observable in override callback", () => {
|
|
2764
|
+
// The strip happens after override callbacks run, so userland override code can still read `jsonSchema.id` if it wants to.
|
|
2765
|
+
const inner = z.string().meta({ id: "Inner" });
|
|
2766
|
+
const seenIds: Array<string | undefined> = [];
|
|
2767
|
+
z.toJSONSchema(z.object({ a: inner }), {
|
|
2768
|
+
override: ({ jsonSchema }) => {
|
|
2769
|
+
if (jsonSchema.id !== undefined) seenIds.push(jsonSchema.id as string);
|
|
2770
|
+
},
|
|
2771
|
+
});
|
|
2772
|
+
expect(seenIds).toContain("Inner");
|
|
2773
|
+
});
|
|
2774
|
+
|
|
2775
|
+
test("describe with id on wrapper", () => {
|
|
2776
|
+
// Test that $ref propagation works when processor sets a different ref (readonly -> innerType) but parent was extracted due to having an id
|
|
2777
|
+
const roJobId = z.string().readonly().meta({ id: "roJobId" });
|
|
2778
|
+
|
|
2779
|
+
const a = z.toJSONSchema(
|
|
2780
|
+
z.object({
|
|
2781
|
+
current: roJobId.describe("Current readonly job"),
|
|
2782
|
+
previous: roJobId.describe("Previous readonly job"),
|
|
2783
|
+
})
|
|
2784
|
+
);
|
|
2785
|
+
expect(a).toMatchInlineSnapshot(`
|
|
2786
|
+
{
|
|
2787
|
+
"$defs": {
|
|
2788
|
+
"roJobId": {
|
|
2789
|
+
"readOnly": true,
|
|
2790
|
+
"type": "string",
|
|
2791
|
+
},
|
|
2792
|
+
},
|
|
2793
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2794
|
+
"additionalProperties": false,
|
|
2795
|
+
"properties": {
|
|
2796
|
+
"current": {
|
|
2797
|
+
"$ref": "#/$defs/roJobId",
|
|
2798
|
+
"description": "Current readonly job",
|
|
2799
|
+
},
|
|
2800
|
+
"previous": {
|
|
2801
|
+
"$ref": "#/$defs/roJobId",
|
|
2802
|
+
"description": "Previous readonly job",
|
|
2803
|
+
},
|
|
2804
|
+
},
|
|
2805
|
+
"required": [
|
|
2806
|
+
"current",
|
|
2807
|
+
"previous",
|
|
2808
|
+
],
|
|
2809
|
+
"type": "object",
|
|
2810
|
+
}
|
|
2811
|
+
`);
|
|
2812
|
+
});
|
|
2813
|
+
|
|
2814
|
+
test("overwrite id", () => {
|
|
2815
|
+
const jobId = z.string().meta({ id: "aaa" });
|
|
2816
|
+
|
|
2817
|
+
const a = z.toJSONSchema(
|
|
2818
|
+
z.object({
|
|
2819
|
+
current: jobId,
|
|
2820
|
+
previous: jobId.meta({ id: "bbb" }),
|
|
2821
|
+
})
|
|
2822
|
+
);
|
|
2823
|
+
expect(a).toMatchInlineSnapshot(`
|
|
2824
|
+
{
|
|
2825
|
+
"$defs": {
|
|
2826
|
+
"aaa": {
|
|
2827
|
+
"type": "string",
|
|
2828
|
+
},
|
|
2829
|
+
"bbb": {
|
|
2830
|
+
"$ref": "#/$defs/aaa",
|
|
2831
|
+
},
|
|
2832
|
+
},
|
|
2833
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2834
|
+
"additionalProperties": false,
|
|
2835
|
+
"properties": {
|
|
2836
|
+
"current": {
|
|
2837
|
+
"$ref": "#/$defs/aaa",
|
|
2838
|
+
},
|
|
2839
|
+
"previous": {
|
|
2840
|
+
"$ref": "#/$defs/bbb",
|
|
2841
|
+
},
|
|
2842
|
+
},
|
|
2843
|
+
"required": [
|
|
2844
|
+
"current",
|
|
2845
|
+
"previous",
|
|
2846
|
+
],
|
|
2847
|
+
"type": "object",
|
|
2848
|
+
}
|
|
2849
|
+
`);
|
|
2850
|
+
|
|
2851
|
+
const b = z.toJSONSchema(
|
|
2852
|
+
z.object({
|
|
2853
|
+
current: jobId,
|
|
2854
|
+
previous: jobId.meta({ id: "ccc" }),
|
|
2855
|
+
}),
|
|
2856
|
+
{
|
|
2857
|
+
reused: "ref",
|
|
2858
|
+
}
|
|
2859
|
+
);
|
|
2860
|
+
expect(b).toMatchInlineSnapshot(`
|
|
2861
|
+
{
|
|
2862
|
+
"$defs": {
|
|
2863
|
+
"aaa": {
|
|
2864
|
+
"type": "string",
|
|
2865
|
+
},
|
|
2866
|
+
"ccc": {
|
|
2867
|
+
"$ref": "#/$defs/aaa",
|
|
2868
|
+
},
|
|
2869
|
+
},
|
|
2870
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2871
|
+
"additionalProperties": false,
|
|
2872
|
+
"properties": {
|
|
2873
|
+
"current": {
|
|
2874
|
+
"$ref": "#/$defs/aaa",
|
|
2875
|
+
},
|
|
2876
|
+
"previous": {
|
|
2877
|
+
"$ref": "#/$defs/ccc",
|
|
2878
|
+
},
|
|
2879
|
+
},
|
|
2880
|
+
"required": [
|
|
2881
|
+
"current",
|
|
2882
|
+
"previous",
|
|
2883
|
+
],
|
|
2884
|
+
"type": "object",
|
|
2885
|
+
}
|
|
2886
|
+
`);
|
|
2887
|
+
});
|
|
2888
|
+
|
|
2889
|
+
test("overwrite descriptions", () => {
|
|
2890
|
+
const field = z.string().describe("a").describe("b").describe("c");
|
|
2891
|
+
|
|
2892
|
+
const a = z.toJSONSchema(
|
|
2893
|
+
z.object({
|
|
2894
|
+
d: field.describe("d"),
|
|
2895
|
+
e: field.describe("e"),
|
|
2896
|
+
})
|
|
2897
|
+
);
|
|
2898
|
+
expect(a).toMatchInlineSnapshot(`
|
|
2899
|
+
{
|
|
2900
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2901
|
+
"additionalProperties": false,
|
|
2902
|
+
"properties": {
|
|
2903
|
+
"d": {
|
|
2904
|
+
"description": "d",
|
|
2905
|
+
"type": "string",
|
|
2906
|
+
},
|
|
2907
|
+
"e": {
|
|
2908
|
+
"description": "e",
|
|
2909
|
+
"type": "string",
|
|
2910
|
+
},
|
|
2911
|
+
},
|
|
2912
|
+
"required": [
|
|
2913
|
+
"d",
|
|
2914
|
+
"e",
|
|
2915
|
+
],
|
|
2916
|
+
"type": "object",
|
|
2917
|
+
}
|
|
2918
|
+
`);
|
|
2919
|
+
|
|
2920
|
+
const b = z.toJSONSchema(
|
|
2921
|
+
z.object({
|
|
2922
|
+
d: field.describe("d"),
|
|
2923
|
+
e: field.describe("e"),
|
|
2924
|
+
}),
|
|
2925
|
+
{
|
|
2926
|
+
reused: "ref",
|
|
2927
|
+
}
|
|
2928
|
+
);
|
|
2929
|
+
expect(b).toMatchInlineSnapshot(`
|
|
2930
|
+
{
|
|
2931
|
+
"$defs": {
|
|
2932
|
+
"__schema0": {
|
|
2933
|
+
"description": "c",
|
|
2934
|
+
"type": "string",
|
|
2935
|
+
},
|
|
2936
|
+
},
|
|
2937
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
2938
|
+
"additionalProperties": false,
|
|
2939
|
+
"properties": {
|
|
2940
|
+
"d": {
|
|
2941
|
+
"$ref": "#/$defs/__schema0",
|
|
2942
|
+
"description": "d",
|
|
2943
|
+
},
|
|
2944
|
+
"e": {
|
|
2945
|
+
"$ref": "#/$defs/__schema0",
|
|
2946
|
+
"description": "e",
|
|
2947
|
+
},
|
|
2948
|
+
},
|
|
2949
|
+
"required": [
|
|
2950
|
+
"d",
|
|
2951
|
+
"e",
|
|
2952
|
+
],
|
|
2953
|
+
"type": "object",
|
|
2954
|
+
}
|
|
2955
|
+
`);
|
|
2956
|
+
});
|
|
2957
|
+
|
|
2958
|
+
test("top-level readonly", () => {
|
|
2959
|
+
const A = z
|
|
2960
|
+
.object({
|
|
2961
|
+
name: z.string(),
|
|
2962
|
+
get b() {
|
|
2963
|
+
return B;
|
|
2964
|
+
},
|
|
2965
|
+
})
|
|
2966
|
+
.readonly()
|
|
2967
|
+
.meta({ id: "A" });
|
|
2968
|
+
// z.globalRegistry.add(A, { id: "A" });
|
|
2969
|
+
// .meta({ id: "A" });
|
|
2970
|
+
|
|
2971
|
+
const B = z
|
|
2972
|
+
.object({
|
|
2973
|
+
name: z.string(),
|
|
2974
|
+
get a() {
|
|
2975
|
+
return A;
|
|
2976
|
+
},
|
|
2977
|
+
})
|
|
2978
|
+
.readonly()
|
|
2979
|
+
.meta({ id: "B" });
|
|
2980
|
+
// z.globalRegistry.add(B, { id: "B" });
|
|
2981
|
+
// .meta({ id: "B" });
|
|
2982
|
+
|
|
2983
|
+
const result = z.toJSONSchema(A);
|
|
2984
|
+
expect(result).toEqual({
|
|
2985
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
2986
|
+
$ref: "#/$defs/A",
|
|
2987
|
+
$defs: {
|
|
2988
|
+
A: {
|
|
2989
|
+
additionalProperties: false,
|
|
2990
|
+
properties: {
|
|
2991
|
+
b: {
|
|
2992
|
+
$ref: "#/$defs/B",
|
|
2993
|
+
},
|
|
2994
|
+
name: {
|
|
2995
|
+
type: "string",
|
|
2996
|
+
},
|
|
2997
|
+
},
|
|
2998
|
+
readOnly: true,
|
|
2999
|
+
required: ["name", "b"],
|
|
3000
|
+
type: "object",
|
|
3001
|
+
},
|
|
3002
|
+
B: {
|
|
3003
|
+
additionalProperties: false,
|
|
3004
|
+
properties: {
|
|
3005
|
+
a: {
|
|
3006
|
+
$ref: "#/$defs/A",
|
|
3007
|
+
},
|
|
3008
|
+
name: {
|
|
3009
|
+
type: "string",
|
|
3010
|
+
},
|
|
3011
|
+
},
|
|
3012
|
+
readOnly: true,
|
|
3013
|
+
required: ["name", "a"],
|
|
3014
|
+
type: "object",
|
|
3015
|
+
},
|
|
3016
|
+
},
|
|
3017
|
+
});
|
|
3018
|
+
});
|
|
3019
|
+
|
|
3020
|
+
test("basic registry", () => {
|
|
3021
|
+
const myRegistry = z.registry<{ id: string }>();
|
|
3022
|
+
const User = z.object({
|
|
3023
|
+
name: z.string(),
|
|
3024
|
+
get posts() {
|
|
3025
|
+
return z.array(Post);
|
|
3026
|
+
},
|
|
3027
|
+
});
|
|
3028
|
+
|
|
3029
|
+
const Post = z.object({
|
|
3030
|
+
title: z.string(),
|
|
3031
|
+
content: z.string(),
|
|
3032
|
+
get author() {
|
|
3033
|
+
return User;
|
|
3034
|
+
},
|
|
3035
|
+
});
|
|
3036
|
+
|
|
3037
|
+
myRegistry.add(User, { id: "User" });
|
|
3038
|
+
myRegistry.add(Post, { id: "Post" });
|
|
3039
|
+
|
|
3040
|
+
const result = z.toJSONSchema(myRegistry, {
|
|
3041
|
+
uri: (id) => `https://example.com/${id}.json`,
|
|
3042
|
+
});
|
|
3043
|
+
expect(result).toMatchInlineSnapshot(`
|
|
3044
|
+
{
|
|
3045
|
+
"schemas": {
|
|
3046
|
+
"Post": {
|
|
3047
|
+
"$id": "https://example.com/Post.json",
|
|
3048
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3049
|
+
"additionalProperties": false,
|
|
3050
|
+
"properties": {
|
|
3051
|
+
"author": {
|
|
3052
|
+
"$ref": "https://example.com/User.json",
|
|
3053
|
+
},
|
|
3054
|
+
"content": {
|
|
3055
|
+
"type": "string",
|
|
3056
|
+
},
|
|
3057
|
+
"title": {
|
|
3058
|
+
"type": "string",
|
|
3059
|
+
},
|
|
3060
|
+
},
|
|
3061
|
+
"required": [
|
|
3062
|
+
"title",
|
|
3063
|
+
"content",
|
|
3064
|
+
"author",
|
|
3065
|
+
],
|
|
3066
|
+
"type": "object",
|
|
3067
|
+
},
|
|
3068
|
+
"User": {
|
|
3069
|
+
"$id": "https://example.com/User.json",
|
|
3070
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3071
|
+
"additionalProperties": false,
|
|
3072
|
+
"properties": {
|
|
3073
|
+
"name": {
|
|
3074
|
+
"type": "string",
|
|
3075
|
+
},
|
|
3076
|
+
"posts": {
|
|
3077
|
+
"items": {
|
|
3078
|
+
"$ref": "https://example.com/Post.json",
|
|
3079
|
+
},
|
|
3080
|
+
"type": "array",
|
|
3081
|
+
},
|
|
3082
|
+
},
|
|
3083
|
+
"required": [
|
|
3084
|
+
"name",
|
|
3085
|
+
"posts",
|
|
3086
|
+
],
|
|
3087
|
+
"type": "object",
|
|
3088
|
+
},
|
|
3089
|
+
},
|
|
3090
|
+
}
|
|
3091
|
+
`);
|
|
3092
|
+
});
|
|
3093
|
+
|
|
3094
|
+
test("large registry converts in linear time", () => {
|
|
3095
|
+
const count = 2000;
|
|
3096
|
+
const convert = (withIntersection: boolean) => {
|
|
3097
|
+
const registry = z.registry<{ id: string }>();
|
|
3098
|
+
for (let i = 0; i < count; i++) {
|
|
3099
|
+
registry.add(
|
|
3100
|
+
z.object({ id: z.string(), name: z.string(), count: z.number(), nested: z.object({ a: z.boolean() }) }),
|
|
3101
|
+
{ id: `Type${i}` }
|
|
3102
|
+
);
|
|
3103
|
+
}
|
|
3104
|
+
if (withIntersection) registry.add(z.object({ a: z.string() }).and(z.object({ b: z.string() })), { id: "Inter" });
|
|
3105
|
+
|
|
3106
|
+
const start = performance.now();
|
|
3107
|
+
const { schemas } = z.toJSONSchema(registry, { uri: (id) => `https://example.com/${id}.json` });
|
|
3108
|
+
return { schemas, elapsed: performance.now() - start };
|
|
3109
|
+
};
|
|
3110
|
+
|
|
3111
|
+
const plain = convert(false);
|
|
3112
|
+
expect(Object.keys(plain.schemas)).toHaveLength(count);
|
|
3113
|
+
expect(plain.schemas.Type0).toMatchObject({
|
|
3114
|
+
$id: "https://example.com/Type0.json",
|
|
3115
|
+
type: "object",
|
|
3116
|
+
properties: { nested: { type: "object" } },
|
|
3117
|
+
});
|
|
3118
|
+
expect(plain.schemas[`Type${count - 1}`]!.$id).toBe(`https://example.com/Type${count - 1}.json`);
|
|
3119
|
+
|
|
3120
|
+
// The whole-map passes in extractDefs/finalize used to re-run once per registered schema, which made this quadratic: ~9s of CPU at this size before the passes were hoisted, ~50ms after.
|
|
3121
|
+
expect(plain.elapsed).toBeLessThan(5000);
|
|
3122
|
+
|
|
3123
|
+
// The intersection fold walks the whole map as well, so it has to run inside the same guard. Hoisting it back out costs ~10x at this size. Comparing the two conversions rather than asserting a fixed budget keeps this independent of how fast the machine is.
|
|
3124
|
+
const folded = convert(true);
|
|
3125
|
+
expect(folded.schemas.Inter).toMatchObject({ type: "object", properties: { a: {}, b: {} } });
|
|
3126
|
+
expect(folded.elapsed).toBeLessThan(plain.elapsed * 4 + 100);
|
|
3127
|
+
});
|
|
3128
|
+
|
|
3129
|
+
test("a registry of records with numeric keys converts in linear time", () => {
|
|
3130
|
+
const count = 2000;
|
|
3131
|
+
const convert = (key: (i: number) => z.core.$ZodType) => {
|
|
3132
|
+
const registry = z.registry<{ id: string }>();
|
|
3133
|
+
for (let i = 0; i < count; i++) {
|
|
3134
|
+
registry.add(z.object({ m: z.record(key(i) as z.core.$ZodRecordKey, z.boolean()) }), { id: `Type${i}` });
|
|
3135
|
+
}
|
|
3136
|
+
const start = performance.now();
|
|
3137
|
+
const { schemas } = z.toJSONSchema(registry, { uri: (id) => `https://example.com/${id}.json` });
|
|
3138
|
+
return { schemas, elapsed: performance.now() - start };
|
|
3139
|
+
};
|
|
3140
|
+
|
|
3141
|
+
const string = convert(() => z.string());
|
|
3142
|
+
const numeric = convert(() => z.number());
|
|
3143
|
+
expect(numeric.schemas.Type0).toMatchObject({
|
|
3144
|
+
properties: { m: { propertyNames: { type: "string", pattern: "^-?\\d+(?:\\.\\d+)?$" } } },
|
|
3145
|
+
});
|
|
3146
|
+
|
|
3147
|
+
// The rewrite has to find every carrier the flatten copied `propertyNames` onto, which means a pass over the whole seen map. Running that once per record rather than once per conversion cost ~10x at this size. A string key needs no rewrite at all, so comparing against it keeps this independent of how fast the machine is.
|
|
3148
|
+
expect(numeric.elapsed).toBeLessThan(string.elapsed * 2 + 50);
|
|
3149
|
+
|
|
3150
|
+
// An extracted key resolves through a map built once per conversion rather than a search per reference. There is no stable timing control for that — extraction has its own $defs cost, which swamps the difference — so this only pins the shape.
|
|
3151
|
+
const extracted = convert((i) => z.number().meta({ id: `Key${i}` }));
|
|
3152
|
+
expect(extracted.schemas.Type0).toMatchObject({
|
|
3153
|
+
properties: { m: { propertyNames: { type: "string", pattern: "^-?\\d+(?:\\.\\d+)?$" } } },
|
|
3154
|
+
});
|
|
3155
|
+
});
|
|
3156
|
+
|
|
3157
|
+
test("registry extracts unregistered subschemas into __shared", () => {
|
|
3158
|
+
const registry = z.registry<{ id: string }>();
|
|
3159
|
+
const address = z.object({ street: z.string() }).meta({ id: "Address" });
|
|
3160
|
+
registry.add(z.object({ home: address, work: address }), { id: "Person" });
|
|
3161
|
+
registry.add(z.object({ hq: address }), { id: "Company" });
|
|
3162
|
+
|
|
3163
|
+
const { schemas } = z.toJSONSchema(registry, { uri: (id) => `https://example.com/${id}.json` });
|
|
3164
|
+
|
|
3165
|
+
expect(schemas.__shared).toMatchInlineSnapshot(`
|
|
3166
|
+
{
|
|
3167
|
+
"$defs": {
|
|
3168
|
+
"Address": {
|
|
3169
|
+
"additionalProperties": false,
|
|
3170
|
+
"properties": {
|
|
3171
|
+
"street": {
|
|
3172
|
+
"type": "string",
|
|
3173
|
+
},
|
|
3174
|
+
},
|
|
3175
|
+
"required": [
|
|
3176
|
+
"street",
|
|
3177
|
+
],
|
|
3178
|
+
"type": "object",
|
|
3179
|
+
},
|
|
3180
|
+
},
|
|
3181
|
+
}
|
|
3182
|
+
`);
|
|
3183
|
+
expect(schemas.Person).toMatchInlineSnapshot(`
|
|
3184
|
+
{
|
|
3185
|
+
"$id": "https://example.com/Person.json",
|
|
3186
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3187
|
+
"additionalProperties": false,
|
|
3188
|
+
"properties": {
|
|
3189
|
+
"home": {
|
|
3190
|
+
"$ref": "https://example.com/__shared.json#/$defs/Address",
|
|
3191
|
+
},
|
|
3192
|
+
"work": {
|
|
3193
|
+
"$ref": "https://example.com/__shared.json#/$defs/Address",
|
|
3194
|
+
},
|
|
3195
|
+
},
|
|
3196
|
+
"required": [
|
|
3197
|
+
"home",
|
|
3198
|
+
"work",
|
|
3199
|
+
],
|
|
3200
|
+
"type": "object",
|
|
3201
|
+
}
|
|
3202
|
+
`);
|
|
3203
|
+
// Company is emitted after Person, so it only resolves if the shared $defs built on the first finalize are still reachable — the pass that writes them no longer runs per schema.
|
|
3204
|
+
expect(schemas.Company!.properties!.hq).toEqual({
|
|
3205
|
+
$ref: "https://example.com/__shared.json#/$defs/Address",
|
|
3206
|
+
});
|
|
3207
|
+
});
|
|
3208
|
+
|
|
3209
|
+
test("registry extracts reused subschemas into __shared without an id", () => {
|
|
3210
|
+
const registry = z.registry<{ id: string }>();
|
|
3211
|
+
const shared = z.object({ q: z.string() });
|
|
3212
|
+
registry.add(z.object({ a: shared, b: shared }), { id: "First" });
|
|
3213
|
+
registry.add(z.object({ c: shared }), { id: "Second" });
|
|
3214
|
+
|
|
3215
|
+
const { schemas } = z.toJSONSchema(registry, { uri: (id) => `${id}.json`, reused: "ref" });
|
|
3216
|
+
|
|
3217
|
+
// The id is counter-generated, so this pins that ctx.counter is consumed exactly once.
|
|
3218
|
+
expect(Object.keys(schemas.__shared!.$defs!)).toEqual(["schema0"]);
|
|
3219
|
+
expect(schemas.First!.properties!.a).toEqual({ $ref: "__shared.json#/$defs/schema0" });
|
|
3220
|
+
expect(schemas.Second!.properties!.c).toEqual({ $ref: "__shared.json#/$defs/schema0" });
|
|
3221
|
+
});
|
|
3222
|
+
|
|
3223
|
+
test("JSONSchemaGenerator re-runs shared passes when emit params change", () => {
|
|
3224
|
+
const shared = z.object({ s: z.string() });
|
|
3225
|
+
const a = z.object({ x: shared, y: shared });
|
|
3226
|
+
const registry = z.registry<{ id: string }>();
|
|
3227
|
+
registry.add(a, { id: "A" });
|
|
3228
|
+
|
|
3229
|
+
const gen = new z.core.JSONSchemaGenerator({ target: "draft-2020-12" });
|
|
3230
|
+
gen.process(a);
|
|
3231
|
+
const defs: Record<string, any> = {};
|
|
3232
|
+
const external = { registry, uri: (id: string) => `${id}.json`, defs };
|
|
3233
|
+
|
|
3234
|
+
gen.emit(a, { external, reused: "inline" });
|
|
3235
|
+
// Same `external`, different `reused` — the second emit must still extract `shared`.
|
|
3236
|
+
const second: any = gen.emit(a, { external, reused: "ref" });
|
|
3237
|
+
|
|
3238
|
+
expect(Object.keys(defs)).toEqual(["schema0"]);
|
|
3239
|
+
expect(second.properties.x).toEqual({ $ref: "__shared.json#/$defs/schema0" });
|
|
3240
|
+
expect(second.properties.y).toEqual({ $ref: "__shared.json#/$defs/schema0" });
|
|
3241
|
+
});
|
|
3242
|
+
|
|
3243
|
+
test("JSONSchemaGenerator still throws on cycles when a later emit asks for it", () => {
|
|
3244
|
+
const Node: any = z.object({
|
|
3245
|
+
v: z.string(),
|
|
3246
|
+
get next() {
|
|
3247
|
+
return Node;
|
|
3248
|
+
},
|
|
3249
|
+
});
|
|
3250
|
+
const registry = z.registry<{ id: string }>();
|
|
3251
|
+
registry.add(Node, { id: "Node" });
|
|
3252
|
+
|
|
3253
|
+
const gen = new z.core.JSONSchemaGenerator({ target: "draft-2020-12" });
|
|
3254
|
+
gen.process(Node);
|
|
3255
|
+
const external = { registry, uri: (id: string) => `${id}.json`, defs: {} };
|
|
3256
|
+
|
|
3257
|
+
gen.emit(Node, { external, cycles: "ref" });
|
|
3258
|
+
expect(() => gen.emit(Node, { external, cycles: "throw" })).toThrow(/Cycle detected/);
|
|
3259
|
+
});
|
|
3260
|
+
|
|
3261
|
+
test("JSONSchemaGenerator re-runs shared passes on a no-params emit", () => {
|
|
3262
|
+
const shared = z.object({ s: z.string() });
|
|
3263
|
+
const a = z.object({ x: shared });
|
|
3264
|
+
const registry = z.registry<{ id: string }>();
|
|
3265
|
+
registry.add(a, { id: "A" });
|
|
3266
|
+
|
|
3267
|
+
const gen = new z.core.JSONSchemaGenerator({ target: "draft-2020-12" });
|
|
3268
|
+
gen.process(a);
|
|
3269
|
+
const defs: Record<string, any> = {};
|
|
3270
|
+
gen.emit(a, { external: { registry, uri: (id: string) => `${id}.json`, defs }, reused: "ref" });
|
|
3271
|
+
|
|
3272
|
+
// Re-processing an already-seen schema bumps `seen.count`, which `extractDefs` branches on under `reused: "ref"` — and it returns early, so it cannot clear the guards itself.
|
|
3273
|
+
gen.process(shared);
|
|
3274
|
+
const second: any = gen.emit(a);
|
|
3275
|
+
|
|
3276
|
+
expect(Object.keys(defs)).toEqual(["schema0"]);
|
|
3277
|
+
expect(second.properties.x).toEqual({ $ref: "__shared.json#/$defs/schema0" });
|
|
3278
|
+
});
|
|
3279
|
+
|
|
3280
|
+
test("_ref", () => {
|
|
3281
|
+
// const a = z.promise(z.string().describe("a"));
|
|
3282
|
+
const a = z.toJSONSchema(z.promise(z.string().describe("a")));
|
|
3283
|
+
expect(a).toMatchInlineSnapshot(`
|
|
3284
|
+
{
|
|
3285
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3286
|
+
"description": "a",
|
|
3287
|
+
"type": "string",
|
|
3288
|
+
}
|
|
3289
|
+
`);
|
|
3290
|
+
|
|
3291
|
+
const b = z.toJSONSchema(z.lazy(() => z.string().describe("a")));
|
|
3292
|
+
expect(b).toMatchInlineSnapshot(`
|
|
3293
|
+
{
|
|
3294
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3295
|
+
"description": "a",
|
|
3296
|
+
"type": "string",
|
|
3297
|
+
}
|
|
3298
|
+
`);
|
|
3299
|
+
|
|
3300
|
+
const c = z.toJSONSchema(z.optional(z.string().describe("a")));
|
|
3301
|
+
expect(c).toMatchInlineSnapshot(`
|
|
3302
|
+
{
|
|
3303
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3304
|
+
"description": "a",
|
|
3305
|
+
"type": "string",
|
|
3306
|
+
}
|
|
3307
|
+
`);
|
|
3308
|
+
|
|
3309
|
+
const d = z.toJSONSchema(z.string().meta({ id: "foo" }).describe("bar").optional());
|
|
3310
|
+
expect(d).toMatchInlineSnapshot(`
|
|
3311
|
+
{
|
|
3312
|
+
"$defs": {
|
|
3313
|
+
"foo": {
|
|
3314
|
+
"type": "string",
|
|
3315
|
+
},
|
|
3316
|
+
},
|
|
3317
|
+
"$ref": "#/$defs/foo",
|
|
3318
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3319
|
+
"description": "bar",
|
|
3320
|
+
}
|
|
3321
|
+
`);
|
|
3322
|
+
});
|
|
3323
|
+
|
|
3324
|
+
test("defaults/prefaults", () => {
|
|
3325
|
+
const a = z
|
|
3326
|
+
.string()
|
|
3327
|
+
.transform((val) => val.length)
|
|
3328
|
+
.pipe(z.number());
|
|
3329
|
+
const b = a.prefault("hello");
|
|
3330
|
+
const c = a.default(1234);
|
|
3331
|
+
|
|
3332
|
+
// a
|
|
3333
|
+
expect(z.toJSONSchema(a)).toMatchInlineSnapshot(`
|
|
3334
|
+
{
|
|
3335
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3336
|
+
"type": "number",
|
|
3337
|
+
}
|
|
3338
|
+
`);
|
|
3339
|
+
expect(z.toJSONSchema(a, { io: "input" })).toMatchInlineSnapshot(`
|
|
3340
|
+
{
|
|
3341
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3342
|
+
"type": "string",
|
|
3343
|
+
}
|
|
3344
|
+
`);
|
|
3345
|
+
|
|
3346
|
+
// b
|
|
3347
|
+
expect(z.toJSONSchema(b)).toMatchInlineSnapshot(`
|
|
3348
|
+
{
|
|
3349
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3350
|
+
"type": "number",
|
|
3351
|
+
}
|
|
3352
|
+
`);
|
|
3353
|
+
expect(z.toJSONSchema(b, { io: "input" })).toMatchInlineSnapshot(`
|
|
3354
|
+
{
|
|
3355
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3356
|
+
"default": "hello",
|
|
3357
|
+
"type": "string",
|
|
3358
|
+
}
|
|
3359
|
+
`);
|
|
3360
|
+
// c
|
|
3361
|
+
expect(z.toJSONSchema(c)).toMatchInlineSnapshot(`
|
|
3362
|
+
{
|
|
3363
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3364
|
+
"default": 1234,
|
|
3365
|
+
"type": "number",
|
|
3366
|
+
}
|
|
3367
|
+
`);
|
|
3368
|
+
expect(z.toJSONSchema(c, { io: "input" })).toMatchInlineSnapshot(`
|
|
3369
|
+
{
|
|
3370
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3371
|
+
"type": "string",
|
|
3372
|
+
}
|
|
3373
|
+
`);
|
|
3374
|
+
});
|
|
3375
|
+
|
|
3376
|
+
test("catch on a transforming schema", () => {
|
|
3377
|
+
const a = z
|
|
3378
|
+
.string()
|
|
3379
|
+
.transform((val) => val.length)
|
|
3380
|
+
.pipe(z.number())
|
|
3381
|
+
.catch(0);
|
|
3382
|
+
|
|
3383
|
+
expect(z.toJSONSchema(a)).toMatchInlineSnapshot(`
|
|
3384
|
+
{
|
|
3385
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3386
|
+
"default": 0,
|
|
3387
|
+
"type": "number",
|
|
3388
|
+
}
|
|
3389
|
+
`);
|
|
3390
|
+
// catch values are output-typed, so they are not valid input
|
|
3391
|
+
expect(z.toJSONSchema(a, { io: "input" })).toMatchInlineSnapshot(`
|
|
3392
|
+
{
|
|
3393
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3394
|
+
"type": "string",
|
|
3395
|
+
}
|
|
3396
|
+
`);
|
|
3397
|
+
|
|
3398
|
+
// the catch no longer hides the inner transform from ancestors, so their output-typed metadata is stripped too — matching a bare nested transform
|
|
3399
|
+
expect(z.toJSONSchema(z.object({ a }).meta({ examples: [{ a: 1 }] }), { io: "input" })).toMatchInlineSnapshot(`
|
|
3400
|
+
{
|
|
3401
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3402
|
+
"properties": {
|
|
3403
|
+
"a": {
|
|
3404
|
+
"type": "string",
|
|
3405
|
+
},
|
|
3406
|
+
},
|
|
3407
|
+
"required": [
|
|
3408
|
+
"a",
|
|
3409
|
+
],
|
|
3410
|
+
"type": "object",
|
|
3411
|
+
}
|
|
3412
|
+
`);
|
|
3413
|
+
});
|
|
3414
|
+
|
|
3415
|
+
test("falsy prefaults (false, 0, empty string)", () => {
|
|
3416
|
+
// boolean prefault false
|
|
3417
|
+
const a = z.boolean().prefault(false);
|
|
3418
|
+
expect(z.toJSONSchema(a, { io: "input" })).toMatchInlineSnapshot(`
|
|
3419
|
+
{
|
|
3420
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3421
|
+
"default": false,
|
|
3422
|
+
"type": "boolean",
|
|
3423
|
+
}
|
|
3424
|
+
`);
|
|
3425
|
+
|
|
3426
|
+
// number prefault 0
|
|
3427
|
+
const b = z.number().prefault(0);
|
|
3428
|
+
expect(z.toJSONSchema(b, { io: "input" })).toMatchInlineSnapshot(`
|
|
3429
|
+
{
|
|
3430
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3431
|
+
"default": 0,
|
|
3432
|
+
"type": "number",
|
|
3433
|
+
}
|
|
3434
|
+
`);
|
|
3435
|
+
|
|
3436
|
+
// string prefault empty string
|
|
3437
|
+
const c = z.string().prefault("");
|
|
3438
|
+
expect(z.toJSONSchema(c, { io: "input" })).toMatchInlineSnapshot(`
|
|
3439
|
+
{
|
|
3440
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3441
|
+
"default": "",
|
|
3442
|
+
"type": "string",
|
|
3443
|
+
}
|
|
3444
|
+
`);
|
|
3445
|
+
});
|
|
3446
|
+
|
|
3447
|
+
test("input type", () => {
|
|
3448
|
+
const schema = z.object({
|
|
3449
|
+
a: z.string(),
|
|
3450
|
+
b: z.string().optional(),
|
|
3451
|
+
c: z.string().default("hello"),
|
|
3452
|
+
d: z.string().nullable(),
|
|
3453
|
+
e: z.string().prefault("hello"),
|
|
3454
|
+
f: z.string().catch("hello"),
|
|
3455
|
+
g: z.never(),
|
|
3456
|
+
h: z.union([z.string(), z.number().default(2)]),
|
|
3457
|
+
i: z.union([z.string(), z.string().optional()]),
|
|
3458
|
+
});
|
|
3459
|
+
expect(z.toJSONSchema(schema, { io: "input" })).toMatchInlineSnapshot(`
|
|
3460
|
+
{
|
|
3461
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3462
|
+
"properties": {
|
|
3463
|
+
"a": {
|
|
3464
|
+
"type": "string",
|
|
3465
|
+
},
|
|
3466
|
+
"b": {
|
|
3467
|
+
"type": "string",
|
|
3468
|
+
},
|
|
3469
|
+
"c": {
|
|
3470
|
+
"default": "hello",
|
|
3471
|
+
"type": "string",
|
|
3472
|
+
},
|
|
3473
|
+
"d": {
|
|
3474
|
+
"type": [
|
|
3475
|
+
"string",
|
|
3476
|
+
"null",
|
|
3477
|
+
],
|
|
3478
|
+
},
|
|
3479
|
+
"e": {
|
|
3480
|
+
"default": "hello",
|
|
3481
|
+
"type": "string",
|
|
3482
|
+
},
|
|
3483
|
+
"f": {
|
|
3484
|
+
"default": "hello",
|
|
3485
|
+
"type": "string",
|
|
3486
|
+
},
|
|
3487
|
+
"g": {
|
|
3488
|
+
"not": {},
|
|
3489
|
+
},
|
|
3490
|
+
"h": {
|
|
3491
|
+
"anyOf": [
|
|
3492
|
+
{
|
|
3493
|
+
"type": "string",
|
|
3494
|
+
},
|
|
3495
|
+
{
|
|
3496
|
+
"default": 2,
|
|
3497
|
+
"type": "number",
|
|
3498
|
+
},
|
|
3499
|
+
],
|
|
3500
|
+
},
|
|
3501
|
+
"i": {
|
|
3502
|
+
"type": "string",
|
|
3503
|
+
},
|
|
3504
|
+
},
|
|
3505
|
+
"required": [
|
|
3506
|
+
"a",
|
|
3507
|
+
"d",
|
|
3508
|
+
"f",
|
|
3509
|
+
"g",
|
|
3510
|
+
],
|
|
3511
|
+
"type": "object",
|
|
3512
|
+
}
|
|
3513
|
+
`);
|
|
3514
|
+
expect(z.toJSONSchema(schema, { io: "output" })).toMatchInlineSnapshot(`
|
|
3515
|
+
{
|
|
3516
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3517
|
+
"additionalProperties": false,
|
|
3518
|
+
"properties": {
|
|
3519
|
+
"a": {
|
|
3520
|
+
"type": "string",
|
|
3521
|
+
},
|
|
3522
|
+
"b": {
|
|
3523
|
+
"type": "string",
|
|
3524
|
+
},
|
|
3525
|
+
"c": {
|
|
3526
|
+
"default": "hello",
|
|
3527
|
+
"type": "string",
|
|
3528
|
+
},
|
|
3529
|
+
"d": {
|
|
3530
|
+
"type": [
|
|
3531
|
+
"string",
|
|
3532
|
+
"null",
|
|
3533
|
+
],
|
|
3534
|
+
},
|
|
3535
|
+
"e": {
|
|
3536
|
+
"type": "string",
|
|
3537
|
+
},
|
|
3538
|
+
"f": {
|
|
3539
|
+
"default": "hello",
|
|
3540
|
+
"type": "string",
|
|
3541
|
+
},
|
|
3542
|
+
"g": {
|
|
3543
|
+
"not": {},
|
|
3544
|
+
},
|
|
3545
|
+
"h": {
|
|
3546
|
+
"anyOf": [
|
|
3547
|
+
{
|
|
3548
|
+
"type": "string",
|
|
3549
|
+
},
|
|
3550
|
+
{
|
|
3551
|
+
"default": 2,
|
|
3552
|
+
"type": "number",
|
|
3553
|
+
},
|
|
3554
|
+
],
|
|
3555
|
+
},
|
|
3556
|
+
"i": {
|
|
3557
|
+
"type": "string",
|
|
3558
|
+
},
|
|
3559
|
+
},
|
|
3560
|
+
"required": [
|
|
3561
|
+
"a",
|
|
3562
|
+
"c",
|
|
3563
|
+
"d",
|
|
3564
|
+
"e",
|
|
3565
|
+
"f",
|
|
3566
|
+
"g",
|
|
3567
|
+
"h",
|
|
3568
|
+
],
|
|
3569
|
+
"type": "object",
|
|
3570
|
+
}
|
|
3571
|
+
`);
|
|
3572
|
+
});
|
|
3573
|
+
|
|
3574
|
+
test("examples on pipe", () => {
|
|
3575
|
+
const schema = z
|
|
3576
|
+
.string()
|
|
3577
|
+
.meta({ examples: ["test"] })
|
|
3578
|
+
.transform(Number)
|
|
3579
|
+
// .pipe(z.transform(Number).meta({ examples: [4] }))
|
|
3580
|
+
.meta({ examples: [4] });
|
|
3581
|
+
|
|
3582
|
+
const i = z.toJSONSchema(schema, { io: "input", unrepresentable: "any" });
|
|
3583
|
+
expect(i).toMatchInlineSnapshot(`
|
|
3584
|
+
{
|
|
3585
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3586
|
+
"examples": [
|
|
3587
|
+
"test",
|
|
3588
|
+
],
|
|
3589
|
+
"type": "string",
|
|
3590
|
+
}
|
|
3591
|
+
`);
|
|
3592
|
+
const o = z.toJSONSchema(schema, { io: "output", unrepresentable: "any" });
|
|
3593
|
+
expect(o).toMatchInlineSnapshot(`
|
|
3594
|
+
{
|
|
3595
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3596
|
+
"examples": [
|
|
3597
|
+
4,
|
|
3598
|
+
],
|
|
3599
|
+
}
|
|
3600
|
+
`);
|
|
3601
|
+
});
|
|
3602
|
+
|
|
3603
|
+
// test("number checks", () => {
|
|
3604
|
+
// expect(z.toJSONSchema(z.number().int())).toMatchInlineSnapshot(`
|
|
3605
|
+
// {
|
|
3606
|
+
// "maximum": 9007199254740991,
|
|
3607
|
+
// "minimum": -9007199254740991,
|
|
3608
|
+
// "type": "integer",
|
|
3609
|
+
// }
|
|
3610
|
+
// `);
|
|
3611
|
+
// expect(z.toJSONSchema(z.int())).toMatchInlineSnapshot(`
|
|
3612
|
+
// {
|
|
3613
|
+
// "maximum": 9007199254740991,
|
|
3614
|
+
// "minimum": -9007199254740991,
|
|
3615
|
+
// "type": "integer",
|
|
3616
|
+
// }
|
|
3617
|
+
// `);
|
|
3618
|
+
// expect(z.toJSONSchema(z.int().positive())).toMatchInlineSnapshot(`
|
|
3619
|
+
// {
|
|
3620
|
+
// "exclusiveMinimum": 0,
|
|
3621
|
+
// "maximum": 9007199254740991,
|
|
3622
|
+
// "minimum": -9007199254740991,
|
|
3623
|
+
// "type": "integer",
|
|
3624
|
+
// }
|
|
3625
|
+
// `);
|
|
3626
|
+
// expect(z.toJSONSchema(z.int().nonnegative())).toMatchInlineSnapshot(`
|
|
3627
|
+
// {
|
|
3628
|
+
// "maximum": 9007199254740991,
|
|
3629
|
+
// "minimum": 0,
|
|
3630
|
+
// "type": "integer",
|
|
3631
|
+
// }
|
|
3632
|
+
// `);
|
|
3633
|
+
// expect(z.toJSONSchema(z.int().gt(0))).toMatchInlineSnapshot(`
|
|
3634
|
+
// {
|
|
3635
|
+
// "exclusiveMinimum": 0,
|
|
3636
|
+
// "maximum": 9007199254740991,
|
|
3637
|
+
// "minimum": -9007199254740991,
|
|
3638
|
+
// "type": "integer",
|
|
3639
|
+
// }
|
|
3640
|
+
// `);
|
|
3641
|
+
// expect(z.toJSONSchema(z.int().gte(0))).toMatchInlineSnapshot(`
|
|
3642
|
+
// {
|
|
3643
|
+
// "maximum": 9007199254740991,
|
|
3644
|
+
// "minimum": 0,
|
|
3645
|
+
// "type": "integer",
|
|
3646
|
+
// }
|
|
3647
|
+
// `);
|
|
3648
|
+
|
|
3649
|
+
// });
|
|
3650
|
+
|
|
3651
|
+
test("use output type for preprocess", () => {
|
|
3652
|
+
const a = z.preprocess((val) => String(val), z.string());
|
|
3653
|
+
|
|
3654
|
+
expect(z.toJSONSchema(a, { io: "input" })).toMatchInlineSnapshot(`
|
|
3655
|
+
{
|
|
3656
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3657
|
+
"type": "string",
|
|
3658
|
+
}
|
|
3659
|
+
`);
|
|
3660
|
+
});
|
|
3661
|
+
|
|
3662
|
+
test("object property with preprocess stays required in input JSON schema", () => {
|
|
3663
|
+
const schema = z.object({
|
|
3664
|
+
noPreprocess: z.string(),
|
|
3665
|
+
withPreprocess: z.preprocess((v) => v, z.string()),
|
|
3666
|
+
optionalPreprocess: z.preprocess((v) => v, z.string().optional()),
|
|
3667
|
+
});
|
|
3668
|
+
|
|
3669
|
+
// A preprocessed property is only optional when its inner schema is — the
|
|
3670
|
+
// transform wrapper must not make a required property optional in the input
|
|
3671
|
+
// JSON schema (matches runtime: `schema.parse({})` rejects `withPreprocess`).
|
|
3672
|
+
expect(z.toJSONSchema(schema, { io: "input" })).toMatchInlineSnapshot(`
|
|
3673
|
+
{
|
|
3674
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3675
|
+
"properties": {
|
|
3676
|
+
"noPreprocess": {
|
|
3677
|
+
"type": "string",
|
|
3678
|
+
},
|
|
3679
|
+
"optionalPreprocess": {
|
|
3680
|
+
"type": "string",
|
|
3681
|
+
},
|
|
3682
|
+
"withPreprocess": {
|
|
3683
|
+
"type": "string",
|
|
3684
|
+
},
|
|
3685
|
+
},
|
|
3686
|
+
"required": [
|
|
3687
|
+
"noPreprocess",
|
|
3688
|
+
"withPreprocess",
|
|
3689
|
+
],
|
|
3690
|
+
"type": "object",
|
|
3691
|
+
}
|
|
3692
|
+
`);
|
|
3693
|
+
});
|
|
3694
|
+
|
|
3695
|
+
test("input JSON schema resolves requiredness past transform and catch wrappers", () => {
|
|
3696
|
+
const required = (schema: z.ZodObject) =>
|
|
3697
|
+
(z.toJSONSchema(schema, { io: "input" }) as z.core.JSONSchema.ObjectSchema).required;
|
|
3698
|
+
const id = (v: unknown) => v;
|
|
3699
|
+
|
|
3700
|
+
// catch observes an absent key at runtime, but its declared input type stays required (#5003)
|
|
3701
|
+
expect(required(z.object({ a: z.string().catch("x") }))).toEqual(["a"]);
|
|
3702
|
+
expect(required(z.object({ a: z.string().optional().catch("x") }))).toBeUndefined();
|
|
3703
|
+
// nested preprocess and the legacy transform-pipe form both resolve through to the inner schema
|
|
3704
|
+
expect(required(z.object({ a: z.preprocess(id, z.preprocess(id, z.string())) }))).toEqual(["a"]);
|
|
3705
|
+
expect(required(z.object({ a: z.transform((v: unknown) => String(v)).pipe(z.string()) }))).toEqual(["a"]);
|
|
3706
|
+
});
|
|
3707
|
+
|
|
3708
|
+
test("strip output-side examples from input JSON schema for codec", () => {
|
|
3709
|
+
const codec = z
|
|
3710
|
+
.codec(z.string(), z.number(), { decode: (s) => Number(s), encode: (n) => String(n) })
|
|
3711
|
+
.meta({ examples: [42] });
|
|
3712
|
+
|
|
3713
|
+
expect(z.toJSONSchema(codec, { io: "input" })).toMatchInlineSnapshot(`
|
|
3714
|
+
{
|
|
3715
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3716
|
+
"type": "string",
|
|
3717
|
+
}
|
|
3718
|
+
`);
|
|
3719
|
+
expect(z.toJSONSchema(codec, { io: "output" })).toMatchInlineSnapshot(`
|
|
3720
|
+
{
|
|
3721
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3722
|
+
"examples": [
|
|
3723
|
+
42,
|
|
3724
|
+
],
|
|
3725
|
+
"type": "number",
|
|
3726
|
+
}
|
|
3727
|
+
`);
|
|
3728
|
+
});
|
|
3729
|
+
|
|
3730
|
+
// test("isTransforming", () => {
|
|
3731
|
+
// const tx = z.core.isTransforming;
|
|
3732
|
+
// expect(tx(z.string())).toEqual(false);
|
|
3733
|
+
// expect(tx(z.string().transform((val) => val))).toEqual(true);
|
|
3734
|
+
// expect(tx(z.string().pipe(z.string()))).toEqual(false);
|
|
3735
|
+
// expect(
|
|
3736
|
+
// tx(
|
|
3737
|
+
// z
|
|
3738
|
+
// .string()
|
|
3739
|
+
// .transform((val) => val)
|
|
3740
|
+
// .pipe(z.string())
|
|
3741
|
+
// )
|
|
3742
|
+
// ).toEqual(true);
|
|
3743
|
+
|
|
3744
|
+
// const a = z.transform((val) => val);
|
|
3745
|
+
// expect(tx(z.transform((val) => val))).toEqual(true);
|
|
3746
|
+
// expect(tx(a.optional())).toEqual(true);
|
|
3747
|
+
|
|
3748
|
+
// const b = z.string().optional();
|
|
3749
|
+
// expect(tx(b)).toEqual(false);
|
|
3750
|
+
|
|
3751
|
+
// const c = z.string().prefault("hello");
|
|
3752
|
+
// expect(tx(c)).toEqual(false);
|
|
3753
|
+
|
|
3754
|
+
// const d = z.string().default("hello");
|
|
3755
|
+
// expect(tx(d)).toEqual(false);
|
|
3756
|
+
// });
|
|
3757
|
+
|
|
3758
|
+
test("flatten simple intersections", () => {
|
|
3759
|
+
const FirstSchema = z.object({
|
|
3760
|
+
testNum: z.number(),
|
|
3761
|
+
});
|
|
3762
|
+
|
|
3763
|
+
const SecondSchema = z.object({
|
|
3764
|
+
testStr: z.string(),
|
|
3765
|
+
});
|
|
3766
|
+
|
|
3767
|
+
const ThirdSchema = z.object({
|
|
3768
|
+
testBool: z.boolean(),
|
|
3769
|
+
});
|
|
3770
|
+
|
|
3771
|
+
const HelloSchema = FirstSchema.and(SecondSchema).and(ThirdSchema).describe("123");
|
|
3772
|
+
|
|
3773
|
+
// Zod 3
|
|
3774
|
+
// console.log(JSON.stringify(zodToJsonSchema(HelloSchema), null, 2));
|
|
3775
|
+
|
|
3776
|
+
// Zod 4
|
|
3777
|
+
const result = z.toJSONSchema(HelloSchema, { target: "draft-7" });
|
|
3778
|
+
expect(result).toMatchInlineSnapshot(`
|
|
3779
|
+
{
|
|
3780
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3781
|
+
"additionalProperties": false,
|
|
3782
|
+
"description": "123",
|
|
3783
|
+
"properties": {
|
|
3784
|
+
"testBool": {
|
|
3785
|
+
"type": "boolean",
|
|
3786
|
+
},
|
|
3787
|
+
"testNum": {
|
|
3788
|
+
"type": "number",
|
|
3789
|
+
},
|
|
3790
|
+
"testStr": {
|
|
3791
|
+
"type": "string",
|
|
3792
|
+
},
|
|
3793
|
+
},
|
|
3794
|
+
"required": [
|
|
3795
|
+
"testNum",
|
|
3796
|
+
"testStr",
|
|
3797
|
+
"testBool",
|
|
3798
|
+
],
|
|
3799
|
+
"type": "object",
|
|
3800
|
+
}
|
|
3801
|
+
`);
|
|
3802
|
+
});
|
|
3803
|
+
|
|
3804
|
+
test("z.file()", () => {
|
|
3805
|
+
const a = z.file();
|
|
3806
|
+
expect(z.toJSONSchema(a)).toMatchInlineSnapshot(`
|
|
3807
|
+
{
|
|
3808
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3809
|
+
"contentEncoding": "binary",
|
|
3810
|
+
"format": "binary",
|
|
3811
|
+
"type": "string",
|
|
3812
|
+
}
|
|
3813
|
+
`);
|
|
3814
|
+
|
|
3815
|
+
const b = z.file().mime("image/png").min(1000).max(10000);
|
|
3816
|
+
expect(z.toJSONSchema(b)).toMatchInlineSnapshot(`
|
|
3817
|
+
{
|
|
3818
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3819
|
+
"contentEncoding": "binary",
|
|
3820
|
+
"contentMediaType": "image/png",
|
|
3821
|
+
"format": "binary",
|
|
3822
|
+
"maxLength": 10000,
|
|
3823
|
+
"minLength": 1000,
|
|
3824
|
+
"type": "string",
|
|
3825
|
+
}
|
|
3826
|
+
`);
|
|
3827
|
+
|
|
3828
|
+
const c = z.file().mime(["image/png", "image/jpg"]).min(1000).max(10000);
|
|
3829
|
+
expect(z.toJSONSchema(c)).toMatchInlineSnapshot(`
|
|
3830
|
+
{
|
|
3831
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3832
|
+
"anyOf": [
|
|
3833
|
+
{
|
|
3834
|
+
"contentMediaType": "image/png",
|
|
3835
|
+
},
|
|
3836
|
+
{
|
|
3837
|
+
"contentMediaType": "image/jpg",
|
|
3838
|
+
},
|
|
3839
|
+
],
|
|
3840
|
+
"contentEncoding": "binary",
|
|
3841
|
+
"format": "binary",
|
|
3842
|
+
"maxLength": 10000,
|
|
3843
|
+
"minLength": 1000,
|
|
3844
|
+
"type": "string",
|
|
3845
|
+
}
|
|
3846
|
+
`);
|
|
3847
|
+
});
|
|
3848
|
+
|
|
3849
|
+
test("custom toJSONSchema", () => {
|
|
3850
|
+
const schema = z.instanceof(Date);
|
|
3851
|
+
schema._zod.toJSONSchema = () => ({
|
|
3852
|
+
type: "string",
|
|
3853
|
+
format: "date-time",
|
|
3854
|
+
});
|
|
3855
|
+
|
|
3856
|
+
expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
|
|
3857
|
+
{
|
|
3858
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3859
|
+
"format": "date-time",
|
|
3860
|
+
"type": "string",
|
|
3861
|
+
}
|
|
3862
|
+
`);
|
|
3863
|
+
});
|
|
3864
|
+
|
|
3865
|
+
test("cycle detection - root", () => {
|
|
3866
|
+
const schema = z.object({
|
|
3867
|
+
name: z.string(),
|
|
3868
|
+
get subcategories() {
|
|
3869
|
+
return z.array(schema);
|
|
3870
|
+
},
|
|
3871
|
+
});
|
|
3872
|
+
|
|
3873
|
+
expect(() => z.toJSONSchema(schema, { cycles: "throw" })).toThrowErrorMatchingInlineSnapshot(`
|
|
3874
|
+
[Error: Cycle detected: #/properties/subcategories/items/<root>
|
|
3875
|
+
|
|
3876
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.]
|
|
3877
|
+
`);
|
|
3878
|
+
});
|
|
3879
|
+
|
|
3880
|
+
test("cycle detection - mutual recursion", () => {
|
|
3881
|
+
const A = z.object({
|
|
3882
|
+
name: z.string(),
|
|
3883
|
+
get subcategories() {
|
|
3884
|
+
return z.array(B);
|
|
3885
|
+
},
|
|
3886
|
+
});
|
|
3887
|
+
|
|
3888
|
+
const B = z.object({
|
|
3889
|
+
name: z.string(),
|
|
3890
|
+
get subcategories() {
|
|
3891
|
+
return z.array(A);
|
|
3892
|
+
},
|
|
3893
|
+
});
|
|
3894
|
+
|
|
3895
|
+
expect(() => z.toJSONSchema(A, { cycles: "throw" })).toThrowErrorMatchingInlineSnapshot(`
|
|
3896
|
+
[Error: Cycle detected: #/properties/subcategories/items/properties/subcategories/items/<root>
|
|
3897
|
+
|
|
3898
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.]
|
|
3899
|
+
`);
|
|
3900
|
+
});
|
|
3901
|
+
|
|
3902
|
+
test("recursive lazy with describe does not stack overflow", () => {
|
|
3903
|
+
const NodeSchema: z.ZodType = z.lazy(() =>
|
|
3904
|
+
z
|
|
3905
|
+
.object({
|
|
3906
|
+
value: z.string().describe("node value"),
|
|
3907
|
+
children: z.array(NodeSchema.describe("child node")).optional().describe("child list"),
|
|
3908
|
+
})
|
|
3909
|
+
.describe("tree node")
|
|
3910
|
+
);
|
|
3911
|
+
|
|
3912
|
+
const result = z.toJSONSchema(NodeSchema, { cycles: "ref", reused: "ref" });
|
|
3913
|
+
expect(result).toBeDefined();
|
|
3914
|
+
expect(result.$defs).toBeDefined();
|
|
3915
|
+
});
|
|
3916
|
+
|
|
3917
|
+
test("__proto__ shape key is emitted as an own property", () => {
|
|
3918
|
+
const schema = z.object({ ["__proto__"]: z.literal("admin"), role: z.string() });
|
|
3919
|
+
const result = z.toJSONSchema(schema, { io: "input" });
|
|
3920
|
+
|
|
3921
|
+
expect(result.required).toEqual(["__proto__", "role"]);
|
|
3922
|
+
// every required key needs a matching entry in properties
|
|
3923
|
+
for (const key of result.required!) {
|
|
3924
|
+
expect(Object.prototype.hasOwnProperty.call(result.properties, key)).toBe(true);
|
|
3925
|
+
}
|
|
3926
|
+
expect(JSON.parse(JSON.stringify(result)).properties.__proto__).toEqual({ type: "string", const: "admin" });
|
|
3927
|
+
});
|
|
3928
|
+
|
|
3929
|
+
test("__proto__ registry id is emitted as an own entry", () => {
|
|
3930
|
+
const myRegistry = z.registry<{ id: string }>();
|
|
3931
|
+
myRegistry.add(z.object({ a: z.string() }), { id: "__proto__" });
|
|
3932
|
+
myRegistry.add(z.object({ b: z.string() }), { id: "normal" });
|
|
3933
|
+
|
|
3934
|
+
expect(Object.keys(z.toJSONSchema(myRegistry).schemas)).toEqual(["__proto__", "normal"]);
|
|
3935
|
+
});
|
|
3936
|
+
|
|
3937
|
+
test("__proto__ def id emits a resolvable $ref", () => {
|
|
3938
|
+
const myRegistry = z.registry<{ id: string }>();
|
|
3939
|
+
const Inner = z.object({ x: z.string() });
|
|
3940
|
+
myRegistry.add(Inner, { id: "__proto__" });
|
|
3941
|
+
|
|
3942
|
+
const json = JSON.parse(JSON.stringify(z.toJSONSchema(z.object({ a: Inner, b: Inner }), { metadata: myRegistry })));
|
|
3943
|
+
expect(json.properties.a.$ref).toBe("#/$defs/__proto__");
|
|
3944
|
+
expect(json.$defs.__proto__).toBeDefined();
|
|
3945
|
+
});
|
|
3946
|
+
|
|
3947
|
+
test("__proto__ patternProperties key is emitted as an own property", () => {
|
|
3948
|
+
const result = z.toJSONSchema(z.looseRecord(z.string().regex(/__proto__/), z.string()));
|
|
3949
|
+
|
|
3950
|
+
expect(Object.getPrototypeOf(result.patternProperties)).toBe(Object.prototype);
|
|
3951
|
+
expect(Object.prototype.hasOwnProperty.call(result.patternProperties, "__proto__")).toBe(true);
|
|
3952
|
+
expect(result.patternProperties?.__proto__).toEqual({ type: "string" });
|
|
3953
|
+
});
|
|
3954
|
+
|
|
3955
|
+
test("__proto__ metadata survives direct and wrapper metadata merges", () => {
|
|
3956
|
+
for (const schema of [z.string(), z.readonly(z.string())]) {
|
|
3957
|
+
const registry = z.registry<Record<string, unknown>>();
|
|
3958
|
+
registry.add(schema, Object.fromEntries([["__proto__", { marker: true }]]));
|
|
3959
|
+
|
|
3960
|
+
const result: any = z.toJSONSchema(schema, { metadata: registry });
|
|
3961
|
+
expect(Object.getPrototypeOf(result)).toBe(Object.prototype);
|
|
3962
|
+
expect(Object.prototype.hasOwnProperty.call(result, "__proto__")).toBe(true);
|
|
3963
|
+
expect(result.__proto__).toEqual({ marker: true });
|
|
3964
|
+
expect(JSON.parse(JSON.stringify(result)).__proto__).toEqual({ marker: true });
|
|
3965
|
+
}
|
|
3966
|
+
});
|
|
3967
|
+
|
|
3968
|
+
test("partialRecord does not require finite keys", () => {
|
|
3969
|
+
const result = z.toJSONSchema(z.partialRecord(z.enum(["__proto__", "b"]), z.string()));
|
|
3970
|
+
|
|
3971
|
+
expect(result.required).toBeUndefined();
|
|
3972
|
+
expect(result.propertyNames).toEqual({ type: "string", enum: ["__proto__", "b"] });
|
|
3973
|
+
expect(result.additionalProperties).toEqual({ type: "string" });
|
|
3974
|
+
});
|
|
3975
|
+
|
|
3976
|
+
describe("unrepresentable callback", () => {
|
|
3977
|
+
test("is consulted for every unrepresentable type", () => {
|
|
3978
|
+
const seen: string[] = [];
|
|
3979
|
+
const collect: z.core.UnrepresentableHandler<z.core.$ZodTypes> = ({ zodSchema }) => {
|
|
3980
|
+
seen.push(zodSchema._zod.def.type);
|
|
3981
|
+
return "any";
|
|
3982
|
+
};
|
|
3983
|
+
|
|
3984
|
+
const schemas = [
|
|
3985
|
+
z.bigint(),
|
|
3986
|
+
z.symbol(),
|
|
3987
|
+
z.undefined(),
|
|
3988
|
+
z.void(),
|
|
3989
|
+
z.date(),
|
|
3990
|
+
z.nan(),
|
|
3991
|
+
z.custom<string>(),
|
|
3992
|
+
z.map(z.string(), z.string()),
|
|
3993
|
+
z.set(z.string()),
|
|
3994
|
+
z.transform((x: unknown) => x),
|
|
3995
|
+
z.literal([undefined]),
|
|
3996
|
+
z.literal([1n]),
|
|
3997
|
+
z.string().catch(() => {
|
|
3998
|
+
throw new Error("dynamic");
|
|
3999
|
+
}),
|
|
4000
|
+
// z.function() is not a ZodType, but its processor is reachable through the same path
|
|
4001
|
+
z.function() as unknown as z.ZodType,
|
|
4002
|
+
];
|
|
4003
|
+
for (const schema of schemas) z.toJSONSchema(schema, { unrepresentable: collect });
|
|
4004
|
+
|
|
4005
|
+
expect(seen).toEqual([
|
|
4006
|
+
"bigint",
|
|
4007
|
+
"symbol",
|
|
4008
|
+
"undefined",
|
|
4009
|
+
"void",
|
|
4010
|
+
"date",
|
|
4011
|
+
"nan",
|
|
4012
|
+
"custom",
|
|
4013
|
+
"map",
|
|
4014
|
+
"set",
|
|
4015
|
+
"transform",
|
|
4016
|
+
"literal",
|
|
4017
|
+
"literal",
|
|
4018
|
+
"catch",
|
|
4019
|
+
"function",
|
|
4020
|
+
]);
|
|
4021
|
+
});
|
|
4022
|
+
|
|
4023
|
+
test("returned JSON Schema replaces the unrepresentable node", () => {
|
|
4024
|
+
// the motivating case: represent dates, keep throwing for everything else
|
|
4025
|
+
const params: z.core.ToJSONSchemaParams = {
|
|
4026
|
+
unrepresentable: ({ zodSchema }) =>
|
|
4027
|
+
zodSchema._zod.def.type === "date" ? { type: "string", format: "date-time" } : "throw",
|
|
4028
|
+
};
|
|
4029
|
+
expect(z.toJSONSchema(z.object({ when: z.date() }), params)).toMatchInlineSnapshot(`
|
|
4030
|
+
{
|
|
4031
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4032
|
+
"additionalProperties": false,
|
|
4033
|
+
"properties": {
|
|
4034
|
+
"when": {
|
|
4035
|
+
"format": "date-time",
|
|
4036
|
+
"type": "string",
|
|
4037
|
+
},
|
|
4038
|
+
},
|
|
4039
|
+
"required": [
|
|
4040
|
+
"when",
|
|
4041
|
+
],
|
|
4042
|
+
"type": "object",
|
|
4043
|
+
}
|
|
4044
|
+
`);
|
|
4045
|
+
expect(() => z.toJSONSchema(z.object({ id: z.bigint() }), params)).toThrow(
|
|
4046
|
+
"BigInt cannot be represented in JSON Schema"
|
|
4047
|
+
);
|
|
4048
|
+
});
|
|
4049
|
+
|
|
4050
|
+
test("`throw` and `undefined` returns produce the default error", () => {
|
|
4051
|
+
expect(() => z.toJSONSchema(z.date(), { unrepresentable: () => "throw" })).toThrow(
|
|
4052
|
+
"Date cannot be represented in JSON Schema"
|
|
4053
|
+
);
|
|
4054
|
+
expect(() => z.toJSONSchema(z.date(), { unrepresentable: () => undefined })).toThrow(
|
|
4055
|
+
"Date cannot be represented in JSON Schema"
|
|
4056
|
+
);
|
|
4057
|
+
});
|
|
4058
|
+
|
|
4059
|
+
test("`any` return matches the string option", () => {
|
|
4060
|
+
expect(z.toJSONSchema(z.date(), { unrepresentable: () => "any" })).toEqual(
|
|
4061
|
+
z.toJSONSchema(z.date(), { unrepresentable: "any" })
|
|
4062
|
+
);
|
|
4063
|
+
});
|
|
4064
|
+
|
|
4065
|
+
test("`message` distinguishes sites that share a schema", () => {
|
|
4066
|
+
const seen: string[] = [];
|
|
4067
|
+
expect(
|
|
4068
|
+
z.toJSONSchema(z.literal([undefined, 1n, "a"]), {
|
|
4069
|
+
unrepresentable: ({ zodSchema, message }) => {
|
|
4070
|
+
seen.push(`${zodSchema._zod.def.type}: ${message}`);
|
|
4071
|
+
return "any";
|
|
4072
|
+
},
|
|
4073
|
+
})
|
|
4074
|
+
).toMatchInlineSnapshot(`
|
|
4075
|
+
{
|
|
4076
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4077
|
+
"enum": [
|
|
4078
|
+
1,
|
|
4079
|
+
"a",
|
|
4080
|
+
],
|
|
4081
|
+
}
|
|
4082
|
+
`);
|
|
4083
|
+
// same `zodSchema`, different message -- the only way to tell the two literal sites apart
|
|
4084
|
+
expect(seen).toEqual([
|
|
4085
|
+
"literal: Literal `undefined` cannot be represented in JSON Schema",
|
|
4086
|
+
"literal: BigInt literals cannot be represented in JSON Schema",
|
|
4087
|
+
]);
|
|
4088
|
+
});
|
|
4089
|
+
|
|
4090
|
+
test("errors thrown by the callback propagate", () => {
|
|
4091
|
+
expect(() =>
|
|
4092
|
+
z.toJSONSchema(z.object({ when: z.date() }), {
|
|
4093
|
+
unrepresentable: ({ zodSchema, path }) => {
|
|
4094
|
+
throw new Error(`${zodSchema._zod.def.type} at /${path.join("/")}`);
|
|
4095
|
+
},
|
|
4096
|
+
})
|
|
4097
|
+
).toThrow("date at /properties/when");
|
|
4098
|
+
});
|
|
4099
|
+
|
|
4100
|
+
test("runs before `override`", () => {
|
|
4101
|
+
const order: string[] = [];
|
|
4102
|
+
expect(
|
|
4103
|
+
z.toJSONSchema(z.date(), {
|
|
4104
|
+
unrepresentable: () => {
|
|
4105
|
+
order.push("unrepresentable");
|
|
4106
|
+
return { type: "string" };
|
|
4107
|
+
},
|
|
4108
|
+
override: (ctx) => {
|
|
4109
|
+
order.push("override");
|
|
4110
|
+
if (ctx.jsonSchema.type === "string") ctx.jsonSchema.format = "date-time";
|
|
4111
|
+
},
|
|
4112
|
+
})
|
|
4113
|
+
).toMatchInlineSnapshot(`
|
|
4114
|
+
{
|
|
4115
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4116
|
+
"format": "date-time",
|
|
4117
|
+
"type": "string",
|
|
4118
|
+
}
|
|
4119
|
+
`);
|
|
4120
|
+
expect(order).toEqual(["unrepresentable", "override"]);
|
|
4121
|
+
});
|
|
4122
|
+
|
|
4123
|
+
test("a returned schema replaces the whole literal", () => {
|
|
4124
|
+
expect(
|
|
4125
|
+
z.toJSONSchema(z.literal(["a", 1n]), {
|
|
4126
|
+
unrepresentable: () => ({ type: "string", pattern: "^\\d+$" }),
|
|
4127
|
+
})
|
|
4128
|
+
).toMatchInlineSnapshot(`
|
|
4129
|
+
{
|
|
4130
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4131
|
+
"pattern": "^\\d+$",
|
|
4132
|
+
"type": "string",
|
|
4133
|
+
}
|
|
4134
|
+
`);
|
|
4135
|
+
|
|
4136
|
+
// "any" keeps the existing per-value behavior: undefined dropped, bigint coerced
|
|
4137
|
+
expect(z.toJSONSchema(z.literal(["a", 1n, undefined]), { unrepresentable: () => "any" })).toEqual(
|
|
4138
|
+
z.toJSONSchema(z.literal(["a", 1n, undefined]), { unrepresentable: "any" })
|
|
4139
|
+
);
|
|
4140
|
+
});
|
|
4141
|
+
|
|
4142
|
+
const dateToString: z.core.ToJSONSchemaParams["unrepresentable"] = ({ zodSchema }) =>
|
|
4143
|
+
zodSchema._zod.def.type === "date" ? { type: "string", format: "date-time" } : "throw";
|
|
4144
|
+
|
|
4145
|
+
test("emits a valid OpenAPI 3.0 schema", async () => {
|
|
4146
|
+
const jsonSchema = z.toJSONSchema(z.object({ start: z.date() }), {
|
|
4147
|
+
target: "openapi-3.0",
|
|
4148
|
+
unrepresentable: dateToString,
|
|
4149
|
+
});
|
|
4150
|
+
expect(jsonSchema).toMatchInlineSnapshot(`
|
|
4151
|
+
{
|
|
4152
|
+
"additionalProperties": false,
|
|
4153
|
+
"properties": {
|
|
4154
|
+
"start": {
|
|
4155
|
+
"format": "date-time",
|
|
4156
|
+
"type": "string",
|
|
4157
|
+
},
|
|
4158
|
+
},
|
|
4159
|
+
"required": [
|
|
4160
|
+
"start",
|
|
4161
|
+
],
|
|
4162
|
+
"type": "object",
|
|
4163
|
+
}
|
|
4164
|
+
`);
|
|
4165
|
+
await expect(validateOpenAPI30Schema(jsonSchema)).resolves.toBe(true);
|
|
4166
|
+
});
|
|
4167
|
+
|
|
4168
|
+
test("the returned schema survives extraction into $defs", () => {
|
|
4169
|
+
const When = z.date().meta({ id: "When" });
|
|
4170
|
+
expect(
|
|
4171
|
+
z.toJSONSchema(z.object({ start: When, end: When }), { unrepresentable: dateToString })
|
|
4172
|
+
).toMatchInlineSnapshot(`
|
|
4173
|
+
{
|
|
4174
|
+
"$defs": {
|
|
4175
|
+
"When": {
|
|
4176
|
+
"format": "date-time",
|
|
4177
|
+
"type": "string",
|
|
4178
|
+
},
|
|
4179
|
+
},
|
|
4180
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4181
|
+
"additionalProperties": false,
|
|
4182
|
+
"properties": {
|
|
4183
|
+
"end": {
|
|
4184
|
+
"$ref": "#/$defs/When",
|
|
4185
|
+
},
|
|
4186
|
+
"start": {
|
|
4187
|
+
"$ref": "#/$defs/When",
|
|
4188
|
+
},
|
|
4189
|
+
},
|
|
4190
|
+
"required": [
|
|
4191
|
+
"start",
|
|
4192
|
+
"end",
|
|
4193
|
+
],
|
|
4194
|
+
"type": "object",
|
|
4195
|
+
}
|
|
4196
|
+
`);
|
|
4197
|
+
});
|
|
4198
|
+
|
|
4199
|
+
test("applies to dynamic catch values", () => {
|
|
4200
|
+
const schema = z.string().catch(() => {
|
|
4201
|
+
throw new Error("dynamic");
|
|
4202
|
+
});
|
|
4203
|
+
expect(
|
|
4204
|
+
z.toJSONSchema(schema, {
|
|
4205
|
+
unrepresentable: () => ({ default: "fallback" }),
|
|
4206
|
+
})
|
|
4207
|
+
).toMatchInlineSnapshot(`
|
|
4208
|
+
{
|
|
4209
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4210
|
+
"default": "fallback",
|
|
4211
|
+
"type": "string",
|
|
4212
|
+
}
|
|
4213
|
+
`);
|
|
4214
|
+
});
|
|
4215
|
+
});
|
|
4216
|
+
|
|
4217
|
+
describe("intersection folding", () => {
|
|
4218
|
+
const TARGETS = ["draft-2020-12", "draft-07", "draft-04", "openapi-3.0"] as const;
|
|
4219
|
+
const body = (schema: z.ZodType, params?: Parameters<typeof z.toJSONSchema>[1]) => {
|
|
4220
|
+
const { $schema, ...rest } = z.toJSONSchema(schema, params) as Record<string, unknown>;
|
|
4221
|
+
return rest;
|
|
4222
|
+
};
|
|
4223
|
+
|
|
4224
|
+
test("two objects become one object", () => {
|
|
4225
|
+
expect(body(z.object({ name: z.string() }).and(z.object({ age: z.number() })))).toMatchInlineSnapshot(`
|
|
4226
|
+
{
|
|
4227
|
+
"additionalProperties": false,
|
|
4228
|
+
"properties": {
|
|
4229
|
+
"age": {
|
|
4230
|
+
"type": "number",
|
|
4231
|
+
},
|
|
4232
|
+
"name": {
|
|
4233
|
+
"type": "string",
|
|
4234
|
+
},
|
|
4235
|
+
},
|
|
4236
|
+
"required": [
|
|
4237
|
+
"name",
|
|
4238
|
+
"age",
|
|
4239
|
+
],
|
|
4240
|
+
"type": "object",
|
|
4241
|
+
}
|
|
4242
|
+
`);
|
|
4243
|
+
});
|
|
4244
|
+
|
|
4245
|
+
test("the folded shape is identical on every target", () => {
|
|
4246
|
+
const schema = z.object({ name: z.string() }).and(z.object({ age: z.number() }));
|
|
4247
|
+
const bodies = TARGETS.map((target) => body(schema, { target }));
|
|
4248
|
+
for (const emitted of bodies) expect(emitted).toEqual(bodies[0]);
|
|
4249
|
+
});
|
|
4250
|
+
|
|
4251
|
+
test("closed only when every member is closed", () => {
|
|
4252
|
+
expect(body(z.strictObject({ a: z.string() }).and(z.strictObject({ b: z.number() })))).toMatchObject({
|
|
4253
|
+
additionalProperties: false,
|
|
4254
|
+
});
|
|
4255
|
+
// A loose member keeps the intersection open, which is what the parser does: it merges both results, so the loose side's extra keys survive.
|
|
4256
|
+
expect(body(z.looseObject({ a: z.string() }).and(z.object({ b: z.number() })))).not.toHaveProperty(
|
|
4257
|
+
"additionalProperties"
|
|
4258
|
+
);
|
|
4259
|
+
});
|
|
4260
|
+
|
|
4261
|
+
test("chained and nested intersections fold flat", () => {
|
|
4262
|
+
const chained = z
|
|
4263
|
+
.object({ a: z.string() })
|
|
4264
|
+
.and(z.object({ b: z.string() }))
|
|
4265
|
+
.and(z.object({ c: z.string() }));
|
|
4266
|
+
expect(body(chained)).toMatchObject({ properties: { a: {}, b: {}, c: {} }, required: ["a", "b", "c"] });
|
|
4267
|
+
const nested = z.object({ a: z.string() }).and(z.object({ b: z.string() }).and(z.object({ c: z.string() })));
|
|
4268
|
+
expect(body(nested)).toEqual(body(chained));
|
|
4269
|
+
});
|
|
4270
|
+
|
|
4271
|
+
test("required is the union, and an optional key stays optional", () => {
|
|
4272
|
+
expect(body(z.object({ a: z.string().optional() }).and(z.object({ b: z.string() })))).toMatchObject({
|
|
4273
|
+
properties: { a: { type: "string" }, b: { type: "string" } },
|
|
4274
|
+
required: ["b"],
|
|
4275
|
+
});
|
|
4276
|
+
});
|
|
4277
|
+
|
|
4278
|
+
test("a key both members declare has to satisfy both", () => {
|
|
4279
|
+
// identical declarations collapse
|
|
4280
|
+
expect(body(z.object({ k: z.string() }).and(z.object({ k: z.string() })))).toMatchObject({
|
|
4281
|
+
properties: { k: { type: "string" } },
|
|
4282
|
+
});
|
|
4283
|
+
// object declarations fold, matching the parser's deep merge
|
|
4284
|
+
expect(
|
|
4285
|
+
body(z.object({ k: z.object({ a: z.string() }) }).and(z.object({ k: z.object({ b: z.string() }) })))
|
|
4286
|
+
).toMatchObject({
|
|
4287
|
+
properties: { k: { type: "object", properties: { a: {}, b: {} }, required: ["a", "b"] } },
|
|
4288
|
+
});
|
|
4289
|
+
// anything else stays an intersection one level down
|
|
4290
|
+
expect(body(z.object({ k: z.string() }).and(z.object({ k: z.number() })))).toMatchObject({
|
|
4291
|
+
properties: { k: { allOf: [{ type: "string" }, { type: "number" }] } },
|
|
4292
|
+
});
|
|
4293
|
+
});
|
|
4294
|
+
|
|
4295
|
+
test("an intersection distributes over a union", () => {
|
|
4296
|
+
const schema = z
|
|
4297
|
+
.object({ name: z.string() })
|
|
4298
|
+
.and(
|
|
4299
|
+
z.discriminatedUnion("type", [
|
|
4300
|
+
z.object({ type: z.literal("a"), value: z.string() }),
|
|
4301
|
+
z.object({ type: z.literal("b"), count: z.number() }),
|
|
4302
|
+
])
|
|
4303
|
+
);
|
|
4304
|
+
expect(body(schema)).toMatchObject({
|
|
4305
|
+
oneOf: [
|
|
4306
|
+
{ type: "object", properties: { name: {}, type: {}, value: {} }, additionalProperties: false },
|
|
4307
|
+
{ type: "object", properties: { name: {}, type: {}, count: {} }, additionalProperties: false },
|
|
4308
|
+
],
|
|
4309
|
+
});
|
|
4310
|
+
const inclusive = z
|
|
4311
|
+
.object({ name: z.string() })
|
|
4312
|
+
.and(z.union([z.object({ v: z.string() }), z.object({ c: z.number() })]));
|
|
4313
|
+
expect(body(inclusive)).toMatchObject({
|
|
4314
|
+
anyOf: [{ properties: { name: {}, v: {} } }, { properties: { name: {}, c: {} } }],
|
|
4315
|
+
});
|
|
4316
|
+
});
|
|
4317
|
+
|
|
4318
|
+
test("input conversion has nothing to close", () => {
|
|
4319
|
+
expect(body(z.object({ a: z.string() }).and(z.object({ b: z.string() })), { io: "input" })).toEqual({
|
|
4320
|
+
type: "object",
|
|
4321
|
+
properties: { a: { type: "string" }, b: { type: "string" } },
|
|
4322
|
+
required: ["a", "b"],
|
|
4323
|
+
});
|
|
4324
|
+
});
|
|
4325
|
+
|
|
4326
|
+
test("folds through a property and through z.lazy", () => {
|
|
4327
|
+
expect(body(z.object({ inner: z.object({ a: z.string() }).and(z.object({ b: z.string() })) }))).toMatchObject({
|
|
4328
|
+
properties: { inner: { type: "object", properties: { a: {}, b: {} } } },
|
|
4329
|
+
});
|
|
4330
|
+
const self: z.ZodType = z.lazy(() => z.object({ a: z.string() }).and(z.object({ next: z.optional(self) })));
|
|
4331
|
+
expect(body(self)).toMatchObject({ type: "object", properties: { a: {}, next: { $ref: "#" } } });
|
|
4332
|
+
});
|
|
4333
|
+
|
|
4334
|
+
test("metadata on the intersection itself survives", () => {
|
|
4335
|
+
expect(
|
|
4336
|
+
body(
|
|
4337
|
+
z
|
|
4338
|
+
.object({ a: z.string() })
|
|
4339
|
+
.and(z.object({ b: z.string() }))
|
|
4340
|
+
.meta({ title: "T" })
|
|
4341
|
+
)
|
|
4342
|
+
).toMatchObject({
|
|
4343
|
+
title: "T",
|
|
4344
|
+
type: "object",
|
|
4345
|
+
properties: { a: {}, b: {} },
|
|
4346
|
+
});
|
|
4347
|
+
});
|
|
4348
|
+
|
|
4349
|
+
test("a catchall constrains the sibling's keys too", () => {
|
|
4350
|
+
// The catchall member does not declare `b`, so its `additionalProperties` is what it demands of `b`. Folding `b` into `properties` has to carry that demand across, or the key would escape it.
|
|
4351
|
+
const schema = z
|
|
4352
|
+
.object({ a: z.string() })
|
|
4353
|
+
.catchall(z.number())
|
|
4354
|
+
.and(z.object({ b: z.string() }));
|
|
4355
|
+
expect(body(schema)).toEqual({
|
|
4356
|
+
type: "object",
|
|
4357
|
+
properties: { a: { type: "string" }, b: { allOf: [{ type: "number" }, { type: "string" }] } },
|
|
4358
|
+
required: ["a", "b"],
|
|
4359
|
+
additionalProperties: { type: "number" },
|
|
4360
|
+
});
|
|
4361
|
+
});
|
|
4362
|
+
|
|
4363
|
+
test("two catchalls both constrain the keys neither declares", () => {
|
|
4364
|
+
const schema = z
|
|
4365
|
+
.object({})
|
|
4366
|
+
.catchall(z.number())
|
|
4367
|
+
.and(z.object({}).catchall(z.number().min(0)));
|
|
4368
|
+
expect(body(schema)).toEqual({
|
|
4369
|
+
type: "object",
|
|
4370
|
+
properties: {},
|
|
4371
|
+
additionalProperties: { allOf: [{ type: "number" }, { type: "number", minimum: 0 }] },
|
|
4372
|
+
});
|
|
4373
|
+
expect(schema.safeParse({ zz: 5 }).success).toBe(true);
|
|
4374
|
+
expect(schema.safeParse({ zz: -1 }).success).toBe(false);
|
|
4375
|
+
});
|
|
4376
|
+
|
|
4377
|
+
test("the emitted openness agrees with the parser for every pair of object modes", () => {
|
|
4378
|
+
const modes = {
|
|
4379
|
+
strip: (shape: z.ZodRawShape) => z.object(shape),
|
|
4380
|
+
strict: (shape: z.ZodRawShape) => z.strictObject(shape),
|
|
4381
|
+
loose: (shape: z.ZodRawShape) => z.looseObject(shape),
|
|
4382
|
+
catchall: (shape: z.ZodRawShape) => z.object(shape).catchall(z.number()),
|
|
4383
|
+
};
|
|
4384
|
+
const grid: Record<string, unknown> = {};
|
|
4385
|
+
for (const [leftName, left] of Object.entries(modes)) {
|
|
4386
|
+
for (const [rightName, right] of Object.entries(modes)) {
|
|
4387
|
+
const schema = left({ a: z.string() }).and(right({ b: z.number() }));
|
|
4388
|
+
const emitted = body(schema) as { additionalProperties?: unknown };
|
|
4389
|
+
grid[`${leftName} & ${rightName}`] = emitted.additionalProperties ?? "open";
|
|
4390
|
+
|
|
4391
|
+
// Whatever the emitted keyword says, it has to agree with what the parser does with a key neither member declares.
|
|
4392
|
+
const parsed = schema.safeParse({ a: "s", b: 1, zz: 7 });
|
|
4393
|
+
const keepsUnknown = parsed.success && Object.prototype.hasOwnProperty.call(parsed.data, "zz");
|
|
4394
|
+
if (keepsUnknown) expect(emitted.additionalProperties).not.toBe(false);
|
|
4395
|
+
}
|
|
4396
|
+
}
|
|
4397
|
+
expect(grid).toMatchInlineSnapshot(`
|
|
4398
|
+
{
|
|
4399
|
+
"catchall & catchall": {
|
|
4400
|
+
"type": "number",
|
|
4401
|
+
},
|
|
4402
|
+
"catchall & loose": {
|
|
4403
|
+
"type": "number",
|
|
4404
|
+
},
|
|
4405
|
+
"catchall & strict": {
|
|
4406
|
+
"type": "number",
|
|
4407
|
+
},
|
|
4408
|
+
"catchall & strip": {
|
|
4409
|
+
"type": "number",
|
|
4410
|
+
},
|
|
4411
|
+
"loose & catchall": {
|
|
4412
|
+
"type": "number",
|
|
4413
|
+
},
|
|
4414
|
+
"loose & loose": "open",
|
|
4415
|
+
"loose & strict": "open",
|
|
4416
|
+
"loose & strip": "open",
|
|
4417
|
+
"strict & catchall": {
|
|
4418
|
+
"type": "number",
|
|
4419
|
+
},
|
|
4420
|
+
"strict & loose": "open",
|
|
4421
|
+
"strict & strict": false,
|
|
4422
|
+
"strict & strip": false,
|
|
4423
|
+
"strip & catchall": {
|
|
4424
|
+
"type": "number",
|
|
4425
|
+
},
|
|
4426
|
+
"strip & loose": "open",
|
|
4427
|
+
"strip & strict": false,
|
|
4428
|
+
"strip & strip": false,
|
|
4429
|
+
}
|
|
4430
|
+
`);
|
|
4431
|
+
});
|
|
4432
|
+
|
|
4433
|
+
test("a __proto__ key stays an own property", () => {
|
|
4434
|
+
const folded = body(z.object({ ["__proto__"]: z.string() }).and(z.object({ b: z.number() }))) as any;
|
|
4435
|
+
expect(Object.prototype.hasOwnProperty.call(folded.properties, "__proto__")).toBe(true);
|
|
4436
|
+
expect(folded.required).toEqual(["__proto__", "b"]);
|
|
4437
|
+
});
|
|
4438
|
+
});
|
|
4439
|
+
|
|
4440
|
+
describe("intersection folding declines", () => {
|
|
4441
|
+
// Every case here keeps the `allOf` it produces today. The fold only understands the four object keywords, so a member carrying anything else is left alone rather than having a constraint dropped or an annotation re-scoped.
|
|
4442
|
+
const allOf = (schema: z.ZodType, params?: Parameters<typeof z.toJSONSchema>[1]) =>
|
|
4443
|
+
(z.toJSONSchema(schema, params) as any).allOf;
|
|
4444
|
+
|
|
4445
|
+
test("a member that is a reference keeps its reference", () => {
|
|
4446
|
+
const named = z.object({ a: z.string() }).meta({ id: "Named" });
|
|
4447
|
+
expect(allOf(named.and(z.object({ b: z.string() })))[0]).toEqual({ $ref: "#/$defs/Named" });
|
|
4448
|
+
|
|
4449
|
+
const shared = z.object({ c: z.string() });
|
|
4450
|
+
const reused = z.toJSONSchema(z.object({ x: shared.and(z.object({ d: z.string() })), y: shared }), {
|
|
4451
|
+
reused: "ref",
|
|
4452
|
+
}) as any;
|
|
4453
|
+
expect(reused.properties.x.allOf[0]).toEqual({ $ref: "#/$defs/__schema0" });
|
|
4454
|
+
|
|
4455
|
+
const cyclic: any = z.object({
|
|
4456
|
+
get next() {
|
|
4457
|
+
return z.optional(cyclic);
|
|
4458
|
+
},
|
|
4459
|
+
n: z.string(),
|
|
4460
|
+
});
|
|
4461
|
+
expect(allOf(cyclic.and(z.object({ m: z.string() })))[0].$ref).toBe("#/$defs/__schema0");
|
|
4462
|
+
});
|
|
4463
|
+
|
|
4464
|
+
test("an annotated member keeps its place", () => {
|
|
4465
|
+
expect(
|
|
4466
|
+
allOf(
|
|
4467
|
+
z
|
|
4468
|
+
.object({ a: z.string() })
|
|
4469
|
+
.describe("A")
|
|
4470
|
+
.and(z.object({ b: z.string() }))
|
|
4471
|
+
)[0]
|
|
4472
|
+
).toMatchObject({
|
|
4473
|
+
description: "A",
|
|
4474
|
+
});
|
|
4475
|
+
});
|
|
4476
|
+
|
|
4477
|
+
test("members that are not plain objects are left alone", () => {
|
|
4478
|
+
expect(allOf(z.intersection(z.string().min(2), z.string().max(5)))).toHaveLength(2);
|
|
4479
|
+
expect(allOf(z.object({ a: z.string() }).and(z.nullable(z.object({ b: z.string() }))))).toHaveLength(2);
|
|
4480
|
+
expect(
|
|
4481
|
+
allOf(z.object({ label: z.string() }).and(z.looseRecord(z.string().regex(/^label:[a-z]{2}$/), z.string())))
|
|
4482
|
+
).toHaveLength(2);
|
|
4483
|
+
});
|
|
4484
|
+
|
|
4485
|
+
test("a shared member is never rewritten for its other uses", () => {
|
|
4486
|
+
const shared = z.object({ c: z.string() });
|
|
4487
|
+
const result = z.toJSONSchema(z.object({ x: shared.and(z.object({ d: z.string() })), y: shared })) as any;
|
|
4488
|
+
expect(result.properties.x).toMatchObject({ properties: { c: {}, d: {} }, additionalProperties: false });
|
|
4489
|
+
// `y` is the same Zod schema, emitted separately, and keeps the closedness it had on its own.
|
|
4490
|
+
expect(result.properties.y).toEqual({
|
|
4491
|
+
type: "object",
|
|
4492
|
+
properties: { c: { type: "string" } },
|
|
4493
|
+
required: ["c"],
|
|
4494
|
+
additionalProperties: false,
|
|
4495
|
+
});
|
|
4496
|
+
});
|
|
4497
|
+
|
|
4498
|
+
test("registry conversion keeps its cross-references", () => {
|
|
4499
|
+
const registry = z.registry<{ id: string }>();
|
|
4500
|
+
const left = z.object({ p: z.string() });
|
|
4501
|
+
const right = z.object({ q: z.string() });
|
|
4502
|
+
registry.add(left, { id: "P" });
|
|
4503
|
+
registry.add(right, { id: "Q" });
|
|
4504
|
+
registry.add(left.and(right), { id: "PQ" });
|
|
4505
|
+
expect((z.toJSONSchema(registry) as any).schemas.PQ.allOf).toEqual([{ $ref: "P" }, { $ref: "Q" }]);
|
|
4506
|
+
});
|
|
4507
|
+
|
|
4508
|
+
test("override still runs, and sees the intersection before it folds", () => {
|
|
4509
|
+
const schema = z.object({ a: z.string() }).and(z.object({ b: z.string() }));
|
|
4510
|
+
const result = z.toJSONSchema(schema, {
|
|
4511
|
+
override(ctx) {
|
|
4512
|
+
if ((ctx.jsonSchema as any).allOf) (ctx.jsonSchema as any).title = "intersection";
|
|
4513
|
+
},
|
|
4514
|
+
}) as any;
|
|
4515
|
+
expect(result).toMatchObject({ title: "intersection", type: "object", properties: { a: {}, b: {} } });
|
|
4516
|
+
});
|
|
4517
|
+
|
|
4518
|
+
test("an override that writes object keywords wins over the fold", () => {
|
|
4519
|
+
// The override runs first, so anything it puts on the intersection is deliberate. Folding would overwrite it silently, so the fold stands down instead.
|
|
4520
|
+
const result = z.toJSONSchema(z.object({ a: z.string() }).and(z.object({ b: z.string() })), {
|
|
4521
|
+
override(ctx) {
|
|
4522
|
+
if ((ctx.jsonSchema as any).allOf) (ctx.jsonSchema as any).additionalProperties = true;
|
|
4523
|
+
},
|
|
4524
|
+
}) as any;
|
|
4525
|
+
expect(result.additionalProperties).toBe(true);
|
|
4526
|
+
expect(result.allOf).toHaveLength(2);
|
|
4527
|
+
});
|
|
4528
|
+
|
|
4529
|
+
test("more than one union member is left alone rather than multiplied out", () => {
|
|
4530
|
+
// The second union lands among the members the first is distributed across, and a union is not an object, so every branch fails to fold and the whole intersection stands down.
|
|
4531
|
+
const schema = z
|
|
4532
|
+
.object({ a: z.string() })
|
|
4533
|
+
.and(z.union([z.object({ v: z.string() }), z.object({ w: z.string() })]))
|
|
4534
|
+
.and(z.union([z.object({ x: z.string() }), z.object({ y: z.string() })]));
|
|
4535
|
+
expect(allOf(schema)).toHaveLength(3);
|
|
4536
|
+
});
|
|
4537
|
+
});
|