diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java index 65b1a202f52..080112520ca 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java @@ -634,33 +634,40 @@ public abstract class AbstractPythonCodegen extends DefaultCodegen implements Co @Override public String toModelName(String name) { - name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. + String sanitizedName = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. // remove dollar sign - name = name.replaceAll("$", ""); - - // model name cannot use reserved keyword, e.g. return - if (isReservedWord(name)) { - LOGGER.warn("{} (reserved word) cannot be used as model name. Renamed to {}", name, camelize("model_" + name)); - name = "model_" + name; // e.g. return => ModelReturn (after camelize) - } - - // model name starts with number - if (name.matches("^\\d.*")) { - LOGGER.warn("{} (model name starts with number) cannot be used as model name. Renamed to {}", name, camelize("model_" + name)); - name = "model_" + name; // e.g. 200Response => Model200Response (after camelize) - } + sanitizedName = sanitizedName.replaceAll("$", ""); + String nameWithPrefixSuffix = sanitizedName; if (!StringUtils.isEmpty(modelNamePrefix)) { - name = modelNamePrefix + "_" + name; + // add '_' so that model name can be camelized correctly + nameWithPrefixSuffix = modelNamePrefix + "_" + nameWithPrefixSuffix; } if (!StringUtils.isEmpty(modelNameSuffix)) { - name = name + "_" + modelNameSuffix; + // add '_' so that model name can be camelized correctly + nameWithPrefixSuffix = nameWithPrefixSuffix + "_" + modelNameSuffix; } // camelize the model name // phone_number => PhoneNumber - return camelize(name); + String camelizedName = camelize(nameWithPrefixSuffix); + + // model name cannot use reserved keyword, e.g. return + if (isReservedWord(camelizedName)) { + String modelName = "Model" + camelizedName; // e.g. return => ModelReturn (after camelize) + LOGGER.warn("{} (reserved word) cannot be used as model name. Renamed to {}", camelizedName, modelName); + return modelName; + } + + // model name starts with number + if (camelizedName.matches("^\\d.*")) { + String modelName = "Model" + camelizedName; // e.g. return => ModelReturn (after camelize) + LOGGER.warn("{} (model name starts with number) cannot be used as model name. Renamed to {}", camelizedName, modelName); + return modelName; + } + + return camelizedName; } @Override diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientTest.java index 2bbfdaca1dc..24870864376 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientTest.java @@ -40,6 +40,7 @@ import org.openapitools.codegen.languages.PythonClientCodegen; import org.openapitools.codegen.languages.PythonExperimentalClientCodegen; import org.openapitools.codegen.utils.ModelUtils; import org.testng.Assert; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @SuppressWarnings("static-method") @@ -519,4 +520,33 @@ public class PythonClientTest { Assert.assertEquals(exampleValue.trim(), expectedValue.trim()); } + @DataProvider + public Object[][] testToModelData() { + return new Object[][] { + new Object[] {"", "", "foo", "Foo"}, + new Object[] {"Abc", "", "foo", "AbcFoo"}, + new Object[] {"", "Abc", "foo", "FooAbc"}, + new Object[] {"Abc", "Xyz", "foo", "AbcFooXyz"}, + + new Object[] {"", "", "1", "Model1"}, + new Object[] {"Abc", "", "1", "Abc1"}, + new Object[] {"", "Abc", "1", "Model1Abc"}, + new Object[] {"Abc", "Xyz", "1", "Abc1Xyz"}, + + new Object[] {"", "", "and", "ModelAnd"}, + new Object[] {"Abc", "", "and", "AbcAnd"}, + new Object[] {"", "Abc", "and", "AndAbc"}, + new Object[] {"Abc", "Xyz", "and", "AbcAndXyz"}, + }; + } + + @Test(dataProvider = "testToModelData") + public void testToModel(String prefix, String suffix, String input, String want) { + PythonClientCodegen codegen = new PythonClientCodegen(); + codegen.setModelNamePrefix(prefix); + codegen.setModelNameSuffix(suffix); + Assert.assertEquals(codegen.toModelName(input), want); + } + + } diff --git a/samples/client/petstore/python-asyncio/docs/Model_200Response.md b/samples/client/petstore/python-asyncio/docs/Model_200Response.md new file mode 100644 index 00000000000..4fd119d1251 --- /dev/null +++ b/samples/client/petstore/python-asyncio/docs/Model_200Response.md @@ -0,0 +1,13 @@ +# Model_200Response + +Model for testing model name starting with number + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **int** | | [optional] +**_class** | **str** | | [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) + + diff --git a/samples/client/petstore/python-asyncio/docs/Model_Return.md b/samples/client/petstore/python-asyncio/docs/Model_Return.md new file mode 100644 index 00000000000..674c441551b --- /dev/null +++ b/samples/client/petstore/python-asyncio/docs/Model_Return.md @@ -0,0 +1,12 @@ +# Model_Return + +Model for testing reserved words + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**_return** | **int** | | [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) + + diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/model_200_response.py b/samples/client/petstore/python-asyncio/petstore_api/models/model_200_response.py new file mode 100644 index 00000000000..96498ac6b1d --- /dev/null +++ b/samples/client/petstore/python-asyncio/petstore_api/models/model_200_response.py @@ -0,0 +1,157 @@ +# 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 Model_200Response(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 = { + 'name': 'int', + '_class': 'str' + } + + attribute_map = { + 'name': 'name', + '_class': 'class' + } + + def __init__(self, name=None, _class=None, local_vars_configuration=None): # noqa: E501 + """Model_200Response - 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._name = None + self.__class = None + self.discriminator = None + + if name is not None: + self.name = name + if _class is not None: + self._class = _class + + @property + def name(self): + """Gets the name of this Model_200Response. # noqa: E501 + + + :return: The name of this Model_200Response. # noqa: E501 + :rtype: int + """ + return self._name + + @name.setter + def name(self, name): + """Sets the name of this Model_200Response. + + + :param name: The name of this Model_200Response. # noqa: E501 + :type name: int + """ + + self._name = name + + @property + def _class(self): + """Gets the _class of this Model_200Response. # noqa: E501 + + + :return: The _class of this Model_200Response. # noqa: E501 + :rtype: str + """ + return self.__class + + @_class.setter + def _class(self, _class): + """Sets the _class of this Model_200Response. + + + :param _class: The _class of this Model_200Response. # noqa: E501 + :type _class: str + """ + + self.__class = _class + + 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, Model_200Response): + 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, Model_200Response): + return True + + return self.to_dict() != other.to_dict() diff --git a/samples/client/petstore/python-asyncio/test/test_model_200_response.py b/samples/client/petstore/python-asyncio/test/test_model_200_response.py new file mode 100644 index 00000000000..314ee5e3dde --- /dev/null +++ b/samples/client/petstore/python-asyncio/test/test_model_200_response.py @@ -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.model_200_response import Model_200Response # noqa: E501 +from petstore_api.rest import ApiException + +class TestModel_200Response(unittest.TestCase): + """Model_200Response unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional): + """Test Model_200Response + 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.model_200_response.Model_200Response() # noqa: E501 + if include_optional : + return Model_200Response( + name = 56, + _class = '' + ) + else : + return Model_200Response( + ) + + def testModel_200Response(self): + """Test Model_200Response""" + inst_req_only = self.make_instance(include_optional=False) + inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python-legacy/docs/Model_200Response.md b/samples/client/petstore/python-legacy/docs/Model_200Response.md new file mode 100644 index 00000000000..4fd119d1251 --- /dev/null +++ b/samples/client/petstore/python-legacy/docs/Model_200Response.md @@ -0,0 +1,13 @@ +# Model_200Response + +Model for testing model name starting with number + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **int** | | [optional] +**_class** | **str** | | [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) + + diff --git a/samples/client/petstore/python-legacy/docs/Model_Return.md b/samples/client/petstore/python-legacy/docs/Model_Return.md new file mode 100644 index 00000000000..674c441551b --- /dev/null +++ b/samples/client/petstore/python-legacy/docs/Model_Return.md @@ -0,0 +1,12 @@ +# Model_Return + +Model for testing reserved words + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**_return** | **int** | | [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) + + diff --git a/samples/client/petstore/python-legacy/petstore_api/models/model_200_response.py b/samples/client/petstore/python-legacy/petstore_api/models/model_200_response.py new file mode 100644 index 00000000000..96498ac6b1d --- /dev/null +++ b/samples/client/petstore/python-legacy/petstore_api/models/model_200_response.py @@ -0,0 +1,157 @@ +# 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 Model_200Response(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 = { + 'name': 'int', + '_class': 'str' + } + + attribute_map = { + 'name': 'name', + '_class': 'class' + } + + def __init__(self, name=None, _class=None, local_vars_configuration=None): # noqa: E501 + """Model_200Response - 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._name = None + self.__class = None + self.discriminator = None + + if name is not None: + self.name = name + if _class is not None: + self._class = _class + + @property + def name(self): + """Gets the name of this Model_200Response. # noqa: E501 + + + :return: The name of this Model_200Response. # noqa: E501 + :rtype: int + """ + return self._name + + @name.setter + def name(self, name): + """Sets the name of this Model_200Response. + + + :param name: The name of this Model_200Response. # noqa: E501 + :type name: int + """ + + self._name = name + + @property + def _class(self): + """Gets the _class of this Model_200Response. # noqa: E501 + + + :return: The _class of this Model_200Response. # noqa: E501 + :rtype: str + """ + return self.__class + + @_class.setter + def _class(self, _class): + """Sets the _class of this Model_200Response. + + + :param _class: The _class of this Model_200Response. # noqa: E501 + :type _class: str + """ + + self.__class = _class + + 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, Model_200Response): + 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, Model_200Response): + return True + + return self.to_dict() != other.to_dict() diff --git a/samples/client/petstore/python-legacy/test/test_model_200_response.py b/samples/client/petstore/python-legacy/test/test_model_200_response.py new file mode 100644 index 00000000000..314ee5e3dde --- /dev/null +++ b/samples/client/petstore/python-legacy/test/test_model_200_response.py @@ -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.model_200_response import Model_200Response # noqa: E501 +from petstore_api.rest import ApiException + +class TestModel_200Response(unittest.TestCase): + """Model_200Response unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional): + """Test Model_200Response + 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.model_200_response.Model_200Response() # noqa: E501 + if include_optional : + return Model_200Response( + name = 56, + _class = '' + ) + else : + return Model_200Response( + ) + + def testModel_200Response(self): + """Test Model_200Response""" + inst_req_only = self.make_instance(include_optional=False) + inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python-tornado/docs/Model_200Response.md b/samples/client/petstore/python-tornado/docs/Model_200Response.md new file mode 100644 index 00000000000..4fd119d1251 --- /dev/null +++ b/samples/client/petstore/python-tornado/docs/Model_200Response.md @@ -0,0 +1,13 @@ +# Model_200Response + +Model for testing model name starting with number + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **int** | | [optional] +**_class** | **str** | | [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) + + diff --git a/samples/client/petstore/python-tornado/docs/Model_Return.md b/samples/client/petstore/python-tornado/docs/Model_Return.md new file mode 100644 index 00000000000..674c441551b --- /dev/null +++ b/samples/client/petstore/python-tornado/docs/Model_Return.md @@ -0,0 +1,12 @@ +# Model_Return + +Model for testing reserved words + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**_return** | **int** | | [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) + + diff --git a/samples/client/petstore/python-tornado/petstore_api/models/model_200_response.py b/samples/client/petstore/python-tornado/petstore_api/models/model_200_response.py new file mode 100644 index 00000000000..96498ac6b1d --- /dev/null +++ b/samples/client/petstore/python-tornado/petstore_api/models/model_200_response.py @@ -0,0 +1,157 @@ +# 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 Model_200Response(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 = { + 'name': 'int', + '_class': 'str' + } + + attribute_map = { + 'name': 'name', + '_class': 'class' + } + + def __init__(self, name=None, _class=None, local_vars_configuration=None): # noqa: E501 + """Model_200Response - 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._name = None + self.__class = None + self.discriminator = None + + if name is not None: + self.name = name + if _class is not None: + self._class = _class + + @property + def name(self): + """Gets the name of this Model_200Response. # noqa: E501 + + + :return: The name of this Model_200Response. # noqa: E501 + :rtype: int + """ + return self._name + + @name.setter + def name(self, name): + """Sets the name of this Model_200Response. + + + :param name: The name of this Model_200Response. # noqa: E501 + :type name: int + """ + + self._name = name + + @property + def _class(self): + """Gets the _class of this Model_200Response. # noqa: E501 + + + :return: The _class of this Model_200Response. # noqa: E501 + :rtype: str + """ + return self.__class + + @_class.setter + def _class(self, _class): + """Sets the _class of this Model_200Response. + + + :param _class: The _class of this Model_200Response. # noqa: E501 + :type _class: str + """ + + self.__class = _class + + 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, Model_200Response): + 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, Model_200Response): + return True + + return self.to_dict() != other.to_dict() diff --git a/samples/client/petstore/python-tornado/test/test_model_200_response.py b/samples/client/petstore/python-tornado/test/test_model_200_response.py new file mode 100644 index 00000000000..314ee5e3dde --- /dev/null +++ b/samples/client/petstore/python-tornado/test/test_model_200_response.py @@ -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.model_200_response import Model_200Response # noqa: E501 +from petstore_api.rest import ApiException + +class TestModel_200Response(unittest.TestCase): + """Model_200Response unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional): + """Test Model_200Response + 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.model_200_response.Model_200Response() # noqa: E501 + if include_optional : + return Model_200Response( + name = 56, + _class = '' + ) + else : + return Model_200Response( + ) + + def testModel_200Response(self): + """Test Model_200Response""" + inst_req_only = self.make_instance(include_optional=False) + inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python/docs/Model_200Response.md b/samples/client/petstore/python/docs/Model_200Response.md new file mode 100644 index 00000000000..3d5777b2b10 --- /dev/null +++ b/samples/client/petstore/python/docs/Model_200Response.md @@ -0,0 +1,14 @@ +# Model_200Response + +Model for testing model name starting with number + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **int** | | [optional] +**_class** | **str** | | [optional] +**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [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) + + diff --git a/samples/client/petstore/python/docs/Model_Return.md b/samples/client/petstore/python/docs/Model_Return.md new file mode 100644 index 00000000000..d9c1a2d8119 --- /dev/null +++ b/samples/client/petstore/python/docs/Model_Return.md @@ -0,0 +1,13 @@ +# Model_Return + +Model for testing reserved words + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**_return** | **int** | | [optional] +**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [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) + + diff --git a/samples/client/petstore/python/petstore_api/model/model_200_response.py b/samples/client/petstore/python/petstore_api/model/model_200_response.py new file mode 100644 index 00000000000..d2f97900d18 --- /dev/null +++ b/samples/client/petstore/python/petstore_api/model/model_200_response.py @@ -0,0 +1,267 @@ +""" + 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 +""" + + +import re # noqa: F401 +import sys # noqa: F401 + +from petstore_api.model_utils import ( # noqa: F401 + ApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, + OpenApiModel +) +from petstore_api.exceptions import ApiAttributeError + + + +class Model_200Response(ModelNormal): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + discriminator_value_class_map (dict): A dict to go from the discriminator + variable value to the discriminator class name. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = { + } + + validations = { + } + + @cached_property + def additional_properties_type(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + """ + return (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501 + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + return { + 'name': (int,), # noqa: E501 + '_class': (str,), # noqa: E501 + } + + @cached_property + def discriminator(): + return None + + + attribute_map = { + 'name': 'name', # noqa: E501 + '_class': 'class', # noqa: E501 + } + + read_only_vars = { + } + + _composed_schemas = {} + + @classmethod + @convert_js_args_to_python_args + def _from_openapi_data(cls, *args, **kwargs): # noqa: E501 + """Model_200Response - a model defined in OpenAPI + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + name (int): [optional] # noqa: E501 + _class (str): [optional] # noqa: E501 + """ + + _check_type = kwargs.pop('_check_type', True) + _spec_property_naming = kwargs.pop('_spec_property_naming', True) + _path_to_item = kwargs.pop('_path_to_item', ()) + _configuration = kwargs.pop('_configuration', None) + _visited_composed_classes = kwargs.pop('_visited_composed_classes', ()) + + self = super(OpenApiModel, cls).__new__(cls) + + if args: + for arg in args: + if isinstance(arg, dict): + kwargs.update(arg) + else: + raise ApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % ( + args, + self.__class__.__name__, + ), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + for var_name, var_value in kwargs.items(): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue + setattr(self, var_name, var_value) + return self + + required_properties = set([ + '_data_store', + '_check_type', + '_spec_property_naming', + '_path_to_item', + '_configuration', + '_visited_composed_classes', + ]) + + @convert_js_args_to_python_args + def __init__(self, *args, **kwargs): # noqa: E501 + """Model_200Response - a model defined in OpenAPI + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + name (int): [optional] # noqa: E501 + _class (str): [optional] # noqa: E501 + """ + + _check_type = kwargs.pop('_check_type', True) + _spec_property_naming = kwargs.pop('_spec_property_naming', False) + _path_to_item = kwargs.pop('_path_to_item', ()) + _configuration = kwargs.pop('_configuration', None) + _visited_composed_classes = kwargs.pop('_visited_composed_classes', ()) + + if args: + for arg in args: + if isinstance(arg, dict): + kwargs.update(arg) + else: + raise ApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % ( + args, + self.__class__.__name__, + ), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + for var_name, var_value in kwargs.items(): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue + setattr(self, var_name, var_value) + if var_name in self.read_only_vars: + raise ApiAttributeError(f"`{var_name}` is a read-only attribute. Use `from_openapi_data` to instantiate " + f"class with read only attributes.") diff --git a/samples/client/petstore/python/test/test_model_200_response.py b/samples/client/petstore/python/test/test_model_200_response.py new file mode 100644 index 00000000000..5858658d294 --- /dev/null +++ b/samples/client/petstore/python/test/test_model_200_response.py @@ -0,0 +1,35 @@ +""" + 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 +""" + + +import sys +import unittest + +import petstore_api +from petstore_api.model.model_200_response import Model_200Response + + +class TestModel_200Response(unittest.TestCase): + """Model_200Response unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testModel_200Response(self): + """Test Model_200Response""" + # FIXME: construct object with mandatory attributes with example values + # model = Model_200Response() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/docs/Model_200Response.md b/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/docs/Model_200Response.md new file mode 100644 index 00000000000..4fd119d1251 --- /dev/null +++ b/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/docs/Model_200Response.md @@ -0,0 +1,13 @@ +# Model_200Response + +Model for testing model name starting with number + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **int** | | [optional] +**_class** | **str** | | [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) + + diff --git a/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/docs/Model_Return.md b/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/docs/Model_Return.md new file mode 100644 index 00000000000..674c441551b --- /dev/null +++ b/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/docs/Model_Return.md @@ -0,0 +1,12 @@ +# Model_Return + +Model for testing reserved words + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**_return** | **int** | | [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) + + diff --git a/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/model/model_200_response.py b/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/model/model_200_response.py new file mode 100644 index 00000000000..0163993dc53 --- /dev/null +++ b/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/model/model_200_response.py @@ -0,0 +1,261 @@ +""" + 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 +""" + + +import re # noqa: F401 +import sys # noqa: F401 + +from petstore_api.model_utils import ( # noqa: F401 + ApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, + OpenApiModel +) +from petstore_api.exceptions import ApiAttributeError + + + +class Model_200Response(ModelNormal): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + discriminator_value_class_map (dict): A dict to go from the discriminator + variable value to the discriminator class name. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = { + } + + validations = { + } + + additional_properties_type = None + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + return { + 'name': (int,), # noqa: E501 + '_class': (str,), # noqa: E501 + } + + @cached_property + def discriminator(): + return None + + + attribute_map = { + 'name': 'name', # noqa: E501 + '_class': 'class', # noqa: E501 + } + + read_only_vars = { + } + + _composed_schemas = {} + + @classmethod + @convert_js_args_to_python_args + def _from_openapi_data(cls, *args, **kwargs): # noqa: E501 + """Model_200Response - a model defined in OpenAPI + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + name (int): [optional] # noqa: E501 + _class (str): [optional] # noqa: E501 + """ + + _check_type = kwargs.pop('_check_type', True) + _spec_property_naming = kwargs.pop('_spec_property_naming', True) + _path_to_item = kwargs.pop('_path_to_item', ()) + _configuration = kwargs.pop('_configuration', None) + _visited_composed_classes = kwargs.pop('_visited_composed_classes', ()) + + self = super(OpenApiModel, cls).__new__(cls) + + if args: + for arg in args: + if isinstance(arg, dict): + kwargs.update(arg) + else: + raise ApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % ( + args, + self.__class__.__name__, + ), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + for var_name, var_value in kwargs.items(): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue + setattr(self, var_name, var_value) + return self + + required_properties = set([ + '_data_store', + '_check_type', + '_spec_property_naming', + '_path_to_item', + '_configuration', + '_visited_composed_classes', + ]) + + @convert_js_args_to_python_args + def __init__(self, *args, **kwargs): # noqa: E501 + """Model_200Response - a model defined in OpenAPI + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + name (int): [optional] # noqa: E501 + _class (str): [optional] # noqa: E501 + """ + + _check_type = kwargs.pop('_check_type', True) + _spec_property_naming = kwargs.pop('_spec_property_naming', False) + _path_to_item = kwargs.pop('_path_to_item', ()) + _configuration = kwargs.pop('_configuration', None) + _visited_composed_classes = kwargs.pop('_visited_composed_classes', ()) + + if args: + for arg in args: + if isinstance(arg, dict): + kwargs.update(arg) + else: + raise ApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % ( + args, + self.__class__.__name__, + ), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + for var_name, var_value in kwargs.items(): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue + setattr(self, var_name, var_value) + if var_name in self.read_only_vars: + raise ApiAttributeError(f"`{var_name}` is a read-only attribute. Use `from_openapi_data` to instantiate " + f"class with read only attributes.") diff --git a/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/test/test_model_200_response.py b/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/test/test_model_200_response.py new file mode 100644 index 00000000000..5858658d294 --- /dev/null +++ b/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/test/test_model_200_response.py @@ -0,0 +1,35 @@ +""" + 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 +""" + + +import sys +import unittest + +import petstore_api +from petstore_api.model.model_200_response import Model_200Response + + +class TestModel_200Response(unittest.TestCase): + """Model_200Response unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testModel_200Response(self): + """Test Model_200Response""" + # FIXME: construct object with mandatory attributes with example values + # model = Model_200Response() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/docs/Model_200Response.md b/samples/openapi3/client/petstore/python-experimental/docs/Model_200Response.md new file mode 100644 index 00000000000..279ea183d9b --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/docs/Model_200Response.md @@ -0,0 +1,13 @@ +# Model_200Response + +model with an invalid class name for python, starts with a number + +#### Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **int** | | [optional] +**class** | **str** | this is a reserved python keyword | [optional] +**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [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) + diff --git a/samples/openapi3/client/petstore/python-experimental/docs/Model_Return.md b/samples/openapi3/client/petstore/python-experimental/docs/Model_Return.md new file mode 100644 index 00000000000..f81000f580e --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/docs/Model_Return.md @@ -0,0 +1,12 @@ +# Model_Return + +Model for testing reserved words + +#### Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**return** | **int** | this is a reserved python keyword | [optional] +**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [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) + diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/model_200_response.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/model_200_response.py new file mode 100644 index 00000000000..828b9619834 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/model_200_response.py @@ -0,0 +1,94 @@ +# 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 +""" + +import re # noqa: F401 +import sys # noqa: F401 +import typing # noqa: F401 + +from frozendict import frozendict # noqa: F401 + +import decimal # noqa: F401 +from datetime import date, datetime # noqa: F401 +from frozendict import frozendict # noqa: F401 + +from petstore_api.schemas import ( # noqa: F401 + AnyTypeSchema, + ComposedSchema, + DictSchema, + ListSchema, + StrSchema, + IntSchema, + Int32Schema, + Int64Schema, + Float32Schema, + Float64Schema, + NumberSchema, + DateSchema, + DateTimeSchema, + DecimalSchema, + BoolSchema, + BinarySchema, + NoneSchema, + none_type, + Configuration, + Unset, + unset, + ComposedBase, + ListBase, + DictBase, + NoneBase, + StrBase, + IntBase, + Int32Base, + Int64Base, + Float32Base, + Float64Base, + NumberBase, + DateBase, + DateTimeBase, + BoolBase, + BinaryBase, + Schema, + _SchemaValidator, + _SchemaTypeChecker, + _SchemaEnumMaker +) + + +class Model_200Response( + AnyTypeSchema +): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + model with an invalid class name for python, starts with a number + """ + name = Int32Schema + _class = StrSchema + locals()['class'] = _class + del locals()['_class'] + + def __new__( + cls, + *args: typing.Union[dict, frozendict, str, date, datetime, int, float, decimal.Decimal, None, list, tuple, bytes], + name: typing.Union[name, Unset] = unset, + _configuration: typing.Optional[Configuration] = None, + **kwargs: typing.Type[Schema], + ) -> 'Model_200Response': + return super().__new__( + cls, + *args, + name=name, + _configuration=_configuration, + **kwargs, + ) diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_model_200_response.py b/samples/openapi3/client/petstore/python-experimental/test/test_model_200_response.py new file mode 100644 index 00000000000..eade978083f --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/test/test_model_200_response.py @@ -0,0 +1,35 @@ +# 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 +""" + +import unittest + +import petstore_api +from petstore_api.model.model_200_response import Model_200Response + + +class TestModel_200Response(unittest.TestCase): + """Model_200Response unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_Model_200Response(self): + """Test Model_200Response""" + # FIXME: construct object with mandatory attributes with example values + # model = Model_200Response() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-legacy/docs/Model_200Response.md b/samples/openapi3/client/petstore/python-legacy/docs/Model_200Response.md new file mode 100644 index 00000000000..4fd119d1251 --- /dev/null +++ b/samples/openapi3/client/petstore/python-legacy/docs/Model_200Response.md @@ -0,0 +1,13 @@ +# Model_200Response + +Model for testing model name starting with number + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **int** | | [optional] +**_class** | **str** | | [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) + + diff --git a/samples/openapi3/client/petstore/python-legacy/docs/Model_Return.md b/samples/openapi3/client/petstore/python-legacy/docs/Model_Return.md new file mode 100644 index 00000000000..674c441551b --- /dev/null +++ b/samples/openapi3/client/petstore/python-legacy/docs/Model_Return.md @@ -0,0 +1,12 @@ +# Model_Return + +Model for testing reserved words + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**_return** | **int** | | [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) + + diff --git a/samples/openapi3/client/petstore/python-legacy/petstore_api/models/model_200_response.py b/samples/openapi3/client/petstore/python-legacy/petstore_api/models/model_200_response.py new file mode 100644 index 00000000000..96498ac6b1d --- /dev/null +++ b/samples/openapi3/client/petstore/python-legacy/petstore_api/models/model_200_response.py @@ -0,0 +1,157 @@ +# 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 Model_200Response(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 = { + 'name': 'int', + '_class': 'str' + } + + attribute_map = { + 'name': 'name', + '_class': 'class' + } + + def __init__(self, name=None, _class=None, local_vars_configuration=None): # noqa: E501 + """Model_200Response - 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._name = None + self.__class = None + self.discriminator = None + + if name is not None: + self.name = name + if _class is not None: + self._class = _class + + @property + def name(self): + """Gets the name of this Model_200Response. # noqa: E501 + + + :return: The name of this Model_200Response. # noqa: E501 + :rtype: int + """ + return self._name + + @name.setter + def name(self, name): + """Sets the name of this Model_200Response. + + + :param name: The name of this Model_200Response. # noqa: E501 + :type name: int + """ + + self._name = name + + @property + def _class(self): + """Gets the _class of this Model_200Response. # noqa: E501 + + + :return: The _class of this Model_200Response. # noqa: E501 + :rtype: str + """ + return self.__class + + @_class.setter + def _class(self, _class): + """Sets the _class of this Model_200Response. + + + :param _class: The _class of this Model_200Response. # noqa: E501 + :type _class: str + """ + + self.__class = _class + + 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, Model_200Response): + 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, Model_200Response): + return True + + return self.to_dict() != other.to_dict() diff --git a/samples/openapi3/client/petstore/python-legacy/test/test_model_200_response.py b/samples/openapi3/client/petstore/python-legacy/test/test_model_200_response.py new file mode 100644 index 00000000000..314ee5e3dde --- /dev/null +++ b/samples/openapi3/client/petstore/python-legacy/test/test_model_200_response.py @@ -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.model_200_response import Model_200Response # noqa: E501 +from petstore_api.rest import ApiException + +class TestModel_200Response(unittest.TestCase): + """Model_200Response unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional): + """Test Model_200Response + 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.model_200_response.Model_200Response() # noqa: E501 + if include_optional : + return Model_200Response( + name = 56, + _class = '' + ) + else : + return Model_200Response( + ) + + def testModel_200Response(self): + """Test Model_200Response""" + inst_req_only = self.make_instance(include_optional=False) + inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python/docs/Model_200Response.md b/samples/openapi3/client/petstore/python/docs/Model_200Response.md new file mode 100644 index 00000000000..3d5777b2b10 --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/Model_200Response.md @@ -0,0 +1,14 @@ +# Model_200Response + +Model for testing model name starting with number + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **int** | | [optional] +**_class** | **str** | | [optional] +**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [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) + + diff --git a/samples/openapi3/client/petstore/python/docs/Model_Return.md b/samples/openapi3/client/petstore/python/docs/Model_Return.md new file mode 100644 index 00000000000..d9c1a2d8119 --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/Model_Return.md @@ -0,0 +1,13 @@ +# Model_Return + +Model for testing reserved words + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**_return** | **int** | | [optional] +**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [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) + + diff --git a/samples/openapi3/client/petstore/python/petstore_api/model/model_200_response.py b/samples/openapi3/client/petstore/python/petstore_api/model/model_200_response.py new file mode 100644 index 00000000000..d2f97900d18 --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/model/model_200_response.py @@ -0,0 +1,267 @@ +""" + 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 +""" + + +import re # noqa: F401 +import sys # noqa: F401 + +from petstore_api.model_utils import ( # noqa: F401 + ApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, + OpenApiModel +) +from petstore_api.exceptions import ApiAttributeError + + + +class Model_200Response(ModelNormal): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + discriminator_value_class_map (dict): A dict to go from the discriminator + variable value to the discriminator class name. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = { + } + + validations = { + } + + @cached_property + def additional_properties_type(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + """ + return (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501 + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + return { + 'name': (int,), # noqa: E501 + '_class': (str,), # noqa: E501 + } + + @cached_property + def discriminator(): + return None + + + attribute_map = { + 'name': 'name', # noqa: E501 + '_class': 'class', # noqa: E501 + } + + read_only_vars = { + } + + _composed_schemas = {} + + @classmethod + @convert_js_args_to_python_args + def _from_openapi_data(cls, *args, **kwargs): # noqa: E501 + """Model_200Response - a model defined in OpenAPI + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + name (int): [optional] # noqa: E501 + _class (str): [optional] # noqa: E501 + """ + + _check_type = kwargs.pop('_check_type', True) + _spec_property_naming = kwargs.pop('_spec_property_naming', True) + _path_to_item = kwargs.pop('_path_to_item', ()) + _configuration = kwargs.pop('_configuration', None) + _visited_composed_classes = kwargs.pop('_visited_composed_classes', ()) + + self = super(OpenApiModel, cls).__new__(cls) + + if args: + for arg in args: + if isinstance(arg, dict): + kwargs.update(arg) + else: + raise ApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % ( + args, + self.__class__.__name__, + ), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + for var_name, var_value in kwargs.items(): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue + setattr(self, var_name, var_value) + return self + + required_properties = set([ + '_data_store', + '_check_type', + '_spec_property_naming', + '_path_to_item', + '_configuration', + '_visited_composed_classes', + ]) + + @convert_js_args_to_python_args + def __init__(self, *args, **kwargs): # noqa: E501 + """Model_200Response - a model defined in OpenAPI + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + name (int): [optional] # noqa: E501 + _class (str): [optional] # noqa: E501 + """ + + _check_type = kwargs.pop('_check_type', True) + _spec_property_naming = kwargs.pop('_spec_property_naming', False) + _path_to_item = kwargs.pop('_path_to_item', ()) + _configuration = kwargs.pop('_configuration', None) + _visited_composed_classes = kwargs.pop('_visited_composed_classes', ()) + + if args: + for arg in args: + if isinstance(arg, dict): + kwargs.update(arg) + else: + raise ApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % ( + args, + self.__class__.__name__, + ), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + + for var_name, var_value in kwargs.items(): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue + setattr(self, var_name, var_value) + if var_name in self.read_only_vars: + raise ApiAttributeError(f"`{var_name}` is a read-only attribute. Use `from_openapi_data` to instantiate " + f"class with read only attributes.") diff --git a/samples/openapi3/client/petstore/python/test/test_model_200_response.py b/samples/openapi3/client/petstore/python/test/test_model_200_response.py new file mode 100644 index 00000000000..5858658d294 --- /dev/null +++ b/samples/openapi3/client/petstore/python/test/test_model_200_response.py @@ -0,0 +1,35 @@ +""" + 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 +""" + + +import sys +import unittest + +import petstore_api +from petstore_api.model.model_200_response import Model_200Response + + +class TestModel_200Response(unittest.TestCase): + """Model_200Response unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testModel_200Response(self): + """Test Model_200Response""" + # FIXME: construct object with mandatory attributes with example values + # model = Model_200Response() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main()