From 09d8d0c6870f27fa060d8189250769595c5f3a40 Mon Sep 17 00:00:00 2001 From: CatBraaain <84499939+CatBraaain@users.noreply.github.com> Date: Wed, 6 Aug 2025 18:10:36 +0900 Subject: [PATCH] fix(python): support default values for array/map field --- .../languages/AbstractPythonCodegen.java | 9 +- ...ith-fake-endpoints-models-for-testing.yaml | 15 +++ .../openapi_client/models/default_value.py | 8 +- .../openapi_client/models/query.py | 2 +- .../openapi_client/models/default_value.py | 8 +- .../python/openapi_client/models/query.py | 2 +- .../python-aiohttp/.openapi-generator/FILES | 2 + .../client/petstore/python-aiohttp/README.md | 1 + .../docs/ModelWithArrayAndMapDefaults.md | 30 ++++++ .../docs/ModelWithArrayAndMapDefaultsMap.md | 30 ++++++ .../python-aiohttp/petstore_api/__init__.py | 3 + .../petstore_api/models/__init__.py | 2 + .../model_with_array_and_map_defaults.py | 89 +++++++++++++++ .../test_model_with_array_and_map_defaults.py | 56 ++++++++++ .../.openapi-generator/FILES | 2 + .../python-pydantic-v1-aiohttp/README.md | 1 + .../docs/ModelWithArrayAndMapDefaults.md | 29 +++++ .../docs/ModelWithArrayAndMapDefaultsMap.md | 29 +++++ .../petstore_api/__init__.py | 2 + .../petstore_api/models/__init__.py | 1 + .../model_with_array_and_map_defaults.py | 73 +++++++++++++ .../test_model_with_array_and_map_defaults.py | 57 ++++++++++ .../.openapi-generator/FILES | 2 + .../petstore/python-pydantic-v1/README.md | 1 + .../docs/ModelWithArrayAndMapDefaults.md | 29 +++++ .../docs/ModelWithArrayAndMapDefaultsMap.md | 29 +++++ .../petstore_api/__init__.py | 2 + .../petstore_api/models/__init__.py | 1 + .../model_with_array_and_map_defaults.py | 85 +++++++++++++++ .../test_model_with_array_and_map_defaults.py | 57 ++++++++++ .../petstore/python/.openapi-generator/FILES | 2 + .../openapi3/client/petstore/python/README.md | 1 + .../docs/ModelWithArrayAndMapDefaults.md | 30 ++++++ .../docs/ModelWithArrayAndMapDefaultsMap.md | 30 ++++++ .../petstore/python/petstore_api/__init__.py | 3 + .../python/petstore_api/models/__init__.py | 2 + .../model_with_array_and_map_defaults.py | 102 ++++++++++++++++++ .../test_model_with_array_and_map_defaults.py | 56 ++++++++++ 38 files changed, 866 insertions(+), 17 deletions(-) create mode 100644 samples/openapi3/client/petstore/python-aiohttp/docs/ModelWithArrayAndMapDefaults.md create mode 100644 samples/openapi3/client/petstore/python-aiohttp/docs/ModelWithArrayAndMapDefaultsMap.md create mode 100644 samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model_with_array_and_map_defaults.py create mode 100644 samples/openapi3/client/petstore/python-aiohttp/test/test_model_with_array_and_map_defaults.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/ModelWithArrayAndMapDefaults.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/ModelWithArrayAndMapDefaultsMap.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/model_with_array_and_map_defaults.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_model_with_array_and_map_defaults.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/docs/ModelWithArrayAndMapDefaults.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/docs/ModelWithArrayAndMapDefaultsMap.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/model_with_array_and_map_defaults.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/test/test_model_with_array_and_map_defaults.py create mode 100644 samples/openapi3/client/petstore/python/docs/ModelWithArrayAndMapDefaults.md create mode 100644 samples/openapi3/client/petstore/python/docs/ModelWithArrayAndMapDefaultsMap.md create mode 100644 samples/openapi3/client/petstore/python/petstore_api/models/model_with_array_and_map_defaults.py create mode 100644 samples/openapi3/client/petstore/python/test/test_model_with_array_and_map_defaults.py diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java index c8c76e394692..3a09b079d260 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java @@ -2160,13 +2160,8 @@ private String finalizeType(CodegenProperty cp, PythonType pt) { if (cp.defaultValue == null) { pt.setDefaultValue("None"); } else { - if (cp.isArray || cp.isMap) { - // TODO handle default value for array/map - pt.setDefaultValue("None"); - } else { - //defaultValue = ; - pt.setDefaultValue(cp.defaultValue); - } + //defaultValue = ; + pt.setDefaultValue(cp.defaultValue); } } 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..f36b52acedc9 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,18 @@ components: - 1.0 - 0.5 - 0.25 + ModelWithArrayAndMapDefaults: + type: object + properties: + array: + type: array + items: + type: number + default: [1, 2] + map: + type: object + additionalProperties: + type: string + default: + key1: "value1" + key2: "value2" diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/default_value.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/default_value.py index 8dceac31e3d5..39d444b7bbeb 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/default_value.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/default_value.py @@ -28,10 +28,10 @@ class DefaultValue(BaseModel): """ to test the default value of properties """ # noqa: E501 - array_string_enum_ref_default: Optional[List[StringEnumRef]] = None - array_string_enum_default: Optional[List[StrictStr]] = None - array_string_default: Optional[List[StrictStr]] = None - array_integer_default: Optional[List[StrictInt]] = None + array_string_enum_ref_default: Optional[List[StringEnumRef]] = ["success","failure"] + array_string_enum_default: Optional[List[StrictStr]] = ["success","failure"] + array_string_default: Optional[List[StrictStr]] = ["failure","skipped"] + array_integer_default: Optional[List[StrictInt]] = [1,3] array_string: Optional[List[StrictStr]] = None array_string_nullable: Optional[List[StrictStr]] = None array_string_extension_nullable: Optional[List[StrictStr]] = None diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/query.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/query.py index 97199fb7fd95..422792edaa23 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/query.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/query.py @@ -28,7 +28,7 @@ class Query(BaseModel): Query """ # noqa: E501 id: Optional[StrictInt] = Field(default=None, description="Query") - outcomes: Optional[List[StrictStr]] = None + outcomes: Optional[List[StrictStr]] = ["SUCCESS","FAILURE"] __properties: ClassVar[List[str]] = ["id", "outcomes"] @field_validator('outcomes') diff --git a/samples/client/echo_api/python/openapi_client/models/default_value.py b/samples/client/echo_api/python/openapi_client/models/default_value.py index feee1843319f..27e8443d3e6e 100644 --- a/samples/client/echo_api/python/openapi_client/models/default_value.py +++ b/samples/client/echo_api/python/openapi_client/models/default_value.py @@ -28,10 +28,10 @@ class DefaultValue(BaseModel): """ to test the default value of properties """ # noqa: E501 - array_string_enum_ref_default: Optional[List[StringEnumRef]] = None - array_string_enum_default: Optional[List[StrictStr]] = None - array_string_default: Optional[List[StrictStr]] = None - array_integer_default: Optional[List[StrictInt]] = None + array_string_enum_ref_default: Optional[List[StringEnumRef]] = ["success","failure"] + array_string_enum_default: Optional[List[StrictStr]] = ["success","failure"] + array_string_default: Optional[List[StrictStr]] = ["failure","skipped"] + array_integer_default: Optional[List[StrictInt]] = [1,3] array_string: Optional[List[StrictStr]] = None array_string_nullable: Optional[List[StrictStr]] = None array_string_extension_nullable: Optional[List[StrictStr]] = None diff --git a/samples/client/echo_api/python/openapi_client/models/query.py b/samples/client/echo_api/python/openapi_client/models/query.py index 97199fb7fd95..422792edaa23 100644 --- a/samples/client/echo_api/python/openapi_client/models/query.py +++ b/samples/client/echo_api/python/openapi_client/models/query.py @@ -28,7 +28,7 @@ class Query(BaseModel): Query """ # noqa: E501 id: Optional[StrictInt] = Field(default=None, description="Query") - outcomes: Optional[List[StrictStr]] = None + outcomes: Optional[List[StrictStr]] = ["SUCCESS","FAILURE"] __properties: ClassVar[List[str]] = ["id", "outcomes"] @field_validator('outcomes') diff --git a/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES index 97c491419a4c..a664e820b2de 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES @@ -69,6 +69,7 @@ docs/Model200Response.md docs/ModelApiResponse.md docs/ModelField.md docs/ModelReturn.md +docs/ModelWithArrayAndMapDefaults.md docs/MultiArrays.md docs/Name.md docs/NullableClass.md @@ -198,6 +199,7 @@ petstore_api/models/model200_response.py petstore_api/models/model_api_response.py petstore_api/models/model_field.py petstore_api/models/model_return.py +petstore_api/models/model_with_array_and_map_defaults.py petstore_api/models/multi_arrays.py petstore_api/models/name.py petstore_api/models/nullable_class.py diff --git a/samples/openapi3/client/petstore/python-aiohttp/README.md b/samples/openapi3/client/petstore/python-aiohttp/README.md index 8c925b77c82f..74c954adaf13 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/README.md +++ b/samples/openapi3/client/petstore/python-aiohttp/README.md @@ -212,6 +212,7 @@ Class | Method | HTTP request | Description - [ModelApiResponse](docs/ModelApiResponse.md) - [ModelField](docs/ModelField.md) - [ModelReturn](docs/ModelReturn.md) + - [ModelWithArrayAndMapDefaults](docs/ModelWithArrayAndMapDefaults.md) - [MultiArrays](docs/MultiArrays.md) - [Name](docs/Name.md) - [NullableClass](docs/NullableClass.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/ModelWithArrayAndMapDefaults.md b/samples/openapi3/client/petstore/python-aiohttp/docs/ModelWithArrayAndMapDefaults.md new file mode 100644 index 000000000000..a037436a1c26 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/ModelWithArrayAndMapDefaults.md @@ -0,0 +1,30 @@ +# ModelWithArrayAndMapDefaults + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**array** | **List[float]** | | [optional] [default to [1,2]] +**map** | **Dict[str, str]** | | [optional] + +## Example + +```python +from petstore_api.models.model_with_array_and_map_defaults import ModelWithArrayAndMapDefaults + +# TODO update the JSON string below +json = "{}" +# create an instance of ModelWithArrayAndMapDefaults from a JSON string +model_with_array_and_map_defaults_instance = ModelWithArrayAndMapDefaults.from_json(json) +# print the JSON string representation of the object +print(ModelWithArrayAndMapDefaults.to_json()) + +# convert the object into a dict +model_with_array_and_map_defaults_dict = model_with_array_and_map_defaults_instance.to_dict() +# create an instance of ModelWithArrayAndMapDefaults from a dict +model_with_array_and_map_defaults_from_dict = ModelWithArrayAndMapDefaults.from_dict(model_with_array_and_map_defaults_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/ModelWithArrayAndMapDefaultsMap.md b/samples/openapi3/client/petstore/python-aiohttp/docs/ModelWithArrayAndMapDefaultsMap.md new file mode 100644 index 000000000000..28b860600aa8 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/ModelWithArrayAndMapDefaultsMap.md @@ -0,0 +1,30 @@ +# ModelWithArrayAndMapDefaultsMap + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**key1** | **str** | | [optional] [default to 'value1'] +**key2** | **str** | | [optional] [default to 'value2'] + +## Example + +```python +from petstore_api.models.model_with_array_and_map_defaults_map import ModelWithArrayAndMapDefaultsMap + +# TODO update the JSON string below +json = "{}" +# create an instance of ModelWithArrayAndMapDefaultsMap from a JSON string +model_with_array_and_map_defaults_map_instance = ModelWithArrayAndMapDefaultsMap.from_json(json) +# print the JSON string representation of the object +print(ModelWithArrayAndMapDefaultsMap.to_json()) + +# convert the object into a dict +model_with_array_and_map_defaults_map_dict = model_with_array_and_map_defaults_map_instance.to_dict() +# create an instance of ModelWithArrayAndMapDefaultsMap from a dict +model_with_array_and_map_defaults_map_from_dict = ModelWithArrayAndMapDefaultsMap.from_dict(model_with_array_and_map_defaults_map_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..2f759f7400e0 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/__init__.py @@ -97,6 +97,7 @@ "ModelApiResponse", "ModelField", "ModelReturn", + "ModelWithArrayAndMapDefaults", "MultiArrays", "Name", "NullableClass", @@ -233,6 +234,7 @@ from petstore_api.models.model_api_response import ModelApiResponse as ModelApiResponse from petstore_api.models.model_field import ModelField as ModelField from petstore_api.models.model_return import ModelReturn as ModelReturn + from petstore_api.models.model_with_array_and_map_defaults import ModelWithArrayAndMapDefaults as ModelWithArrayAndMapDefaults from petstore_api.models.multi_arrays import MultiArrays as MultiArrays from petstore_api.models.name import Name as Name from petstore_api.models.nullable_class import NullableClass as NullableClass @@ -375,6 +377,7 @@ from petstore_api.models.model_api_response import ModelApiResponse as ModelApiResponse from petstore_api.models.model_field import ModelField as ModelField from petstore_api.models.model_return import ModelReturn as ModelReturn +from petstore_api.models.model_with_array_and_map_defaults import ModelWithArrayAndMapDefaults as ModelWithArrayAndMapDefaults from petstore_api.models.multi_arrays import MultiArrays as MultiArrays from petstore_api.models.name import Name as Name from petstore_api.models.nullable_class import NullableClass as NullableClass 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..e4617af533c9 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 @@ -76,6 +76,7 @@ from petstore_api.models.model_api_response import ModelApiResponse from petstore_api.models.model_field import ModelField from petstore_api.models.model_return import ModelReturn + from petstore_api.models.model_with_array_and_map_defaults import ModelWithArrayAndMapDefaults from petstore_api.models.multi_arrays import MultiArrays from petstore_api.models.name import Name from petstore_api.models.nullable_class import NullableClass @@ -194,6 +195,7 @@ from petstore_api.models.model_api_response import ModelApiResponse from petstore_api.models.model_field import ModelField from petstore_api.models.model_return import ModelReturn +from petstore_api.models.model_with_array_and_map_defaults import ModelWithArrayAndMapDefaults from petstore_api.models.multi_arrays import MultiArrays from petstore_api.models.name import Name from petstore_api.models.nullable_class import NullableClass diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model_with_array_and_map_defaults.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model_with_array_and_map_defaults.py new file mode 100644 index 000000000000..e65462e5b5e7 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/model_with_array_and_map_defaults.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 BaseModel, ConfigDict, StrictStr +from typing import Any, ClassVar, Dict, List, Optional +from typing import Optional, Set +from typing_extensions import Self + +class ModelWithArrayAndMapDefaults(BaseModel): + """ + ModelWithArrayAndMapDefaults + """ # noqa: E501 + array: Optional[List[float]] = [1,2] + map: Optional[Dict[str, StrictStr]] = None + __properties: ClassVar[List[str]] = ["array", "map"] + + 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 ModelWithArrayAndMapDefaults 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 ModelWithArrayAndMapDefaults from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "array": obj.get("array"), + "map": obj.get("map") + }) + return _obj + + diff --git a/samples/openapi3/client/petstore/python-aiohttp/test/test_model_with_array_and_map_defaults.py b/samples/openapi3/client/petstore/python-aiohttp/test/test_model_with_array_and_map_defaults.py new file mode 100644 index 000000000000..84e05f8b89f9 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/test/test_model_with_array_and_map_defaults.py @@ -0,0 +1,56 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + 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.model_with_array_and_map_defaults import ModelWithArrayAndMapDefaults + +class TestModelWithArrayAndMapDefaults(unittest.TestCase): + """ModelWithArrayAndMapDefaults unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> ModelWithArrayAndMapDefaults: + """Test ModelWithArrayAndMapDefaults + 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 `ModelWithArrayAndMapDefaults` + """ + model = ModelWithArrayAndMapDefaults() + if include_optional: + return ModelWithArrayAndMapDefaults( + array = [ + 1.337 + ], + map = { + 'key' : '' + } + ) + else: + return ModelWithArrayAndMapDefaults( + ) + """ + + def testModelWithArrayAndMapDefaults(self): + """Test ModelWithArrayAndMapDefaults""" + # 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..b0f88370cbb2 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 @@ -69,6 +69,7 @@ docs/MapTest.md docs/MixedPropertiesAndAdditionalPropertiesClass.md docs/Model200Response.md docs/ModelReturn.md +docs/ModelWithArrayAndMapDefaults.md docs/MultiArrays.md docs/Name.md docs/NullableClass.md @@ -198,6 +199,7 @@ petstore_api/models/map_test.py petstore_api/models/mixed_properties_and_additional_properties_class.py petstore_api/models/model200_response.py petstore_api/models/model_return.py +petstore_api/models/model_with_array_and_map_defaults.py petstore_api/models/multi_arrays.py petstore_api/models/name.py petstore_api/models/nullable_class.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 2d2251760605..4027f1529225 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/README.md +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/README.md @@ -213,6 +213,7 @@ Class | Method | HTTP request | Description - [MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md) - [Model200Response](docs/Model200Response.md) - [ModelReturn](docs/ModelReturn.md) + - [ModelWithArrayAndMapDefaults](docs/ModelWithArrayAndMapDefaults.md) - [MultiArrays](docs/MultiArrays.md) - [Name](docs/Name.md) - [NullableClass](docs/NullableClass.md) diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/ModelWithArrayAndMapDefaults.md b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/ModelWithArrayAndMapDefaults.md new file mode 100644 index 000000000000..237871a17be9 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/ModelWithArrayAndMapDefaults.md @@ -0,0 +1,29 @@ +# ModelWithArrayAndMapDefaults + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**array** | **List[float]** | | [optional] [default to [1,2]] +**map** | **Dict[str, str]** | | [optional] + +## Example + +```python +from petstore_api.models.model_with_array_and_map_defaults import ModelWithArrayAndMapDefaults + +# TODO update the JSON string below +json = "{}" +# create an instance of ModelWithArrayAndMapDefaults from a JSON string +model_with_array_and_map_defaults_instance = ModelWithArrayAndMapDefaults.from_json(json) +# print the JSON string representation of the object +print ModelWithArrayAndMapDefaults.to_json() + +# convert the object into a dict +model_with_array_and_map_defaults_dict = model_with_array_and_map_defaults_instance.to_dict() +# create an instance of ModelWithArrayAndMapDefaults from a dict +model_with_array_and_map_defaults_from_dict = ModelWithArrayAndMapDefaults.from_dict(model_with_array_and_map_defaults_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/ModelWithArrayAndMapDefaultsMap.md b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/ModelWithArrayAndMapDefaultsMap.md new file mode 100644 index 000000000000..7e0bdb71eea8 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/ModelWithArrayAndMapDefaultsMap.md @@ -0,0 +1,29 @@ +# ModelWithArrayAndMapDefaultsMap + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**key1** | **str** | | [optional] [default to 'value1'] +**key2** | **str** | | [optional] [default to 'value2'] + +## Example + +```python +from petstore_api.models.model_with_array_and_map_defaults_map import ModelWithArrayAndMapDefaultsMap + +# TODO update the JSON string below +json = "{}" +# create an instance of ModelWithArrayAndMapDefaultsMap from a JSON string +model_with_array_and_map_defaults_map_instance = ModelWithArrayAndMapDefaultsMap.from_json(json) +# print the JSON string representation of the object +print ModelWithArrayAndMapDefaultsMap.to_json() + +# convert the object into a dict +model_with_array_and_map_defaults_map_dict = model_with_array_and_map_defaults_map_instance.to_dict() +# create an instance of ModelWithArrayAndMapDefaultsMap from a dict +model_with_array_and_map_defaults_map_from_dict = ModelWithArrayAndMapDefaultsMap.from_dict(model_with_array_and_map_defaults_map_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..80cf3c62cb20 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 @@ -97,6 +97,7 @@ "MixedPropertiesAndAdditionalPropertiesClass", "Model200Response", "ModelReturn", + "ModelWithArrayAndMapDefaults", "MultiArrays", "Name", "NullableClass", @@ -232,6 +233,7 @@ from petstore_api.models.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass as MixedPropertiesAndAdditionalPropertiesClass from petstore_api.models.model200_response import Model200Response as Model200Response from petstore_api.models.model_return import ModelReturn as ModelReturn +from petstore_api.models.model_with_array_and_map_defaults import ModelWithArrayAndMapDefaults as ModelWithArrayAndMapDefaults from petstore_api.models.multi_arrays import MultiArrays as MultiArrays from petstore_api.models.name import Name as Name from petstore_api.models.nullable_class import NullableClass as NullableClass 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..62f5996d6809 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 @@ -75,6 +75,7 @@ from petstore_api.models.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass from petstore_api.models.model200_response import Model200Response from petstore_api.models.model_return import ModelReturn +from petstore_api.models.model_with_array_and_map_defaults import ModelWithArrayAndMapDefaults from petstore_api.models.multi_arrays import MultiArrays from petstore_api.models.name import Name from petstore_api.models.nullable_class import NullableClass diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/model_with_array_and_map_defaults.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/model_with_array_and_map_defaults.py new file mode 100644 index 000000000000..ff825f6ab791 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/model_with_array_and_map_defaults.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 Dict, List, Optional +from pydantic import BaseModel, StrictStr, conlist + +class ModelWithArrayAndMapDefaults(BaseModel): + """ + ModelWithArrayAndMapDefaults + """ + array: Optional[conlist(float)] = None + map: Optional[Dict[str, StrictStr]] = None + __properties = ["array", "map"] + + 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) -> ModelWithArrayAndMapDefaults: + """Create an instance of ModelWithArrayAndMapDefaults 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) -> ModelWithArrayAndMapDefaults: + """Create an instance of ModelWithArrayAndMapDefaults from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return ModelWithArrayAndMapDefaults.parse_obj(obj) + + _obj = ModelWithArrayAndMapDefaults.parse_obj({ + "array": obj.get("array"), + "map": obj.get("map") + }) + return _obj + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_model_with_array_and_map_defaults.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_model_with_array_and_map_defaults.py new file mode 100644 index 000000000000..29868b12c63a --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_model_with_array_and_map_defaults.py @@ -0,0 +1,57 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + 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.model_with_array_and_map_defaults import ModelWithArrayAndMapDefaults # noqa: E501 + +class TestModelWithArrayAndMapDefaults(unittest.TestCase): + """ModelWithArrayAndMapDefaults unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> ModelWithArrayAndMapDefaults: + """Test ModelWithArrayAndMapDefaults + 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 `ModelWithArrayAndMapDefaults` + """ + model = ModelWithArrayAndMapDefaults() # noqa: E501 + if include_optional: + return ModelWithArrayAndMapDefaults( + array = [ + 1.337 + ], + map = { + 'key' : '' + } + ) + else: + return ModelWithArrayAndMapDefaults( + ) + """ + + def testModelWithArrayAndMapDefaults(self): + """Test ModelWithArrayAndMapDefaults""" + # 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..b0f88370cbb2 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-pydantic-v1/.openapi-generator/FILES @@ -69,6 +69,7 @@ docs/MapTest.md docs/MixedPropertiesAndAdditionalPropertiesClass.md docs/Model200Response.md docs/ModelReturn.md +docs/ModelWithArrayAndMapDefaults.md docs/MultiArrays.md docs/Name.md docs/NullableClass.md @@ -198,6 +199,7 @@ petstore_api/models/map_test.py petstore_api/models/mixed_properties_and_additional_properties_class.py petstore_api/models/model200_response.py petstore_api/models/model_return.py +petstore_api/models/model_with_array_and_map_defaults.py petstore_api/models/multi_arrays.py petstore_api/models/name.py petstore_api/models/nullable_class.py diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/README.md b/samples/openapi3/client/petstore/python-pydantic-v1/README.md index ae1b76c2a368..9525f5b5c40f 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/README.md +++ b/samples/openapi3/client/petstore/python-pydantic-v1/README.md @@ -213,6 +213,7 @@ Class | Method | HTTP request | Description - [MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md) - [Model200Response](docs/Model200Response.md) - [ModelReturn](docs/ModelReturn.md) + - [ModelWithArrayAndMapDefaults](docs/ModelWithArrayAndMapDefaults.md) - [MultiArrays](docs/MultiArrays.md) - [Name](docs/Name.md) - [NullableClass](docs/NullableClass.md) diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/docs/ModelWithArrayAndMapDefaults.md b/samples/openapi3/client/petstore/python-pydantic-v1/docs/ModelWithArrayAndMapDefaults.md new file mode 100644 index 000000000000..237871a17be9 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/docs/ModelWithArrayAndMapDefaults.md @@ -0,0 +1,29 @@ +# ModelWithArrayAndMapDefaults + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**array** | **List[float]** | | [optional] [default to [1,2]] +**map** | **Dict[str, str]** | | [optional] + +## Example + +```python +from petstore_api.models.model_with_array_and_map_defaults import ModelWithArrayAndMapDefaults + +# TODO update the JSON string below +json = "{}" +# create an instance of ModelWithArrayAndMapDefaults from a JSON string +model_with_array_and_map_defaults_instance = ModelWithArrayAndMapDefaults.from_json(json) +# print the JSON string representation of the object +print ModelWithArrayAndMapDefaults.to_json() + +# convert the object into a dict +model_with_array_and_map_defaults_dict = model_with_array_and_map_defaults_instance.to_dict() +# create an instance of ModelWithArrayAndMapDefaults from a dict +model_with_array_and_map_defaults_from_dict = ModelWithArrayAndMapDefaults.from_dict(model_with_array_and_map_defaults_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/ModelWithArrayAndMapDefaultsMap.md b/samples/openapi3/client/petstore/python-pydantic-v1/docs/ModelWithArrayAndMapDefaultsMap.md new file mode 100644 index 000000000000..7e0bdb71eea8 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/docs/ModelWithArrayAndMapDefaultsMap.md @@ -0,0 +1,29 @@ +# ModelWithArrayAndMapDefaultsMap + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**key1** | **str** | | [optional] [default to 'value1'] +**key2** | **str** | | [optional] [default to 'value2'] + +## Example + +```python +from petstore_api.models.model_with_array_and_map_defaults_map import ModelWithArrayAndMapDefaultsMap + +# TODO update the JSON string below +json = "{}" +# create an instance of ModelWithArrayAndMapDefaultsMap from a JSON string +model_with_array_and_map_defaults_map_instance = ModelWithArrayAndMapDefaultsMap.from_json(json) +# print the JSON string representation of the object +print ModelWithArrayAndMapDefaultsMap.to_json() + +# convert the object into a dict +model_with_array_and_map_defaults_map_dict = model_with_array_and_map_defaults_map_instance.to_dict() +# create an instance of ModelWithArrayAndMapDefaultsMap from a dict +model_with_array_and_map_defaults_map_from_dict = ModelWithArrayAndMapDefaultsMap.from_dict(model_with_array_and_map_defaults_map_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..80cf3c62cb20 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 @@ -97,6 +97,7 @@ "MixedPropertiesAndAdditionalPropertiesClass", "Model200Response", "ModelReturn", + "ModelWithArrayAndMapDefaults", "MultiArrays", "Name", "NullableClass", @@ -232,6 +233,7 @@ from petstore_api.models.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass as MixedPropertiesAndAdditionalPropertiesClass from petstore_api.models.model200_response import Model200Response as Model200Response from petstore_api.models.model_return import ModelReturn as ModelReturn +from petstore_api.models.model_with_array_and_map_defaults import ModelWithArrayAndMapDefaults as ModelWithArrayAndMapDefaults from petstore_api.models.multi_arrays import MultiArrays as MultiArrays from petstore_api.models.name import Name as Name from petstore_api.models.nullable_class import NullableClass as NullableClass 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..62f5996d6809 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 @@ -75,6 +75,7 @@ from petstore_api.models.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass from petstore_api.models.model200_response import Model200Response from petstore_api.models.model_return import ModelReturn +from petstore_api.models.model_with_array_and_map_defaults import ModelWithArrayAndMapDefaults from petstore_api.models.multi_arrays import MultiArrays from petstore_api.models.name import Name from petstore_api.models.nullable_class import NullableClass diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/model_with_array_and_map_defaults.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/model_with_array_and_map_defaults.py new file mode 100644 index 000000000000..2d6395fde872 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/model_with_array_and_map_defaults.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, List, Optional +from pydantic import BaseModel, StrictFloat, StrictStr, conlist + +class ModelWithArrayAndMapDefaults(BaseModel): + """ + ModelWithArrayAndMapDefaults + """ + array: Optional[conlist(StrictFloat)] = None + map: Optional[Dict[str, StrictStr]] = None + additional_properties: Dict[str, Any] = {} + __properties = ["array", "map"] + + 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) -> ModelWithArrayAndMapDefaults: + """Create an instance of ModelWithArrayAndMapDefaults 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) -> ModelWithArrayAndMapDefaults: + """Create an instance of ModelWithArrayAndMapDefaults from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return ModelWithArrayAndMapDefaults.parse_obj(obj) + + _obj = ModelWithArrayAndMapDefaults.parse_obj({ + "array": obj.get("array"), + "map": obj.get("map") + }) + # 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_model_with_array_and_map_defaults.py b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_model_with_array_and_map_defaults.py new file mode 100644 index 000000000000..29868b12c63a --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_model_with_array_and_map_defaults.py @@ -0,0 +1,57 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + 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.model_with_array_and_map_defaults import ModelWithArrayAndMapDefaults # noqa: E501 + +class TestModelWithArrayAndMapDefaults(unittest.TestCase): + """ModelWithArrayAndMapDefaults unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> ModelWithArrayAndMapDefaults: + """Test ModelWithArrayAndMapDefaults + 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 `ModelWithArrayAndMapDefaults` + """ + model = ModelWithArrayAndMapDefaults() # noqa: E501 + if include_optional: + return ModelWithArrayAndMapDefaults( + array = [ + 1.337 + ], + map = { + 'key' : '' + } + ) + else: + return ModelWithArrayAndMapDefaults( + ) + """ + + def testModelWithArrayAndMapDefaults(self): + """Test ModelWithArrayAndMapDefaults""" + # 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..a664e820b2de 100755 --- a/samples/openapi3/client/petstore/python/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python/.openapi-generator/FILES @@ -69,6 +69,7 @@ docs/Model200Response.md docs/ModelApiResponse.md docs/ModelField.md docs/ModelReturn.md +docs/ModelWithArrayAndMapDefaults.md docs/MultiArrays.md docs/Name.md docs/NullableClass.md @@ -198,6 +199,7 @@ petstore_api/models/model200_response.py petstore_api/models/model_api_response.py petstore_api/models/model_field.py petstore_api/models/model_return.py +petstore_api/models/model_with_array_and_map_defaults.py petstore_api/models/multi_arrays.py petstore_api/models/name.py petstore_api/models/nullable_class.py diff --git a/samples/openapi3/client/petstore/python/README.md b/samples/openapi3/client/petstore/python/README.md index 90a80826e618..653241b311e6 100755 --- a/samples/openapi3/client/petstore/python/README.md +++ b/samples/openapi3/client/petstore/python/README.md @@ -212,6 +212,7 @@ Class | Method | HTTP request | Description - [ModelApiResponse](docs/ModelApiResponse.md) - [ModelField](docs/ModelField.md) - [ModelReturn](docs/ModelReturn.md) + - [ModelWithArrayAndMapDefaults](docs/ModelWithArrayAndMapDefaults.md) - [MultiArrays](docs/MultiArrays.md) - [Name](docs/Name.md) - [NullableClass](docs/NullableClass.md) diff --git a/samples/openapi3/client/petstore/python/docs/ModelWithArrayAndMapDefaults.md b/samples/openapi3/client/petstore/python/docs/ModelWithArrayAndMapDefaults.md new file mode 100644 index 000000000000..a037436a1c26 --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/ModelWithArrayAndMapDefaults.md @@ -0,0 +1,30 @@ +# ModelWithArrayAndMapDefaults + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**array** | **List[float]** | | [optional] [default to [1,2]] +**map** | **Dict[str, str]** | | [optional] + +## Example + +```python +from petstore_api.models.model_with_array_and_map_defaults import ModelWithArrayAndMapDefaults + +# TODO update the JSON string below +json = "{}" +# create an instance of ModelWithArrayAndMapDefaults from a JSON string +model_with_array_and_map_defaults_instance = ModelWithArrayAndMapDefaults.from_json(json) +# print the JSON string representation of the object +print(ModelWithArrayAndMapDefaults.to_json()) + +# convert the object into a dict +model_with_array_and_map_defaults_dict = model_with_array_and_map_defaults_instance.to_dict() +# create an instance of ModelWithArrayAndMapDefaults from a dict +model_with_array_and_map_defaults_from_dict = ModelWithArrayAndMapDefaults.from_dict(model_with_array_and_map_defaults_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/ModelWithArrayAndMapDefaultsMap.md b/samples/openapi3/client/petstore/python/docs/ModelWithArrayAndMapDefaultsMap.md new file mode 100644 index 000000000000..28b860600aa8 --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/ModelWithArrayAndMapDefaultsMap.md @@ -0,0 +1,30 @@ +# ModelWithArrayAndMapDefaultsMap + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**key1** | **str** | | [optional] [default to 'value1'] +**key2** | **str** | | [optional] [default to 'value2'] + +## Example + +```python +from petstore_api.models.model_with_array_and_map_defaults_map import ModelWithArrayAndMapDefaultsMap + +# TODO update the JSON string below +json = "{}" +# create an instance of ModelWithArrayAndMapDefaultsMap from a JSON string +model_with_array_and_map_defaults_map_instance = ModelWithArrayAndMapDefaultsMap.from_json(json) +# print the JSON string representation of the object +print(ModelWithArrayAndMapDefaultsMap.to_json()) + +# convert the object into a dict +model_with_array_and_map_defaults_map_dict = model_with_array_and_map_defaults_map_instance.to_dict() +# create an instance of ModelWithArrayAndMapDefaultsMap from a dict +model_with_array_and_map_defaults_map_from_dict = ModelWithArrayAndMapDefaultsMap.from_dict(model_with_array_and_map_defaults_map_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..2f759f7400e0 100755 --- a/samples/openapi3/client/petstore/python/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/__init__.py @@ -97,6 +97,7 @@ "ModelApiResponse", "ModelField", "ModelReturn", + "ModelWithArrayAndMapDefaults", "MultiArrays", "Name", "NullableClass", @@ -233,6 +234,7 @@ from petstore_api.models.model_api_response import ModelApiResponse as ModelApiResponse from petstore_api.models.model_field import ModelField as ModelField from petstore_api.models.model_return import ModelReturn as ModelReturn + from petstore_api.models.model_with_array_and_map_defaults import ModelWithArrayAndMapDefaults as ModelWithArrayAndMapDefaults from petstore_api.models.multi_arrays import MultiArrays as MultiArrays from petstore_api.models.name import Name as Name from petstore_api.models.nullable_class import NullableClass as NullableClass @@ -375,6 +377,7 @@ from petstore_api.models.model_api_response import ModelApiResponse as ModelApiResponse from petstore_api.models.model_field import ModelField as ModelField from petstore_api.models.model_return import ModelReturn as ModelReturn +from petstore_api.models.model_with_array_and_map_defaults import ModelWithArrayAndMapDefaults as ModelWithArrayAndMapDefaults from petstore_api.models.multi_arrays import MultiArrays as MultiArrays from petstore_api.models.name import Name as Name from petstore_api.models.nullable_class import NullableClass as NullableClass 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..e4617af533c9 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py @@ -76,6 +76,7 @@ from petstore_api.models.model_api_response import ModelApiResponse from petstore_api.models.model_field import ModelField from petstore_api.models.model_return import ModelReturn + from petstore_api.models.model_with_array_and_map_defaults import ModelWithArrayAndMapDefaults from petstore_api.models.multi_arrays import MultiArrays from petstore_api.models.name import Name from petstore_api.models.nullable_class import NullableClass @@ -194,6 +195,7 @@ from petstore_api.models.model_api_response import ModelApiResponse from petstore_api.models.model_field import ModelField from petstore_api.models.model_return import ModelReturn +from petstore_api.models.model_with_array_and_map_defaults import ModelWithArrayAndMapDefaults from petstore_api.models.multi_arrays import MultiArrays from petstore_api.models.name import Name from petstore_api.models.nullable_class import NullableClass diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/model_with_array_and_map_defaults.py b/samples/openapi3/client/petstore/python/petstore_api/models/model_with_array_and_map_defaults.py new file mode 100644 index 000000000000..52fa4e133773 --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/models/model_with_array_and_map_defaults.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 BaseModel, ConfigDict, StrictFloat, StrictStr +from typing import Any, ClassVar, Dict, List, Optional +from typing import Optional, Set +from typing_extensions import Self + +class ModelWithArrayAndMapDefaults(BaseModel): + """ + ModelWithArrayAndMapDefaults + """ # noqa: E501 + array: Optional[List[StrictFloat]] = [1,2] + map: Optional[Dict[str, StrictStr]] = None + additional_properties: Dict[str, Any] = {} + __properties: ClassVar[List[str]] = ["array", "map"] + + 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 ModelWithArrayAndMapDefaults 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 ModelWithArrayAndMapDefaults from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "array": obj.get("array"), + "map": obj.get("map") + }) + # 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_model_with_array_and_map_defaults.py b/samples/openapi3/client/petstore/python/test/test_model_with_array_and_map_defaults.py new file mode 100644 index 000000000000..84e05f8b89f9 --- /dev/null +++ b/samples/openapi3/client/petstore/python/test/test_model_with_array_and_map_defaults.py @@ -0,0 +1,56 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + 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.model_with_array_and_map_defaults import ModelWithArrayAndMapDefaults + +class TestModelWithArrayAndMapDefaults(unittest.TestCase): + """ModelWithArrayAndMapDefaults unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> ModelWithArrayAndMapDefaults: + """Test ModelWithArrayAndMapDefaults + 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 `ModelWithArrayAndMapDefaults` + """ + model = ModelWithArrayAndMapDefaults() + if include_optional: + return ModelWithArrayAndMapDefaults( + array = [ + 1.337 + ], + map = { + 'key' : '' + } + ) + else: + return ModelWithArrayAndMapDefaults( + ) + """ + + def testModelWithArrayAndMapDefaults(self): + """Test ModelWithArrayAndMapDefaults""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main()