Skip to content

fix: forward forceResolution through parseBrandedDef to prevent circular $ref#1829

Open
xodn348 wants to merge 1 commit intoopenai:masterfrom
xodn348:fix/issue-1739-circular-ref-branded-zod
Open

fix: forward forceResolution through parseBrandedDef to prevent circular $ref#1829
xodn348 wants to merge 1 commit intoopenai:masterfrom
xodn348:fix/issue-1739-circular-ref-branded-zod

Conversation

@xodn348
Copy link
Copy Markdown

@xodn348 xodn348 commented Apr 18, 2026

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 definition entry that is just { $ref: '#/definitions/..._same_name' } — a self-referencing circular $ref.

The fix passes forceResolution through parseBrandedDef so the inner type is always fully resolved when required.

Changes:

  • src/_vendor/zod-to-json-schema/parsers/branded.ts: Accept and forward forceResolution parameter
  • src/_vendor/zod-to-json-schema/parseDef.ts: Pass forceResolution to parseBrandedDef at call site

Fixes #1739

…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
@xodn348 xodn348 requested a review from a team as a code owner April 18, 2026 23:05
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.

zodTextFormat generates invalid circular $ref in JSON schema definitions

1 participant