Skip to content

Commit 32e10f6

Browse files
committed
[FIX] model_generic.mustache
add exclude_none=True, on .to_str()
1 parent 2dfc1a2 commit 32e10f6

File tree

411 files changed

+411
-1082
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

411 files changed

+411
-1082
lines changed

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

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
from __future__ import annotations
2-
import pprint
3-
import re # noqa: F401
42
{{#vendorExtensions.x-py-other-imports}}
53
{{{.}}}
64
{{/vendorExtensions.x-py-other-imports}}
@@ -18,9 +16,8 @@ class {{classname}}(RootModel[Union[{{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyO
1816
"""
1917
{{{description}}}{{^description}}{{{classname}}}{{/description}}
2018
"""
21-
2219
root: Union[{{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyOf}}{{#isNullable}}, None{{/isNullable}}] = Field(
23-
{{#isNullable}}None{{/isNullable}}{{^isNullable}}...{{/isNullable}}{{#discriminator}}, discriminator="{{discriminatorName}}"{{/discriminator}}
20+
{{#isNullable}}None{{/isNullable}}{{^isNullable}}...{{/isNullable}}{{#discriminator}}, discriminator="{{discriminatorName}}"{{/discriminator}}
2421
)
2522

2623
def __getattr__(self, name):
@@ -38,29 +35,6 @@ class {{classname}}(RootModel[Union[{{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyO
3835

3936
raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'")
4037

41-
@classmethod
42-
def from_dict(cls, obj: Dict[str, Any]) -> Self:
43-
"""Returns the object represented by the Dict"""
44-
return cls.model_validate(obj, strict=True)
45-
46-
@classmethod
47-
def from_json(cls, json_str: str) -> Self:
48-
"""Returns the object represented by the json string"""
49-
return cls.model_validate_json(json_str)
50-
51-
def to_json(self) -> str:
52-
"""Returns the JSON representation of the actual instance"""
53-
return self.model_dump_json(by_alias=True, exclude_none=True)
54-
55-
def to_dict(self) -> Dict[str, Any]:
56-
"""Returns the dict representation of the actual instance"""
57-
return self.model_dump(by_alias=True)
58-
59-
def to_str(self) -> str:
60-
"""Returns the string representation of the actual instance"""
61-
return pprint.pformat(self.model_dump(by_alias=True, mode="json"))
62-
63-
6438
{{#vendorExtensions.x-py-postponed-model-imports.size}}
6539
{{#vendorExtensions.x-py-postponed-model-imports}}
6640
{{{.}}}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
176176

177177
def to_str(self) -> str:
178178
"""Returns the string representation of the model using alias"""
179-
return pprint.pformat(self.model_dump(by_alias=True))
179+
return pprint.pformat(self.model_dump(by_alias=True, exclude_none=True, mode="json"))
180180

181181

182182
{{#vendorExtensions.x-py-postponed-model-imports.size}}

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

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
from __future__ import annotations
2-
import json
3-
import pprint
42
{{#vendorExtensions.x-py-other-imports}}
53
{{{.}}}
64
{{/vendorExtensions.x-py-other-imports}}
@@ -13,6 +11,7 @@ from typing_extensions import Literal, Self
1311

1412
{{#lambda.uppercase}}{{{classname}}}{{/lambda.uppercase}}_ONE_OF_SCHEMAS = [{{#oneOf}}"{{.}}"{{^-last}}, {{/-last}}{{/oneOf}}]
1513

14+
1615
class {{classname}}(RootModel[Union[{{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}]]):
1716
"""
1817
{{{description}}}{{^description}}{{{classname}}}{{/description}}
@@ -36,28 +35,6 @@ class {{classname}}(RootModel[Union[{{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/on
3635

3736
raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'")
3837

39-
@classmethod
40-
def from_dict(cls, obj: Dict[str, Any]) -> Self:
41-
"""Returns the object represented by the Dict"""
42-
return cls.model_validate(obj, strict=True)
43-
44-
@classmethod
45-
def from_json(cls, json_str: str) -> Self:
46-
"""Returns the object represented by the json string"""
47-
return cls.model_validate_json(json_str)
48-
49-
def to_json(self) -> str:
50-
"""Returns the JSON representation of the actual instance"""
51-
return self.model_dump_json(by_alias=True, exclude_none=True)
52-
53-
def to_dict(self) -> Dict[str, Any]:
54-
"""Returns the dict representation of the actual instance"""
55-
return self.model_dump(by_alias=True)
56-
57-
def to_str(self) -> str:
58-
"""Returns the string representation of the actual instance"""
59-
return pprint.pformat(self.model_dump(by_alias=True, mode="json"))
60-
6138
{{#vendorExtensions.x-py-postponed-model-imports.size}}
6239
{{#vendorExtensions.x-py-postponed-model-imports}}
6340
{{{.}}}

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/bird.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def to_dict(self) -> Dict[str, Any]:
5959

6060
def to_str(self) -> str:
6161
"""Returns the string representation of the model using alias"""
62-
return pprint.pformat(self.model_dump(by_alias=True))
62+
return pprint.pformat(self.model_dump(by_alias=True, exclude_none=True, mode="json"))
6363

6464

6565

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/category.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def to_dict(self) -> Dict[str, Any]:
5959

6060
def to_str(self) -> str:
6161
"""Returns the string representation of the model using alias"""
62-
return pprint.pformat(self.model_dump(by_alias=True))
62+
return pprint.pformat(self.model_dump(by_alias=True, exclude_none=True, mode="json"))
6363

6464

6565

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/data_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def to_dict(self) -> Dict[str, Any]:
6262

6363
def to_str(self) -> str:
6464
"""Returns the string representation of the model using alias"""
65-
return pprint.pformat(self.model_dump(by_alias=True))
65+
return pprint.pformat(self.model_dump(by_alias=True, exclude_none=True, mode="json"))
6666

6767

6868

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/default_value.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def to_dict(self) -> Dict[str, Any]:
8080

8181
def to_str(self) -> str:
8282
"""Returns the string representation of the model using alias"""
83-
return pprint.pformat(self.model_dump(by_alias=True))
83+
return pprint.pformat(self.model_dump(by_alias=True, exclude_none=True, mode="json"))
8484

8585

8686

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/number_properties_only.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def to_dict(self) -> Dict[str, Any]:
6161

6262
def to_str(self) -> str:
6363
"""Returns the string representation of the model using alias"""
64-
return pprint.pformat(self.model_dump(by_alias=True))
64+
return pprint.pformat(self.model_dump(by_alias=True, exclude_none=True, mode="json"))
6565

6666

6767

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def to_dict(self) -> Dict[str, Any]:
7878

7979
def to_str(self) -> str:
8080
"""Returns the string representation of the model using alias"""
81-
return pprint.pformat(self.model_dump(by_alias=True))
81+
return pprint.pformat(self.model_dump(by_alias=True, exclude_none=True, mode="json"))
8282

8383

8484

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def to_dict(self) -> Dict[str, Any]:
7373

7474
def to_str(self) -> str:
7575
"""Returns the string representation of the model using alias"""
76-
return pprint.pformat(self.model_dump(by_alias=True))
76+
return pprint.pformat(self.model_dump(by_alias=True, exclude_none=True, mode="json"))
7777

7878

7979

0 commit comments

Comments
 (0)