From 7b3de8dbce5d8bb611e036c7bb54db09f2f7eede Mon Sep 17 00:00:00 2001 From: William Cheng Date: Tue, 9 Sep 2025 09:21:09 +0800 Subject: [PATCH] [python] fix default value when enum is a reference (#21923) * fix default value when enum is ref (python) * update spec --- .../python-pydantic-v1/model_generic.mustache | 2 +- .../resources/python/model_generic.mustache | 2 +- ...ith-fake-endpoints-models-for-testing.yaml | 9 ++ .../python-aiohttp/.openapi-generator/FILES | 4 + .../client/petstore/python-aiohttp/README.md | 2 + .../python-aiohttp/docs/DataOutputFormat.md | 14 +++ .../docs/EnumRefWithDefaultValue.md | 29 +++++ .../python-aiohttp/petstore_api/__init__.py | 6 ++ .../petstore_api/models/__init__.py | 4 + .../petstore_api/models/data_output_format.py | 38 +++++++ .../models/enum_ref_with_default_value.py | 88 +++++++++++++++ .../test/test_data_output_format.py | 33 ++++++ .../test/test_enum_ref_with_default_value.py | 51 +++++++++ .../.openapi-generator/FILES | 4 + .../python-pydantic-v1-aiohttp/README.md | 2 + .../docs/DataOutputFormat.md | 14 +++ .../docs/EnumRefWithDefaultValue.md | 28 +++++ .../petstore_api/__init__.py | 4 + .../petstore_api/models/__init__.py | 2 + .../petstore_api/models/data_output_format.py | 41 +++++++ .../models/enum_ref_with_default_value.py | 72 +++++++++++++ .../test/test_data_output_format.py | 34 ++++++ .../test/test_enum_ref_with_default_value.py | 52 +++++++++ .../.openapi-generator/FILES | 4 + .../petstore/python-pydantic-v1/README.md | 2 + .../docs/DataOutputFormat.md | 14 +++ .../docs/EnumRefWithDefaultValue.md | 28 +++++ .../petstore_api/__init__.py | 4 + .../petstore_api/models/__init__.py | 2 + .../petstore_api/models/data_output_format.py | 41 +++++++ .../models/enum_ref_with_default_value.py | 84 +++++++++++++++ .../test/test_data_output_format.py | 34 ++++++ .../test/test_enum_ref_with_default_value.py | 52 +++++++++ .../petstore/python/.openapi-generator/FILES | 4 + .../openapi3/client/petstore/python/README.md | 2 + .../petstore/python/docs/DataOutputFormat.md | 14 +++ .../python/docs/EnumRefWithDefaultValue.md | 29 +++++ .../petstore/python/petstore_api/__init__.py | 6 ++ .../python/petstore_api/models/__init__.py | 4 + .../petstore_api/models/data_output_format.py | 38 +++++++ .../models/enum_ref_with_default_value.py | 101 ++++++++++++++++++ .../python/test/test_data_output_format.py | 33 ++++++ .../test/test_enum_ref_with_default_value.py | 51 +++++++++ 43 files changed, 1080 insertions(+), 2 deletions(-) create mode 100644 samples/openapi3/client/petstore/python-aiohttp/docs/DataOutputFormat.md create mode 100644 samples/openapi3/client/petstore/python-aiohttp/docs/EnumRefWithDefaultValue.md create mode 100644 samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/data_output_format.py create mode 100644 samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_ref_with_default_value.py create mode 100644 samples/openapi3/client/petstore/python-aiohttp/test/test_data_output_format.py create mode 100644 samples/openapi3/client/petstore/python-aiohttp/test/test_enum_ref_with_default_value.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/DataOutputFormat.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/EnumRefWithDefaultValue.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/data_output_format.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/enum_ref_with_default_value.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_data_output_format.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_enum_ref_with_default_value.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/docs/DataOutputFormat.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/docs/EnumRefWithDefaultValue.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/data_output_format.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/enum_ref_with_default_value.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/test/test_data_output_format.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/test/test_enum_ref_with_default_value.py create mode 100644 samples/openapi3/client/petstore/python/docs/DataOutputFormat.md create mode 100644 samples/openapi3/client/petstore/python/docs/EnumRefWithDefaultValue.md create mode 100644 samples/openapi3/client/petstore/python/petstore_api/models/data_output_format.py create mode 100644 samples/openapi3/client/petstore/python/petstore_api/models/enum_ref_with_default_value.py create mode 100644 samples/openapi3/client/petstore/python/test/test_data_output_format.py create mode 100644 samples/openapi3/client/petstore/python/test/test_enum_ref_with_default_value.py 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 5422b0790d0f..e9ed69317f5f 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 @@ -343,7 +343,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} "{{{name}}}": {{{dataType}}}.from_dict(obj.get("{{{baseName}}}")) if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}} {{/isEnumOrRef}} {{#isEnumOrRef}} - "{{{name}}}": obj.get("{{{baseName}}}"){{#defaultValue}} if obj.get("{{baseName}}") is not None else {{defaultValue}}{{/defaultValue}}{{^-last}},{{/-last}} + "{{{name}}}": obj.get("{{{baseName}}}"){{#defaultValue}} if obj.get("{{baseName}}") is not None else {{{defaultValue}}}{{/defaultValue}}{{^-last}},{{/-last}} {{/isEnumOrRef}} {{/isPrimitiveType}} {{#isPrimitiveType}} 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 9fa35c84fab4..70804d448de0 100644 --- a/modules/openapi-generator/src/main/resources/python/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_generic.mustache @@ -370,7 +370,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} "{{{baseName}}}": {{{dataType}}}.from_dict(obj["{{{baseName}}}"]) if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}} {{/isEnumOrRef}} {{#isEnumOrRef}} - "{{{baseName}}}": obj.get("{{{baseName}}}"){{#defaultValue}} if obj.get("{{baseName}}") is not None else {{defaultValue}}{{/defaultValue}}{{^-last}},{{/-last}} + "{{{baseName}}}": obj.get("{{{baseName}}}"){{#defaultValue}} if obj.get("{{baseName}}") is not None else {{{defaultValue}}}{{/defaultValue}}{{^-last}},{{/-last}} {{/isEnumOrRef}} {{/isPrimitiveType}} {{#isPrimitiveType}} 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 e1c1388f3df7..6b2b56b0daf7 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 @@ -2910,3 +2910,12 @@ components: - 1.0 - 0.5 - 0.25 + EnumRefWithDefaultValue: + type: object + properties: + report_format: + $ref: '#/components/schemas/DataOutputFormat' + DataOutputFormat: + type: string + enum: [JSON, CSV, XML] + default: JSON diff --git a/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES index 97c491419a4c..6cbba41b5b1b 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES @@ -31,6 +31,7 @@ docs/Color.md docs/Creature.md docs/CreatureInfo.md docs/DanishPig.md +docs/DataOutputFormat.md docs/DefaultApi.md docs/DeprecatedObject.md docs/DiscriminatorAllOfSub.md @@ -40,6 +41,7 @@ docs/DummyModel.md docs/EnumArrays.md docs/EnumClass.md docs/EnumNumberVendorExt.md +docs/EnumRefWithDefaultValue.md docs/EnumString1.md docs/EnumString2.md docs/EnumStringVendorExt.md @@ -164,6 +166,7 @@ petstore_api/models/color.py petstore_api/models/creature.py petstore_api/models/creature_info.py petstore_api/models/danish_pig.py +petstore_api/models/data_output_format.py petstore_api/models/deprecated_object.py petstore_api/models/discriminator_all_of_sub.py petstore_api/models/discriminator_all_of_super.py @@ -172,6 +175,7 @@ petstore_api/models/dummy_model.py petstore_api/models/enum_arrays.py petstore_api/models/enum_class.py petstore_api/models/enum_number_vendor_ext.py +petstore_api/models/enum_ref_with_default_value.py petstore_api/models/enum_string1.py petstore_api/models/enum_string2.py petstore_api/models/enum_string_vendor_ext.py diff --git a/samples/openapi3/client/petstore/python-aiohttp/README.md b/samples/openapi3/client/petstore/python-aiohttp/README.md index 25de02e93863..311e6e4c2dfa 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/README.md +++ b/samples/openapi3/client/petstore/python-aiohttp/README.md @@ -178,6 +178,7 @@ Class | Method | HTTP request | Description - [Creature](docs/Creature.md) - [CreatureInfo](docs/CreatureInfo.md) - [DanishPig](docs/DanishPig.md) + - [DataOutputFormat](docs/DataOutputFormat.md) - [DeprecatedObject](docs/DeprecatedObject.md) - [DiscriminatorAllOfSub](docs/DiscriminatorAllOfSub.md) - [DiscriminatorAllOfSuper](docs/DiscriminatorAllOfSuper.md) @@ -186,6 +187,7 @@ Class | Method | HTTP request | Description - [EnumArrays](docs/EnumArrays.md) - [EnumClass](docs/EnumClass.md) - [EnumNumberVendorExt](docs/EnumNumberVendorExt.md) + - [EnumRefWithDefaultValue](docs/EnumRefWithDefaultValue.md) - [EnumString1](docs/EnumString1.md) - [EnumString2](docs/EnumString2.md) - [EnumStringVendorExt](docs/EnumStringVendorExt.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/DataOutputFormat.md b/samples/openapi3/client/petstore/python-aiohttp/docs/DataOutputFormat.md new file mode 100644 index 000000000000..d9df2a1cffdc --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/DataOutputFormat.md @@ -0,0 +1,14 @@ +# DataOutputFormat + + +## Enum + +* `JSON` (value: `'JSON'`) + +* `CSV` (value: `'CSV'`) + +* `XML` (value: `'XML'`) + +[[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/EnumRefWithDefaultValue.md b/samples/openapi3/client/petstore/python-aiohttp/docs/EnumRefWithDefaultValue.md new file mode 100644 index 000000000000..eeb0dc66969f --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/EnumRefWithDefaultValue.md @@ -0,0 +1,29 @@ +# EnumRefWithDefaultValue + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**report_format** | [**DataOutputFormat**](DataOutputFormat.md) | | [optional] [default to DataOutputFormat.JSON] + +## Example + +```python +from petstore_api.models.enum_ref_with_default_value import EnumRefWithDefaultValue + +# TODO update the JSON string below +json = "{}" +# create an instance of EnumRefWithDefaultValue from a JSON string +enum_ref_with_default_value_instance = EnumRefWithDefaultValue.from_json(json) +# print the JSON string representation of the object +print(EnumRefWithDefaultValue.to_json()) + +# convert the object into a dict +enum_ref_with_default_value_dict = enum_ref_with_default_value_instance.to_dict() +# create an instance of EnumRefWithDefaultValue from a dict +enum_ref_with_default_value_from_dict = EnumRefWithDefaultValue.from_dict(enum_ref_with_default_value_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 9ca83e0d223f..5fc37d488192 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/__init__.py @@ -63,6 +63,7 @@ __all__ = [ "Creature", "CreatureInfo", "DanishPig", + "DataOutputFormat", "DeprecatedObject", "DiscriminatorAllOfSub", "DiscriminatorAllOfSuper", @@ -71,6 +72,7 @@ __all__ = [ "EnumArrays", "EnumClass", "EnumNumberVendorExt", + "EnumRefWithDefaultValue", "EnumString1", "EnumString2", "EnumStringVendorExt", @@ -199,6 +201,7 @@ if __import__("typing").TYPE_CHECKING: from petstore_api.models.creature import Creature as Creature from petstore_api.models.creature_info import CreatureInfo as CreatureInfo from petstore_api.models.danish_pig import DanishPig as DanishPig + from petstore_api.models.data_output_format import DataOutputFormat as DataOutputFormat from petstore_api.models.deprecated_object import DeprecatedObject as DeprecatedObject from petstore_api.models.discriminator_all_of_sub import DiscriminatorAllOfSub as DiscriminatorAllOfSub from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSuper as DiscriminatorAllOfSuper @@ -207,6 +210,7 @@ if __import__("typing").TYPE_CHECKING: from petstore_api.models.enum_arrays import EnumArrays as EnumArrays from petstore_api.models.enum_class import EnumClass as EnumClass from petstore_api.models.enum_number_vendor_ext import EnumNumberVendorExt as EnumNumberVendorExt + from petstore_api.models.enum_ref_with_default_value import EnumRefWithDefaultValue as EnumRefWithDefaultValue from petstore_api.models.enum_string1 import EnumString1 as EnumString1 from petstore_api.models.enum_string2 import EnumString2 as EnumString2 from petstore_api.models.enum_string_vendor_ext import EnumStringVendorExt as EnumStringVendorExt @@ -341,6 +345,7 @@ from petstore_api.models.color import Color as Color from petstore_api.models.creature import Creature as Creature from petstore_api.models.creature_info import CreatureInfo as CreatureInfo from petstore_api.models.danish_pig import DanishPig as DanishPig +from petstore_api.models.data_output_format import DataOutputFormat as DataOutputFormat from petstore_api.models.deprecated_object import DeprecatedObject as DeprecatedObject from petstore_api.models.discriminator_all_of_sub import DiscriminatorAllOfSub as DiscriminatorAllOfSub from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSuper as DiscriminatorAllOfSuper @@ -349,6 +354,7 @@ from petstore_api.models.dummy_model import DummyModel as DummyModel from petstore_api.models.enum_arrays import EnumArrays as EnumArrays from petstore_api.models.enum_class import EnumClass as EnumClass from petstore_api.models.enum_number_vendor_ext import EnumNumberVendorExt as EnumNumberVendorExt +from petstore_api.models.enum_ref_with_default_value import EnumRefWithDefaultValue as EnumRefWithDefaultValue from petstore_api.models.enum_string1 import EnumString1 as EnumString1 from petstore_api.models.enum_string2 import EnumString2 as EnumString2 from petstore_api.models.enum_string_vendor_ext import EnumStringVendorExt as EnumStringVendorExt 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 4673bbecb038..68a0bf95df1e 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 @@ -42,6 +42,7 @@ if __import__("typing").TYPE_CHECKING: from petstore_api.models.creature import Creature from petstore_api.models.creature_info import CreatureInfo from petstore_api.models.danish_pig import DanishPig + from petstore_api.models.data_output_format import DataOutputFormat from petstore_api.models.deprecated_object import DeprecatedObject from petstore_api.models.discriminator_all_of_sub import DiscriminatorAllOfSub from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSuper @@ -50,6 +51,7 @@ if __import__("typing").TYPE_CHECKING: from petstore_api.models.enum_arrays import EnumArrays from petstore_api.models.enum_class import EnumClass from petstore_api.models.enum_number_vendor_ext import EnumNumberVendorExt + from petstore_api.models.enum_ref_with_default_value import EnumRefWithDefaultValue from petstore_api.models.enum_string1 import EnumString1 from petstore_api.models.enum_string2 import EnumString2 from petstore_api.models.enum_string_vendor_ext import EnumStringVendorExt @@ -160,6 +162,7 @@ from petstore_api.models.color import Color from petstore_api.models.creature import Creature from petstore_api.models.creature_info import CreatureInfo from petstore_api.models.danish_pig import DanishPig +from petstore_api.models.data_output_format import DataOutputFormat from petstore_api.models.deprecated_object import DeprecatedObject from petstore_api.models.discriminator_all_of_sub import DiscriminatorAllOfSub from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSuper @@ -168,6 +171,7 @@ from petstore_api.models.dummy_model import DummyModel from petstore_api.models.enum_arrays import EnumArrays from petstore_api.models.enum_class import EnumClass from petstore_api.models.enum_number_vendor_ext import EnumNumberVendorExt +from petstore_api.models.enum_ref_with_default_value import EnumRefWithDefaultValue from petstore_api.models.enum_string1 import EnumString1 from petstore_api.models.enum_string2 import EnumString2 from petstore_api.models.enum_string_vendor_ext import EnumStringVendorExt diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/data_output_format.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/data_output_format.py new file mode 100644 index 000000000000..ee3df76c5169 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/data_output_format.py @@ -0,0 +1,38 @@ +# 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 json +from enum import Enum +from typing_extensions import Self + + +class DataOutputFormat(str, Enum): + """ + DataOutputFormat + """ + + """ + allowed enum values + """ + JSON = 'JSON' + CSV = 'CSV' + XML = 'XML' + + @classmethod + def from_json(cls, json_str: str) -> Self: + """Create an instance of DataOutputFormat from a JSON string""" + return cls(json.loads(json_str)) + + diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_ref_with_default_value.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_ref_with_default_value.py new file mode 100644 index 000000000000..9d97e3fd16d4 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/enum_ref_with_default_value.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 pydantic import BaseModel, ConfigDict +from typing import Any, ClassVar, Dict, List, Optional +from petstore_api.models.data_output_format import DataOutputFormat +from typing import Optional, Set +from typing_extensions import Self + +class EnumRefWithDefaultValue(BaseModel): + """ + EnumRefWithDefaultValue + """ # noqa: E501 + report_format: Optional[DataOutputFormat] = DataOutputFormat.JSON + __properties: ClassVar[List[str]] = ["report_format"] + + 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 EnumRefWithDefaultValue 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 EnumRefWithDefaultValue from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "report_format": obj.get("report_format") if obj.get("report_format") is not None else DataOutputFormat.JSON + }) + return _obj + + diff --git a/samples/openapi3/client/petstore/python-aiohttp/test/test_data_output_format.py b/samples/openapi3/client/petstore/python-aiohttp/test/test_data_output_format.py new file mode 100644 index 000000000000..99ff73179204 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/test/test_data_output_format.py @@ -0,0 +1,33 @@ +# 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.data_output_format import DataOutputFormat + +class TestDataOutputFormat(unittest.TestCase): + """DataOutputFormat unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testDataOutputFormat(self): + """Test DataOutputFormat""" + # inst = DataOutputFormat() + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-aiohttp/test/test_enum_ref_with_default_value.py b/samples/openapi3/client/petstore/python-aiohttp/test/test_enum_ref_with_default_value.py new file mode 100644 index 000000000000..839d9583998d --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/test/test_enum_ref_with_default_value.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.enum_ref_with_default_value import EnumRefWithDefaultValue + +class TestEnumRefWithDefaultValue(unittest.TestCase): + """EnumRefWithDefaultValue unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> EnumRefWithDefaultValue: + """Test EnumRefWithDefaultValue + include_optional 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 `EnumRefWithDefaultValue` + """ + model = EnumRefWithDefaultValue() + if include_optional: + return EnumRefWithDefaultValue( + report_format = 'JSON' + ) + else: + return EnumRefWithDefaultValue( + ) + """ + + def testEnumRefWithDefaultValue(self): + """Test EnumRefWithDefaultValue""" + # 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 8fcd0acf7a1d..b531da364d10 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 @@ -32,6 +32,7 @@ docs/Color.md docs/Creature.md docs/CreatureInfo.md docs/DanishPig.md +docs/DataOutputFormat.md docs/DefaultApi.md docs/DeprecatedObject.md docs/DiscriminatorAllOfSub.md @@ -41,6 +42,7 @@ docs/DummyModel.md docs/EnumArrays.md docs/EnumClass.md docs/EnumNumberVendorExt.md +docs/EnumRefWithDefaultValue.md docs/EnumString1.md docs/EnumString2.md docs/EnumStringVendorExt.md @@ -165,6 +167,7 @@ petstore_api/models/color.py petstore_api/models/creature.py petstore_api/models/creature_info.py petstore_api/models/danish_pig.py +petstore_api/models/data_output_format.py petstore_api/models/deprecated_object.py petstore_api/models/discriminator_all_of_sub.py petstore_api/models/discriminator_all_of_super.py @@ -173,6 +176,7 @@ petstore_api/models/dummy_model.py petstore_api/models/enum_arrays.py petstore_api/models/enum_class.py petstore_api/models/enum_number_vendor_ext.py +petstore_api/models/enum_ref_with_default_value.py petstore_api/models/enum_string1.py petstore_api/models/enum_string2.py petstore_api/models/enum_string_vendor_ext.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 5d36b55332e1..3f3e2a8eea5c 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/README.md +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/README.md @@ -180,6 +180,7 @@ Class | Method | HTTP request | Description - [Creature](docs/Creature.md) - [CreatureInfo](docs/CreatureInfo.md) - [DanishPig](docs/DanishPig.md) + - [DataOutputFormat](docs/DataOutputFormat.md) - [DeprecatedObject](docs/DeprecatedObject.md) - [DiscriminatorAllOfSub](docs/DiscriminatorAllOfSub.md) - [DiscriminatorAllOfSuper](docs/DiscriminatorAllOfSuper.md) @@ -188,6 +189,7 @@ Class | Method | HTTP request | Description - [EnumArrays](docs/EnumArrays.md) - [EnumClass](docs/EnumClass.md) - [EnumNumberVendorExt](docs/EnumNumberVendorExt.md) + - [EnumRefWithDefaultValue](docs/EnumRefWithDefaultValue.md) - [EnumString1](docs/EnumString1.md) - [EnumString2](docs/EnumString2.md) - [EnumStringVendorExt](docs/EnumStringVendorExt.md) diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/DataOutputFormat.md b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/DataOutputFormat.md new file mode 100644 index 000000000000..d9df2a1cffdc --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/DataOutputFormat.md @@ -0,0 +1,14 @@ +# DataOutputFormat + + +## Enum + +* `JSON` (value: `'JSON'`) + +* `CSV` (value: `'CSV'`) + +* `XML` (value: `'XML'`) + +[[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/EnumRefWithDefaultValue.md b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/EnumRefWithDefaultValue.md new file mode 100644 index 000000000000..31590fa6d407 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/EnumRefWithDefaultValue.md @@ -0,0 +1,28 @@ +# EnumRefWithDefaultValue + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**report_format** | [**DataOutputFormat**](DataOutputFormat.md) | | [optional] + +## Example + +```python +from petstore_api.models.enum_ref_with_default_value import EnumRefWithDefaultValue + +# TODO update the JSON string below +json = "{}" +# create an instance of EnumRefWithDefaultValue from a JSON string +enum_ref_with_default_value_instance = EnumRefWithDefaultValue.from_json(json) +# print the JSON string representation of the object +print EnumRefWithDefaultValue.to_json() + +# convert the object into a dict +enum_ref_with_default_value_dict = enum_ref_with_default_value_instance.to_dict() +# create an instance of EnumRefWithDefaultValue from a dict +enum_ref_with_default_value_from_dict = EnumRefWithDefaultValue.from_dict(enum_ref_with_default_value_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 343757e2f372..f72338bad1da 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 @@ -64,6 +64,7 @@ __all__ = [ "Creature", "CreatureInfo", "DanishPig", + "DataOutputFormat", "DeprecatedObject", "DiscriminatorAllOfSub", "DiscriminatorAllOfSuper", @@ -72,6 +73,7 @@ __all__ = [ "EnumArrays", "EnumClass", "EnumNumberVendorExt", + "EnumRefWithDefaultValue", "EnumString1", "EnumString2", "EnumStringVendorExt", @@ -199,6 +201,7 @@ from petstore_api.models.color import Color as Color from petstore_api.models.creature import Creature as Creature from petstore_api.models.creature_info import CreatureInfo as CreatureInfo from petstore_api.models.danish_pig import DanishPig as DanishPig +from petstore_api.models.data_output_format import DataOutputFormat as DataOutputFormat from petstore_api.models.deprecated_object import DeprecatedObject as DeprecatedObject from petstore_api.models.discriminator_all_of_sub import DiscriminatorAllOfSub as DiscriminatorAllOfSub from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSuper as DiscriminatorAllOfSuper @@ -207,6 +210,7 @@ from petstore_api.models.dummy_model import DummyModel as DummyModel from petstore_api.models.enum_arrays import EnumArrays as EnumArrays from petstore_api.models.enum_class import EnumClass as EnumClass from petstore_api.models.enum_number_vendor_ext import EnumNumberVendorExt as EnumNumberVendorExt +from petstore_api.models.enum_ref_with_default_value import EnumRefWithDefaultValue as EnumRefWithDefaultValue from petstore_api.models.enum_string1 import EnumString1 as EnumString1 from petstore_api.models.enum_string2 import EnumString2 as EnumString2 from petstore_api.models.enum_string_vendor_ext import EnumStringVendorExt as EnumStringVendorExt 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 8244d7625958..6d809c201c18 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 @@ -42,6 +42,7 @@ from petstore_api.models.color import Color from petstore_api.models.creature import Creature from petstore_api.models.creature_info import CreatureInfo from petstore_api.models.danish_pig import DanishPig +from petstore_api.models.data_output_format import DataOutputFormat from petstore_api.models.deprecated_object import DeprecatedObject from petstore_api.models.discriminator_all_of_sub import DiscriminatorAllOfSub from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSuper @@ -50,6 +51,7 @@ from petstore_api.models.dummy_model import DummyModel from petstore_api.models.enum_arrays import EnumArrays from petstore_api.models.enum_class import EnumClass from petstore_api.models.enum_number_vendor_ext import EnumNumberVendorExt +from petstore_api.models.enum_ref_with_default_value import EnumRefWithDefaultValue from petstore_api.models.enum_string1 import EnumString1 from petstore_api.models.enum_string2 import EnumString2 from petstore_api.models.enum_string_vendor_ext import EnumStringVendorExt diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/data_output_format.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/data_output_format.py new file mode 100644 index 000000000000..0420095483e7 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/data_output_format.py @@ -0,0 +1,41 @@ +# 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 json +import pprint +import re # noqa: F401 +from aenum import Enum, no_arg + + + + + +class DataOutputFormat(str, Enum): + """ + DataOutputFormat + """ + + """ + allowed enum values + """ + JSON = 'JSON' + CSV = 'CSV' + XML = 'XML' + + @classmethod + def from_json(cls, json_str: str) -> DataOutputFormat: + """Create an instance of DataOutputFormat from a JSON string""" + return DataOutputFormat(json.loads(json_str)) + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/enum_ref_with_default_value.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/enum_ref_with_default_value.py new file mode 100644 index 000000000000..65bb0365e1aa --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/enum_ref_with_default_value.py @@ -0,0 +1,72 @@ +# 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 BaseModel +from petstore_api.models.data_output_format import DataOutputFormat + +class EnumRefWithDefaultValue(BaseModel): + """ + EnumRefWithDefaultValue + """ + report_format: Optional[DataOutputFormat] = None + __properties = ["report_format"] + + 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) -> EnumRefWithDefaultValue: + """Create an instance of EnumRefWithDefaultValue 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) -> EnumRefWithDefaultValue: + """Create an instance of EnumRefWithDefaultValue from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return EnumRefWithDefaultValue.parse_obj(obj) + + _obj = EnumRefWithDefaultValue.parse_obj({ + "report_format": obj.get("report_format") + }) + return _obj + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_data_output_format.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_data_output_format.py new file mode 100644 index 000000000000..297d40716d1f --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_data_output_format.py @@ -0,0 +1,34 @@ +# 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.data_output_format import DataOutputFormat # noqa: E501 + +class TestDataOutputFormat(unittest.TestCase): + """DataOutputFormat unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testDataOutputFormat(self): + """Test DataOutputFormat""" + # inst = DataOutputFormat() + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_enum_ref_with_default_value.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_enum_ref_with_default_value.py new file mode 100644 index 000000000000..e9771481d4eb --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_enum_ref_with_default_value.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.enum_ref_with_default_value import EnumRefWithDefaultValue # noqa: E501 + +class TestEnumRefWithDefaultValue(unittest.TestCase): + """EnumRefWithDefaultValue unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> EnumRefWithDefaultValue: + """Test EnumRefWithDefaultValue + 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 `EnumRefWithDefaultValue` + """ + model = EnumRefWithDefaultValue() # noqa: E501 + if include_optional: + return EnumRefWithDefaultValue( + report_format = 'JSON' + ) + else: + return EnumRefWithDefaultValue( + ) + """ + + def testEnumRefWithDefaultValue(self): + """Test EnumRefWithDefaultValue""" + # 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 8fcd0acf7a1d..b531da364d10 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-pydantic-v1/.openapi-generator/FILES @@ -32,6 +32,7 @@ docs/Color.md docs/Creature.md docs/CreatureInfo.md docs/DanishPig.md +docs/DataOutputFormat.md docs/DefaultApi.md docs/DeprecatedObject.md docs/DiscriminatorAllOfSub.md @@ -41,6 +42,7 @@ docs/DummyModel.md docs/EnumArrays.md docs/EnumClass.md docs/EnumNumberVendorExt.md +docs/EnumRefWithDefaultValue.md docs/EnumString1.md docs/EnumString2.md docs/EnumStringVendorExt.md @@ -165,6 +167,7 @@ petstore_api/models/color.py petstore_api/models/creature.py petstore_api/models/creature_info.py petstore_api/models/danish_pig.py +petstore_api/models/data_output_format.py petstore_api/models/deprecated_object.py petstore_api/models/discriminator_all_of_sub.py petstore_api/models/discriminator_all_of_super.py @@ -173,6 +176,7 @@ petstore_api/models/dummy_model.py petstore_api/models/enum_arrays.py petstore_api/models/enum_class.py petstore_api/models/enum_number_vendor_ext.py +petstore_api/models/enum_ref_with_default_value.py petstore_api/models/enum_string1.py petstore_api/models/enum_string2.py petstore_api/models/enum_string_vendor_ext.py diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/README.md b/samples/openapi3/client/petstore/python-pydantic-v1/README.md index d1f49d9e6cb8..9186dab605c7 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/README.md +++ b/samples/openapi3/client/petstore/python-pydantic-v1/README.md @@ -180,6 +180,7 @@ Class | Method | HTTP request | Description - [Creature](docs/Creature.md) - [CreatureInfo](docs/CreatureInfo.md) - [DanishPig](docs/DanishPig.md) + - [DataOutputFormat](docs/DataOutputFormat.md) - [DeprecatedObject](docs/DeprecatedObject.md) - [DiscriminatorAllOfSub](docs/DiscriminatorAllOfSub.md) - [DiscriminatorAllOfSuper](docs/DiscriminatorAllOfSuper.md) @@ -188,6 +189,7 @@ Class | Method | HTTP request | Description - [EnumArrays](docs/EnumArrays.md) - [EnumClass](docs/EnumClass.md) - [EnumNumberVendorExt](docs/EnumNumberVendorExt.md) + - [EnumRefWithDefaultValue](docs/EnumRefWithDefaultValue.md) - [EnumString1](docs/EnumString1.md) - [EnumString2](docs/EnumString2.md) - [EnumStringVendorExt](docs/EnumStringVendorExt.md) diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/docs/DataOutputFormat.md b/samples/openapi3/client/petstore/python-pydantic-v1/docs/DataOutputFormat.md new file mode 100644 index 000000000000..d9df2a1cffdc --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/docs/DataOutputFormat.md @@ -0,0 +1,14 @@ +# DataOutputFormat + + +## Enum + +* `JSON` (value: `'JSON'`) + +* `CSV` (value: `'CSV'`) + +* `XML` (value: `'XML'`) + +[[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/EnumRefWithDefaultValue.md b/samples/openapi3/client/petstore/python-pydantic-v1/docs/EnumRefWithDefaultValue.md new file mode 100644 index 000000000000..31590fa6d407 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/docs/EnumRefWithDefaultValue.md @@ -0,0 +1,28 @@ +# EnumRefWithDefaultValue + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**report_format** | [**DataOutputFormat**](DataOutputFormat.md) | | [optional] + +## Example + +```python +from petstore_api.models.enum_ref_with_default_value import EnumRefWithDefaultValue + +# TODO update the JSON string below +json = "{}" +# create an instance of EnumRefWithDefaultValue from a JSON string +enum_ref_with_default_value_instance = EnumRefWithDefaultValue.from_json(json) +# print the JSON string representation of the object +print EnumRefWithDefaultValue.to_json() + +# convert the object into a dict +enum_ref_with_default_value_dict = enum_ref_with_default_value_instance.to_dict() +# create an instance of EnumRefWithDefaultValue from a dict +enum_ref_with_default_value_from_dict = EnumRefWithDefaultValue.from_dict(enum_ref_with_default_value_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 343757e2f372..f72338bad1da 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 @@ -64,6 +64,7 @@ __all__ = [ "Creature", "CreatureInfo", "DanishPig", + "DataOutputFormat", "DeprecatedObject", "DiscriminatorAllOfSub", "DiscriminatorAllOfSuper", @@ -72,6 +73,7 @@ __all__ = [ "EnumArrays", "EnumClass", "EnumNumberVendorExt", + "EnumRefWithDefaultValue", "EnumString1", "EnumString2", "EnumStringVendorExt", @@ -199,6 +201,7 @@ from petstore_api.models.color import Color as Color from petstore_api.models.creature import Creature as Creature from petstore_api.models.creature_info import CreatureInfo as CreatureInfo from petstore_api.models.danish_pig import DanishPig as DanishPig +from petstore_api.models.data_output_format import DataOutputFormat as DataOutputFormat from petstore_api.models.deprecated_object import DeprecatedObject as DeprecatedObject from petstore_api.models.discriminator_all_of_sub import DiscriminatorAllOfSub as DiscriminatorAllOfSub from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSuper as DiscriminatorAllOfSuper @@ -207,6 +210,7 @@ from petstore_api.models.dummy_model import DummyModel as DummyModel from petstore_api.models.enum_arrays import EnumArrays as EnumArrays from petstore_api.models.enum_class import EnumClass as EnumClass from petstore_api.models.enum_number_vendor_ext import EnumNumberVendorExt as EnumNumberVendorExt +from petstore_api.models.enum_ref_with_default_value import EnumRefWithDefaultValue as EnumRefWithDefaultValue from petstore_api.models.enum_string1 import EnumString1 as EnumString1 from petstore_api.models.enum_string2 import EnumString2 as EnumString2 from petstore_api.models.enum_string_vendor_ext import EnumStringVendorExt as EnumStringVendorExt 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 8244d7625958..6d809c201c18 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 @@ -42,6 +42,7 @@ from petstore_api.models.color import Color from petstore_api.models.creature import Creature from petstore_api.models.creature_info import CreatureInfo from petstore_api.models.danish_pig import DanishPig +from petstore_api.models.data_output_format import DataOutputFormat from petstore_api.models.deprecated_object import DeprecatedObject from petstore_api.models.discriminator_all_of_sub import DiscriminatorAllOfSub from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSuper @@ -50,6 +51,7 @@ from petstore_api.models.dummy_model import DummyModel from petstore_api.models.enum_arrays import EnumArrays from petstore_api.models.enum_class import EnumClass from petstore_api.models.enum_number_vendor_ext import EnumNumberVendorExt +from petstore_api.models.enum_ref_with_default_value import EnumRefWithDefaultValue from petstore_api.models.enum_string1 import EnumString1 from petstore_api.models.enum_string2 import EnumString2 from petstore_api.models.enum_string_vendor_ext import EnumStringVendorExt diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/data_output_format.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/data_output_format.py new file mode 100644 index 000000000000..0420095483e7 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/data_output_format.py @@ -0,0 +1,41 @@ +# 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 json +import pprint +import re # noqa: F401 +from aenum import Enum, no_arg + + + + + +class DataOutputFormat(str, Enum): + """ + DataOutputFormat + """ + + """ + allowed enum values + """ + JSON = 'JSON' + CSV = 'CSV' + XML = 'XML' + + @classmethod + def from_json(cls, json_str: str) -> DataOutputFormat: + """Create an instance of DataOutputFormat from a JSON string""" + return DataOutputFormat(json.loads(json_str)) + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/enum_ref_with_default_value.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/enum_ref_with_default_value.py new file mode 100644 index 000000000000..f40852f5bbd3 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/enum_ref_with_default_value.py @@ -0,0 +1,84 @@ +# 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 BaseModel +from petstore_api.models.data_output_format import DataOutputFormat + +class EnumRefWithDefaultValue(BaseModel): + """ + EnumRefWithDefaultValue + """ + report_format: Optional[DataOutputFormat] = None + additional_properties: Dict[str, Any] = {} + __properties = ["report_format"] + + 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) -> EnumRefWithDefaultValue: + """Create an instance of EnumRefWithDefaultValue 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) -> EnumRefWithDefaultValue: + """Create an instance of EnumRefWithDefaultValue from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return EnumRefWithDefaultValue.parse_obj(obj) + + _obj = EnumRefWithDefaultValue.parse_obj({ + "report_format": obj.get("report_format") + }) + # 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_data_output_format.py b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_data_output_format.py new file mode 100644 index 000000000000..297d40716d1f --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_data_output_format.py @@ -0,0 +1,34 @@ +# 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.data_output_format import DataOutputFormat # noqa: E501 + +class TestDataOutputFormat(unittest.TestCase): + """DataOutputFormat unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testDataOutputFormat(self): + """Test DataOutputFormat""" + # inst = DataOutputFormat() + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/test/test_enum_ref_with_default_value.py b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_enum_ref_with_default_value.py new file mode 100644 index 000000000000..e9771481d4eb --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_enum_ref_with_default_value.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.enum_ref_with_default_value import EnumRefWithDefaultValue # noqa: E501 + +class TestEnumRefWithDefaultValue(unittest.TestCase): + """EnumRefWithDefaultValue unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> EnumRefWithDefaultValue: + """Test EnumRefWithDefaultValue + 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 `EnumRefWithDefaultValue` + """ + model = EnumRefWithDefaultValue() # noqa: E501 + if include_optional: + return EnumRefWithDefaultValue( + report_format = 'JSON' + ) + else: + return EnumRefWithDefaultValue( + ) + """ + + def testEnumRefWithDefaultValue(self): + """Test EnumRefWithDefaultValue""" + # 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 97c491419a4c..6cbba41b5b1b 100755 --- a/samples/openapi3/client/petstore/python/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python/.openapi-generator/FILES @@ -31,6 +31,7 @@ docs/Color.md docs/Creature.md docs/CreatureInfo.md docs/DanishPig.md +docs/DataOutputFormat.md docs/DefaultApi.md docs/DeprecatedObject.md docs/DiscriminatorAllOfSub.md @@ -40,6 +41,7 @@ docs/DummyModel.md docs/EnumArrays.md docs/EnumClass.md docs/EnumNumberVendorExt.md +docs/EnumRefWithDefaultValue.md docs/EnumString1.md docs/EnumString2.md docs/EnumStringVendorExt.md @@ -164,6 +166,7 @@ petstore_api/models/color.py petstore_api/models/creature.py petstore_api/models/creature_info.py petstore_api/models/danish_pig.py +petstore_api/models/data_output_format.py petstore_api/models/deprecated_object.py petstore_api/models/discriminator_all_of_sub.py petstore_api/models/discriminator_all_of_super.py @@ -172,6 +175,7 @@ petstore_api/models/dummy_model.py petstore_api/models/enum_arrays.py petstore_api/models/enum_class.py petstore_api/models/enum_number_vendor_ext.py +petstore_api/models/enum_ref_with_default_value.py petstore_api/models/enum_string1.py petstore_api/models/enum_string2.py petstore_api/models/enum_string_vendor_ext.py diff --git a/samples/openapi3/client/petstore/python/README.md b/samples/openapi3/client/petstore/python/README.md index f0186ef2df59..47517933af16 100755 --- a/samples/openapi3/client/petstore/python/README.md +++ b/samples/openapi3/client/petstore/python/README.md @@ -178,6 +178,7 @@ Class | Method | HTTP request | Description - [Creature](docs/Creature.md) - [CreatureInfo](docs/CreatureInfo.md) - [DanishPig](docs/DanishPig.md) + - [DataOutputFormat](docs/DataOutputFormat.md) - [DeprecatedObject](docs/DeprecatedObject.md) - [DiscriminatorAllOfSub](docs/DiscriminatorAllOfSub.md) - [DiscriminatorAllOfSuper](docs/DiscriminatorAllOfSuper.md) @@ -186,6 +187,7 @@ Class | Method | HTTP request | Description - [EnumArrays](docs/EnumArrays.md) - [EnumClass](docs/EnumClass.md) - [EnumNumberVendorExt](docs/EnumNumberVendorExt.md) + - [EnumRefWithDefaultValue](docs/EnumRefWithDefaultValue.md) - [EnumString1](docs/EnumString1.md) - [EnumString2](docs/EnumString2.md) - [EnumStringVendorExt](docs/EnumStringVendorExt.md) diff --git a/samples/openapi3/client/petstore/python/docs/DataOutputFormat.md b/samples/openapi3/client/petstore/python/docs/DataOutputFormat.md new file mode 100644 index 000000000000..d9df2a1cffdc --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/DataOutputFormat.md @@ -0,0 +1,14 @@ +# DataOutputFormat + + +## Enum + +* `JSON` (value: `'JSON'`) + +* `CSV` (value: `'CSV'`) + +* `XML` (value: `'XML'`) + +[[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/EnumRefWithDefaultValue.md b/samples/openapi3/client/petstore/python/docs/EnumRefWithDefaultValue.md new file mode 100644 index 000000000000..eeb0dc66969f --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/EnumRefWithDefaultValue.md @@ -0,0 +1,29 @@ +# EnumRefWithDefaultValue + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**report_format** | [**DataOutputFormat**](DataOutputFormat.md) | | [optional] [default to DataOutputFormat.JSON] + +## Example + +```python +from petstore_api.models.enum_ref_with_default_value import EnumRefWithDefaultValue + +# TODO update the JSON string below +json = "{}" +# create an instance of EnumRefWithDefaultValue from a JSON string +enum_ref_with_default_value_instance = EnumRefWithDefaultValue.from_json(json) +# print the JSON string representation of the object +print(EnumRefWithDefaultValue.to_json()) + +# convert the object into a dict +enum_ref_with_default_value_dict = enum_ref_with_default_value_instance.to_dict() +# create an instance of EnumRefWithDefaultValue from a dict +enum_ref_with_default_value_from_dict = EnumRefWithDefaultValue.from_dict(enum_ref_with_default_value_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 9ca83e0d223f..5fc37d488192 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/__init__.py @@ -63,6 +63,7 @@ __all__ = [ "Creature", "CreatureInfo", "DanishPig", + "DataOutputFormat", "DeprecatedObject", "DiscriminatorAllOfSub", "DiscriminatorAllOfSuper", @@ -71,6 +72,7 @@ __all__ = [ "EnumArrays", "EnumClass", "EnumNumberVendorExt", + "EnumRefWithDefaultValue", "EnumString1", "EnumString2", "EnumStringVendorExt", @@ -199,6 +201,7 @@ if __import__("typing").TYPE_CHECKING: from petstore_api.models.creature import Creature as Creature from petstore_api.models.creature_info import CreatureInfo as CreatureInfo from petstore_api.models.danish_pig import DanishPig as DanishPig + from petstore_api.models.data_output_format import DataOutputFormat as DataOutputFormat from petstore_api.models.deprecated_object import DeprecatedObject as DeprecatedObject from petstore_api.models.discriminator_all_of_sub import DiscriminatorAllOfSub as DiscriminatorAllOfSub from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSuper as DiscriminatorAllOfSuper @@ -207,6 +210,7 @@ if __import__("typing").TYPE_CHECKING: from petstore_api.models.enum_arrays import EnumArrays as EnumArrays from petstore_api.models.enum_class import EnumClass as EnumClass from petstore_api.models.enum_number_vendor_ext import EnumNumberVendorExt as EnumNumberVendorExt + from petstore_api.models.enum_ref_with_default_value import EnumRefWithDefaultValue as EnumRefWithDefaultValue from petstore_api.models.enum_string1 import EnumString1 as EnumString1 from petstore_api.models.enum_string2 import EnumString2 as EnumString2 from petstore_api.models.enum_string_vendor_ext import EnumStringVendorExt as EnumStringVendorExt @@ -341,6 +345,7 @@ from petstore_api.models.color import Color as Color from petstore_api.models.creature import Creature as Creature from petstore_api.models.creature_info import CreatureInfo as CreatureInfo from petstore_api.models.danish_pig import DanishPig as DanishPig +from petstore_api.models.data_output_format import DataOutputFormat as DataOutputFormat from petstore_api.models.deprecated_object import DeprecatedObject as DeprecatedObject from petstore_api.models.discriminator_all_of_sub import DiscriminatorAllOfSub as DiscriminatorAllOfSub from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSuper as DiscriminatorAllOfSuper @@ -349,6 +354,7 @@ from petstore_api.models.dummy_model import DummyModel as DummyModel from petstore_api.models.enum_arrays import EnumArrays as EnumArrays from petstore_api.models.enum_class import EnumClass as EnumClass from petstore_api.models.enum_number_vendor_ext import EnumNumberVendorExt as EnumNumberVendorExt +from petstore_api.models.enum_ref_with_default_value import EnumRefWithDefaultValue as EnumRefWithDefaultValue from petstore_api.models.enum_string1 import EnumString1 as EnumString1 from petstore_api.models.enum_string2 import EnumString2 as EnumString2 from petstore_api.models.enum_string_vendor_ext import EnumStringVendorExt as EnumStringVendorExt 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 4673bbecb038..68a0bf95df1e 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py @@ -42,6 +42,7 @@ if __import__("typing").TYPE_CHECKING: from petstore_api.models.creature import Creature from petstore_api.models.creature_info import CreatureInfo from petstore_api.models.danish_pig import DanishPig + from petstore_api.models.data_output_format import DataOutputFormat from petstore_api.models.deprecated_object import DeprecatedObject from petstore_api.models.discriminator_all_of_sub import DiscriminatorAllOfSub from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSuper @@ -50,6 +51,7 @@ if __import__("typing").TYPE_CHECKING: from petstore_api.models.enum_arrays import EnumArrays from petstore_api.models.enum_class import EnumClass from petstore_api.models.enum_number_vendor_ext import EnumNumberVendorExt + from petstore_api.models.enum_ref_with_default_value import EnumRefWithDefaultValue from petstore_api.models.enum_string1 import EnumString1 from petstore_api.models.enum_string2 import EnumString2 from petstore_api.models.enum_string_vendor_ext import EnumStringVendorExt @@ -160,6 +162,7 @@ from petstore_api.models.color import Color from petstore_api.models.creature import Creature from petstore_api.models.creature_info import CreatureInfo from petstore_api.models.danish_pig import DanishPig +from petstore_api.models.data_output_format import DataOutputFormat from petstore_api.models.deprecated_object import DeprecatedObject from petstore_api.models.discriminator_all_of_sub import DiscriminatorAllOfSub from petstore_api.models.discriminator_all_of_super import DiscriminatorAllOfSuper @@ -168,6 +171,7 @@ from petstore_api.models.dummy_model import DummyModel from petstore_api.models.enum_arrays import EnumArrays from petstore_api.models.enum_class import EnumClass from petstore_api.models.enum_number_vendor_ext import EnumNumberVendorExt +from petstore_api.models.enum_ref_with_default_value import EnumRefWithDefaultValue from petstore_api.models.enum_string1 import EnumString1 from petstore_api.models.enum_string2 import EnumString2 from petstore_api.models.enum_string_vendor_ext import EnumStringVendorExt diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/data_output_format.py b/samples/openapi3/client/petstore/python/petstore_api/models/data_output_format.py new file mode 100644 index 000000000000..ee3df76c5169 --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/models/data_output_format.py @@ -0,0 +1,38 @@ +# 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 json +from enum import Enum +from typing_extensions import Self + + +class DataOutputFormat(str, Enum): + """ + DataOutputFormat + """ + + """ + allowed enum values + """ + JSON = 'JSON' + CSV = 'CSV' + XML = 'XML' + + @classmethod + def from_json(cls, json_str: str) -> Self: + """Create an instance of DataOutputFormat from a JSON string""" + return cls(json.loads(json_str)) + + diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/enum_ref_with_default_value.py b/samples/openapi3/client/petstore/python/petstore_api/models/enum_ref_with_default_value.py new file mode 100644 index 000000000000..d864e80d0a73 --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/models/enum_ref_with_default_value.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 pydantic import BaseModel, ConfigDict +from typing import Any, ClassVar, Dict, List, Optional +from petstore_api.models.data_output_format import DataOutputFormat +from typing import Optional, Set +from typing_extensions import Self + +class EnumRefWithDefaultValue(BaseModel): + """ + EnumRefWithDefaultValue + """ # noqa: E501 + report_format: Optional[DataOutputFormat] = DataOutputFormat.JSON + additional_properties: Dict[str, Any] = {} + __properties: ClassVar[List[str]] = ["report_format"] + + 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 EnumRefWithDefaultValue 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 EnumRefWithDefaultValue from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "report_format": obj.get("report_format") if obj.get("report_format") is not None else DataOutputFormat.JSON + }) + # 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_data_output_format.py b/samples/openapi3/client/petstore/python/test/test_data_output_format.py new file mode 100644 index 000000000000..99ff73179204 --- /dev/null +++ b/samples/openapi3/client/petstore/python/test/test_data_output_format.py @@ -0,0 +1,33 @@ +# 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.data_output_format import DataOutputFormat + +class TestDataOutputFormat(unittest.TestCase): + """DataOutputFormat unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testDataOutputFormat(self): + """Test DataOutputFormat""" + # inst = DataOutputFormat() + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python/test/test_enum_ref_with_default_value.py b/samples/openapi3/client/petstore/python/test/test_enum_ref_with_default_value.py new file mode 100644 index 000000000000..839d9583998d --- /dev/null +++ b/samples/openapi3/client/petstore/python/test/test_enum_ref_with_default_value.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.enum_ref_with_default_value import EnumRefWithDefaultValue + +class TestEnumRefWithDefaultValue(unittest.TestCase): + """EnumRefWithDefaultValue unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> EnumRefWithDefaultValue: + """Test EnumRefWithDefaultValue + include_optional 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 `EnumRefWithDefaultValue` + """ + model = EnumRefWithDefaultValue() + if include_optional: + return EnumRefWithDefaultValue( + report_format = 'JSON' + ) + else: + return EnumRefWithDefaultValue( + ) + """ + + def testEnumRefWithDefaultValue(self): + """Test EnumRefWithDefaultValue""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main()