mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 20:50:55 +00:00
add a test for allOf with nested inline object with oneOf
This commit is contained in:
parent
a4b5b85067
commit
225d590b53
@ -1985,6 +1985,19 @@ components:
|
|||||||
enum:
|
enum:
|
||||||
- admin
|
- admin
|
||||||
- user
|
- user
|
||||||
|
AllOfWithNestedOneOf:
|
||||||
|
type: object
|
||||||
|
title: allOf with nested oneOf model (inline)
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/components/schemas/Tag'
|
||||||
|
- type: object
|
||||||
|
properties:
|
||||||
|
inner_name:
|
||||||
|
type: string
|
||||||
|
nested_oneof:
|
||||||
|
oneOf:
|
||||||
|
- $ref: '#/components/schemas/BasquePig'
|
||||||
|
- $ref: '#/components/schemas/DanishPig'
|
||||||
Pig:
|
Pig:
|
||||||
oneOf:
|
oneOf:
|
||||||
- $ref: '#/components/schemas/BasquePig'
|
- $ref: '#/components/schemas/BasquePig'
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
.travis.yml
|
.travis.yml
|
||||||
README.md
|
README.md
|
||||||
docs/AdditionalPropertiesClass.md
|
docs/AdditionalPropertiesClass.md
|
||||||
|
docs/AllOfWithNestedOneOf.md
|
||||||
|
docs/AllOfWithNestedOneOfAllOf.md
|
||||||
docs/AllOfWithSingleRef.md
|
docs/AllOfWithSingleRef.md
|
||||||
docs/Animal.md
|
docs/Animal.md
|
||||||
docs/AnotherFakeApi.md
|
docs/AnotherFakeApi.md
|
||||||
@ -83,6 +85,8 @@ petstore_api/configuration.py
|
|||||||
petstore_api/exceptions.py
|
petstore_api/exceptions.py
|
||||||
petstore_api/models/__init__.py
|
petstore_api/models/__init__.py
|
||||||
petstore_api/models/additional_properties_class.py
|
petstore_api/models/additional_properties_class.py
|
||||||
|
petstore_api/models/all_of_with_nested_one_of.py
|
||||||
|
petstore_api/models/all_of_with_nested_one_of_all_of.py
|
||||||
petstore_api/models/all_of_with_single_ref.py
|
petstore_api/models/all_of_with_single_ref.py
|
||||||
petstore_api/models/animal.py
|
petstore_api/models/animal.py
|
||||||
petstore_api/models/any_of_color.py
|
petstore_api/models/any_of_color.py
|
||||||
|
@ -128,6 +128,8 @@ Class | Method | HTTP request | Description
|
|||||||
## Documentation For Models
|
## Documentation For Models
|
||||||
|
|
||||||
- [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md)
|
- [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md)
|
||||||
|
- [AllOfWithNestedOneOf](docs/AllOfWithNestedOneOf.md)
|
||||||
|
- [AllOfWithNestedOneOfAllOf](docs/AllOfWithNestedOneOfAllOf.md)
|
||||||
- [AllOfWithSingleRef](docs/AllOfWithSingleRef.md)
|
- [AllOfWithSingleRef](docs/AllOfWithSingleRef.md)
|
||||||
- [Animal](docs/Animal.md)
|
- [Animal](docs/Animal.md)
|
||||||
- [AnyOfColor](docs/AnyOfColor.md)
|
- [AnyOfColor](docs/AnyOfColor.md)
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
# AllOfWithNestedOneOf
|
||||||
|
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**id** | **int** | | [optional]
|
||||||
|
**name** | **str** | | [optional]
|
||||||
|
**inner_name** | **str** | | [optional]
|
||||||
|
**nested_oneof** | [**OneOfBasquePigDanishPig**](OneOfBasquePigDanishPig.md) | | [optional]
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
from petstore_api.models.all_of_with_nested_one_of import AllOfWithNestedOneOf
|
||||||
|
|
||||||
|
# TODO update the JSON string below
|
||||||
|
json = "{}"
|
||||||
|
# create an instance of AllOfWithNestedOneOf from a JSON string
|
||||||
|
all_of_with_nested_one_of_instance = AllOfWithNestedOneOf.from_json(json)
|
||||||
|
# print the JSON string representation of the object
|
||||||
|
print AllOfWithNestedOneOf.to_json()
|
||||||
|
|
||||||
|
# convert the object into a dict
|
||||||
|
all_of_with_nested_one_of_dict = all_of_with_nested_one_of_instance.to_dict()
|
||||||
|
# create an instance of AllOfWithNestedOneOf from a dict
|
||||||
|
all_of_with_nested_one_of_form_dict = all_of_with_nested_one_of.from_dict(all_of_with_nested_one_of_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,29 @@
|
|||||||
|
# AllOfWithNestedOneOfAllOf
|
||||||
|
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**inner_name** | **str** | | [optional]
|
||||||
|
**nested_oneof** | [**OneOfBasquePigDanishPig**](OneOfBasquePigDanishPig.md) | | [optional]
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
from petstore_api.models.all_of_with_nested_one_of_all_of import AllOfWithNestedOneOfAllOf
|
||||||
|
|
||||||
|
# TODO update the JSON string below
|
||||||
|
json = "{}"
|
||||||
|
# create an instance of AllOfWithNestedOneOfAllOf from a JSON string
|
||||||
|
all_of_with_nested_one_of_all_of_instance = AllOfWithNestedOneOfAllOf.from_json(json)
|
||||||
|
# print the JSON string representation of the object
|
||||||
|
print AllOfWithNestedOneOfAllOf.to_json()
|
||||||
|
|
||||||
|
# convert the object into a dict
|
||||||
|
all_of_with_nested_one_of_all_of_dict = all_of_with_nested_one_of_all_of_instance.to_dict()
|
||||||
|
# create an instance of AllOfWithNestedOneOfAllOf from a dict
|
||||||
|
all_of_with_nested_one_of_all_of_form_dict = all_of_with_nested_one_of_all_of.from_dict(all_of_with_nested_one_of_all_of_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)
|
||||||
|
|
||||||
|
|
@ -36,6 +36,8 @@ from petstore_api.exceptions import ApiAttributeError
|
|||||||
from petstore_api.exceptions import ApiException
|
from petstore_api.exceptions import ApiException
|
||||||
# import models into sdk package
|
# import models into sdk package
|
||||||
from petstore_api.models.additional_properties_class import AdditionalPropertiesClass
|
from petstore_api.models.additional_properties_class import AdditionalPropertiesClass
|
||||||
|
from petstore_api.models.all_of_with_nested_one_of import AllOfWithNestedOneOf
|
||||||
|
from petstore_api.models.all_of_with_nested_one_of_all_of import AllOfWithNestedOneOfAllOf
|
||||||
from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef
|
from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef
|
||||||
from petstore_api.models.animal import Animal
|
from petstore_api.models.animal import Animal
|
||||||
from petstore_api.models.any_of_color import AnyOfColor
|
from petstore_api.models.any_of_color import AnyOfColor
|
||||||
|
@ -15,6 +15,8 @@ from __future__ import absolute_import
|
|||||||
|
|
||||||
# import models into model package
|
# import models into model package
|
||||||
from petstore_api.models.additional_properties_class import AdditionalPropertiesClass
|
from petstore_api.models.additional_properties_class import AdditionalPropertiesClass
|
||||||
|
from petstore_api.models.all_of_with_nested_one_of import AllOfWithNestedOneOf
|
||||||
|
from petstore_api.models.all_of_with_nested_one_of_all_of import AllOfWithNestedOneOfAllOf
|
||||||
from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef
|
from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef
|
||||||
from petstore_api.models.animal import Animal
|
from petstore_api.models.animal import Animal
|
||||||
from petstore_api.models.any_of_color import AnyOfColor
|
from petstore_api.models.any_of_color import AnyOfColor
|
||||||
|
@ -0,0 +1,95 @@
|
|||||||
|
# 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: https://openapi-generator.tech
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
from inspect import getfullargspec
|
||||||
|
import pprint
|
||||||
|
import re # noqa: F401
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
from typing import Any, Optional
|
||||||
|
from pydantic import BaseModel, StrictInt, StrictStr
|
||||||
|
|
||||||
|
class AllOfWithNestedOneOf(BaseModel):
|
||||||
|
"""NOTE: This class is auto generated by OpenAPI Generator.
|
||||||
|
Ref: https://openapi-generator.tech
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
"""
|
||||||
|
id: Optional[StrictInt] = None
|
||||||
|
name: Optional[StrictStr] = None
|
||||||
|
inner_name: Optional[StrictStr] = None
|
||||||
|
nested_oneof: Optional[Any] = None
|
||||||
|
additional_properties: Dict[str, Any] = {}
|
||||||
|
__properties = ["id", "name", "inner_name", "nested_oneof"]
|
||||||
|
|
||||||
|
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) -> AllOfWithNestedOneOf:
|
||||||
|
"""Create an instance of AllOfWithNestedOneOf 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 nested_oneof
|
||||||
|
if self.nested_oneof:
|
||||||
|
_dict['nested_oneof'] = self.nested_oneof.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
|
||||||
|
|
||||||
|
# set to None if nested_oneof (nullable) is None
|
||||||
|
if self.nested_oneof is None:
|
||||||
|
_dict['nested_oneof'] = None
|
||||||
|
|
||||||
|
return _dict
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, obj: dict) -> AllOfWithNestedOneOf:
|
||||||
|
"""Create an instance of AllOfWithNestedOneOf from a dict"""
|
||||||
|
if obj is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if type(obj) is not dict:
|
||||||
|
return AllOfWithNestedOneOf.parse_obj(obj)
|
||||||
|
|
||||||
|
_obj = AllOfWithNestedOneOf.parse_obj({
|
||||||
|
"id": obj.get("id"),
|
||||||
|
"name": obj.get("name"),
|
||||||
|
"inner_name": obj.get("inner_name"),
|
||||||
|
"nested_oneof": OneOfBasquePigDanishPig.from_dict(obj.get("nested_oneof")) if obj.get("nested_oneof") 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,91 @@
|
|||||||
|
# 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: https://openapi-generator.tech
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
from inspect import getfullargspec
|
||||||
|
import pprint
|
||||||
|
import re # noqa: F401
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
from typing import Any, Optional
|
||||||
|
from pydantic import BaseModel, StrictStr
|
||||||
|
|
||||||
|
class AllOfWithNestedOneOfAllOf(BaseModel):
|
||||||
|
"""NOTE: This class is auto generated by OpenAPI Generator.
|
||||||
|
Ref: https://openapi-generator.tech
|
||||||
|
|
||||||
|
Do not edit the class manually.
|
||||||
|
"""
|
||||||
|
inner_name: Optional[StrictStr] = None
|
||||||
|
nested_oneof: Optional[Any] = None
|
||||||
|
additional_properties: Dict[str, Any] = {}
|
||||||
|
__properties = ["inner_name", "nested_oneof"]
|
||||||
|
|
||||||
|
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) -> AllOfWithNestedOneOfAllOf:
|
||||||
|
"""Create an instance of AllOfWithNestedOneOfAllOf 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 nested_oneof
|
||||||
|
if self.nested_oneof:
|
||||||
|
_dict['nested_oneof'] = self.nested_oneof.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
|
||||||
|
|
||||||
|
# set to None if nested_oneof (nullable) is None
|
||||||
|
if self.nested_oneof is None:
|
||||||
|
_dict['nested_oneof'] = None
|
||||||
|
|
||||||
|
return _dict
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_dict(cls, obj: dict) -> AllOfWithNestedOneOfAllOf:
|
||||||
|
"""Create an instance of AllOfWithNestedOneOfAllOf from a dict"""
|
||||||
|
if obj is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if type(obj) is not dict:
|
||||||
|
return AllOfWithNestedOneOfAllOf.parse_obj(obj)
|
||||||
|
|
||||||
|
_obj = AllOfWithNestedOneOfAllOf.parse_obj({
|
||||||
|
"inner_name": obj.get("inner_name"),
|
||||||
|
"nested_oneof": OneOfBasquePigDanishPig.from_dict(obj.get("nested_oneof")) if obj.get("nested_oneof") 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: https://openapi-generator.tech
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
import petstore_api
|
||||||
|
from petstore_api.models.all_of_with_nested_one_of import AllOfWithNestedOneOf # noqa: E501
|
||||||
|
from petstore_api.rest import ApiException
|
||||||
|
|
||||||
|
class TestAllOfWithNestedOneOf(unittest.TestCase):
|
||||||
|
"""AllOfWithNestedOneOf unit test stubs"""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def make_instance(self, include_optional):
|
||||||
|
"""Test AllOfWithNestedOneOf
|
||||||
|
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 `AllOfWithNestedOneOf`
|
||||||
|
"""
|
||||||
|
model = petstore_api.models.all_of_with_nested_one_of.AllOfWithNestedOneOf() # noqa: E501
|
||||||
|
if include_optional :
|
||||||
|
return AllOfWithNestedOneOf(
|
||||||
|
id = 56,
|
||||||
|
name = None,
|
||||||
|
nested_oneof = None
|
||||||
|
)
|
||||||
|
else :
|
||||||
|
return AllOfWithNestedOneOf(
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
|
||||||
|
def testAllOfWithNestedOneOf(self):
|
||||||
|
"""Test AllOfWithNestedOneOf"""
|
||||||
|
# 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,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: https://openapi-generator.tech
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
import petstore_api
|
||||||
|
from petstore_api.models.all_of_with_nested_one_of_all_of import AllOfWithNestedOneOfAllOf # noqa: E501
|
||||||
|
from petstore_api.rest import ApiException
|
||||||
|
|
||||||
|
class TestAllOfWithNestedOneOfAllOf(unittest.TestCase):
|
||||||
|
"""AllOfWithNestedOneOfAllOf unit test stubs"""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def make_instance(self, include_optional):
|
||||||
|
"""Test AllOfWithNestedOneOfAllOf
|
||||||
|
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 `AllOfWithNestedOneOfAllOf`
|
||||||
|
"""
|
||||||
|
model = petstore_api.models.all_of_with_nested_one_of_all_of.AllOfWithNestedOneOfAllOf() # noqa: E501
|
||||||
|
if include_optional :
|
||||||
|
return AllOfWithNestedOneOfAllOf(
|
||||||
|
name = None,
|
||||||
|
nested_oneof = None
|
||||||
|
)
|
||||||
|
else :
|
||||||
|
return AllOfWithNestedOneOfAllOf(
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
|
||||||
|
def testAllOfWithNestedOneOfAllOf(self):
|
||||||
|
"""Test AllOfWithNestedOneOfAllOf"""
|
||||||
|
# inst_req_only = self.make_instance(include_optional=False)
|
||||||
|
# inst_req_and_optional = self.make_instance(include_optional=True)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user