Skip to content

Commit befb80c

Browse files
committed
Fix Python .to_json to use Pydantic .model_dump_json
This fixes an issue when exporting models with UUID fields
1 parent 81a3488 commit befb80c

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

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 self.model_dump_json(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}}]:

0 commit comments

Comments
 (0)