Skip to content

Commit 82bb97c

Browse files
committed
revert Literal for class_name
1 parent 8a7c0af commit 82bb97c

18 files changed

Lines changed: 16 additions & 106 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -454,23 +454,6 @@ protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Sc
454454
}
455455
}
456456

457-
@Override
458-
public CodegenModel fromModel(String name, Schema model) {
459-
CodegenModel codegenModel = super.fromModel(name, model);
460-
setEnumDiscriminatorDefaultValue(codegenModel);
461-
462-
// Additional logic: mark className fields as discriminators for Pydantic v2 compatibility
463-
if (codegenModel.vars != null) {
464-
for (CodegenProperty property : codegenModel.vars) {
465-
if ("className".equals(property.baseName)) {
466-
property.isDiscriminator = true;
467-
}
468-
}
469-
}
470-
471-
return codegenModel;
472-
}
473-
474457
@Override
475458
public String escapeReservedWord(String name) {
476459
if (this.reservedWordsMappings().containsKey(name)) {

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

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

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

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

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

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

4238
model_config = ConfigDict(

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

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

4339
model_config = ConfigDict(

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

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

4137
model_config = ConfigDict(

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

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

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

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

4238
model_config = ConfigDict(

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

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

4339
model_config = ConfigDict(

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

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

4137
model_config = ConfigDict(

0 commit comments

Comments
 (0)