mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-08 02:46:23 +00:00
Better inline model resolver to handle inline schema in array item (#12104)
* better support of inline schema in array item * update tests * update samples * regenerate samples * fix allof naming, remove files * add files * update samples * update readme * fix tests * update samples * update samples * add new files * update test spec * add back tests * remove unused files * comment out python test * update js test using own spec * remove files * remove unused files * remove files * remove unused files * better handling of allOf with a single type * comment out go test * remove test_all_of_with_single_ref_single_ref_type.py * fix inline resolver, uncomment go test
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
.travis.yml
|
||||
README.md
|
||||
docs/AdditionalPropertiesClass.md
|
||||
docs/AllOfWithSingleRef.md
|
||||
docs/Animal.md
|
||||
docs/AnotherFakeApi.md
|
||||
docs/ApiResponse.md
|
||||
@@ -50,12 +51,12 @@ docs/OuterObjectWithEnumProperty.md
|
||||
docs/Pet.md
|
||||
docs/PetApi.md
|
||||
docs/ReadOnlyFirst.md
|
||||
docs/SingleRefType.md
|
||||
docs/SpecialModelName.md
|
||||
docs/StoreApi.md
|
||||
docs/Tag.md
|
||||
docs/User.md
|
||||
docs/UserApi.md
|
||||
docs/UserType.md
|
||||
git_push.sh
|
||||
petstore_api/__init__.py
|
||||
petstore_api/api/__init__.py
|
||||
@@ -71,6 +72,7 @@ petstore_api/configuration.py
|
||||
petstore_api/exceptions.py
|
||||
petstore_api/models/__init__.py
|
||||
petstore_api/models/additional_properties_class.py
|
||||
petstore_api/models/all_of_with_single_ref.py
|
||||
petstore_api/models/animal.py
|
||||
petstore_api/models/api_response.py
|
||||
petstore_api/models/array_of_array_of_number_only.py
|
||||
@@ -113,10 +115,10 @@ petstore_api/models/outer_enum_integer_default_value.py
|
||||
petstore_api/models/outer_object_with_enum_property.py
|
||||
petstore_api/models/pet.py
|
||||
petstore_api/models/read_only_first.py
|
||||
petstore_api/models/single_ref_type.py
|
||||
petstore_api/models/special_model_name.py
|
||||
petstore_api/models/tag.py
|
||||
petstore_api/models/user.py
|
||||
petstore_api/models/user_type.py
|
||||
petstore_api/rest.py
|
||||
requirements.txt
|
||||
setup.cfg
|
||||
|
||||
@@ -127,6 +127,7 @@ Class | Method | HTTP request | Description
|
||||
## Documentation For Models
|
||||
|
||||
- [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md)
|
||||
- [AllOfWithSingleRef](docs/AllOfWithSingleRef.md)
|
||||
- [Animal](docs/Animal.md)
|
||||
- [ApiResponse](docs/ApiResponse.md)
|
||||
- [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md)
|
||||
@@ -169,10 +170,10 @@ Class | Method | HTTP request | Description
|
||||
- [OuterObjectWithEnumProperty](docs/OuterObjectWithEnumProperty.md)
|
||||
- [Pet](docs/Pet.md)
|
||||
- [ReadOnlyFirst](docs/ReadOnlyFirst.md)
|
||||
- [SingleRefType](docs/SingleRefType.md)
|
||||
- [SpecialModelName](docs/SpecialModelName.md)
|
||||
- [Tag](docs/Tag.md)
|
||||
- [User](docs/User.md)
|
||||
- [UserType](docs/UserType.md)
|
||||
|
||||
|
||||
## Documentation For Authorization
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
# AllOfWithSingleRef
|
||||
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**username** | **str** | | [optional]
|
||||
**single_ref_type** | [**SingleRefType**](SingleRefType.md) | | [optional]
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# UserType
|
||||
# SingleRefType
|
||||
|
||||
|
||||
## Properties
|
||||
@@ -12,7 +12,6 @@ Name | Type | Description | Notes
|
||||
**password** | **str** | | [optional]
|
||||
**phone** | **str** | | [optional]
|
||||
**user_status** | **int** | User Status | [optional]
|
||||
**user_type** | [**UserType**](UserType.md) | | [optional]
|
||||
|
||||
[[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,7 @@ from petstore_api.exceptions import ApiAttributeError
|
||||
from petstore_api.exceptions import ApiException
|
||||
# import models into sdk package
|
||||
from petstore_api.models.additional_properties_class import AdditionalPropertiesClass
|
||||
from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef
|
||||
from petstore_api.models.animal import Animal
|
||||
from petstore_api.models.api_response import ApiResponse
|
||||
from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly
|
||||
@@ -78,8 +79,8 @@ from petstore_api.models.outer_enum_integer_default_value import OuterEnumIntege
|
||||
from petstore_api.models.outer_object_with_enum_property import OuterObjectWithEnumProperty
|
||||
from petstore_api.models.pet import Pet
|
||||
from petstore_api.models.read_only_first import ReadOnlyFirst
|
||||
from petstore_api.models.single_ref_type import SingleRefType
|
||||
from petstore_api.models.special_model_name import SpecialModelName
|
||||
from petstore_api.models.tag import Tag
|
||||
from petstore_api.models.user import User
|
||||
from petstore_api.models.user_type import UserType
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ from __future__ import absolute_import
|
||||
|
||||
# import models into model package
|
||||
from petstore_api.models.additional_properties_class import AdditionalPropertiesClass
|
||||
from petstore_api.models.all_of_with_single_ref import AllOfWithSingleRef
|
||||
from petstore_api.models.animal import Animal
|
||||
from petstore_api.models.api_response import ApiResponse
|
||||
from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly
|
||||
@@ -57,7 +58,7 @@ from petstore_api.models.outer_enum_integer_default_value import OuterEnumIntege
|
||||
from petstore_api.models.outer_object_with_enum_property import OuterObjectWithEnumProperty
|
||||
from petstore_api.models.pet import Pet
|
||||
from petstore_api.models.read_only_first import ReadOnlyFirst
|
||||
from petstore_api.models.single_ref_type import SingleRefType
|
||||
from petstore_api.models.special_model_name import SpecialModelName
|
||||
from petstore_api.models.tag import Tag
|
||||
from petstore_api.models.user import User
|
||||
from petstore_api.models.user_type import UserType
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
# 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
|
||||
"""
|
||||
|
||||
|
||||
try:
|
||||
from inspect import getfullargspec
|
||||
except ImportError:
|
||||
from inspect import getargspec as getfullargspec
|
||||
import pprint
|
||||
import re # noqa: F401
|
||||
import six
|
||||
|
||||
from petstore_api.configuration import Configuration
|
||||
|
||||
|
||||
class AllOfWithSingleRef(object):
|
||||
"""NOTE: This class is auto generated by OpenAPI Generator.
|
||||
Ref: https://openapi-generator.tech
|
||||
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
|
||||
"""
|
||||
Attributes:
|
||||
openapi_types (dict): The key is attribute name
|
||||
and the value is attribute type.
|
||||
attribute_map (dict): The key is attribute name
|
||||
and the value is json key in definition.
|
||||
"""
|
||||
openapi_types = {
|
||||
'username': 'str',
|
||||
'single_ref_type': 'SingleRefType'
|
||||
}
|
||||
|
||||
attribute_map = {
|
||||
'username': 'username',
|
||||
'single_ref_type': 'SingleRefType'
|
||||
}
|
||||
|
||||
def __init__(self, username=None, single_ref_type=None, local_vars_configuration=None): # noqa: E501
|
||||
"""AllOfWithSingleRef - a model defined in OpenAPI""" # noqa: E501
|
||||
if local_vars_configuration is None:
|
||||
local_vars_configuration = Configuration.get_default_copy()
|
||||
self.local_vars_configuration = local_vars_configuration
|
||||
|
||||
self._username = None
|
||||
self._single_ref_type = None
|
||||
self.discriminator = None
|
||||
|
||||
if username is not None:
|
||||
self.username = username
|
||||
self.single_ref_type = single_ref_type
|
||||
|
||||
@property
|
||||
def username(self):
|
||||
"""Gets the username of this AllOfWithSingleRef. # noqa: E501
|
||||
|
||||
|
||||
:return: The username of this AllOfWithSingleRef. # noqa: E501
|
||||
:rtype: str
|
||||
"""
|
||||
return self._username
|
||||
|
||||
@username.setter
|
||||
def username(self, username):
|
||||
"""Sets the username of this AllOfWithSingleRef.
|
||||
|
||||
|
||||
:param username: The username of this AllOfWithSingleRef. # noqa: E501
|
||||
:type username: str
|
||||
"""
|
||||
|
||||
self._username = username
|
||||
|
||||
@property
|
||||
def single_ref_type(self):
|
||||
"""Gets the single_ref_type of this AllOfWithSingleRef. # noqa: E501
|
||||
|
||||
|
||||
:return: The single_ref_type of this AllOfWithSingleRef. # noqa: E501
|
||||
:rtype: SingleRefType
|
||||
"""
|
||||
return self._single_ref_type
|
||||
|
||||
@single_ref_type.setter
|
||||
def single_ref_type(self, single_ref_type):
|
||||
"""Sets the single_ref_type of this AllOfWithSingleRef.
|
||||
|
||||
|
||||
:param single_ref_type: The single_ref_type of this AllOfWithSingleRef. # noqa: E501
|
||||
:type single_ref_type: SingleRefType
|
||||
"""
|
||||
|
||||
self._single_ref_type = single_ref_type
|
||||
|
||||
def to_dict(self, serialize=False):
|
||||
"""Returns the model properties as a dict"""
|
||||
result = {}
|
||||
|
||||
def convert(x):
|
||||
if hasattr(x, "to_dict"):
|
||||
args = getfullargspec(x.to_dict).args
|
||||
if len(args) == 1:
|
||||
return x.to_dict()
|
||||
else:
|
||||
return x.to_dict(serialize)
|
||||
else:
|
||||
return x
|
||||
|
||||
for attr, _ in six.iteritems(self.openapi_types):
|
||||
value = getattr(self, attr)
|
||||
attr = self.attribute_map.get(attr, attr) if serialize else attr
|
||||
if isinstance(value, list):
|
||||
result[attr] = list(map(
|
||||
lambda x: convert(x),
|
||||
value
|
||||
))
|
||||
elif isinstance(value, dict):
|
||||
result[attr] = dict(map(
|
||||
lambda item: (item[0], convert(item[1])),
|
||||
value.items()
|
||||
))
|
||||
else:
|
||||
result[attr] = convert(value)
|
||||
|
||||
return result
|
||||
|
||||
def to_str(self):
|
||||
"""Returns the string representation of the model"""
|
||||
return pprint.pformat(self.to_dict())
|
||||
|
||||
def __repr__(self):
|
||||
"""For `print` and `pprint`"""
|
||||
return self.to_str()
|
||||
|
||||
def __eq__(self, other):
|
||||
"""Returns true if both objects are equal"""
|
||||
if not isinstance(other, AllOfWithSingleRef):
|
||||
return False
|
||||
|
||||
return self.to_dict() == other.to_dict()
|
||||
|
||||
def __ne__(self, other):
|
||||
"""Returns true if both objects are not equal"""
|
||||
if not isinstance(other, AllOfWithSingleRef):
|
||||
return True
|
||||
|
||||
return self.to_dict() != other.to_dict()
|
||||
@@ -21,7 +21,7 @@ import six
|
||||
from petstore_api.configuration import Configuration
|
||||
|
||||
|
||||
class UserType(object):
|
||||
class SingleRefType(object):
|
||||
"""NOTE: This class is auto generated by OpenAPI Generator.
|
||||
Ref: https://openapi-generator.tech
|
||||
|
||||
@@ -50,7 +50,7 @@ class UserType(object):
|
||||
}
|
||||
|
||||
def __init__(self, local_vars_configuration=None): # noqa: E501
|
||||
"""UserType - a model defined in OpenAPI""" # noqa: E501
|
||||
"""SingleRefType - a model defined in OpenAPI""" # noqa: E501
|
||||
if local_vars_configuration is None:
|
||||
local_vars_configuration = Configuration.get_default_copy()
|
||||
self.local_vars_configuration = local_vars_configuration
|
||||
@@ -98,14 +98,14 @@ class UserType(object):
|
||||
|
||||
def __eq__(self, other):
|
||||
"""Returns true if both objects are equal"""
|
||||
if not isinstance(other, UserType):
|
||||
if not isinstance(other, SingleRefType):
|
||||
return False
|
||||
|
||||
return self.to_dict() == other.to_dict()
|
||||
|
||||
def __ne__(self, other):
|
||||
"""Returns true if both objects are not equal"""
|
||||
if not isinstance(other, UserType):
|
||||
if not isinstance(other, SingleRefType):
|
||||
return True
|
||||
|
||||
return self.to_dict() != other.to_dict()
|
||||
@@ -43,8 +43,7 @@ class User(object):
|
||||
'email': 'str',
|
||||
'password': 'str',
|
||||
'phone': 'str',
|
||||
'user_status': 'int',
|
||||
'user_type': 'UserType'
|
||||
'user_status': 'int'
|
||||
}
|
||||
|
||||
attribute_map = {
|
||||
@@ -55,11 +54,10 @@ class User(object):
|
||||
'email': 'email',
|
||||
'password': 'password',
|
||||
'phone': 'phone',
|
||||
'user_status': 'userStatus',
|
||||
'user_type': 'userType'
|
||||
'user_status': 'userStatus'
|
||||
}
|
||||
|
||||
def __init__(self, id=None, username=None, first_name=None, last_name=None, email=None, password=None, phone=None, user_status=None, user_type=None, local_vars_configuration=None): # noqa: E501
|
||||
def __init__(self, id=None, username=None, first_name=None, last_name=None, email=None, password=None, phone=None, user_status=None, local_vars_configuration=None): # noqa: E501
|
||||
"""User - a model defined in OpenAPI""" # noqa: E501
|
||||
if local_vars_configuration is None:
|
||||
local_vars_configuration = Configuration.get_default_copy()
|
||||
@@ -73,7 +71,6 @@ class User(object):
|
||||
self._password = None
|
||||
self._phone = None
|
||||
self._user_status = None
|
||||
self._user_type = None
|
||||
self.discriminator = None
|
||||
|
||||
if id is not None:
|
||||
@@ -92,7 +89,6 @@ class User(object):
|
||||
self.phone = phone
|
||||
if user_status is not None:
|
||||
self.user_status = user_status
|
||||
self.user_type = user_type
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
@@ -264,27 +260,6 @@ class User(object):
|
||||
|
||||
self._user_status = user_status
|
||||
|
||||
@property
|
||||
def user_type(self):
|
||||
"""Gets the user_type of this User. # noqa: E501
|
||||
|
||||
|
||||
:return: The user_type of this User. # noqa: E501
|
||||
:rtype: UserType
|
||||
"""
|
||||
return self._user_type
|
||||
|
||||
@user_type.setter
|
||||
def user_type(self, user_type):
|
||||
"""Sets the user_type of this User.
|
||||
|
||||
|
||||
:param user_type: The user_type of this User. # noqa: E501
|
||||
:type user_type: UserType
|
||||
"""
|
||||
|
||||
self._user_type = user_type
|
||||
|
||||
def to_dict(self, serialize=False):
|
||||
"""Returns the model properties as a dict"""
|
||||
result = {}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
# 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_single_ref import AllOfWithSingleRef # noqa: E501
|
||||
from petstore_api.rest import ApiException
|
||||
|
||||
class TestAllOfWithSingleRef(unittest.TestCase):
|
||||
"""AllOfWithSingleRef unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def make_instance(self, include_optional):
|
||||
"""Test AllOfWithSingleRef
|
||||
include_option is a boolean, when False only required
|
||||
params are included, when True both required and
|
||||
optional params are included """
|
||||
# model = petstore_api.models.all_of_with_single_ref.AllOfWithSingleRef() # noqa: E501
|
||||
if include_optional :
|
||||
return AllOfWithSingleRef(
|
||||
username = '',
|
||||
single_ref_type = None
|
||||
)
|
||||
else :
|
||||
return AllOfWithSingleRef(
|
||||
)
|
||||
|
||||
def testAllOfWithSingleRef(self):
|
||||
"""Test AllOfWithSingleRef"""
|
||||
inst_req_only = self.make_instance(include_optional=False)
|
||||
inst_req_and_optional = self.make_instance(include_optional=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -16,11 +16,11 @@ import unittest
|
||||
import datetime
|
||||
|
||||
import petstore_api
|
||||
from petstore_api.models.user_type import UserType # noqa: E501
|
||||
from petstore_api.models.single_ref_type import SingleRefType # noqa: E501
|
||||
from petstore_api.rest import ApiException
|
||||
|
||||
class TestUserType(unittest.TestCase):
|
||||
"""UserType unit test stubs"""
|
||||
class TestSingleRefType(unittest.TestCase):
|
||||
"""SingleRefType unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
@@ -29,20 +29,20 @@ class TestUserType(unittest.TestCase):
|
||||
pass
|
||||
|
||||
def make_instance(self, include_optional):
|
||||
"""Test UserType
|
||||
"""Test SingleRefType
|
||||
include_option is a boolean, when False only required
|
||||
params are included, when True both required and
|
||||
optional params are included """
|
||||
# model = petstore_api.models.user_type.UserType() # noqa: E501
|
||||
# model = petstore_api.models.single_ref_type.SingleRefType() # noqa: E501
|
||||
if include_optional :
|
||||
return UserType(
|
||||
return SingleRefType(
|
||||
)
|
||||
else :
|
||||
return UserType(
|
||||
return SingleRefType(
|
||||
)
|
||||
|
||||
def testUserType(self):
|
||||
"""Test UserType"""
|
||||
def testSingleRefType(self):
|
||||
"""Test SingleRefType"""
|
||||
inst_req_only = self.make_instance(include_optional=False)
|
||||
inst_req_and_optional = self.make_instance(include_optional=True)
|
||||
|
||||
Reference in New Issue
Block a user