Skip to content

fix(zod): sanitize extracted definition refs#1903

Open
FU-max-boop wants to merge 2 commits into
openai:masterfrom
FU-max-boop:fix/web-search-open-page-action-types
Open

fix(zod): sanitize extracted definition refs#1903
FU-max-boop wants to merge 2 commits into
openai:masterfrom
FU-max-boop:fix/web-search-open-page-action-types

Conversation

@FU-max-boop
Copy link
Copy Markdown

  • I understand that this repository is auto-generated and my pull request may not be merged

Summary

  • normalize whitespace to _ when zod v3 schemas extract reused definitions to root refs
  • keep $ref values and definitions keys aligned after normalization
  • add a regression test for reused schemas under property names containing spaces

Why

zodResponseFormat can currently produce $ref values such as #/definitions/example-scope_properties_group_properties_Thing With Spaces. Those literal spaces can be rejected by the API and make the generated schema harder to consume.

Fixes #1679.

Testing

@FU-max-boop FU-max-boop requested a review from a team as a code owner May 28, 2026 22:45
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6ad9563f79

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +134 to +137
const name = item.path
.slice(refs.basePath.length + 1)
.join('_')
.replace(/\s+/g, '_');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve unique names when normalizing refs

When a schema contains two distinct reused definitions whose extracted paths differ only by whitespace vs underscores, this normalization maps both to the same definition name. For example, reused properties named Thing With Spaces and Thing_With_Spaces now both emit refs ending in Thing_With_Spaces, so the later refs.definitions[name] = item.def overwrites the earlier definition and existing $refs can resolve to the wrong schema. The sanitizer needs to escape or otherwise disambiguate normalized names instead of using a lossy replacement.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d3c808dc: extracted definition path parts now encode non-alphanumeric characters instead of replacing whitespace with underscores, so Thing With Spaces and Thing_With_Spaces stay distinct. The test now covers both names.

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.

zodResponseFormat emits $ref values and definition keys with spaces

1 participant