-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[python] Fix unnamed dicts with additional properties (#16779)
* test: Add two extra models for testing * Fix unnamed dicts with additional properties Closes #16630
- Loading branch information
1 parent
7af4593
commit f180aa0
Showing
45 changed files
with
1,500 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...nt/petstore/python-aiohttp/docs/UnnamedDictWithAdditionalModelListProperties.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# UnnamedDictWithAdditionalModelListProperties | ||
|
||
|
||
## Properties | ||
Name | Type | Description | Notes | ||
------------ | ------------- | ------------- | ------------- | ||
**dict_property** | **Dict[str, List[CreatureInfo]]** | | [optional] | ||
|
||
## Example | ||
|
||
```python | ||
from petstore_api.models.unnamed_dict_with_additional_model_list_properties import UnnamedDictWithAdditionalModelListProperties | ||
|
||
# TODO update the JSON string below | ||
json = "{}" | ||
# create an instance of UnnamedDictWithAdditionalModelListProperties from a JSON string | ||
unnamed_dict_with_additional_model_list_properties_instance = UnnamedDictWithAdditionalModelListProperties.from_json(json) | ||
# print the JSON string representation of the object | ||
print UnnamedDictWithAdditionalModelListProperties.to_json() | ||
|
||
# convert the object into a dict | ||
unnamed_dict_with_additional_model_list_properties_dict = unnamed_dict_with_additional_model_list_properties_instance.to_dict() | ||
# create an instance of UnnamedDictWithAdditionalModelListProperties from a dict | ||
unnamed_dict_with_additional_model_list_properties_form_dict = unnamed_dict_with_additional_model_list_properties.from_dict(unnamed_dict_with_additional_model_list_properties_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) | ||
|
||
|
28 changes: 28 additions & 0 deletions
28
...t/petstore/python-aiohttp/docs/UnnamedDictWithAdditionalStringListProperties.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# UnnamedDictWithAdditionalStringListProperties | ||
|
||
|
||
## Properties | ||
Name | Type | Description | Notes | ||
------------ | ------------- | ------------- | ------------- | ||
**dict_property** | **Dict[str, List[str]]** | | [optional] | ||
|
||
## Example | ||
|
||
```python | ||
from petstore_api.models.unnamed_dict_with_additional_string_list_properties import UnnamedDictWithAdditionalStringListProperties | ||
|
||
# TODO update the JSON string below | ||
json = "{}" | ||
# create an instance of UnnamedDictWithAdditionalStringListProperties from a JSON string | ||
unnamed_dict_with_additional_string_list_properties_instance = UnnamedDictWithAdditionalStringListProperties.from_json(json) | ||
# print the JSON string representation of the object | ||
print UnnamedDictWithAdditionalStringListProperties.to_json() | ||
|
||
# convert the object into a dict | ||
unnamed_dict_with_additional_string_list_properties_dict = unnamed_dict_with_additional_string_list_properties_instance.to_dict() | ||
# create an instance of UnnamedDictWithAdditionalStringListProperties from a dict | ||
unnamed_dict_with_additional_string_list_properties_form_dict = unnamed_dict_with_additional_string_list_properties.from_dict(unnamed_dict_with_additional_string_list_properties_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) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
.../python-aiohttp/petstore_api/models/unnamed_dict_with_additional_model_list_properties.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# 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 | ||
from pydantic import Field | ||
from petstore_api.models.creature_info import CreatureInfo | ||
from typing import Dict, Any | ||
try: | ||
from typing import Self | ||
except ImportError: | ||
from typing_extensions import Self | ||
|
||
class UnnamedDictWithAdditionalModelListProperties(BaseModel): | ||
""" | ||
UnnamedDictWithAdditionalModelListProperties | ||
""" | ||
dict_property: Optional[Dict[str, List[CreatureInfo]]] = Field(default=None, alias="dictProperty") | ||
__properties: ClassVar[List[str]] = ["dictProperty"] | ||
|
||
model_config = { | ||
"populate_by_name": True, | ||
"validate_assignment": True | ||
} | ||
|
||
|
||
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) -> Self: | ||
"""Create an instance of UnnamedDictWithAdditionalModelListProperties 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.model_dump(by_alias=True, | ||
exclude={ | ||
}, | ||
exclude_none=True) | ||
# 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] | ||
] | ||
_dict['dictProperty'] = _field_dict_of_array | ||
return _dict | ||
|
||
@classmethod | ||
def from_dict(cls, obj: dict) -> Self: | ||
"""Create an instance of UnnamedDictWithAdditionalModelListProperties from a dict""" | ||
if obj is None: | ||
return None | ||
|
||
if not isinstance(obj, dict): | ||
return cls.model_validate(obj) | ||
|
||
_obj = cls.model_validate({ | ||
"dictProperty": dict( | ||
(_k, | ||
[CreatureInfo.from_dict(_item) for _item in _v] | ||
if _v is not None | ||
else None | ||
) | ||
for _k, _v in obj.get("dictProperty").items() | ||
) | ||
}) | ||
return _obj | ||
|
||
|
79 changes: 79 additions & 0 deletions
79
...python-aiohttp/petstore_api/models/unnamed_dict_with_additional_string_list_properties.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# 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 | ||
from pydantic import Field | ||
from typing import Dict, Any | ||
try: | ||
from typing import Self | ||
except ImportError: | ||
from typing_extensions import Self | ||
|
||
class UnnamedDictWithAdditionalStringListProperties(BaseModel): | ||
""" | ||
UnnamedDictWithAdditionalStringListProperties | ||
""" | ||
dict_property: Optional[Dict[str, List[StrictStr]]] = Field(default=None, alias="dictProperty") | ||
__properties: ClassVar[List[str]] = ["dictProperty"] | ||
|
||
model_config = { | ||
"populate_by_name": True, | ||
"validate_assignment": True | ||
} | ||
|
||
|
||
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) -> Self: | ||
"""Create an instance of UnnamedDictWithAdditionalStringListProperties 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.model_dump(by_alias=True, | ||
exclude={ | ||
}, | ||
exclude_none=True) | ||
return _dict | ||
|
||
@classmethod | ||
def from_dict(cls, obj: dict) -> Self: | ||
"""Create an instance of UnnamedDictWithAdditionalStringListProperties from a dict""" | ||
if obj is None: | ||
return None | ||
|
||
if not isinstance(obj, dict): | ||
return cls.model_validate(obj) | ||
|
||
_obj = cls.model_validate({ | ||
"dictProperty": obj.get("dictProperty") | ||
}) | ||
return _obj | ||
|
||
|
57 changes: 57 additions & 0 deletions
57
...t/petstore/python-aiohttp/test/test_unnamed_dict_with_additional_model_list_properties.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.unnamed_dict_with_additional_model_list_properties import UnnamedDictWithAdditionalModelListProperties # noqa: E501 | ||
|
||
class TestUnnamedDictWithAdditionalModelListProperties(unittest.TestCase): | ||
"""UnnamedDictWithAdditionalModelListProperties unit test stubs""" | ||
|
||
def setUp(self): | ||
pass | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def make_instance(self, include_optional) -> UnnamedDictWithAdditionalModelListProperties: | ||
"""Test UnnamedDictWithAdditionalModelListProperties | ||
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 `UnnamedDictWithAdditionalModelListProperties` | ||
""" | ||
model = UnnamedDictWithAdditionalModelListProperties() # noqa: E501 | ||
if include_optional: | ||
return UnnamedDictWithAdditionalModelListProperties( | ||
dict_property = { | ||
'key' : [ | ||
petstore_api.models.creature_info.CreatureInfo( | ||
name = '', ) | ||
] | ||
} | ||
) | ||
else: | ||
return UnnamedDictWithAdditionalModelListProperties( | ||
) | ||
""" | ||
|
||
def testUnnamedDictWithAdditionalModelListProperties(self): | ||
"""Test UnnamedDictWithAdditionalModelListProperties""" | ||
# inst_req_only = self.make_instance(include_optional=False) | ||
# inst_req_and_optional = self.make_instance(include_optional=True) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.