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 6e228f38056..4a759f4e5c9 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 @@ -1985,6 +1985,19 @@ components: enum: - admin - user + AllOfWithNestedOneOf: + type: object + title: allOf with nested oneOf model (inline) + allOf: + - $ref: '#/components/schemas/Tag' + - type: object + properties: + inner_name: + type: string + nested_oneof: + oneOf: + - $ref: '#/components/schemas/BasquePig' + - $ref: '#/components/schemas/DanishPig' Pig: oneOf: - $ref: '#/components/schemas/BasquePig' diff --git a/samples/openapi3/client/petstore/python-nextgen/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-nextgen/.openapi-generator/FILES index b8e0a20aec6..3eaad3ada2a 100755 --- a/samples/openapi3/client/petstore/python-nextgen/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-nextgen/.openapi-generator/FILES @@ -4,6 +4,8 @@ .travis.yml README.md docs/AdditionalPropertiesClass.md +docs/AllOfWithNestedOneOf.md +docs/AllOfWithNestedOneOfAllOf.md docs/AllOfWithSingleRef.md docs/Animal.md docs/AnotherFakeApi.md @@ -83,6 +85,8 @@ petstore_api/configuration.py petstore_api/exceptions.py petstore_api/models/__init__.py petstore_api/models/additional_properties_class.py +petstore_api/models/all_of_with_nested_one_of.py +petstore_api/models/all_of_with_nested_one_of_all_of.py petstore_api/models/all_of_with_single_ref.py petstore_api/models/animal.py petstore_api/models/any_of_color.py diff --git a/samples/openapi3/client/petstore/python-nextgen/README.md b/samples/openapi3/client/petstore/python-nextgen/README.md index 595e187329e..7f25bbea48e 100755 --- a/samples/openapi3/client/petstore/python-nextgen/README.md +++ b/samples/openapi3/client/petstore/python-nextgen/README.md @@ -128,6 +128,8 @@ Class | Method | HTTP request | Description ## Documentation For Models - [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md) + - [AllOfWithNestedOneOf](docs/AllOfWithNestedOneOf.md) + - [AllOfWithNestedOneOfAllOf](docs/AllOfWithNestedOneOfAllOf.md) - [AllOfWithSingleRef](docs/AllOfWithSingleRef.md) - [Animal](docs/Animal.md) - [AnyOfColor](docs/AnyOfColor.md) diff --git a/samples/openapi3/client/petstore/python-nextgen/docs/AllOfWithNestedOneOf.md b/samples/openapi3/client/petstore/python-nextgen/docs/AllOfWithNestedOneOf.md new file mode 100644 index 00000000000..182feeff2c4 --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/docs/AllOfWithNestedOneOf.md @@ -0,0 +1,31 @@ +# AllOfWithNestedOneOf + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | **int** | | [optional] +**name** | **str** | | [optional] +**inner_name** | **str** | | [optional] +**nested_oneof** | [**OneOfBasquePigDanishPig**](OneOfBasquePigDanishPig.md) | | [optional] + +## Example + +```python +from petstore_api.models.all_of_with_nested_one_of import AllOfWithNestedOneOf + +# TODO update the JSON string below +json = "{}" +# create an instance of AllOfWithNestedOneOf from a JSON string +all_of_with_nested_one_of_instance = AllOfWithNestedOneOf.from_json(json) +# print the JSON string representation of the object +print AllOfWithNestedOneOf.to_json() + +# convert the object into a dict +all_of_with_nested_one_of_dict = all_of_with_nested_one_of_instance.to_dict() +# create an instance of AllOfWithNestedOneOf from a dict +all_of_with_nested_one_of_form_dict = all_of_with_nested_one_of.from_dict(all_of_with_nested_one_of_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/docs/AllOfWithNestedOneOfAllOf.md b/samples/openapi3/client/petstore/python-nextgen/docs/AllOfWithNestedOneOfAllOf.md new file mode 100644 index 00000000000..02e5960d2c2 --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/docs/AllOfWithNestedOneOfAllOf.md @@ -0,0 +1,29 @@ +# AllOfWithNestedOneOfAllOf + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**inner_name** | **str** | | [optional] +**nested_oneof** | [**OneOfBasquePigDanishPig**](OneOfBasquePigDanishPig.md) | | [optional] + +## Example + +```python +from petstore_api.models.all_of_with_nested_one_of_all_of import AllOfWithNestedOneOfAllOf + +# TODO update the JSON string below +json = "{}" +# create an instance of AllOfWithNestedOneOfAllOf from a JSON string +all_of_with_nested_one_of_all_of_instance = AllOfWithNestedOneOfAllOf.from_json(json) +# print the JSON string representation of the object +print AllOfWithNestedOneOfAllOf.to_json() + +# convert the object into a dict +all_of_with_nested_one_of_all_of_dict = all_of_with_nested_one_of_all_of_instance.to_dict() +# create an instance of AllOfWithNestedOneOfAllOf from a dict +all_of_with_nested_one_of_all_of_form_dict = all_of_with_nested_one_of_all_of.from_dict(all_of_with_nested_one_of_all_of_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 ff667b0dd14..e682cbad7d1 100755 --- a/samples/openapi3/client/petstore/python-nextgen/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/__init__.py @@ -36,6 +36,8 @@ from petstore_api.exceptions import ApiAttributeError from petstore_api.exceptions import ApiException # import models into sdk package from petstore_api.models.additional_properties_class import AdditionalPropertiesClass +from petstore_api.models.all_of_with_nested_one_of import AllOfWithNestedOneOf +from petstore_api.models.all_of_with_nested_one_of_all_of import AllOfWithNestedOneOfAllOf from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef from petstore_api.models.animal import Animal from petstore_api.models.any_of_color import AnyOfColor 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 47c33519b11..638525ce0ab 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 @@ -15,6 +15,8 @@ from __future__ import absolute_import # import models into model package from petstore_api.models.additional_properties_class import AdditionalPropertiesClass +from petstore_api.models.all_of_with_nested_one_of import AllOfWithNestedOneOf +from petstore_api.models.all_of_with_nested_one_of_all_of import AllOfWithNestedOneOfAllOf from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef from petstore_api.models.animal import Animal from petstore_api.models.any_of_color import AnyOfColor diff --git a/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/all_of_with_nested_one_of.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/all_of_with_nested_one_of.py new file mode 100644 index 00000000000..ee78b59e144 --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/all_of_with_nested_one_of.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: https://openapi-generator.tech +""" + + +from __future__ import annotations +from inspect import getfullargspec +import pprint +import re # noqa: F401 +import json + + +from typing import Any, Optional +from pydantic import BaseModel, StrictInt, StrictStr + +class AllOfWithNestedOneOf(BaseModel): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + id: Optional[StrictInt] = None + name: Optional[StrictStr] = None + inner_name: Optional[StrictStr] = None + nested_oneof: Optional[Any] = None + additional_properties: Dict[str, Any] = {} + __properties = ["id", "name", "inner_name", "nested_oneof"] + + 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) -> AllOfWithNestedOneOf: + """Create an instance of AllOfWithNestedOneOf 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 nested_oneof + if self.nested_oneof: + _dict['nested_oneof'] = self.nested_oneof.to_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 + + # set to None if nested_oneof (nullable) is None + if self.nested_oneof is None: + _dict['nested_oneof'] = None + + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> AllOfWithNestedOneOf: + """Create an instance of AllOfWithNestedOneOf from a dict""" + if obj is None: + return None + + if type(obj) is not dict: + return AllOfWithNestedOneOf.parse_obj(obj) + + _obj = AllOfWithNestedOneOf.parse_obj({ + "id": obj.get("id"), + "name": obj.get("name"), + "inner_name": obj.get("inner_name"), + "nested_oneof": OneOfBasquePigDanishPig.from_dict(obj.get("nested_oneof")) if obj.get("nested_oneof") 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/all_of_with_nested_one_of_all_of.py b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/all_of_with_nested_one_of_all_of.py new file mode 100644 index 00000000000..3a9b46606ff --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/petstore_api/models/all_of_with_nested_one_of_all_of.py @@ -0,0 +1,91 @@ +# 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: https://openapi-generator.tech +""" + + +from __future__ import annotations +from inspect import getfullargspec +import pprint +import re # noqa: F401 +import json + + +from typing import Any, Optional +from pydantic import BaseModel, StrictStr + +class AllOfWithNestedOneOfAllOf(BaseModel): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + inner_name: Optional[StrictStr] = None + nested_oneof: Optional[Any] = None + additional_properties: Dict[str, Any] = {} + __properties = ["inner_name", "nested_oneof"] + + 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) -> AllOfWithNestedOneOfAllOf: + """Create an instance of AllOfWithNestedOneOfAllOf 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 nested_oneof + if self.nested_oneof: + _dict['nested_oneof'] = self.nested_oneof.to_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 + + # set to None if nested_oneof (nullable) is None + if self.nested_oneof is None: + _dict['nested_oneof'] = None + + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> AllOfWithNestedOneOfAllOf: + """Create an instance of AllOfWithNestedOneOfAllOf from a dict""" + if obj is None: + return None + + if type(obj) is not dict: + return AllOfWithNestedOneOfAllOf.parse_obj(obj) + + _obj = AllOfWithNestedOneOfAllOf.parse_obj({ + "inner_name": obj.get("inner_name"), + "nested_oneof": OneOfBasquePigDanishPig.from_dict(obj.get("nested_oneof")) if obj.get("nested_oneof") 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/test/test_all_of_with_nested_one_of.py b/samples/openapi3/client/petstore/python-nextgen/test/test_all_of_with_nested_one_of.py new file mode 100644 index 00000000000..9dd77019fdf --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/test/test_all_of_with_nested_one_of.py @@ -0,0 +1,56 @@ +# 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: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import unittest +import datetime + +import petstore_api +from petstore_api.models.all_of_with_nested_one_of import AllOfWithNestedOneOf # noqa: E501 +from petstore_api.rest import ApiException + +class TestAllOfWithNestedOneOf(unittest.TestCase): + """AllOfWithNestedOneOf unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional): + """Test AllOfWithNestedOneOf + 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 `AllOfWithNestedOneOf` + """ + model = petstore_api.models.all_of_with_nested_one_of.AllOfWithNestedOneOf() # noqa: E501 + if include_optional : + return AllOfWithNestedOneOf( + id = 56, + name = None, + nested_oneof = None + ) + else : + return AllOfWithNestedOneOf( + ) + """ + + def testAllOfWithNestedOneOf(self): + """Test AllOfWithNestedOneOf""" + # 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/test/test_all_of_with_nested_one_of_all_of.py b/samples/openapi3/client/petstore/python-nextgen/test/test_all_of_with_nested_one_of_all_of.py new file mode 100644 index 00000000000..fb0180046bb --- /dev/null +++ b/samples/openapi3/client/petstore/python-nextgen/test/test_all_of_with_nested_one_of_all_of.py @@ -0,0 +1,55 @@ +# 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: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import unittest +import datetime + +import petstore_api +from petstore_api.models.all_of_with_nested_one_of_all_of import AllOfWithNestedOneOfAllOf # noqa: E501 +from petstore_api.rest import ApiException + +class TestAllOfWithNestedOneOfAllOf(unittest.TestCase): + """AllOfWithNestedOneOfAllOf unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional): + """Test AllOfWithNestedOneOfAllOf + 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 `AllOfWithNestedOneOfAllOf` + """ + model = petstore_api.models.all_of_with_nested_one_of_all_of.AllOfWithNestedOneOfAllOf() # noqa: E501 + if include_optional : + return AllOfWithNestedOneOfAllOf( + name = None, + nested_oneof = None + ) + else : + return AllOfWithNestedOneOfAllOf( + ) + """ + + def testAllOfWithNestedOneOfAllOf(self): + """Test AllOfWithNestedOneOfAllOf""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main()