forked from loafle/openapi-generator-original
[python-nextgen] fix optional dict in property (#15009)
* fix optional dict in property * update samples
This commit is contained in:
parent
88da3649b2
commit
cf432522aa
@ -220,7 +220,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
|
||||
{{#isMap}}
|
||||
{{^items.isPrimitiveType}}
|
||||
{{^items.isEnumOrRef}}
|
||||
"{{{name}}}": dict((_k, {{{dataType}}}.from_dict(_v)) for _k, _v in obj.get("{{{baseName}}}").items()){{^-last}},{{/-last}}
|
||||
"{{{name}}}": dict((_k, {{{dataType}}}.from_dict(_v)) for _k, _v in obj.get("{{{baseName}}}").items()) if obj.get("{{{baseName}}}") is not None else None{{^-last}},{{/-last}}
|
||||
{{/items.isEnumOrRef}}
|
||||
{{#items.isEnumOrRef}}
|
||||
"{{{name}}}": dict((_k, _v) for _k, _v in obj.get("{{{baseName}}}").items()){{^-last}},{{/-last}}
|
||||
|
@ -2109,3 +2109,17 @@ components:
|
||||
- $ref: '#/components/schemas/RgbColor'
|
||||
- $ref: '#/components/schemas/RgbaColor'
|
||||
- $ref: '#/components/schemas/HexColor'
|
||||
InnerDictWithProperty:
|
||||
type: object
|
||||
properties:
|
||||
aProperty:
|
||||
type: object
|
||||
DictWithAdditionalProperties:
|
||||
type: object
|
||||
additionalProperties:
|
||||
$ref: "#/components/schemas/InnerDictWithProperty"
|
||||
ParentWithOptionalDict:
|
||||
type: object
|
||||
properties:
|
||||
optionalDict:
|
||||
$ref: "#/components/schemas/DictWithAdditionalProperties"
|
||||
|
@ -39,6 +39,7 @@ docs/FooGetDefaultResponse.md
|
||||
docs/FormatTest.md
|
||||
docs/HasOnlyReadOnly.md
|
||||
docs/HealthCheckResult.md
|
||||
docs/InnerDictWithProperty.md
|
||||
docs/List.md
|
||||
docs/MapTest.md
|
||||
docs/MixedPropertiesAndAdditionalPropertiesClass.md
|
||||
@ -55,6 +56,7 @@ docs/OuterEnumDefaultValue.md
|
||||
docs/OuterEnumInteger.md
|
||||
docs/OuterEnumIntegerDefaultValue.md
|
||||
docs/OuterObjectWithEnumProperty.md
|
||||
docs/ParentWithOptionalDict.md
|
||||
docs/Pet.md
|
||||
docs/PetApi.md
|
||||
docs/Pig.md
|
||||
@ -115,6 +117,7 @@ petstore_api/models/foo_get_default_response.py
|
||||
petstore_api/models/format_test.py
|
||||
petstore_api/models/has_only_read_only.py
|
||||
petstore_api/models/health_check_result.py
|
||||
petstore_api/models/inner_dict_with_property.py
|
||||
petstore_api/models/list.py
|
||||
petstore_api/models/map_test.py
|
||||
petstore_api/models/mixed_properties_and_additional_properties_class.py
|
||||
@ -131,6 +134,7 @@ petstore_api/models/outer_enum_default_value.py
|
||||
petstore_api/models/outer_enum_integer.py
|
||||
petstore_api/models/outer_enum_integer_default_value.py
|
||||
petstore_api/models/outer_object_with_enum_property.py
|
||||
petstore_api/models/parent_with_optional_dict.py
|
||||
petstore_api/models/pet.py
|
||||
petstore_api/models/pig.py
|
||||
petstore_api/models/read_only_first.py
|
||||
|
@ -164,6 +164,7 @@ Class | Method | HTTP request | Description
|
||||
- [FormatTest](docs/FormatTest.md)
|
||||
- [HasOnlyReadOnly](docs/HasOnlyReadOnly.md)
|
||||
- [HealthCheckResult](docs/HealthCheckResult.md)
|
||||
- [InnerDictWithProperty](docs/InnerDictWithProperty.md)
|
||||
- [List](docs/List.md)
|
||||
- [MapTest](docs/MapTest.md)
|
||||
- [MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md)
|
||||
@ -180,6 +181,7 @@ Class | Method | HTTP request | Description
|
||||
- [OuterEnumInteger](docs/OuterEnumInteger.md)
|
||||
- [OuterEnumIntegerDefaultValue](docs/OuterEnumIntegerDefaultValue.md)
|
||||
- [OuterObjectWithEnumProperty](docs/OuterObjectWithEnumProperty.md)
|
||||
- [ParentWithOptionalDict](docs/ParentWithOptionalDict.md)
|
||||
- [Pet](docs/Pet.md)
|
||||
- [Pig](docs/Pig.md)
|
||||
- [ReadOnlyFirst](docs/ReadOnlyFirst.md)
|
||||
|
@ -0,0 +1,28 @@
|
||||
# InnerDictWithProperty
|
||||
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**a_property** | **object** | | [optional]
|
||||
|
||||
## Example
|
||||
|
||||
```python
|
||||
from petstore_api.models.inner_dict_with_property import InnerDictWithProperty
|
||||
|
||||
# TODO update the JSON string below
|
||||
json = "{}"
|
||||
# create an instance of InnerDictWithProperty from a JSON string
|
||||
inner_dict_with_property_instance = InnerDictWithProperty.from_json(json)
|
||||
# print the JSON string representation of the object
|
||||
print InnerDictWithProperty.to_json()
|
||||
|
||||
# convert the object into a dict
|
||||
inner_dict_with_property_dict = inner_dict_with_property_instance.to_dict()
|
||||
# create an instance of InnerDictWithProperty from a dict
|
||||
inner_dict_with_property_form_dict = inner_dict_with_property.from_dict(inner_dict_with_property_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 @@
|
||||
# ParentWithOptionalDict
|
||||
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**optional_dict** | [**Dict[str, InnerDictWithProperty]**](InnerDictWithProperty.md) | | [optional]
|
||||
|
||||
## Example
|
||||
|
||||
```python
|
||||
from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict
|
||||
|
||||
# TODO update the JSON string below
|
||||
json = "{}"
|
||||
# create an instance of ParentWithOptionalDict from a JSON string
|
||||
parent_with_optional_dict_instance = ParentWithOptionalDict.from_json(json)
|
||||
# print the JSON string representation of the object
|
||||
print ParentWithOptionalDict.to_json()
|
||||
|
||||
# convert the object into a dict
|
||||
parent_with_optional_dict_dict = parent_with_optional_dict_instance.to_dict()
|
||||
# create an instance of ParentWithOptionalDict from a dict
|
||||
parent_with_optional_dict_form_dict = parent_with_optional_dict.from_dict(parent_with_optional_dict_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)
|
||||
|
||||
|
@ -69,6 +69,7 @@ from petstore_api.models.foo_get_default_response import FooGetDefaultResponse
|
||||
from petstore_api.models.format_test import FormatTest
|
||||
from petstore_api.models.has_only_read_only import HasOnlyReadOnly
|
||||
from petstore_api.models.health_check_result import HealthCheckResult
|
||||
from petstore_api.models.inner_dict_with_property import InnerDictWithProperty
|
||||
from petstore_api.models.list import List
|
||||
from petstore_api.models.map_test import MapTest
|
||||
from petstore_api.models.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass
|
||||
@ -85,6 +86,7 @@ from petstore_api.models.outer_enum_default_value import OuterEnumDefaultValue
|
||||
from petstore_api.models.outer_enum_integer import OuterEnumInteger
|
||||
from petstore_api.models.outer_enum_integer_default_value import OuterEnumIntegerDefaultValue
|
||||
from petstore_api.models.outer_object_with_enum_property import OuterObjectWithEnumProperty
|
||||
from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict
|
||||
from petstore_api.models.pet import Pet
|
||||
from petstore_api.models.pig import Pig
|
||||
from petstore_api.models.read_only_first import ReadOnlyFirst
|
||||
|
@ -48,6 +48,7 @@ from petstore_api.models.foo_get_default_response import FooGetDefaultResponse
|
||||
from petstore_api.models.format_test import FormatTest
|
||||
from petstore_api.models.has_only_read_only import HasOnlyReadOnly
|
||||
from petstore_api.models.health_check_result import HealthCheckResult
|
||||
from petstore_api.models.inner_dict_with_property import InnerDictWithProperty
|
||||
from petstore_api.models.list import List
|
||||
from petstore_api.models.map_test import MapTest
|
||||
from petstore_api.models.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass
|
||||
@ -64,6 +65,7 @@ from petstore_api.models.outer_enum_default_value import OuterEnumDefaultValue
|
||||
from petstore_api.models.outer_enum_integer import OuterEnumInteger
|
||||
from petstore_api.models.outer_enum_integer_default_value import OuterEnumIntegerDefaultValue
|
||||
from petstore_api.models.outer_object_with_enum_property import OuterObjectWithEnumProperty
|
||||
from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict
|
||||
from petstore_api.models.pet import Pet
|
||||
from petstore_api.models.pig import Pig
|
||||
from petstore_api.models.read_only_first import ReadOnlyFirst
|
||||
|
@ -0,0 +1,70 @@
|
||||
# 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: \" \\ # noqa: E501
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
|
||||
from __future__ import annotations
|
||||
from inspect import getfullargspec
|
||||
import pprint
|
||||
import re # noqa: F401
|
||||
import json
|
||||
|
||||
|
||||
from typing import Any, Dict, Optional
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
class InnerDictWithProperty(BaseModel):
|
||||
"""
|
||||
InnerDictWithProperty
|
||||
"""
|
||||
a_property: Optional[Dict[str, Any]] = Field(None, alias="aProperty")
|
||||
__properties = ["aProperty"]
|
||||
|
||||
class Config:
|
||||
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) -> InnerDictWithProperty:
|
||||
"""Create an instance of InnerDictWithProperty from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
def to_dict(self):
|
||||
"""Returns the dictionary representation of the model using alias"""
|
||||
_dict = self.dict(by_alias=True,
|
||||
exclude={
|
||||
},
|
||||
exclude_none=True)
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> InnerDictWithProperty:
|
||||
"""Create an instance of InnerDictWithProperty from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if type(obj) is not dict:
|
||||
return InnerDictWithProperty.parse_obj(obj)
|
||||
|
||||
_obj = InnerDictWithProperty.parse_obj({
|
||||
"a_property": obj.get("aProperty")
|
||||
})
|
||||
return _obj
|
||||
|
@ -76,7 +76,7 @@ class MixedPropertiesAndAdditionalPropertiesClass(BaseModel):
|
||||
_obj = MixedPropertiesAndAdditionalPropertiesClass.parse_obj({
|
||||
"uuid": obj.get("uuid"),
|
||||
"date_time": obj.get("dateTime"),
|
||||
"map": dict((_k, Dict[str, Animal].from_dict(_v)) for _k, _v in obj.get("map").items())
|
||||
"map": dict((_k, Dict[str, Animal].from_dict(_v)) for _k, _v in obj.get("map").items()) if obj.get("map") is not None else None
|
||||
})
|
||||
return _obj
|
||||
|
||||
|
@ -0,0 +1,78 @@
|
||||
# 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: \" \\ # noqa: E501
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
|
||||
from __future__ import annotations
|
||||
from inspect import getfullargspec
|
||||
import pprint
|
||||
import re # noqa: F401
|
||||
import json
|
||||
|
||||
|
||||
from typing import Dict, Optional
|
||||
from pydantic import BaseModel, Field
|
||||
from petstore_api.models.inner_dict_with_property import InnerDictWithProperty
|
||||
|
||||
class ParentWithOptionalDict(BaseModel):
|
||||
"""
|
||||
ParentWithOptionalDict
|
||||
"""
|
||||
optional_dict: Optional[Dict[str, InnerDictWithProperty]] = Field(None, alias="optionalDict")
|
||||
__properties = ["optionalDict"]
|
||||
|
||||
class Config:
|
||||
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) -> ParentWithOptionalDict:
|
||||
"""Create an instance of ParentWithOptionalDict 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 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()
|
||||
_dict['optionalDict'] = _field_dict
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> ParentWithOptionalDict:
|
||||
"""Create an instance of ParentWithOptionalDict from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if type(obj) is not dict:
|
||||
return ParentWithOptionalDict.parse_obj(obj)
|
||||
|
||||
_obj = ParentWithOptionalDict.parse_obj({
|
||||
"optional_dict": dict((_k, Dict[str, InnerDictWithProperty].from_dict(_v)) for _k, _v in obj.get("optionalDict").items()) if obj.get("optionalDict") is not None else None
|
||||
})
|
||||
return _obj
|
||||
|
@ -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: \" \\ # noqa: E501
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import unittest
|
||||
import datetime
|
||||
|
||||
import petstore_api
|
||||
from petstore_api.models.inner_dict_with_property import InnerDictWithProperty # noqa: E501
|
||||
from petstore_api.rest import ApiException
|
||||
|
||||
class TestInnerDictWithProperty(unittest.TestCase):
|
||||
"""InnerDictWithProperty unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def make_instance(self, include_optional):
|
||||
"""Test InnerDictWithProperty
|
||||
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 `InnerDictWithProperty`
|
||||
"""
|
||||
model = petstore_api.models.inner_dict_with_property.InnerDictWithProperty() # noqa: E501
|
||||
if include_optional :
|
||||
return InnerDictWithProperty(
|
||||
a_property = None
|
||||
)
|
||||
else :
|
||||
return InnerDictWithProperty(
|
||||
)
|
||||
"""
|
||||
|
||||
def testInnerDictWithProperty(self):
|
||||
"""Test InnerDictWithProperty"""
|
||||
# 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,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: \" \\ # noqa: E501
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import unittest
|
||||
import datetime
|
||||
|
||||
import petstore_api
|
||||
from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict # noqa: E501
|
||||
from petstore_api.rest import ApiException
|
||||
|
||||
class TestParentWithOptionalDict(unittest.TestCase):
|
||||
"""ParentWithOptionalDict unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def make_instance(self, include_optional):
|
||||
"""Test ParentWithOptionalDict
|
||||
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 `ParentWithOptionalDict`
|
||||
"""
|
||||
model = petstore_api.models.parent_with_optional_dict.ParentWithOptionalDict() # noqa: E501
|
||||
if include_optional :
|
||||
return ParentWithOptionalDict(
|
||||
optional_dict = {
|
||||
'key' : petstore_api.models.inner_dict_with_property.InnerDictWithProperty(
|
||||
a_property = petstore_api.models.a_property.aProperty(), )
|
||||
}
|
||||
)
|
||||
else :
|
||||
return ParentWithOptionalDict(
|
||||
)
|
||||
"""
|
||||
|
||||
def testParentWithOptionalDict(self):
|
||||
"""Test ParentWithOptionalDict"""
|
||||
# inst_req_only = self.make_instance(include_optional=False)
|
||||
# inst_req_and_optional = self.make_instance(include_optional=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
@ -39,6 +39,7 @@ docs/FooGetDefaultResponse.md
|
||||
docs/FormatTest.md
|
||||
docs/HasOnlyReadOnly.md
|
||||
docs/HealthCheckResult.md
|
||||
docs/InnerDictWithProperty.md
|
||||
docs/List.md
|
||||
docs/MapTest.md
|
||||
docs/MixedPropertiesAndAdditionalPropertiesClass.md
|
||||
@ -55,6 +56,7 @@ docs/OuterEnumDefaultValue.md
|
||||
docs/OuterEnumInteger.md
|
||||
docs/OuterEnumIntegerDefaultValue.md
|
||||
docs/OuterObjectWithEnumProperty.md
|
||||
docs/ParentWithOptionalDict.md
|
||||
docs/Pet.md
|
||||
docs/PetApi.md
|
||||
docs/Pig.md
|
||||
@ -115,6 +117,7 @@ petstore_api/models/foo_get_default_response.py
|
||||
petstore_api/models/format_test.py
|
||||
petstore_api/models/has_only_read_only.py
|
||||
petstore_api/models/health_check_result.py
|
||||
petstore_api/models/inner_dict_with_property.py
|
||||
petstore_api/models/list.py
|
||||
petstore_api/models/map_test.py
|
||||
petstore_api/models/mixed_properties_and_additional_properties_class.py
|
||||
@ -131,6 +134,7 @@ petstore_api/models/outer_enum_default_value.py
|
||||
petstore_api/models/outer_enum_integer.py
|
||||
petstore_api/models/outer_enum_integer_default_value.py
|
||||
petstore_api/models/outer_object_with_enum_property.py
|
||||
petstore_api/models/parent_with_optional_dict.py
|
||||
petstore_api/models/pet.py
|
||||
petstore_api/models/pig.py
|
||||
petstore_api/models/read_only_first.py
|
||||
|
@ -164,6 +164,7 @@ Class | Method | HTTP request | Description
|
||||
- [FormatTest](docs/FormatTest.md)
|
||||
- [HasOnlyReadOnly](docs/HasOnlyReadOnly.md)
|
||||
- [HealthCheckResult](docs/HealthCheckResult.md)
|
||||
- [InnerDictWithProperty](docs/InnerDictWithProperty.md)
|
||||
- [List](docs/List.md)
|
||||
- [MapTest](docs/MapTest.md)
|
||||
- [MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md)
|
||||
@ -180,6 +181,7 @@ Class | Method | HTTP request | Description
|
||||
- [OuterEnumInteger](docs/OuterEnumInteger.md)
|
||||
- [OuterEnumIntegerDefaultValue](docs/OuterEnumIntegerDefaultValue.md)
|
||||
- [OuterObjectWithEnumProperty](docs/OuterObjectWithEnumProperty.md)
|
||||
- [ParentWithOptionalDict](docs/ParentWithOptionalDict.md)
|
||||
- [Pet](docs/Pet.md)
|
||||
- [Pig](docs/Pig.md)
|
||||
- [ReadOnlyFirst](docs/ReadOnlyFirst.md)
|
||||
|
@ -0,0 +1,28 @@
|
||||
# InnerDictWithProperty
|
||||
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**a_property** | **object** | | [optional]
|
||||
|
||||
## Example
|
||||
|
||||
```python
|
||||
from petstore_api.models.inner_dict_with_property import InnerDictWithProperty
|
||||
|
||||
# TODO update the JSON string below
|
||||
json = "{}"
|
||||
# create an instance of InnerDictWithProperty from a JSON string
|
||||
inner_dict_with_property_instance = InnerDictWithProperty.from_json(json)
|
||||
# print the JSON string representation of the object
|
||||
print InnerDictWithProperty.to_json()
|
||||
|
||||
# convert the object into a dict
|
||||
inner_dict_with_property_dict = inner_dict_with_property_instance.to_dict()
|
||||
# create an instance of InnerDictWithProperty from a dict
|
||||
inner_dict_with_property_form_dict = inner_dict_with_property.from_dict(inner_dict_with_property_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 @@
|
||||
# ParentWithOptionalDict
|
||||
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**optional_dict** | [**Dict[str, InnerDictWithProperty]**](InnerDictWithProperty.md) | | [optional]
|
||||
|
||||
## Example
|
||||
|
||||
```python
|
||||
from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict
|
||||
|
||||
# TODO update the JSON string below
|
||||
json = "{}"
|
||||
# create an instance of ParentWithOptionalDict from a JSON string
|
||||
parent_with_optional_dict_instance = ParentWithOptionalDict.from_json(json)
|
||||
# print the JSON string representation of the object
|
||||
print ParentWithOptionalDict.to_json()
|
||||
|
||||
# convert the object into a dict
|
||||
parent_with_optional_dict_dict = parent_with_optional_dict_instance.to_dict()
|
||||
# create an instance of ParentWithOptionalDict from a dict
|
||||
parent_with_optional_dict_form_dict = parent_with_optional_dict.from_dict(parent_with_optional_dict_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)
|
||||
|
||||
|
@ -69,6 +69,7 @@ from petstore_api.models.foo_get_default_response import FooGetDefaultResponse
|
||||
from petstore_api.models.format_test import FormatTest
|
||||
from petstore_api.models.has_only_read_only import HasOnlyReadOnly
|
||||
from petstore_api.models.health_check_result import HealthCheckResult
|
||||
from petstore_api.models.inner_dict_with_property import InnerDictWithProperty
|
||||
from petstore_api.models.list import List
|
||||
from petstore_api.models.map_test import MapTest
|
||||
from petstore_api.models.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass
|
||||
@ -85,6 +86,7 @@ from petstore_api.models.outer_enum_default_value import OuterEnumDefaultValue
|
||||
from petstore_api.models.outer_enum_integer import OuterEnumInteger
|
||||
from petstore_api.models.outer_enum_integer_default_value import OuterEnumIntegerDefaultValue
|
||||
from petstore_api.models.outer_object_with_enum_property import OuterObjectWithEnumProperty
|
||||
from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict
|
||||
from petstore_api.models.pet import Pet
|
||||
from petstore_api.models.pig import Pig
|
||||
from petstore_api.models.read_only_first import ReadOnlyFirst
|
||||
|
@ -48,6 +48,7 @@ from petstore_api.models.foo_get_default_response import FooGetDefaultResponse
|
||||
from petstore_api.models.format_test import FormatTest
|
||||
from petstore_api.models.has_only_read_only import HasOnlyReadOnly
|
||||
from petstore_api.models.health_check_result import HealthCheckResult
|
||||
from petstore_api.models.inner_dict_with_property import InnerDictWithProperty
|
||||
from petstore_api.models.list import List
|
||||
from petstore_api.models.map_test import MapTest
|
||||
from petstore_api.models.mixed_properties_and_additional_properties_class import MixedPropertiesAndAdditionalPropertiesClass
|
||||
@ -64,6 +65,7 @@ from petstore_api.models.outer_enum_default_value import OuterEnumDefaultValue
|
||||
from petstore_api.models.outer_enum_integer import OuterEnumInteger
|
||||
from petstore_api.models.outer_enum_integer_default_value import OuterEnumIntegerDefaultValue
|
||||
from petstore_api.models.outer_object_with_enum_property import OuterObjectWithEnumProperty
|
||||
from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict
|
||||
from petstore_api.models.pet import Pet
|
||||
from petstore_api.models.pig import Pig
|
||||
from petstore_api.models.read_only_first import ReadOnlyFirst
|
||||
|
@ -0,0 +1,82 @@
|
||||
# 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: \" \\ # noqa: E501
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
|
||||
from __future__ import annotations
|
||||
from inspect import getfullargspec
|
||||
import pprint
|
||||
import re # noqa: F401
|
||||
import json
|
||||
|
||||
|
||||
from typing import Any, Dict, Optional
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
class InnerDictWithProperty(BaseModel):
|
||||
"""
|
||||
InnerDictWithProperty
|
||||
"""
|
||||
a_property: Optional[Dict[str, Any]] = Field(None, alias="aProperty")
|
||||
additional_properties: Dict[str, Any] = {}
|
||||
__properties = ["aProperty"]
|
||||
|
||||
class Config:
|
||||
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) -> InnerDictWithProperty:
|
||||
"""Create an instance of InnerDictWithProperty from a JSON string"""
|
||||
return cls.from_dict(json.loads(json_str))
|
||||
|
||||
def to_dict(self):
|
||||
"""Returns the dictionary representation of the model using alias"""
|
||||
_dict = self.dict(by_alias=True,
|
||||
exclude={
|
||||
"additional_properties"
|
||||
},
|
||||
exclude_none=True)
|
||||
# puts key-value pairs in additional_properties in the top level
|
||||
if self.additional_properties is not None:
|
||||
for _key, _value in self.additional_properties.items():
|
||||
_dict[_key] = _value
|
||||
|
||||
return _dict
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, obj: dict) -> InnerDictWithProperty:
|
||||
"""Create an instance of InnerDictWithProperty from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if type(obj) is not dict:
|
||||
return InnerDictWithProperty.parse_obj(obj)
|
||||
|
||||
_obj = InnerDictWithProperty.parse_obj({
|
||||
"a_property": obj.get("aProperty")
|
||||
})
|
||||
# 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
|
||||
|
@ -83,7 +83,7 @@ class MixedPropertiesAndAdditionalPropertiesClass(BaseModel):
|
||||
_obj = MixedPropertiesAndAdditionalPropertiesClass.parse_obj({
|
||||
"uuid": obj.get("uuid"),
|
||||
"date_time": obj.get("dateTime"),
|
||||
"map": dict((_k, Dict[str, Animal].from_dict(_v)) for _k, _v in obj.get("map").items())
|
||||
"map": dict((_k, Dict[str, Animal].from_dict(_v)) for _k, _v in obj.get("map").items()) if obj.get("map") is not None else None
|
||||
})
|
||||
# store additional fields in additional_properties
|
||||
for _key in obj.keys():
|
||||
|
@ -0,0 +1,90 @@
|
||||
# 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: \" \\ # noqa: E501
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
|
||||
from __future__ import annotations
|
||||
from inspect import getfullargspec
|
||||
import pprint
|
||||
import re # noqa: F401
|
||||
import json
|
||||
|
||||
|
||||
from typing import Dict, Optional
|
||||
from pydantic import BaseModel, Field
|
||||
from petstore_api.models.inner_dict_with_property import InnerDictWithProperty
|
||||
|
||||
class ParentWithOptionalDict(BaseModel):
|
||||
"""
|
||||
ParentWithOptionalDict
|
||||
"""
|
||||
optional_dict: Optional[Dict[str, InnerDictWithProperty]] = Field(None, alias="optionalDict")
|
||||
additional_properties: Dict[str, Any] = {}
|
||||
__properties = ["optionalDict"]
|
||||
|
||||
class Config:
|
||||
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) -> ParentWithOptionalDict:
|
||||
"""Create an instance of ParentWithOptionalDict 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 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()
|
||||
_dict['optionalDict'] = _field_dict
|
||||
# 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) -> ParentWithOptionalDict:
|
||||
"""Create an instance of ParentWithOptionalDict from a dict"""
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
if type(obj) is not dict:
|
||||
return ParentWithOptionalDict.parse_obj(obj)
|
||||
|
||||
_obj = ParentWithOptionalDict.parse_obj({
|
||||
"optional_dict": dict((_k, Dict[str, InnerDictWithProperty].from_dict(_v)) for _k, _v in obj.get("optionalDict").items()) if obj.get("optionalDict") 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
|
||||
|
@ -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: \" \\ # noqa: E501
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import unittest
|
||||
import datetime
|
||||
|
||||
import petstore_api
|
||||
from petstore_api.models.inner_dict_with_property import InnerDictWithProperty # noqa: E501
|
||||
from petstore_api.rest import ApiException
|
||||
|
||||
class TestInnerDictWithProperty(unittest.TestCase):
|
||||
"""InnerDictWithProperty unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def make_instance(self, include_optional):
|
||||
"""Test InnerDictWithProperty
|
||||
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 `InnerDictWithProperty`
|
||||
"""
|
||||
model = petstore_api.models.inner_dict_with_property.InnerDictWithProperty() # noqa: E501
|
||||
if include_optional :
|
||||
return InnerDictWithProperty(
|
||||
a_property = None
|
||||
)
|
||||
else :
|
||||
return InnerDictWithProperty(
|
||||
)
|
||||
"""
|
||||
|
||||
def testInnerDictWithProperty(self):
|
||||
"""Test InnerDictWithProperty"""
|
||||
# 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,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: \" \\ # noqa: E501
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
||||
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import unittest
|
||||
import datetime
|
||||
|
||||
import petstore_api
|
||||
from petstore_api.models.parent_with_optional_dict import ParentWithOptionalDict # noqa: E501
|
||||
from petstore_api.rest import ApiException
|
||||
|
||||
class TestParentWithOptionalDict(unittest.TestCase):
|
||||
"""ParentWithOptionalDict unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def make_instance(self, include_optional):
|
||||
"""Test ParentWithOptionalDict
|
||||
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 `ParentWithOptionalDict`
|
||||
"""
|
||||
model = petstore_api.models.parent_with_optional_dict.ParentWithOptionalDict() # noqa: E501
|
||||
if include_optional :
|
||||
return ParentWithOptionalDict(
|
||||
optional_dict = {
|
||||
'key' : petstore_api.models.inner_dict_with_property.InnerDictWithProperty(
|
||||
a_property = petstore_api.models.a_property.aProperty(), )
|
||||
}
|
||||
)
|
||||
else :
|
||||
return ParentWithOptionalDict(
|
||||
)
|
||||
"""
|
||||
|
||||
def testParentWithOptionalDict(self):
|
||||
"""Test ParentWithOptionalDict"""
|
||||
# inst_req_only = self.make_instance(include_optional=False)
|
||||
# inst_req_and_optional = self.make_instance(include_optional=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
@ -387,3 +387,9 @@ class ModelTests(unittest.TestCase):
|
||||
enum_test = petstore_api.EnumTest(enum_string_required="lower")
|
||||
self.assertEqual(enum_test.enum_integer_default, 5)
|
||||
|
||||
def test_object_with_optional_dict(self):
|
||||
# for https://github.com/OpenAPITools/openapi-generator/issues/14913
|
||||
# shouldn't throw exception by the optional dict property
|
||||
a = petstore_api.ParentWithOptionalDict.from_dict({})
|
||||
self.assertFalse(a is None)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user