mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-11 12:02:43 +00:00
Adds spec additionalProperties + nullable examples (#2405)
* Adds v2 spec additionalproperties examples, adds v3 spec nulllable model example, updates samples * Remaining samples updates * Adds csharp generator update to handle models with multilevel parent types, which works for the AdditionalPropertiesObject model, samples updated
This commit is contained in:
committed by
William Cheng
parent
c10463600a
commit
b67318ef21
@@ -146,6 +146,7 @@ Class | Method | HTTP request | Description
|
||||
- [Model200Response](docs/Model200Response.md)
|
||||
- [ModelReturn](docs/ModelReturn.md)
|
||||
- [Name](docs/Name.md)
|
||||
- [NullableClass](docs/NullableClass.md)
|
||||
- [NumberOnly](docs/NumberOnly.md)
|
||||
- [Order](docs/Order.md)
|
||||
- [OuterComposite](docs/OuterComposite.md)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# NullableClass
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**integer_prop** | **int** | | [optional]
|
||||
**number_prop** | **float** | | [optional]
|
||||
**boolean_prop** | **bool** | | [optional]
|
||||
**string_prop** | **str** | | [optional]
|
||||
**date_prop** | **date** | | [optional]
|
||||
**datetime_prop** | **datetime** | | [optional]
|
||||
**array_nullable_prop** | **list[object]** | | [optional]
|
||||
**array_and_items_nullable_prop** | **list[object]** | | [optional]
|
||||
**array_items_nullable** | **list[object]** | | [optional]
|
||||
**object_nullable_prop** | **dict(str, object)** | | [optional]
|
||||
**object_and_items_nullable_prop** | **dict(str, object)** | | [optional]
|
||||
**object_items_nullable** | **dict(str, object)** | | [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)
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ from petstore_api.models.mixed_properties_and_additional_properties_class import
|
||||
from petstore_api.models.model200_response import Model200Response
|
||||
from petstore_api.models.model_return import ModelReturn
|
||||
from petstore_api.models.name import Name
|
||||
from petstore_api.models.nullable_class import NullableClass
|
||||
from petstore_api.models.number_only import NumberOnly
|
||||
from petstore_api.models.order import Order
|
||||
from petstore_api.models.outer_composite import OuterComposite
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
# 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
|
||||
|
||||
OpenAPI spec version: 1.0.0
|
||||
Generated by: https://openapi-generator.tech
|
||||
"""
|
||||
|
||||
|
||||
import six
|
||||
|
||||
|
||||
class OpenApiException(Exception):
|
||||
"""The base exception class for all OpenAPIExceptions"""
|
||||
|
||||
|
||||
class ApiTypeError(OpenApiException, TypeError):
|
||||
def __init__(self, msg, path_to_item=None, valid_classes=None,
|
||||
key_type=None):
|
||||
""" Raises an exception for TypeErrors
|
||||
|
||||
Args:
|
||||
msg (str): the exception message
|
||||
|
||||
Keyword Args:
|
||||
path_to_item (list): a list of keys an indices to get to the
|
||||
current_item
|
||||
None if unset
|
||||
valid_classes (tuple): the primitive classes that current item
|
||||
should be an instance of
|
||||
None if unset
|
||||
key_type (bool): False if our value is a value in a dict
|
||||
True if it is a key in a dict
|
||||
False if our item is an item in a list
|
||||
None if unset
|
||||
"""
|
||||
self.path_to_item = path_to_item
|
||||
self.valid_classes = valid_classes
|
||||
self.key_type = key_type
|
||||
full_msg = msg
|
||||
if path_to_item:
|
||||
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
|
||||
super(ApiTypeError, self).__init__(full_msg)
|
||||
|
||||
|
||||
class ApiValueError(OpenApiException, ValueError):
|
||||
def __init__(self, msg, path_to_item=None):
|
||||
"""
|
||||
Args:
|
||||
msg (str): the exception message
|
||||
|
||||
Keyword Args:
|
||||
path_to_item (list) the path to the exception in the
|
||||
received_data dict. None if unset
|
||||
"""
|
||||
|
||||
self.path_to_item = path_to_item
|
||||
full_msg = msg
|
||||
if path_to_item:
|
||||
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
|
||||
super(ApiValueError, self).__init__(full_msg)
|
||||
|
||||
|
||||
class ApiKeyError(OpenApiException, KeyError):
|
||||
def __init__(self, msg, path_to_item=None):
|
||||
"""
|
||||
Args:
|
||||
msg (str): the exception message
|
||||
|
||||
Keyword Args:
|
||||
path_to_item (None/list) the path to the exception in the
|
||||
received_data dict
|
||||
"""
|
||||
self.path_to_item = path_to_item
|
||||
full_msg = msg
|
||||
if path_to_item:
|
||||
full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
|
||||
super(ApiKeyError, self).__init__(full_msg)
|
||||
|
||||
|
||||
class ApiException(OpenApiException):
|
||||
|
||||
def __init__(self, status=None, reason=None, http_resp=None):
|
||||
if http_resp:
|
||||
self.status = http_resp.status
|
||||
self.reason = http_resp.reason
|
||||
self.body = http_resp.data
|
||||
self.headers = http_resp.getheaders()
|
||||
else:
|
||||
self.status = status
|
||||
self.reason = reason
|
||||
self.body = None
|
||||
self.headers = None
|
||||
|
||||
def __str__(self):
|
||||
"""Custom error messages for exception"""
|
||||
error_message = "({0})\n"\
|
||||
"Reason: {1}\n".format(self.status, self.reason)
|
||||
if self.headers:
|
||||
error_message += "HTTP response headers: {0}\n".format(
|
||||
self.headers)
|
||||
|
||||
if self.body:
|
||||
error_message += "HTTP response body: {0}\n".format(self.body)
|
||||
|
||||
return error_message
|
||||
|
||||
|
||||
def render_path(path_to_item):
|
||||
"""Returns a string representation of a path"""
|
||||
result = ""
|
||||
for pth in path_to_item:
|
||||
if isinstance(pth, six.integer_types):
|
||||
result += "[{0}]".format(pth)
|
||||
else:
|
||||
result += "['{0}']".format(pth)
|
||||
return result
|
||||
@@ -48,6 +48,7 @@ from petstore_api.models.mixed_properties_and_additional_properties_class import
|
||||
from petstore_api.models.model200_response import Model200Response
|
||||
from petstore_api.models.model_return import ModelReturn
|
||||
from petstore_api.models.name import Name
|
||||
from petstore_api.models.nullable_class import NullableClass
|
||||
from petstore_api.models.number_only import NumberOnly
|
||||
from petstore_api.models.order import Order
|
||||
from petstore_api.models.outer_composite import OuterComposite
|
||||
|
||||
@@ -0,0 +1,388 @@
|
||||
# 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
|
||||
|
||||
OpenAPI spec version: 1.0.0
|
||||
Generated by: https://openapi-generator.tech
|
||||
"""
|
||||
|
||||
|
||||
import pprint
|
||||
import re # noqa: F401
|
||||
|
||||
import six
|
||||
|
||||
|
||||
class NullableClass(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 = {
|
||||
'integer_prop': 'int',
|
||||
'number_prop': 'float',
|
||||
'boolean_prop': 'bool',
|
||||
'string_prop': 'str',
|
||||
'date_prop': 'date',
|
||||
'datetime_prop': 'datetime',
|
||||
'array_nullable_prop': 'list[object]',
|
||||
'array_and_items_nullable_prop': 'list[object]',
|
||||
'array_items_nullable': 'list[object]',
|
||||
'object_nullable_prop': 'dict(str, object)',
|
||||
'object_and_items_nullable_prop': 'dict(str, object)',
|
||||
'object_items_nullable': 'dict(str, object)'
|
||||
}
|
||||
|
||||
attribute_map = {
|
||||
'integer_prop': 'integer_prop',
|
||||
'number_prop': 'number_prop',
|
||||
'boolean_prop': 'boolean_prop',
|
||||
'string_prop': 'string_prop',
|
||||
'date_prop': 'date_prop',
|
||||
'datetime_prop': 'datetime_prop',
|
||||
'array_nullable_prop': 'array_nullable_prop',
|
||||
'array_and_items_nullable_prop': 'array_and_items_nullable_prop',
|
||||
'array_items_nullable': 'array_items_nullable',
|
||||
'object_nullable_prop': 'object_nullable_prop',
|
||||
'object_and_items_nullable_prop': 'object_and_items_nullable_prop',
|
||||
'object_items_nullable': 'object_items_nullable'
|
||||
}
|
||||
|
||||
def __init__(self, integer_prop=None, number_prop=None, boolean_prop=None, string_prop=None, date_prop=None, datetime_prop=None, array_nullable_prop=None, array_and_items_nullable_prop=None, array_items_nullable=None, object_nullable_prop=None, object_and_items_nullable_prop=None, object_items_nullable=None): # noqa: E501
|
||||
"""NullableClass - a model defined in OpenAPI""" # noqa: E501
|
||||
|
||||
self._integer_prop = None
|
||||
self._number_prop = None
|
||||
self._boolean_prop = None
|
||||
self._string_prop = None
|
||||
self._date_prop = None
|
||||
self._datetime_prop = None
|
||||
self._array_nullable_prop = None
|
||||
self._array_and_items_nullable_prop = None
|
||||
self._array_items_nullable = None
|
||||
self._object_nullable_prop = None
|
||||
self._object_and_items_nullable_prop = None
|
||||
self._object_items_nullable = None
|
||||
self.discriminator = None
|
||||
|
||||
self.integer_prop = integer_prop
|
||||
self.number_prop = number_prop
|
||||
self.boolean_prop = boolean_prop
|
||||
self.string_prop = string_prop
|
||||
self.date_prop = date_prop
|
||||
self.datetime_prop = datetime_prop
|
||||
self.array_nullable_prop = array_nullable_prop
|
||||
self.array_and_items_nullable_prop = array_and_items_nullable_prop
|
||||
if array_items_nullable is not None:
|
||||
self.array_items_nullable = array_items_nullable
|
||||
self.object_nullable_prop = object_nullable_prop
|
||||
self.object_and_items_nullable_prop = object_and_items_nullable_prop
|
||||
if object_items_nullable is not None:
|
||||
self.object_items_nullable = object_items_nullable
|
||||
|
||||
@property
|
||||
def integer_prop(self):
|
||||
"""Gets the integer_prop of this NullableClass. # noqa: E501
|
||||
|
||||
|
||||
:return: The integer_prop of this NullableClass. # noqa: E501
|
||||
:rtype: int
|
||||
"""
|
||||
return self._integer_prop
|
||||
|
||||
@integer_prop.setter
|
||||
def integer_prop(self, integer_prop):
|
||||
"""Sets the integer_prop of this NullableClass.
|
||||
|
||||
|
||||
:param integer_prop: The integer_prop of this NullableClass. # noqa: E501
|
||||
:type: int
|
||||
"""
|
||||
|
||||
self._integer_prop = integer_prop
|
||||
|
||||
@property
|
||||
def number_prop(self):
|
||||
"""Gets the number_prop of this NullableClass. # noqa: E501
|
||||
|
||||
|
||||
:return: The number_prop of this NullableClass. # noqa: E501
|
||||
:rtype: float
|
||||
"""
|
||||
return self._number_prop
|
||||
|
||||
@number_prop.setter
|
||||
def number_prop(self, number_prop):
|
||||
"""Sets the number_prop of this NullableClass.
|
||||
|
||||
|
||||
:param number_prop: The number_prop of this NullableClass. # noqa: E501
|
||||
:type: float
|
||||
"""
|
||||
|
||||
self._number_prop = number_prop
|
||||
|
||||
@property
|
||||
def boolean_prop(self):
|
||||
"""Gets the boolean_prop of this NullableClass. # noqa: E501
|
||||
|
||||
|
||||
:return: The boolean_prop of this NullableClass. # noqa: E501
|
||||
:rtype: bool
|
||||
"""
|
||||
return self._boolean_prop
|
||||
|
||||
@boolean_prop.setter
|
||||
def boolean_prop(self, boolean_prop):
|
||||
"""Sets the boolean_prop of this NullableClass.
|
||||
|
||||
|
||||
:param boolean_prop: The boolean_prop of this NullableClass. # noqa: E501
|
||||
:type: bool
|
||||
"""
|
||||
|
||||
self._boolean_prop = boolean_prop
|
||||
|
||||
@property
|
||||
def string_prop(self):
|
||||
"""Gets the string_prop of this NullableClass. # noqa: E501
|
||||
|
||||
|
||||
:return: The string_prop of this NullableClass. # noqa: E501
|
||||
:rtype: str
|
||||
"""
|
||||
return self._string_prop
|
||||
|
||||
@string_prop.setter
|
||||
def string_prop(self, string_prop):
|
||||
"""Sets the string_prop of this NullableClass.
|
||||
|
||||
|
||||
:param string_prop: The string_prop of this NullableClass. # noqa: E501
|
||||
:type: str
|
||||
"""
|
||||
|
||||
self._string_prop = string_prop
|
||||
|
||||
@property
|
||||
def date_prop(self):
|
||||
"""Gets the date_prop of this NullableClass. # noqa: E501
|
||||
|
||||
|
||||
:return: The date_prop of this NullableClass. # noqa: E501
|
||||
:rtype: date
|
||||
"""
|
||||
return self._date_prop
|
||||
|
||||
@date_prop.setter
|
||||
def date_prop(self, date_prop):
|
||||
"""Sets the date_prop of this NullableClass.
|
||||
|
||||
|
||||
:param date_prop: The date_prop of this NullableClass. # noqa: E501
|
||||
:type: date
|
||||
"""
|
||||
|
||||
self._date_prop = date_prop
|
||||
|
||||
@property
|
||||
def datetime_prop(self):
|
||||
"""Gets the datetime_prop of this NullableClass. # noqa: E501
|
||||
|
||||
|
||||
:return: The datetime_prop of this NullableClass. # noqa: E501
|
||||
:rtype: datetime
|
||||
"""
|
||||
return self._datetime_prop
|
||||
|
||||
@datetime_prop.setter
|
||||
def datetime_prop(self, datetime_prop):
|
||||
"""Sets the datetime_prop of this NullableClass.
|
||||
|
||||
|
||||
:param datetime_prop: The datetime_prop of this NullableClass. # noqa: E501
|
||||
:type: datetime
|
||||
"""
|
||||
|
||||
self._datetime_prop = datetime_prop
|
||||
|
||||
@property
|
||||
def array_nullable_prop(self):
|
||||
"""Gets the array_nullable_prop of this NullableClass. # noqa: E501
|
||||
|
||||
|
||||
:return: The array_nullable_prop of this NullableClass. # noqa: E501
|
||||
:rtype: list[object]
|
||||
"""
|
||||
return self._array_nullable_prop
|
||||
|
||||
@array_nullable_prop.setter
|
||||
def array_nullable_prop(self, array_nullable_prop):
|
||||
"""Sets the array_nullable_prop of this NullableClass.
|
||||
|
||||
|
||||
:param array_nullable_prop: The array_nullable_prop of this NullableClass. # noqa: E501
|
||||
:type: list[object]
|
||||
"""
|
||||
|
||||
self._array_nullable_prop = array_nullable_prop
|
||||
|
||||
@property
|
||||
def array_and_items_nullable_prop(self):
|
||||
"""Gets the array_and_items_nullable_prop of this NullableClass. # noqa: E501
|
||||
|
||||
|
||||
:return: The array_and_items_nullable_prop of this NullableClass. # noqa: E501
|
||||
:rtype: list[object]
|
||||
"""
|
||||
return self._array_and_items_nullable_prop
|
||||
|
||||
@array_and_items_nullable_prop.setter
|
||||
def array_and_items_nullable_prop(self, array_and_items_nullable_prop):
|
||||
"""Sets the array_and_items_nullable_prop of this NullableClass.
|
||||
|
||||
|
||||
:param array_and_items_nullable_prop: The array_and_items_nullable_prop of this NullableClass. # noqa: E501
|
||||
:type: list[object]
|
||||
"""
|
||||
|
||||
self._array_and_items_nullable_prop = array_and_items_nullable_prop
|
||||
|
||||
@property
|
||||
def array_items_nullable(self):
|
||||
"""Gets the array_items_nullable of this NullableClass. # noqa: E501
|
||||
|
||||
|
||||
:return: The array_items_nullable of this NullableClass. # noqa: E501
|
||||
:rtype: list[object]
|
||||
"""
|
||||
return self._array_items_nullable
|
||||
|
||||
@array_items_nullable.setter
|
||||
def array_items_nullable(self, array_items_nullable):
|
||||
"""Sets the array_items_nullable of this NullableClass.
|
||||
|
||||
|
||||
:param array_items_nullable: The array_items_nullable of this NullableClass. # noqa: E501
|
||||
:type: list[object]
|
||||
"""
|
||||
|
||||
self._array_items_nullable = array_items_nullable
|
||||
|
||||
@property
|
||||
def object_nullable_prop(self):
|
||||
"""Gets the object_nullable_prop of this NullableClass. # noqa: E501
|
||||
|
||||
|
||||
:return: The object_nullable_prop of this NullableClass. # noqa: E501
|
||||
:rtype: dict(str, object)
|
||||
"""
|
||||
return self._object_nullable_prop
|
||||
|
||||
@object_nullable_prop.setter
|
||||
def object_nullable_prop(self, object_nullable_prop):
|
||||
"""Sets the object_nullable_prop of this NullableClass.
|
||||
|
||||
|
||||
:param object_nullable_prop: The object_nullable_prop of this NullableClass. # noqa: E501
|
||||
:type: dict(str, object)
|
||||
"""
|
||||
|
||||
self._object_nullable_prop = object_nullable_prop
|
||||
|
||||
@property
|
||||
def object_and_items_nullable_prop(self):
|
||||
"""Gets the object_and_items_nullable_prop of this NullableClass. # noqa: E501
|
||||
|
||||
|
||||
:return: The object_and_items_nullable_prop of this NullableClass. # noqa: E501
|
||||
:rtype: dict(str, object)
|
||||
"""
|
||||
return self._object_and_items_nullable_prop
|
||||
|
||||
@object_and_items_nullable_prop.setter
|
||||
def object_and_items_nullable_prop(self, object_and_items_nullable_prop):
|
||||
"""Sets the object_and_items_nullable_prop of this NullableClass.
|
||||
|
||||
|
||||
:param object_and_items_nullable_prop: The object_and_items_nullable_prop of this NullableClass. # noqa: E501
|
||||
:type: dict(str, object)
|
||||
"""
|
||||
|
||||
self._object_and_items_nullable_prop = object_and_items_nullable_prop
|
||||
|
||||
@property
|
||||
def object_items_nullable(self):
|
||||
"""Gets the object_items_nullable of this NullableClass. # noqa: E501
|
||||
|
||||
|
||||
:return: The object_items_nullable of this NullableClass. # noqa: E501
|
||||
:rtype: dict(str, object)
|
||||
"""
|
||||
return self._object_items_nullable
|
||||
|
||||
@object_items_nullable.setter
|
||||
def object_items_nullable(self, object_items_nullable):
|
||||
"""Sets the object_items_nullable of this NullableClass.
|
||||
|
||||
|
||||
:param object_items_nullable: The object_items_nullable of this NullableClass. # noqa: E501
|
||||
:type: dict(str, object)
|
||||
"""
|
||||
|
||||
self._object_items_nullable = object_items_nullable
|
||||
|
||||
def to_dict(self):
|
||||
"""Returns the model properties as a dict"""
|
||||
result = {}
|
||||
|
||||
for attr, _ in six.iteritems(self.openapi_types):
|
||||
value = getattr(self, attr)
|
||||
if isinstance(value, list):
|
||||
result[attr] = list(map(
|
||||
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
|
||||
value
|
||||
))
|
||||
elif hasattr(value, "to_dict"):
|
||||
result[attr] = value.to_dict()
|
||||
elif isinstance(value, dict):
|
||||
result[attr] = dict(map(
|
||||
lambda item: (item[0], item[1].to_dict())
|
||||
if hasattr(item[1], "to_dict") else item,
|
||||
value.items()
|
||||
))
|
||||
else:
|
||||
result[attr] = 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, NullableClass):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
"""Returns true if both objects are not equal"""
|
||||
return not self == other
|
||||
@@ -0,0 +1,39 @@
|
||||
# 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
|
||||
|
||||
OpenAPI spec version: 1.0.0
|
||||
Generated by: https://openapi-generator.tech
|
||||
"""
|
||||
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import unittest
|
||||
|
||||
import petstore_api
|
||||
from petstore_api.models.nullable_class import NullableClass # noqa: E501
|
||||
from petstore_api.rest import ApiException
|
||||
|
||||
|
||||
class TestNullableClass(unittest.TestCase):
|
||||
"""NullableClass unit test stubs"""
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def testNullableClass(self):
|
||||
"""Test NullableClass"""
|
||||
# FIXME: construct object with mandatory attributes with example values
|
||||
# model = petstore_api.models.nullable_class.NullableClass() # noqa: E501
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user