Add tests for #16217 (#16221)

* add tests for #16217

* add new files
This commit is contained in:
William Cheng 2023-07-31 11:03:36 +08:00 committed by GitHub
parent 77311c3d76
commit 3278eea9a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 1044 additions and 0 deletions

View File

@ -2246,3 +2246,30 @@ components:
description: Property
type: boolean
default: false
Creature:
type: object
required:
- info
- type
properties:
info:
$ref: "#/components/schemas/CreatureInfo"
type:
type: string
discriminator:
propertyName: type
CreatureInfo:
type: object
required:
- name
properties:
name:
type: string
Tiger:
allOf:
- $ref: "#/components/schemas/Tiger"
- type: object
properties:
skill:
type: string

View File

@ -22,6 +22,8 @@ docs/CircularReferenceModel.md
docs/ClassModel.md
docs/Client.md
docs/Color.md
docs/Creature.md
docs/CreatureInfo.md
docs/DanishPig.md
docs/DefaultApi.md
docs/DeprecatedObject.md
@ -79,6 +81,7 @@ docs/SpecialModelName.md
docs/SpecialName.md
docs/StoreApi.md
docs/Tag.md
docs/Tiger.md
docs/User.md
docs/UserApi.md
docs/WithNestedOneOf.md
@ -115,6 +118,8 @@ petstore_api/models/circular_reference_model.py
petstore_api/models/class_model.py
petstore_api/models/client.py
petstore_api/models/color.py
petstore_api/models/creature.py
petstore_api/models/creature_info.py
petstore_api/models/danish_pig.py
petstore_api/models/deprecated_object.py
petstore_api/models/dog.py
@ -167,6 +172,7 @@ petstore_api/models/special_character_enum.py
petstore_api/models/special_model_name.py
petstore_api/models/special_name.py
petstore_api/models/tag.py
petstore_api/models/tiger.py
petstore_api/models/user.py
petstore_api/models/with_nested_one_of.py
petstore_api/py.typed

View File

@ -150,6 +150,8 @@ Class | Method | HTTP request | Description
- [ClassModel](docs/ClassModel.md)
- [Client](docs/Client.md)
- [Color](docs/Color.md)
- [Creature](docs/Creature.md)
- [CreatureInfo](docs/CreatureInfo.md)
- [DanishPig](docs/DanishPig.md)
- [DeprecatedObject](docs/DeprecatedObject.md)
- [Dog](docs/Dog.md)
@ -202,6 +204,7 @@ Class | Method | HTTP request | Description
- [SpecialModelName](docs/SpecialModelName.md)
- [SpecialName](docs/SpecialName.md)
- [Tag](docs/Tag.md)
- [Tiger](docs/Tiger.md)
- [User](docs/User.md)
- [WithNestedOneOf](docs/WithNestedOneOf.md)

View File

@ -0,0 +1,29 @@
# Creature
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**info** | [**CreatureInfo**](CreatureInfo.md) | |
**type** | **str** | |
## Example
```python
from petstore_api.models.creature import Creature
# TODO update the JSON string below
json = "{}"
# create an instance of Creature from a JSON string
creature_instance = Creature.from_json(json)
# print the JSON string representation of the object
print Creature.to_json()
# convert the object into a dict
creature_dict = creature_instance.to_dict()
# create an instance of Creature from a dict
creature_form_dict = creature.from_dict(creature_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)

View File

@ -0,0 +1,28 @@
# CreatureInfo
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**name** | **str** | |
## Example
```python
from petstore_api.models.creature_info import CreatureInfo
# TODO update the JSON string below
json = "{}"
# create an instance of CreatureInfo from a JSON string
creature_info_instance = CreatureInfo.from_json(json)
# print the JSON string representation of the object
print CreatureInfo.to_json()
# convert the object into a dict
creature_info_dict = creature_info_instance.to_dict()
# create an instance of CreatureInfo from a dict
creature_info_form_dict = creature_info.from_dict(creature_info_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)

View File

@ -0,0 +1,28 @@
# Tiger
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**skill** | **str** | | [optional]
## Example
```python
from petstore_api.models.tiger import Tiger
# TODO update the JSON string below
json = "{}"
# create an instance of Tiger from a JSON string
tiger_instance = Tiger.from_json(json)
# print the JSON string representation of the object
print Tiger.to_json()
# convert the object into a dict
tiger_dict = tiger_instance.to_dict()
# create an instance of Tiger from a dict
tiger_form_dict = tiger.from_dict(tiger_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)

View File

@ -56,6 +56,8 @@ from petstore_api.models.circular_reference_model import CircularReferenceModel
from petstore_api.models.class_model import ClassModel
from petstore_api.models.client import Client
from petstore_api.models.color import Color
from petstore_api.models.creature import Creature
from petstore_api.models.creature_info import CreatureInfo
from petstore_api.models.danish_pig import DanishPig
from petstore_api.models.deprecated_object import DeprecatedObject
from petstore_api.models.dog import Dog
@ -108,5 +110,6 @@ from petstore_api.models.special_character_enum import SpecialCharacterEnum
from petstore_api.models.special_model_name import SpecialModelName
from petstore_api.models.special_name import SpecialName
from petstore_api.models.tag import Tag
from petstore_api.models.tiger import Tiger
from petstore_api.models.user import User
from petstore_api.models.with_nested_one_of import WithNestedOneOf

View File

@ -32,6 +32,8 @@ from petstore_api.models.circular_reference_model import CircularReferenceModel
from petstore_api.models.class_model import ClassModel
from petstore_api.models.client import Client
from petstore_api.models.color import Color
from petstore_api.models.creature import Creature
from petstore_api.models.creature_info import CreatureInfo
from petstore_api.models.danish_pig import DanishPig
from petstore_api.models.deprecated_object import DeprecatedObject
from petstore_api.models.dog import Dog
@ -84,5 +86,6 @@ from petstore_api.models.special_character_enum import SpecialCharacterEnum
from petstore_api.models.special_model_name import SpecialModelName
from petstore_api.models.special_name import SpecialName
from petstore_api.models.tag import Tag
from petstore_api.models.tiger import Tiger
from petstore_api.models.user import User
from petstore_api.models.with_nested_one_of import WithNestedOneOf

View File

@ -0,0 +1,77 @@
# 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
import pprint
import re # noqa: F401
import json
from pydantic import BaseModel, Field, StrictStr
from petstore_api.models.creature_info import CreatureInfo
class Creature(BaseModel):
"""
Creature
"""
info: CreatureInfo = Field(...)
type: StrictStr = Field(...)
__properties = ["info", "type"]
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) -> Creature:
"""Create an instance of Creature 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 info
if self.info:
_dict['info'] = self.info.to_dict()
return _dict
@classmethod
def from_dict(cls, obj: dict) -> Creature:
"""Create an instance of Creature from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return Creature.parse_obj(obj)
_obj = Creature.parse_obj({
"info": CreatureInfo.from_dict(obj.get("info")) if obj.get("info") is not None else None,
"type": obj.get("type")
})
return _obj

View File

@ -0,0 +1,71 @@
# 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
import pprint
import re # noqa: F401
import json
from pydantic import BaseModel, Field, StrictStr
class CreatureInfo(BaseModel):
"""
CreatureInfo
"""
name: StrictStr = Field(...)
__properties = ["name"]
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) -> CreatureInfo:
"""Create an instance of CreatureInfo 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) -> CreatureInfo:
"""Create an instance of CreatureInfo from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return CreatureInfo.parse_obj(obj)
_obj = CreatureInfo.parse_obj({
"name": obj.get("name")
})
return _obj

View File

@ -0,0 +1,71 @@
# 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
import pprint
import re # noqa: F401
import json
from typing import Optional
from pydantic import BaseModel, StrictStr
class Tiger(BaseModel):
"""
Tiger
"""
skill: Optional[StrictStr] = None
__properties = ["skill"]
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) -> Tiger:
"""Create an instance of Tiger 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) -> Tiger:
"""Create an instance of Tiger from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return Tiger.parse_obj(obj)
_obj = Tiger.parse_obj({
"skill": obj.get("skill")
})
return _obj

View File

@ -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.
"""
import unittest
import datetime
import petstore_api
from petstore_api.models.creature import Creature # noqa: E501
from petstore_api.rest import ApiException
class TestCreature(unittest.TestCase):
"""Creature unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def make_instance(self, include_optional):
"""Test Creature
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 `Creature`
"""
model = petstore_api.models.creature.Creature() # noqa: E501
if include_optional :
return Creature(
info = petstore_api.models.creature_info.CreatureInfo(
name = '', ),
type = ''
)
else :
return Creature(
info = petstore_api.models.creature_info.CreatureInfo(
name = '', ),
type = '',
)
"""
def testCreature(self):
"""Test Creature"""
# inst_req_only = self.make_instance(include_optional=False)
# inst_req_and_optional = self.make_instance(include_optional=True)
if __name__ == '__main__':
unittest.main()

View File

@ -0,0 +1,55 @@
# 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.
"""
import unittest
import datetime
import petstore_api
from petstore_api.models.creature_info import CreatureInfo # noqa: E501
from petstore_api.rest import ApiException
class TestCreatureInfo(unittest.TestCase):
"""CreatureInfo unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def make_instance(self, include_optional):
"""Test CreatureInfo
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 `CreatureInfo`
"""
model = petstore_api.models.creature_info.CreatureInfo() # noqa: E501
if include_optional :
return CreatureInfo(
name = ''
)
else :
return CreatureInfo(
name = '',
)
"""
def testCreatureInfo(self):
"""Test CreatureInfo"""
# inst_req_only = self.make_instance(include_optional=False)
# inst_req_and_optional = self.make_instance(include_optional=True)
if __name__ == '__main__':
unittest.main()

View File

@ -0,0 +1,54 @@
# 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.
"""
import unittest
import datetime
import petstore_api
from petstore_api.models.tiger import Tiger # noqa: E501
from petstore_api.rest import ApiException
class TestTiger(unittest.TestCase):
"""Tiger unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def make_instance(self, include_optional):
"""Test Tiger
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 `Tiger`
"""
model = petstore_api.models.tiger.Tiger() # noqa: E501
if include_optional :
return Tiger(
skill = ''
)
else :
return Tiger(
)
"""
def testTiger(self):
"""Test Tiger"""
# inst_req_only = self.make_instance(include_optional=False)
# inst_req_and_optional = self.make_instance(include_optional=True)
if __name__ == '__main__':
unittest.main()

View File

@ -22,6 +22,8 @@ docs/CircularReferenceModel.md
docs/ClassModel.md
docs/Client.md
docs/Color.md
docs/Creature.md
docs/CreatureInfo.md
docs/DanishPig.md
docs/DefaultApi.md
docs/DeprecatedObject.md
@ -79,6 +81,7 @@ docs/SpecialModelName.md
docs/SpecialName.md
docs/StoreApi.md
docs/Tag.md
docs/Tiger.md
docs/User.md
docs/UserApi.md
docs/WithNestedOneOf.md
@ -115,6 +118,8 @@ petstore_api/models/circular_reference_model.py
petstore_api/models/class_model.py
petstore_api/models/client.py
petstore_api/models/color.py
petstore_api/models/creature.py
petstore_api/models/creature_info.py
petstore_api/models/danish_pig.py
petstore_api/models/deprecated_object.py
petstore_api/models/dog.py
@ -167,6 +172,7 @@ petstore_api/models/special_character_enum.py
petstore_api/models/special_model_name.py
petstore_api/models/special_name.py
petstore_api/models/tag.py
petstore_api/models/tiger.py
petstore_api/models/user.py
petstore_api/models/with_nested_one_of.py
petstore_api/py.typed

View File

@ -150,6 +150,8 @@ Class | Method | HTTP request | Description
- [ClassModel](docs/ClassModel.md)
- [Client](docs/Client.md)
- [Color](docs/Color.md)
- [Creature](docs/Creature.md)
- [CreatureInfo](docs/CreatureInfo.md)
- [DanishPig](docs/DanishPig.md)
- [DeprecatedObject](docs/DeprecatedObject.md)
- [Dog](docs/Dog.md)
@ -202,6 +204,7 @@ Class | Method | HTTP request | Description
- [SpecialModelName](docs/SpecialModelName.md)
- [SpecialName](docs/SpecialName.md)
- [Tag](docs/Tag.md)
- [Tiger](docs/Tiger.md)
- [User](docs/User.md)
- [WithNestedOneOf](docs/WithNestedOneOf.md)

View File

@ -0,0 +1,29 @@
# Creature
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**info** | [**CreatureInfo**](CreatureInfo.md) | |
**type** | **str** | |
## Example
```python
from petstore_api.models.creature import Creature
# TODO update the JSON string below
json = "{}"
# create an instance of Creature from a JSON string
creature_instance = Creature.from_json(json)
# print the JSON string representation of the object
print Creature.to_json()
# convert the object into a dict
creature_dict = creature_instance.to_dict()
# create an instance of Creature from a dict
creature_form_dict = creature.from_dict(creature_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)

View File

@ -0,0 +1,28 @@
# CreatureInfo
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**name** | **str** | |
## Example
```python
from petstore_api.models.creature_info import CreatureInfo
# TODO update the JSON string below
json = "{}"
# create an instance of CreatureInfo from a JSON string
creature_info_instance = CreatureInfo.from_json(json)
# print the JSON string representation of the object
print CreatureInfo.to_json()
# convert the object into a dict
creature_info_dict = creature_info_instance.to_dict()
# create an instance of CreatureInfo from a dict
creature_info_form_dict = creature_info.from_dict(creature_info_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)

View File

@ -0,0 +1,28 @@
# Tiger
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**skill** | **str** | | [optional]
## Example
```python
from petstore_api.models.tiger import Tiger
# TODO update the JSON string below
json = "{}"
# create an instance of Tiger from a JSON string
tiger_instance = Tiger.from_json(json)
# print the JSON string representation of the object
print Tiger.to_json()
# convert the object into a dict
tiger_dict = tiger_instance.to_dict()
# create an instance of Tiger from a dict
tiger_form_dict = tiger.from_dict(tiger_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)

View File

@ -56,6 +56,8 @@ from petstore_api.models.circular_reference_model import CircularReferenceModel
from petstore_api.models.class_model import ClassModel
from petstore_api.models.client import Client
from petstore_api.models.color import Color
from petstore_api.models.creature import Creature
from petstore_api.models.creature_info import CreatureInfo
from petstore_api.models.danish_pig import DanishPig
from petstore_api.models.deprecated_object import DeprecatedObject
from petstore_api.models.dog import Dog
@ -108,5 +110,6 @@ from petstore_api.models.special_character_enum import SpecialCharacterEnum
from petstore_api.models.special_model_name import SpecialModelName
from petstore_api.models.special_name import SpecialName
from petstore_api.models.tag import Tag
from petstore_api.models.tiger import Tiger
from petstore_api.models.user import User
from petstore_api.models.with_nested_one_of import WithNestedOneOf

View File

@ -32,6 +32,8 @@ from petstore_api.models.circular_reference_model import CircularReferenceModel
from petstore_api.models.class_model import ClassModel
from petstore_api.models.client import Client
from petstore_api.models.color import Color
from petstore_api.models.creature import Creature
from petstore_api.models.creature_info import CreatureInfo
from petstore_api.models.danish_pig import DanishPig
from petstore_api.models.deprecated_object import DeprecatedObject
from petstore_api.models.dog import Dog
@ -84,5 +86,6 @@ from petstore_api.models.special_character_enum import SpecialCharacterEnum
from petstore_api.models.special_model_name import SpecialModelName
from petstore_api.models.special_name import SpecialName
from petstore_api.models.tag import Tag
from petstore_api.models.tiger import Tiger
from petstore_api.models.user import User
from petstore_api.models.with_nested_one_of import WithNestedOneOf

View File

@ -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: \" \\ # 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
import pprint
import re # noqa: F401
import json
from typing import Any, Dict
from pydantic import BaseModel, Field, StrictStr
from petstore_api.models.creature_info import CreatureInfo
class Creature(BaseModel):
"""
Creature
"""
info: CreatureInfo = Field(...)
type: StrictStr = Field(...)
additional_properties: Dict[str, Any] = {}
__properties = ["info", "type"]
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) -> Creature:
"""Create an instance of Creature 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 info
if self.info:
_dict['info'] = self.info.to_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) -> Creature:
"""Create an instance of Creature from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return Creature.parse_obj(obj)
_obj = Creature.parse_obj({
"info": CreatureInfo.from_dict(obj.get("info")) if obj.get("info") is not None else None,
"type": obj.get("type")
})
# 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

View File

@ -0,0 +1,83 @@
# 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
import pprint
import re # noqa: F401
import json
from typing import Any, Dict
from pydantic import BaseModel, Field, StrictStr
class CreatureInfo(BaseModel):
"""
CreatureInfo
"""
name: StrictStr = Field(...)
additional_properties: Dict[str, Any] = {}
__properties = ["name"]
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) -> CreatureInfo:
"""Create an instance of CreatureInfo 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) -> CreatureInfo:
"""Create an instance of CreatureInfo from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return CreatureInfo.parse_obj(obj)
_obj = CreatureInfo.parse_obj({
"name": obj.get("name")
})
# 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

View File

@ -0,0 +1,83 @@
# 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
import pprint
import re # noqa: F401
import json
from typing import Any, Dict, Optional
from pydantic import BaseModel, StrictStr
class Tiger(BaseModel):
"""
Tiger
"""
skill: Optional[StrictStr] = None
additional_properties: Dict[str, Any] = {}
__properties = ["skill"]
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) -> Tiger:
"""Create an instance of Tiger 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) -> Tiger:
"""Create an instance of Tiger from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return Tiger.parse_obj(obj)
_obj = Tiger.parse_obj({
"skill": obj.get("skill")
})
# 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

View File

@ -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.
"""
import unittest
import datetime
import petstore_api
from petstore_api.models.creature import Creature # noqa: E501
from petstore_api.rest import ApiException
class TestCreature(unittest.TestCase):
"""Creature unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def make_instance(self, include_optional):
"""Test Creature
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 `Creature`
"""
model = petstore_api.models.creature.Creature() # noqa: E501
if include_optional :
return Creature(
info = petstore_api.models.creature_info.CreatureInfo(
name = '', ),
type = ''
)
else :
return Creature(
info = petstore_api.models.creature_info.CreatureInfo(
name = '', ),
type = '',
)
"""
def testCreature(self):
"""Test Creature"""
# inst_req_only = self.make_instance(include_optional=False)
# inst_req_and_optional = self.make_instance(include_optional=True)
if __name__ == '__main__':
unittest.main()

View File

@ -0,0 +1,55 @@
# 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.
"""
import unittest
import datetime
import petstore_api
from petstore_api.models.creature_info import CreatureInfo # noqa: E501
from petstore_api.rest import ApiException
class TestCreatureInfo(unittest.TestCase):
"""CreatureInfo unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def make_instance(self, include_optional):
"""Test CreatureInfo
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 `CreatureInfo`
"""
model = petstore_api.models.creature_info.CreatureInfo() # noqa: E501
if include_optional :
return CreatureInfo(
name = ''
)
else :
return CreatureInfo(
name = '',
)
"""
def testCreatureInfo(self):
"""Test CreatureInfo"""
# inst_req_only = self.make_instance(include_optional=False)
# inst_req_and_optional = self.make_instance(include_optional=True)
if __name__ == '__main__':
unittest.main()

View File

@ -0,0 +1,54 @@
# 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.
"""
import unittest
import datetime
import petstore_api
from petstore_api.models.tiger import Tiger # noqa: E501
from petstore_api.rest import ApiException
class TestTiger(unittest.TestCase):
"""Tiger unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def make_instance(self, include_optional):
"""Test Tiger
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 `Tiger`
"""
model = petstore_api.models.tiger.Tiger() # noqa: E501
if include_optional :
return Tiger(
skill = ''
)
else :
return Tiger(
)
"""
def testTiger(self):
"""Test Tiger"""
# inst_req_only = self.make_instance(include_optional=False)
# inst_req_and_optional = self.make_instance(include_optional=True)
if __name__ == '__main__':
unittest.main()

View File

@ -513,3 +513,10 @@ class ModelTests(unittest.TestCase):
a = petstore_api.FirstRef.from_dict({})
self.assertEqual(a.to_json(), "{}")
def test_allof(self):
# for issue 16104
model = petstore_api.Tiger.from_json('{"skill": "none", "type": "tiger", "info": {"name": "creature info"}}')
# shouldn't throw NameError
self.assertEqual(model.to_json(), '{"skill": "none", "type": "tiger", "info": {"name": "creature info"}}')