-
Notifications
You must be signed in to change notification settings - Fork 4.4k
fix(json-schema-to-zod): issue #2109 #2163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Conversation
Add dual Zod v3/v4 compatibility in
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue on line in ts/packages/json-schema-to-zod/src/parsers/parse-object.ts:122:
Suggestion: guard for empty patternProperties. Indexing patternPropertyValues[0] feeds undefined into z.record/catchall and can crash. Only read the first value when non-empty; otherwise skip the catchall or use a safe fallback (e.g., existing properties schema).
- if (normalizedSchema.patternProperties) {
+ if (hasPatternProperties) {🚀 Reply to ask Macroscope to explain or update this suggestion.
👍 Helpful? React to give us feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue on line in ts/packages/json-schema-to-zod/src/parsers/parse-object.ts:136:
catchall is set to a union of patternProperties when additionalProperties is true or unspecified, so unmatched keys are still validated and can fail. Consider using z.any() for catchall when additionalProperties allows any value; keep schema-only validation for additionalProperties as an object.
🚀 Reply to ask Macroscope to explain or update this suggestion.
👍 Helpful? React to give us feedback.
| ctx.addIssue({ | ||
| path: [...ctx.path, key], | ||
| code: 'custom', | ||
| message: `Invalid input: Key matching regex /${key}/ must match schema`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patternProperties error message uses the input key instead of the regex pattern, which is misleading. Consider interpolating patternPropertyKey in the message so it references the actual pattern (e.g., /patternPropertyKey/).
| message: `Invalid input: Key matching regex /${key}/ must match schema`, | |
| message: `Invalid input: Key matching regex /${patternPropertyKey}/ must match schema`, |
🚀 Reply to ask Macroscope to explain or update this suggestion.
👍 Helpful? React to give us feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue on line in ts/packages/json-schema-to-zod/src/parsers/parse-enum.ts:5:
z.literal checks object/array values by reference, but JSON Schema enum uses structural equality. When the single enum value is a non-primitive, this will incorrectly reject structurally equal values. Consider using a deep-equality refine for non-primitives in the single-value branch, and keep z.literal for primitives.
🚀 Reply to ask Macroscope to explain or update this suggestion.
👍 Helpful? React to give us feedback.
This PR:
@composio/json-schema-to-zodso that it produces output consistent with the installed version of Zod^3.25.0 || ^4.0.0