You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
An OpenAPI schema with a self-referencing object with a discriminated union produces code with undefined variables for all output model types except pydantic v1 BaseModel.
from __future__ importannotationsfromtypingimportList, Unionfromtyping_extensionsimportNotRequired, TypedDictclassBar(TypedDict):
kind: NotRequired[str]
Children=Union[Foo, Bar] # Foo is undefined!classFoo(TypedDict):
kind: NotRequired[str]
children: List[Children]
Similar error happens for other output model types. Only pydantic v1 works because Foo is a variable annotation, rather than in a Union in a type alias.
Expected behavior
Reference to Foo properly turned into forward reference
Version:
OS: Ubuntu 20.04
Python version: 3.12
datamodel-code-generator version: 0.25.3
Additional context
It works properly if the discriminator is removed from the schema.
The text was updated successfully, but these errors were encountered:
Describe the bug
An OpenAPI schema with a self-referencing object with a discriminated union produces code with undefined variables for all output model types except pydantic v1 BaseModel.
To Reproduce
Example schema:
Used commandline:
Output:
Similar error happens for other output model types. Only pydantic v1 works because
Foo
is a variable annotation, rather than in aUnion
in a type alias.Expected behavior
Reference to
Foo
properly turned into forward referenceVersion:
Additional context
It works properly if the
discriminator
is removed from the schema.The text was updated successfully, but these errors were encountered: