@@ -145,8 +145,9 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
145145 { {#allVars} }
146146 { {#isContainer} }
147147 { {#isArray} }
148- { {#items.isArray } }
148+ { {#items.isContainer } }
149149 { {^items.items.isPrimitiveType} }
150+ { {#items.isArray} }
150151 # override the default output from pydantic by calling `to_dict()` of each item in { {{name} }} (list of list)
151152 _items = []
152153 if self.{ {{name} }}:
@@ -156,9 +157,21 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
156157 [_inner_item.to_dict() for _inner_item in _item if _inner_item is not None]
157158 )
158159 _dict['{ {{baseName} }}'] = _items
159- { {/items.items.isPrimitiveType} }
160160 { {/items.isArray} }
161- { {^items.isArray} }
161+ { {#items.isMap} }
162+ # override the default output from pydantic by calling `to_dict()` of each item in { {{name} }} (list of map)
163+ _items = []
164+ if self.{ {{name} }}:
165+ for _item in self.{ {{name} }}:
166+ if _item:
167+ _items.append(
168+ { _inner_key: _inner_value.to_dict() for _inner_key, _inner_value in _item.items if _inner_value is not None}
169+ )
170+ _dict['{ {{baseName} }}'] = _items
171+ { {/items.isMap} }
172+ { {/items.items.isPrimitiveType} }
173+ { {/items.isContainer} }
174+ { {^items.isContainer} }
162175 { {^items.isPrimitiveType} }
163176 { {^items.isEnumOrRef} }
164177 # override the default output from pydantic by calling `to_dict()` of each item in { {{name} }} (list)
@@ -170,11 +183,12 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
170183 _dict['{ {{baseName} }}'] = _items
171184 { {/items.isEnumOrRef} }
172185 { {/items.isPrimitiveType} }
173- { {/items.isArray } }
186+ { {/items.isContainer } }
174187 { {/isArray} }
175188 { {#isMap} }
176- { {#items.isArray } }
189+ { {#items.isContainer } }
177190 { {^items.items.isPrimitiveType} }
191+ { {#items.isArray} }
178192 # override the default output from pydantic by calling `to_dict()` of each value in { {{name} }} (dict of array)
179193 _field_dict_of_array = { }
180194 if self.{ {{name} }}:
@@ -184,9 +198,21 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
184198 _item.to_dict() for _item in self.{ {{name} }}[_key]
185199 ]
186200 _dict['{ {{baseName} }}'] = _field_dict_of_array
187- { {/items.items.isPrimitiveType} }
188201 { {/items.isArray} }
189- { {^items.isArray} }
202+ { {#items.isMap} }
203+ # override the default output from pydantic by calling `to_dict()` of each value in { {{name} }} (dict of dict)
204+ _field_dict_of_dict = { }
205+ if self.{ {{name} }}:
206+ for _key, _value in self.{ {{name} }}.items():
207+ if _value is not None:
208+ _field_dict_of_dict[_key] = {
209+ _inner_key: _inner_value.to_dict() for _inner_key, _inner_value in _value.items() if _inner_value is not None
210+ }
211+ _dict['{ {{baseName} }}'] = _field_dict_of_dict
212+ { {/items.isMap} }
213+ { {/items.items.isPrimitiveType} }
214+ { {/items.isContainer} }
215+ { {^items.isContainer} }
190216 { {^items.isPrimitiveType} }
191217 { {^items.isEnumOrRef} }
192218 # override the default output from pydantic by calling `to_dict()` of each value in { {{name} }} (dict)
@@ -198,7 +224,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
198224 _dict['{ {{baseName} }}'] = _field_dict
199225 { {/items.isEnumOrRef} }
200226 { {/items.isPrimitiveType} }
201- { {/items.isArray } }
227+ { {/items.isContainer } }
202228 { {/isMap} }
203229 { {/isContainer} }
204230 { {^isContainer} }
0 commit comments