Repository navigation
feat(zod)!: make emToZodSchema a native branded z.enum - #39
Merged
Merged
Conversation
emToZodSchema is a z.custom schema, which z.toJSONSchema and MCP or model tool definitions cannot describe. emToZodEnum builds a native z.enum from the declaration's member object, so it converts to a JSON Schema string enum while its output stays the branded member union.
CatOfJupit3r
temporarily deployed
to
extended-validation
October 15, 2026 19:10 — with
GitHub Actions
Inactive
Fold the JSON Schema friendly behavior into emToZodSchema instead of adding a second adapter. emToZodSchema now returns z.enum built from the declaration's member object, typed as the branded member union, so z.toJSONSchema can describe it. Invalid values report an invalid_value issue with the same message. The zod peer range is now ^4.0.0. BREAKING CHANGE: enumwaii/zod requires Zod 4, emToZodSchema returns z.ZodEnum instead of z.ZodType, and invalid values report invalid_value instead of a custom issue.
CatOfJupit3r
temporarily deployed
to
extended-validation
October 15, 2026 19:27 — with
GitHub Actions
Inactive
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
emToZodSchemareturns az.customschema. Parsing works, but tools that introspect Zod schemas cannot describe it.z.toJSONSchemacannot represent it, so it cannot sit in MCP or model tool input schemas. Consumers who need JSON Schema have to writez.enum(declaration.rawValues), which drops the brand, and then cast back withas unknown as z.ZodType<...>.Behavior
emToZodSchema(declaration)now returns a native Zod 4z.enumbuilt from the declaration's.enummember object, typed as the branded member union, with no cast.z.toJSONSchemadescribes it as{ type: "string", enum: [...] }.Differences from the previous
z.customschemaWhat the
z.customversion did, and what the new one does:z.custom(before)z.enum(now)declaration.is(string in the member set)customissue, messageExpected one of: A, Binvalid_valueissue withvalues. The message is kept asExpected one of: A, B.z.ZodType<Branded>z.ZodEnum<{ [key]: Branded }>, still assignable toz.ZodType<Branded>. Adds.enum,.options,.extract(),.exclude().em({ ORDER_PAID: "order-paid" }))schema.enum.pick,omit,extend,em.combine,derive-withcasing)ispickandextend).z.toJSONSchema{ type: "string", enum: [...] }^3.25.0 || ^4.0.0)z.enum(object)is Zod 4 API, so the peer range is now^4.0.0.Nothing that the
z.customversion did needed keeping beyond the error message, which is kept.Release level
This is a major change for
enumwaii, because of the narrower Zod peer range, the different issue code, and the different return type.eslint-plugin-enumwaiigets a patch for the report wording. See the changeset.Changes
packages/enumwaii/src/adapters/zod.ts:emToZodSchemareturnsz.enum(declaration.enum, { error }), with updated JSDoc.packages/enumwaii/package.json:zodpeer range^4.0.0.invalid_valueissue and message,options, JSON Schema output, object-declaration keys,pickandextend) and type tests (brandedz.output,ZodEnum, composition inz.object, raw literals not assignable).prefer-native-schema-adapters: the report says the adapter keeps the branded output type.enumwaiimajor,eslint-plugin-enumwaiipatch. No version bump or publish in this PR.Validation
pnpm checkpasses (exit 0): format, pins, lint, tests (enumwaii 24 passed), type tests, skills, build, API JSDoc, publint/attw, and every example (including the orpc and tanstack-start-solid examples that composeemToZodSchemaintoz.object).