forked from loafle/openapi-generator-original
[python] Fix unnamed dicts with additional properties (#16779)
* test: Add two extra models for testing * Fix unnamed dicts with additional properties Closes #16630
This commit is contained in:
@@ -86,6 +86,8 @@ docs/StoreApi.md
|
||||
docs/Tag.md
|
||||
docs/TestInlineFreeformAdditionalPropertiesRequest.md
|
||||
docs/Tiger.md
|
||||
docs/UnnamedDictWithAdditionalModelListProperties.md
|
||||
docs/UnnamedDictWithAdditionalStringListProperties.md
|
||||
docs/User.md
|
||||
docs/UserApi.md
|
||||
docs/WithNestedOneOf.md
|
||||
@@ -181,6 +183,8 @@ petstore_api/models/special_name.py
|
||||
petstore_api/models/tag.py
|
||||
petstore_api/models/test_inline_freeform_additional_properties_request.py
|
||||
petstore_api/models/tiger.py
|
||||
petstore_api/models/unnamed_dict_with_additional_model_list_properties.py
|
||||
petstore_api/models/unnamed_dict_with_additional_string_list_properties.py
|
||||
petstore_api/models/user.py
|
||||
petstore_api/models/with_nested_one_of.py
|
||||
petstore_api/py.typed
|
||||
|
||||
@@ -212,6 +212,8 @@ Class | Method | HTTP request | Description
|
||||
- [Tag](docs/Tag.md)
|
||||
- [TestInlineFreeformAdditionalPropertiesRequest](docs/TestInlineFreeformAdditionalPropertiesRequest.md)
|
||||
- [Tiger](docs/Tiger.md)
|
||||
- [UnnamedDictWithAdditionalModelListProperties](docs/UnnamedDictWithAdditionalModelListProperties.md)
|
||||
- [UnnamedDictWithAdditionalStringListProperties](docs/UnnamedDictWithAdditionalStringListProperties.md)
|
||||
- [User](docs/User.md)
|
||||
- [WithNestedOneOf](docs/WithNestedOneOf.md)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -115,5 +115,7 @@ from petstore_api.models.special_name import SpecialName
|
||||
from petstore_api.models.tag import Tag
|
||||
from petstore_api.models.test_inline_freeform_additional_properties_request import TestInlineFreeformAdditionalPropertiesRequest
|
||||
from petstore_api.models.tiger import Tiger
|
||||
from petstore_api.models.unnamed_dict_with_additional_model_list_properties import UnnamedDictWithAdditionalModelListProperties
|
||||
from petstore_api.models.unnamed_dict_with_additional_string_list_properties import UnnamedDictWithAdditionalStringListProperties
|
||||
from petstore_api.models.user import User
|
||||
from petstore_api.models.with_nested_one_of import WithNestedOneOf
|
||||
|
||||
@@ -91,5 +91,7 @@ from petstore_api.models.special_name import SpecialName
|
||||
from petstore_api.models.tag import Tag
|
||||
from petstore_api.models.test_inline_freeform_additional_properties_request import TestInlineFreeformAdditionalPropertiesRequest
|
||||
from petstore_api.models.tiger import Tiger
|
||||
from petstore_api.models.unnamed_dict_with_additional_model_list_properties import UnnamedDictWithAdditionalModelListProperties
|
||||
from petstore_api.models.unnamed_dict_with_additional_string_list_properties import UnnamedDictWithAdditionalStringListProperties
|
||||
from petstore_api.models.user import User
|
||||
from petstore_api.models.with_nested_one_of import WithNestedOneOf
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
# coding: utf-8
|
||||
|
||||
"""
|
||||
OpenAPI Petstore
|
||||
|
||||
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||
|
||||
Do not edit the class manually.
|
||||
""" # noqa: E501
|
||||
|
||||
|
||||
from __future__ import annotations
|
||||
import pprint
|
||||
import re # noqa: F401
|
||||
import json
|
||||
|
||||
|
||||
from typing import Dict, List, Optional
|
||||
from pydantic import BaseModel, Field, conlist
|
||||
from petstore_api.models.creature_info import CreatureInfo
|
||||
|
||||
class UnnamedDictWithAdditionalModelListProperties(BaseModel):
|
||||
"""
|
||||
UnnamedDictWithAdditionalModelListProperties
|
||||
"""
|
||||
dict_property: Optional[Dict[str, conlist(CreatureInfo)]] = Field(None, alias="dictProperty")
|
||||
__properties = ["dictProperty"]
|
||||
|
||||
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) -> UnnamedDictWithAdditionalModelListProperties:
|
||||
"""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.dict(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]:
|
||||
_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) -> UnnamedDictWithAdditionalModelListProperties:
|
||||
"""Create an instance of UnnamedDictWithAdditionalModelListProperties from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return UnnamedDictWithAdditionalModelListProperties.parse_obj(obj)
|
||||
|
||||
_obj = UnnamedDictWithAdditionalModelListProperties.parse_obj({
|
||||
"dict_property": 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
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
# 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, Field, StrictStr, conlist
|
||||
|
||||
class UnnamedDictWithAdditionalStringListProperties(BaseModel):
|
||||
"""
|
||||
UnnamedDictWithAdditionalStringListProperties
|
||||
"""
|
||||
dict_property: Optional[Dict[str, conlist(StrictStr)]] = Field(None, alias="dictProperty")
|
||||
__properties = ["dictProperty"]
|
||||
|
||||
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) -> UnnamedDictWithAdditionalStringListProperties:
|
||||
"""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.dict(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]:
|
||||
_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) -> UnnamedDictWithAdditionalStringListProperties:
|
||||
"""Create an instance of UnnamedDictWithAdditionalStringListProperties from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if not isinstance(obj, dict):
|
||||
return UnnamedDictWithAdditionalStringListProperties.parse_obj(obj)
|
||||
|
||||
_obj = UnnamedDictWithAdditionalStringListProperties.parse_obj({
|
||||
"dict_property": obj.get("dictProperty")
|
||||
})
|
||||
return _obj
|
||||
|
||||
|
||||
@@ -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()
|
||||
@@ -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
|
||||
import datetime
|
||||
|
||||
from petstore_api.models.unnamed_dict_with_additional_string_list_properties import UnnamedDictWithAdditionalStringListProperties # noqa: E501
|
||||
|
||||
class TestUnnamedDictWithAdditionalStringListProperties(unittest.TestCase):
|
||||
"""UnnamedDictWithAdditionalStringListProperties unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def make_instance(self, include_optional) -> UnnamedDictWithAdditionalStringListProperties:
|
||||
"""Test UnnamedDictWithAdditionalStringListProperties
|
||||
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 `UnnamedDictWithAdditionalStringListProperties`
|
||||
"""
|
||||
model = UnnamedDictWithAdditionalStringListProperties() # noqa: E501
|
||||
if include_optional:
|
||||
return UnnamedDictWithAdditionalStringListProperties(
|
||||
dict_property = {
|
||||
'key' : [
|
||||
''
|
||||
]
|
||||
}
|
||||
)
|
||||
else:
|
||||
return UnnamedDictWithAdditionalStringListProperties(
|
||||
)
|
||||
"""
|
||||
|
||||
def testUnnamedDictWithAdditionalStringListProperties(self):
|
||||
"""Test UnnamedDictWithAdditionalStringListProperties"""
|
||||
# inst_req_only = self.make_instance(include_optional=False)
|
||||
# inst_req_and_optional = self.make_instance(include_optional=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user