From 95b5597fd808ffb00c82801b62279587d797ff01 Mon Sep 17 00:00:00 2001 From: Volodymyr Samokhatko Date: Mon, 22 Jul 2024 16:06:35 +0200 Subject: [PATCH 1/2] [python] mypy fix for multiple arrays of objects --- .../resources/python/model_generic.mustache | 26 +++++++++---------- .../openapi_client/models/pet.py | 6 ++--- .../python/openapi_client/models/pet.py | 6 ++--- .../models/array_of_array_of_model.py | 6 ++--- .../petstore_api/models/array_test.py | 6 ++--- .../models/circular_all_of_ref.py | 6 ++--- .../models/file_schema_test_class.py | 6 ++--- .../petstore_api/models/input_all_of.py | 6 ++--- .../models/map_of_array_of_model.py | 8 +++--- ...perties_and_additional_properties_class.py | 6 ++--- .../petstore_api/models/parent.py | 6 ++--- .../models/parent_with_optional_dict.py | 6 ++--- .../python-aiohttp/petstore_api/models/pet.py | 6 ++--- .../petstore_api/models/property_map.py | 6 ++--- .../models/second_circular_all_of_ref.py | 6 ++--- ...t_with_additional_model_list_properties.py | 8 +++--- .../models/array_of_array_of_model.py | 6 ++--- .../python/petstore_api/models/array_test.py | 6 ++--- .../models/circular_all_of_ref.py | 6 ++--- .../models/file_schema_test_class.py | 6 ++--- .../petstore_api/models/input_all_of.py | 6 ++--- .../models/map_of_array_of_model.py | 8 +++--- ...perties_and_additional_properties_class.py | 6 ++--- .../python/petstore_api/models/parent.py | 6 ++--- .../models/parent_with_optional_dict.py | 6 ++--- .../python/petstore_api/models/pet.py | 6 ++--- .../petstore_api/models/property_map.py | 6 ++--- .../models/second_circular_all_of_ref.py | 6 ++--- ...t_with_additional_model_list_properties.py | 8 +++--- 29 files changed, 101 insertions(+), 101 deletions(-) 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 2fadb7365717..768f4f75072f 100644 --- a/modules/openapi-generator/src/main/resources/python/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_generic.mustache @@ -166,10 +166,10 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} # override the default output from pydantic by calling `to_dict()` of each item in {{{name}}} (list of list) _items = [] if self.{{{name}}}: - for _item in self.{{{name}}}: - if _item: + for _item_{{{name}}} in self.{{{name}}}: + if _item_{{{name}}}: _items.append( - [_inner_item.to_dict() for _inner_item in _item if _inner_item is not None] + [_inner_item.to_dict() for _inner_item in _item_{{{name}}} if _inner_item is not None] ) _dict['{{{baseName}}}'] = _items {{/items.items.isPrimitiveType}} @@ -180,9 +180,9 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} # override the default output from pydantic by calling `to_dict()` of each item in {{{name}}} (list) _items = [] if self.{{{name}}}: - for _item in self.{{{name}}}: - if _item: - _items.append(_item.to_dict()) + for _item_{{{name}}} in self.{{{name}}}: + if _item_{{{name}}}: + _items.append(_item_{{{name}}}.to_dict()) _dict['{{{baseName}}}'] = _items {{/items.isEnumOrRef}} {{/items.isPrimitiveType}} @@ -194,10 +194,10 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} # override the default output from pydantic by calling `to_dict()` of each value in {{{name}}} (dict of array) _field_dict_of_array = {} if self.{{{name}}}: - for _key in self.{{{name}}}: - if self.{{{name}}}[_key] is not None: - _field_dict_of_array[_key] = [ - _item.to_dict() for _item in self.{{{name}}}[_key] + for _key_{{{name}}} in self.{{{name}}}: + if self.{{{name}}}[_key_{{{name}}}] is not None: + _field_dict_of_array[_key_{{{name}}}] = [ + _item.to_dict() for _item in self.{{{name}}}[_key_{{{name}}}] ] _dict['{{{baseName}}}'] = _field_dict_of_array {{/items.items.isPrimitiveType}} @@ -208,9 +208,9 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} # override the default output from pydantic by calling `to_dict()` of each value in {{{name}}} (dict) _field_dict = {} if self.{{{name}}}: - for _key in self.{{{name}}}: - if self.{{{name}}}[_key]: - _field_dict[_key] = self.{{{name}}}[_key].to_dict() + for _key_{{{name}}} in self.{{{name}}}: + if self.{{{name}}}[_key_{{{name}}}]: + _field_dict[_key_{{{name}}}] = self.{{{name}}}[_key_{{{name}}}].to_dict() _dict['{{{baseName}}}'] = _field_dict {{/items.isEnumOrRef}} {{/items.isPrimitiveType}} diff --git a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py index b02ce560504c..bfe90956d977 100644 --- a/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py +++ b/samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/models/pet.py @@ -92,9 +92,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in tags (list) _items = [] if self.tags: - for _item in self.tags: - if _item: - _items.append(_item.to_dict()) + for _item_tags in self.tags: + if _item_tags: + _items.append(_item_tags.to_dict()) _dict['tags'] = _items return _dict diff --git a/samples/client/echo_api/python/openapi_client/models/pet.py b/samples/client/echo_api/python/openapi_client/models/pet.py index 53d7895d8d63..0a0ae74d1155 100644 --- a/samples/client/echo_api/python/openapi_client/models/pet.py +++ b/samples/client/echo_api/python/openapi_client/models/pet.py @@ -92,9 +92,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in tags (list) _items = [] if self.tags: - for _item in self.tags: - if _item: - _items.append(_item.to_dict()) + for _item_tags in self.tags: + if _item_tags: + _items.append(_item_tags.to_dict()) _dict['tags'] = _items return _dict diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_array_of_model.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_array_of_model.py index c94d7884aaf9..4f8eeda66c30 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_of_array_of_model.py @@ -72,10 +72,10 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in another_property (list of list) _items = [] if self.another_property: - for _item in self.another_property: - if _item: + for _item_another_property in self.another_property: + if _item_another_property: _items.append( - [_inner_item.to_dict() for _inner_item in _item if _inner_item is not None] + [_inner_item.to_dict() for _inner_item in _item_another_property if _inner_item is not None] ) _dict['another_property'] = _items return _dict diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_test.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_test.py index 297936585e1c..e8f8acf67cc0 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_test.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/array_test.py @@ -76,10 +76,10 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in array_array_of_model (list of list) _items = [] if self.array_array_of_model: - for _item in self.array_array_of_model: - if _item: + for _item_array_array_of_model in self.array_array_of_model: + if _item_array_array_of_model: _items.append( - [_inner_item.to_dict() for _inner_item in _item if _inner_item is not None] + [_inner_item.to_dict() for _inner_item in _item_array_array_of_model if _inner_item is not None] ) _dict['array_array_of_model'] = _items return _dict diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/circular_all_of_ref.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/circular_all_of_ref.py index 32c742e9d108..f98247ae0fb5 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/circular_all_of_ref.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/circular_all_of_ref.py @@ -72,9 +72,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in second_circular_all_of_ref (list) _items = [] if self.second_circular_all_of_ref: - for _item in self.second_circular_all_of_ref: - if _item: - _items.append(_item.to_dict()) + for _item_second_circular_all_of_ref in self.second_circular_all_of_ref: + if _item_second_circular_all_of_ref: + _items.append(_item_second_circular_all_of_ref.to_dict()) _dict['secondCircularAllOfRef'] = _items return _dict diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/file_schema_test_class.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/file_schema_test_class.py index 960777493b8d..c533c0777b24 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/file_schema_test_class.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/file_schema_test_class.py @@ -76,9 +76,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in files (list) _items = [] if self.files: - for _item in self.files: - if _item: - _items.append(_item.to_dict()) + for _item_files in self.files: + if _item_files: + _items.append(_item_files.to_dict()) _dict['files'] = _items return _dict diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/input_all_of.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/input_all_of.py index 86b3b8c1e6f6..63870cca83ed 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/input_all_of.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/input_all_of.py @@ -72,9 +72,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each value in some_data (dict) _field_dict = {} if self.some_data: - for _key in self.some_data: - if self.some_data[_key]: - _field_dict[_key] = self.some_data[_key].to_dict() + for _key_some_data in self.some_data: + if self.some_data[_key_some_data]: + _field_dict[_key_some_data] = self.some_data[_key_some_data].to_dict() _dict['some_data'] = _field_dict return _dict diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_of_array_of_model.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_of_array_of_model.py index 80329880d824..a9bd000ad9ba 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_of_array_of_model.py @@ -72,10 +72,10 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each value in shop_id_to_org_online_lip_map (dict of array) _field_dict_of_array = {} if self.shop_id_to_org_online_lip_map: - for _key in self.shop_id_to_org_online_lip_map: - if self.shop_id_to_org_online_lip_map[_key] is not None: - _field_dict_of_array[_key] = [ - _item.to_dict() for _item in self.shop_id_to_org_online_lip_map[_key] + for _key_shop_id_to_org_online_lip_map in self.shop_id_to_org_online_lip_map: + if self.shop_id_to_org_online_lip_map[_key_shop_id_to_org_online_lip_map] is not None: + _field_dict_of_array[_key_shop_id_to_org_online_lip_map] = [ + _item.to_dict() for _item in self.shop_id_to_org_online_lip_map[_key_shop_id_to_org_online_lip_map] ] _dict['shopIdToOrgOnlineLipMap'] = _field_dict_of_array return _dict diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/mixed_properties_and_additional_properties_class.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/mixed_properties_and_additional_properties_class.py index 9148a9edab4a..5e28a547c67d 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/mixed_properties_and_additional_properties_class.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/mixed_properties_and_additional_properties_class.py @@ -75,9 +75,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each value in map (dict) _field_dict = {} if self.map: - for _key in self.map: - if self.map[_key]: - _field_dict[_key] = self.map[_key].to_dict() + for _key_map in self.map: + if self.map[_key_map]: + _field_dict[_key_map] = self.map[_key_map].to_dict() _dict['map'] = _field_dict return _dict diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent.py index bbdf75b1a96d..5986da45ab04 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent.py @@ -72,9 +72,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each value in optional_dict (dict) _field_dict = {} if self.optional_dict: - for _key in self.optional_dict: - if self.optional_dict[_key]: - _field_dict[_key] = self.optional_dict[_key].to_dict() + for _key_optional_dict in self.optional_dict: + if self.optional_dict[_key_optional_dict]: + _field_dict[_key_optional_dict] = self.optional_dict[_key_optional_dict].to_dict() _dict['optionalDict'] = _field_dict return _dict diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent_with_optional_dict.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent_with_optional_dict.py index d9ef2cd31a91..84445b64043a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent_with_optional_dict.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/parent_with_optional_dict.py @@ -72,9 +72,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each value in optional_dict (dict) _field_dict = {} if self.optional_dict: - for _key in self.optional_dict: - if self.optional_dict[_key]: - _field_dict[_key] = self.optional_dict[_key].to_dict() + for _key_optional_dict in self.optional_dict: + if self.optional_dict[_key_optional_dict]: + _field_dict[_key_optional_dict] = self.optional_dict[_key_optional_dict].to_dict() _dict['optionalDict'] = _field_dict return _dict diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pet.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pet.py index f04c6eba4fe1..be47c3b1a894 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pet.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/pet.py @@ -92,9 +92,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in tags (list) _items = [] if self.tags: - for _item in self.tags: - if _item: - _items.append(_item.to_dict()) + for _item_tags in self.tags: + if _item_tags: + _items.append(_item_tags.to_dict()) _dict['tags'] = _items return _dict diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/property_map.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/property_map.py index caed05a5a117..940016a86a72 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/property_map.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/property_map.py @@ -72,9 +72,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each value in some_data (dict) _field_dict = {} if self.some_data: - for _key in self.some_data: - if self.some_data[_key]: - _field_dict[_key] = self.some_data[_key].to_dict() + for _key_some_data in self.some_data: + if self.some_data[_key_some_data]: + _field_dict[_key_some_data] = self.some_data[_key_some_data].to_dict() _dict['some_data'] = _field_dict return _dict diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/second_circular_all_of_ref.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/second_circular_all_of_ref.py index b7668004013f..854749b4fb13 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/second_circular_all_of_ref.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/second_circular_all_of_ref.py @@ -72,9 +72,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in circular_all_of_ref (list) _items = [] if self.circular_all_of_ref: - for _item in self.circular_all_of_ref: - if _item: - _items.append(_item.to_dict()) + for _item_circular_all_of_ref in self.circular_all_of_ref: + if _item_circular_all_of_ref: + _items.append(_item_circular_all_of_ref.to_dict()) _dict['circularAllOfRef'] = _items return _dict diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py index 90959ce2cb4e..e50edf2efa85 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py @@ -72,10 +72,10 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each value in dict_property (dict of array) _field_dict_of_array = {} if self.dict_property: - for _key in self.dict_property: - if self.dict_property[_key] is not None: - _field_dict_of_array[_key] = [ - _item.to_dict() for _item in self.dict_property[_key] + for _key_dict_property in self.dict_property: + if self.dict_property[_key_dict_property] is not None: + _field_dict_of_array[_key_dict_property] = [ + _item.to_dict() for _item in self.dict_property[_key_dict_property] ] _dict['dictProperty'] = _field_dict_of_array return _dict diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_model.py b/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_model.py index 5ad30edea22d..80d4aa689164 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_model.py @@ -75,10 +75,10 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in another_property (list of list) _items = [] if self.another_property: - for _item in self.another_property: - if _item: + for _item_another_property in self.another_property: + if _item_another_property: _items.append( - [_inner_item.to_dict() for _inner_item in _item if _inner_item is not None] + [_inner_item.to_dict() for _inner_item in _item_another_property if _inner_item is not None] ) _dict['another_property'] = _items # puts key-value pairs in additional_properties in the top level diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/array_test.py b/samples/openapi3/client/petstore/python/petstore_api/models/array_test.py index 5d9dbe15cd8b..9cadd4e7beb7 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/array_test.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/array_test.py @@ -79,10 +79,10 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in array_array_of_model (list of list) _items = [] if self.array_array_of_model: - for _item in self.array_array_of_model: - if _item: + for _item_array_array_of_model in self.array_array_of_model: + if _item_array_array_of_model: _items.append( - [_inner_item.to_dict() for _inner_item in _item if _inner_item is not None] + [_inner_item.to_dict() for _inner_item in _item_array_array_of_model if _inner_item is not None] ) _dict['array_array_of_model'] = _items # puts key-value pairs in additional_properties in the top level diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/circular_all_of_ref.py b/samples/openapi3/client/petstore/python/petstore_api/models/circular_all_of_ref.py index fb2241d0dae3..d3b6cbe57ea1 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/circular_all_of_ref.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/circular_all_of_ref.py @@ -75,9 +75,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in second_circular_all_of_ref (list) _items = [] if self.second_circular_all_of_ref: - for _item in self.second_circular_all_of_ref: - if _item: - _items.append(_item.to_dict()) + for _item_second_circular_all_of_ref in self.second_circular_all_of_ref: + if _item_second_circular_all_of_ref: + _items.append(_item_second_circular_all_of_ref.to_dict()) _dict['secondCircularAllOfRef'] = _items # puts key-value pairs in additional_properties in the top level if self.additional_properties is not None: diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/file_schema_test_class.py b/samples/openapi3/client/petstore/python/petstore_api/models/file_schema_test_class.py index eaa82b8c1aff..09a543010f4d 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/file_schema_test_class.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/file_schema_test_class.py @@ -79,9 +79,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in files (list) _items = [] if self.files: - for _item in self.files: - if _item: - _items.append(_item.to_dict()) + for _item_files in self.files: + if _item_files: + _items.append(_item_files.to_dict()) _dict['files'] = _items # puts key-value pairs in additional_properties in the top level if self.additional_properties is not None: diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/input_all_of.py b/samples/openapi3/client/petstore/python/petstore_api/models/input_all_of.py index c07bb83519be..e4a81ff70006 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/input_all_of.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/input_all_of.py @@ -75,9 +75,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each value in some_data (dict) _field_dict = {} if self.some_data: - for _key in self.some_data: - if self.some_data[_key]: - _field_dict[_key] = self.some_data[_key].to_dict() + for _key_some_data in self.some_data: + if self.some_data[_key_some_data]: + _field_dict[_key_some_data] = self.some_data[_key_some_data].to_dict() _dict['some_data'] = _field_dict # puts key-value pairs in additional_properties in the top level if self.additional_properties is not None: diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/map_of_array_of_model.py b/samples/openapi3/client/petstore/python/petstore_api/models/map_of_array_of_model.py index 8d88c98995bf..68816ab29531 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/map_of_array_of_model.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/map_of_array_of_model.py @@ -75,10 +75,10 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each value in shop_id_to_org_online_lip_map (dict of array) _field_dict_of_array = {} if self.shop_id_to_org_online_lip_map: - for _key in self.shop_id_to_org_online_lip_map: - if self.shop_id_to_org_online_lip_map[_key] is not None: - _field_dict_of_array[_key] = [ - _item.to_dict() for _item in self.shop_id_to_org_online_lip_map[_key] + for _key_shop_id_to_org_online_lip_map in self.shop_id_to_org_online_lip_map: + if self.shop_id_to_org_online_lip_map[_key_shop_id_to_org_online_lip_map] is not None: + _field_dict_of_array[_key_shop_id_to_org_online_lip_map] = [ + _item.to_dict() for _item in self.shop_id_to_org_online_lip_map[_key_shop_id_to_org_online_lip_map] ] _dict['shopIdToOrgOnlineLipMap'] = _field_dict_of_array # puts key-value pairs in additional_properties in the top level diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/mixed_properties_and_additional_properties_class.py b/samples/openapi3/client/petstore/python/petstore_api/models/mixed_properties_and_additional_properties_class.py index 6f017ce04da5..be56ba40f721 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/mixed_properties_and_additional_properties_class.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/mixed_properties_and_additional_properties_class.py @@ -78,9 +78,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each value in map (dict) _field_dict = {} if self.map: - for _key in self.map: - if self.map[_key]: - _field_dict[_key] = self.map[_key].to_dict() + for _key_map in self.map: + if self.map[_key_map]: + _field_dict[_key_map] = self.map[_key_map].to_dict() _dict['map'] = _field_dict # puts key-value pairs in additional_properties in the top level if self.additional_properties is not None: diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/parent.py b/samples/openapi3/client/petstore/python/petstore_api/models/parent.py index 3a1bdfb674ed..8a30758ab8fd 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/parent.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/parent.py @@ -75,9 +75,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each value in optional_dict (dict) _field_dict = {} if self.optional_dict: - for _key in self.optional_dict: - if self.optional_dict[_key]: - _field_dict[_key] = self.optional_dict[_key].to_dict() + for _key_optional_dict in self.optional_dict: + if self.optional_dict[_key_optional_dict]: + _field_dict[_key_optional_dict] = self.optional_dict[_key_optional_dict].to_dict() _dict['optionalDict'] = _field_dict # puts key-value pairs in additional_properties in the top level if self.additional_properties is not None: diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/parent_with_optional_dict.py b/samples/openapi3/client/petstore/python/petstore_api/models/parent_with_optional_dict.py index 16b6cd1390bb..509693dd1441 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/parent_with_optional_dict.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/parent_with_optional_dict.py @@ -75,9 +75,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each value in optional_dict (dict) _field_dict = {} if self.optional_dict: - for _key in self.optional_dict: - if self.optional_dict[_key]: - _field_dict[_key] = self.optional_dict[_key].to_dict() + for _key_optional_dict in self.optional_dict: + if self.optional_dict[_key_optional_dict]: + _field_dict[_key_optional_dict] = self.optional_dict[_key_optional_dict].to_dict() _dict['optionalDict'] = _field_dict # puts key-value pairs in additional_properties in the top level if self.additional_properties is not None: diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/pet.py b/samples/openapi3/client/petstore/python/petstore_api/models/pet.py index d624adf2c029..48f0c2fceeb7 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/pet.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/pet.py @@ -95,9 +95,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in tags (list) _items = [] if self.tags: - for _item in self.tags: - if _item: - _items.append(_item.to_dict()) + for _item_tags in self.tags: + if _item_tags: + _items.append(_item_tags.to_dict()) _dict['tags'] = _items # puts key-value pairs in additional_properties in the top level if self.additional_properties is not None: diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/property_map.py b/samples/openapi3/client/petstore/python/petstore_api/models/property_map.py index 1b44dcef4cb1..0da2a14293de 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/property_map.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/property_map.py @@ -75,9 +75,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each value in some_data (dict) _field_dict = {} if self.some_data: - for _key in self.some_data: - if self.some_data[_key]: - _field_dict[_key] = self.some_data[_key].to_dict() + for _key_some_data in self.some_data: + if self.some_data[_key_some_data]: + _field_dict[_key_some_data] = self.some_data[_key_some_data].to_dict() _dict['some_data'] = _field_dict # puts key-value pairs in additional_properties in the top level if self.additional_properties is not None: diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/second_circular_all_of_ref.py b/samples/openapi3/client/petstore/python/petstore_api/models/second_circular_all_of_ref.py index 34d4dc244574..13d6327314c3 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/second_circular_all_of_ref.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/second_circular_all_of_ref.py @@ -75,9 +75,9 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each item in circular_all_of_ref (list) _items = [] if self.circular_all_of_ref: - for _item in self.circular_all_of_ref: - if _item: - _items.append(_item.to_dict()) + for _item_circular_all_of_ref in self.circular_all_of_ref: + if _item_circular_all_of_ref: + _items.append(_item_circular_all_of_ref.to_dict()) _dict['circularAllOfRef'] = _items # puts key-value pairs in additional_properties in the top level if self.additional_properties is not None: diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py b/samples/openapi3/client/petstore/python/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py index 365160f4f0e9..e5b5cb4ddeda 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py @@ -75,10 +75,10 @@ def to_dict(self) -> Dict[str, Any]: # override the default output from pydantic by calling `to_dict()` of each value in dict_property (dict of array) _field_dict_of_array = {} if self.dict_property: - for _key in self.dict_property: - if self.dict_property[_key] is not None: - _field_dict_of_array[_key] = [ - _item.to_dict() for _item in self.dict_property[_key] + for _key_dict_property in self.dict_property: + if self.dict_property[_key_dict_property] is not None: + _field_dict_of_array[_key_dict_property] = [ + _item.to_dict() for _item in self.dict_property[_key_dict_property] ] _dict['dictProperty'] = _field_dict_of_array # puts key-value pairs in additional_properties in the top level From 12ae860e4fecd8ce5b6d7b8e392cdf237393c15a Mon Sep 17 00:00:00 2001 From: Volodymyr Samokhatko Date: Mon, 22 Jul 2024 17:51:05 +0200 Subject: [PATCH 2/2] [python] mypy test for multiple arrays of objects --- ...ith-fake-endpoints-models-for-testing.yaml | 12 ++ .../python-aiohttp/.openapi-generator/FILES | 2 + .../client/petstore/python-aiohttp/README.md | 1 + .../python-aiohttp/docs/MultiArrays.md | 30 +++++ .../python-aiohttp/petstore_api/__init__.py | 1 + .../petstore_api/models/__init__.py | 1 + .../petstore_api/models/multi_arrays.py | 105 ++++++++++++++++ .../python-aiohttp/test/test_multi_arrays.py | 59 +++++++++ .../.openapi-generator/FILES | 2 + .../python-pydantic-v1-aiohttp/README.md | 1 + .../docs/MultiArrays.md | 29 +++++ .../petstore_api/__init__.py | 1 + .../petstore_api/models/__init__.py | 1 + .../petstore_api/models/multi_arrays.py | 89 +++++++++++++ .../test/test_multi_arrays.py | 60 +++++++++ .../.openapi-generator/FILES | 2 + .../petstore/python-pydantic-v1/README.md | 1 + .../python-pydantic-v1/docs/MultiArrays.md | 29 +++++ .../petstore_api/__init__.py | 1 + .../petstore_api/models/__init__.py | 1 + .../petstore_api/models/multi_arrays.py | 101 +++++++++++++++ .../test/test_multi_arrays.py | 60 +++++++++ .../petstore/python/.openapi-generator/FILES | 2 + .../openapi3/client/petstore/python/README.md | 1 + .../petstore/python/docs/MultiArrays.md | 30 +++++ .../petstore/python/petstore_api/__init__.py | 1 + .../python/petstore_api/models/__init__.py | 1 + .../petstore_api/models/multi_arrays.py | 118 ++++++++++++++++++ .../petstore/python/test/test_multi_arrays.py | 59 +++++++++ 29 files changed, 801 insertions(+) create mode 100644 samples/openapi3/client/petstore/python-aiohttp/docs/MultiArrays.md create mode 100644 samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/multi_arrays.py create mode 100644 samples/openapi3/client/petstore/python-aiohttp/test/test_multi_arrays.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/MultiArrays.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/multi_arrays.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_multi_arrays.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/docs/MultiArrays.md create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/multi_arrays.py create mode 100644 samples/openapi3/client/petstore/python-pydantic-v1/test/test_multi_arrays.py create mode 100644 samples/openapi3/client/petstore/python/docs/MultiArrays.md create mode 100644 samples/openapi3/client/petstore/python/petstore_api/models/multi_arrays.py create mode 100644 samples/openapi3/client/petstore/python/test/test_multi_arrays.py 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 51eb757d3746..e6fc5fbf6fc0 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 @@ -2253,6 +2253,18 @@ components: enum: - fish - crab + MultiArrays: + type: object + properties: + tags: + type: array + items: + $ref: '#/components/schemas/Tag' + files: + type: array + description: Another array of objects in addition to tags (mypy check to not to reuse the same iterator) + items: + $ref: '#/components/schemas/File' FreeFormObject: type: object description: A schema consisting only of additional properties diff --git a/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES index 8b7953128a76..36cb0392c334 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-aiohttp/.openapi-generator/FILES @@ -66,6 +66,7 @@ docs/Model200Response.md docs/ModelApiResponse.md docs/ModelField.md docs/ModelReturn.md +docs/MultiArrays.md docs/Name.md docs/NullableClass.md docs/NullableProperty.md @@ -188,6 +189,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/multi_arrays.py petstore_api/models/name.py petstore_api/models/nullable_class.py petstore_api/models/nullable_property.py diff --git a/samples/openapi3/client/petstore/python-aiohttp/README.md b/samples/openapi3/client/petstore/python-aiohttp/README.md index 16ef4e18c480..be1e071d723c 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/README.md +++ b/samples/openapi3/client/petstore/python-aiohttp/README.md @@ -208,6 +208,7 @@ Class | Method | HTTP request | Description - [ModelApiResponse](docs/ModelApiResponse.md) - [ModelField](docs/ModelField.md) - [ModelReturn](docs/ModelReturn.md) + - [MultiArrays](docs/MultiArrays.md) - [Name](docs/Name.md) - [NullableClass](docs/NullableClass.md) - [NullableProperty](docs/NullableProperty.md) diff --git a/samples/openapi3/client/petstore/python-aiohttp/docs/MultiArrays.md b/samples/openapi3/client/petstore/python-aiohttp/docs/MultiArrays.md new file mode 100644 index 000000000000..fea5139e7e73 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/docs/MultiArrays.md @@ -0,0 +1,30 @@ +# MultiArrays + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**tags** | [**List[Tag]**](Tag.md) | | [optional] +**files** | [**List[File]**](File.md) | Another array of objects in addition to tags (mypy check to not to reuse the same iterator) | [optional] + +## Example + +```python +from petstore_api.models.multi_arrays import MultiArrays + +# TODO update the JSON string below +json = "{}" +# create an instance of MultiArrays from a JSON string +multi_arrays_instance = MultiArrays.from_json(json) +# print the JSON string representation of the object +print(MultiArrays.to_json()) + +# convert the object into a dict +multi_arrays_dict = multi_arrays_instance.to_dict() +# create an instance of MultiArrays from a dict +multi_arrays_from_dict = MultiArrays.from_dict(multi_arrays_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 efc802ab039e..5c8b494eec36 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 @@ 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.multi_arrays import MultiArrays from petstore_api.models.name import Name from petstore_api.models.nullable_class import NullableClass from petstore_api.models.nullable_property import NullableProperty 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 22498dd88fcd..b1dbefee666d 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 @@ -72,6 +72,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.multi_arrays import MultiArrays from petstore_api.models.name import Name from petstore_api.models.nullable_class import NullableClass from petstore_api.models.nullable_property import NullableProperty diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/multi_arrays.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/multi_arrays.py new file mode 100644 index 000000000000..177a8359468f --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/multi_arrays.py @@ -0,0 +1,105 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + +from pydantic import BaseModel, ConfigDict, Field +from typing import Any, ClassVar, Dict, List, Optional +from petstore_api.models.file import File +from petstore_api.models.tag import Tag +from typing import Optional, Set +from typing_extensions import Self + +class MultiArrays(BaseModel): + """ + MultiArrays + """ # noqa: E501 + tags: Optional[List[Tag]] = None + files: Optional[List[File]] = Field(default=None, description="Another array of objects in addition to tags (mypy check to not to reuse the same iterator)") + __properties: ClassVar[List[str]] = ["tags", "files"] + + 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 MultiArrays from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self) -> Dict[str, Any]: + """Return the dictionary representation of the model using alias. + + This has the following differences from calling pydantic's + `self.model_dump(by_alias=True)`: + + * `None` is only added to the output dict for nullable fields that + were set at model initialization. Other fields with value `None` + are ignored. + """ + excluded_fields: Set[str] = set([ + ]) + + _dict = self.model_dump( + by_alias=True, + exclude=excluded_fields, + exclude_none=True, + ) + # override the default output from pydantic by calling `to_dict()` of each item in tags (list) + _items = [] + if self.tags: + for _item_tags in self.tags: + if _item_tags: + _items.append(_item_tags.to_dict()) + _dict['tags'] = _items + # override the default output from pydantic by calling `to_dict()` of each item in files (list) + _items = [] + if self.files: + for _item_files in self.files: + if _item_files: + _items.append(_item_files.to_dict()) + _dict['files'] = _items + return _dict + + @classmethod + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: + """Create an instance of MultiArrays from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "tags": [Tag.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None, + "files": [File.from_dict(_item) for _item in obj["files"]] if obj.get("files") is not None else None + }) + return _obj + + diff --git a/samples/openapi3/client/petstore/python-aiohttp/test/test_multi_arrays.py b/samples/openapi3/client/petstore/python-aiohttp/test/test_multi_arrays.py new file mode 100644 index 000000000000..bfd4f2998811 --- /dev/null +++ b/samples/openapi3/client/petstore/python-aiohttp/test/test_multi_arrays.py @@ -0,0 +1,59 @@ +# 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.multi_arrays import MultiArrays + +class TestMultiArrays(unittest.TestCase): + """MultiArrays unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> MultiArrays: + """Test MultiArrays + 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 `MultiArrays` + """ + model = MultiArrays() + if include_optional: + return MultiArrays( + tags = [ + petstore_api.models.tag.Tag( + id = 56, + name = '', ) + ], + files = [ + petstore_api.models.file.File( + source_uri = '', ) + ] + ) + else: + return MultiArrays( + ) + """ + + def testMultiArrays(self): + """Test MultiArrays""" + # 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 ae45c6c2c954..aa4a8eee280b 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 @@ -66,6 +66,7 @@ docs/MapTest.md docs/MixedPropertiesAndAdditionalPropertiesClass.md docs/Model200Response.md docs/ModelReturn.md +docs/MultiArrays.md docs/Name.md docs/NullableClass.md docs/NullableProperty.md @@ -188,6 +189,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/multi_arrays.py petstore_api/models/name.py petstore_api/models/nullable_class.py petstore_api/models/nullable_property.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 ae6bde4762c6..e7eccd1745db 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/README.md +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/README.md @@ -209,6 +209,7 @@ Class | Method | HTTP request | Description - [MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md) - [Model200Response](docs/Model200Response.md) - [ModelReturn](docs/ModelReturn.md) + - [MultiArrays](docs/MultiArrays.md) - [Name](docs/Name.md) - [NullableClass](docs/NullableClass.md) - [NullableProperty](docs/NullableProperty.md) diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/MultiArrays.md b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/MultiArrays.md new file mode 100644 index 000000000000..2b461769611c --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/docs/MultiArrays.md @@ -0,0 +1,29 @@ +# MultiArrays + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**tags** | [**List[Tag]**](Tag.md) | | [optional] +**files** | [**List[File]**](File.md) | Another array of objects in addition to tags (mypy check to not to reuse the same iterator) | [optional] + +## Example + +```python +from petstore_api.models.multi_arrays import MultiArrays + +# TODO update the JSON string below +json = "{}" +# create an instance of MultiArrays from a JSON string +multi_arrays_instance = MultiArrays.from_json(json) +# print the JSON string representation of the object +print MultiArrays.to_json() + +# convert the object into a dict +multi_arrays_dict = multi_arrays_instance.to_dict() +# create an instance of MultiArrays from a dict +multi_arrays_from_dict = MultiArrays.from_dict(multi_arrays_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 87a7d672b9a9..0d1b6af243ff 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 @@ 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.multi_arrays import MultiArrays from petstore_api.models.name import Name from petstore_api.models.nullable_class import NullableClass from petstore_api.models.nullable_property import NullableProperty 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 ffa70bc3422c..de87c281c8fb 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 @@ -72,6 +72,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.multi_arrays import MultiArrays from petstore_api.models.name import Name from petstore_api.models.nullable_class import NullableClass from petstore_api.models.nullable_property import NullableProperty diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/multi_arrays.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/multi_arrays.py new file mode 100644 index 000000000000..ce0acf8c8fda --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/petstore_api/models/multi_arrays.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 typing import List, Optional +from pydantic import BaseModel, Field, conlist +from petstore_api.models.file import File +from petstore_api.models.tag import Tag + +class MultiArrays(BaseModel): + """ + MultiArrays + """ + tags: Optional[conlist(Tag)] = None + files: Optional[conlist(File)] = Field(default=None, description="Another array of objects in addition to tags (mypy check to not to reuse the same iterator)") + __properties = ["tags", "files"] + + 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) -> MultiArrays: + """Create an instance of MultiArrays from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self): + """Returns the dictionary representation of the model using alias""" + _dict = self.dict(by_alias=True, + exclude={ + }, + exclude_none=True) + # override the default output from pydantic by calling `to_dict()` of each item in tags (list) + _items = [] + if self.tags: + for _item in self.tags: + if _item: + _items.append(_item.to_dict()) + _dict['tags'] = _items + # override the default output from pydantic by calling `to_dict()` of each item in files (list) + _items = [] + if self.files: + for _item in self.files: + if _item: + _items.append(_item.to_dict()) + _dict['files'] = _items + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> MultiArrays: + """Create an instance of MultiArrays from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return MultiArrays.parse_obj(obj) + + _obj = MultiArrays.parse_obj({ + "tags": [Tag.from_dict(_item) for _item in obj.get("tags")] if obj.get("tags") is not None else None, + "files": [File.from_dict(_item) for _item in obj.get("files")] if obj.get("files") is not None else None + }) + return _obj + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_multi_arrays.py b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_multi_arrays.py new file mode 100644 index 000000000000..a954d40b820e --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1-aiohttp/test/test_multi_arrays.py @@ -0,0 +1,60 @@ +# 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.multi_arrays import MultiArrays # noqa: E501 + +class TestMultiArrays(unittest.TestCase): + """MultiArrays unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> MultiArrays: + """Test MultiArrays + 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 `MultiArrays` + """ + model = MultiArrays() # noqa: E501 + if include_optional: + return MultiArrays( + tags = [ + petstore_api.models.tag.Tag( + id = 56, + name = '', ) + ], + files = [ + petstore_api.models.file.File( + source_uri = '', ) + ] + ) + else: + return MultiArrays( + ) + """ + + def testMultiArrays(self): + """Test MultiArrays""" + # 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 ae45c6c2c954..aa4a8eee280b 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-pydantic-v1/.openapi-generator/FILES @@ -66,6 +66,7 @@ docs/MapTest.md docs/MixedPropertiesAndAdditionalPropertiesClass.md docs/Model200Response.md docs/ModelReturn.md +docs/MultiArrays.md docs/Name.md docs/NullableClass.md docs/NullableProperty.md @@ -188,6 +189,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/multi_arrays.py petstore_api/models/name.py petstore_api/models/nullable_class.py petstore_api/models/nullable_property.py diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/README.md b/samples/openapi3/client/petstore/python-pydantic-v1/README.md index 8979b37db999..189a10bce21c 100644 --- a/samples/openapi3/client/petstore/python-pydantic-v1/README.md +++ b/samples/openapi3/client/petstore/python-pydantic-v1/README.md @@ -209,6 +209,7 @@ Class | Method | HTTP request | Description - [MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md) - [Model200Response](docs/Model200Response.md) - [ModelReturn](docs/ModelReturn.md) + - [MultiArrays](docs/MultiArrays.md) - [Name](docs/Name.md) - [NullableClass](docs/NullableClass.md) - [NullableProperty](docs/NullableProperty.md) diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/docs/MultiArrays.md b/samples/openapi3/client/petstore/python-pydantic-v1/docs/MultiArrays.md new file mode 100644 index 000000000000..2b461769611c --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/docs/MultiArrays.md @@ -0,0 +1,29 @@ +# MultiArrays + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**tags** | [**List[Tag]**](Tag.md) | | [optional] +**files** | [**List[File]**](File.md) | Another array of objects in addition to tags (mypy check to not to reuse the same iterator) | [optional] + +## Example + +```python +from petstore_api.models.multi_arrays import MultiArrays + +# TODO update the JSON string below +json = "{}" +# create an instance of MultiArrays from a JSON string +multi_arrays_instance = MultiArrays.from_json(json) +# print the JSON string representation of the object +print MultiArrays.to_json() + +# convert the object into a dict +multi_arrays_dict = multi_arrays_instance.to_dict() +# create an instance of MultiArrays from a dict +multi_arrays_from_dict = MultiArrays.from_dict(multi_arrays_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 87a7d672b9a9..0d1b6af243ff 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 @@ 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.multi_arrays import MultiArrays from petstore_api.models.name import Name from petstore_api.models.nullable_class import NullableClass from petstore_api.models.nullable_property import NullableProperty 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 ffa70bc3422c..de87c281c8fb 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 @@ -72,6 +72,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.multi_arrays import MultiArrays from petstore_api.models.name import Name from petstore_api.models.nullable_class import NullableClass from petstore_api.models.nullable_property import NullableProperty diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/multi_arrays.py b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/multi_arrays.py new file mode 100644 index 000000000000..f7bfff779303 --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/petstore_api/models/multi_arrays.py @@ -0,0 +1,101 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + + +from typing import Any, Dict, List, Optional +from pydantic import BaseModel, Field, conlist +from petstore_api.models.file import File +from petstore_api.models.tag import Tag + +class MultiArrays(BaseModel): + """ + MultiArrays + """ + tags: Optional[conlist(Tag)] = None + files: Optional[conlist(File)] = Field(default=None, description="Another array of objects in addition to tags (mypy check to not to reuse the same iterator)") + additional_properties: Dict[str, Any] = {} + __properties = ["tags", "files"] + + 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) -> MultiArrays: + """Create an instance of MultiArrays from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self): + """Returns the dictionary representation of the model using alias""" + _dict = self.dict(by_alias=True, + exclude={ + "additional_properties" + }, + exclude_none=True) + # override the default output from pydantic by calling `to_dict()` of each item in tags (list) + _items = [] + if self.tags: + for _item in self.tags: + if _item: + _items.append(_item.to_dict()) + _dict['tags'] = _items + # override the default output from pydantic by calling `to_dict()` of each item in files (list) + _items = [] + if self.files: + for _item in self.files: + if _item: + _items.append(_item.to_dict()) + _dict['files'] = _items + # 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) -> MultiArrays: + """Create an instance of MultiArrays from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return MultiArrays.parse_obj(obj) + + _obj = MultiArrays.parse_obj({ + "tags": [Tag.from_dict(_item) for _item in obj.get("tags")] if obj.get("tags") is not None else None, + "files": [File.from_dict(_item) for _item in obj.get("files")] if obj.get("files") is not None else None + }) + # store additional fields in additional_properties + for _key in obj.keys(): + if _key not in cls.__properties: + _obj.additional_properties[_key] = obj.get(_key) + + return _obj + + diff --git a/samples/openapi3/client/petstore/python-pydantic-v1/test/test_multi_arrays.py b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_multi_arrays.py new file mode 100644 index 000000000000..a954d40b820e --- /dev/null +++ b/samples/openapi3/client/petstore/python-pydantic-v1/test/test_multi_arrays.py @@ -0,0 +1,60 @@ +# 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.multi_arrays import MultiArrays # noqa: E501 + +class TestMultiArrays(unittest.TestCase): + """MultiArrays unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> MultiArrays: + """Test MultiArrays + 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 `MultiArrays` + """ + model = MultiArrays() # noqa: E501 + if include_optional: + return MultiArrays( + tags = [ + petstore_api.models.tag.Tag( + id = 56, + name = '', ) + ], + files = [ + petstore_api.models.file.File( + source_uri = '', ) + ] + ) + else: + return MultiArrays( + ) + """ + + def testMultiArrays(self): + """Test MultiArrays""" + # 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 8b7953128a76..36cb0392c334 100755 --- a/samples/openapi3/client/petstore/python/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python/.openapi-generator/FILES @@ -66,6 +66,7 @@ docs/Model200Response.md docs/ModelApiResponse.md docs/ModelField.md docs/ModelReturn.md +docs/MultiArrays.md docs/Name.md docs/NullableClass.md docs/NullableProperty.md @@ -188,6 +189,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/multi_arrays.py petstore_api/models/name.py petstore_api/models/nullable_class.py petstore_api/models/nullable_property.py diff --git a/samples/openapi3/client/petstore/python/README.md b/samples/openapi3/client/petstore/python/README.md index 524942ab9e35..321f2d163854 100755 --- a/samples/openapi3/client/petstore/python/README.md +++ b/samples/openapi3/client/petstore/python/README.md @@ -208,6 +208,7 @@ Class | Method | HTTP request | Description - [ModelApiResponse](docs/ModelApiResponse.md) - [ModelField](docs/ModelField.md) - [ModelReturn](docs/ModelReturn.md) + - [MultiArrays](docs/MultiArrays.md) - [Name](docs/Name.md) - [NullableClass](docs/NullableClass.md) - [NullableProperty](docs/NullableProperty.md) diff --git a/samples/openapi3/client/petstore/python/docs/MultiArrays.md b/samples/openapi3/client/petstore/python/docs/MultiArrays.md new file mode 100644 index 000000000000..fea5139e7e73 --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/MultiArrays.md @@ -0,0 +1,30 @@ +# MultiArrays + + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**tags** | [**List[Tag]**](Tag.md) | | [optional] +**files** | [**List[File]**](File.md) | Another array of objects in addition to tags (mypy check to not to reuse the same iterator) | [optional] + +## Example + +```python +from petstore_api.models.multi_arrays import MultiArrays + +# TODO update the JSON string below +json = "{}" +# create an instance of MultiArrays from a JSON string +multi_arrays_instance = MultiArrays.from_json(json) +# print the JSON string representation of the object +print(MultiArrays.to_json()) + +# convert the object into a dict +multi_arrays_dict = multi_arrays_instance.to_dict() +# create an instance of MultiArrays from a dict +multi_arrays_from_dict = MultiArrays.from_dict(multi_arrays_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 efc802ab039e..5c8b494eec36 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 @@ 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.multi_arrays import MultiArrays from petstore_api.models.name import Name from petstore_api.models.nullable_class import NullableClass from petstore_api.models.nullable_property import NullableProperty 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 22498dd88fcd..b1dbefee666d 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py @@ -72,6 +72,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.multi_arrays import MultiArrays from petstore_api.models.name import Name from petstore_api.models.nullable_class import NullableClass from petstore_api.models.nullable_property import NullableProperty diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/multi_arrays.py b/samples/openapi3/client/petstore/python/petstore_api/models/multi_arrays.py new file mode 100644 index 000000000000..80fa67f8a11c --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/models/multi_arrays.py @@ -0,0 +1,118 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + +from pydantic import BaseModel, ConfigDict, Field +from typing import Any, ClassVar, Dict, List, Optional +from petstore_api.models.file import File +from petstore_api.models.tag import Tag +from typing import Optional, Set +from typing_extensions import Self + +class MultiArrays(BaseModel): + """ + MultiArrays + """ # noqa: E501 + tags: Optional[List[Tag]] = None + files: Optional[List[File]] = Field(default=None, description="Another array of objects in addition to tags (mypy check to not to reuse the same iterator)") + additional_properties: Dict[str, Any] = {} + __properties: ClassVar[List[str]] = ["tags", "files"] + + 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 MultiArrays from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self) -> Dict[str, Any]: + """Return the dictionary representation of the model using alias. + + This has the following differences from calling pydantic's + `self.model_dump(by_alias=True)`: + + * `None` is only added to the output dict for nullable fields that + were set at model initialization. Other fields with value `None` + are ignored. + * Fields in `self.additional_properties` are added to the output dict. + """ + excluded_fields: Set[str] = set([ + "additional_properties", + ]) + + _dict = self.model_dump( + by_alias=True, + exclude=excluded_fields, + exclude_none=True, + ) + # override the default output from pydantic by calling `to_dict()` of each item in tags (list) + _items = [] + if self.tags: + for _item_tags in self.tags: + if _item_tags: + _items.append(_item_tags.to_dict()) + _dict['tags'] = _items + # override the default output from pydantic by calling `to_dict()` of each item in files (list) + _items = [] + if self.files: + for _item_files in self.files: + if _item_files: + _items.append(_item_files.to_dict()) + _dict['files'] = _items + # 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 MultiArrays from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate({ + "tags": [Tag.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None, + "files": [File.from_dict(_item) for _item in obj["files"]] if obj.get("files") is not None else None + }) + # store additional fields in additional_properties + for _key in obj.keys(): + if _key not in cls.__properties: + _obj.additional_properties[_key] = obj.get(_key) + + return _obj + + diff --git a/samples/openapi3/client/petstore/python/test/test_multi_arrays.py b/samples/openapi3/client/petstore/python/test/test_multi_arrays.py new file mode 100644 index 000000000000..bfd4f2998811 --- /dev/null +++ b/samples/openapi3/client/petstore/python/test/test_multi_arrays.py @@ -0,0 +1,59 @@ +# 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.multi_arrays import MultiArrays + +class TestMultiArrays(unittest.TestCase): + """MultiArrays unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> MultiArrays: + """Test MultiArrays + 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 `MultiArrays` + """ + model = MultiArrays() + if include_optional: + return MultiArrays( + tags = [ + petstore_api.models.tag.Tag( + id = 56, + name = '', ) + ], + files = [ + petstore_api.models.file.File( + source_uri = '', ) + ] + ) + else: + return MultiArrays( + ) + """ + + def testMultiArrays(self): + """Test MultiArrays""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main()