diff --git a/modules/openapi-generator/src/main/resources/python-nextgen/model_generic.mustache b/modules/openapi-generator/src/main/resources/python-nextgen/model_generic.mustache index d4f1306e833..6402a352c8b 100644 --- a/modules/openapi-generator/src/main/resources/python-nextgen/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/python-nextgen/model_generic.mustache @@ -241,7 +241,42 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{#isMap}} {{^items.isPrimitiveType}} {{^items.isEnumOrRef}} - "{{{name}}}": dict((_k, {{{items.dataType}}}.from_dict(_v)) for _k, _v in obj.get("{{{baseName}}}").items()) if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}} + {{#items.isContainer}} + {{#items.isMap}} + "{{{name}}}": dict( + (_k, dict( + (_ik, {{{items.items.dataType}}}.from_dict(_iv)) + for _ik, _iv in _v.items() + ) + if _v is not None + else None + ) + for _k, _v in obj.get("{{{baseName}}}").items() + ) + if obj.get("{{{baseName}}}") is not None + else None{{^-last}},{{/-last}} + {{/items.isMap}} + {{#items.isArray}} + "{{{name}}}": dict( + (_k, [(_ik, {{{items.items.dataType}}}.from_dict(_iv))] + for _ik, _iv in _v.items() + if _v is not None + else None + ) + for _k, _v in obj.get("{{{baseName}}}").items() + ) + if obj.get("{{{baseName}}}") is not None + else None{{^-last}},{{/-last}} + {{/items.isArray}} + {{/items.isContainer}} + {{^items.isContainer}} + "{{{name}}}": dict( + (_k, {{{items.dataType}}}.from_dict(_v)) + for _k, _v in obj.get("{{{baseName}}}").items() + ) + if obj.get("{{{baseName}}}") is not None + else None{{^-last}},{{/-last}} + {{/items.isContainer}} {{/items.isEnumOrRef}} {{#items.isEnumOrRef}} "{{{name}}}": dict((_k, _v) for _k, _v in obj.get("{{{baseName}}}").items()){{^-last}},{{/-last}} diff --git a/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml index 9dedcf30521..f639a2430da 100644 --- a/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml @@ -2147,3 +2147,12 @@ components: type: string circular_ref: $ref: '#/components/schemas/Circular-Reference-Model' + InnerDictWithAdditionalProperties: + type: object + additionalProperties: + $ref: "#/components/schemas/InnerDictWithProperty" + Parent: + type: object + properties: + optionalDict: + $ref: "#/components/schemas/DictWithAdditionalProperties" diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-nextgen-aiohttp/.openapi-generator/FILES index 970be2c4e66..b83f61f5cfa 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/.openapi-generator/FILES @@ -58,6 +58,7 @@ docs/OuterEnumDefaultValue.md docs/OuterEnumInteger.md docs/OuterEnumIntegerDefaultValue.md docs/OuterObjectWithEnumProperty.md +docs/Parent.md docs/ParentWithOptionalDict.md docs/Pet.md docs/PetApi.md @@ -139,6 +140,7 @@ petstore_api/models/outer_enum_default_value.py petstore_api/models/outer_enum_integer.py petstore_api/models/outer_enum_integer_default_value.py petstore_api/models/outer_object_with_enum_property.py +petstore_api/models/parent.py petstore_api/models/parent_with_optional_dict.py petstore_api/models/pet.py petstore_api/models/pig.py diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/README.md b/samples/openapi3/client/petstore/python-nextgen-aiohttp/README.md index e26d9f33e89..a5c458c1115 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/README.md +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/README.md @@ -183,6 +183,7 @@ Class | Method | HTTP request | Description - [OuterEnumInteger](docs/OuterEnumInteger.md) - [OuterEnumIntegerDefaultValue](docs/OuterEnumIntegerDefaultValue.md) - [OuterObjectWithEnumProperty](docs/OuterObjectWithEnumProperty.md) + - [Parent](docs/Parent.md) - [ParentWithOptionalDict](docs/ParentWithOptionalDict.md) - [Pet](docs/Pet.md) - [Pig](docs/Pig.md) diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/Parent.md b/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/Parent.md new file mode 100644 index 00000000000..9a963a6b722 --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/docs/Parent.md @@ -0,0 +1,28 @@ +# Parent + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**optional_dict** | [**Dict[str, InnerDictWithProperty]**](InnerDictWithProperty.md) | | [optional] + +## Example + +```python +from petstore_api.models.parent import Parent + +# TODO update the JSON string below +json = "{}" +# create an instance of Parent from a JSON string +parent_instance = Parent.from_json(json) +# print the JSON string representation of the object +print Parent.to_json() + +# convert the object into a dict +parent_dict = parent_instance.to_dict() +# create an instance of Parent from a dict +parent_form_dict = parent.from_dict(parent_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) + + diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/__init__.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/__init__.py index 417db16491d..ef57b5c6e93 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/__init__.py @@ -86,6 +86,7 @@ from petstore_api.models.outer_enum_default_value import OuterEnumDefaultValue from petstore_api.models.outer_enum_integer import OuterEnumInteger from petstore_api.models.outer_enum_integer_default_value import OuterEnumIntegerDefaultValue from petstore_api.models.outer_object_with_enum_property import OuterObjectWithEnumProperty +from petstore_api.models.parent import Parent from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict from petstore_api.models.pet import Pet from petstore_api.models.pig import Pig diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/__init__.py index 212f2096311..7a56cdeccd2 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/__init__.py @@ -65,6 +65,7 @@ from petstore_api.models.outer_enum_default_value import OuterEnumDefaultValue from petstore_api.models.outer_enum_integer import OuterEnumInteger from petstore_api.models.outer_enum_integer_default_value import OuterEnumIntegerDefaultValue from petstore_api.models.outer_object_with_enum_property import OuterObjectWithEnumProperty +from petstore_api.models.parent import Parent from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict from petstore_api.models.pet import Pet from petstore_api.models.pig import Pig diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/mixed_properties_and_additional_properties_class.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/mixed_properties_and_additional_properties_class.py index 5c96c891435..23b80efa20e 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/mixed_properties_and_additional_properties_class.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/mixed_properties_and_additional_properties_class.py @@ -76,7 +76,12 @@ class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): _obj = MixedPropertiesAndAdditionalPropertiesClass.parse_obj({ "uuid": obj.get("uuid"), "date_time": obj.get("dateTime"), - "map": dict((_k, Animal.from_dict(_v)) for _k, _v in obj.get("map").items()) if obj.get("map") is not None else None + "map": dict( + (_k, Animal.from_dict(_v)) + for _k, _v in obj.get("map").items() + ) + if obj.get("map") is not None + else None }) return _obj diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/parent.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/parent.py new file mode 100644 index 00000000000..8af68a0065d --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/parent.py @@ -0,0 +1,83 @@ +# 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: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" + + +from __future__ import annotations +from inspect import getfullargspec +import pprint +import re # noqa: F401 +import json + + +from typing import Dict, Optional +from pydantic import BaseModel, Field +from petstore_api.models.inner_dict_with_property import InnerDictWithProperty + +class Parent(BaseModel): + """ + Parent + """ + optional_dict: Optional[Dict[str, InnerDictWithProperty]] = Field(None, alias="optionalDict") + __properties = ["optionalDict"] + + class Config: + allow_population_by_field_name = True + validate_assignment = True + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.dict(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Parent: + """Create an instance of Parent from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self): + """Returns the dictionary representation of the model using alias""" + _dict = self.dict(by_alias=True, + exclude={ + }, + exclude_none=True) + # override the default output from pydantic by calling `to_dict()` of each value in optional_dict (dict) + _field_dict = {} + if self.optional_dict: + for _key in self.optional_dict: + if self.optional_dict[_key]: + _field_dict[_key] = self.optional_dict[_key].to_dict() + _dict['optionalDict'] = _field_dict + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> Parent: + """Create an instance of Parent from a dict""" + if obj is None: + return None + + if type(obj) is not dict: + return Parent.parse_obj(obj) + + _obj = Parent.parse_obj({ + "optional_dict": dict( + (_k, InnerDictWithProperty.from_dict(_v)) + for _k, _v in obj.get("optionalDict").items() + ) + if obj.get("optionalDict") is not None + else None + }) + return _obj + diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/parent_with_optional_dict.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/parent_with_optional_dict.py index e886b75bd08..0918d6e7e38 100644 --- a/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/parent_with_optional_dict.py +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/petstore_api/models/parent_with_optional_dict.py @@ -72,7 +72,12 @@ class ParentWithOptionalDict(BaseModel): return ParentWithOptionalDict.parse_obj(obj) _obj = ParentWithOptionalDict.parse_obj({ - "optional_dict": dict((_k, InnerDictWithProperty.from_dict(_v)) for _k, _v in obj.get("optionalDict").items()) if obj.get("optionalDict") is not None else None + "optional_dict": dict( + (_k, InnerDictWithProperty.from_dict(_v)) + for _k, _v in obj.get("optionalDict").items() + ) + if obj.get("optionalDict") is not None + else None }) return _obj diff --git a/samples/openapi3/client/petstore/python-nextgen-aiohttp/test/test_parent.py b/samples/openapi3/client/petstore/python-nextgen-aiohttp/test/test_parent.py new file mode 100644 index 00000000000..2a74505f08a --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen-aiohttp/test/test_parent.py @@ -0,0 +1,57 @@ +# 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: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" + + +import unittest +import datetime + +import petstore_api +from petstore_api.models.parent import Parent # noqa: E501 +from petstore_api.rest import ApiException + +class TestParent(unittest.TestCase): + """Parent unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional): + """Test Parent + include_option is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `Parent` + """ + model = petstore_api.models.parent.Parent() # noqa: E501 + if include_optional : + return Parent( + optional_dict = { + 'key' : petstore_api.models.inner_dict_with_property.InnerDictWithProperty( + a_property = petstore_api.models.a_property.aProperty(), ) + } + ) + else : + return Parent( + ) + """ + + def testParent(self): + """Test Parent""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-nextgen/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-nextgen/.openapi-generator/FILES index 1c063f5f802..2021ca9627f 100755 --- a/samples/openapi3/client/petstore/python-nextgen/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-nextgen/.openapi-generator/FILES @@ -58,6 +58,7 @@ docs/OuterEnumDefaultValue.md docs/OuterEnumInteger.md docs/OuterEnumIntegerDefaultValue.md docs/OuterObjectWithEnumProperty.md +docs/Parent.md docs/ParentWithOptionalDict.md docs/Pet.md docs/PetApi.md @@ -139,6 +140,7 @@ petstore_api/models/outer_enum_default_value.py petstore_api/models/outer_enum_integer.py petstore_api/models/outer_enum_integer_default_value.py petstore_api/models/outer_object_with_enum_property.py +petstore_api/models/parent.py petstore_api/models/parent_with_optional_dict.py petstore_api/models/pet.py petstore_api/models/pig.py diff --git a/samples/openapi3/client/petstore/python-nextgen/README.md b/samples/openapi3/client/petstore/python-nextgen/README.md index a7b98f0887e..2b8531ac04f 100755 --- a/samples/openapi3/client/petstore/python-nextgen/README.md +++ b/samples/openapi3/client/petstore/python-nextgen/README.md @@ -183,6 +183,7 @@ Class | Method | HTTP request | Description - [OuterEnumInteger](docs/OuterEnumInteger.md) - [OuterEnumIntegerDefaultValue](docs/OuterEnumIntegerDefaultValue.md) - [OuterObjectWithEnumProperty](docs/OuterObjectWithEnumProperty.md) + - [Parent](docs/Parent.md) - [ParentWithOptionalDict](docs/ParentWithOptionalDict.md) - [Pet](docs/Pet.md) - [Pig](docs/Pig.md) diff --git a/samples/openapi3/client/petstore/python-nextgen/docs/Parent.md b/samples/openapi3/client/petstore/python-nextgen/docs/Parent.md new file mode 100644 index 00000000000..9a963a6b722 --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/docs/Parent.md @@ -0,0 +1,28 @@ +# Parent + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**optional_dict** | [**Dict[str, InnerDictWithProperty]**](InnerDictWithProperty.md) | | [optional] + +## Example + +```python +from petstore_api.models.parent import Parent + +# TODO update the JSON string below +json = "{}" +# create an instance of Parent from a JSON string +parent_instance = Parent.from_json(json) +# print the JSON string representation of the object +print Parent.to_json() + +# convert the object into a dict +parent_dict = parent_instance.to_dict() +# create an instance of Parent from a dict +parent_form_dict = parent.from_dict(parent_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) + + diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/__init__.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/__init__.py index 417db16491d..ef57b5c6e93 100755 --- a/samples/openapi3/client/petstore/python-nextgen/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/__init__.py @@ -86,6 +86,7 @@ from petstore_api.models.outer_enum_default_value import OuterEnumDefaultValue from petstore_api.models.outer_enum_integer import OuterEnumInteger from petstore_api.models.outer_enum_integer_default_value import OuterEnumIntegerDefaultValue from petstore_api.models.outer_object_with_enum_property import OuterObjectWithEnumProperty +from petstore_api.models.parent import Parent from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict from petstore_api.models.pet import Pet from petstore_api.models.pig import Pig diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/__init__.py index 212f2096311..7a56cdeccd2 100644 --- a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/__init__.py @@ -65,6 +65,7 @@ from petstore_api.models.outer_enum_default_value import OuterEnumDefaultValue from petstore_api.models.outer_enum_integer import OuterEnumInteger from petstore_api.models.outer_enum_integer_default_value import OuterEnumIntegerDefaultValue from petstore_api.models.outer_object_with_enum_property import OuterObjectWithEnumProperty +from petstore_api.models.parent import Parent from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict from petstore_api.models.pet import Pet from petstore_api.models.pig import Pig diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/mixed_properties_and_additional_properties_class.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/mixed_properties_and_additional_properties_class.py index cd9c0204841..0e9351ebf19 100644 --- a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/mixed_properties_and_additional_properties_class.py +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/mixed_properties_and_additional_properties_class.py @@ -83,7 +83,12 @@ class MixedPropertiesAndAdditionalPropertiesClass(BaseModel): _obj = MixedPropertiesAndAdditionalPropertiesClass.parse_obj({ "uuid": obj.get("uuid"), "date_time": obj.get("dateTime"), - "map": dict((_k, Animal.from_dict(_v)) for _k, _v in obj.get("map").items()) if obj.get("map") is not None else None + "map": dict( + (_k, Animal.from_dict(_v)) + for _k, _v in obj.get("map").items() + ) + if obj.get("map") is not None + else None }) # store additional fields in additional_properties for _key in obj.keys(): diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/parent.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/parent.py new file mode 100644 index 00000000000..1ed518fabbc --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/parent.py @@ -0,0 +1,95 @@ +# 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: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" + + +from __future__ import annotations +from inspect import getfullargspec +import pprint +import re # noqa: F401 +import json + + +from typing import Dict, Optional +from pydantic import BaseModel, Field +from petstore_api.models.inner_dict_with_property import InnerDictWithProperty + +class Parent(BaseModel): + """ + Parent + """ + optional_dict: Optional[Dict[str, InnerDictWithProperty]] = Field(None, alias="optionalDict") + additional_properties: Dict[str, Any] = {} + __properties = ["optionalDict"] + + class Config: + allow_population_by_field_name = True + validate_assignment = True + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.dict(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Parent: + """Create an instance of Parent from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self): + """Returns the dictionary representation of the model using alias""" + _dict = self.dict(by_alias=True, + exclude={ + "additional_properties" + }, + exclude_none=True) + # override the default output from pydantic by calling `to_dict()` of each value in optional_dict (dict) + _field_dict = {} + if self.optional_dict: + for _key in self.optional_dict: + if self.optional_dict[_key]: + _field_dict[_key] = self.optional_dict[_key].to_dict() + _dict['optionalDict'] = _field_dict + # puts key-value pairs in additional_properties in the top level + if self.additional_properties is not None: + for _key, _value in self.additional_properties.items(): + _dict[_key] = _value + + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> Parent: + """Create an instance of Parent from a dict""" + if obj is None: + return None + + if type(obj) is not dict: + return Parent.parse_obj(obj) + + _obj = Parent.parse_obj({ + "optional_dict": dict( + (_k, InnerDictWithProperty.from_dict(_v)) + for _k, _v in obj.get("optionalDict").items() + ) + if obj.get("optionalDict") is not None + else None + }) + # store additional fields in additional_properties + for _key in obj.keys(): + if _key not in cls.__properties: + _obj.additional_properties[_key] = obj.get(_key) + + return _obj + diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/parent_with_optional_dict.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/parent_with_optional_dict.py index 9c18456d3b8..0e7948d73b3 100644 --- a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/parent_with_optional_dict.py +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/parent_with_optional_dict.py @@ -79,7 +79,12 @@ class ParentWithOptionalDict(BaseModel): return ParentWithOptionalDict.parse_obj(obj) _obj = ParentWithOptionalDict.parse_obj({ - "optional_dict": dict((_k, InnerDictWithProperty.from_dict(_v)) for _k, _v in obj.get("optionalDict").items()) if obj.get("optionalDict") is not None else None + "optional_dict": dict( + (_k, InnerDictWithProperty.from_dict(_v)) + for _k, _v in obj.get("optionalDict").items() + ) + if obj.get("optionalDict") is not None + else None }) # store additional fields in additional_properties for _key in obj.keys(): diff --git a/samples/openapi3/client/petstore/python-nextgen/test/test_parent.py b/samples/openapi3/client/petstore/python-nextgen/test/test_parent.py new file mode 100644 index 00000000000..2a74505f08a --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/test/test_parent.py @@ -0,0 +1,57 @@ +# 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: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" + + +import unittest +import datetime + +import petstore_api +from petstore_api.models.parent import Parent # noqa: E501 +from petstore_api.rest import ApiException + +class TestParent(unittest.TestCase): + """Parent unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional): + """Test Parent + include_option is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `Parent` + """ + model = petstore_api.models.parent.Parent() # noqa: E501 + if include_optional : + return Parent( + optional_dict = { + 'key' : petstore_api.models.inner_dict_with_property.InnerDictWithProperty( + a_property = petstore_api.models.a_property.aProperty(), ) + } + ) + else : + return Parent( + ) + """ + + def testParent(self): + """Test Parent""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-nextgen/tests/test_model.py b/samples/openapi3/client/petstore/python-nextgen/tests/test_model.py index 9674d1b6d59..6c39247f9da 100644 --- a/samples/openapi3/client/petstore/python-nextgen/tests/test_model.py +++ b/samples/openapi3/client/petstore/python-nextgen/tests/test_model.py @@ -407,3 +407,9 @@ class ModelTests(unittest.TestCase): b = petstore_api.ParentWithOptionalDict.from_dict({"optionalDict": {"key": {"aProperty": {"a": "b"}}}}) self.assertFalse(b is None) self.assertEqual(b.optional_dict["key"].a_property["a"], "b") + + def test_object_with_dict_of_dict_of_object(self): + # for https://github.com/OpenAPITools/openapi-generator/issues/15135 + d = {"optionalDict": {"a": {"b": {"aProperty": "value"}}}} + a = petstore_api.Parent.from_dict(d) + self.assertEqual(a.to_dict(), d)