Skip to content

Conversation

@jkomyno
Copy link
Collaborator

@jkomyno jkomyno commented Nov 11, 2025

This PR:

@macroscopeapp
Copy link

macroscopeapp bot commented Nov 11, 2025

Add dual Zod v3/v4 compatibility in ts/packages/json-schema-to-zod via zod-compat and refactor object additionalProperties handling to use catchall(z.any()) when true

Introduce a zod-compat layer and update parsers to operate with Zod v3/v4, adjust typing to ZodTypeAny, and refactor object parsing to treat additionalProperties true as catchall(z.any()) and false as strict(); add a Mastra example script and update example dependencies.

🖇️ Linked Issues

This pull request addresses issue #2109 referenced in the title by implementing Zod version compatibility within the json-schema-to-zod package.

📍Where to Start

Start with the zod-compat module in zod-compat.ts, then review the entry point jsonSchemaToZod in json-schema-to-zod.ts and the object parser changes in parse-object.ts.


📊 Macroscope summarized 82d0618. 16 files reviewed, 21 issues evaluated, 20 issues filtered, 1 comment posted. View details

Copy link

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.

Copy link

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`,
Copy link

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/).

Suggested change
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.

Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Composio mastra provider gettools failed

2 participants