diff --git a/modules/openapi-generator/src/main/resources/python-pydantic-v1/model_generic.mustache b/modules/openapi-generator/src/main/resources/python-pydantic-v1/model_generic.mustache index 87b793dc8f73..9a24a9b6553e 100644 --- a/modules/openapi-generator/src/main/resources/python-pydantic-v1/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/python-pydantic-v1/model_generic.mustache @@ -237,7 +237,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} # look up the object type based on discriminator mapping object_type = cls.get_discriminator_value(obj) {{#mappedModels}} - if object_type == '{{{mappingName}}}': + if object_type == '{{{modelName}}}': return import_module("{{packageName}}.models.{{model.classVarName}}").{{modelName}}.from_dict(obj) {{/mappedModels}} raise ValueError("{{{classname}}} failed to lookup discriminator value from " + diff --git a/modules/openapi-generator/src/main/resources/python/model_generic.mustache b/modules/openapi-generator/src/main/resources/python/model_generic.mustache index 1612beeddcf9..fb9ece0f4639 100644 --- a/modules/openapi-generator/src/main/resources/python/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_generic.mustache @@ -253,7 +253,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} # look up the object type based on discriminator mapping object_type = cls.get_discriminator_value(obj) {{#mappedModels}} - if object_type == '{{{mappingName}}}': + if object_type == '{{{modelName}}}': return import_module("{{packageName}}.models.{{model.classVarName}}").{{modelName}}.from_dict(obj) {{/mappedModels}} 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 0d98d5759736..f092a7acc6e9 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 @@ -2741,3 +2741,26 @@ components: _name: type: string type: object + Info: + allOf: + - $ref: '#/components/schemas/BaseDiscriminator' + - properties: + val: + $ref: '#/components/schemas/BaseDiscriminator' + type: object + BaseDiscriminator: + discriminator: + mapping: + string: '#/components/schemas/PrimitiveString' + propertyName: _typeName + properties: + _typeName: + type: string + type: object + PrimitiveString: + allOf: + - $ref: '#/components/schemas/BaseDiscriminator' + - properties: + _value: + type: string + type: object \ No newline at end of file diff --git a/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES index f7e65690c399..6b44ba44379a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES @@ -17,6 +17,7 @@ docs/ArrayOfArrayOfModel.md docs/ArrayOfArrayOfNumberOnly.md docs/ArrayOfNumberOnly.md docs/ArrayTest.md +docs/BaseDiscriminator.md docs/BasquePig.md docs/Bathing.md docs/Capitalization.md @@ -53,6 +54,7 @@ docs/FormatTest.md docs/HasOnlyReadOnly.md docs/HealthCheckResult.md docs/ImportTestDatetimeApi.md +docs/Info.md docs/InnerDictWithProperty.md docs/InputAllOf.md docs/IntOrString.md @@ -84,6 +86,7 @@ docs/Pet.md docs/PetApi.md docs/Pig.md docs/PoopCleaning.md +docs/PrimitiveString.md docs/PropertyMap.md docs/PropertyNameCollision.md docs/ReadOnlyFirst.md @@ -137,6 +140,7 @@ petstore_api/models/array_of_array_of_model.py petstore_api/models/array_of_array_of_number_only.py petstore_api/models/array_of_number_only.py petstore_api/models/array_test.py +petstore_api/models/base_discriminator.py petstore_api/models/basque_pig.py petstore_api/models/bathing.py petstore_api/models/capitalization.py @@ -169,6 +173,7 @@ petstore_api/models/foo_get_default_response.py petstore_api/models/format_test.py petstore_api/models/has_only_read_only.py petstore_api/models/health_check_result.py +petstore_api/models/info.py petstore_api/models/inner_dict_with_property.py petstore_api/models/input_all_of.py petstore_api/models/int_or_string.py @@ -199,6 +204,7 @@ petstore_api/models/parent_with_optional_dict.py petstore_api/models/pet.py petstore_api/models/pig.py petstore_api/models/poop_cleaning.py +petstore_api/models/primitive_string.py petstore_api/models/property_map.py petstore_api/models/property_name_collision.py petstore_api/models/read_only_first.py diff --git a/samples/openapi3/client/petstore/python-aiohttp/README.md b/samples/openapi3/client/petstore/python-aiohttp/README.md index b7e79f34df8e..7e51f8fa7c5c 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/README.md +++ b/samples/openapi3/client/petstore/python-aiohttp/README.md @@ -163,6 +163,7 @@ Class | Method | HTTP request | Description - [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md) - [ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md) - [ArrayTest](docs/ArrayTest.md) + - [BaseDiscriminator](docs/BaseDiscriminator.md) - [BasquePig](docs/BasquePig.md) - [Bathing](docs/Bathing.md) - [Capitalization](docs/Capitalization.md) @@ -195,6 +196,7 @@ Class | Method | HTTP request | Description - [FormatTest](docs/FormatTest.md) - [HasOnlyReadOnly](docs/HasOnlyReadOnly.md) - [HealthCheckResult](docs/HealthCheckResult.md) + - [Info](docs/Info.md) - [InnerDictWithProperty](docs/InnerDictWithProperty.md) - [InputAllOf](docs/InputAllOf.md) - [IntOrString](docs/IntOrString.md) @@ -225,6 +227,7 @@ Class | Method | HTTP request | Description - [Pet](docs/Pet.md) - [Pig](docs/Pig.md) - [PoopCleaning](docs/PoopCleaning.md) + - [PrimitiveString](docs/PrimitiveString.md) - [PropertyMap](docs/PropertyMap.md) - [PropertyNameCollision](docs/PropertyNameCollision.md) - [ReadOnlyFirst](docs/ReadOnlyFirst.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/BaseDiscriminator.md b/samples/openapi3/client/petstore/python-aiohttp/docs/BaseDiscriminator.md new file mode 100644 index 000000000000..fcdbeb032e68 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/BaseDiscriminator.md @@ -0,0 +1,29 @@ +# BaseDiscriminator + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**type_name** | **str** | | [optional] + +## Example + +```python +from petstore_api.models.base_discriminator import BaseDiscriminator + +# TODO update the JSON string below +json = "{}" +# create an instance of BaseDiscriminator from a JSON string +base_discriminator_instance = BaseDiscriminator.from_json(json) +# print the JSON string representation of the object +print(BaseDiscriminator.to_json()) + +# convert the object into a dict +base_discriminator_dict = base_discriminator_instance.to_dict() +# create an instance of BaseDiscriminator from a dict +base_discriminator_from_dict = BaseDiscriminator.from_dict(base_discriminator_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-aiohttp/docs/Info.md b/samples/openapi3/client/petstore/python-aiohttp/docs/Info.md new file mode 100644 index 000000000000..db88778a9143 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/Info.md @@ -0,0 +1,29 @@ +# Info + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**val** | [**BaseDiscriminator**](BaseDiscriminator.md) | | [optional] + +## Example + +```python +from petstore_api.models.info import Info + +# TODO update the JSON string below +json = "{}" +# create an instance of Info from a JSON string +info_instance = Info.from_json(json) +# print the JSON string representation of the object +print(Info.to_json()) + +# convert the object into a dict +info_dict = info_instance.to_dict() +# create an instance of Info from a dict +info_from_dict = Info.from_dict(info_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-aiohttp/docs/PrimitiveString.md b/samples/openapi3/client/petstore/python-aiohttp/docs/PrimitiveString.md new file mode 100644 index 000000000000..85ceb632e167 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/PrimitiveString.md @@ -0,0 +1,29 @@ +# PrimitiveString + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**value** | **str** | | [optional] + +## Example + +```python +from petstore_api.models.primitive_string import PrimitiveString + +# TODO update the JSON string below +json = "{}" +# create an instance of PrimitiveString from a JSON string +primitive_string_instance = PrimitiveString.from_json(json) +# print the JSON string representation of the object +print(PrimitiveString.to_json()) + +# convert the object into a dict +primitive_string_dict = primitive_string_instance.to_dict() +# create an instance of PrimitiveString from a dict +primitive_string_from_dict = PrimitiveString.from_dict(primitive_string_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-aiohttp/petstore_api/__init__.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/__init__.py index 1d2a609f13be..3f6c3aabf138 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/__init__.py @@ -52,6 +52,7 @@ from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly 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 from petstore_api.models.basque_pig import BasquePig from petstore_api.models.bathing import Bathing from petstore_api.models.capitalization import Capitalization @@ -84,6 +85,7 @@ from petstore_api.models.format_test import FormatTest from petstore_api.models.has_only_read_only import HasOnlyReadOnly from petstore_api.models.health_check_result import HealthCheckResult +from petstore_api.models.info import Info from petstore_api.models.inner_dict_with_property import InnerDictWithProperty from petstore_api.models.input_all_of import InputAllOf from petstore_api.models.int_or_string import IntOrString @@ -114,6 +116,7 @@ from petstore_api.models.pet import Pet from petstore_api.models.pig import Pig from petstore_api.models.poop_cleaning import PoopCleaning +from petstore_api.models.primitive_string import PrimitiveString from petstore_api.models.property_map import PropertyMap from petstore_api.models.property_name_collision import PropertyNameCollision from petstore_api.models.read_only_first import ReadOnlyFirst diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/__init__.py index efd9c939d21f..30718c766d7d 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/__init__.py @@ -27,6 +27,7 @@ from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly 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 from petstore_api.models.basque_pig import BasquePig from petstore_api.models.bathing import Bathing from petstore_api.models.capitalization import Capitalization @@ -59,6 +60,7 @@ from petstore_api.models.format_test import FormatTest from petstore_api.models.has_only_read_only import HasOnlyReadOnly from petstore_api.models.health_check_result import HealthCheckResult +from petstore_api.models.info import Info from petstore_api.models.inner_dict_with_property import InnerDictWithProperty from petstore_api.models.input_all_of import InputAllOf from petstore_api.models.int_or_string import IntOrString @@ -89,6 +91,7 @@ from petstore_api.models.pet import Pet from petstore_api.models.pig import Pig from petstore_api.models.poop_cleaning import PoopCleaning +from petstore_api.models.primitive_string import PrimitiveString from petstore_api.models.property_map import PropertyMap from petstore_api.models.property_name_collision import PropertyNameCollision from petstore_api.models.read_only_first import ReadOnlyFirst diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/base_discriminator.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/base_discriminator.py new file mode 100644 index 000000000000..f13c270b56b5 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/base_discriminator.py @@ -0,0 +1,110 @@ +# 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 importlib import import_module +from pydantic import BaseModel, ConfigDict, Field, StrictStr +from typing import Any, ClassVar, Dict, List, Optional, Union +from typing import Optional, Set +from typing_extensions import Self + +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from petstore_api.models.primitive_string import PrimitiveString + from petstore_api.models.info import Info + +class BaseDiscriminator(BaseModel): + """ + BaseDiscriminator + """ # noqa: E501 + type_name: Optional[StrictStr] = Field(default=None, alias="_typeName") + __properties: ClassVar[List[str]] = ["_typeName"] + + model_config = ConfigDict( + populate_by_name=True, + validate_assignment=True, + protected_namespaces=(), + ) + + + # JSON field name that stores the object type + __discriminator_property_name: ClassVar[str] = '_typeName' + + # discriminator mappings + __discriminator_value_class_map: ClassVar[Dict[str, str]] = { + 'string': 'PrimitiveString','Info': 'Info' + } + + @classmethod + def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]: + """Returns the discriminator value (object type) of the data""" + discriminator_value = obj[cls.__discriminator_property_name] + if discriminator_value: + return cls.__discriminator_value_class_map.get(discriminator_value) + else: + return None + + 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[Union[PrimitiveString, Info]]: + """Create an instance of BaseDiscriminator 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, + ) + return _dict + + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[PrimitiveString, Info]]: + """Create an instance of BaseDiscriminator from a dict""" + # look up the object type based on discriminator mapping + object_type = cls.get_discriminator_value(obj) + if object_type == 'PrimitiveString': + return import_module("petstore_api.models.primitive_string").PrimitiveString.from_dict(obj) + if object_type == 'Info': + return import_module("petstore_api.models.info").Info.from_dict(obj) + + raise ValueError("BaseDiscriminator failed to lookup discriminator value from " + + json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + + ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) + + diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/info.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/info.py new file mode 100644 index 000000000000..5a15b5f9f52f --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/info.py @@ -0,0 +1,92 @@ +# 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 ConfigDict +from typing import Any, ClassVar, Dict, List, Optional +from petstore_api.models.base_discriminator import BaseDiscriminator +from typing import Optional, Set +from typing_extensions import Self + +class Info(BaseDiscriminator): + """ + Info + """ # noqa: E501 + val: Optional[BaseDiscriminator] = None + __properties: ClassVar[List[str]] = ["_typeName", "val"] + + model_config = ConfigDict( + populate_by_name=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 Info 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 val + if self.val: + _dict['val'] = self.val.to_dict() + return _dict + + @classmethod + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: + """Create an instance of Info from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "_typeName": obj.get("_typeName"), + "val": BaseDiscriminator.from_dict(obj["val"]) if obj.get("val") is not None else None + }) + return _obj + + diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/primitive_string.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/primitive_string.py new file mode 100644 index 000000000000..5a7065597861 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/primitive_string.py @@ -0,0 +1,89 @@ +# 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 ConfigDict, Field, StrictStr +from typing import Any, ClassVar, Dict, List, Optional +from petstore_api.models.base_discriminator import BaseDiscriminator +from typing import Optional, Set +from typing_extensions import Self + +class PrimitiveString(BaseDiscriminator): + """ + PrimitiveString + """ # noqa: E501 + value: Optional[StrictStr] = Field(default=None, alias="_value") + __properties: ClassVar[List[str]] = ["_typeName", "_value"] + + model_config = ConfigDict( + populate_by_name=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 PrimitiveString 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, + ) + return _dict + + @classmethod + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: + """Create an instance of PrimitiveString from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "_typeName": obj.get("_typeName"), + "_value": obj.get("_value") + }) + return _obj + + diff --git a/samples/openapi3/client/petstore/python-aiohttp/test/test_base_discriminator.py b/samples/openapi3/client/petstore/python-aiohttp/test/test_base_discriminator.py new file mode 100644 index 000000000000..61c40f7f6809 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/test/test_base_discriminator.py @@ -0,0 +1,51 @@ +# 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 + + +import unittest + +from petstore_api.models.base_discriminator import BaseDiscriminator + +class TestBaseDiscriminator(unittest.TestCase): + """BaseDiscriminator unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> BaseDiscriminator: + """Test BaseDiscriminator + 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 `BaseDiscriminator` + """ + model = BaseDiscriminator() + if include_optional: + return BaseDiscriminator( + type_name = '' + ) + else: + return BaseDiscriminator( + ) + """ + + def testBaseDiscriminator(self): + """Test BaseDiscriminator""" + # 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-aiohttp/test/test_info.py b/samples/openapi3/client/petstore/python-aiohttp/test/test_info.py new file mode 100644 index 000000000000..e1fce9f9c1ec --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/test/test_info.py @@ -0,0 +1,51 @@ +# 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 + + +import unittest + +from petstore_api.models.info import Info + +class TestInfo(unittest.TestCase): + """Info unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> Info: + """Test Info + 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 `Info` + """ + model = Info() + if include_optional: + return Info( + val = petstore_api.models.base_discriminator.BaseDiscriminator() + ) + else: + return Info( + ) + """ + + def testInfo(self): + """Test Info""" + # 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-aiohttp/test/test_primitive_string.py b/samples/openapi3/client/petstore/python-aiohttp/test/test_primitive_string.py new file mode 100644 index 000000000000..8b9ccf59893b --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/test/test_primitive_string.py @@ -0,0 +1,51 @@ +# 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 + + +import unittest + +from petstore_api.models.primitive_string import PrimitiveString + +class TestPrimitiveString(unittest.TestCase): + """PrimitiveString unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> PrimitiveString: + """Test PrimitiveString + 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 `PrimitiveString` + """ + model = PrimitiveString() + if include_optional: + return PrimitiveString( + value = '' + ) + else: + return PrimitiveString( + ) + """ + + def testPrimitiveString(self): + """Test PrimitiveString""" + # 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-pydantic-v1-aiohttp/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/.openapi-generator/FILES index c9774b574f89..5bd01d524209 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/.openapi-generator/FILES @@ -18,6 +18,7 @@ docs/ArrayOfArrayOfModel.md docs/ArrayOfArrayOfNumberOnly.md docs/ArrayOfNumberOnly.md docs/ArrayTest.md +docs/BaseDiscriminator.md docs/BasquePig.md docs/Bathing.md docs/Capitalization.md @@ -55,6 +56,7 @@ docs/FormatTest.md docs/HasOnlyReadOnly.md docs/HealthCheckResult.md docs/ImportTestDatetimeApi.md +docs/Info.md docs/InnerDictWithProperty.md docs/InputAllOf.md docs/IntOrString.md @@ -84,6 +86,7 @@ docs/Pet.md docs/PetApi.md docs/Pig.md docs/PoopCleaning.md +docs/PrimitiveString.md docs/PropertyMap.md docs/PropertyNameCollision.md docs/ReadOnlyFirst.md @@ -138,6 +141,7 @@ petstore_api/models/array_of_array_of_model.py petstore_api/models/array_of_array_of_number_only.py petstore_api/models/array_of_number_only.py petstore_api/models/array_test.py +petstore_api/models/base_discriminator.py petstore_api/models/basque_pig.py petstore_api/models/bathing.py petstore_api/models/capitalization.py @@ -171,6 +175,7 @@ petstore_api/models/foo_get_default_response.py petstore_api/models/format_test.py petstore_api/models/has_only_read_only.py petstore_api/models/health_check_result.py +petstore_api/models/info.py petstore_api/models/inner_dict_with_property.py petstore_api/models/input_all_of.py petstore_api/models/int_or_string.py @@ -199,6 +204,7 @@ petstore_api/models/parent_with_optional_dict.py petstore_api/models/pet.py petstore_api/models/pig.py petstore_api/models/poop_cleaning.py +petstore_api/models/primitive_string.py petstore_api/models/property_map.py petstore_api/models/property_name_collision.py petstore_api/models/read_only_first.py diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/README.md b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/README.md index 4bf145333acf..899708a1e898 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/README.md +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/README.md @@ -165,6 +165,7 @@ Class | Method | HTTP request | Description - [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md) - [ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md) - [ArrayTest](docs/ArrayTest.md) + - [BaseDiscriminator](docs/BaseDiscriminator.md) - [BasquePig](docs/BasquePig.md) - [Bathing](docs/Bathing.md) - [Capitalization](docs/Capitalization.md) @@ -198,6 +199,7 @@ Class | Method | HTTP request | Description - [FormatTest](docs/FormatTest.md) - [HasOnlyReadOnly](docs/HasOnlyReadOnly.md) - [HealthCheckResult](docs/HealthCheckResult.md) + - [Info](docs/Info.md) - [InnerDictWithProperty](docs/InnerDictWithProperty.md) - [InputAllOf](docs/InputAllOf.md) - [IntOrString](docs/IntOrString.md) @@ -226,6 +228,7 @@ Class | Method | HTTP request | Description - [Pet](docs/Pet.md) - [Pig](docs/Pig.md) - [PoopCleaning](docs/PoopCleaning.md) + - [PrimitiveString](docs/PrimitiveString.md) - [PropertyMap](docs/PropertyMap.md) - [PropertyNameCollision](docs/PropertyNameCollision.md) - [ReadOnlyFirst](docs/ReadOnlyFirst.md) diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/BaseDiscriminator.md b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/BaseDiscriminator.md new file mode 100644 index 000000000000..38e238100e24 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/BaseDiscriminator.md @@ -0,0 +1,28 @@ +# BaseDiscriminator + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**type_name** | **str** | | [optional] + +## Example + +```python +from petstore_api.models.base_discriminator import BaseDiscriminator + +# TODO update the JSON string below +json = "{}" +# create an instance of BaseDiscriminator from a JSON string +base_discriminator_instance = BaseDiscriminator.from_json(json) +# print the JSON string representation of the object +print BaseDiscriminator.to_json() + +# convert the object into a dict +base_discriminator_dict = base_discriminator_instance.to_dict() +# create an instance of BaseDiscriminator from a dict +base_discriminator_from_dict = BaseDiscriminator.from_dict(base_discriminator_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-pydantic-v1-aiohttp/docs/Info.md b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/Info.md new file mode 100644 index 000000000000..20497b998d16 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/Info.md @@ -0,0 +1,28 @@ +# Info + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**val** | [**BaseDiscriminator**](BaseDiscriminator.md) | | [optional] + +## Example + +```python +from petstore_api.models.info import Info + +# TODO update the JSON string below +json = "{}" +# create an instance of Info from a JSON string +info_instance = Info.from_json(json) +# print the JSON string representation of the object +print Info.to_json() + +# convert the object into a dict +info_dict = info_instance.to_dict() +# create an instance of Info from a dict +info_from_dict = Info.from_dict(info_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-pydantic-v1-aiohttp/docs/PrimitiveString.md b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/PrimitiveString.md new file mode 100644 index 000000000000..e4af0dda380e --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/PrimitiveString.md @@ -0,0 +1,28 @@ +# PrimitiveString + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**value** | **str** | | [optional] + +## Example + +```python +from petstore_api.models.primitive_string import PrimitiveString + +# TODO update the JSON string below +json = "{}" +# create an instance of PrimitiveString from a JSON string +primitive_string_instance = PrimitiveString.from_json(json) +# print the JSON string representation of the object +print PrimitiveString.to_json() + +# convert the object into a dict +primitive_string_dict = primitive_string_instance.to_dict() +# create an instance of PrimitiveString from a dict +primitive_string_from_dict = PrimitiveString.from_dict(primitive_string_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-pydantic-v1-aiohttp/petstore_api/__init__.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/__init__.py index daedab928cf4..c0b99d8bf822 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/__init__.py @@ -53,6 +53,7 @@ from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly 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 from petstore_api.models.basque_pig import BasquePig from petstore_api.models.bathing import Bathing from petstore_api.models.capitalization import Capitalization @@ -86,6 +87,7 @@ from petstore_api.models.format_test import FormatTest from petstore_api.models.has_only_read_only import HasOnlyReadOnly from petstore_api.models.health_check_result import HealthCheckResult +from petstore_api.models.info import Info from petstore_api.models.inner_dict_with_property import InnerDictWithProperty from petstore_api.models.input_all_of import InputAllOf from petstore_api.models.int_or_string import IntOrString @@ -114,6 +116,7 @@ from petstore_api.models.pet import Pet from petstore_api.models.pig import Pig from petstore_api.models.poop_cleaning import PoopCleaning +from petstore_api.models.primitive_string import PrimitiveString from petstore_api.models.property_map import PropertyMap from petstore_api.models.property_name_collision import PropertyNameCollision from petstore_api.models.read_only_first import ReadOnlyFirst diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/__init__.py index 92d7dc877f2c..2124d65dc346 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/__init__.py @@ -28,6 +28,7 @@ from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly 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 from petstore_api.models.basque_pig import BasquePig from petstore_api.models.bathing import Bathing from petstore_api.models.capitalization import Capitalization @@ -61,6 +62,7 @@ from petstore_api.models.format_test import FormatTest from petstore_api.models.has_only_read_only import HasOnlyReadOnly from petstore_api.models.health_check_result import HealthCheckResult +from petstore_api.models.info import Info from petstore_api.models.inner_dict_with_property import InnerDictWithProperty from petstore_api.models.input_all_of import InputAllOf from petstore_api.models.int_or_string import IntOrString @@ -89,6 +91,7 @@ from petstore_api.models.pet import Pet from petstore_api.models.pig import Pig from petstore_api.models.poop_cleaning import PoopCleaning +from petstore_api.models.primitive_string import PrimitiveString from petstore_api.models.property_map import PropertyMap from petstore_api.models.property_name_collision import PropertyNameCollision from petstore_api.models.read_only_first import ReadOnlyFirst diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/base_discriminator.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/base_discriminator.py new file mode 100644 index 000000000000..aa1514c94448 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/base_discriminator.py @@ -0,0 +1,94 @@ +# 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 typing import Optional, Union +from pydantic import BaseModel, Field, StrictStr + +from typing import TYPE_CHECKING +from importlib import import_module +if TYPE_CHECKING: + from petstore_api.models.primitive_string import PrimitiveString + from petstore_api.models.info import Info + +class BaseDiscriminator(BaseModel): + """ + BaseDiscriminator + """ + type_name: Optional[StrictStr] = Field(default=None, alias="_typeName") + __properties = ["_typeName"] + + class Config: + """Pydantic configuration""" + allow_population_by_field_name = True + validate_assignment = True + + # JSON field name that stores the object type + __discriminator_property_name = '_typeName' + + # discriminator mappings + __discriminator_value_class_map = { + 'string': 'PrimitiveString', + 'Info': 'Info' + } + + @classmethod + def get_discriminator_value(cls, obj: dict) -> str: + """Returns the discriminator value (object type) of the data""" + discriminator_value = obj[cls.__discriminator_property_name] + if discriminator_value: + return cls.__discriminator_value_class_map.get(discriminator_value) + else: + return None + + 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) -> Union(Info, PrimitiveString): + """Create an instance of BaseDiscriminator 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) + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> Union(Info, PrimitiveString): + """Create an instance of BaseDiscriminator from a dict""" + # look up the object type based on discriminator mapping + object_type = cls.get_discriminator_value(obj) + if object_type == 'PrimitiveString': + return import_module("petstore_api.models.primitive_string").PrimitiveString.from_dict(obj) + if object_type == 'Info': + return import_module("petstore_api.models.info").Info.from_dict(obj) + raise ValueError("BaseDiscriminator failed to lookup discriminator value from " + + json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + + ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/info.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/info.py new file mode 100644 index 000000000000..a181034ea313 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/info.py @@ -0,0 +1,76 @@ +# 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 typing import Optional + +from petstore_api.models.base_discriminator import BaseDiscriminator + +class Info(BaseDiscriminator): + """ + Info + """ + val: Optional[BaseDiscriminator] = None + __properties = ["_typeName", "val"] + + class Config: + """Pydantic configuration""" + 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) -> Info: + """Create an instance of Info 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 val + if self.val: + _dict['val'] = self.val.to_dict() + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> Info: + """Create an instance of Info from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return Info.parse_obj(obj) + + _obj = Info.parse_obj({ + "type_name": obj.get("_typeName"), + "val": BaseDiscriminator.from_dict(obj.get("val")) if obj.get("val") is not None else None + }) + return _obj + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/primitive_string.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/primitive_string.py new file mode 100644 index 000000000000..4d84353e6035 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/primitive_string.py @@ -0,0 +1,73 @@ +# 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 typing import Optional +from pydantic import Field, StrictStr +from petstore_api.models.base_discriminator import BaseDiscriminator + +class PrimitiveString(BaseDiscriminator): + """ + PrimitiveString + """ + value: Optional[StrictStr] = Field(default=None, alias="_value") + __properties = ["_typeName", "_value"] + + class Config: + """Pydantic configuration""" + 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) -> PrimitiveString: + """Create an instance of PrimitiveString 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) + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> PrimitiveString: + """Create an instance of PrimitiveString from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return PrimitiveString.parse_obj(obj) + + _obj = PrimitiveString.parse_obj({ + "type_name": obj.get("_typeName"), + "value": obj.get("_value") + }) + return _obj + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_base_discriminator.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_base_discriminator.py new file mode 100644 index 000000000000..c31f6bdea261 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_base_discriminator.py @@ -0,0 +1,52 @@ +# 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 + + +import unittest +import datetime + +from petstore_api.models.base_discriminator import BaseDiscriminator # noqa: E501 + +class TestBaseDiscriminator(unittest.TestCase): + """BaseDiscriminator unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> BaseDiscriminator: + """Test BaseDiscriminator + 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 `BaseDiscriminator` + """ + model = BaseDiscriminator() # noqa: E501 + if include_optional: + return BaseDiscriminator( + type_name = '' + ) + else: + return BaseDiscriminator( + ) + """ + + def testBaseDiscriminator(self): + """Test BaseDiscriminator""" + # 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-pydantic-v1-aiohttp/test/test_info.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_info.py new file mode 100644 index 000000000000..f16c34e34a4b --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_info.py @@ -0,0 +1,52 @@ +# 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 + + +import unittest +import datetime + +from petstore_api.models.info import Info # noqa: E501 + +class TestInfo(unittest.TestCase): + """Info unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> Info: + """Test Info + 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 `Info` + """ + model = Info() # noqa: E501 + if include_optional: + return Info( + val = petstore_api.models.base_discriminator.BaseDiscriminator() + ) + else: + return Info( + ) + """ + + def testInfo(self): + """Test Info""" + # 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-pydantic-v1-aiohttp/test/test_primitive_string.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_primitive_string.py new file mode 100644 index 000000000000..7d873f8d6212 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_primitive_string.py @@ -0,0 +1,52 @@ +# 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 + + +import unittest +import datetime + +from petstore_api.models.primitive_string import PrimitiveString # noqa: E501 + +class TestPrimitiveString(unittest.TestCase): + """PrimitiveString unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> PrimitiveString: + """Test PrimitiveString + 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 `PrimitiveString` + """ + model = PrimitiveString() # noqa: E501 + if include_optional: + return PrimitiveString( + value = '' + ) + else: + return PrimitiveString( + ) + """ + + def testPrimitiveString(self): + """Test PrimitiveString""" + # 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-pydantic-v1/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-pydantic-v1/.openapi-generator/FILES index c9774b574f89..5bd01d524209 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-pydantic-v1/.openapi-generator/FILES @@ -18,6 +18,7 @@ docs/ArrayOfArrayOfModel.md docs/ArrayOfArrayOfNumberOnly.md docs/ArrayOfNumberOnly.md docs/ArrayTest.md +docs/BaseDiscriminator.md docs/BasquePig.md docs/Bathing.md docs/Capitalization.md @@ -55,6 +56,7 @@ docs/FormatTest.md docs/HasOnlyReadOnly.md docs/HealthCheckResult.md docs/ImportTestDatetimeApi.md +docs/Info.md docs/InnerDictWithProperty.md docs/InputAllOf.md docs/IntOrString.md @@ -84,6 +86,7 @@ docs/Pet.md docs/PetApi.md docs/Pig.md docs/PoopCleaning.md +docs/PrimitiveString.md docs/PropertyMap.md docs/PropertyNameCollision.md docs/ReadOnlyFirst.md @@ -138,6 +141,7 @@ petstore_api/models/array_of_array_of_model.py petstore_api/models/array_of_array_of_number_only.py petstore_api/models/array_of_number_only.py petstore_api/models/array_test.py +petstore_api/models/base_discriminator.py petstore_api/models/basque_pig.py petstore_api/models/bathing.py petstore_api/models/capitalization.py @@ -171,6 +175,7 @@ petstore_api/models/foo_get_default_response.py petstore_api/models/format_test.py petstore_api/models/has_only_read_only.py petstore_api/models/health_check_result.py +petstore_api/models/info.py petstore_api/models/inner_dict_with_property.py petstore_api/models/input_all_of.py petstore_api/models/int_or_string.py @@ -199,6 +204,7 @@ petstore_api/models/parent_with_optional_dict.py petstore_api/models/pet.py petstore_api/models/pig.py petstore_api/models/poop_cleaning.py +petstore_api/models/primitive_string.py petstore_api/models/property_map.py petstore_api/models/property_name_collision.py petstore_api/models/read_only_first.py diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/README.md b/samples/openapi3/client/petstore/python-pydantic-v1/README.md index 1f0342838c00..f6981efbf93e 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/README.md +++ b/samples/openapi3/client/petstore/python-pydantic-v1/README.md @@ -165,6 +165,7 @@ Class | Method | HTTP request | Description - [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md) - [ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md) - [ArrayTest](docs/ArrayTest.md) + - [BaseDiscriminator](docs/BaseDiscriminator.md) - [BasquePig](docs/BasquePig.md) - [Bathing](docs/Bathing.md) - [Capitalization](docs/Capitalization.md) @@ -198,6 +199,7 @@ Class | Method | HTTP request | Description - [FormatTest](docs/FormatTest.md) - [HasOnlyReadOnly](docs/HasOnlyReadOnly.md) - [HealthCheckResult](docs/HealthCheckResult.md) + - [Info](docs/Info.md) - [InnerDictWithProperty](docs/InnerDictWithProperty.md) - [InputAllOf](docs/InputAllOf.md) - [IntOrString](docs/IntOrString.md) @@ -226,6 +228,7 @@ Class | Method | HTTP request | Description - [Pet](docs/Pet.md) - [Pig](docs/Pig.md) - [PoopCleaning](docs/PoopCleaning.md) + - [PrimitiveString](docs/PrimitiveString.md) - [PropertyMap](docs/PropertyMap.md) - [PropertyNameCollision](docs/PropertyNameCollision.md) - [ReadOnlyFirst](docs/ReadOnlyFirst.md) diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/docs/BaseDiscriminator.md b/samples/openapi3/client/petstore/python-pydantic-v1/docs/BaseDiscriminator.md new file mode 100644 index 000000000000..38e238100e24 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/docs/BaseDiscriminator.md @@ -0,0 +1,28 @@ +# BaseDiscriminator + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**type_name** | **str** | | [optional] + +## Example + +```python +from petstore_api.models.base_discriminator import BaseDiscriminator + +# TODO update the JSON string below +json = "{}" +# create an instance of BaseDiscriminator from a JSON string +base_discriminator_instance = BaseDiscriminator.from_json(json) +# print the JSON string representation of the object +print BaseDiscriminator.to_json() + +# convert the object into a dict +base_discriminator_dict = base_discriminator_instance.to_dict() +# create an instance of BaseDiscriminator from a dict +base_discriminator_from_dict = BaseDiscriminator.from_dict(base_discriminator_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-pydantic-v1/docs/Info.md b/samples/openapi3/client/petstore/python-pydantic-v1/docs/Info.md new file mode 100644 index 000000000000..20497b998d16 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/docs/Info.md @@ -0,0 +1,28 @@ +# Info + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**val** | [**BaseDiscriminator**](BaseDiscriminator.md) | | [optional] + +## Example + +```python +from petstore_api.models.info import Info + +# TODO update the JSON string below +json = "{}" +# create an instance of Info from a JSON string +info_instance = Info.from_json(json) +# print the JSON string representation of the object +print Info.to_json() + +# convert the object into a dict +info_dict = info_instance.to_dict() +# create an instance of Info from a dict +info_from_dict = Info.from_dict(info_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-pydantic-v1/docs/PrimitiveString.md b/samples/openapi3/client/petstore/python-pydantic-v1/docs/PrimitiveString.md new file mode 100644 index 000000000000..e4af0dda380e --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/docs/PrimitiveString.md @@ -0,0 +1,28 @@ +# PrimitiveString + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**value** | **str** | | [optional] + +## Example + +```python +from petstore_api.models.primitive_string import PrimitiveString + +# TODO update the JSON string below +json = "{}" +# create an instance of PrimitiveString from a JSON string +primitive_string_instance = PrimitiveString.from_json(json) +# print the JSON string representation of the object +print PrimitiveString.to_json() + +# convert the object into a dict +primitive_string_dict = primitive_string_instance.to_dict() +# create an instance of PrimitiveString from a dict +primitive_string_from_dict = PrimitiveString.from_dict(primitive_string_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-pydantic-v1/petstore_api/__init__.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/__init__.py index daedab928cf4..c0b99d8bf822 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/__init__.py @@ -53,6 +53,7 @@ from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly 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 from petstore_api.models.basque_pig import BasquePig from petstore_api.models.bathing import Bathing from petstore_api.models.capitalization import Capitalization @@ -86,6 +87,7 @@ from petstore_api.models.format_test import FormatTest from petstore_api.models.has_only_read_only import HasOnlyReadOnly from petstore_api.models.health_check_result import HealthCheckResult +from petstore_api.models.info import Info from petstore_api.models.inner_dict_with_property import InnerDictWithProperty from petstore_api.models.input_all_of import InputAllOf from petstore_api.models.int_or_string import IntOrString @@ -114,6 +116,7 @@ from petstore_api.models.pet import Pet from petstore_api.models.pig import Pig from petstore_api.models.poop_cleaning import PoopCleaning +from petstore_api.models.primitive_string import PrimitiveString from petstore_api.models.property_map import PropertyMap from petstore_api.models.property_name_collision import PropertyNameCollision from petstore_api.models.read_only_first import ReadOnlyFirst diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/__init__.py index 92d7dc877f2c..2124d65dc346 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/__init__.py @@ -28,6 +28,7 @@ from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly 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 from petstore_api.models.basque_pig import BasquePig from petstore_api.models.bathing import Bathing from petstore_api.models.capitalization import Capitalization @@ -61,6 +62,7 @@ from petstore_api.models.format_test import FormatTest from petstore_api.models.has_only_read_only import HasOnlyReadOnly from petstore_api.models.health_check_result import HealthCheckResult +from petstore_api.models.info import Info from petstore_api.models.inner_dict_with_property import InnerDictWithProperty from petstore_api.models.input_all_of import InputAllOf from petstore_api.models.int_or_string import IntOrString @@ -89,6 +91,7 @@ from petstore_api.models.pet import Pet from petstore_api.models.pig import Pig from petstore_api.models.poop_cleaning import PoopCleaning +from petstore_api.models.primitive_string import PrimitiveString from petstore_api.models.property_map import PropertyMap from petstore_api.models.property_name_collision import PropertyNameCollision from petstore_api.models.read_only_first import ReadOnlyFirst diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/base_discriminator.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/base_discriminator.py new file mode 100644 index 000000000000..1eaf3731bf79 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/base_discriminator.py @@ -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 typing import Any, Dict, Optional, Union +from pydantic import BaseModel, Field, StrictStr + +from typing import TYPE_CHECKING +from importlib import import_module +if TYPE_CHECKING: + from petstore_api.models.primitive_string import PrimitiveString + from petstore_api.models.info import Info + +class BaseDiscriminator(BaseModel): + """ + BaseDiscriminator + """ + type_name: Optional[StrictStr] = Field(default=None, alias="_typeName") + additional_properties: Dict[str, Any] = {} + __properties = ["_typeName"] + + class Config: + """Pydantic configuration""" + allow_population_by_field_name = True + validate_assignment = True + + # JSON field name that stores the object type + __discriminator_property_name = '_typeName' + + # discriminator mappings + __discriminator_value_class_map = { + 'string': 'PrimitiveString', + 'Info': 'Info' + } + + @classmethod + def get_discriminator_value(cls, obj: dict) -> str: + """Returns the discriminator value (object type) of the data""" + discriminator_value = obj[cls.__discriminator_property_name] + if discriminator_value: + return cls.__discriminator_value_class_map.get(discriminator_value) + else: + return None + + 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) -> Union(Info, PrimitiveString): + """Create an instance of BaseDiscriminator 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) + # 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) -> Union(Info, PrimitiveString): + """Create an instance of BaseDiscriminator from a dict""" + # look up the object type based on discriminator mapping + object_type = cls.get_discriminator_value(obj) + if object_type == 'PrimitiveString': + return import_module("petstore_api.models.primitive_string").PrimitiveString.from_dict(obj) + if object_type == 'Info': + return import_module("petstore_api.models.info").Info.from_dict(obj) + raise ValueError("BaseDiscriminator failed to lookup discriminator value from " + + json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + + ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/info.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/info.py new file mode 100644 index 000000000000..46ea104c0a70 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/info.py @@ -0,0 +1,88 @@ +# 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 typing import Any, Dict, Optional + +from petstore_api.models.base_discriminator import BaseDiscriminator + +class Info(BaseDiscriminator): + """ + Info + """ + val: Optional[BaseDiscriminator] = None + additional_properties: Dict[str, Any] = {} + __properties = ["_typeName", "val"] + + class Config: + """Pydantic configuration""" + 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) -> Info: + """Create an instance of Info 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 val + if self.val: + _dict['val'] = self.val.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 + + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> Info: + """Create an instance of Info from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return Info.parse_obj(obj) + + _obj = Info.parse_obj({ + "type_name": obj.get("_typeName"), + "val": BaseDiscriminator.from_dict(obj.get("val")) if obj.get("val") 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-pydantic-v1/petstore_api/models/primitive_string.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/primitive_string.py new file mode 100644 index 000000000000..b67daec1d987 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/primitive_string.py @@ -0,0 +1,85 @@ +# 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 typing import Any, Dict, Optional +from pydantic import Field, StrictStr +from petstore_api.models.base_discriminator import BaseDiscriminator + +class PrimitiveString(BaseDiscriminator): + """ + PrimitiveString + """ + value: Optional[StrictStr] = Field(default=None, alias="_value") + additional_properties: Dict[str, Any] = {} + __properties = ["_typeName", "_value"] + + class Config: + """Pydantic configuration""" + 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) -> PrimitiveString: + """Create an instance of PrimitiveString 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) + # 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) -> PrimitiveString: + """Create an instance of PrimitiveString from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return PrimitiveString.parse_obj(obj) + + _obj = PrimitiveString.parse_obj({ + "type_name": obj.get("_typeName"), + "value": obj.get("_value") + }) + # 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-pydantic-v1/test/test_base_discriminator.py b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_base_discriminator.py new file mode 100644 index 000000000000..c31f6bdea261 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_base_discriminator.py @@ -0,0 +1,52 @@ +# 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 + + +import unittest +import datetime + +from petstore_api.models.base_discriminator import BaseDiscriminator # noqa: E501 + +class TestBaseDiscriminator(unittest.TestCase): + """BaseDiscriminator unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> BaseDiscriminator: + """Test BaseDiscriminator + 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 `BaseDiscriminator` + """ + model = BaseDiscriminator() # noqa: E501 + if include_optional: + return BaseDiscriminator( + type_name = '' + ) + else: + return BaseDiscriminator( + ) + """ + + def testBaseDiscriminator(self): + """Test BaseDiscriminator""" + # 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-pydantic-v1/test/test_info.py b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_info.py new file mode 100644 index 000000000000..f16c34e34a4b --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_info.py @@ -0,0 +1,52 @@ +# 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 + + +import unittest +import datetime + +from petstore_api.models.info import Info # noqa: E501 + +class TestInfo(unittest.TestCase): + """Info unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> Info: + """Test Info + 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 `Info` + """ + model = Info() # noqa: E501 + if include_optional: + return Info( + val = petstore_api.models.base_discriminator.BaseDiscriminator() + ) + else: + return Info( + ) + """ + + def testInfo(self): + """Test Info""" + # 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-pydantic-v1/test/test_primitive_string.py b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_primitive_string.py new file mode 100644 index 000000000000..7d873f8d6212 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_primitive_string.py @@ -0,0 +1,52 @@ +# 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 + + +import unittest +import datetime + +from petstore_api.models.primitive_string import PrimitiveString # noqa: E501 + +class TestPrimitiveString(unittest.TestCase): + """PrimitiveString unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> PrimitiveString: + """Test PrimitiveString + 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 `PrimitiveString` + """ + model = PrimitiveString() # noqa: E501 + if include_optional: + return PrimitiveString( + value = '' + ) + else: + return PrimitiveString( + ) + """ + + def testPrimitiveString(self): + """Test PrimitiveString""" + # 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/.openapi-generator/FILES b/samples/openapi3/client/petstore/python/.openapi-generator/FILES index f7e65690c399..6b44ba44379a 100755 --- a/samples/openapi3/client/petstore/python/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python/.openapi-generator/FILES @@ -17,6 +17,7 @@ docs/ArrayOfArrayOfModel.md docs/ArrayOfArrayOfNumberOnly.md docs/ArrayOfNumberOnly.md docs/ArrayTest.md +docs/BaseDiscriminator.md docs/BasquePig.md docs/Bathing.md docs/Capitalization.md @@ -53,6 +54,7 @@ docs/FormatTest.md docs/HasOnlyReadOnly.md docs/HealthCheckResult.md docs/ImportTestDatetimeApi.md +docs/Info.md docs/InnerDictWithProperty.md docs/InputAllOf.md docs/IntOrString.md @@ -84,6 +86,7 @@ docs/Pet.md docs/PetApi.md docs/Pig.md docs/PoopCleaning.md +docs/PrimitiveString.md docs/PropertyMap.md docs/PropertyNameCollision.md docs/ReadOnlyFirst.md @@ -137,6 +140,7 @@ petstore_api/models/array_of_array_of_model.py petstore_api/models/array_of_array_of_number_only.py petstore_api/models/array_of_number_only.py petstore_api/models/array_test.py +petstore_api/models/base_discriminator.py petstore_api/models/basque_pig.py petstore_api/models/bathing.py petstore_api/models/capitalization.py @@ -169,6 +173,7 @@ petstore_api/models/foo_get_default_response.py petstore_api/models/format_test.py petstore_api/models/has_only_read_only.py petstore_api/models/health_check_result.py +petstore_api/models/info.py petstore_api/models/inner_dict_with_property.py petstore_api/models/input_all_of.py petstore_api/models/int_or_string.py @@ -199,6 +204,7 @@ petstore_api/models/parent_with_optional_dict.py petstore_api/models/pet.py petstore_api/models/pig.py petstore_api/models/poop_cleaning.py +petstore_api/models/primitive_string.py petstore_api/models/property_map.py petstore_api/models/property_name_collision.py petstore_api/models/read_only_first.py diff --git a/samples/openapi3/client/petstore/python/README.md b/samples/openapi3/client/petstore/python/README.md index 89ecb5e3cba2..b3afb5872093 100755 --- a/samples/openapi3/client/petstore/python/README.md +++ b/samples/openapi3/client/petstore/python/README.md @@ -163,6 +163,7 @@ Class | Method | HTTP request | Description - [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md) - [ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md) - [ArrayTest](docs/ArrayTest.md) + - [BaseDiscriminator](docs/BaseDiscriminator.md) - [BasquePig](docs/BasquePig.md) - [Bathing](docs/Bathing.md) - [Capitalization](docs/Capitalization.md) @@ -195,6 +196,7 @@ Class | Method | HTTP request | Description - [FormatTest](docs/FormatTest.md) - [HasOnlyReadOnly](docs/HasOnlyReadOnly.md) - [HealthCheckResult](docs/HealthCheckResult.md) + - [Info](docs/Info.md) - [InnerDictWithProperty](docs/InnerDictWithProperty.md) - [InputAllOf](docs/InputAllOf.md) - [IntOrString](docs/IntOrString.md) @@ -225,6 +227,7 @@ Class | Method | HTTP request | Description - [Pet](docs/Pet.md) - [Pig](docs/Pig.md) - [PoopCleaning](docs/PoopCleaning.md) + - [PrimitiveString](docs/PrimitiveString.md) - [PropertyMap](docs/PropertyMap.md) - [PropertyNameCollision](docs/PropertyNameCollision.md) - [ReadOnlyFirst](docs/ReadOnlyFirst.md) diff --git a/samples/openapi3/client/petstore/python/docs/BaseDiscriminator.md b/samples/openapi3/client/petstore/python/docs/BaseDiscriminator.md new file mode 100644 index 000000000000..fcdbeb032e68 --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/BaseDiscriminator.md @@ -0,0 +1,29 @@ +# BaseDiscriminator + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**type_name** | **str** | | [optional] + +## Example + +```python +from petstore_api.models.base_discriminator import BaseDiscriminator + +# TODO update the JSON string below +json = "{}" +# create an instance of BaseDiscriminator from a JSON string +base_discriminator_instance = BaseDiscriminator.from_json(json) +# print the JSON string representation of the object +print(BaseDiscriminator.to_json()) + +# convert the object into a dict +base_discriminator_dict = base_discriminator_instance.to_dict() +# create an instance of BaseDiscriminator from a dict +base_discriminator_from_dict = BaseDiscriminator.from_dict(base_discriminator_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/docs/Info.md b/samples/openapi3/client/petstore/python/docs/Info.md new file mode 100644 index 000000000000..db88778a9143 --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/Info.md @@ -0,0 +1,29 @@ +# Info + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**val** | [**BaseDiscriminator**](BaseDiscriminator.md) | | [optional] + +## Example + +```python +from petstore_api.models.info import Info + +# TODO update the JSON string below +json = "{}" +# create an instance of Info from a JSON string +info_instance = Info.from_json(json) +# print the JSON string representation of the object +print(Info.to_json()) + +# convert the object into a dict +info_dict = info_instance.to_dict() +# create an instance of Info from a dict +info_from_dict = Info.from_dict(info_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/docs/PrimitiveString.md b/samples/openapi3/client/petstore/python/docs/PrimitiveString.md new file mode 100644 index 000000000000..85ceb632e167 --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/PrimitiveString.md @@ -0,0 +1,29 @@ +# PrimitiveString + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**value** | **str** | | [optional] + +## Example + +```python +from petstore_api.models.primitive_string import PrimitiveString + +# TODO update the JSON string below +json = "{}" +# create an instance of PrimitiveString from a JSON string +primitive_string_instance = PrimitiveString.from_json(json) +# print the JSON string representation of the object +print(PrimitiveString.to_json()) + +# convert the object into a dict +primitive_string_dict = primitive_string_instance.to_dict() +# create an instance of PrimitiveString from a dict +primitive_string_from_dict = PrimitiveString.from_dict(primitive_string_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/petstore_api/__init__.py b/samples/openapi3/client/petstore/python/petstore_api/__init__.py index 1d2a609f13be..3f6c3aabf138 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/__init__.py @@ -52,6 +52,7 @@ from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly 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 from petstore_api.models.basque_pig import BasquePig from petstore_api.models.bathing import Bathing from petstore_api.models.capitalization import Capitalization @@ -84,6 +85,7 @@ from petstore_api.models.format_test import FormatTest from petstore_api.models.has_only_read_only import HasOnlyReadOnly from petstore_api.models.health_check_result import HealthCheckResult +from petstore_api.models.info import Info from petstore_api.models.inner_dict_with_property import InnerDictWithProperty from petstore_api.models.input_all_of import InputAllOf from petstore_api.models.int_or_string import IntOrString @@ -114,6 +116,7 @@ from petstore_api.models.pet import Pet from petstore_api.models.pig import Pig from petstore_api.models.poop_cleaning import PoopCleaning +from petstore_api.models.primitive_string import PrimitiveString from petstore_api.models.property_map import PropertyMap from petstore_api.models.property_name_collision import PropertyNameCollision from petstore_api.models.read_only_first import ReadOnlyFirst diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py index efd9c939d21f..30718c766d7d 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py @@ -27,6 +27,7 @@ from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly 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 from petstore_api.models.basque_pig import BasquePig from petstore_api.models.bathing import Bathing from petstore_api.models.capitalization import Capitalization @@ -59,6 +60,7 @@ from petstore_api.models.format_test import FormatTest from petstore_api.models.has_only_read_only import HasOnlyReadOnly from petstore_api.models.health_check_result import HealthCheckResult +from petstore_api.models.info import Info from petstore_api.models.inner_dict_with_property import InnerDictWithProperty from petstore_api.models.input_all_of import InputAllOf from petstore_api.models.int_or_string import IntOrString @@ -89,6 +91,7 @@ from petstore_api.models.pet import Pet from petstore_api.models.pig import Pig from petstore_api.models.poop_cleaning import PoopCleaning +from petstore_api.models.primitive_string import PrimitiveString from petstore_api.models.property_map import PropertyMap from petstore_api.models.property_name_collision import PropertyNameCollision from petstore_api.models.read_only_first import ReadOnlyFirst diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/base_discriminator.py b/samples/openapi3/client/petstore/python/petstore_api/models/base_discriminator.py new file mode 100644 index 000000000000..40b49a2fca7f --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/models/base_discriminator.py @@ -0,0 +1,118 @@ +# 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 importlib import import_module +from pydantic import BaseModel, ConfigDict, Field, StrictStr +from typing import Any, ClassVar, Dict, List, Optional, Union +from typing import Optional, Set +from typing_extensions import Self + +from typing import TYPE_CHECKING +if TYPE_CHECKING: + from petstore_api.models.primitive_string import PrimitiveString + from petstore_api.models.info import Info + +class BaseDiscriminator(BaseModel): + """ + BaseDiscriminator + """ # noqa: E501 + type_name: Optional[StrictStr] = Field(default=None, alias="_typeName") + additional_properties: Dict[str, Any] = {} + __properties: ClassVar[List[str]] = ["_typeName"] + + model_config = ConfigDict( + populate_by_name=True, + validate_assignment=True, + protected_namespaces=(), + ) + + + # JSON field name that stores the object type + __discriminator_property_name: ClassVar[str] = '_typeName' + + # discriminator mappings + __discriminator_value_class_map: ClassVar[Dict[str, str]] = { + 'string': 'PrimitiveString','Info': 'Info' + } + + @classmethod + def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]: + """Returns the discriminator value (object type) of the data""" + discriminator_value = obj[cls.__discriminator_property_name] + if discriminator_value: + return cls.__discriminator_value_class_map.get(discriminator_value) + else: + return None + + 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[Union[PrimitiveString, Info]]: + """Create an instance of BaseDiscriminator 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. + * Fields in `self.additional_properties` are added to the output dict. + """ + excluded_fields: Set[str] = set([ + "additional_properties", + ]) + + _dict = self.model_dump( + by_alias=True, + exclude=excluded_fields, + exclude_none=True, + ) + # 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[str, Any]) -> Optional[Union[PrimitiveString, Info]]: + """Create an instance of BaseDiscriminator from a dict""" + # look up the object type based on discriminator mapping + object_type = cls.get_discriminator_value(obj) + if object_type == 'PrimitiveString': + return import_module("petstore_api.models.primitive_string").PrimitiveString.from_dict(obj) + if object_type == 'Info': + return import_module("petstore_api.models.info").Info.from_dict(obj) + + raise ValueError("BaseDiscriminator failed to lookup discriminator value from " + + json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name + + ", mapping: " + json.dumps(cls.__discriminator_value_class_map)) + + diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/info.py b/samples/openapi3/client/petstore/python/petstore_api/models/info.py new file mode 100644 index 000000000000..94e663b3aaab --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/models/info.py @@ -0,0 +1,105 @@ +# 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 ConfigDict +from typing import Any, ClassVar, Dict, List, Optional +from petstore_api.models.base_discriminator import BaseDiscriminator +from typing import Optional, Set +from typing_extensions import Self + +class Info(BaseDiscriminator): + """ + Info + """ # noqa: E501 + val: Optional[BaseDiscriminator] = None + additional_properties: Dict[str, Any] = {} + __properties: ClassVar[List[str]] = ["_typeName", "val"] + + model_config = ConfigDict( + populate_by_name=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 Info 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. + * Fields in `self.additional_properties` are added to the output dict. + """ + excluded_fields: Set[str] = set([ + "additional_properties", + ]) + + _dict = self.model_dump( + by_alias=True, + exclude=excluded_fields, + exclude_none=True, + ) + # override the default output from pydantic by calling `to_dict()` of val + if self.val: + _dict['val'] = self.val.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 + + return _dict + + @classmethod + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: + """Create an instance of Info from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "_typeName": obj.get("_typeName"), + "val": BaseDiscriminator.from_dict(obj["val"]) if obj.get("val") 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/petstore_api/models/primitive_string.py b/samples/openapi3/client/petstore/python/petstore_api/models/primitive_string.py new file mode 100644 index 000000000000..f7a971519f2f --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/models/primitive_string.py @@ -0,0 +1,102 @@ +# 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 ConfigDict, Field, StrictStr +from typing import Any, ClassVar, Dict, List, Optional +from petstore_api.models.base_discriminator import BaseDiscriminator +from typing import Optional, Set +from typing_extensions import Self + +class PrimitiveString(BaseDiscriminator): + """ + PrimitiveString + """ # noqa: E501 + value: Optional[StrictStr] = Field(default=None, alias="_value") + additional_properties: Dict[str, Any] = {} + __properties: ClassVar[List[str]] = ["_typeName", "_value"] + + model_config = ConfigDict( + populate_by_name=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 PrimitiveString 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. + * Fields in `self.additional_properties` are added to the output dict. + """ + excluded_fields: Set[str] = set([ + "additional_properties", + ]) + + _dict = self.model_dump( + by_alias=True, + exclude=excluded_fields, + exclude_none=True, + ) + # 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: Optional[Dict[str, Any]]) -> Optional[Self]: + """Create an instance of PrimitiveString from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "_typeName": obj.get("_typeName"), + "_value": obj.get("_value") + }) + # 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/test/test_base_discriminator.py b/samples/openapi3/client/petstore/python/test/test_base_discriminator.py new file mode 100644 index 000000000000..61c40f7f6809 --- /dev/null +++ b/samples/openapi3/client/petstore/python/test/test_base_discriminator.py @@ -0,0 +1,51 @@ +# 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 + + +import unittest + +from petstore_api.models.base_discriminator import BaseDiscriminator + +class TestBaseDiscriminator(unittest.TestCase): + """BaseDiscriminator unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> BaseDiscriminator: + """Test BaseDiscriminator + 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 `BaseDiscriminator` + """ + model = BaseDiscriminator() + if include_optional: + return BaseDiscriminator( + type_name = '' + ) + else: + return BaseDiscriminator( + ) + """ + + def testBaseDiscriminator(self): + """Test BaseDiscriminator""" + # 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/test/test_info.py b/samples/openapi3/client/petstore/python/test/test_info.py new file mode 100644 index 000000000000..e1fce9f9c1ec --- /dev/null +++ b/samples/openapi3/client/petstore/python/test/test_info.py @@ -0,0 +1,51 @@ +# 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 + + +import unittest + +from petstore_api.models.info import Info + +class TestInfo(unittest.TestCase): + """Info unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> Info: + """Test Info + 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 `Info` + """ + model = Info() + if include_optional: + return Info( + val = petstore_api.models.base_discriminator.BaseDiscriminator() + ) + else: + return Info( + ) + """ + + def testInfo(self): + """Test Info""" + # 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/test/test_primitive_string.py b/samples/openapi3/client/petstore/python/test/test_primitive_string.py new file mode 100644 index 000000000000..8b9ccf59893b --- /dev/null +++ b/samples/openapi3/client/petstore/python/test/test_primitive_string.py @@ -0,0 +1,51 @@ +# 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 + + +import unittest + +from petstore_api.models.primitive_string import PrimitiveString + +class TestPrimitiveString(unittest.TestCase): + """PrimitiveString unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> PrimitiveString: + """Test PrimitiveString + 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 `PrimitiveString` + """ + model = PrimitiveString() + if include_optional: + return PrimitiveString( + value = '' + ) + else: + return PrimitiveString( + ) + """ + + def testPrimitiveString(self): + """Test PrimitiveString""" + # 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/tests/test_model.py b/samples/openapi3/client/petstore/python/tests/test_model.py index f65d62745080..3a0502e4ed8e 100644 --- a/samples/openapi3/client/petstore/python/tests/test_model.py +++ b/samples/openapi3/client/petstore/python/tests/test_model.py @@ -629,6 +629,13 @@ def test_allof_circular_imports(self): self.assertEqual(model_a.to_json(), '{"_name": "nameA", "second_circular_all_of_ref": {"name": "nameB"}}') self.assertEqual(model_b.to_json(), '{"_name": "nameB", "circular_all_of_ref": {"name": "nameA"}}') + def test_allof_discriminator_mapping(self): + # for issue 18498 + user_info_json = '{"_typeName": "Info", "val": {"_typeName": "string", "_value": "some string"}}' + user_info = petstore_api.models.Info.from_json(user_info_json) + # shouldn't throw ValueError("BaseDiscriminator failed to lookup discriminator value...") + assert user_info is not None + self.assertEqual(user_info.to_json(), user_info_json) class TestdditionalPropertiesAnyType(unittest.TestCase): def test_additional_properties(self):