-
-
Notifications
You must be signed in to change notification settings - Fork 438
Fix indefinite hang on OpenAPI schemas with cyclic model dependencies #3078
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
koxudaxi
merged 27 commits into
koxudaxi:main
from
kevin-paulson-mindbridge-ai:slow_schema_generation_fix
May 7, 2026
Merged
Changes from 7 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
ae7ba7a
Add fix and tests
kevin-paulson-mindbridge-ai dff13a4
Remove unused noqa
kevin-paulson-mindbridge-ai b4e675c
Add one more noqa
kevin-paulson-mindbridge-ai 7eaf6ab
Add assertions to test
kevin-paulson-mindbridge-ai 7786cf9
add some generation test for schemas with cyclic references in order …
kevin-paulson-mindbridge-ai 8d3ee39
Add missing expected_file
kevin-paulson-mindbridge-ai bb037b0
Update the `test_main_cyclic_` tests so that before the change they a…
kevin-paulson-mindbridge-ai db5f26a
tmp add
kevin-paulson-mindbridge-ai 6b51fbe
Merge remote-tracking branch 'origin/main' into slow_schema_generatio…
kevin-paulson-mindbridge-ai 207dda3
Revert all changes
kevin-paulson-mindbridge-ai 6cc7834
Add test that takes much more than 30 seconds (probably will never fi…
kevin-paulson-mindbridge-ai f9da08d
Add test timeout
kevin-paulson-mindbridge-ai 670f35d
Code format mostly
kevin-paulson-mindbridge-ai 7deb47d
whitespace changes to help view the code better
kevin-paulson-mindbridge-ai c380a72
Produce smaler openapi example (still fails)
kevin-paulson-mindbridge-ai 582a495
Resolve test failure
kevin-paulson-mindbridge-ai 45f0208
Merge branch 'main' into slow_schema_generation_fix
kevin-paulson-mindbridge-ai b3a3e3e
handle None model case in discriminator mapping validation
kevin-paulson-mindbridge-ai 064c620
Rename and describe test
kevin-paulson-mindbridge-ai d10ed4a
No disable timestamp like the other tests
kevin-paulson-mindbridge-ai 26eeb74
Merge remote-tracking branch 'origin/main' into slow_schema_generatio…
kevin-paulson-mindbridge-ai 622476d
Remove unneeded if model is none
kevin-paulson-mindbridge-ai f4ed663
Add jsonschema test
kevin-paulson-mindbridge-ai d1190ed
Add graphql test
kevin-paulson-mindbridge-ai c9a99b6
Revert "Add graphql test"
kevin-paulson-mindbridge-ai 9eaaaf9
Update test docstrings
kevin-paulson-mindbridge-ai 269f6f2
Merge branch 'main' into slow_schema_generation_fix
koxudaxi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # generated by datamodel-codegen: | ||
| # filename: cyclic-mutual-types.graphql | ||
| # timestamp: 2019-07-26T00:00:00+00:00 | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Literal | ||
|
|
||
| from pydantic import BaseModel, Field | ||
| from typing_extensions import TypeAliasType | ||
|
|
||
| Boolean = TypeAliasType("Boolean", bool) | ||
| """ | ||
| The `Boolean` scalar type represents `true` or `false`. | ||
| """ | ||
|
|
||
|
|
||
| String = TypeAliasType("String", str) | ||
| """ | ||
| The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text. | ||
| """ | ||
|
|
||
|
|
||
| class Model(BaseModel): | ||
| name: String | None = None | ||
| typename__: Literal['Model'] | None = Field('Model', alias='__typename') | ||
|
|
||
|
|
||
| class Team(Person, Model): | ||
| name: String | None = None | ||
| typename__: Literal['Team'] | None = Field('Team', alias='__typename') | ||
|
|
||
|
|
||
| class Person(Team, Model): | ||
| name: String | None = None | ||
| typename__: Literal['Person'] | None = Field('Person', alias='__typename') |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # generated by datamodel-codegen: | ||
| # filename: cyclic_mutual_defs.json | ||
| # timestamp: 2019-07-26T00:00:00+00:00 | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pydantic import BaseModel | ||
|
|
||
|
|
||
| class Model(BaseModel): | ||
| pass | ||
|
|
||
|
|
||
| class Person(Team, Model): | ||
| name: str | None = None | ||
|
|
||
|
|
||
| class Team(Person, Model): | ||
| name: str | None = None | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # generated by datamodel-codegen: | ||
| # filename: cyclic_component_refs.yaml | ||
| # timestamp: 2019-07-26T00:00:00+00:00 | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pydantic import BaseModel | ||
|
|
||
|
|
||
| class Model(BaseModel): | ||
| pass | ||
|
|
||
|
|
||
| class Person(Team, Model): | ||
| name: str | None = None | ||
|
|
||
|
|
||
| class Team(Person, Model): | ||
| name: str | None = None | ||
|
koxudaxi marked this conversation as resolved.
Outdated
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| type Query { | ||
| entry: Team | ||
| } | ||
|
|
||
| # GraphQL interfaces must declare fields; OpenAPI `Model` is an empty object, so `name` | ||
| # is the shared optional field carried by Team/Person (mirrors OpenAPI `name` on each). | ||
| interface Model { | ||
| name: String | ||
| } | ||
|
|
||
| # Mirrors allOf [Model, Person] + properties { name }. | ||
| interface Team implements Model & Person { | ||
| name: String | ||
| } | ||
|
|
||
| # Mirrors allOf [Model, Team] + properties { name }. | ||
| interface Person implements Model & Team { | ||
| name: String | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "type": "object", | ||
| "properties": {}, | ||
| "definitions": { | ||
| "Model": { | ||
| "title": "Model", | ||
| "type": "object" | ||
| }, | ||
| "Team": { | ||
| "title": "Team", | ||
| "allOf": [ | ||
| { "$ref": "#/definitions/Model" }, | ||
| { "$ref": "#/definitions/Person" } | ||
| ], | ||
| "type": "object", | ||
| "properties": { | ||
| "name": { "type": "string" } | ||
| } | ||
| }, | ||
| "Person": { | ||
| "title": "Person", | ||
| "allOf": [ | ||
| { "$ref": "#/definitions/Model" }, | ||
| { "$ref": "#/definitions/Team" } | ||
| ], | ||
| "type": "object", | ||
| "properties": { | ||
| "name": { "type": "string" } | ||
| } | ||
| } | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| openapi: 3.0.0 | ||
| info: | ||
| title: Cyclic component $ref | ||
| version: "1.0" | ||
| paths: {} | ||
| components: | ||
| schemas: | ||
| Model: | ||
| type: object | ||
| Team: | ||
| allOf: | ||
| - $ref: "#/components/schemas/Model" | ||
| - $ref: "#/components/schemas/Person" | ||
| type: object | ||
| properties: | ||
| name: | ||
| type: string | ||
| Person: | ||
| allOf: | ||
| - $ref: "#/components/schemas/Model" | ||
| - $ref: "#/components/schemas/Team" | ||
| type: object | ||
| properties: | ||
| name: | ||
| type: string |
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.