Skip to content

fix: prevent metadata from overriding schema-derived type in toJSONSchema - #6270

Open
deepshekhardas wants to merge 1 commit into
colinhacks:mainfrom
deepshekhardas:fix/metadata-no-type-override
Open

fix: prevent metadata from overriding schema-derived type in toJSONSchema#6270
deepshekhardas wants to merge 1 commit into
colinhacks:mainfrom
deepshekhardas:fix/metadata-no-type-override

Conversation

@deepshekhardas

Copy link
Copy Markdown

Fixes #5990.

Problem

Calling z.string().meta({ type: 'number' }).toJSONSchema() produces { type: "number" } because all metadata fields are blindly copied into the JSON Schema output, allowing metadata to override schema-derived properties like type.

Fix

Exclude the type field from metadata before merging into the JSON Schema. Schema-derived properties always take precedence over metadata.

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.

z.toJSONSchema() allows overriding type via metadata

1 participant