Repository navigation
fix(tools): support self-referencing component schemas in OpenAPITool - #2012
Merged
Tomas2D merged 1 commit intoNov 26, 2026
Merged
Conversation
A schema in components/schemas that refers to itself (a tree, a comment thread) made OpenAPITool.input_schema fail with RecursionError. Point those references at $defs so inline_schema_refs keeps the cycle, and move the kept definitions to the top of the operation's schema, where JSONSchemaModel.create reads them. Signed-off-by: Shlok Bam <[email protected]>
Tomas2D
force-pushed
the
fix/openapi-recursive-component-schemas
branch
from
November 26, 2026 22:49
1cb95dd to
36f5130
Compare
Tomas2D
approved these changes
Nov 26, 2026
Tomas2D
left a comment
Contributor
There was a problem hiding this comment.
Thanks. I rebased this onto main (the only conflict was both PRs adding a module-level helper in the same place) and reran the OpenAPI tests.
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.
Which issue(s) does this pull-request address?
Closes: #2011
Description
If a schema in
components/schemasrefers to itself (a tree, a comment thread),OpenAPITool.input_schemafails withRecursionError. #1970 handles cycles ininline_schema_refs, but only for references into$defs, and OpenAPI specs use#/components/schemas/....Changes in
tools/openapi.py:#/components/schemas/Xreferences are rewritten to#/$defs/Xand the component schemas are passed as$defs, soinline_schema_refskeeps the references that close a cycle instead of producing a cyclic dict.JSONSchemaModel.createonly reads$defsthere (left insidebody,model_json_schema()fails withKeyError: '#/$defs/Category').The result matches #1970: the first levels of a recursive type are validated, and deeper levels accept any object.
Schemas without cycles give the same input schema as before. I compared
model_json_schema()on main and with this change for 455 tools from 150 generated specs (nested, array,anyOfand parameter references, no cycles): all identical.Checklist
General
PythonCode quality checks
ruff check,ruff format --check(0.9.10). pyrefly: not runTesting
tests/tools/test_openapi.py,test_openapi_ssrf.py,tests/backend/test_utils.py,tests/utils/test_models.py: 41 passed (+2 new)RecursionErrorand pass with this change.Documentation