Repository navigation
Conversation
compress_schema() collected referenced definition names from the raw
pointer text (ref.split("/")[-1]), so definitions referenced through
RFC 6901 escapes (#/$defs/a~1b), percent-encoding
(#/$defs/Alias%20One), or sub-pointers
(#/$defs/Container/properties/value) were treated as unused and pruned,
leaving dangling $refs in the returned schema. The same raw-text
extraction in the OpenAPI parser's schema dependency collector and in
the request-body $defs pruner missed component schemas whose names
contain those characters.
Add ref_target_name(), which returns the decoded first segment after a
definition root using _resolve_local_ref's convention (percent-decode
the fragment, then unescape ~1/~0), and use it at all three extraction
sites. A sub-pointer now names the container definition instead of its
last path segment.
Fixes PrefectHQ#6034
Co-authored-by: RS-ITACHI <276741997+RS-ITACHI@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes #6034
Problem
compress_schema()decided whichare referenced by reading the raw pointer text of each(ref.split("/")[-1]in_single_pass_optimize). A definition referenced through a properly encoded JSON Pointer therefore looked unused and was pruned, leaving dangling ``s in the returned schema:#/$defs/a~1b(definitiona/b),#/$defs/c~0d(definitionc~d)#/$defs/Alias%20One(definitionAlias One)#/$defs/Container/properties/value— the raw last segment isproperties, notContainerThe same raw-text extraction is used in two OpenAPI paths, with the same effect:
OpenAPIParser._extract_schema_dependencies(collecting component schemas by name) and the request-bodypruner inside `_combine_schemas_and_map_params`. A component schema named `a/b`, referenced as `#/components/schemas/a~1b`, was never collected and its rewrittendangled.Fix
Add
ref_target_name()tofastmcp.utilities.json_schema. It returns the first pointer segment after a definition root (`` by default,components/schemasfor raw OpenAPI documents), decoded the same way `_resolve_local_ref` decodes pointers: percent-decode the fragment, then unescape `~1`/`~0` per RFC 6901. Matching the resolver's own convention keeps the collectors consistent with what actually resolves — anything `_resolve_local_ref` can resolve is never treated as unused. A pointer may continue past the name, so a sub-pointer names the container definition.The helper is used at all three extraction sites:
_single_pass_optimize(compress_schema`` pruning)OpenAPIParser._extract_schema_dependencies_combine_schemas_and_map_paramsrequest-body `` pruningRaw `` values are untouched everywhere; only the used/unused decision changes.
Tests
TestRefTargetName: the decoder itself — escapes,~01not re-decoded, percent-encoding, sub-pointers, non-definition pointers, alternate rootsTestCompressSchemaEscapedRefNames: the issue's schema keeps all four referenced definitions; def→def escaped references keep both definitions; unused escaped definitions are still prunedTestEscapedSchemaNameReferences(OpenAPI): schemas nameda/bandAlias Oneare collected from the document and survive_combine_schemas_and_map_paramswith their references intactThe
compress_schemaregression fails onmainfor the reported reason (all four referenced definitions pruned, soresult.get("$defs")isNone) and passes with this change.Verification
uv run pytest tests/utilities/ -n 0— 1312 passed, 1 skippeduv run pytest tests/tools tests/resources tests/prompts -n 0— 893 passed, 1 skippeduv run prek run --files <changed files>— ruff check/format, prettier, codespell, loq passed;ty checkpasses on all changed files when run directly (the prek runner hit a transient allocator OOM on ty, not a type error); gitleaks was skipped locally because the binary is not installed