Skip to content

Commit 918a028

Browse files
committed
[FIX] field 'class_name' to be of type Literal
1 parent 867f497 commit 918a028

17 files changed

Lines changed: 89 additions & 16 deletions

File tree

modules/openapi-generator/src/main/resources/python/model_generic.mustache

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,16 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
6161
{{/allowableValues}}
6262
{{/isEnum}}
6363
{{^isEnum}}
64+
{{#isDiscriminator}}
65+
{{name}}: Literal['{{{vendorExtensions.x-py-discriminator-value}}}'] = Field(
66+
{{#required}}...{{/required}}{{^required}}None{{/required}},
67+
description="{{description}}{{^description}}{{{name}}} of the {{classname}}{{/description}}",
68+
alias="{{{baseName}}}"
69+
)
70+
{{/isDiscriminator}}
71+
{{^isDiscriminator}}
6472
{{name}}: {{{vendorExtensions.x-py-typing}}}
73+
{{/isDiscriminator}}
6574
{{/isEnum}}
6675
{{/vars}}
6776
{{#isAdditionalPropertiesTrue}}

samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/animal.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ class Animal(BaseModel):
3232
"""
3333
Animal
3434
""" # noqa: E501
35-
class_name: StrictStr = Field(alias="className")
35+
class_name: Literal[''] = Field(
36+
...,
37+
description="class_name of the Animal",
38+
alias="className"
39+
)
3640
color: Optional[StrictStr] = 'red'
3741
__properties: ClassVar[List[str]] = ["className", "color"]
3842

samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/base_discriminator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ class BaseDiscriminator(BaseModel):
3232
"""
3333
BaseDiscriminator
3434
""" # noqa: E501
35-
type_name: Optional[StrictStr] = Field(default=None, alias="_typeName")
35+
type_name: Literal[''] = Field(
36+
None,
37+
description="type_name of the BaseDiscriminator",
38+
alias="_typeName"
39+
)
3640
__properties: ClassVar[List[str]] = ["_typeName"]
3741

3842
model_config = ConfigDict(

samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/creature.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ class Creature(BaseModel):
3333
Creature
3434
""" # noqa: E501
3535
info: CreatureInfo
36-
type: StrictStr
36+
type: Literal[''] = Field(
37+
...,
38+
description="type of the Creature",
39+
alias="type"
40+
)
3741
__properties: ClassVar[List[str]] = ["info", "type"]
3842

3943
model_config = ConfigDict(

samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/discriminator_all_of_super.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ class DiscriminatorAllOfSuper(BaseModel):
3131
"""
3232
DiscriminatorAllOfSuper
3333
""" # noqa: E501
34-
element_type: StrictStr = Field(alias="elementType")
34+
element_type: Literal[''] = Field(
35+
...,
36+
description="element_type of the DiscriminatorAllOfSuper",
37+
alias="elementType"
38+
)
3539
__properties: ClassVar[List[str]] = ["elementType"]
3640

3741
model_config = ConfigDict(

samples/openapi3/client/petstore/python-httpx/petstore_api/models/animal.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ class Animal(BaseModel):
3232
"""
3333
Animal
3434
""" # noqa: E501
35-
class_name: StrictStr = Field(alias="className")
35+
class_name: Literal[''] = Field(
36+
...,
37+
description="class_name of the Animal",
38+
alias="className"
39+
)
3640
color: Optional[StrictStr] = 'red'
3741
__properties: ClassVar[List[str]] = ["className", "color"]
3842

samples/openapi3/client/petstore/python-httpx/petstore_api/models/base_discriminator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ class BaseDiscriminator(BaseModel):
3232
"""
3333
BaseDiscriminator
3434
""" # noqa: E501
35-
type_name: Optional[StrictStr] = Field(default=None, alias="_typeName")
35+
type_name: Literal[''] = Field(
36+
None,
37+
description="type_name of the BaseDiscriminator",
38+
alias="_typeName"
39+
)
3640
__properties: ClassVar[List[str]] = ["_typeName"]
3741

3842
model_config = ConfigDict(

samples/openapi3/client/petstore/python-httpx/petstore_api/models/creature.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ class Creature(BaseModel):
3333
Creature
3434
""" # noqa: E501
3535
info: CreatureInfo
36-
type: StrictStr
36+
type: Literal[''] = Field(
37+
...,
38+
description="type of the Creature",
39+
alias="type"
40+
)
3741
__properties: ClassVar[List[str]] = ["info", "type"]
3842

3943
model_config = ConfigDict(

samples/openapi3/client/petstore/python-httpx/petstore_api/models/discriminator_all_of_super.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ class DiscriminatorAllOfSuper(BaseModel):
3131
"""
3232
DiscriminatorAllOfSuper
3333
""" # noqa: E501
34-
element_type: StrictStr = Field(alias="elementType")
34+
element_type: Literal[''] = Field(
35+
...,
36+
description="element_type of the DiscriminatorAllOfSuper",
37+
alias="elementType"
38+
)
3539
__properties: ClassVar[List[str]] = ["elementType"]
3640

3741
model_config = ConfigDict(

samples/openapi3/client/petstore/python-lazyImports/petstore_api/models/animal.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ class Animal(BaseModel):
3232
"""
3333
Animal
3434
""" # noqa: E501
35-
class_name: StrictStr = Field(alias="className")
35+
class_name: Literal[''] = Field(
36+
...,
37+
description="class_name of the Animal",
38+
alias="className"
39+
)
3640
color: Optional[StrictStr] = 'red'
3741
additional_properties: Dict[str, Any] = {}
3842
__properties: ClassVar[List[str]] = ["className", "color"]

0 commit comments

Comments
 (0)