You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""Returns the JSON representation of the model using alias"""
@@ -81,7 +81,96 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
81
81
return cls.from_dict(json.loads(json_str))
82
82
83
83
def to_dict(self) -> Dict[str, Any]:
84
-
return self.model_dump(by_alias=True)
84
+
"""Return the dictionary representation of the model using alias.
85
+
86
+
This is the same as `self.mode_dump` from Pydantic, except that we only add to the output dict for nullable fields that were set at model initialization. Other fields with value `None` are ignored
87
+
"""
88
+
_dict = self.model_dump(
89
+
by_alias=True,
90
+
exclude_unset=True,
91
+
exclude_defaults=True,
92
+
exclude_none=True,
93
+
exclude={
94
+
{{#vendorExtensions.x-py-readonly}}
95
+
"{{{.}}}",
96
+
{{/vendorExtensions.x-py-readonly}}
97
+
{{#isAdditionalPropertiesTrue}}
98
+
"additional_properties",
99
+
{{/isAdditionalPropertiesTrue}}
100
+
},
101
+
)
102
+
{{#allVars}}
103
+
{{#isContainer}}
104
+
{{#isArray}}
105
+
{{#items.isArray}}
106
+
{{^items.items.isPrimitiveType}}
107
+
_items = []
108
+
if self.{{{name}}}:
109
+
for _item in self.{{{name}}}:
110
+
if _item:
111
+
_items.append(
112
+
[_inner_item.to_dict() for _inner_item in _item if _inner_item is not None]
113
+
)
114
+
_dict['{{{baseName}}}'] = _items
115
+
{{/items.items.isPrimitiveType}}
116
+
{{/items.isArray}}
117
+
{{^items.isArray}}
118
+
{{^items.isPrimitiveType}}
119
+
{{^items.isEnumOrRef}}
120
+
_items = []
121
+
if self.{{{name}}}:
122
+
for _item in self.{{{name}}}:
123
+
if _item:
124
+
_items.append(_item.to_dict())
125
+
_dict['{{{baseName}}}'] = _items
126
+
{{/items.isEnumOrRef}}
127
+
{{/items.isPrimitiveType}}
128
+
{{/items.isArray}}
129
+
{{/isArray}}
130
+
{{#isMap}}
131
+
{{#items.isArray}}
132
+
{{^items.items.isPrimitiveType}}
133
+
_field_dict_of_array = {}
134
+
if self.{{{name}}}:
135
+
for _key in self.{{{name}}}:
136
+
if self.{{{name}}}[_key] is not None:
137
+
_field_dict_of_array[_key] = [
138
+
_item.to_dict() for _item in self.{{{name}}}[_key]
@@ -23,6 +21,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
23
21
]] = None
24
22
25
23
model_config = ConfigDict(
24
+
use_enum_values=True,
26
25
validate_assignment=True,
27
26
protected_namespaces=(),
28
27
)
@@ -76,7 +75,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
76
75
raise ValueError("No match found when deserializing the JSON string into {{{classname}}} with oneOf schemas: {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}. Details: " + ", ".join(error_messages))
77
76
78
77
def to_json(self) -> str:
79
-
"""Returns the JSON representation of the actual instance"""
78
+
"""Returns the JSON representation of the one_of value"""
80
79
if self.value is None:
81
80
return "null"
82
81
if hasattr(self.value, "to_json") and callable(self.value.to_json):
@@ -85,7 +84,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
0 commit comments