fix: forward forceResolution through parseBrandedDef to prevent circular $ref#1829
Open
xodn348 wants to merge 1 commit intoopenai:masterfrom
Open
fix: forward forceResolution through parseBrandedDef to prevent circular $ref#1829xodn348 wants to merge 1 commit intoopenai:masterfrom
xodn348 wants to merge 1 commit intoopenai:masterfrom
Conversation
…lar $ref
When a branded Zod type (e.g. z.string().brand<'SlideId'>()) is used in
multiple places in a schema, parseDef registers the inner type's def in
refs.seen on first encounter. On second encounter, because parseBrandedDef
did not forward the forceResolution parameter, parseDef returns a $ref
instead of re-resolving. With the extract-to-root strategy this creates a
self-referencing circular $ref like { $ref: '#/definitions/..._same' }.
The fix passes forceResolution through parseBrandedDef so the inner type
is always fully resolved when required.
Fixes openai#1739
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.
When a branded Zod type (e.g.
z.string().brand<"SlideId">()) is used in multiple places in a schema,parseDefregisters the inner type's def inrefs.seenon first encounter. On second encounter, becauseparseBrandedDefdid not forward theforceResolutionparameter,parseDefreturns a$refinstead of re-resolving. With theextract-to-rootstrategy this creates a definition entry that is just{ $ref: '#/definitions/..._same_name' }— a self-referencing circular$ref.The fix passes
forceResolutionthroughparseBrandedDefso the inner type is always fully resolved when required.Changes:
src/_vendor/zod-to-json-schema/parsers/branded.ts: Accept and forwardforceResolutionparametersrc/_vendor/zod-to-json-schema/parseDef.ts: PassforceResolutiontoparseBrandedDefat call siteFixes #1739