Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,21 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
_dict['{{{baseName}}}'] = _items
{{/items.items.isPrimitiveType}}
{{/items.isArray}}
{{#items.isMap}}
{{^items.items.isPrimitiveType}}
# override the default output from pydantic by calling `to_dict()` of each item in {{{name}}} (list of dict)
_items = []
if self.{{{name}}}:
for _item_{{{name}}} in self.{{{name}}}:
if _item_{{{name}}}:
_items.append(
{_inner_key: _inner_value.to_dict() for _inner_key, _inner_value in _item_{{{name}}}.items()}
)
_dict['{{{baseName}}}'] = _items
{{/items.items.isPrimitiveType}}
{{/items.isMap}}
{{^items.isArray}}
{{^items.isMap}}
{{^items.isPrimitiveType}}
{{^items.isEnumOrRef}}
# override the default output from pydantic by calling `to_dict()` of each item in {{{name}}} (list)
Expand All @@ -194,6 +208,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
_dict['{{{baseName}}}'] = _items
{{/items.isEnumOrRef}}
{{/items.isPrimitiveType}}
{{/items.isMap}}
{{/items.isArray}}
{{/isArray}}
{{#isMap}}
Expand All @@ -210,6 +225,20 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
_dict['{{{baseName}}}'] = _field_dict_of_array
{{/items.items.isPrimitiveType}}
{{/items.isArray}}
{{#items.isMap}}
{{^items.items.isPrimitiveType}}
# override the default output from pydantic by calling `to_dict()` of each value in {{{name}}} (dict of dict)
_field_dict_of_dict = {}
if self.{{{name}}}:
for _key_{{{name}}}, _value_{{{name}}} in self.{{{name}}}.items():
if _value_{{{name}}} is not None:
_field_dict_of_dict[_key_{{{name}}}] = {
_key: _value.to_dict() for _key, _value in _value_{{{name}}}.items()
}
_dict['{{{baseName}}}'] = _field_dict_of_dict
{{/items.items.isPrimitiveType}}
{{/items.isMap}}
{{^items.isMap}}
{{^items.isArray}}
{{^items.isPrimitiveType}}
{{^items.isEnumOrRef}}
Expand All @@ -223,6 +252,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
{{/items.isEnumOrRef}}
{{/items.isPrimitiveType}}
{{/items.isArray}}
{{/items.isMap}}
{{/isMap}}
{{/isContainer}}
{{^isContainer}}
Expand Down Expand Up @@ -293,6 +323,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
{{#allVars}}
{{#isContainer}}
{{#isArray}}
{{#items.isContainer}}
{{#items.isArray}}
{{#items.items.isPrimitiveType}}
"{{{baseName}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
Expand All @@ -304,7 +335,19 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
] if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}}
{{/items.items.isPrimitiveType}}
{{/items.isArray}}
{{^items.isArray}}
{{#items.isMap}}
{{#items.items.isPrimitiveType}}
"{{{baseName}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
{{/items.items.isPrimitiveType}}
{{^items.items.isPrimitiveType}}
"{{{baseName}}}": [
{_inner_key: {{{items.items.dataType}}}.from_dict(_inner_value) for _inner_key, _inner_value in _item.items()}
for _item in obj["{{{baseName}}}"]
] if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}}
{{/items.items.isPrimitiveType}}
{{/items.isMap}}
{{/items.isContainer}}
{{^items.isContainer}}
{{^items.isPrimitiveType}}
{{#items.isEnumOrRef}}
"{{{baseName}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
Expand All @@ -316,7 +359,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
{{#items.isPrimitiveType}}
"{{{baseName}}}": obj.get("{{{baseName}}}"){{^-last}},{{/-last}}
{{/items.isPrimitiveType}}
{{/items.isArray}}
{{/items.isContainer}}
{{/isArray}}
{{#isMap}}
{{^items.isPrimitiveType}}
Expand All @@ -331,7 +374,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
if _v is not None
else None
)
for _k, _v in obj.get("{{{baseName}}}").items()
for _k, _v in obj["{{{baseName}}}"].items()
)
if obj.get("{{{baseName}}}") is not None
else None{{^-last}},{{/-last}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2137,6 +2137,12 @@ components:
type: object
additionalProperties:
type: string
map_of_map_non_primitive_property:
type: object
additionalProperties:
type: object
additionalProperties:
$ref: '#/components/schemas/Pet'
MixedPropertiesAndAdditionalPropertiesClass:
type: object
properties:
Expand Down Expand Up @@ -2705,6 +2711,15 @@ components:
type: array
items:
$ref: "#/components/schemas/Tag"
ArrayOfMapModel:
type: object
properties:
array_of_map_property:
type: array
items:
type: object
additionalProperties:
$ref: "#/components/schemas/Tag"
ArrayOfArrayOfModel:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ docs/AnyOfColor.md
docs/AnyOfPig.md
docs/ArrayOfArrayOfModel.md
docs/ArrayOfArrayOfNumberOnly.md
docs/ArrayOfMapModel.md
docs/ArrayOfNumberOnly.md
docs/ArrayTest.md
docs/BaseDiscriminator.md
Expand Down Expand Up @@ -151,6 +152,7 @@ petstore_api/models/any_of_color.py
petstore_api/models/any_of_pig.py
petstore_api/models/array_of_array_of_model.py
petstore_api/models/array_of_array_of_number_only.py
petstore_api/models/array_of_map_model.py
petstore_api/models/array_of_number_only.py
petstore_api/models/array_test.py
petstore_api/models/base_discriminator.py
Expand Down
1 change: 1 addition & 0 deletions samples/openapi3/client/petstore/python-aiohttp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ Class | Method | HTTP request | Description
- [AnyOfPig](docs/AnyOfPig.md)
- [ArrayOfArrayOfModel](docs/ArrayOfArrayOfModel.md)
- [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md)
- [ArrayOfMapModel](docs/ArrayOfMapModel.md)
- [ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md)
- [ArrayTest](docs/ArrayTest.md)
- [BaseDiscriminator](docs/BaseDiscriminator.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**map_property** | **Dict[str, str]** | | [optional]
**map_of_map_property** | **Dict[str, Dict[str, str]]** | | [optional]
**map_of_map_non_primitive_property** | **Dict[str, Dict[str, Pet]]** | | [optional]

## Example

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# ArrayOfMapModel


## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**array_of_map_property** | **List[Dict[str, Tag]]** | | [optional]

## Example

```python
from petstore_api.models.array_of_map_model import ArrayOfMapModel

# TODO update the JSON string below
json = "{}"
# create an instance of ArrayOfMapModel from a JSON string
array_of_map_model_instance = ArrayOfMapModel.from_json(json)
# print the JSON string representation of the object
print(ArrayOfMapModel.to_json())

# convert the object into a dict
array_of_map_model_dict = array_of_map_model_instance.to_dict()
# create an instance of ArrayOfMapModel from a dict
array_of_map_model_from_dict = ArrayOfMapModel.from_dict(array_of_map_model_dict)
```
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"AnyOfPig",
"ArrayOfArrayOfModel",
"ArrayOfArrayOfNumberOnly",
"ArrayOfMapModel",
"ArrayOfNumberOnly",
"ArrayTest",
"BaseDiscriminator",
Expand Down Expand Up @@ -185,6 +186,7 @@
from petstore_api.models.any_of_pig import AnyOfPig as AnyOfPig
from petstore_api.models.array_of_array_of_model import ArrayOfArrayOfModel as ArrayOfArrayOfModel
from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly as ArrayOfArrayOfNumberOnly
from petstore_api.models.array_of_map_model import ArrayOfMapModel as ArrayOfMapModel
from petstore_api.models.array_of_number_only import ArrayOfNumberOnly as ArrayOfNumberOnly
from petstore_api.models.array_test import ArrayTest as ArrayTest
from petstore_api.models.base_discriminator import BaseDiscriminator as BaseDiscriminator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from petstore_api.models.any_of_pig import AnyOfPig
from petstore_api.models.array_of_array_of_model import ArrayOfArrayOfModel
from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly
from petstore_api.models.array_of_map_model import ArrayOfMapModel
from petstore_api.models.array_of_number_only import ArrayOfNumberOnly
from petstore_api.models.array_test import ArrayTest
from petstore_api.models.base_discriminator import BaseDiscriminator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from pydantic import BaseModel, ConfigDict, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from petstore_api.models.pet import Pet
from typing import Optional, Set
from typing_extensions import Self

Expand All @@ -28,7 +29,8 @@ class AdditionalPropertiesClass(BaseModel):
""" # noqa: E501
map_property: Optional[Dict[str, StrictStr]] = None
map_of_map_property: Optional[Dict[str, Dict[str, StrictStr]]] = None
__properties: ClassVar[List[str]] = ["map_property", "map_of_map_property"]
map_of_map_non_primitive_property: Optional[Dict[str, Dict[str, Pet]]] = None
__properties: ClassVar[List[str]] = ["map_property", "map_of_map_property", "map_of_map_non_primitive_property"]

model_config = ConfigDict(
validate_by_name=True,
Expand Down Expand Up @@ -70,6 +72,15 @@ def to_dict(self) -> Dict[str, Any]:
exclude=excluded_fields,
exclude_none=True,
)
# override the default output from pydantic by calling `to_dict()` of each value in map_of_map_non_primitive_property (dict of dict)
_field_dict_of_dict = {}
if self.map_of_map_non_primitive_property:
for _key_map_of_map_non_primitive_property, _value_map_of_map_non_primitive_property in self.map_of_map_non_primitive_property.items():
if _value_map_of_map_non_primitive_property is not None:
_field_dict_of_dict[_key_map_of_map_non_primitive_property] = {
_key: _value.to_dict() for _key, _value in _value_map_of_map_non_primitive_property.items()
}
_dict['map_of_map_non_primitive_property'] = _field_dict_of_dict
return _dict

@classmethod
Expand All @@ -83,7 +94,19 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:

_obj = cls.model_validate({
"map_property": obj.get("map_property"),
"map_of_map_property": obj.get("map_of_map_property")
"map_of_map_property": obj.get("map_of_map_property"),
"map_of_map_non_primitive_property": dict(
(_k, dict(
(_ik, Pet.from_dict(_iv))
for _ik, _iv in _v.items()
)
if _v is not None
else None
)
for _k, _v in obj["map_of_map_non_primitive_property"].items()
)
if obj.get("map_of_map_non_primitive_property") is not None
else None
})
return _obj

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# coding: utf-8

"""
OpenAPI Petstore

This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\

The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
""" # noqa: E501


from __future__ import annotations
import pprint
import re # noqa: F401
import json

from pydantic import BaseModel, ConfigDict
from typing import Any, ClassVar, Dict, List, Optional
from petstore_api.models.tag import Tag
from typing import Optional, Set
from typing_extensions import Self

class ArrayOfMapModel(BaseModel):
"""
ArrayOfMapModel
""" # noqa: E501
array_of_map_property: Optional[List[Dict[str, Tag]]] = None
__properties: ClassVar[List[str]] = ["array_of_map_property"]

model_config = ConfigDict(
validate_by_name=True,
validate_by_alias=True,
validate_assignment=True,
protected_namespaces=(),
)


def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))

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

@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of ArrayOfMapModel from a JSON string"""
return cls.from_dict(json.loads(json_str))

def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.

This has the following differences from calling pydantic's
`self.model_dump(by_alias=True)`:

* `None` is only added to the output dict for nullable fields that
were set at model initialization. Other fields with value `None`
are ignored.
"""
excluded_fields: Set[str] = set([
])

_dict = self.model_dump(
by_alias=True,
exclude=excluded_fields,
exclude_none=True,
)
# override the default output from pydantic by calling `to_dict()` of each item in array_of_map_property (list of dict)
_items = []
if self.array_of_map_property:
for _item_array_of_map_property in self.array_of_map_property:
if _item_array_of_map_property:
_items.append(
{_inner_key: _inner_value.to_dict() for _inner_key, _inner_value in _item_array_of_map_property.items()}
)
_dict['array_of_map_property'] = _items
return _dict

@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of ArrayOfMapModel from a dict"""
if obj is None:
return None

if not isinstance(obj, dict):
return cls.model_validate(obj)

_obj = cls.model_validate({
"array_of_map_property": [
{_inner_key: Tag.from_dict(_inner_value) for _inner_key, _inner_value in _item.items()}
for _item in obj["array_of_map_property"]
] if obj.get("array_of_map_property") is not None else None
})
return _obj


Loading
Loading