Skip to content

fix(pydantic): decode escaped local JSON schema references - #3602

Open
weivwang wants to merge 1 commit into
openai:mainfrom
weivwang:fix/decode-json-pointer-refs
Open

fix(pydantic): decode escaped local JSON schema references#3602
weivwang wants to merge 1 commit into
openai:mainfrom
weivwang:fix/decode-json-pointer-refs

Conversation

@weivwang

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

Changes being requested

Decode URI fragments and RFC 6901 escape sequences while resolving local JSON Schema references in the handwritten Pydantic helper.

resolve_ref() currently splits a local $ref and uses each raw segment as a dictionary key. Definitions containing /, ~, spaces, or other escaped characters therefore fail with KeyError, for example:

{"$ref":"#/$defs/path~1to%20model~0v1"}

The change decodes each segment after splitting it, then applies JSON Pointer's ~1/ and ~0~ substitutions. Decoding after the split is important: a percent-encoded / belongs to the definition key and must not become an extra path segment.

Two regressions cover both direct resolution and the real strict-schema inlining path with sibling properties.

Additional context & links

No matching issue or open PR was found for escaped local $ref handling. The modified source is under src/openai/lib/, which CONTRIBUTING.md identifies as outside the generated SDK surface.

Validation:

  • pytest -q tests/lib/test_pydantic.py — 5 passed
  • ruff check src/openai/lib/_pydantic.py tests/lib/test_pydantic.py
  • ruff format --check src/openai/lib/_pydantic.py tests/lib/test_pydantic.py
  • git diff --check

@weivwang
weivwang marked this pull request as ready for review August 13, 2026 12:37
@weivwang
weivwang requested a review from a team as a code owner August 13, 2026 12:37

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

Copy link
Copy Markdown

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: 97c05c2015

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

raise ValueError(f"Unexpected $ref format {ref!r}; Does not start with #/")

path = ref[2:].split("/")
path = [unquote(key).replace("~1", "/").replace("~0", "~") for key in ref[2:].split("/")]

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 Decode the fragment before splitting pointer tokens

When a valid URI fragment percent-encodes a JSON Pointer separator, such as #/$defs%2FGroup%2FItem, percent-decoding produces the pointer /$defs/Group/Item. Splitting the raw fragment first instead treats $defs/Group/Item as one dictionary key and raises KeyError rather than traversing the nested schema. Decode the fragment before tokenization; literal slashes in a reference token remain represented by JSON Pointer's ~1 escape.

Useful? React with 👍 / 👎.

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.

1 participant