Skip to content

Commit 8c9f2dd

Browse files
committed
remove deprecated usage of pydantic v2 to_dict method with model_dump method
1 parent 9b39c05 commit 8c9f2dd

208 files changed

Lines changed: 208 additions & 416 deletions

File tree

Some content is hidden

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

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
114114

115115
def to_json(self) -> str:
116116
"""Returns the JSON representation of the model using alias"""
117-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
118-
return json.dumps(self.to_dict())
117+
return json.dumps(self.model_dump(by_alias=True, exclude_unset=True))
119118

120119
@classmethod
121120
def from_json(cls, json_str: str) -> {{^hasChildren}}Self{{/hasChildren}}{{#hasChildren}}{{#discriminator}}Union[{{#children}}Self{{^-last}}, {{/-last}}{{/children}}]{{/discriminator}}{{^discriminator}}Self{{/discriminator}}{{/hasChildren}}:

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
127127

128128
def to_json(self) -> str:
129129
"""Returns the JSON representation of the model using alias"""
130-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
131-
return json.dumps(self.to_dict())
130+
return json.dumps(self.model_dump(by_alias=True, exclude_unset=True))
132131

133132
@classmethod
134133
def from_json(cls, json_str: str) -> Optional[{{^hasChildren}}Self{{/hasChildren}}{{#hasChildren}}{{#discriminator}}Union[{{#mappedModels}}{{{modelName}}}{{^-last}}, {{/-last}}{{/mappedModels}}]{{/discriminator}}{{^discriminator}}Self{{/discriminator}}{{/hasChildren}}]:

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ def to_str(self) -> str:
4444

4545
def to_json(self) -> str:
4646
"""Returns the JSON representation of the model using alias"""
47-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
48-
return json.dumps(self.to_dict())
47+
return json.dumps(self.model_dump(by_alias=True, exclude_unset=True))
4948

5049
@classmethod
5150
def from_json(cls, json_str: str) -> Optional[Self]:

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ def to_str(self) -> str:
4444

4545
def to_json(self) -> str:
4646
"""Returns the JSON representation of the model using alias"""
47-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
48-
return json.dumps(self.to_dict())
47+
return json.dumps(self.model_dump(by_alias=True, exclude_unset=True))
4948

5049
@classmethod
5150
def from_json(cls, json_str: str) -> Optional[Self]:

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ def to_str(self) -> str:
4747

4848
def to_json(self) -> str:
4949
"""Returns the JSON representation of the model using alias"""
50-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
51-
return json.dumps(self.to_dict())
50+
return json.dumps(self.model_dump(by_alias=True, exclude_unset=True))
5251

5352
@classmethod
5453
def from_json(cls, json_str: str) -> Optional[Self]:

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ def to_str(self) -> str:
6262

6363
def to_json(self) -> str:
6464
"""Returns the JSON representation of the model using alias"""
65-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
66-
return json.dumps(self.to_dict())
65+
return json.dumps(self.model_dump(by_alias=True, exclude_unset=True))
6766

6867
@classmethod
6968
def from_json(cls, json_str: str) -> Optional[Self]:

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ def to_str(self) -> str:
4646

4747
def to_json(self) -> str:
4848
"""Returns the JSON representation of the model using alias"""
49-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
50-
return json.dumps(self.to_dict())
49+
return json.dumps(self.model_dump(by_alias=True, exclude_unset=True))
5150

5251
@classmethod
5352
def from_json(cls, json_str: str) -> Optional[Self]:

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ def to_str(self) -> str:
6060

6161
def to_json(self) -> str:
6262
"""Returns the JSON representation of the model using alias"""
63-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
64-
return json.dumps(self.to_dict())
63+
return json.dumps(self.model_dump(by_alias=True, exclude_unset=True))
6564

6665
@classmethod
6766
def from_json(cls, json_str: str) -> Optional[Self]:

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ def to_str(self) -> str:
5555

5656
def to_json(self) -> str:
5757
"""Returns the JSON representation of the model using alias"""
58-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
59-
return json.dumps(self.to_dict())
58+
return json.dumps(self.model_dump(by_alias=True, exclude_unset=True))
6059

6160
@classmethod
6261
def from_json(cls, json_str: str) -> Optional[Self]:

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ def to_str(self) -> str:
4444

4545
def to_json(self) -> str:
4646
"""Returns the JSON representation of the model using alias"""
47-
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
48-
return json.dumps(self.to_dict())
47+
return json.dumps(self.model_dump(by_alias=True, exclude_unset=True))
4948

5049
@classmethod
5150
def from_json(cls, json_str: str) -> Optional[Self]:

0 commit comments

Comments
 (0)