diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java index 987fe692606c..477fa1c3ccba 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java @@ -69,6 +69,8 @@ public class CodegenModel { //The type of the value from additional properties. Used in map like objects. public String additionalPropertiesType; + //The CodegenProperty to store additional properties. Used in map like objects. + public CodegenProperty additionalProperties; @Override public String toString() { @@ -122,6 +124,7 @@ public String toString() { .append("externalDocumentation", externalDocumentation) .append("vendorExtensions", vendorExtensions) .append("additionalPropertiesType", additionalPropertiesType) + .append("additionalProperties", additionalProperties) .toString(); } @@ -553,6 +556,14 @@ public void setAdditionalPropertiesType(String additionalPropertiesType) { this.additionalPropertiesType = additionalPropertiesType; } + public void setAdditionalProperties(CodegenProperty cp) { + this.additionalProperties = cp; + } + + public CodegenProperty getAdditionalProperties() { + return additionalProperties; + } + /** * Remove duplicated properties in all variable list and update "hasMore" */ diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index b4142f360fd2..4ee817c0ca6b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -1827,6 +1827,10 @@ private CodegenDiscriminator createDiscriminator(String schemaName, Schema schem protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) { addParentContainer(codegenModel, codegenModel.name, schema); + Schema additionalPropertiesSchema = ModelUtils.getAdditionalProperties(schema); + CodegenProperty additionalProperties = fromProperty("additionalPropertiesValue", additionalPropertiesSchema); + codegenModel.setAdditionalProperties(additionalProperties); + codegenModel.setAdditionalPropertiesType(additionalProperties.dataType); } /** diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java index aa6e8ad01588..a67809facf5d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java @@ -18,6 +18,7 @@ package org.openapitools.codegen.languages; import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.MapSchema; import io.swagger.v3.oas.models.media.Schema; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; @@ -91,6 +92,8 @@ public PythonClientCodegen() { // TODO file and binary is mapped as `file` languageSpecificPrimitives.add("file"); + instantiationTypes.put("map", "dict"); + typeMapping.clear(); typeMapping.put("integer", "int"); typeMapping.put("float", "float"); @@ -238,6 +241,8 @@ public void processOpts() { supportingFiles.add(new SupportingFile("__init__package.mustache", packagePath(), "__init__.py")); supportingFiles.add(new SupportingFile("__init__model.mustache", packagePath() + File.separatorChar + modelPackage, "__init__.py")); supportingFiles.add(new SupportingFile("__init__api.mustache", packagePath() + File.separatorChar + apiPackage, "__init__.py")); + supportingFiles.add(new SupportingFile("model_utils.mustache", packagePath(), "model_utils.py")); + supportingFiles.add(new SupportingFile("exceptions.mustache", packagePath(), "exceptions.py")); if (Boolean.FALSE.equals(excludeTests)) { supportingFiles.add(new SupportingFile("__init__test.mustache", testFolder, "__init__.py")); @@ -295,6 +300,65 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert postProcessPattern(property.pattern, property.vendorExtensions); } + public void addModelImport(Map objs, CodegenModel cm, String otherModelName) { + // adds the absolute path to otherModelName as an import in CodegenModel cm + HashMap referencedModel = (HashMap) objs.get(otherModelName); + ArrayList myModel = (ArrayList) referencedModel.get("models"); + HashMap modelData = (HashMap) myModel.get(0); + String importPath = (String) modelData.get("importPath"); + // only add importPath to parameters if it isn't in importPaths + if (!cm.imports.contains(importPath)) { + cm.imports.add(importPath); + } + } + + // override with any special post-processing for all models + @SuppressWarnings({"static-method", "unchecked"}) + public Map postProcessAllModels(Map objs) { + // loop through properties of each model to update + // the model imports to absolute paths + for (Map.Entry entry : objs.entrySet()) { + Map inner = (Map) entry.getValue(); + List> models = (List>) inner.get("models"); + for (Map mo : models) { + CodegenModel cm = (CodegenModel) mo.get("model"); + // clear out imports so we will only include full path imports + cm.imports.clear(); + CodegenDiscriminator discriminator = cm.discriminator; + if (discriminator != null) { + Set mappedModels = discriminator.getMappedModels(); + for (CodegenDiscriminator.MappedModel mappedModel : mappedModels) { + String otherModelName = mappedModel.getModelName(); + addModelImport(objs, cm, otherModelName); + } + } + ArrayList> listOfLists= new ArrayList>(); + listOfLists.add(cm.allVars); + listOfLists.add(cm.requiredVars); + listOfLists.add(cm.optionalVars); + listOfLists.add(cm.vars); + for (List varList : listOfLists) { + for (CodegenProperty cp : varList) { + String otherModelName = null; + if (cp.complexType != null) { + otherModelName = cp.complexType; + } + if (cp.mostInnerItems != null) { + if (cp.mostInnerItems.complexType != null) { + otherModelName = cp.mostInnerItems.complexType; + } + } + if (otherModelName != null) { + addModelImport(objs, cm, otherModelName); + } + } + } + } + } + + return objs; + } + /* * The OpenAPI pattern spec follows the Perl convention and style of modifiers. Python * does not support this in as natural a way so it needs to convert it. See @@ -402,18 +466,62 @@ public String modelTestFileFolder() { return outputFolder + File.separatorChar + testFolder; } - @Override - public String getTypeDeclaration(Schema p) { - if (ModelUtils.isArraySchema(p)) { + /** + * Output the type declaration of the property + * + * @param schema property schema + * @return a string presentation of the property type + */ + public String getSimpleTypeDeclaration(Schema schema) { + String oasType = getSchemaType(schema); + if (typeMapping.containsKey(oasType)) { + return typeMapping.get(oasType); + } + return oasType; + } + + public String getTypeString(Schema p, String prefix, String suffix) { + // this is used to set dataType, which defines a python tuple of classes + String typeSuffix = suffix; + if (suffix == ")") { + typeSuffix = "," + suffix; + } + if (ModelUtils.isNullable(p)) { + typeSuffix = ", none_type" + suffix; + } + if (ModelUtils.isFreeFormObject(p) && ModelUtils.getAdditionalProperties(p) == null) { + if (!ModelUtils.isNullable(p)) { + typeSuffix = suffix; + } + return prefix + "bool, date, datetime, dict, float, int, list, str" + typeSuffix; + } + if (ModelUtils.isMapSchema(p)) { + Schema inner = ModelUtils.getAdditionalProperties(p); + return prefix + "{str: " + getTypeString(inner, "(", ")") + "}" + typeSuffix; + } else if (ModelUtils.isArraySchema(p)) { ArraySchema ap = (ArraySchema) p; Schema inner = ap.getItems(); - return getSchemaType(p) + "[" + getTypeDeclaration(inner) + "]"; - } else if (ModelUtils.isMapSchema(p)) { - Schema inner = ModelUtils.getAdditionalProperties(p); + return prefix + "[" + getTypeString(inner, "(", ")") + "]" + typeSuffix; + } + String baseType = getSimpleTypeDeclaration(p); + if (baseType == "file") { + baseType = "file_type"; + } + return prefix + baseType + typeSuffix; + } - return getSchemaType(p) + "(str, " + getTypeDeclaration(inner) + ")"; + @Override + public String getTypeDeclaration(Schema p) { + // this is used to set dataType, which defines a python tuple of classes + return getTypeString(p, "", ""); + } + + @Override + public String toInstantiationType(Schema property) { + if (property instanceof ArraySchema || property instanceof MapSchema || property.getAdditionalProperties() != null) { + return getSchemaType(property); } - return super.getTypeDeclaration(p); + return super.toInstantiationType(property); } @Override diff --git a/modules/openapi-generator/src/main/resources/python/api.mustache b/modules/openapi-generator/src/main/resources/python/api.mustache index 5e8027e839f0..f8908199982f 100644 --- a/modules/openapi-generator/src/main/resources/python/api.mustache +++ b/modules/openapi-generator/src/main/resources/python/api.mustache @@ -10,6 +10,22 @@ import re # noqa: F401 import six from {{packageName}}.api_client import ApiClient +from {{packageName}}.exceptions import ( + ApiTypeError, + ApiValueError +) +from {{packageName}}.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +{{#imports}} +{{{import}}} +{{/imports}} {{#operations}} @@ -26,7 +42,7 @@ class {{classname}}(object): self.api_client = api_client {{#operation}} - def {{operationId}}(self, {{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs): # noqa: E501 + def {{operationId}}(self, {{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}_check_type=False, **kwargs): # noqa: E501 """{{#summary}}{{{.}}}{{/summary}}{{^summary}}{{operationId}}{{/summary}} # noqa: E501 {{#notes}} @@ -52,12 +68,12 @@ class {{classname}}(object): """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.{{operationId}}_with_http_info({{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs) # noqa: E501 + return self.{{operationId}}_with_http_info({{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.{{operationId}}_with_http_info({{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs) # noqa: E501 + (data) = self.{{operationId}}_with_http_info({{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}_check_type=_check_type, **kwargs) # noqa: E501 return data - def {{operationId}}_with_http_info(self, {{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs): # noqa: E501 + def {{operationId}}_with_http_info(self, {{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}_check_type=False, **kwargs): # noqa: E501 """{{#summary}}{{{.}}}{{/summary}}{{^summary}}{{operationId}}{{/summary}} # noqa: E501 {{#notes}} @@ -82,15 +98,19 @@ class {{classname}}(object): returns the request thread. """ + local_var_params = locals() {{#servers.0}} local_var_hosts = [{{#servers}}'{{{url}}}'{{^-last}}, {{/-last}}{{/servers}}] # noqa: E501 local_var_host = local_var_hosts[0] - if kwargs.get('_host_index'): - if int(kwags.get('_host_index')) < 0 or int(kawgs.get('_host_index')) >= len(local_var_hosts): - raise ValueError("Invalid host index. Must be 0 <= index < %s" % len(local_var_host)) - local_var_host = local_var_hosts[int(kwargs.get('_host_index'))] + _host_index = kwargs.get('_host_index') + if _host_index: + if (int(_host_index) < 0 or + int(_host_index) >= len(local_var_hosts)): + raise ApiValueError( + "Invalid host index. Must be 0 <= index < %s" % + len(local_var_host)) + local_var_host = local_var_hosts[int(_host_index)] {{/servers.0}} - local_var_params = locals() all_params = [{{#allParams}}'{{paramName}}'{{#hasMore}}, {{/hasMore}}{{/allParams}}] # noqa: E501 all_params.append('async_req') @@ -100,19 +120,33 @@ class {{classname}}(object): for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params{{#servers.0}} and key != "_host_index"{{/servers.0}}: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method {{operationId}}" % key ) local_var_params[key] = val del local_var_params['kwargs'] +{{#hasParams}} + data_types_by_param = { +{{#allParams}} + '{{paramName}}': [{{{dataType}}}], +{{/allParams}} + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) +{{/hasParams}} {{#allParams}} {{^isNullable}} {{#required}} # verify the required parameter '{{paramName}}' is set if ('{{paramName}}' not in local_var_params or local_var_params['{{paramName}}'] is None): - raise ValueError("Missing the required parameter `{{paramName}}` when calling `{{operationId}}`") # noqa: E501 + raise ApiValueError("Missing the required parameter `{{paramName}}` when calling `{{operationId}}`") # noqa: E501 {{/required}} {{/isNullable}} {{/allParams}} @@ -122,34 +156,34 @@ class {{classname}}(object): {{#maxLength}} if ('{{paramName}}' in local_var_params and len(local_var_params['{{paramName}}']) > {{maxLength}}): - raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, length must be less than or equal to `{{maxLength}}`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, length must be less than or equal to `{{maxLength}}`") # noqa: E501 {{/maxLength}} {{#minLength}} if ('{{paramName}}' in local_var_params and len(local_var_params['{{paramName}}']) < {{minLength}}): - raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, length must be greater than or equal to `{{minLength}}`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, length must be greater than or equal to `{{minLength}}`") # noqa: E501 {{/minLength}} {{#maximum}} if '{{paramName}}' in local_var_params and local_var_params['{{paramName}}'] >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}: # noqa: E501 - raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must be a value less than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}`{{maximum}}`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must be a value less than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}`{{maximum}}`") # noqa: E501 {{/maximum}} {{#minimum}} if '{{paramName}}' in local_var_params and local_var_params['{{paramName}}'] <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}: # noqa: E501 - raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must be a value greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}`{{minimum}}`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must be a value greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}`{{minimum}}`") # noqa: E501 {{/minimum}} {{#pattern}} if '{{paramName}}' in local_var_params and not re.search(r'{{{vendorExtensions.x-regex}}}', local_var_params['{{paramName}}']{{#vendorExtensions.x-modifiers}}{{#-first}}, flags={{/-first}}re.{{.}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}}): # noqa: E501 - raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must conform to the pattern `{{{pattern}}}`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, must conform to the pattern `{{{pattern}}}`") # noqa: E501 {{/pattern}} {{#maxItems}} if ('{{paramName}}' in local_var_params and len(local_var_params['{{paramName}}']) > {{maxItems}}): - raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, number of items must be less than or equal to `{{maxItems}}`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, number of items must be less than or equal to `{{maxItems}}`") # noqa: E501 {{/maxItems}} {{#minItems}} if ('{{paramName}}' in local_var_params and len(local_var_params['{{paramName}}']) < {{minItems}}): - raise ValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, number of items must be greater than or equal to `{{minItems}}`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `{{paramName}}` when calling `{{operationId}}`, number of items must be greater than or equal to `{{minItems}}`") # noqa: E501 {{/minItems}} {{/hasValidation}} {{#-last}} @@ -214,7 +248,7 @@ class {{classname}}(object): body=body_params, post_params=form_params, files=local_var_files, - response_type={{#returnType}}'{{returnType}}'{{/returnType}}{{^returnType}}None{{/returnType}}, # noqa: E501 + response_types_mixed={{#returnType}}[{{{returnType}}}]{{/returnType}}{{^returnType}}None{{/returnType}}, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/modules/openapi-generator/src/main/resources/python/api_client.mustache b/modules/openapi-generator/src/main/resources/python/api_client.mustache index 5325a63cfacd..0d026776ced5 100644 --- a/modules/openapi-generator/src/main/resources/python/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/python/api_client.mustache @@ -2,7 +2,7 @@ {{>partial_header}} from __future__ import absolute_import -import datetime +import copy import json import mimetypes from multiprocessing.pool import ThreadPool @@ -18,6 +18,22 @@ import tornado.gen {{/tornado}} from {{packageName}}.configuration import Configuration +from {{packageName}}.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError +) +from {{packageName}}.model_utils import ( + OpenApiModel, + date, + datetime, + deserialize_file, + file_type, + model_to_dict, + none_type, + str, + validate_and_convert_types +) import {{modelPackage}} from {{packageName}} import rest @@ -44,17 +60,11 @@ class ApiClient(object): to the API. More threads means more concurrent API requests. """ - PRIMITIVE_TYPES = (float, bool, bytes, six.text_type) + six.integer_types - NATIVE_TYPES_MAPPING = { - 'int': int, - 'long': int if six.PY3 else long, # noqa: F821 - 'float': float, - 'str': str, - 'bool': bool, - 'date': datetime.date, - 'datetime': datetime.datetime, - 'object': object, - } + # six.binary_type python2=str, python3=bytes + # six.text_type python2=unicode, python3=str + PRIMITIVE_TYPES = ( + (float, bool, six.binary_type, six.text_type) + six.integer_types + ) _pool = None def __init__(self, configuration=None, header_name=None, header_value=None, @@ -105,7 +115,7 @@ class ApiClient(object): {{#asyncio}}async {{/asyncio}}def __call_api( self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, - files=None, response_type=None, auth_settings=None, + files=None, response_types_mixed=None, auth_settings=None, _return_http_data_only=None, collection_formats=None, _preload_content=True, _request_timeout=None, _host=None): @@ -172,8 +182,9 @@ class ApiClient(object): return_data = response_data if _preload_content: # deserialize response data - if response_type: - return_data = self.deserialize(response_data, response_type) + if response_types_mixed: + return_data = self.deserialize(response_data, + response_types_mixed) else: return_data = None @@ -216,89 +227,59 @@ class ApiClient(object): elif isinstance(obj, tuple): return tuple(self.sanitize_for_serialization(sub_obj) for sub_obj in obj) - elif isinstance(obj, (datetime.datetime, datetime.date)): + elif isinstance(obj, (datetime, date)): return obj.isoformat() if isinstance(obj, dict): obj_dict = obj else: - # Convert model obj to dict except - # attributes `openapi_types`, `attribute_map` - # and attributes which value is not None. + # Convert model obj to dict # Convert attribute name to json key in # model definition for request. - obj_dict = {obj.attribute_map[attr]: getattr(obj, attr) - for attr, _ in six.iteritems(obj.openapi_types) - if getattr(obj, attr) is not None} + obj_dict = model_to_dict(obj, serialize=True) return {key: self.sanitize_for_serialization(val) for key, val in six.iteritems(obj_dict)} - def deserialize(self, response, response_type): + def deserialize(self, response, response_types_mixed): """Deserializes response into an object. :param response: RESTResponse object to be deserialized. - :param response_type: class literal for - deserialized object, or string of class name. + :param response_types_mixed: For the response, a list of + valid classes, or a list tuples of valid classes, or a dict where + the value is a tuple of value classes. :return: deserialized object. """ # handle file downloading # save response body into a tmp file and return the instance - if response_type == "file": - return self.__deserialize_file(response) + if response_types_mixed == [file_type]: + content_disposition = response.getheader("Content-Disposition") + return deserialize_file(response.data, self.configuration, + content_disposition=content_disposition) # fetch data from response object try: - data = json.loads(response.data) + received_data = json.loads(response.data) except ValueError: - data = response.data + # this path is used if we are deserializing string data + received_data = response.data - return self.__deserialize(data, response_type) + # store our data under the key of 'received_data' so users have some + # context if they are deserializing a string and the data type is wrong + deserialized_data = validate_and_convert_types( + received_data, + response_types_mixed, + ['received_data'], + configuration=self.configuration + ) + return deserialized_data - def __deserialize(self, data, klass): - """Deserializes dict, list, str into an object. - - :param data: dict, list or str. - :param klass: class literal, or string of class name. - - :return: object. - """ - if data is None: - return None - - if type(klass) == str: - if klass.startswith('list['): - sub_kls = re.match(r'list\[(.*)\]', klass).group(1) - return [self.__deserialize(sub_data, sub_kls) - for sub_data in data] - - if klass.startswith('dict('): - sub_kls = re.match(r'dict\(([^,]*), (.*)\)', klass).group(2) - return {k: self.__deserialize(v, sub_kls) - for k, v in six.iteritems(data)} - - # convert str to class - if klass in self.NATIVE_TYPES_MAPPING: - klass = self.NATIVE_TYPES_MAPPING[klass] - else: - klass = getattr({{modelPackage}}, klass) - - if klass in self.PRIMITIVE_TYPES: - return self.__deserialize_primitive(data, klass) - elif klass == object: - return self.__deserialize_object(data) - elif klass == datetime.date: - return self.__deserialize_date(data) - elif klass == datetime.datetime: - return self.__deserialize_datatime(data) - else: - return self.__deserialize_model(data, klass) def call_api(self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, files=None, - response_type=None, auth_settings=None, async_req=None, + response_types_mixed=None, auth_settings=None, async_req=None, _return_http_data_only=None, collection_formats=None, _preload_content=True, _request_timeout=None, _host=None): """Makes the HTTP request (synchronous) and returns deserialized data. @@ -315,7 +296,15 @@ class ApiClient(object): :param post_params dict: Request post form parameters, for `application/x-www-form-urlencoded`, `multipart/form-data`. :param auth_settings list: Auth Settings names for the request. - :param response: Response data type. + :param response_types_mixed: For the response, a list of + valid classes, or a list tuples of valid classes, or a dict where + the value is a tuple of value classes. + Example values: + [str] + [Pet] + [float, none_type], + [[(int, none_type)]], + [{str: (bool, str, int, float, date, datetime, str, none_type)}] :param files dict: key -> filename, value -> filepath, for `multipart/form-data`. :param async_req bool: execute request asynchronously @@ -341,7 +330,7 @@ class ApiClient(object): return self.__call_api(resource_path, method, path_params, query_params, header_params, body, post_params, files, - response_type, auth_settings, + response_types_mixed, auth_settings, _return_http_data_only, collection_formats, _preload_content, _request_timeout, _host) else: @@ -349,7 +338,7 @@ class ApiClient(object): method, path_params, query_params, header_params, body, post_params, files, - response_type, auth_settings, + response_types_mixed, auth_settings, _return_http_data_only, collection_formats, _preload_content, @@ -413,7 +402,7 @@ class ApiClient(object): _request_timeout=_request_timeout, body=body) else: - raise ValueError( + raise ApiValueError( "http method must be `GET`, `HEAD`, `OPTIONS`," " `POST`, `PATCH`, `PUT` or `DELETE`." ) @@ -528,120 +517,6 @@ class ApiClient(object): elif auth_setting['in'] == 'query': querys.append((auth_setting['key'], auth_setting['value'])) else: - raise ValueError( + raise ApiValueError( 'Authentication token must be in `query` or `header`' ) - - def __deserialize_file(self, response): - """Deserializes body to file - - Saves response body into a file in a temporary folder, - using the filename from the `Content-Disposition` header if provided. - - :param response: RESTResponse. - :return: file path. - """ - fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path) - os.close(fd) - os.remove(path) - - content_disposition = response.getheader("Content-Disposition") - if content_disposition: - filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?', - content_disposition).group(1) - path = os.path.join(os.path.dirname(path), filename) - - with open(path, "wb") as f: - f.write(response.data) - - return path - - def __deserialize_primitive(self, data, klass): - """Deserializes string to primitive type. - - :param data: str. - :param klass: class literal. - - :return: int, long, float, str, bool. - """ - try: - return klass(data) - except UnicodeEncodeError: - return six.text_type(data) - except TypeError: - return data - - def __deserialize_object(self, value): - """Return an original value. - - :return: object. - """ - return value - - def __deserialize_date(self, string): - """Deserializes string to date. - - :param string: str. - :return: date. - """ - try: - from dateutil.parser import parse - return parse(string).date() - except ImportError: - return string - except ValueError: - raise rest.ApiException( - status=0, - reason="Failed to parse `{0}` as date object".format(string) - ) - - def __deserialize_datatime(self, string): - """Deserializes string to datetime. - - The string should be in iso8601 datetime format. - - :param string: str. - :return: datetime. - """ - try: - from dateutil.parser import parse - return parse(string) - except ImportError: - return string - except ValueError: - raise rest.ApiException( - status=0, - reason=( - "Failed to parse `{0}` as datetime object" - .format(string) - ) - ) - - def __deserialize_model(self, data, klass): - """Deserializes list or dict to model. - - :param data: dict, list. - :param klass: class literal. - :return: model object. - """ - - if not klass.openapi_types and not hasattr(klass, - 'get_real_child_model'): - return data - - kwargs = {} - if klass.openapi_types is not None: - for attr, attr_type in six.iteritems(klass.openapi_types): - if (data is not None and - klass.attribute_map[attr] in data and - isinstance(data, (list, dict))): - value = data[klass.attribute_map[attr]] - kwargs[attr] = self.__deserialize(value, attr_type) - - instance = klass(**kwargs) - - if hasattr(instance, 'get_real_child_model'): - klass_name = instance.get_real_child_model(data) - if klass_name: - instance = self.__deserialize(data, klass_name) - return instance diff --git a/modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache b/modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache index 727dfae42364..36b061f8f49c 100644 --- a/modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache +++ b/modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache @@ -14,6 +14,8 @@ import asyncio # python 2 and python 3 compatibility library from six.moves.urllib.parse import urlencode +from {{packageName}}.exceptions import ApiException, ApiValueError + logger = logging.getLogger(__name__) @@ -100,7 +102,7 @@ class RESTClientObject(object): 'PATCH', 'OPTIONS'] if post_params and body: - raise ValueError( + raise ApiValueError( "body parameter cannot be used with post_params parameter." ) @@ -238,30 +240,3 @@ class RESTClientObject(object): _preload_content=_preload_content, _request_timeout=_request_timeout, body=body)) - - -class ApiException(Exception): - - 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})\nReason: {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 diff --git a/modules/openapi-generator/src/main/resources/python/exceptions.mustache b/modules/openapi-generator/src/main/resources/python/exceptions.mustache new file mode 100644 index 000000000000..6e37a57edb2d --- /dev/null +++ b/modules/openapi-generator/src/main/resources/python/exceptions.mustache @@ -0,0 +1,113 @@ +# coding: utf-8 + +{{>partial_header}} + +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: + is_int = isinstance(pth, int) + if six.PY2 and isinstance(pth, long) and is_int == False: + is_int = True + if is_int: + result += "[{0}]".format(pth) + else: + result += "['{0}']".format(pth) + return result diff --git a/modules/openapi-generator/src/main/resources/python/model.mustache b/modules/openapi-generator/src/main/resources/python/model.mustache index 16c8dadbf620..1cef4c75d0df 100644 --- a/modules/openapi-generator/src/main/resources/python/model.mustache +++ b/modules/openapi-generator/src/main/resources/python/model.mustache @@ -7,10 +7,30 @@ import re # noqa: F401 import six +from {{packageName}}.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from {{packageName}}.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +{{#models}}{{#model}}{{#imports}}{{.}} +{{/imports}}{{/model}}{{/models}} {{#models}} {{#model}} -class {{classname}}(object): +class {{classname}}(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -29,52 +49,144 @@ class {{classname}}(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. +{{#additionalProperties}} + additional_properties_type (str): The attribute type for + additional_properties variables only. +{{/additionalProperties}} """ openapi_types = { -{{#vars}} - '{{name}}': '{{{dataType}}}'{{#hasMore}},{{/hasMore}} -{{/vars}} +{{#allVars}} + '{{name}}': [{{{dataType}}}]{{#hasMore}},{{/hasMore}} # noqa: E501 +{{/allVars}} } - attribute_map = { -{{#vars}} - '{{name}}': '{{baseName}}'{{#hasMore}},{{/hasMore}} -{{/vars}} +{{#allVars}} + '{{name}}': '{{baseName}}'{{#hasMore}},{{/hasMore}} # noqa: E501 +{{/allVars}} } +{{#additionalProperties}} + additional_properties_type = [{{{dataType}}}] # noqa: E501 +{{/additionalProperties}} {{#discriminator}} - discriminator_value_class_map = { - {{#children}}'{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}': '{{{classname}}}'{{^-last}}, + {{#children}}'{{^vendorExtensions.x-discriminator-value}}{{name}}{{/vendorExtensions.x-discriminator-value}}{{#vendorExtensions.x-discriminator-value}}{{{vendorExtensions.x-discriminator-value}}}{{/vendorExtensions.x-discriminator-value}}': {{{classname}}}{{^-last}}, {{/-last}}{{/children}} } {{/discriminator}} - def __init__(self{{#vars}}, {{name}}={{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}{{/vars}}): # noqa: E501 - """{{classname}} - a model defined in OpenAPI""" # noqa: E501 -{{#vars}}{{#-first}} -{{/-first}} - self._{{name}} = None -{{/vars}} + def __init__(self{{#requiredVars}}{{^defaultValue}}, {{name}}{{/defaultValue}}{{/requiredVars}}{{#requiredVars}}{{#defaultValue}}, {{name}}={{{defaultValue}}}{{/defaultValue}}{{/requiredVars}}, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """{{classname}} - a model defined in OpenAPI + +{{#requiredVars}}{{^hasMore}} Args:{{/hasMore}}{{/requiredVars}}{{#requiredVars}}{{^defaultValue}} + {{name}} ({{{dataType}}}):{{#description}} {{description}}{{/description}}{{/defaultValue}}{{/requiredVars}}{{#requiredVars}}{{#defaultValue}} + {{name}} ({{{dataType}}}):{{#description}} {{description}}.{{/description}} defaults to {{{defaultValue}}}, must be one of [{{{defaultValue}}}] # noqa: E501{{/defaultValue}}{{/requiredVars}} + + 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 False + _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 + _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.{{#optionalVars}} + {{name}} ({{{dataType}}}):{{#description}} {{description}}.{{/description}} [optional]{{#defaultValue}} if omitted the server will use the default value of {{{defaultValue}}}{{/defaultValue}} # noqa: E501{{/optionalVars}} + """ + + self._data_store = {} self.discriminator = {{#discriminator}}'{{{discriminatorName}}}'{{/discriminator}}{{^discriminator}}None{{/discriminator}} -{{#vars}}{{#-first}} -{{/-first}} -{{#required}} + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration +{{#requiredVars}}{{^hasMore}} + # assign using .var_name to check against nullable and enums{{/hasMore}}{{/requiredVars}} +{{#requiredVars}} self.{{name}} = {{name}} -{{/required}} -{{^required}} -{{#isNullable}} - self.{{name}} = {{name}} -{{/isNullable}} -{{^isNullable}} - if {{name}} is not None: - self.{{name}} = {{name}} -{{/isNullable}} -{{/required}} -{{/vars}} +{{/requiredVars}} + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: +{{#additionalProperties}} + check_type = True + required_types_mixed = self.additional_properties_type +{{/additionalProperties}} +{{^additionalProperties}} + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) +{{/additionalProperties}} + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) -{{#vars}} + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value +{{#additionalProperties}} + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name +{{/additionalProperties}} + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + +{{#allVars}} @property def {{name}}(self): """Gets the {{name}} of this {{classname}}. # noqa: E501 @@ -83,26 +195,27 @@ class {{classname}}(object): {{{description}}} # noqa: E501 {{/description}} - :return: The {{name}} of this {{classname}}. # noqa: E501 - :rtype: {{dataType}} + Returns: + ({{{dataType}}}): The {{name}} of this {{classname}}. # noqa: E501 """ - return self._{{name}} + return self._data_store.get('{{name}}') @{{name}}.setter - def {{name}}(self, {{name}}): + def {{name}}( + self, {{name}}): """Sets the {{name}} of this {{classname}}. {{#description}} {{{description}}} # noqa: E501 {{/description}} - :param {{name}}: The {{name}} of this {{classname}}. # noqa: E501 - :type: {{dataType}} + Returns: + ({{{dataType}}}): The {{name}} of this {{classname}}. # noqa: E501 """ {{^isNullable}} {{#required}} if {{name}} is None: - raise ValueError("Invalid value for `{{name}}`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `{{name}}`, must not be `None`") # noqa: E501 {{/required}} {{/isNullable}} {{#isEnum}} @@ -110,7 +223,7 @@ class {{classname}}(object): allowed_values = [{{#isNullable}}None,{{/isNullable}}{{#allowableValues}}{{#values}}{{#items.isString}}"{{/items.isString}}{{{this}}}{{#items.isString}}"{{/items.isString}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}] # noqa: E501 {{#isListContainer}} if not set({{{name}}}).issubset(set(allowed_values)): - raise ValueError( + raise ApiValueError( "Invalid values for `{{{name}}}` [{0}], must be a subset of [{1}]" # noqa: E501 .format(", ".join(map(str, set({{{name}}}) - set(allowed_values))), # noqa: E501 ", ".join(map(str, allowed_values))) @@ -118,7 +231,7 @@ class {{classname}}(object): {{/isListContainer}} {{#isMapContainer}} if not set({{{name}}}.keys()).issubset(set(allowed_values)): - raise ValueError( + raise ApiValueError( "Invalid keys in `{{{name}}}` [{0}], must be a subset of [{1}]" # noqa: E501 .format(", ".join(map(str, set({{{name}}}.keys()) - set(allowed_values))), # noqa: E501 ", ".join(map(str, allowed_values))) @@ -128,7 +241,7 @@ class {{classname}}(object): {{^isContainer}} allowed_values = [{{#isNullable}}None,{{/isNullable}}{{#allowableValues}}{{#values}}{{#isString}}"{{/isString}}{{{this}}}{{#isString}}"{{/isString}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}] # noqa: E501 if {{{name}}} not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `{{{name}}}` ({0}), must be one of {1}" # noqa: E501 .format({{{name}}}, allowed_values) ) @@ -138,38 +251,41 @@ class {{classname}}(object): {{#hasValidation}} {{#maxLength}} if {{name}} is not None and len({{name}}) > {{maxLength}}: - raise ValueError("Invalid value for `{{name}}`, length must be less than or equal to `{{maxLength}}`") # noqa: E501 + raise ApiValueError("Invalid value for `{{name}}`, length must be less than or equal to `{{maxLength}}`") # noqa: E501 {{/maxLength}} {{#minLength}} if {{name}} is not None and len({{name}}) < {{minLength}}: - raise ValueError("Invalid value for `{{name}}`, length must be greater than or equal to `{{minLength}}`") # noqa: E501 + raise ApiValueError("Invalid value for `{{name}}`, length must be greater than or equal to `{{minLength}}`") # noqa: E501 {{/minLength}} {{#maximum}} if {{name}} is not None and {{name}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}: # noqa: E501 - raise ValueError("Invalid value for `{{name}}`, must be a value less than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}`{{maximum}}`") # noqa: E501 + raise ApiValueError("Invalid value for `{{name}}`, must be a value less than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}`{{maximum}}`") # noqa: E501 {{/maximum}} {{#minimum}} if {{name}} is not None and {{name}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}: # noqa: E501 - raise ValueError("Invalid value for `{{name}}`, must be a value greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}`{{minimum}}`") # noqa: E501 + raise ApiValueError("Invalid value for `{{name}}`, must be a value greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}`{{minimum}}`") # noqa: E501 {{/minimum}} {{#pattern}} if {{name}} is not None and not re.search(r'{{{vendorExtensions.x-regex}}}', {{name}}{{#vendorExtensions.x-modifiers}}{{#-first}}, flags={{/-first}}re.{{.}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}}): # noqa: E501 - raise ValueError(r"Invalid value for `{{name}}`, must be a follow pattern or equal to `{{{pattern}}}`") # noqa: E501 + raise ApiValueError(r"Invalid value for `{{name}}`, must be a follow pattern or equal to `{{{pattern}}}`") # noqa: E501 {{/pattern}} {{#maxItems}} if {{name}} is not None and len({{name}}) > {{maxItems}}: - raise ValueError("Invalid value for `{{name}}`, number of items must be less than or equal to `{{maxItems}}`") # noqa: E501 + raise ApiValueError("Invalid value for `{{name}}`, number of items must be less than or equal to `{{maxItems}}`") # noqa: E501 {{/maxItems}} {{#minItems}} if {{name}} is not None and len({{name}}) < {{minItems}}: - raise ValueError("Invalid value for `{{name}}`, number of items must be greater than or equal to `{{minItems}}`") # noqa: E501 + raise ApiValueError("Invalid value for `{{name}}`, number of items must be greater than or equal to `{{minItems}}`") # noqa: E501 {{/minItems}} {{/hasValidation}} {{/isEnum}} - self._{{name}} = {{name}} + self.__setitem__( + '{{name}}', + {{name}} + ) -{{/vars}} +{{/allVars}} {{#discriminator}} def get_real_child_model(self, data): """Returns the real base class specified by the discriminator""" @@ -180,27 +296,7 @@ class {{classname}}(object): {{/discriminator}} 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/modules/openapi-generator/src/main/resources/python/model_doc.mustache b/modules/openapi-generator/src/main/resources/python/model_doc.mustache index 0216a3372cdb..5d9cf8b12f17 100644 --- a/modules/openapi-generator/src/main/resources/python/model_doc.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_doc.mustache @@ -3,8 +3,8 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -{{#vars}}**{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#readOnly}}[readonly] {{/readOnly}}{{#defaultValue}}[default to {{{.}}}]{{/defaultValue}} -{{/vars}} +{{#allVars}}**{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional] {{/required}}{{#readOnly}}[readonly] {{/readOnly}}{{#defaultValue}}[default to {{{.}}}]{{/defaultValue}} +{{/allVars}} [[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/modules/openapi-generator/src/main/resources/python/model_utils.mustache b/modules/openapi-generator/src/main/resources/python/model_utils.mustache new file mode 100644 index 000000000000..9479e3d8213f --- /dev/null +++ b/modules/openapi-generator/src/main/resources/python/model_utils.mustache @@ -0,0 +1,597 @@ +# coding: utf-8 + +{{>partial_header}} + +import copy +from datetime import date, datetime # noqa: F401 +import os +import re +import tempfile + +from dateutil.parser import parse +import six + +from {{packageName}}.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) + +none_type = type(None) +if six.PY3: + import io + file_type = io.IOBase + # these are needed for when other modules import str and int from here + str = str + int = int +else: + file_type = file # noqa: F821 + str_py2 = str + unicode_py2 = unicode + long_py2 = long + int_py2 = int + # this requires that the future library is installed + from builtins import int, str + + +class OpenApiModel(object): + """The base class for all OpenAPIModels""" + + +def get_simple_class(input_value): + """Returns an input_value's simple class that we will use for type checking + Python2: + float and int will return int, where int is the python3 int backport + str and unicode will return str, where str is the python3 str backport + Note: float and int ARE both instances of int backport + Note: str_py2 and unicode_py2 are NOT both instances of str backport + + Args: + input_value (class/class_instance): the item for which we will return + the simple class + """ + if isinstance(input_value, type): + # input_value is a class + return input_value + elif isinstance(input_value, list): + return list + elif isinstance(input_value, dict): + return dict + elif isinstance(input_value, none_type): + return none_type + elif isinstance(input_value, file_type): + return file_type + elif isinstance(input_value, bool): + # this must be higher than the int check because + # isinstance(True, int) == True + return bool + elif isinstance(input_value, int): + # for python2 input_value==long_instance -> return int + # where int is the python3 int backport + return int + elif isinstance(input_value, datetime): + # this must be higher than the date check because + # isinstance(datetime_instance, date) == True + return datetime + elif isinstance(input_value, date): + return datetime + elif (six.PY2 and isinstance(input_value, (str_py2, unicode_py2, str)) or + isinstance(input_value, str)): + return str + return type(input_value) + + +COERCION_INDEX_BY_TYPE = { + none_type: 0, + list: 1, + OpenApiModel: 2, + dict: 3, + float: 4, + int: 5, + bool: 6, + datetime: 7, + date: 8, + str: 9 +} + +# these are used to limit what type conversions we try to do +# when we have a valid type already and we want to try converting +# to another type +UPCONVERSION_TYPE_PAIRS = ( + (str, datetime), + (str, date), + (list, OpenApiModel), + (dict, OpenApiModel), +) + +COERCIBLE_TYPE_PAIRS = ( + (dict, OpenApiModel), + (list, OpenApiModel), + (str, int), + (str, float), + (str, datetime), + (str, date), + (int, str), + (float, str), + (str, file_type) +) + + +def order_response_types(required_types): + """Returns the required types sorted in coercion order + + Args: + required_types (list/tuple): collection of classes or instance of + list or dict with classs information inside it + + Returns: + (list): coercion order sorted collection of classes or instance + of list or dict with classs information inside it + """ + + def index_getter(class_or_instance): + if isinstance(class_or_instance, list): + return COERCION_INDEX_BY_TYPE[list] + elif isinstance(class_or_instance, dict): + return COERCION_INDEX_BY_TYPE[dict] + elif issubclass(class_or_instance, OpenApiModel): + return COERCION_INDEX_BY_TYPE[OpenApiModel] + return COERCION_INDEX_BY_TYPE[class_or_instance] + + sorted_types = sorted( + required_types, + key=lambda class_or_instance: index_getter(class_or_instance) + ) + return sorted_types + + +def remove_uncoercible(required_types_classes, current_item, must_convert=True): + """Only keeps the type conversions that are possible + + Args: + required_types_classes (tuple): tuple of classes that are required + these should be ordered by COERCION_INDEX_BY_TYPE + current_item (any): the current item to be converted + + Keyword Args: + must_convert (bool): if True the item to convert is of the wrong + type and we want a big list of coercibles + if False, we want a limited list of coercibles + + Returns: + (list): the remaining coercible required types, classes only + """ + current_type_simple = get_simple_class(current_item) + + results_classes = [] + for required_type_class in required_types_classes: + # convert our models to OpenApiModel + required_type_class_simplified = required_type_class + if isinstance(required_type_class_simplified, type): + if issubclass(required_type_class_simplified, OpenApiModel): + required_type_class_simplified = OpenApiModel + + if required_type_class_simplified == current_type_simple: + # don't consider converting to one's own class + continue + + class_pair = (current_type_simple, required_type_class_simplified) + if must_convert and class_pair in COERCIBLE_TYPE_PAIRS: + results_classes.append(required_type_class) + elif class_pair in UPCONVERSION_TYPE_PAIRS: + results_classes.append(required_type_class) + return results_classes + + +def get_required_type_classes(required_types_mixed): + """Converts the tuple required_types into a tuple and a dict described + below + + Args: + required_types_mixed (tuple/list): will contain either classes or + instance of list or dict + + Returns: + (valid_classes, dict_valid_class_to_child_types_mixed): + valid_classes (tuple): the valid classes that the current item + should be + dict_valid_class_to_child_types_mixed (doct): + valid_class (class): this is the key + child_types_mixed (list/dict/tuple): describes the valid child + types + """ + valid_classes = [] + child_req_types_by_current_type = {} + for required_type in required_types_mixed: + if isinstance(required_type, list): + valid_classes.append(list) + child_req_types_by_current_type[list] = required_type[0] + elif isinstance(required_type, dict): + valid_classes.append(dict) + child_req_types_by_current_type[dict] = required_type[str] + else: + valid_classes.append(required_type) + return tuple(valid_classes), child_req_types_by_current_type + + +def change_keys_js_to_python(input_dict, model_class): + """ + Converts from javascript_key keys in the input_dict to python_keys in + the output dict using the mapping in model_class + """ + + output_dict = {} + reversed_attr_map = {value: key for key, value in + six.iteritems(model_class.attribute_map)} + for javascript_key, value in six.iteritems(input_dict): + python_key = reversed_attr_map.get(javascript_key) + if python_key is None: + # if the key is unknown, it is in error or it is an + # additionalProperties variable + python_key = javascript_key + output_dict[python_key] = value + return output_dict + + +def get_type_error(var_value, path_to_item, valid_classes, key_type=False): + error_msg = type_error_message( + var_name=path_to_item[-1], + var_value=var_value, + valid_classes=valid_classes, + key_type=key_type + ) + return ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=valid_classes, + key_type=key_type + ) + + +def deserialize_primitive(data, klass, path_to_item): + """Deserializes string to primitive type. + + :param data: str/int/float + :param klass: str/class the class to convert to + + :return: int, float, str, bool, date, datetime + """ + additional_message = "" + try: + if klass in {datetime, date}: + additional_message = ( + "If you need your parameter to have a fallback " + "string value, please set its type as `type: {}` in your " + "spec. That allows the value to be any type. " + ) + if klass == datetime: + if len(data) < 8: + raise ValueError("This is not a datetime") + # The string should be in iso8601 datetime format. + parsed_datetime = parse(data) + date_only = (parsed_datetime.hour == 0 and + parsed_datetime.minute == 0 and + parsed_datetime.second == 0 and + parsed_datetime.tzinfo == None and + 8 <= len(data) <= 10) + if date_only: + raise ValueError("This is a date, not a datetime") + return parsed_datetime + elif klass == date: + if len(data) < 8: + raise ValueError("This is not a date") + return parse(data).date() + else: + converted_value = klass(data) + if isinstance(data, str) and klass == float: + if str(converted_value) != data: + # '7' -> 7.0 -> '7.0' != '7' + raise ValueError('This is not a float') + return converted_value + except (OverflowError, ValueError): + # parse can raise OverflowError + raise ApiValueError( + "{0}Failed to parse {1} as {2}".format( + additional_message, repr(data), get_py3_class_name(klass) + ), + path_to_item=path_to_item + ) + + +def deserialize_model(model_data, model_class, path_to_item, configuration): + """Deserializes model_data to model instance. + + Args: + model_data (list/dict): data to instantiate the model + model_class (OpenApiModel): the model class + path_to_item (list): path to the model in the received data + configuration (Configuration): the instance to use to convert files + + Returns: + model instance + + Raise: + ApiTypeError + ApiValueError + ApiKeyError + """ + fixed_model_data = copy.deepcopy(model_data) + + if isinstance(fixed_model_data, dict): + fixed_model_data = change_keys_js_to_python(fixed_model_data, + model_class) + + kw_args = dict(_check_type=True, + _path_to_item=path_to_item, + _configuration=configuration) + if isinstance(model_data, list): + instance = model_class(*model_data, **kw_args) + elif isinstance(model_data, dict): + kw_args.update(fixed_model_data) + instance = model_class(**kw_args) + + if hasattr(instance, 'get_real_child_model'): + discriminator_class = instance.get_real_child_model(model_data) + if discriminator_class: + if isinstance(model_data, list): + instance = discriminator_class(*model_data, **kw_args) + elif isinstance(model_data, dict): + instance = discriminator_class(**kw_args) + + return instance + + +def deserialize_file(response_data, configuration, content_disposition=None): + """Deserializes body to file + + Saves response body into a file in a temporary folder, + using the filename from the `Content-Disposition` header if provided. + + Args: + param response_data (str): the file data to write + configuration (Configuration): the instance to use to convert files + + Keyword Args: + content_disposition (str): the value of the Content-Disposition + header + + Returns: + (str): the deserialized file path + """ + fd, path = tempfile.mkstemp(dir=configuration.temp_folder_path) + os.close(fd) + os.remove(path) + + if content_disposition: + filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?', + content_disposition).group(1) + path = os.path.join(os.path.dirname(path), filename) + + with open(path, "wb") as f: + if six.PY3 and isisinstance(response_data, str): + # in python3 change str to bytes so we can write it + response_data = response_data.encode('utf-8') + f.write(response_data) + + return path + + +def attempt_convert_item(input_value, valid_classes, path_to_item, + configuration, key_type=False, must_convert=False): + """ + Args: + input_value (any): the data to convert + valid_classes (any): the classes that are valid + path_to_item (list): the path to the item to convert + configuration (Configuration): the instance to use to convert files + key_type (bool): if True we need to convert a key type (not supported) + must_convert (bool): if True we must convert + + Returns: + instance (any) the fixed item + + Raises: + ApiTypeError + ApiValueError + ApiKeyError + """ + valid_classes_ordered = order_response_types(valid_classes) + valid_classes_coercible = remove_uncoercible( + valid_classes_ordered, input_value) + if not valid_classes_coercible or key_type: + # we do not handle keytype errors, json will take care + # of this for us + raise get_type_error(input_value, path_to_item, valid_classes, + key_type=key_type) + deserialized_item = None + for valid_class in valid_classes_coercible: + try: + if issubclass(valid_class, OpenApiModel): + return deserialize_model(input_value, valid_class, + path_to_item, configuration) + elif valid_class == file_type: + return deserialize_file(input_value, configuration) + return deserialize_primitive(input_value, valid_class, + path_to_item) + except (ApiTypeError, ApiValueError, ApiKeyError) as conversion_exc: + if must_convert: + raise conversion_exc + # if we have conversion errors when must_convert == False + # we ignore the exception and move on to the next class + continue + # we were unable to convert, must_convert == False + return input_value + + +def validate_and_convert_types(input_value, required_types_mixed, path_to_item, + configuration=None): + """Raises a TypeError is there is a problem, otherwise returns value + + Args: + input_value (any): the data to validate/convert + required_types_mixed (list/dict/tuple): A list of + valid classes, or a list tuples of valid classes, or a dict where + the value is a tuple of value classes + path_to_item: (list) the path to the data being validated + this stores a list of keys or indices to get to the data being + validated + configuration: (Configuration): the configuration class to use + when converting file_type items. + If passed, conversion will be attempted when possible + If not passed, no conversions will be attempted and + exceptions will be raised + + Returns: + the correctly typed value + + Raises: + ApiTypeError + """ + results = get_required_type_classes(required_types_mixed) + valid_classes, child_req_types_by_current_type = results + + input_class_simple = get_simple_class(input_value) + valid_type = input_class_simple in set(valid_classes) + if not valid_type: + if configuration: + # if input_value is not valid_type try to convert it + converted_instance = attempt_convert_item(input_value, + valid_classes, path_to_item, configuration, key_type=False, + must_convert=True) + return converted_instance + else: + raise get_type_error(input_value, path_to_item, valid_classes, + key_type=False) + + # input_value's type is in valid_classes + if len(valid_classes) > 1 and configuration: + # there are valid classes which are not the current class + valid_classes_coercible = remove_uncoercible( + valid_classes, input_value, must_convert=False) + if valid_classes_coercible: + converted_instance = attempt_convert_item(input_value, + valid_classes_coercible, path_to_item, configuration, + key_type=False, must_convert=False) + return converted_instance + + if child_req_types_by_current_type == {}: + # all types are of the required types and there are no more inner + # variables left to look at + return input_value + inner_required_types = child_req_types_by_current_type.get( + type(input_value) + ) + if inner_required_types is None: + # for this type, there are not more inner variables left to look at + return input_value + if isinstance(input_value, list): + if input_value == []: + # allow an empty list + return input_value + for index, inner_value in enumerate(input_value): + inner_path = list(path_to_item) + inner_path.append(index) + input_value[index] = validate_and_convert_types(inner_value, + inner_required_types, inner_path, configuration=configuration) + elif isinstance(input_value, dict): + if input_value == {}: + # allow an empty dict + return input_value + for inner_key, inner_val in six.iteritems(input_value): + inner_path = list(path_to_item) + inner_path.append(inner_key) + if get_simple_class(inner_key) != str: + raise get_type_error(inner_key, inner_path, valid_classes, + key_type=True) + input_value[inner_key] = validate_and_convert_types(inner_val, + inner_required_types, inner_path, configuration=configuration) + return input_value + + +def model_to_dict(model_instance, serialize=True): + """Returns the model properties as a dict + + Args: + model_instance (one of your model instances): the model instance that + will be converted to a dict. + + Keyword Args: + serialize (bool): if True, the keys in the dict will be values from + attribute_map + """ + result = {} + + for attr, value in six.iteritems(model_instance._data_store): + if serialize: + attr = model_instance.attribute_map[attr] + if isinstance(value, list): + result[attr] = list(map( + lambda x: model_to_dict(x, serialize=serialize) + if hasattr(x, '_data_store') else x, value + )) + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], + model_to_dict(item[1], serialize=serialize)) + if hasattr(item[1], '_data_store') else item, + value.items() + )) + elif hasattr(value, '_data_store'): + result[attr] = model_to_dict(value, serialize=serialize) + else: + result[attr] = value + + return result + + +def type_error_message(var_value=None, var_name=None, valid_classes=None, + key_type=None): + """ + Keyword Args: + var_value (any): the variable which has the type_error + var_name (str): the name of the variable which has the typ error + valid_classes (tuple): the accepted classes for current_item's + value + 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 + """ + key_or_value = 'value' + if key_type: + key_or_value = 'key' + valid_classes_phrase = get_valid_classes_phrase(valid_classes) + msg = ( + "Invalid type for variable '{0}'. Required {1} type {2} and " + "passed type was {3}".format( + var_name, + key_or_value, + valid_classes_phrase, + type(var_value).__name__, + ) + ) + return msg + + +def get_valid_classes_phrase(input_classes): + """Returns a string phrase describing what types are allowed + Note: Adds the extra valid classes in python2 + """ + all_classes = list(input_classes) + if six.PY2 and str in input_classes: + all_classes.extend([str_py2, unicode_py2]) + if six.PY2 and int in input_classes: + all_classes.extend([int_py2, long_py2]) + all_classes = sorted(all_classes, key=lambda cls: cls.__name__) + all_class_names = [cls.__name__ for cls in all_classes] + if len(all_class_names) == 1: + return 'is {0}'.format(all_class_names[0]) + return "is one of [{0}]".format(", ".join(all_class_names)) + + +def get_py3_class_name(input_class): + if six.PY2: + if input_class == str: + return 'str' + elif input_class == int: + return 'int' + return input_class.__name__ diff --git a/modules/openapi-generator/src/main/resources/python/requirements.mustache b/modules/openapi-generator/src/main/resources/python/requirements.mustache index bafdc07532f5..2e252c8a0833 100644 --- a/modules/openapi-generator/src/main/resources/python/requirements.mustache +++ b/modules/openapi-generator/src/main/resources/python/requirements.mustache @@ -1,5 +1,6 @@ certifi >= 14.05.14 -six >= 1.10 +future; python_version<="2.7" python_dateutil >= 2.5.3 setuptools >= 21.0.0 +six >= 1.10 urllib3 >= 1.15.1 diff --git a/modules/openapi-generator/src/main/resources/python/rest.mustache b/modules/openapi-generator/src/main/resources/python/rest.mustache index 8418ec2a0fde..e197f63efeb4 100644 --- a/modules/openapi-generator/src/main/resources/python/rest.mustache +++ b/modules/openapi-generator/src/main/resources/python/rest.mustache @@ -14,12 +14,9 @@ import certifi # python 2 and python 3 compatibility library import six from six.moves.urllib.parse import urlencode +import urllib3 -try: - import urllib3 -except ImportError: - raise ImportError('OpenAPI Python client requires urllib3.') - +from {{packageName}}.exceptions import ApiException, ApiValueError logger = logging.getLogger(__name__) @@ -122,7 +119,7 @@ class RESTClientObject(object): 'PATCH', 'OPTIONS'] if post_params and body: - raise ValueError( + raise ApiValueError( "body parameter cannot be used with post_params parameter." ) @@ -284,31 +281,3 @@ class RESTClientObject(object): _preload_content=_preload_content, _request_timeout=_request_timeout, body=body) - - -class ApiException(Exception): - - 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 diff --git a/modules/openapi-generator/src/main/resources/python/setup.mustache b/modules/openapi-generator/src/main/resources/python/setup.mustache index 201b79e217cb..f4b2d9f42fd9 100644 --- a/modules/openapi-generator/src/main/resources/python/setup.mustache +++ b/modules/openapi-generator/src/main/resources/python/setup.mustache @@ -32,6 +32,11 @@ setup( url="{{packageUrl}}", keywords=["OpenAPI", "OpenAPI-Generator", "{{{appName}}}"], install_requires=REQUIRES, + extras_require={ + ':python_version <= "2.7"': [ + 'future', + ], + }, packages=find_packages(), include_package_data=True, long_description="""\ diff --git a/modules/openapi-generator/src/main/resources/python/tornado/rest.mustache b/modules/openapi-generator/src/main/resources/python/tornado/rest.mustache index bc74fbc295b2..e7a760f37060 100644 --- a/modules/openapi-generator/src/main/resources/python/tornado/rest.mustache +++ b/modules/openapi-generator/src/main/resources/python/tornado/rest.mustache @@ -15,6 +15,8 @@ import tornado.gen from tornado import httpclient from urllib3.filepost import encode_multipart_formdata +from {{packageName}}.exceptions import ApiException, ApiValueError + logger = logging.getLogger(__name__) @@ -87,7 +89,7 @@ class RESTClientObject(object): 'PATCH', 'OPTIONS'] if post_params and body: - raise ValueError( + raise ApiValueError( "body parameter cannot be used with post_params parameter." ) @@ -225,31 +227,3 @@ class RESTClientObject(object): _request_timeout=_request_timeout, body=body) raise tornado.gen.Return(result) - - -class ApiException(Exception): - - 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})\nReason: {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 diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonTest.java index 7a2a37f4132d..a8e9f7d7e028 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonTest.java @@ -134,7 +134,7 @@ public void listPropertyTest() { final CodegenProperty property2 = cm.vars.get(1); Assert.assertEquals(property2.baseName, "urls"); - Assert.assertEquals(property2.dataType, "list[str]"); + Assert.assertEquals(property2.dataType, "[(str,)]"); Assert.assertEquals(property2.name, "urls"); Assert.assertNull(property2.defaultValue); Assert.assertEquals(property2.baseType, "list"); @@ -164,7 +164,7 @@ public void mapPropertyTest() { final CodegenProperty property1 = cm.vars.get(0); Assert.assertEquals(property1.baseName, "translations"); - Assert.assertEquals(property1.dataType, "dict(str, str)"); + Assert.assertEquals(property1.dataType, "{str: (str,)}"); Assert.assertEquals(property1.name, "translations"); Assert.assertEquals(property1.baseType, "dict"); Assert.assertEquals(property1.containerType, "map"); @@ -216,7 +216,7 @@ public void complexListPropertyTest() { final CodegenProperty property1 = cm.vars.get(0); Assert.assertEquals(property1.baseName, "children"); Assert.assertEquals(property1.complexType, "Children"); - Assert.assertEquals(property1.dataType, "list[Children]"); + Assert.assertEquals(property1.dataType, "[(Children,)]"); Assert.assertEquals(property1.name, "children"); Assert.assertEquals(property1.baseType, "list"); Assert.assertEquals(property1.containerType, "array"); @@ -244,7 +244,7 @@ public void complexMapPropertyTest() { final CodegenProperty property1 = cm.vars.get(0); Assert.assertEquals(property1.baseName, "children"); Assert.assertEquals(property1.complexType, "Children"); - Assert.assertEquals(property1.dataType, "dict(str, Children)"); + Assert.assertEquals(property1.dataType, "{str: (Children,)}"); Assert.assertEquals(property1.name, "children"); Assert.assertEquals(property1.baseType, "dict"); Assert.assertEquals(property1.containerType, "map"); @@ -269,7 +269,7 @@ public void arrayModelTest() { Assert.assertEquals(cm.classname, "Sample"); Assert.assertEquals(cm.description, "an array model"); Assert.assertEquals(cm.vars.size(), 0); - Assert.assertEquals(cm.parent, "null"); + Assert.assertEquals(cm.parent, "list"); Assert.assertEquals(cm.imports.size(), 1); Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("Children")).size(), 1); } @@ -289,7 +289,7 @@ public void mapModelTest() { Assert.assertEquals(cm.classname, "Sample"); Assert.assertEquals(cm.description, "a map model"); Assert.assertEquals(cm.vars.size(), 0); - Assert.assertEquals(cm.parent, "null"); + Assert.assertEquals(cm.parent, "dict"); Assert.assertEquals(cm.imports.size(), 1); Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("Children")).size(), 1); } diff --git a/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml index 2de23983ffb3..8d7070b2df4e 100644 --- a/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml @@ -1391,16 +1391,105 @@ definitions: AdditionalPropertiesClass: type: object properties: - map_property: + map_string: type: object additionalProperties: type: string - map_of_map_property: + map_number: + type: object + additionalProperties: + type: number + map_integer: + type: object + additionalProperties: + type: integer + map_boolean: + type: object + additionalProperties: + type: boolean + map_array_integer: + type: object + additionalProperties: + type: array + items: + type: integer + map_array_anytype: + type: object + additionalProperties: + type: array + items: + type: object + map_map_string: type: object additionalProperties: type: object additionalProperties: type: string + map_map_anytype: + type: object + additionalProperties: + type: object + additionalProperties: + type: object + anytype_1: + type: object + anytype_2: {} + anytype_3: + type: object + properties: {} + AdditionalPropertiesString: + type: object + properties: + name: + type: string + additionalProperties: + type: string + AdditionalPropertiesInteger: + type: object + properties: + name: + type: string + additionalProperties: + type: integer + AdditionalPropertiesNumber: + type: object + properties: + name: + type: string + additionalProperties: + type: number + AdditionalPropertiesBoolean: + type: object + properties: + name: + type: string + additionalProperties: + type: boolean + AdditionalPropertiesArray: + type: object + properties: + name: + type: string + additionalProperties: + type: array + items: + type: object + AdditionalPropertiesObject: + type: object + properties: + name: + type: string + additionalProperties: + type: object + additionalProperties: + type: object + AdditionalPropertiesAnyType: + type: object + properties: + name: + type: string + additionalProperties: + type: object MixedPropertiesAndAdditionalPropertiesClass: type: object properties: diff --git a/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml index 35335d5cdc3c..a8a0687c738c 100644 --- a/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml @@ -1380,7 +1380,7 @@ components: maxLength: 64 minLength: 10 pattern_with_digits: - description: A string that is a 10 digit number. Can have leading zeros. + description: A string that is a 10 digit number. Can have leading zeros. type: string pattern: '^\d{10}$' pattern_with_digits_and_delimiter: @@ -1654,3 +1654,61 @@ components: nullable: true type: string description: Just a string to inform instance is up and running. Make it nullable in hope to get it as pointer in generated model. + NullableClass: + type: object + properties: + integer_prop: + type: integer + nullable: true + number_prop: + type: number + nullable: true + boolean_prop: + type: boolean + nullable: true + string_prop: + type: string + nullable: true + date_prop: + type: string + format: date + nullable: true + datetime_prop: + type: string + format: date-time + nullable: true + array_nullable_prop: + type: array + nullable: true + items: + type: object + array_and_items_nullable_prop: + type: array + nullable: true + items: + type: object + nullable: true + array_items_nullable: + type: array + items: + type: object + nullable: true + object_nullable_prop: + type: object + nullable: true + additionalProperties: + type: object + object_and_items_nullable_prop: + type: object + nullable: true + additionalProperties: + type: object + nullable: true + object_items_nullable: + type: object + additionalProperties: + type: object + nullable: true + additionalProperties: + type: object + nullable: true diff --git a/samples/client/petstore-security-test/python/README.md b/samples/client/petstore-security-test/python/README.md index 72ef2b830b1c..d1ed889e202c 100644 --- a/samples/client/petstore-security-test/python/README.md +++ b/samples/client/petstore-security-test/python/README.md @@ -51,6 +51,7 @@ import petstore_api from petstore_api.rest import ApiException from pprint import pprint + # create an instance of the API class api_instance = petstore_api.FakeApi(petstore_api.ApiClient(configuration)) test_code_inject____end____rn_n_r = 'test_code_inject____end____rn_n_r_example' # str | To test code injection */ ' \\\" =end -- \\\\r\\\\n \\\\n \\\\r (optional) @@ -86,6 +87,7 @@ Class | Method | HTTP request | Description - **API key parameter name**: api_key */ ' " =end -- \r\n \n \r - **Location**: HTTP header + ## petstore_auth - **Type**: OAuth diff --git a/samples/client/petstore-security-test/python/docs/FakeApi.md b/samples/client/petstore-security-test/python/docs/FakeApi.md index 559e39fb202d..42a1ec123079 100644 --- a/samples/client/petstore-security-test/python/docs/FakeApi.md +++ b/samples/client/petstore-security-test/python/docs/FakeApi.md @@ -15,6 +15,7 @@ To test code injection */ ' \" =end -- \\r\\n \\n \\r To test code injection */ ' \" =end -- \\r\\n \\n \\r ### Example + ```python from __future__ import print_function import time diff --git a/samples/client/petstore-security-test/python/petstore_api/configuration.py b/samples/client/petstore-security-test/python/petstore_api/configuration.py index ec9b97540828..b7ae97b238d5 100644 --- a/samples/client/petstore-security-test/python/petstore_api/configuration.py +++ b/samples/client/petstore-security-test/python/petstore_api/configuration.py @@ -60,10 +60,8 @@ def __init__(self): self.username = "" # Password for HTTP basic authentication self.password = "" - - # access token for OAuth + # access token for OAuth/Bearer self.access_token = "" - # Logging Settings self.logger = {} self.logger["package_logger"] = logging.getLogger("petstore_api") @@ -223,7 +221,6 @@ def auth_settings(self): 'key': 'api_key */ ' " =end -- \r\n \n \r', 'value': self.get_api_key_with_prefix('api_key */ ' " =end -- \r\n \n \r') }, - 'petstore_auth': { 'type': 'oauth2', @@ -231,7 +228,6 @@ def auth_settings(self): 'key': 'Authorization', 'value': 'Bearer ' + self.access_token }, - } def to_debug_report(self): @@ -245,3 +241,54 @@ def to_debug_report(self): "Version of the API: 1.0.0 */ ' \" =end -- \\r\\n \\n \\r\n"\ "SDK Package Version: 1.0.0".\ format(env=sys.platform, pyversion=sys.version) + + def get_host_settings(self): + """Gets an array of host settings + + :return: An array of host settings + """ + return [ + { + 'url': "//petstore.swagger.io */ ' " =end -- \r\n \n \r/v2 */ ' " =end -- \r\n \n \r", + 'description': "No description provided", + } + ] + + def get_host_from_settings(self, index, variables={}): + """Gets host URL based on the index and variables + :param index: array index of the host settings + :param variables: hash of variable and the corresponding value + :return: URL based on host settings + """ + + servers = self.get_host_settings() + + # check array index out of bound + if index < 0 or index >= len(servers): + raise ValueError( + "Invalid index {} when selecting the host settings. Must be less than {}" # noqa: E501 + .format(index, len(servers))) + + server = servers[index] + url = server['url'] + + # go through variable and assign a value + for variable_name in server['variables']: + if variable_name in variables: + if variables[variable_name] in server['variables'][ + variable_name]['enum_values']: + url = url.replace("{" + variable_name + "}", + variables[variable_name]) + else: + raise ValueError( + "The variable `{}` in the host URL has invalid value {}. Must be {}." # noqa: E501 + .format( + variable_name, variables[variable_name], + server['variables'][variable_name]['enum_values'])) + else: + # use default value + url = url.replace( + "{" + variable_name + "}", + server['variables'][variable_name]['default_value']) + + return url diff --git a/samples/client/petstore-security-test/python/petstore_api/models/model_return.py b/samples/client/petstore-security-test/python/petstore_api/models/model_return.py index c3d94ad9eaba..b072e539d470 100644 --- a/samples/client/petstore-security-test/python/petstore_api/models/model_return.py +++ b/samples/client/petstore-security-test/python/petstore_api/models/model_return.py @@ -34,19 +34,76 @@ class ModelReturn(object): openapi_types = { '_return': 'int' } - attribute_map = { '_return': 'return' } - def __init__(self, _return=None): # noqa: E501 - """ModelReturn - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, **kwargs): # noqa: E501 + """ModelReturn - a model defined in OpenAPI + + + + Keyword Args: + _return (int): property description */ ' \" =end -- \\r\\n \\n \\r. [optional] + + """ # noqa: E501 + + self._data_store = {} - self.__return = None self.discriminator = None - if _return is not None: - self._return = _return + for var_name, var_value in six.iteritems(kwargs): + self.__setitem__(var_name, var_value) + + def recursive_type(self, item): + """Gets a string describing the full the recursive type of a value""" + item_type = type(item) + if item_type == dict: + child_key_types = set() + child_value_types = set() + for child_key, child_value in six.iteritems(item): + child_key_types.add(self.recursive_type(child_key)) + child_value_types.add(self.recursive_type(child_value)) + if child_key_types != set(['str']): + raise ValueError('Invalid dict key type. All Openapi dict keys must be strings') + child_value_types = '|'.join(sorted(list(child_value_types))) + return "dict(str, {0})".format(child_value_types) + elif item_type == list: + child_value_types = set() + for child_item in item: + child_value_types.add(self.recursive_type(child_item)) + child_value_types = '|'.join(sorted(list(child_value_types))) + return "list[{0}]".format(child_value_types) + else: + return type(item).__name__ + + def __setitem__(self, name, value): + check_type = False + if name in self.openapi_types: + required_type = self.openapi_types[name] + else: + raise KeyError("{0} has no key '{1}'".format( + type(self).__name__, name)) + + passed_type = self.recursive_type(value) + if type(name) != str: + raise TypeError('Variable name must be type string and %s was not' % name) + elif passed_type != required_type and check_type: + raise ValueError('Variable value must be type %s but you passed in %s' % + (required_type, passed_type)) + + if name in self.openapi_types: + setattr(self, name, value) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + raise KeyError("{0} has no key {1}".format( + type(self).__name__, name)) @property def _return(self): @@ -57,7 +114,7 @@ def _return(self): :return: The _return of this ModelReturn. # noqa: E501 :rtype: int """ - return self.__return + return self._data_store.get('_return') @_return.setter def _return(self, _return): @@ -69,14 +126,13 @@ def _return(self, _return): :type: int """ - self.__return = _return + self._data_store['_return'] = _return def to_dict(self): """Returns the model properties as a dict""" result = {} - for attr, _ in six.iteritems(self.openapi_types): - value = getattr(self, attr) + for attr, value in six.iteritems(self._data_store): if isinstance(value, list): result[attr] = list(map( lambda x: x.to_dict() if hasattr(x, "to_dict") else x, diff --git a/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Model/AdditionalPropertiesClass.cs b/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Model/AdditionalPropertiesClass.cs index adafe21ea167..a6b422548eba 100644 --- a/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Model/AdditionalPropertiesClass.cs +++ b/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Model/AdditionalPropertiesClass.cs @@ -28,14 +28,14 @@ namespace Org.OpenAPITools.Model /// AdditionalPropertiesClass /// [DataContract] - public partial class AdditionalPropertiesClass : IEquatable, IValidatableObject + public partial class AdditionalPropertiesClass : Dictionary, IEquatable, IValidatableObject { /// /// Initializes a new instance of the class. /// /// mapProperty. /// mapOfMapProperty. - public AdditionalPropertiesClass(Dictionary mapProperty = default(Dictionary), Dictionary> mapOfMapProperty = default(Dictionary>)) + public AdditionalPropertiesClass(Dictionary mapProperty = default(Dictionary), Dictionary> mapOfMapProperty = default(Dictionary>)) : base() { this.MapProperty = mapProperty; this.MapOfMapProperty = mapOfMapProperty; @@ -61,6 +61,7 @@ public override string ToString() { var sb = new StringBuilder(); sb.Append("class AdditionalPropertiesClass {\n"); + sb.Append(" ").Append(base.ToString().Replace("\n", "\n ")).Append("\n"); sb.Append(" MapProperty: ").Append(MapProperty).Append("\n"); sb.Append(" MapOfMapProperty: ").Append(MapOfMapProperty).Append("\n"); sb.Append("}\n"); @@ -71,7 +72,7 @@ public override string ToString() /// Returns the JSON string presentation of the object /// /// JSON string presentation of the object - public virtual string ToJson() + public string ToJson() { return JsonConvert.SerializeObject(this, Formatting.Indented); } @@ -96,12 +97,12 @@ public bool Equals(AdditionalPropertiesClass input) if (input == null) return false; - return + return base.Equals(input) && ( this.MapProperty == input.MapProperty || this.MapProperty != null && this.MapProperty.SequenceEqual(input.MapProperty) - ) && + ) && base.Equals(input) && ( this.MapOfMapProperty == input.MapOfMapProperty || this.MapOfMapProperty != null && @@ -117,7 +118,7 @@ public override int GetHashCode() { unchecked // Overflow is fine, just wrap { - int hashCode = 41; + int hashCode = base.GetHashCode(); if (this.MapProperty != null) hashCode = hashCode * 59 + this.MapProperty.GetHashCode(); if (this.MapOfMapProperty != null) diff --git a/samples/client/petstore/go/go-petstore/api/openapi.yaml b/samples/client/petstore/go/go-petstore/api/openapi.yaml index 2b13b056b955..8b0c07512488 100644 --- a/samples/client/petstore/go/go-petstore/api/openapi.yaml +++ b/samples/client/petstore/go/go-petstore/api/openapi.yaml @@ -1475,6 +1475,8 @@ components: - enum_string_required type: object AdditionalPropertiesClass: + additionalProperties: + type: string properties: map_property: additionalProperties: diff --git a/samples/client/petstore/haskell-http-client/openapi.yaml b/samples/client/petstore/haskell-http-client/openapi.yaml index 2b13b056b955..8b0c07512488 100644 --- a/samples/client/petstore/haskell-http-client/openapi.yaml +++ b/samples/client/petstore/haskell-http-client/openapi.yaml @@ -1475,6 +1475,8 @@ components: - enum_string_required type: object AdditionalPropertiesClass: + additionalProperties: + type: string properties: map_property: additionalProperties: diff --git a/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index 7a3b327765d8..2abf26475949 100644 --- a/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/feign/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -28,7 +28,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") private Map mapProperty = new HashMap(); @@ -98,12 +98,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -111,6 +112,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/feign10x/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/feign10x/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index 7a3b327765d8..2abf26475949 100644 --- a/samples/client/petstore/java/feign10x/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/feign10x/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -28,7 +28,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") private Map mapProperty = new HashMap(); @@ -98,12 +98,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -111,6 +112,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/google-api-client/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/google-api-client/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index 7a3b327765d8..2abf26475949 100644 --- a/samples/client/petstore/java/google-api-client/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/google-api-client/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -28,7 +28,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") private Map mapProperty = new HashMap(); @@ -98,12 +98,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -111,6 +112,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/jersey1/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/jersey1/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index 7a3b327765d8..2abf26475949 100644 --- a/samples/client/petstore/java/jersey1/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/jersey1/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -28,7 +28,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") private Map mapProperty = new HashMap(); @@ -98,12 +98,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -111,6 +112,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/jersey2-java6/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/jersey2-java6/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index 6c317896dce6..71bda144d977 100644 --- a/samples/client/petstore/java/jersey2-java6/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/jersey2-java6/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -27,7 +27,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") private Map mapProperty = new HashMap(); @@ -97,12 +97,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return ObjectUtils.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - ObjectUtils.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + ObjectUtils.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return ObjectUtils.hashCodeMulti(mapProperty, mapOfMapProperty); + return ObjectUtils.hashCodeMulti(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -110,6 +111,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index cad894e240ab..d1863592679c 100644 --- a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -28,7 +28,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") private Map mapProperty = new HashMap<>(); @@ -98,12 +98,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -111,6 +112,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/jersey2/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/jersey2/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index 7a3b327765d8..2abf26475949 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/jersey2/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -28,7 +28,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") private Map mapProperty = new HashMap(); @@ -98,12 +98,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -111,6 +112,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index 271952639cae..fcda7514309d 100644 --- a/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -33,7 +33,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass implements Parcelable { +public class AdditionalPropertiesClass extends HashMap implements Parcelable { public static final String SERIALIZED_NAME_MAP_PROPERTY = "map_property"; @SerializedName(SERIALIZED_NAME_MAP_PROPERTY) private Map mapProperty = new HashMap(); @@ -43,6 +43,7 @@ public class AdditionalPropertiesClass implements Parcelable { private Map> mapOfMapProperty = new HashMap>(); public AdditionalPropertiesClass() { + super(); } public AdditionalPropertiesClass mapProperty(Map mapProperty) { this.mapProperty = mapProperty; @@ -107,12 +108,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -120,6 +122,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); @@ -139,11 +142,13 @@ private String toIndentedString(java.lang.Object o) { public void writeToParcel(Parcel out, int flags) { + super.writeToParcel(out, flags); out.writeValue(mapProperty); out.writeValue(mapOfMapProperty); } AdditionalPropertiesClass(Parcel in) { + super(in); mapProperty = (Map)in.readValue(null); mapOfMapProperty = (Map>)in.readValue(Map.class.getClassLoader()); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index 9b0a89359933..0d0f5643fad2 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -31,7 +31,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { public static final String SERIALIZED_NAME_MAP_PROPERTY = "map_property"; @SerializedName(SERIALIZED_NAME_MAP_PROPERTY) private Map mapProperty = new HashMap(); @@ -103,12 +103,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -116,6 +117,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/rest-assured/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/rest-assured/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index 9b0a89359933..0d0f5643fad2 100644 --- a/samples/client/petstore/java/rest-assured/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/rest-assured/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -31,7 +31,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { public static final String SERIALIZED_NAME_MAP_PROPERTY = "map_property"; @SerializedName(SERIALIZED_NAME_MAP_PROPERTY) private Map mapProperty = new HashMap(); @@ -103,12 +103,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -116,6 +117,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/resteasy/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/resteasy/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index 7a3b327765d8..2abf26475949 100644 --- a/samples/client/petstore/java/resteasy/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/resteasy/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -28,7 +28,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") private Map mapProperty = new HashMap(); @@ -98,12 +98,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -111,6 +112,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index ce4f409b6205..9d4188f2de10 100644 --- a/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/resttemplate-withXml/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -33,7 +33,7 @@ @XmlRootElement(name = "AdditionalPropertiesClass") @XmlAccessorType(XmlAccessType.FIELD) @JacksonXmlRootElement(localName = "AdditionalPropertiesClass") -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") // Is a container wrapped=false // items.name=inner items.baseName=inner items.xmlName= items.xmlNamespace= @@ -111,12 +111,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -124,6 +125,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index 7a3b327765d8..2abf26475949 100644 --- a/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/resttemplate/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -28,7 +28,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") private Map mapProperty = new HashMap(); @@ -98,12 +98,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -111,6 +112,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/retrofit/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/retrofit/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index 9b0a89359933..0d0f5643fad2 100644 --- a/samples/client/petstore/java/retrofit/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/retrofit/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -31,7 +31,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { public static final String SERIALIZED_NAME_MAP_PROPERTY = "map_property"; @SerializedName(SERIALIZED_NAME_MAP_PROPERTY) private Map mapProperty = new HashMap(); @@ -103,12 +103,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -116,6 +117,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/retrofit2-play24/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/retrofit2-play24/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index efca429ba4cb..7ee9f4b49a8f 100644 --- a/samples/client/petstore/java/retrofit2-play24/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/retrofit2-play24/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -30,7 +30,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") private Map mapProperty = new HashMap<>(); @@ -101,12 +101,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -114,6 +115,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/retrofit2-play25/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/retrofit2-play25/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index efca429ba4cb..7ee9f4b49a8f 100644 --- a/samples/client/petstore/java/retrofit2-play25/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/retrofit2-play25/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -30,7 +30,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") private Map mapProperty = new HashMap<>(); @@ -101,12 +101,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -114,6 +115,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/retrofit2-play26/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/retrofit2-play26/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index efca429ba4cb..7ee9f4b49a8f 100644 --- a/samples/client/petstore/java/retrofit2-play26/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/retrofit2-play26/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -30,7 +30,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") private Map mapProperty = new HashMap<>(); @@ -101,12 +101,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -114,6 +115,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/retrofit2/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/retrofit2/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index 9b0a89359933..0d0f5643fad2 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -31,7 +31,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { public static final String SERIALIZED_NAME_MAP_PROPERTY = "map_property"; @SerializedName(SERIALIZED_NAME_MAP_PROPERTY) private Map mapProperty = new HashMap(); @@ -103,12 +103,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -116,6 +117,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/retrofit2rx/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/retrofit2rx/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index 9b0a89359933..0d0f5643fad2 100644 --- a/samples/client/petstore/java/retrofit2rx/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/retrofit2rx/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -31,7 +31,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { public static final String SERIALIZED_NAME_MAP_PROPERTY = "map_property"; @SerializedName(SERIALIZED_NAME_MAP_PROPERTY) private Map mapProperty = new HashMap(); @@ -103,12 +103,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -116,6 +117,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/retrofit2rx2/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/retrofit2rx2/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index 9b0a89359933..0d0f5643fad2 100644 --- a/samples/client/petstore/java/retrofit2rx2/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/retrofit2rx2/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -31,7 +31,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { public static final String SERIALIZED_NAME_MAP_PROPERTY = "map_property"; @SerializedName(SERIALIZED_NAME_MAP_PROPERTY) private Map mapProperty = new HashMap(); @@ -103,12 +103,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -116,6 +117,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/vertx/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/vertx/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index cad894e240ab..d1863592679c 100644 --- a/samples/client/petstore/java/vertx/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/vertx/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -28,7 +28,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") private Map mapProperty = new HashMap<>(); @@ -98,12 +98,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -111,6 +112,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java b/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java index cad894e240ab..d1863592679c 100644 --- a/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java +++ b/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/model/AdditionalPropertiesClass.java @@ -28,7 +28,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") private Map mapProperty = new HashMap<>(); @@ -98,12 +98,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -111,6 +112,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Model/AdditionalPropertiesClass.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/AdditionalPropertiesClass.php index 8d996a0fdb3d..835679c323e4 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Model/AdditionalPropertiesClass.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Model/AdditionalPropertiesClass.php @@ -193,7 +193,7 @@ public function __construct(array $data = null) */ public function listInvalidProperties() { - $invalidProperties = []; + $invalidProperties = parent::listInvalidProperties(); return $invalidProperties; } diff --git a/samples/client/petstore/python-asyncio/README.md b/samples/client/petstore/python-asyncio/README.md index 4c67e17b44c8..ce1fcee98043 100644 --- a/samples/client/petstore/python-asyncio/README.md +++ b/samples/client/petstore/python-asyncio/README.md @@ -111,7 +111,14 @@ Class | Method | HTTP request | Description ## Documentation For Models + - [AdditionalPropertiesAnyType](docs/AdditionalPropertiesAnyType.md) + - [AdditionalPropertiesArray](docs/AdditionalPropertiesArray.md) + - [AdditionalPropertiesBoolean](docs/AdditionalPropertiesBoolean.md) - [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md) + - [AdditionalPropertiesInteger](docs/AdditionalPropertiesInteger.md) + - [AdditionalPropertiesNumber](docs/AdditionalPropertiesNumber.md) + - [AdditionalPropertiesObject](docs/AdditionalPropertiesObject.md) + - [AdditionalPropertiesString](docs/AdditionalPropertiesString.md) - [Animal](docs/Animal.md) - [ApiResponse](docs/ApiResponse.md) - [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md) diff --git a/samples/client/petstore/python-asyncio/docs/AdditionalPropertiesAnyType.md b/samples/client/petstore/python-asyncio/docs/AdditionalPropertiesAnyType.md new file mode 100644 index 000000000000..9843d35ab906 --- /dev/null +++ b/samples/client/petstore/python-asyncio/docs/AdditionalPropertiesAnyType.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesAnyType + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/AdditionalPropertiesArray.md b/samples/client/petstore/python-asyncio/docs/AdditionalPropertiesArray.md new file mode 100644 index 000000000000..cfe09d91c726 --- /dev/null +++ b/samples/client/petstore/python-asyncio/docs/AdditionalPropertiesArray.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesArray + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/AdditionalPropertiesBoolean.md b/samples/client/petstore/python-asyncio/docs/AdditionalPropertiesBoolean.md new file mode 100644 index 000000000000..74f009554a7f --- /dev/null +++ b/samples/client/petstore/python-asyncio/docs/AdditionalPropertiesBoolean.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesBoolean + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/AdditionalPropertiesClass.md b/samples/client/petstore/python-asyncio/docs/AdditionalPropertiesClass.md index 796a789d4c4b..56326055a412 100644 --- a/samples/client/petstore/python-asyncio/docs/AdditionalPropertiesClass.md +++ b/samples/client/petstore/python-asyncio/docs/AdditionalPropertiesClass.md @@ -3,8 +3,17 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**map_property** | **dict(str, str)** | | [optional] -**map_of_map_property** | **dict(str, dict(str, str))** | | [optional] +**map_string** | **{str: (str,)}** | | [optional] +**map_number** | **{str: (float,)}** | | [optional] +**map_integer** | **{str: (int,)}** | | [optional] +**map_boolean** | **{str: (bool,)}** | | [optional] +**map_array_integer** | **{str: ([(int,)],)}** | | [optional] +**map_array_anytype** | **{str: ([(bool, date, datetime, dict, float, int, list, str)],)}** | | [optional] +**map_map_string** | **{str: ({str: (str,)},)}** | | [optional] +**map_map_anytype** | **{str: ({str: (bool, date, datetime, dict, float, int, list, str)},)}** | | [optional] +**anytype_1** | [**bool, date, datetime, dict, float, int, list, str**](.md) | | [optional] +**anytype_2** | [**bool, date, datetime, dict, float, int, list, str**](.md) | | [optional] +**anytype_3** | [**bool, date, datetime, dict, float, int, list, str**](.md) | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-asyncio/docs/AdditionalPropertiesInteger.md b/samples/client/petstore/python-asyncio/docs/AdditionalPropertiesInteger.md new file mode 100644 index 000000000000..a3e58fd1b0bd --- /dev/null +++ b/samples/client/petstore/python-asyncio/docs/AdditionalPropertiesInteger.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesInteger + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/AdditionalPropertiesNumber.md b/samples/client/petstore/python-asyncio/docs/AdditionalPropertiesNumber.md new file mode 100644 index 000000000000..37eafe1ff031 --- /dev/null +++ b/samples/client/petstore/python-asyncio/docs/AdditionalPropertiesNumber.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesNumber + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/AdditionalPropertiesObject.md b/samples/client/petstore/python-asyncio/docs/AdditionalPropertiesObject.md new file mode 100644 index 000000000000..7f4d6713c758 --- /dev/null +++ b/samples/client/petstore/python-asyncio/docs/AdditionalPropertiesObject.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesObject + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/AdditionalPropertiesString.md b/samples/client/petstore/python-asyncio/docs/AdditionalPropertiesString.md new file mode 100644 index 000000000000..9317cfeee80b --- /dev/null +++ b/samples/client/petstore/python-asyncio/docs/AdditionalPropertiesString.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesString + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/ArrayOfArrayOfNumberOnly.md b/samples/client/petstore/python-asyncio/docs/ArrayOfArrayOfNumberOnly.md index aa3988ab1679..323b6edc56b9 100644 --- a/samples/client/petstore/python-asyncio/docs/ArrayOfArrayOfNumberOnly.md +++ b/samples/client/petstore/python-asyncio/docs/ArrayOfArrayOfNumberOnly.md @@ -3,7 +3,7 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**array_array_number** | **list[list[float]]** | | [optional] +**array_array_number** | **[([(float,)],)]** | | [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/ArrayOfNumberOnly.md b/samples/client/petstore/python-asyncio/docs/ArrayOfNumberOnly.md index 2c3de967aec6..502d335fcfc3 100644 --- a/samples/client/petstore/python-asyncio/docs/ArrayOfNumberOnly.md +++ b/samples/client/petstore/python-asyncio/docs/ArrayOfNumberOnly.md @@ -3,7 +3,7 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**array_number** | **list[float]** | | [optional] +**array_number** | **[(float,)]** | | [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/ArrayTest.md b/samples/client/petstore/python-asyncio/docs/ArrayTest.md index 6ab0d1378065..d3a915da27c1 100644 --- a/samples/client/petstore/python-asyncio/docs/ArrayTest.md +++ b/samples/client/petstore/python-asyncio/docs/ArrayTest.md @@ -3,9 +3,9 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**array_of_string** | **list[str]** | | [optional] -**array_array_of_integer** | **list[list[int]]** | | [optional] -**array_array_of_model** | **list[list[ReadOnlyFirst]]** | | [optional] +**array_of_string** | **[(str,)]** | | [optional] +**array_array_of_integer** | **[([(int,)],)]** | | [optional] +**array_array_of_model** | **[([(ReadOnlyFirst,)],)]** | | [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/Cat.md b/samples/client/petstore/python-asyncio/docs/Cat.md index 8d30565d014e..d052c5615b84 100644 --- a/samples/client/petstore/python-asyncio/docs/Cat.md +++ b/samples/client/petstore/python-asyncio/docs/Cat.md @@ -3,6 +3,8 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**class_name** | **str** | | +**color** | **str** | | [optional] [default to 'red'] **declawed** | **bool** | | [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/Dog.md b/samples/client/petstore/python-asyncio/docs/Dog.md index f727487975c4..ac70f17e668a 100644 --- a/samples/client/petstore/python-asyncio/docs/Dog.md +++ b/samples/client/petstore/python-asyncio/docs/Dog.md @@ -3,6 +3,8 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**class_name** | **str** | | +**color** | **str** | | [optional] [default to 'red'] **breed** | **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/EnumArrays.md b/samples/client/petstore/python-asyncio/docs/EnumArrays.md index e15a5f1fd049..4a87d6a62ea2 100644 --- a/samples/client/petstore/python-asyncio/docs/EnumArrays.md +++ b/samples/client/petstore/python-asyncio/docs/EnumArrays.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **just_symbol** | **str** | | [optional] -**array_enum** | **list[str]** | | [optional] +**array_enum** | **[(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/FakeApi.md b/samples/client/petstore/python-asyncio/docs/FakeApi.md index c46bf1e49748..2a72ffe650da 100644 --- a/samples/client/petstore/python-asyncio/docs/FakeApi.md +++ b/samples/client/petstore/python-asyncio/docs/FakeApi.md @@ -434,7 +434,7 @@ int32 = 56 # int | None (optional) int64 = 56 # int | None (optional) float = 3.4 # float | None (optional) string = 'string_example' # str | None (optional) -binary = '/path/to/file' # file | None (optional) +binary = '/path/to/file' # file_type | None (optional) date = '2013-10-20' # date | None (optional) date_time = '2013-10-20T19:20:30+01:00' # datetime | None (optional) password = 'password_example' # str | None (optional) @@ -460,7 +460,7 @@ Name | Type | Description | Notes **int64** | **int**| None | [optional] **float** | **float**| None | [optional] **string** | **str**| None | [optional] - **binary** | **file**| None | [optional] + **binary** | **file_type**| None | [optional] **date** | **date**| None | [optional] **date_time** | **datetime**| None | [optional] **password** | **str**| None | [optional] @@ -499,13 +499,13 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.FakeApi() -enum_header_string_array = ['enum_header_string_array_example'] # list[str] | Header parameter enum test (string array) (optional) +enum_header_string_array = ['enum_header_string_array_example'] # [(str,)] | Header parameter enum test (string array) (optional) enum_header_string = '-efg' # str | Header parameter enum test (string) (optional) (default to '-efg') -enum_query_string_array = ['enum_query_string_array_example'] # list[str] | Query parameter enum test (string array) (optional) +enum_query_string_array = ['enum_query_string_array_example'] # [(str,)] | Query parameter enum test (string array) (optional) enum_query_string = '-efg' # str | Query parameter enum test (string) (optional) (default to '-efg') enum_query_integer = 56 # int | Query parameter enum test (double) (optional) enum_query_double = 3.4 # float | Query parameter enum test (double) (optional) -enum_form_string_array = '$' # list[str] | Form parameter enum test (string array) (optional) (default to '$') +enum_form_string_array = '$' # [(str,)] | Form parameter enum test (string array) (optional) (default to '$') enum_form_string = '-efg' # str | Form parameter enum test (string) (optional) (default to '-efg') try: @@ -519,13 +519,13 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **enum_header_string_array** | [**list[str]**](str.md)| Header parameter enum test (string array) | [optional] + **enum_header_string_array** | [**[(str,)]**](str.md)| Header parameter enum test (string array) | [optional] **enum_header_string** | **str**| Header parameter enum test (string) | [optional] [default to '-efg'] - **enum_query_string_array** | [**list[str]**](str.md)| Query parameter enum test (string array) | [optional] + **enum_query_string_array** | [**[(str,)]**](str.md)| Query parameter enum test (string array) | [optional] **enum_query_string** | **str**| Query parameter enum test (string) | [optional] [default to '-efg'] **enum_query_integer** | **int**| Query parameter enum test (double) | [optional] **enum_query_double** | **float**| Query parameter enum test (double) | [optional] - **enum_form_string_array** | [**list[str]**](str.md)| Form parameter enum test (string array) | [optional] [default to '$'] + **enum_form_string_array** | [**[(str,)]**](str.md)| Form parameter enum test (string array) | [optional] [default to '$'] **enum_form_string** | **str**| Form parameter enum test (string) | [optional] [default to '-efg'] ### Return type @@ -617,7 +617,7 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.FakeApi() -param = {'key': 'param_example'} # dict(str, str) | request body +param = {'key': 'param_example'} # {str: (str,)} | request body try: # test inline additionalProperties @@ -630,7 +630,7 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **param** | [**dict(str, str)**](str.md)| request body | + **param** | [**{str: (str,)}**](str.md)| request body | ### Return type diff --git a/samples/client/petstore/python-asyncio/docs/FileSchemaTestClass.md b/samples/client/petstore/python-asyncio/docs/FileSchemaTestClass.md index dc3722289887..73009bdb1bfb 100644 --- a/samples/client/petstore/python-asyncio/docs/FileSchemaTestClass.md +++ b/samples/client/petstore/python-asyncio/docs/FileSchemaTestClass.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **file** | [**File**](File.md) | | [optional] -**files** | [**list[File]**](File.md) | | [optional] +**files** | [**[(File,)]**](File.md) | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-asyncio/docs/FormatTest.md b/samples/client/petstore/python-asyncio/docs/FormatTest.md index 31d92e2a750e..5431d4e7169b 100644 --- a/samples/client/petstore/python-asyncio/docs/FormatTest.md +++ b/samples/client/petstore/python-asyncio/docs/FormatTest.md @@ -11,7 +11,7 @@ Name | Type | Description | Notes **double** | **float** | | [optional] **string** | **str** | | [optional] **byte** | **str** | | -**binary** | **file** | | [optional] +**binary** | **file_type** | | [optional] **date** | **date** | | **date_time** | **datetime** | | [optional] **uuid** | **str** | | [optional] diff --git a/samples/client/petstore/python-asyncio/docs/MapTest.md b/samples/client/petstore/python-asyncio/docs/MapTest.md index a5601691f885..c88c578cf82e 100644 --- a/samples/client/petstore/python-asyncio/docs/MapTest.md +++ b/samples/client/petstore/python-asyncio/docs/MapTest.md @@ -3,10 +3,10 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**map_map_of_string** | **dict(str, dict(str, str))** | | [optional] -**map_of_enum_string** | **dict(str, str)** | | [optional] -**direct_map** | **dict(str, bool)** | | [optional] -**indirect_map** | **dict(str, bool)** | | [optional] +**map_map_of_string** | **{str: ({str: (str,)},)}** | | [optional] +**map_of_enum_string** | **{str: (str,)}** | | [optional] +**direct_map** | **{str: (bool,)}** | | [optional] +**indirect_map** | **{str: (bool,)}** | | [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/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/client/petstore/python-asyncio/docs/MixedPropertiesAndAdditionalPropertiesClass.md index b9808d5275e5..1484c0638d83 100644 --- a/samples/client/petstore/python-asyncio/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/client/petstore/python-asyncio/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -5,7 +5,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **uuid** | **str** | | [optional] **date_time** | **datetime** | | [optional] -**map** | [**dict(str, Animal)**](Animal.md) | | [optional] +**map** | [**{str: (Animal,)}**](Animal.md) | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-asyncio/docs/Pet.md b/samples/client/petstore/python-asyncio/docs/Pet.md index 9e15090300f8..745d5da843e7 100644 --- a/samples/client/petstore/python-asyncio/docs/Pet.md +++ b/samples/client/petstore/python-asyncio/docs/Pet.md @@ -6,8 +6,8 @@ Name | Type | Description | Notes **id** | **int** | | [optional] **category** | [**Category**](Category.md) | | [optional] **name** | **str** | | -**photo_urls** | **list[str]** | | -**tags** | [**list[Tag]**](Tag.md) | | [optional] +**photo_urls** | **[(str,)]** | | +**tags** | [**[(Tag,)]**](Tag.md) | | [optional] **status** | **str** | pet status in the store | [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/PetApi.md b/samples/client/petstore/python-asyncio/docs/PetApi.md index 227fa2ada134..07d1016f42bb 100644 --- a/samples/client/petstore/python-asyncio/docs/PetApi.md +++ b/samples/client/petstore/python-asyncio/docs/PetApi.md @@ -118,7 +118,7 @@ void (empty response body) [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **find_pets_by_status** -> list[Pet] find_pets_by_status(status) +> [(Pet,)] find_pets_by_status(status) Finds Pets by status @@ -139,7 +139,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN' # create an instance of the API class api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration)) -status = ['status_example'] # list[str] | Status values that need to be considered for filter +status = ['status_example'] # [(str,)] | Status values that need to be considered for filter try: # Finds Pets by status @@ -153,11 +153,11 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **status** | [**list[str]**](str.md)| Status values that need to be considered for filter | + **status** | [**[(str,)]**](str.md)| Status values that need to be considered for filter | ### Return type -[**list[Pet]**](Pet.md) +[**[(Pet,)]**](Pet.md) ### Authorization @@ -171,7 +171,7 @@ Name | Type | Description | Notes [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **find_pets_by_tags** -> list[Pet] find_pets_by_tags(tags) +> [(Pet,)] find_pets_by_tags(tags) Finds Pets by tags @@ -192,7 +192,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN' # create an instance of the API class api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration)) -tags = ['tags_example'] # list[str] | Tags to filter by +tags = ['tags_example'] # [(str,)] | Tags to filter by try: # Finds Pets by tags @@ -206,11 +206,11 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **tags** | [**list[str]**](str.md)| Tags to filter by | + **tags** | [**[(str,)]**](str.md)| Tags to filter by | ### Return type -[**list[Pet]**](Pet.md) +[**[(Pet,)]**](Pet.md) ### Authorization @@ -404,7 +404,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN' api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration)) pet_id = 56 # int | ID of pet to update additional_metadata = 'additional_metadata_example' # str | Additional data to pass to server (optional) -file = '/path/to/file' # file | file to upload (optional) +file = '/path/to/file' # file_type | file to upload (optional) try: # uploads an image @@ -420,7 +420,7 @@ Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **pet_id** | **int**| ID of pet to update | **additional_metadata** | **str**| Additional data to pass to server | [optional] - **file** | **file**| file to upload | [optional] + **file** | **file_type**| file to upload | [optional] ### Return type @@ -458,7 +458,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN' # create an instance of the API class api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration)) pet_id = 56 # int | ID of pet to update -required_file = '/path/to/file' # file | file to upload +required_file = '/path/to/file' # file_type | file to upload additional_metadata = 'additional_metadata_example' # str | Additional data to pass to server (optional) try: @@ -474,7 +474,7 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **pet_id** | **int**| ID of pet to update | - **required_file** | **file**| file to upload | + **required_file** | **file_type**| file to upload | **additional_metadata** | **str**| Additional data to pass to server | [optional] ### Return type diff --git a/samples/client/petstore/python-asyncio/docs/StoreApi.md b/samples/client/petstore/python-asyncio/docs/StoreApi.md index af190f931d2e..ce0ef54222f1 100644 --- a/samples/client/petstore/python-asyncio/docs/StoreApi.md +++ b/samples/client/petstore/python-asyncio/docs/StoreApi.md @@ -59,7 +59,7 @@ No authorization required [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **get_inventory** -> dict(str, int) get_inventory() +> {str: (int,)} get_inventory() Returns pet inventories by status @@ -96,7 +96,7 @@ This endpoint does not need any parameter. ### Return type -**dict(str, int)** +**{str: (int,)}** ### Authorization diff --git a/samples/client/petstore/python-asyncio/docs/TypeHolderDefault.md b/samples/client/petstore/python-asyncio/docs/TypeHolderDefault.md index 861da021826a..3a6ba43b37c7 100644 --- a/samples/client/petstore/python-asyncio/docs/TypeHolderDefault.md +++ b/samples/client/petstore/python-asyncio/docs/TypeHolderDefault.md @@ -7,7 +7,7 @@ Name | Type | Description | Notes **number_item** | **float** | | **integer_item** | **int** | | **bool_item** | **bool** | | [default to True] -**array_item** | **list[int]** | | +**array_item** | **[(int,)]** | | [[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/TypeHolderExample.md b/samples/client/petstore/python-asyncio/docs/TypeHolderExample.md index d59718cdcb16..0daefd05c50e 100644 --- a/samples/client/petstore/python-asyncio/docs/TypeHolderExample.md +++ b/samples/client/petstore/python-asyncio/docs/TypeHolderExample.md @@ -7,7 +7,7 @@ Name | Type | Description | Notes **number_item** | **float** | | **integer_item** | **int** | | **bool_item** | **bool** | | -**array_item** | **list[int]** | | +**array_item** | **[(int,)]** | | [[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/UserApi.md b/samples/client/petstore/python-asyncio/docs/UserApi.md index 33e86f9e8fd2..2e27cf02301d 100644 --- a/samples/client/petstore/python-asyncio/docs/UserApi.md +++ b/samples/client/petstore/python-asyncio/docs/UserApi.md @@ -78,7 +78,7 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.UserApi() -body = NULL # list[User] | List of user object +body = NULL # [(User,)] | List of user object try: # Creates list of users with given input array @@ -91,7 +91,7 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **body** | [**list[User]**](list.md)| List of user object | + **body** | [**[(User,)]**](list.md)| List of user object | ### Return type @@ -124,7 +124,7 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.UserApi() -body = NULL # list[User] | List of user object +body = NULL # [(User,)] | List of user object try: # Creates list of users with given input array @@ -137,7 +137,7 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **body** | [**list[User]**](list.md)| List of user object | + **body** | [**[(User,)]**](list.md)| List of user object | ### Return type diff --git a/samples/client/petstore/python-asyncio/docs/XmlItem.md b/samples/client/petstore/python-asyncio/docs/XmlItem.md index 3dd09833fe52..185da1eb0119 100644 --- a/samples/client/petstore/python-asyncio/docs/XmlItem.md +++ b/samples/client/petstore/python-asyncio/docs/XmlItem.md @@ -7,31 +7,31 @@ Name | Type | Description | Notes **attribute_number** | **float** | | [optional] **attribute_integer** | **int** | | [optional] **attribute_boolean** | **bool** | | [optional] -**wrapped_array** | **list[int]** | | [optional] +**wrapped_array** | **[(int,)]** | | [optional] **name_string** | **str** | | [optional] **name_number** | **float** | | [optional] **name_integer** | **int** | | [optional] **name_boolean** | **bool** | | [optional] -**name_array** | **list[int]** | | [optional] -**name_wrapped_array** | **list[int]** | | [optional] +**name_array** | **[(int,)]** | | [optional] +**name_wrapped_array** | **[(int,)]** | | [optional] **prefix_string** | **str** | | [optional] **prefix_number** | **float** | | [optional] **prefix_integer** | **int** | | [optional] **prefix_boolean** | **bool** | | [optional] -**prefix_array** | **list[int]** | | [optional] -**prefix_wrapped_array** | **list[int]** | | [optional] +**prefix_array** | **[(int,)]** | | [optional] +**prefix_wrapped_array** | **[(int,)]** | | [optional] **namespace_string** | **str** | | [optional] **namespace_number** | **float** | | [optional] **namespace_integer** | **int** | | [optional] **namespace_boolean** | **bool** | | [optional] -**namespace_array** | **list[int]** | | [optional] -**namespace_wrapped_array** | **list[int]** | | [optional] +**namespace_array** | **[(int,)]** | | [optional] +**namespace_wrapped_array** | **[(int,)]** | | [optional] **prefix_ns_string** | **str** | | [optional] **prefix_ns_number** | **float** | | [optional] **prefix_ns_integer** | **int** | | [optional] **prefix_ns_boolean** | **bool** | | [optional] -**prefix_ns_array** | **list[int]** | | [optional] -**prefix_ns_wrapped_array** | **list[int]** | | [optional] +**prefix_ns_array** | **[(int,)]** | | [optional] +**prefix_ns_wrapped_array** | **[(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/__init__.py b/samples/client/petstore/python-asyncio/petstore_api/__init__.py index cf9b1b0db3f9..516f759d02c3 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/__init__.py +++ b/samples/client/petstore/python-asyncio/petstore_api/__init__.py @@ -28,7 +28,14 @@ from petstore_api.api_client import ApiClient from petstore_api.configuration import Configuration # import models into sdk package +from petstore_api.models.additional_properties_any_type import AdditionalPropertiesAnyType +from petstore_api.models.additional_properties_array import AdditionalPropertiesArray +from petstore_api.models.additional_properties_boolean import AdditionalPropertiesBoolean from petstore_api.models.additional_properties_class import AdditionalPropertiesClass +from petstore_api.models.additional_properties_integer import AdditionalPropertiesInteger +from petstore_api.models.additional_properties_number import AdditionalPropertiesNumber +from petstore_api.models.additional_properties_object import AdditionalPropertiesObject +from petstore_api.models.additional_properties_string import AdditionalPropertiesString from petstore_api.models.animal import Animal from petstore_api.models.api_response import ApiResponse from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly diff --git a/samples/client/petstore/python-asyncio/petstore_api/api/another_fake_api.py b/samples/client/petstore/python-asyncio/petstore_api/api/another_fake_api.py index 9fd3f816b9ca..058210d0bd4d 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/api/another_fake_api.py +++ b/samples/client/petstore/python-asyncio/petstore_api/api/another_fake_api.py @@ -18,6 +18,20 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.client import Client class AnotherFakeApi(object): @@ -32,7 +46,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def call_123_test_special_tags(self, body, **kwargs): # noqa: E501 + def call_123_test_special_tags(self, body, _check_type=False, **kwargs): # noqa: E501 """To test special tags # noqa: E501 To test special tags and operation ID starting with number # noqa: E501 @@ -49,12 +63,12 @@ def call_123_test_special_tags(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.call_123_test_special_tags_with_http_info(body, **kwargs) # noqa: E501 + return self.call_123_test_special_tags_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.call_123_test_special_tags_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.call_123_test_special_tags_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E501 + def call_123_test_special_tags_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """To test special tags # noqa: E501 To test special tags and operation ID starting with number # noqa: E501 @@ -80,16 +94,26 @@ def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E5 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method call_123_test_special_tags" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [Client], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `call_123_test_special_tags`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `call_123_test_special_tags`") # noqa: E501 collection_formats = {} @@ -124,7 +148,7 @@ def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E5 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types_mixed=[Client], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-asyncio/petstore_api/api/fake_api.py b/samples/client/petstore/python-asyncio/petstore_api/api/fake_api.py index c7405e51c381..9c4355a95c35 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/api/fake_api.py +++ b/samples/client/petstore/python-asyncio/petstore_api/api/fake_api.py @@ -18,6 +18,24 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.client import Client +from petstore_api.models.file_schema_test_class import FileSchemaTestClass +from petstore_api.models.outer_composite import OuterComposite +from petstore_api.models.user import User +from petstore_api.models.xml_item import XmlItem class FakeApi(object): @@ -32,7 +50,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def create_xml_item(self, xml_item, **kwargs): # noqa: E501 + def create_xml_item(self, xml_item, _check_type=False, **kwargs): # noqa: E501 """creates an XmlItem # noqa: E501 this route creates an XmlItem # noqa: E501 @@ -49,12 +67,12 @@ def create_xml_item(self, xml_item, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.create_xml_item_with_http_info(xml_item, **kwargs) # noqa: E501 + return self.create_xml_item_with_http_info(xml_item, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.create_xml_item_with_http_info(xml_item, **kwargs) # noqa: E501 + (data) = self.create_xml_item_with_http_info(xml_item, _check_type=_check_type, **kwargs) # noqa: E501 return data - def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501 + def create_xml_item_with_http_info(self, xml_item, _check_type=False, **kwargs): # noqa: E501 """creates an XmlItem # noqa: E501 this route creates an XmlItem # noqa: E501 @@ -80,16 +98,26 @@ def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method create_xml_item" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'xml_item': [XmlItem], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'xml_item' is set if ('xml_item' not in local_var_params or local_var_params['xml_item'] is None): - raise ValueError("Missing the required parameter `xml_item` when calling `create_xml_item`") # noqa: E501 + raise ApiValueError("Missing the required parameter `xml_item` when calling `create_xml_item`") # noqa: E501 collection_formats = {} @@ -120,7 +148,7 @@ def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -128,7 +156,7 @@ def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def fake_outer_boolean_serialize(self, **kwargs): # noqa: E501 + def fake_outer_boolean_serialize(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_boolean_serialize # noqa: E501 Test serialization of outer boolean types # noqa: E501 @@ -145,12 +173,12 @@ def fake_outer_boolean_serialize(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.fake_outer_boolean_serialize_with_http_info(**kwargs) # noqa: E501 + return self.fake_outer_boolean_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.fake_outer_boolean_serialize_with_http_info(**kwargs) # noqa: E501 + (data) = self.fake_outer_boolean_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 + def fake_outer_boolean_serialize_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_boolean_serialize # noqa: E501 Test serialization of outer boolean types # noqa: E501 @@ -176,12 +204,22 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method fake_outer_boolean_serialize" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [bool], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) collection_formats = {} @@ -212,7 +250,7 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='bool', # noqa: E501 + response_types_mixed=[bool], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -220,7 +258,7 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def fake_outer_composite_serialize(self, **kwargs): # noqa: E501 + def fake_outer_composite_serialize(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_composite_serialize # noqa: E501 Test serialization of object with outer number type # noqa: E501 @@ -237,12 +275,12 @@ def fake_outer_composite_serialize(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.fake_outer_composite_serialize_with_http_info(**kwargs) # noqa: E501 + return self.fake_outer_composite_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.fake_outer_composite_serialize_with_http_info(**kwargs) # noqa: E501 + (data) = self.fake_outer_composite_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 + def fake_outer_composite_serialize_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_composite_serialize # noqa: E501 Test serialization of object with outer number type # noqa: E501 @@ -268,12 +306,22 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method fake_outer_composite_serialize" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [OuterComposite], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) collection_formats = {} @@ -304,7 +352,7 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='OuterComposite', # noqa: E501 + response_types_mixed=[OuterComposite], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -312,7 +360,7 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def fake_outer_number_serialize(self, **kwargs): # noqa: E501 + def fake_outer_number_serialize(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_number_serialize # noqa: E501 Test serialization of outer number types # noqa: E501 @@ -329,12 +377,12 @@ def fake_outer_number_serialize(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.fake_outer_number_serialize_with_http_info(**kwargs) # noqa: E501 + return self.fake_outer_number_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.fake_outer_number_serialize_with_http_info(**kwargs) # noqa: E501 + (data) = self.fake_outer_number_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 + def fake_outer_number_serialize_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_number_serialize # noqa: E501 Test serialization of outer number types # noqa: E501 @@ -360,12 +408,22 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method fake_outer_number_serialize" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [float], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) collection_formats = {} @@ -396,7 +454,7 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='float', # noqa: E501 + response_types_mixed=[float], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -404,7 +462,7 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def fake_outer_string_serialize(self, **kwargs): # noqa: E501 + def fake_outer_string_serialize(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_string_serialize # noqa: E501 Test serialization of outer string types # noqa: E501 @@ -421,12 +479,12 @@ def fake_outer_string_serialize(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.fake_outer_string_serialize_with_http_info(**kwargs) # noqa: E501 + return self.fake_outer_string_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.fake_outer_string_serialize_with_http_info(**kwargs) # noqa: E501 + (data) = self.fake_outer_string_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 + def fake_outer_string_serialize_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_string_serialize # noqa: E501 Test serialization of outer string types # noqa: E501 @@ -452,12 +510,22 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method fake_outer_string_serialize" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) collection_formats = {} @@ -488,7 +556,7 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='str', # noqa: E501 + response_types_mixed=[str], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -496,7 +564,7 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_body_with_file_schema(self, body, **kwargs): # noqa: E501 + def test_body_with_file_schema(self, body, _check_type=False, **kwargs): # noqa: E501 """test_body_with_file_schema # noqa: E501 For this test, the body for this request much reference a schema named `File`. # noqa: E501 @@ -513,12 +581,12 @@ def test_body_with_file_schema(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_body_with_file_schema_with_http_info(body, **kwargs) # noqa: E501 + return self.test_body_with_file_schema_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_body_with_file_schema_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.test_body_with_file_schema_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E501 + def test_body_with_file_schema_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """test_body_with_file_schema # noqa: E501 For this test, the body for this request much reference a schema named `File`. # noqa: E501 @@ -544,16 +612,26 @@ def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E5 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_body_with_file_schema" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [FileSchemaTestClass], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `test_body_with_file_schema`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `test_body_with_file_schema`") # noqa: E501 collection_formats = {} @@ -584,7 +662,7 @@ def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E5 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -592,7 +670,7 @@ def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E5 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_body_with_query_params(self, query, body, **kwargs): # noqa: E501 + def test_body_with_query_params(self, query, body, _check_type=False, **kwargs): # noqa: E501 """test_body_with_query_params # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -609,12 +687,12 @@ def test_body_with_query_params(self, query, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_body_with_query_params_with_http_info(query, body, **kwargs) # noqa: E501 + return self.test_body_with_query_params_with_http_info(query, body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_body_with_query_params_with_http_info(query, body, **kwargs) # noqa: E501 + (data) = self.test_body_with_query_params_with_http_info(query, body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_body_with_query_params_with_http_info(self, query, body, **kwargs): # noqa: E501 + def test_body_with_query_params_with_http_info(self, query, body, _check_type=False, **kwargs): # noqa: E501 """test_body_with_query_params # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -640,20 +718,31 @@ def test_body_with_query_params_with_http_info(self, query, body, **kwargs): # for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_body_with_query_params" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'query': [str], + 'body': [User], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'query' is set if ('query' not in local_var_params or local_var_params['query'] is None): - raise ValueError("Missing the required parameter `query` when calling `test_body_with_query_params`") # noqa: E501 + raise ApiValueError("Missing the required parameter `query` when calling `test_body_with_query_params`") # noqa: E501 # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `test_body_with_query_params`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `test_body_with_query_params`") # noqa: E501 collection_formats = {} @@ -686,7 +775,7 @@ def test_body_with_query_params_with_http_info(self, query, body, **kwargs): # body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -694,7 +783,7 @@ def test_body_with_query_params_with_http_info(self, query, body, **kwargs): # _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_client_model(self, body, **kwargs): # noqa: E501 + def test_client_model(self, body, _check_type=False, **kwargs): # noqa: E501 """To test \"client\" model # noqa: E501 To test \"client\" model # noqa: E501 @@ -711,12 +800,12 @@ def test_client_model(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_client_model_with_http_info(body, **kwargs) # noqa: E501 + return self.test_client_model_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_client_model_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.test_client_model_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501 + def test_client_model_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """To test \"client\" model # noqa: E501 To test \"client\" model # noqa: E501 @@ -742,16 +831,26 @@ def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_client_model" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [Client], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `test_client_model`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `test_client_model`") # noqa: E501 collection_formats = {} @@ -786,7 +885,7 @@ def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types_mixed=[Client], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -794,7 +893,7 @@ def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_endpoint_parameters(self, number, double, pattern_without_delimiter, byte, **kwargs): # noqa: E501 + def test_endpoint_parameters(self, number, double, pattern_without_delimiter, byte, _check_type=False, **kwargs): # noqa: E501 """Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 @@ -813,7 +912,7 @@ def test_endpoint_parameters(self, number, double, pattern_without_delimiter, by :param int int64: None :param float float: None :param str string: None - :param file binary: None + :param file_type binary: None :param date date: None :param datetime date_time: None :param str password: None @@ -824,12 +923,12 @@ def test_endpoint_parameters(self, number, double, pattern_without_delimiter, by """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_endpoint_parameters_with_http_info(number, double, pattern_without_delimiter, byte, **kwargs) # noqa: E501 + return self.test_endpoint_parameters_with_http_info(number, double, pattern_without_delimiter, byte, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_endpoint_parameters_with_http_info(number, double, pattern_without_delimiter, byte, **kwargs) # noqa: E501 + (data) = self.test_endpoint_parameters_with_http_info(number, double, pattern_without_delimiter, byte, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_endpoint_parameters_with_http_info(self, number, double, pattern_without_delimiter, byte, **kwargs): # noqa: E501 + def test_endpoint_parameters_with_http_info(self, number, double, pattern_without_delimiter, byte, _check_type=False, **kwargs): # noqa: E501 """Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 @@ -848,7 +947,7 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou :param int int64: None :param float float: None :param str string: None - :param file binary: None + :param file_type binary: None :param date date: None :param datetime date_time: None :param str password: None @@ -868,57 +967,80 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_endpoint_parameters" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'number': [float], + 'double': [float], + 'pattern_without_delimiter': [str], + 'byte': [str], + 'integer': [int], + 'int32': [int], + 'int64': [int], + 'float': [float], + 'string': [str], + 'binary': [file_type], + 'date': [date], + 'date_time': [datetime], + 'password': [str], + 'param_callback': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'number' is set if ('number' not in local_var_params or local_var_params['number'] is None): - raise ValueError("Missing the required parameter `number` when calling `test_endpoint_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `number` when calling `test_endpoint_parameters`") # noqa: E501 # verify the required parameter 'double' is set if ('double' not in local_var_params or local_var_params['double'] is None): - raise ValueError("Missing the required parameter `double` when calling `test_endpoint_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `double` when calling `test_endpoint_parameters`") # noqa: E501 # verify the required parameter 'pattern_without_delimiter' is set if ('pattern_without_delimiter' not in local_var_params or local_var_params['pattern_without_delimiter'] is None): - raise ValueError("Missing the required parameter `pattern_without_delimiter` when calling `test_endpoint_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pattern_without_delimiter` when calling `test_endpoint_parameters`") # noqa: E501 # verify the required parameter 'byte' is set if ('byte' not in local_var_params or local_var_params['byte'] is None): - raise ValueError("Missing the required parameter `byte` when calling `test_endpoint_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `byte` when calling `test_endpoint_parameters`") # noqa: E501 if 'number' in local_var_params and local_var_params['number'] > 543.2: # noqa: E501 - raise ValueError("Invalid value for parameter `number` when calling `test_endpoint_parameters`, must be a value less than or equal to `543.2`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `number` when calling `test_endpoint_parameters`, must be a value less than or equal to `543.2`") # noqa: E501 if 'number' in local_var_params and local_var_params['number'] < 32.1: # noqa: E501 - raise ValueError("Invalid value for parameter `number` when calling `test_endpoint_parameters`, must be a value greater than or equal to `32.1`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `number` when calling `test_endpoint_parameters`, must be a value greater than or equal to `32.1`") # noqa: E501 if 'double' in local_var_params and local_var_params['double'] > 123.4: # noqa: E501 - raise ValueError("Invalid value for parameter `double` when calling `test_endpoint_parameters`, must be a value less than or equal to `123.4`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `double` when calling `test_endpoint_parameters`, must be a value less than or equal to `123.4`") # noqa: E501 if 'double' in local_var_params and local_var_params['double'] < 67.8: # noqa: E501 - raise ValueError("Invalid value for parameter `double` when calling `test_endpoint_parameters`, must be a value greater than or equal to `67.8`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `double` when calling `test_endpoint_parameters`, must be a value greater than or equal to `67.8`") # noqa: E501 if 'pattern_without_delimiter' in local_var_params and not re.search(r'^[A-Z].*', local_var_params['pattern_without_delimiter']): # noqa: E501 - raise ValueError("Invalid value for parameter `pattern_without_delimiter` when calling `test_endpoint_parameters`, must conform to the pattern `/^[A-Z].*/`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `pattern_without_delimiter` when calling `test_endpoint_parameters`, must conform to the pattern `/^[A-Z].*/`") # noqa: E501 if 'integer' in local_var_params and local_var_params['integer'] > 100: # noqa: E501 - raise ValueError("Invalid value for parameter `integer` when calling `test_endpoint_parameters`, must be a value less than or equal to `100`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `integer` when calling `test_endpoint_parameters`, must be a value less than or equal to `100`") # noqa: E501 if 'integer' in local_var_params and local_var_params['integer'] < 10: # noqa: E501 - raise ValueError("Invalid value for parameter `integer` when calling `test_endpoint_parameters`, must be a value greater than or equal to `10`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `integer` when calling `test_endpoint_parameters`, must be a value greater than or equal to `10`") # noqa: E501 if 'int32' in local_var_params and local_var_params['int32'] > 200: # noqa: E501 - raise ValueError("Invalid value for parameter `int32` when calling `test_endpoint_parameters`, must be a value less than or equal to `200`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `int32` when calling `test_endpoint_parameters`, must be a value less than or equal to `200`") # noqa: E501 if 'int32' in local_var_params and local_var_params['int32'] < 20: # noqa: E501 - raise ValueError("Invalid value for parameter `int32` when calling `test_endpoint_parameters`, must be a value greater than or equal to `20`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `int32` when calling `test_endpoint_parameters`, must be a value greater than or equal to `20`") # noqa: E501 if 'float' in local_var_params and local_var_params['float'] > 987.6: # noqa: E501 - raise ValueError("Invalid value for parameter `float` when calling `test_endpoint_parameters`, must be a value less than or equal to `987.6`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `float` when calling `test_endpoint_parameters`, must be a value less than or equal to `987.6`") # noqa: E501 if 'string' in local_var_params and not re.search(r'[a-z]', local_var_params['string'], flags=re.IGNORECASE): # noqa: E501 - raise ValueError("Invalid value for parameter `string` when calling `test_endpoint_parameters`, must conform to the pattern `/[a-z]/i`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `string` when calling `test_endpoint_parameters`, must conform to the pattern `/[a-z]/i`") # noqa: E501 if ('password' in local_var_params and len(local_var_params['password']) > 64): - raise ValueError("Invalid value for parameter `password` when calling `test_endpoint_parameters`, length must be less than or equal to `64`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `password` when calling `test_endpoint_parameters`, length must be less than or equal to `64`") # noqa: E501 if ('password' in local_var_params and len(local_var_params['password']) < 10): - raise ValueError("Invalid value for parameter `password` when calling `test_endpoint_parameters`, length must be greater than or equal to `10`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `password` when calling `test_endpoint_parameters`, length must be greater than or equal to `10`") # noqa: E501 collection_formats = {} path_params = {} @@ -974,7 +1096,7 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -982,7 +1104,7 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_enum_parameters(self, **kwargs): # noqa: E501 + def test_enum_parameters(self, _check_type=False, **kwargs): # noqa: E501 """To test enum parameters # noqa: E501 To test enum parameters # noqa: E501 @@ -992,13 +1114,13 @@ def test_enum_parameters(self, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] enum_header_string_array: Header parameter enum test (string array) + :param [(str,)] enum_header_string_array: Header parameter enum test (string array) :param str enum_header_string: Header parameter enum test (string) - :param list[str] enum_query_string_array: Query parameter enum test (string array) + :param [(str,)] enum_query_string_array: Query parameter enum test (string array) :param str enum_query_string: Query parameter enum test (string) :param int enum_query_integer: Query parameter enum test (double) :param float enum_query_double: Query parameter enum test (double) - :param list[str] enum_form_string_array: Form parameter enum test (string array) + :param [(str,)] enum_form_string_array: Form parameter enum test (string array) :param str enum_form_string: Form parameter enum test (string) :return: None If the method is called asynchronously, @@ -1006,12 +1128,12 @@ def test_enum_parameters(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_enum_parameters_with_http_info(**kwargs) # noqa: E501 + return self.test_enum_parameters_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_enum_parameters_with_http_info(**kwargs) # noqa: E501 + (data) = self.test_enum_parameters_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 + def test_enum_parameters_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """To test enum parameters # noqa: E501 To test enum parameters # noqa: E501 @@ -1021,13 +1143,13 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] enum_header_string_array: Header parameter enum test (string array) + :param [(str,)] enum_header_string_array: Header parameter enum test (string array) :param str enum_header_string: Header parameter enum test (string) - :param list[str] enum_query_string_array: Query parameter enum test (string array) + :param [(str,)] enum_query_string_array: Query parameter enum test (string array) :param str enum_query_string: Query parameter enum test (string) :param int enum_query_integer: Query parameter enum test (double) :param float enum_query_double: Query parameter enum test (double) - :param list[str] enum_form_string_array: Form parameter enum test (string array) + :param [(str,)] enum_form_string_array: Form parameter enum test (string array) :param str enum_form_string: Form parameter enum test (string) :return: None If the method is called asynchronously, @@ -1044,12 +1166,29 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_enum_parameters" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'enum_header_string_array': [[(str,)]], + 'enum_header_string': [str], + 'enum_query_string_array': [[(str,)]], + 'enum_query_string': [str], + 'enum_query_integer': [int], + 'enum_query_double': [float], + 'enum_form_string_array': [[(str,)]], + 'enum_form_string': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) collection_formats = {} @@ -1097,7 +1236,7 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1105,7 +1244,7 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_group_parameters(self, required_string_group, required_boolean_group, required_int64_group, **kwargs): # noqa: E501 + def test_group_parameters(self, required_string_group, required_boolean_group, required_int64_group, _check_type=False, **kwargs): # noqa: E501 """Fake endpoint to test group parameters (optional) # noqa: E501 Fake endpoint to test group parameters (optional) # noqa: E501 @@ -1127,12 +1266,12 @@ def test_group_parameters(self, required_string_group, required_boolean_group, r """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_group_parameters_with_http_info(required_string_group, required_boolean_group, required_int64_group, **kwargs) # noqa: E501 + return self.test_group_parameters_with_http_info(required_string_group, required_boolean_group, required_int64_group, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_group_parameters_with_http_info(required_string_group, required_boolean_group, required_int64_group, **kwargs) # noqa: E501 + (data) = self.test_group_parameters_with_http_info(required_string_group, required_boolean_group, required_int64_group, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_group_parameters_with_http_info(self, required_string_group, required_boolean_group, required_int64_group, **kwargs): # noqa: E501 + def test_group_parameters_with_http_info(self, required_string_group, required_boolean_group, required_int64_group, _check_type=False, **kwargs): # noqa: E501 """Fake endpoint to test group parameters (optional) # noqa: E501 Fake endpoint to test group parameters (optional) # noqa: E501 @@ -1163,24 +1302,39 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_group_parameters" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'required_string_group': [int], + 'required_boolean_group': [bool], + 'required_int64_group': [int], + 'string_group': [int], + 'boolean_group': [bool], + 'int64_group': [int], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'required_string_group' is set if ('required_string_group' not in local_var_params or local_var_params['required_string_group'] is None): - raise ValueError("Missing the required parameter `required_string_group` when calling `test_group_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `required_string_group` when calling `test_group_parameters`") # noqa: E501 # verify the required parameter 'required_boolean_group' is set if ('required_boolean_group' not in local_var_params or local_var_params['required_boolean_group'] is None): - raise ValueError("Missing the required parameter `required_boolean_group` when calling `test_group_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `required_boolean_group` when calling `test_group_parameters`") # noqa: E501 # verify the required parameter 'required_int64_group' is set if ('required_int64_group' not in local_var_params or local_var_params['required_int64_group'] is None): - raise ValueError("Missing the required parameter `required_int64_group` when calling `test_group_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `required_int64_group` when calling `test_group_parameters`") # noqa: E501 collection_formats = {} @@ -1217,7 +1371,7 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1225,7 +1379,7 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_inline_additional_properties(self, param, **kwargs): # noqa: E501 + def test_inline_additional_properties(self, param, _check_type=False, **kwargs): # noqa: E501 """test inline additionalProperties # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -1234,19 +1388,19 @@ def test_inline_additional_properties(self, param, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param dict(str, str) param: request body (required) + :param {str: (str,)} param: request body (required) :return: None If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_inline_additional_properties_with_http_info(param, **kwargs) # noqa: E501 + return self.test_inline_additional_properties_with_http_info(param, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_inline_additional_properties_with_http_info(param, **kwargs) # noqa: E501 + (data) = self.test_inline_additional_properties_with_http_info(param, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_inline_additional_properties_with_http_info(self, param, **kwargs): # noqa: E501 + def test_inline_additional_properties_with_http_info(self, param, _check_type=False, **kwargs): # noqa: E501 """test inline additionalProperties # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -1255,7 +1409,7 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): # >>> result = thread.get() :param async_req bool - :param dict(str, str) param: request body (required) + :param {str: (str,)} param: request body (required) :return: None If the method is called asynchronously, returns the request thread. @@ -1271,16 +1425,26 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): # for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_inline_additional_properties" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'param': [{str: (str,)}], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'param' is set if ('param' not in local_var_params or local_var_params['param'] is None): - raise ValueError("Missing the required parameter `param` when calling `test_inline_additional_properties`") # noqa: E501 + raise ApiValueError("Missing the required parameter `param` when calling `test_inline_additional_properties`") # noqa: E501 collection_formats = {} @@ -1311,7 +1475,7 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): # body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1319,7 +1483,7 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): # _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_json_form_data(self, param, param2, **kwargs): # noqa: E501 + def test_json_form_data(self, param, param2, _check_type=False, **kwargs): # noqa: E501 """test json serialization of form data # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -1336,12 +1500,12 @@ def test_json_form_data(self, param, param2, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_json_form_data_with_http_info(param, param2, **kwargs) # noqa: E501 + return self.test_json_form_data_with_http_info(param, param2, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_json_form_data_with_http_info(param, param2, **kwargs) # noqa: E501 + (data) = self.test_json_form_data_with_http_info(param, param2, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa: E501 + def test_json_form_data_with_http_info(self, param, param2, _check_type=False, **kwargs): # noqa: E501 """test json serialization of form data # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -1367,20 +1531,31 @@ def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa: for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_json_form_data" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'param': [str], + 'param2': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'param' is set if ('param' not in local_var_params or local_var_params['param'] is None): - raise ValueError("Missing the required parameter `param` when calling `test_json_form_data`") # noqa: E501 + raise ApiValueError("Missing the required parameter `param` when calling `test_json_form_data`") # noqa: E501 # verify the required parameter 'param2' is set if ('param2' not in local_var_params or local_var_params['param2'] is None): - raise ValueError("Missing the required parameter `param2` when calling `test_json_form_data`") # noqa: E501 + raise ApiValueError("Missing the required parameter `param2` when calling `test_json_form_data`") # noqa: E501 collection_formats = {} @@ -1413,7 +1588,7 @@ def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-asyncio/petstore_api/api/fake_classname_tags_123_api.py b/samples/client/petstore/python-asyncio/petstore_api/api/fake_classname_tags_123_api.py index dbf6ef3dfb37..765a41b2827e 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/api/fake_classname_tags_123_api.py +++ b/samples/client/petstore/python-asyncio/petstore_api/api/fake_classname_tags_123_api.py @@ -18,6 +18,20 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.client import Client class FakeClassnameTags123Api(object): @@ -32,7 +46,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def test_classname(self, body, **kwargs): # noqa: E501 + def test_classname(self, body, _check_type=False, **kwargs): # noqa: E501 """To test class name in snake case # noqa: E501 To test class name in snake case # noqa: E501 @@ -49,12 +63,12 @@ def test_classname(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_classname_with_http_info(body, **kwargs) # noqa: E501 + return self.test_classname_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_classname_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.test_classname_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_classname_with_http_info(self, body, **kwargs): # noqa: E501 + def test_classname_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """To test class name in snake case # noqa: E501 To test class name in snake case # noqa: E501 @@ -80,16 +94,26 @@ def test_classname_with_http_info(self, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_classname" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [Client], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `test_classname`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `test_classname`") # noqa: E501 collection_formats = {} @@ -124,7 +148,7 @@ def test_classname_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types_mixed=[Client], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-asyncio/petstore_api/api/pet_api.py b/samples/client/petstore/python-asyncio/petstore_api/api/pet_api.py index f29e7239666a..7e07c241e0e1 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/api/pet_api.py +++ b/samples/client/petstore/python-asyncio/petstore_api/api/pet_api.py @@ -18,6 +18,21 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.api_response import ApiResponse +from petstore_api.models.pet import Pet class PetApi(object): @@ -32,7 +47,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def add_pet(self, body, **kwargs): # noqa: E501 + def add_pet(self, body, _check_type=False, **kwargs): # noqa: E501 """Add a new pet to the store # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -48,12 +63,12 @@ def add_pet(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.add_pet_with_http_info(body, **kwargs) # noqa: E501 + return self.add_pet_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.add_pet_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.add_pet_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def add_pet_with_http_info(self, body, **kwargs): # noqa: E501 + def add_pet_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """Add a new pet to the store # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -78,16 +93,26 @@ def add_pet_with_http_info(self, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method add_pet" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [Pet], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `add_pet`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `add_pet`") # noqa: E501 collection_formats = {} @@ -118,7 +143,7 @@ def add_pet_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -126,7 +151,7 @@ def add_pet_with_http_info(self, body, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def delete_pet(self, pet_id, **kwargs): # noqa: E501 + def delete_pet(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Deletes a pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -143,12 +168,12 @@ def delete_pet(self, pet_id, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.delete_pet_with_http_info(pet_id, **kwargs) # noqa: E501 + return self.delete_pet_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.delete_pet_with_http_info(pet_id, **kwargs) # noqa: E501 + (data) = self.delete_pet_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 + def delete_pet_with_http_info(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Deletes a pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -174,16 +199,27 @@ def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method delete_pet" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet_id': [int], + 'api_key': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet_id' is set if ('pet_id' not in local_var_params or local_var_params['pet_id'] is None): - raise ValueError("Missing the required parameter `pet_id` when calling `delete_pet`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet_id` when calling `delete_pet`") # noqa: E501 collection_formats = {} @@ -212,7 +248,7 @@ def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -220,7 +256,7 @@ def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def find_pets_by_status(self, status, **kwargs): # noqa: E501 + def find_pets_by_status(self, status, _check_type=False, **kwargs): # noqa: E501 """Finds Pets by status # noqa: E501 Multiple status values can be provided with comma separated strings # noqa: E501 @@ -230,19 +266,19 @@ def find_pets_by_status(self, status, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] status: Status values that need to be considered for filter (required) - :return: list[Pet] + :param [(str,)] status: Status values that need to be considered for filter (required) + :return: [(Pet,)] If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.find_pets_by_status_with_http_info(status, **kwargs) # noqa: E501 + return self.find_pets_by_status_with_http_info(status, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.find_pets_by_status_with_http_info(status, **kwargs) # noqa: E501 + (data) = self.find_pets_by_status_with_http_info(status, _check_type=_check_type, **kwargs) # noqa: E501 return data - def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 + def find_pets_by_status_with_http_info(self, status, _check_type=False, **kwargs): # noqa: E501 """Finds Pets by status # noqa: E501 Multiple status values can be provided with comma separated strings # noqa: E501 @@ -252,8 +288,8 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] status: Status values that need to be considered for filter (required) - :return: list[Pet] + :param [(str,)] status: Status values that need to be considered for filter (required) + :return: [(Pet,)] If the method is called asynchronously, returns the request thread. """ @@ -268,16 +304,26 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method find_pets_by_status" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'status': [[(str,)]], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'status' is set if ('status' not in local_var_params or local_var_params['status'] is None): - raise ValueError("Missing the required parameter `status` when calling `find_pets_by_status`") # noqa: E501 + raise ApiValueError("Missing the required parameter `status` when calling `find_pets_by_status`") # noqa: E501 collection_formats = {} @@ -309,7 +355,7 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='list[Pet]', # noqa: E501 + response_types_mixed=[[(Pet,)]], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -317,7 +363,7 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def find_pets_by_tags(self, tags, **kwargs): # noqa: E501 + def find_pets_by_tags(self, tags, _check_type=False, **kwargs): # noqa: E501 """Finds Pets by tags # noqa: E501 Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. # noqa: E501 @@ -327,19 +373,19 @@ def find_pets_by_tags(self, tags, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] tags: Tags to filter by (required) - :return: list[Pet] + :param [(str,)] tags: Tags to filter by (required) + :return: [(Pet,)] If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.find_pets_by_tags_with_http_info(tags, **kwargs) # noqa: E501 + return self.find_pets_by_tags_with_http_info(tags, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.find_pets_by_tags_with_http_info(tags, **kwargs) # noqa: E501 + (data) = self.find_pets_by_tags_with_http_info(tags, _check_type=_check_type, **kwargs) # noqa: E501 return data - def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 + def find_pets_by_tags_with_http_info(self, tags, _check_type=False, **kwargs): # noqa: E501 """Finds Pets by tags # noqa: E501 Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. # noqa: E501 @@ -349,8 +395,8 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] tags: Tags to filter by (required) - :return: list[Pet] + :param [(str,)] tags: Tags to filter by (required) + :return: [(Pet,)] If the method is called asynchronously, returns the request thread. """ @@ -365,16 +411,26 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method find_pets_by_tags" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'tags': [[(str,)]], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'tags' is set if ('tags' not in local_var_params or local_var_params['tags'] is None): - raise ValueError("Missing the required parameter `tags` when calling `find_pets_by_tags`") # noqa: E501 + raise ApiValueError("Missing the required parameter `tags` when calling `find_pets_by_tags`") # noqa: E501 collection_formats = {} @@ -406,7 +462,7 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='list[Pet]', # noqa: E501 + response_types_mixed=[[(Pet,)]], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -414,7 +470,7 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def get_pet_by_id(self, pet_id, **kwargs): # noqa: E501 + def get_pet_by_id(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Find pet by ID # noqa: E501 Returns a single pet # noqa: E501 @@ -431,12 +487,12 @@ def get_pet_by_id(self, pet_id, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.get_pet_by_id_with_http_info(pet_id, **kwargs) # noqa: E501 + return self.get_pet_by_id_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.get_pet_by_id_with_http_info(pet_id, **kwargs) # noqa: E501 + (data) = self.get_pet_by_id_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 + def get_pet_by_id_with_http_info(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Find pet by ID # noqa: E501 Returns a single pet # noqa: E501 @@ -462,16 +518,26 @@ def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method get_pet_by_id" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet_id': [int], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet_id' is set if ('pet_id' not in local_var_params or local_var_params['pet_id'] is None): - raise ValueError("Missing the required parameter `pet_id` when calling `get_pet_by_id`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet_id` when calling `get_pet_by_id`") # noqa: E501 collection_formats = {} @@ -502,7 +568,7 @@ def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Pet', # noqa: E501 + response_types_mixed=[Pet], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -510,7 +576,7 @@ def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def update_pet(self, body, **kwargs): # noqa: E501 + def update_pet(self, body, _check_type=False, **kwargs): # noqa: E501 """Update an existing pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -526,12 +592,12 @@ def update_pet(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.update_pet_with_http_info(body, **kwargs) # noqa: E501 + return self.update_pet_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.update_pet_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.update_pet_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def update_pet_with_http_info(self, body, **kwargs): # noqa: E501 + def update_pet_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """Update an existing pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -556,16 +622,26 @@ def update_pet_with_http_info(self, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method update_pet" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [Pet], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `update_pet`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `update_pet`") # noqa: E501 collection_formats = {} @@ -596,7 +672,7 @@ def update_pet_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -604,7 +680,7 @@ def update_pet_with_http_info(self, body, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def update_pet_with_form(self, pet_id, **kwargs): # noqa: E501 + def update_pet_with_form(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Updates a pet in the store with form data # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -622,12 +698,12 @@ def update_pet_with_form(self, pet_id, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.update_pet_with_form_with_http_info(pet_id, **kwargs) # noqa: E501 + return self.update_pet_with_form_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.update_pet_with_form_with_http_info(pet_id, **kwargs) # noqa: E501 + (data) = self.update_pet_with_form_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 + def update_pet_with_form_with_http_info(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Updates a pet in the store with form data # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -654,16 +730,28 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method update_pet_with_form" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet_id': [int], + 'name': [str], + 'status': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet_id' is set if ('pet_id' not in local_var_params or local_var_params['pet_id'] is None): - raise ValueError("Missing the required parameter `pet_id` when calling `update_pet_with_form`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet_id` when calling `update_pet_with_form`") # noqa: E501 collection_formats = {} @@ -698,7 +786,7 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -706,7 +794,7 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def upload_file(self, pet_id, **kwargs): # noqa: E501 + def upload_file(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """uploads an image # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -717,19 +805,19 @@ def upload_file(self, pet_id, **kwargs): # noqa: E501 :param async_req bool :param int pet_id: ID of pet to update (required) :param str additional_metadata: Additional data to pass to server - :param file file: file to upload + :param file_type file: file to upload :return: ApiResponse If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.upload_file_with_http_info(pet_id, **kwargs) # noqa: E501 + return self.upload_file_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.upload_file_with_http_info(pet_id, **kwargs) # noqa: E501 + (data) = self.upload_file_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 + def upload_file_with_http_info(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """uploads an image # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -740,7 +828,7 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 :param async_req bool :param int pet_id: ID of pet to update (required) :param str additional_metadata: Additional data to pass to server - :param file file: file to upload + :param file_type file: file to upload :return: ApiResponse If the method is called asynchronously, returns the request thread. @@ -756,16 +844,28 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method upload_file" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet_id': [int], + 'additional_metadata': [str], + 'file': [file_type], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet_id' is set if ('pet_id' not in local_var_params or local_var_params['pet_id'] is None): - raise ValueError("Missing the required parameter `pet_id` when calling `upload_file`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet_id` when calling `upload_file`") # noqa: E501 collection_formats = {} @@ -804,7 +904,7 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='ApiResponse', # noqa: E501 + response_types_mixed=[ApiResponse], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -812,7 +912,7 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def upload_file_with_required_file(self, pet_id, required_file, **kwargs): # noqa: E501 + def upload_file_with_required_file(self, pet_id, required_file, _check_type=False, **kwargs): # noqa: E501 """uploads an image (required) # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -822,7 +922,7 @@ def upload_file_with_required_file(self, pet_id, required_file, **kwargs): # no :param async_req bool :param int pet_id: ID of pet to update (required) - :param file required_file: file to upload (required) + :param file_type required_file: file to upload (required) :param str additional_metadata: Additional data to pass to server :return: ApiResponse If the method is called asynchronously, @@ -830,12 +930,12 @@ def upload_file_with_required_file(self, pet_id, required_file, **kwargs): # no """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.upload_file_with_required_file_with_http_info(pet_id, required_file, **kwargs) # noqa: E501 + return self.upload_file_with_required_file_with_http_info(pet_id, required_file, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.upload_file_with_required_file_with_http_info(pet_id, required_file, **kwargs) # noqa: E501 + (data) = self.upload_file_with_required_file_with_http_info(pet_id, required_file, _check_type=_check_type, **kwargs) # noqa: E501 return data - def upload_file_with_required_file_with_http_info(self, pet_id, required_file, **kwargs): # noqa: E501 + def upload_file_with_required_file_with_http_info(self, pet_id, required_file, _check_type=False, **kwargs): # noqa: E501 """uploads an image (required) # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -845,7 +945,7 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, * :param async_req bool :param int pet_id: ID of pet to update (required) - :param file required_file: file to upload (required) + :param file_type required_file: file to upload (required) :param str additional_metadata: Additional data to pass to server :return: ApiResponse If the method is called asynchronously, @@ -862,20 +962,32 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, * for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method upload_file_with_required_file" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet_id': [int], + 'required_file': [file_type], + 'additional_metadata': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet_id' is set if ('pet_id' not in local_var_params or local_var_params['pet_id'] is None): - raise ValueError("Missing the required parameter `pet_id` when calling `upload_file_with_required_file`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet_id` when calling `upload_file_with_required_file`") # noqa: E501 # verify the required parameter 'required_file' is set if ('required_file' not in local_var_params or local_var_params['required_file'] is None): - raise ValueError("Missing the required parameter `required_file` when calling `upload_file_with_required_file`") # noqa: E501 + raise ApiValueError("Missing the required parameter `required_file` when calling `upload_file_with_required_file`") # noqa: E501 collection_formats = {} @@ -914,7 +1026,7 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, * body=body_params, post_params=form_params, files=local_var_files, - response_type='ApiResponse', # noqa: E501 + response_types_mixed=[ApiResponse], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-asyncio/petstore_api/api/store_api.py b/samples/client/petstore/python-asyncio/petstore_api/api/store_api.py index bd2677ef92bc..6a8bba9ac620 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/api/store_api.py +++ b/samples/client/petstore/python-asyncio/petstore_api/api/store_api.py @@ -18,6 +18,20 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.order import Order class StoreApi(object): @@ -32,7 +46,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def delete_order(self, order_id, **kwargs): # noqa: E501 + def delete_order(self, order_id, _check_type=False, **kwargs): # noqa: E501 """Delete purchase order by ID # noqa: E501 For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors # noqa: E501 @@ -49,12 +63,12 @@ def delete_order(self, order_id, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.delete_order_with_http_info(order_id, **kwargs) # noqa: E501 + return self.delete_order_with_http_info(order_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.delete_order_with_http_info(order_id, **kwargs) # noqa: E501 + (data) = self.delete_order_with_http_info(order_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 + def delete_order_with_http_info(self, order_id, _check_type=False, **kwargs): # noqa: E501 """Delete purchase order by ID # noqa: E501 For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors # noqa: E501 @@ -80,16 +94,26 @@ def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method delete_order" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'order_id': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'order_id' is set if ('order_id' not in local_var_params or local_var_params['order_id'] is None): - raise ValueError("Missing the required parameter `order_id` when calling `delete_order`") # noqa: E501 + raise ApiValueError("Missing the required parameter `order_id` when calling `delete_order`") # noqa: E501 collection_formats = {} @@ -116,7 +140,7 @@ def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -124,7 +148,7 @@ def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def get_inventory(self, **kwargs): # noqa: E501 + def get_inventory(self, _check_type=False, **kwargs): # noqa: E501 """Returns pet inventories by status # noqa: E501 Returns a map of status codes to quantities # noqa: E501 @@ -134,18 +158,18 @@ def get_inventory(self, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :return: dict(str, int) + :return: {str: (int,)} If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.get_inventory_with_http_info(**kwargs) # noqa: E501 + return self.get_inventory_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.get_inventory_with_http_info(**kwargs) # noqa: E501 + (data) = self.get_inventory_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def get_inventory_with_http_info(self, **kwargs): # noqa: E501 + def get_inventory_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """Returns pet inventories by status # noqa: E501 Returns a map of status codes to quantities # noqa: E501 @@ -155,7 +179,7 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :return: dict(str, int) + :return: {str: (int,)} If the method is called asynchronously, returns the request thread. """ @@ -170,7 +194,7 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method get_inventory" % key ) @@ -204,7 +228,7 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='dict(str, int)', # noqa: E501 + response_types_mixed=[{str: (int,)}], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -212,7 +236,7 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def get_order_by_id(self, order_id, **kwargs): # noqa: E501 + def get_order_by_id(self, order_id, _check_type=False, **kwargs): # noqa: E501 """Find purchase order by ID # noqa: E501 For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions # noqa: E501 @@ -229,12 +253,12 @@ def get_order_by_id(self, order_id, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.get_order_by_id_with_http_info(order_id, **kwargs) # noqa: E501 + return self.get_order_by_id_with_http_info(order_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.get_order_by_id_with_http_info(order_id, **kwargs) # noqa: E501 + (data) = self.get_order_by_id_with_http_info(order_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 + def get_order_by_id_with_http_info(self, order_id, _check_type=False, **kwargs): # noqa: E501 """Find purchase order by ID # noqa: E501 For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions # noqa: E501 @@ -260,21 +284,31 @@ def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method get_order_by_id" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'order_id': [int], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'order_id' is set if ('order_id' not in local_var_params or local_var_params['order_id'] is None): - raise ValueError("Missing the required parameter `order_id` when calling `get_order_by_id`") # noqa: E501 + raise ApiValueError("Missing the required parameter `order_id` when calling `get_order_by_id`") # noqa: E501 if 'order_id' in local_var_params and local_var_params['order_id'] > 5: # noqa: E501 - raise ValueError("Invalid value for parameter `order_id` when calling `get_order_by_id`, must be a value less than or equal to `5`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `order_id` when calling `get_order_by_id`, must be a value less than or equal to `5`") # noqa: E501 if 'order_id' in local_var_params and local_var_params['order_id'] < 1: # noqa: E501 - raise ValueError("Invalid value for parameter `order_id` when calling `get_order_by_id`, must be a value greater than or equal to `1`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `order_id` when calling `get_order_by_id`, must be a value greater than or equal to `1`") # noqa: E501 collection_formats = {} path_params = {} @@ -304,7 +338,7 @@ def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Order', # noqa: E501 + response_types_mixed=[Order], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -312,7 +346,7 @@ def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def place_order(self, body, **kwargs): # noqa: E501 + def place_order(self, body, _check_type=False, **kwargs): # noqa: E501 """Place an order for a pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -328,12 +362,12 @@ def place_order(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.place_order_with_http_info(body, **kwargs) # noqa: E501 + return self.place_order_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.place_order_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.place_order_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def place_order_with_http_info(self, body, **kwargs): # noqa: E501 + def place_order_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """Place an order for a pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -358,16 +392,26 @@ def place_order_with_http_info(self, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method place_order" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [Order], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `place_order`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `place_order`") # noqa: E501 collection_formats = {} @@ -398,7 +442,7 @@ def place_order_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Order', # noqa: E501 + response_types_mixed=[Order], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-asyncio/petstore_api/api/user_api.py b/samples/client/petstore/python-asyncio/petstore_api/api/user_api.py index c27299309a6d..672bbc57b59e 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/api/user_api.py +++ b/samples/client/petstore/python-asyncio/petstore_api/api/user_api.py @@ -18,6 +18,20 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.user import User class UserApi(object): @@ -32,7 +46,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def create_user(self, body, **kwargs): # noqa: E501 + def create_user(self, body, _check_type=False, **kwargs): # noqa: E501 """Create user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -49,12 +63,12 @@ def create_user(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.create_user_with_http_info(body, **kwargs) # noqa: E501 + return self.create_user_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.create_user_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.create_user_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def create_user_with_http_info(self, body, **kwargs): # noqa: E501 + def create_user_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """Create user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -80,16 +94,26 @@ def create_user_with_http_info(self, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method create_user" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [User], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `create_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `create_user`") # noqa: E501 collection_formats = {} @@ -116,7 +140,7 @@ def create_user_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -124,7 +148,7 @@ def create_user_with_http_info(self, body, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def create_users_with_array_input(self, body, **kwargs): # noqa: E501 + def create_users_with_array_input(self, body, _check_type=False, **kwargs): # noqa: E501 """Creates list of users with given input array # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -133,19 +157,19 @@ def create_users_with_array_input(self, body, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[User] body: List of user object (required) + :param [(User,)] body: List of user object (required) :return: None If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.create_users_with_array_input_with_http_info(body, **kwargs) # noqa: E501 + return self.create_users_with_array_input_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.create_users_with_array_input_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.create_users_with_array_input_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: E501 + def create_users_with_array_input_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """Creates list of users with given input array # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -154,7 +178,7 @@ def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: >>> result = thread.get() :param async_req bool - :param list[User] body: List of user object (required) + :param [(User,)] body: List of user object (required) :return: None If the method is called asynchronously, returns the request thread. @@ -170,16 +194,26 @@ def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method create_users_with_array_input" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [[(User,)]], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `create_users_with_array_input`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `create_users_with_array_input`") # noqa: E501 collection_formats = {} @@ -206,7 +240,7 @@ def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -214,7 +248,7 @@ def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def create_users_with_list_input(self, body, **kwargs): # noqa: E501 + def create_users_with_list_input(self, body, _check_type=False, **kwargs): # noqa: E501 """Creates list of users with given input array # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -223,19 +257,19 @@ def create_users_with_list_input(self, body, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[User] body: List of user object (required) + :param [(User,)] body: List of user object (required) :return: None If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.create_users_with_list_input_with_http_info(body, **kwargs) # noqa: E501 + return self.create_users_with_list_input_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.create_users_with_list_input_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.create_users_with_list_input_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: E501 + def create_users_with_list_input_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """Creates list of users with given input array # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -244,7 +278,7 @@ def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: >>> result = thread.get() :param async_req bool - :param list[User] body: List of user object (required) + :param [(User,)] body: List of user object (required) :return: None If the method is called asynchronously, returns the request thread. @@ -260,16 +294,26 @@ def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method create_users_with_list_input" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [[(User,)]], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `create_users_with_list_input`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `create_users_with_list_input`") # noqa: E501 collection_formats = {} @@ -296,7 +340,7 @@ def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -304,7 +348,7 @@ def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def delete_user(self, username, **kwargs): # noqa: E501 + def delete_user(self, username, _check_type=False, **kwargs): # noqa: E501 """Delete user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -321,12 +365,12 @@ def delete_user(self, username, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.delete_user_with_http_info(username, **kwargs) # noqa: E501 + return self.delete_user_with_http_info(username, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.delete_user_with_http_info(username, **kwargs) # noqa: E501 + (data) = self.delete_user_with_http_info(username, _check_type=_check_type, **kwargs) # noqa: E501 return data - def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 + def delete_user_with_http_info(self, username, _check_type=False, **kwargs): # noqa: E501 """Delete user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -352,16 +396,26 @@ def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method delete_user" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'username': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'username' is set if ('username' not in local_var_params or local_var_params['username'] is None): - raise ValueError("Missing the required parameter `username` when calling `delete_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `username` when calling `delete_user`") # noqa: E501 collection_formats = {} @@ -388,7 +442,7 @@ def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -396,7 +450,7 @@ def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def get_user_by_name(self, username, **kwargs): # noqa: E501 + def get_user_by_name(self, username, _check_type=False, **kwargs): # noqa: E501 """Get user by user name # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -412,12 +466,12 @@ def get_user_by_name(self, username, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.get_user_by_name_with_http_info(username, **kwargs) # noqa: E501 + return self.get_user_by_name_with_http_info(username, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.get_user_by_name_with_http_info(username, **kwargs) # noqa: E501 + (data) = self.get_user_by_name_with_http_info(username, _check_type=_check_type, **kwargs) # noqa: E501 return data - def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 + def get_user_by_name_with_http_info(self, username, _check_type=False, **kwargs): # noqa: E501 """Get user by user name # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -442,16 +496,26 @@ def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method get_user_by_name" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'username': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'username' is set if ('username' not in local_var_params or local_var_params['username'] is None): - raise ValueError("Missing the required parameter `username` when calling `get_user_by_name`") # noqa: E501 + raise ApiValueError("Missing the required parameter `username` when calling `get_user_by_name`") # noqa: E501 collection_formats = {} @@ -482,7 +546,7 @@ def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='User', # noqa: E501 + response_types_mixed=[User], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -490,7 +554,7 @@ def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def login_user(self, username, password, **kwargs): # noqa: E501 + def login_user(self, username, password, _check_type=False, **kwargs): # noqa: E501 """Logs user into the system # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -507,12 +571,12 @@ def login_user(self, username, password, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.login_user_with_http_info(username, password, **kwargs) # noqa: E501 + return self.login_user_with_http_info(username, password, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.login_user_with_http_info(username, password, **kwargs) # noqa: E501 + (data) = self.login_user_with_http_info(username, password, _check_type=_check_type, **kwargs) # noqa: E501 return data - def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 + def login_user_with_http_info(self, username, password, _check_type=False, **kwargs): # noqa: E501 """Logs user into the system # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -538,20 +602,31 @@ def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method login_user" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'username': [str], + 'password': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'username' is set if ('username' not in local_var_params or local_var_params['username'] is None): - raise ValueError("Missing the required parameter `username` when calling `login_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `username` when calling `login_user`") # noqa: E501 # verify the required parameter 'password' is set if ('password' not in local_var_params or local_var_params['password'] is None): - raise ValueError("Missing the required parameter `password` when calling `login_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `password` when calling `login_user`") # noqa: E501 collection_formats = {} @@ -584,7 +659,7 @@ def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='str', # noqa: E501 + response_types_mixed=[str], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -592,7 +667,7 @@ def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def logout_user(self, **kwargs): # noqa: E501 + def logout_user(self, _check_type=False, **kwargs): # noqa: E501 """Logs out current logged in user session # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -607,12 +682,12 @@ def logout_user(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.logout_user_with_http_info(**kwargs) # noqa: E501 + return self.logout_user_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.logout_user_with_http_info(**kwargs) # noqa: E501 + (data) = self.logout_user_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def logout_user_with_http_info(self, **kwargs): # noqa: E501 + def logout_user_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """Logs out current logged in user session # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -636,7 +711,7 @@ def logout_user_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method logout_user" % key ) @@ -666,7 +741,7 @@ def logout_user_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -674,7 +749,7 @@ def logout_user_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def update_user(self, username, body, **kwargs): # noqa: E501 + def update_user(self, username, body, _check_type=False, **kwargs): # noqa: E501 """Updated user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -692,12 +767,12 @@ def update_user(self, username, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.update_user_with_http_info(username, body, **kwargs) # noqa: E501 + return self.update_user_with_http_info(username, body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.update_user_with_http_info(username, body, **kwargs) # noqa: E501 + (data) = self.update_user_with_http_info(username, body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def update_user_with_http_info(self, username, body, **kwargs): # noqa: E501 + def update_user_with_http_info(self, username, body, _check_type=False, **kwargs): # noqa: E501 """Updated user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -724,20 +799,31 @@ def update_user_with_http_info(self, username, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method update_user" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'username': [str], + 'body': [User], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'username' is set if ('username' not in local_var_params or local_var_params['username'] is None): - raise ValueError("Missing the required parameter `username` when calling `update_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `username` when calling `update_user`") # noqa: E501 # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `update_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `update_user`") # noqa: E501 collection_formats = {} @@ -766,7 +852,7 @@ def update_user_with_http_info(self, username, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-asyncio/petstore_api/api_client.py b/samples/client/petstore/python-asyncio/petstore_api/api_client.py index d10ef76ce17c..4bbd372f8bd2 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/api_client.py +++ b/samples/client/petstore/python-asyncio/petstore_api/api_client.py @@ -10,7 +10,7 @@ from __future__ import absolute_import -import datetime +import copy import json import mimetypes from multiprocessing.pool import ThreadPool @@ -23,6 +23,22 @@ from six.moves.urllib.parse import quote from petstore_api.configuration import Configuration +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( + OpenApiModel, + date, + datetime, + deserialize_file, + file_type, + model_to_dict, + none_type, + str, + validate_and_convert_types +) import petstore_api.models from petstore_api import rest @@ -49,17 +65,11 @@ class ApiClient(object): to the API. More threads means more concurrent API requests. """ - PRIMITIVE_TYPES = (float, bool, bytes, six.text_type) + six.integer_types - NATIVE_TYPES_MAPPING = { - 'int': int, - 'long': int if six.PY3 else long, # noqa: F821 - 'float': float, - 'str': str, - 'bool': bool, - 'date': datetime.date, - 'datetime': datetime.datetime, - 'object': object, - } + # six.binary_type python2=str, python3=bytes + # six.text_type python2=unicode, python3=str + PRIMITIVE_TYPES = ( + (float, bool, six.binary_type, six.text_type) + six.integer_types + ) _pool = None def __init__(self, configuration=None, header_name=None, header_value=None, @@ -107,7 +117,7 @@ def set_default_header(self, header_name, header_value): async def __call_api( self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, - files=None, response_type=None, auth_settings=None, + files=None, response_types_mixed=None, auth_settings=None, _return_http_data_only=None, collection_formats=None, _preload_content=True, _request_timeout=None, _host=None): @@ -174,8 +184,9 @@ async def __call_api( return_data = response_data if _preload_content: # deserialize response data - if response_type: - return_data = self.deserialize(response_data, response_type) + if response_types_mixed: + return_data = self.deserialize(response_data, + response_types_mixed) else: return_data = None @@ -209,89 +220,59 @@ def sanitize_for_serialization(self, obj): elif isinstance(obj, tuple): return tuple(self.sanitize_for_serialization(sub_obj) for sub_obj in obj) - elif isinstance(obj, (datetime.datetime, datetime.date)): + elif isinstance(obj, (datetime, date)): return obj.isoformat() if isinstance(obj, dict): obj_dict = obj else: - # Convert model obj to dict except - # attributes `openapi_types`, `attribute_map` - # and attributes which value is not None. + # Convert model obj to dict # Convert attribute name to json key in # model definition for request. - obj_dict = {obj.attribute_map[attr]: getattr(obj, attr) - for attr, _ in six.iteritems(obj.openapi_types) - if getattr(obj, attr) is not None} + obj_dict = model_to_dict(obj, serialize=True) return {key: self.sanitize_for_serialization(val) for key, val in six.iteritems(obj_dict)} - def deserialize(self, response, response_type): + def deserialize(self, response, response_types_mixed): """Deserializes response into an object. :param response: RESTResponse object to be deserialized. - :param response_type: class literal for - deserialized object, or string of class name. + :param response_types_mixed: For the response, a list of + valid classes, or a list tuples of valid classes, or a dict where + the value is a tuple of value classes. :return: deserialized object. """ # handle file downloading # save response body into a tmp file and return the instance - if response_type == "file": - return self.__deserialize_file(response) + if response_types_mixed == [file_type]: + content_disposition = response.getheader("Content-Disposition") + return deserialize_file(response.data, self.configuration, + content_disposition=content_disposition) # fetch data from response object try: - data = json.loads(response.data) + received_data = json.loads(response.data) except ValueError: - data = response.data + # this path is used if we are deserializing string data + received_data = response.data - return self.__deserialize(data, response_type) + # store our data under the key of 'received_data' so users have some + # context if they are deserializing a string and the data type is wrong + deserialized_data = validate_and_convert_types( + received_data, + response_types_mixed, + ['received_data'], + configuration=self.configuration + ) + return deserialized_data - def __deserialize(self, data, klass): - """Deserializes dict, list, str into an object. - - :param data: dict, list or str. - :param klass: class literal, or string of class name. - - :return: object. - """ - if data is None: - return None - - if type(klass) == str: - if klass.startswith('list['): - sub_kls = re.match(r'list\[(.*)\]', klass).group(1) - return [self.__deserialize(sub_data, sub_kls) - for sub_data in data] - - if klass.startswith('dict('): - sub_kls = re.match(r'dict\(([^,]*), (.*)\)', klass).group(2) - return {k: self.__deserialize(v, sub_kls) - for k, v in six.iteritems(data)} - - # convert str to class - if klass in self.NATIVE_TYPES_MAPPING: - klass = self.NATIVE_TYPES_MAPPING[klass] - else: - klass = getattr(petstore_api.models, klass) - - if klass in self.PRIMITIVE_TYPES: - return self.__deserialize_primitive(data, klass) - elif klass == object: - return self.__deserialize_object(data) - elif klass == datetime.date: - return self.__deserialize_date(data) - elif klass == datetime.datetime: - return self.__deserialize_datatime(data) - else: - return self.__deserialize_model(data, klass) def call_api(self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, files=None, - response_type=None, auth_settings=None, async_req=None, + response_types_mixed=None, auth_settings=None, async_req=None, _return_http_data_only=None, collection_formats=None, _preload_content=True, _request_timeout=None, _host=None): """Makes the HTTP request (synchronous) and returns deserialized data. @@ -308,7 +289,15 @@ def call_api(self, resource_path, method, :param post_params dict: Request post form parameters, for `application/x-www-form-urlencoded`, `multipart/form-data`. :param auth_settings list: Auth Settings names for the request. - :param response: Response data type. + :param response_types_mixed: For the response, a list of + valid classes, or a list tuples of valid classes, or a dict where + the value is a tuple of value classes. + Example values: + [str] + [Pet] + [float, none_type], + [[(int, none_type)]], + [{str: (bool, str, int, float, date, datetime, str, none_type)}] :param files dict: key -> filename, value -> filepath, for `multipart/form-data`. :param async_req bool: execute request asynchronously @@ -334,7 +323,7 @@ def call_api(self, resource_path, method, return self.__call_api(resource_path, method, path_params, query_params, header_params, body, post_params, files, - response_type, auth_settings, + response_types_mixed, auth_settings, _return_http_data_only, collection_formats, _preload_content, _request_timeout, _host) else: @@ -342,7 +331,7 @@ def call_api(self, resource_path, method, method, path_params, query_params, header_params, body, post_params, files, - response_type, auth_settings, + response_types_mixed, auth_settings, _return_http_data_only, collection_formats, _preload_content, @@ -406,7 +395,7 @@ def request(self, method, url, query_params=None, headers=None, _request_timeout=_request_timeout, body=body) else: - raise ValueError( + raise ApiValueError( "http method must be `GET`, `HEAD`, `OPTIONS`," " `POST`, `PATCH`, `PUT` or `DELETE`." ) @@ -521,120 +510,6 @@ def update_params_for_auth(self, headers, querys, auth_settings): elif auth_setting['in'] == 'query': querys.append((auth_setting['key'], auth_setting['value'])) else: - raise ValueError( + raise ApiValueError( 'Authentication token must be in `query` or `header`' ) - - def __deserialize_file(self, response): - """Deserializes body to file - - Saves response body into a file in a temporary folder, - using the filename from the `Content-Disposition` header if provided. - - :param response: RESTResponse. - :return: file path. - """ - fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path) - os.close(fd) - os.remove(path) - - content_disposition = response.getheader("Content-Disposition") - if content_disposition: - filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?', - content_disposition).group(1) - path = os.path.join(os.path.dirname(path), filename) - - with open(path, "wb") as f: - f.write(response.data) - - return path - - def __deserialize_primitive(self, data, klass): - """Deserializes string to primitive type. - - :param data: str. - :param klass: class literal. - - :return: int, long, float, str, bool. - """ - try: - return klass(data) - except UnicodeEncodeError: - return six.text_type(data) - except TypeError: - return data - - def __deserialize_object(self, value): - """Return an original value. - - :return: object. - """ - return value - - def __deserialize_date(self, string): - """Deserializes string to date. - - :param string: str. - :return: date. - """ - try: - from dateutil.parser import parse - return parse(string).date() - except ImportError: - return string - except ValueError: - raise rest.ApiException( - status=0, - reason="Failed to parse `{0}` as date object".format(string) - ) - - def __deserialize_datatime(self, string): - """Deserializes string to datetime. - - The string should be in iso8601 datetime format. - - :param string: str. - :return: datetime. - """ - try: - from dateutil.parser import parse - return parse(string) - except ImportError: - return string - except ValueError: - raise rest.ApiException( - status=0, - reason=( - "Failed to parse `{0}` as datetime object" - .format(string) - ) - ) - - def __deserialize_model(self, data, klass): - """Deserializes list or dict to model. - - :param data: dict, list. - :param klass: class literal. - :return: model object. - """ - - if not klass.openapi_types and not hasattr(klass, - 'get_real_child_model'): - return data - - kwargs = {} - if klass.openapi_types is not None: - for attr, attr_type in six.iteritems(klass.openapi_types): - if (data is not None and - klass.attribute_map[attr] in data and - isinstance(data, (list, dict))): - value = data[klass.attribute_map[attr]] - kwargs[attr] = self.__deserialize(value, attr_type) - - instance = klass(**kwargs) - - if hasattr(instance, 'get_real_child_model'): - klass_name = instance.get_real_child_model(data) - if klass_name: - instance = self.__deserialize(data, klass_name) - return instance diff --git a/samples/client/petstore/python-asyncio/petstore_api/exceptions.py b/samples/client/petstore/python-asyncio/petstore_api/exceptions.py new file mode 100644 index 000000000000..6bf34b3f9fa7 --- /dev/null +++ b/samples/client/petstore/python-asyncio/petstore_api/exceptions.py @@ -0,0 +1,121 @@ +# 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: + is_int = isinstance(pth, int) + if six.PY2 and isinstance(pth, long) and is_int == False: + is_int = True + if is_int: + result += "[{0}]".format(pth) + else: + result += "['{0}']".format(pth) + return result diff --git a/samples/client/petstore/python-asyncio/petstore_api/model_utils.py b/samples/client/petstore/python-asyncio/petstore_api/model_utils.py new file mode 100644 index 000000000000..148a9cf683ea --- /dev/null +++ b/samples/client/petstore/python-asyncio/petstore_api/model_utils.py @@ -0,0 +1,605 @@ +# 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 copy +from datetime import date, datetime # noqa: F401 +import os +import re +import tempfile + +from dateutil.parser import parse +import six + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) + +none_type = type(None) +if six.PY3: + import io + file_type = io.IOBase + # these are needed for when other modules import str and int from here + str = str + int = int +else: + file_type = file # noqa: F821 + str_py2 = str + unicode_py2 = unicode + long_py2 = long + int_py2 = int + # this requires that the future library is installed + from builtins import int, str + + +class OpenApiModel(object): + """The base class for all OpenAPIModels""" + + +def get_simple_class(input_value): + """Returns an input_value's simple class that we will use for type checking + Python2: + float and int will return int, where int is the python3 int backport + str and unicode will return str, where str is the python3 str backport + Note: float and int ARE both instances of int backport + Note: str_py2 and unicode_py2 are NOT both instances of str backport + + Args: + input_value (class/class_instance): the item for which we will return + the simple class + """ + if isinstance(input_value, type): + # input_value is a class + return input_value + elif isinstance(input_value, list): + return list + elif isinstance(input_value, dict): + return dict + elif isinstance(input_value, none_type): + return none_type + elif isinstance(input_value, file_type): + return file_type + elif isinstance(input_value, bool): + # this must be higher than the int check because + # isinstance(True, int) == True + return bool + elif isinstance(input_value, int): + # for python2 input_value==long_instance -> return int + # where int is the python3 int backport + return int + elif isinstance(input_value, datetime): + # this must be higher than the date check because + # isinstance(datetime_instance, date) == True + return datetime + elif isinstance(input_value, date): + return datetime + elif (six.PY2 and isinstance(input_value, (str_py2, unicode_py2, str)) or + isinstance(input_value, str)): + return str + return type(input_value) + + +COERCION_INDEX_BY_TYPE = { + none_type: 0, + list: 1, + OpenApiModel: 2, + dict: 3, + float: 4, + int: 5, + bool: 6, + datetime: 7, + date: 8, + str: 9 +} + +# these are used to limit what type conversions we try to do +# when we have a valid type already and we want to try converting +# to another type +UPCONVERSION_TYPE_PAIRS = ( + (str, datetime), + (str, date), + (list, OpenApiModel), + (dict, OpenApiModel), +) + +COERCIBLE_TYPE_PAIRS = ( + (dict, OpenApiModel), + (list, OpenApiModel), + (str, int), + (str, float), + (str, datetime), + (str, date), + (int, str), + (float, str), + (str, file_type) +) + + +def order_response_types(required_types): + """Returns the required types sorted in coercion order + + Args: + required_types (list/tuple): collection of classes or instance of + list or dict with classs information inside it + + Returns: + (list): coercion order sorted collection of classes or instance + of list or dict with classs information inside it + """ + + def index_getter(class_or_instance): + if isinstance(class_or_instance, list): + return COERCION_INDEX_BY_TYPE[list] + elif isinstance(class_or_instance, dict): + return COERCION_INDEX_BY_TYPE[dict] + elif issubclass(class_or_instance, OpenApiModel): + return COERCION_INDEX_BY_TYPE[OpenApiModel] + return COERCION_INDEX_BY_TYPE[class_or_instance] + + sorted_types = sorted( + required_types, + key=lambda class_or_instance: index_getter(class_or_instance) + ) + return sorted_types + + +def remove_uncoercible(required_types_classes, current_item, must_convert=True): + """Only keeps the type conversions that are possible + + Args: + required_types_classes (tuple): tuple of classes that are required + these should be ordered by COERCION_INDEX_BY_TYPE + current_item (any): the current item to be converted + + Keyword Args: + must_convert (bool): if True the item to convert is of the wrong + type and we want a big list of coercibles + if False, we want a limited list of coercibles + + Returns: + (list): the remaining coercible required types, classes only + """ + current_type_simple = get_simple_class(current_item) + + results_classes = [] + for required_type_class in required_types_classes: + # convert our models to OpenApiModel + required_type_class_simplified = required_type_class + if isinstance(required_type_class_simplified, type): + if issubclass(required_type_class_simplified, OpenApiModel): + required_type_class_simplified = OpenApiModel + + if required_type_class_simplified == current_type_simple: + # don't consider converting to one's own class + continue + + class_pair = (current_type_simple, required_type_class_simplified) + if must_convert and class_pair in COERCIBLE_TYPE_PAIRS: + results_classes.append(required_type_class) + elif class_pair in UPCONVERSION_TYPE_PAIRS: + results_classes.append(required_type_class) + return results_classes + + +def get_required_type_classes(required_types_mixed): + """Converts the tuple required_types into a tuple and a dict described + below + + Args: + required_types_mixed (tuple/list): will contain either classes or + instance of list or dict + + Returns: + (valid_classes, dict_valid_class_to_child_types_mixed): + valid_classes (tuple): the valid classes that the current item + should be + dict_valid_class_to_child_types_mixed (doct): + valid_class (class): this is the key + child_types_mixed (list/dict/tuple): describes the valid child + types + """ + valid_classes = [] + child_req_types_by_current_type = {} + for required_type in required_types_mixed: + if isinstance(required_type, list): + valid_classes.append(list) + child_req_types_by_current_type[list] = required_type[0] + elif isinstance(required_type, dict): + valid_classes.append(dict) + child_req_types_by_current_type[dict] = required_type[str] + else: + valid_classes.append(required_type) + return tuple(valid_classes), child_req_types_by_current_type + + +def change_keys_js_to_python(input_dict, model_class): + """ + Converts from javascript_key keys in the input_dict to python_keys in + the output dict using the mapping in model_class + """ + + output_dict = {} + reversed_attr_map = {value: key for key, value in + six.iteritems(model_class.attribute_map)} + for javascript_key, value in six.iteritems(input_dict): + python_key = reversed_attr_map.get(javascript_key) + if python_key is None: + # if the key is unknown, it is in error or it is an + # additionalProperties variable + python_key = javascript_key + output_dict[python_key] = value + return output_dict + + +def get_type_error(var_value, path_to_item, valid_classes, key_type=False): + error_msg = type_error_message( + var_name=path_to_item[-1], + var_value=var_value, + valid_classes=valid_classes, + key_type=key_type + ) + return ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=valid_classes, + key_type=key_type + ) + + +def deserialize_primitive(data, klass, path_to_item): + """Deserializes string to primitive type. + + :param data: str/int/float + :param klass: str/class the class to convert to + + :return: int, float, str, bool, date, datetime + """ + additional_message = "" + try: + if klass in {datetime, date}: + additional_message = ( + "If you need your parameter to have a fallback " + "string value, please set its type as `type: {}` in your " + "spec. That allows the value to be any type. " + ) + if klass == datetime: + if len(data) < 8: + raise ValueError("This is not a datetime") + # The string should be in iso8601 datetime format. + parsed_datetime = parse(data) + date_only = (parsed_datetime.hour == 0 and + parsed_datetime.minute == 0 and + parsed_datetime.second == 0 and + parsed_datetime.tzinfo == None and + 8 <= len(data) <= 10) + if date_only: + raise ValueError("This is a date, not a datetime") + return parsed_datetime + elif klass == date: + if len(data) < 8: + raise ValueError("This is not a date") + return parse(data).date() + else: + converted_value = klass(data) + if isinstance(data, str) and klass == float: + if str(converted_value) != data: + # '7' -> 7.0 -> '7.0' != '7' + raise ValueError('This is not a float') + return converted_value + except (OverflowError, ValueError): + # parse can raise OverflowError + raise ApiValueError( + "{0}Failed to parse {1} as {2}".format( + additional_message, repr(data), get_py3_class_name(klass) + ), + path_to_item=path_to_item + ) + + +def deserialize_model(model_data, model_class, path_to_item, configuration): + """Deserializes model_data to model instance. + + Args: + model_data (list/dict): data to instantiate the model + model_class (OpenApiModel): the model class + path_to_item (list): path to the model in the received data + configuration (Configuration): the instance to use to convert files + + Returns: + model instance + + Raise: + ApiTypeError + ApiValueError + ApiKeyError + """ + fixed_model_data = copy.deepcopy(model_data) + + if isinstance(fixed_model_data, dict): + fixed_model_data = change_keys_js_to_python(fixed_model_data, + model_class) + + kw_args = dict(_check_type=True, + _path_to_item=path_to_item, + _configuration=configuration) + if isinstance(model_data, list): + instance = model_class(*model_data, **kw_args) + elif isinstance(model_data, dict): + kw_args.update(fixed_model_data) + instance = model_class(**kw_args) + + if hasattr(instance, 'get_real_child_model'): + discriminator_class = instance.get_real_child_model(model_data) + if discriminator_class: + if isinstance(model_data, list): + instance = discriminator_class(*model_data, **kw_args) + elif isinstance(model_data, dict): + instance = discriminator_class(**kw_args) + + return instance + + +def deserialize_file(response_data, configuration, content_disposition=None): + """Deserializes body to file + + Saves response body into a file in a temporary folder, + using the filename from the `Content-Disposition` header if provided. + + Args: + param response_data (str): the file data to write + configuration (Configuration): the instance to use to convert files + + Keyword Args: + content_disposition (str): the value of the Content-Disposition + header + + Returns: + (str): the deserialized file path + """ + fd, path = tempfile.mkstemp(dir=configuration.temp_folder_path) + os.close(fd) + os.remove(path) + + if content_disposition: + filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?', + content_disposition).group(1) + path = os.path.join(os.path.dirname(path), filename) + + with open(path, "wb") as f: + if six.PY3 and isisinstance(response_data, str): + # in python3 change str to bytes so we can write it + response_data = response_data.encode('utf-8') + f.write(response_data) + + return path + + +def attempt_convert_item(input_value, valid_classes, path_to_item, + configuration, key_type=False, must_convert=False): + """ + Args: + input_value (any): the data to convert + valid_classes (any): the classes that are valid + path_to_item (list): the path to the item to convert + configuration (Configuration): the instance to use to convert files + key_type (bool): if True we need to convert a key type (not supported) + must_convert (bool): if True we must convert + + Returns: + instance (any) the fixed item + + Raises: + ApiTypeError + ApiValueError + ApiKeyError + """ + valid_classes_ordered = order_response_types(valid_classes) + valid_classes_coercible = remove_uncoercible( + valid_classes_ordered, input_value) + if not valid_classes_coercible or key_type: + # we do not handle keytype errors, json will take care + # of this for us + raise get_type_error(input_value, path_to_item, valid_classes, + key_type=key_type) + deserialized_item = None + for valid_class in valid_classes_coercible: + try: + if issubclass(valid_class, OpenApiModel): + return deserialize_model(input_value, valid_class, + path_to_item, configuration) + elif valid_class == file_type: + return deserialize_file(input_value, configuration) + return deserialize_primitive(input_value, valid_class, + path_to_item) + except (ApiTypeError, ApiValueError, ApiKeyError) as conversion_exc: + if must_convert: + raise conversion_exc + # if we have conversion errors when must_convert == False + # we ignore the exception and move on to the next class + continue + # we were unable to convert, must_convert == False + return input_value + + +def validate_and_convert_types(input_value, required_types_mixed, path_to_item, + configuration=None): + """Raises a TypeError is there is a problem, otherwise returns value + + Args: + input_value (any): the data to validate/convert + required_types_mixed (list/dict/tuple): A list of + valid classes, or a list tuples of valid classes, or a dict where + the value is a tuple of value classes + path_to_item: (list) the path to the data being validated + this stores a list of keys or indices to get to the data being + validated + configuration: (Configuration): the configuration class to use + when converting file_type items. + If passed, conversion will be attempted when possible + If not passed, no conversions will be attempted and + exceptions will be raised + + Returns: + the correctly typed value + + Raises: + ApiTypeError + """ + results = get_required_type_classes(required_types_mixed) + valid_classes, child_req_types_by_current_type = results + + input_class_simple = get_simple_class(input_value) + valid_type = input_class_simple in set(valid_classes) + if not valid_type: + if configuration: + # if input_value is not valid_type try to convert it + converted_instance = attempt_convert_item(input_value, + valid_classes, path_to_item, configuration, key_type=False, + must_convert=True) + return converted_instance + else: + raise get_type_error(input_value, path_to_item, valid_classes, + key_type=False) + + # input_value's type is in valid_classes + if len(valid_classes) > 1 and configuration: + # there are valid classes which are not the current class + valid_classes_coercible = remove_uncoercible( + valid_classes, input_value, must_convert=False) + if valid_classes_coercible: + converted_instance = attempt_convert_item(input_value, + valid_classes_coercible, path_to_item, configuration, + key_type=False, must_convert=False) + return converted_instance + + if child_req_types_by_current_type == {}: + # all types are of the required types and there are no more inner + # variables left to look at + return input_value + inner_required_types = child_req_types_by_current_type.get( + type(input_value) + ) + if inner_required_types is None: + # for this type, there are not more inner variables left to look at + return input_value + if isinstance(input_value, list): + if input_value == []: + # allow an empty list + return input_value + for index, inner_value in enumerate(input_value): + inner_path = list(path_to_item) + inner_path.append(index) + input_value[index] = validate_and_convert_types(inner_value, + inner_required_types, inner_path, configuration=configuration) + elif isinstance(input_value, dict): + if input_value == {}: + # allow an empty dict + return input_value + for inner_key, inner_val in six.iteritems(input_value): + inner_path = list(path_to_item) + inner_path.append(inner_key) + if get_simple_class(inner_key) != str: + raise get_type_error(inner_key, inner_path, valid_classes, + key_type=True) + input_value[inner_key] = validate_and_convert_types(inner_val, + inner_required_types, inner_path, configuration=configuration) + return input_value + + +def model_to_dict(model_instance, serialize=True): + """Returns the model properties as a dict + + Args: + model_instance (one of your model instances): the model instance that + will be converted to a dict. + + Keyword Args: + serialize (bool): if True, the keys in the dict will be values from + attribute_map + """ + result = {} + + for attr, value in six.iteritems(model_instance._data_store): + if serialize: + attr = model_instance.attribute_map[attr] + if isinstance(value, list): + result[attr] = list(map( + lambda x: model_to_dict(x, serialize=serialize) + if hasattr(x, '_data_store') else x, value + )) + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], + model_to_dict(item[1], serialize=serialize)) + if hasattr(item[1], '_data_store') else item, + value.items() + )) + elif hasattr(value, '_data_store'): + result[attr] = model_to_dict(value, serialize=serialize) + else: + result[attr] = value + + return result + + +def type_error_message(var_value=None, var_name=None, valid_classes=None, + key_type=None): + """ + Keyword Args: + var_value (any): the variable which has the type_error + var_name (str): the name of the variable which has the typ error + valid_classes (tuple): the accepted classes for current_item's + value + 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 + """ + key_or_value = 'value' + if key_type: + key_or_value = 'key' + valid_classes_phrase = get_valid_classes_phrase(valid_classes) + msg = ( + "Invalid type for variable '{0}'. Required {1} type {2} and " + "passed type was {3}".format( + var_name, + key_or_value, + valid_classes_phrase, + type(var_value).__name__, + ) + ) + return msg + + +def get_valid_classes_phrase(input_classes): + """Returns a string phrase describing what types are allowed + Note: Adds the extra valid classes in python2 + """ + all_classes = list(input_classes) + if six.PY2 and str in input_classes: + all_classes.extend([str_py2, unicode_py2]) + if six.PY2 and int in input_classes: + all_classes.extend([int_py2, long_py2]) + all_classes = sorted(all_classes, key=lambda cls: cls.__name__) + all_class_names = [cls.__name__ for cls in all_classes] + if len(all_class_names) == 1: + return 'is {0}'.format(all_class_names[0]) + return "is one of [{0}]".format(", ".join(all_class_names)) + + +def get_py3_class_name(input_class): + if six.PY2: + if input_class == str: + return 'str' + elif input_class == int: + return 'int' + return input_class.__name__ diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/__init__.py b/samples/client/petstore/python-asyncio/petstore_api/models/__init__.py index 3a39467a63ac..9c318d971f6f 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/__init__.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/__init__.py @@ -14,7 +14,14 @@ from __future__ import absolute_import # import models into model package +from petstore_api.models.additional_properties_any_type import AdditionalPropertiesAnyType +from petstore_api.models.additional_properties_array import AdditionalPropertiesArray +from petstore_api.models.additional_properties_boolean import AdditionalPropertiesBoolean from petstore_api.models.additional_properties_class import AdditionalPropertiesClass +from petstore_api.models.additional_properties_integer import AdditionalPropertiesInteger +from petstore_api.models.additional_properties_number import AdditionalPropertiesNumber +from petstore_api.models.additional_properties_object import AdditionalPropertiesObject +from petstore_api.models.additional_properties_string import AdditionalPropertiesString from petstore_api.models.animal import Animal from petstore_api.models.api_response import ApiResponse from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_any_type.py b/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_any_type.py new file mode 100644 index 000000000000..2438b307cf8b --- /dev/null +++ b/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_any_type.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesAnyType(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [bool, date, datetime, dict, float, int, list, str] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesAnyType - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesAnyType. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesAnyType. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesAnyType. + + + Returns: + (str): The name of this AdditionalPropertiesAnyType. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesAnyType): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_array.py b/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_array.py new file mode 100644 index 000000000000..ba0306157ff9 --- /dev/null +++ b/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_array.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesArray(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [[(bool, date, datetime, dict, float, int, list, str)]] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesArray - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesArray. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesArray. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesArray. + + + Returns: + (str): The name of this AdditionalPropertiesArray. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesArray): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_boolean.py b/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_boolean.py new file mode 100644 index 000000000000..4d59de6fe53b --- /dev/null +++ b/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_boolean.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesBoolean(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [bool] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesBoolean - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesBoolean. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesBoolean. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesBoolean. + + + Returns: + (str): The name of this AdditionalPropertiesBoolean. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesBoolean): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_class.py b/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_class.py index dc4648ae1c7f..a38defb2045e 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_class.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_class.py @@ -15,8 +15,27 @@ import six - -class AdditionalPropertiesClass(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesClass(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +46,415 @@ class AdditionalPropertiesClass(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'map_property': 'dict(str, str)', - 'map_of_map_property': 'dict(str, dict(str, str))' + 'map_string': [{str: (str,)}], # noqa: E501 + 'map_number': [{str: (float,)}], # noqa: E501 + 'map_integer': [{str: (int,)}], # noqa: E501 + 'map_boolean': [{str: (bool,)}], # noqa: E501 + 'map_array_integer': [{str: ([(int,)],)}], # noqa: E501 + 'map_array_anytype': [{str: ([(bool, date, datetime, dict, float, int, list, str)],)}], # noqa: E501 + 'map_map_string': [{str: ({str: (str,)},)}], # noqa: E501 + 'map_map_anytype': [{str: ({str: (bool, date, datetime, dict, float, int, list, str)},)}], # noqa: E501 + 'anytype_1': [bool, date, datetime, dict, float, int, list, str], # noqa: E501 + 'anytype_2': [bool, date, datetime, dict, float, int, list, str], # noqa: E501 + 'anytype_3': [bool, date, datetime, dict, float, int, list, str] # noqa: E501 } - attribute_map = { - 'map_property': 'map_property', - 'map_of_map_property': 'map_of_map_property' + 'map_string': 'map_string', # noqa: E501 + 'map_number': 'map_number', # noqa: E501 + 'map_integer': 'map_integer', # noqa: E501 + 'map_boolean': 'map_boolean', # noqa: E501 + 'map_array_integer': 'map_array_integer', # noqa: E501 + 'map_array_anytype': 'map_array_anytype', # noqa: E501 + 'map_map_string': 'map_map_string', # noqa: E501 + 'map_map_anytype': 'map_map_anytype', # noqa: E501 + 'anytype_1': 'anytype_1', # noqa: E501 + 'anytype_2': 'anytype_2', # noqa: E501 + 'anytype_3': 'anytype_3' # noqa: E501 } - def __init__(self, map_property=None, map_of_map_property=None): # noqa: E501 - """AdditionalPropertiesClass - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesClass - 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 False + _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 + _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. + map_string ({str: (str,)}): [optional] # noqa: E501 + map_number ({str: (float,)}): [optional] # noqa: E501 + map_integer ({str: (int,)}): [optional] # noqa: E501 + map_boolean ({str: (bool,)}): [optional] # noqa: E501 + map_array_integer ({str: ([(int,)],)}): [optional] # noqa: E501 + map_array_anytype ({str: ([(bool, date, datetime, dict, float, int, list, str)],)}): [optional] # noqa: E501 + map_map_string ({str: ({str: (str,)},)}): [optional] # noqa: E501 + map_map_anytype ({str: ({str: (bool, date, datetime, dict, float, int, list, str)},)}): [optional] # noqa: E501 + anytype_1 (bool, date, datetime, dict, float, int, list, str): [optional] # noqa: E501 + anytype_2 (bool, date, datetime, dict, float, int, list, str): [optional] # noqa: E501 + anytype_3 (bool, date, datetime, dict, float, int, list, str): [optional] # noqa: E501 + """ - self._map_property = None - self._map_of_map_property = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def map_string(self): + """Gets the map_string of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + ({str: (str,)}): The map_string of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('map_string') + + @map_string.setter + def map_string( + self, map_string): + """Sets the map_string of this AdditionalPropertiesClass. + + + Returns: + ({str: (str,)}): The map_string of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'map_string', + map_string + ) + + @property + def map_number(self): + """Gets the map_number of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + ({str: (float,)}): The map_number of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('map_number') + + @map_number.setter + def map_number( + self, map_number): + """Sets the map_number of this AdditionalPropertiesClass. + + + Returns: + ({str: (float,)}): The map_number of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'map_number', + map_number + ) + + @property + def map_integer(self): + """Gets the map_integer of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + ({str: (int,)}): The map_integer of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('map_integer') + + @map_integer.setter + def map_integer( + self, map_integer): + """Sets the map_integer of this AdditionalPropertiesClass. + + + Returns: + ({str: (int,)}): The map_integer of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'map_integer', + map_integer + ) + + @property + def map_boolean(self): + """Gets the map_boolean of this AdditionalPropertiesClass. # noqa: E501 - if map_property is not None: - self.map_property = map_property - if map_of_map_property is not None: - self.map_of_map_property = map_of_map_property + + Returns: + ({str: (bool,)}): The map_boolean of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('map_boolean') + + @map_boolean.setter + def map_boolean( + self, map_boolean): + """Sets the map_boolean of this AdditionalPropertiesClass. + + + Returns: + ({str: (bool,)}): The map_boolean of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'map_boolean', + map_boolean + ) @property - def map_property(self): - """Gets the map_property of this AdditionalPropertiesClass. # noqa: E501 + def map_array_integer(self): + """Gets the map_array_integer of this AdditionalPropertiesClass. # noqa: E501 - :return: The map_property of this AdditionalPropertiesClass. # noqa: E501 - :rtype: dict(str, str) + Returns: + ({str: ([(int,)],)}): The map_array_integer of this AdditionalPropertiesClass. # noqa: E501 """ - return self._map_property + return self._data_store.get('map_array_integer') - @map_property.setter - def map_property(self, map_property): - """Sets the map_property of this AdditionalPropertiesClass. + @map_array_integer.setter + def map_array_integer( + self, map_array_integer): + """Sets the map_array_integer of this AdditionalPropertiesClass. - :param map_property: The map_property of this AdditionalPropertiesClass. # noqa: E501 - :type: dict(str, str) + Returns: + ({str: ([(int,)],)}): The map_array_integer of this AdditionalPropertiesClass. # noqa: E501 """ - self._map_property = map_property + self.__setitem__( + 'map_array_integer', + map_array_integer + ) @property - def map_of_map_property(self): - """Gets the map_of_map_property of this AdditionalPropertiesClass. # noqa: E501 + def map_array_anytype(self): + """Gets the map_array_anytype of this AdditionalPropertiesClass. # noqa: E501 - :return: The map_of_map_property of this AdditionalPropertiesClass. # noqa: E501 - :rtype: dict(str, dict(str, str)) + Returns: + ({str: ([(bool, date, datetime, dict, float, int, list, str)],)}): The map_array_anytype of this AdditionalPropertiesClass. # noqa: E501 """ - return self._map_of_map_property + return self._data_store.get('map_array_anytype') - @map_of_map_property.setter - def map_of_map_property(self, map_of_map_property): - """Sets the map_of_map_property of this AdditionalPropertiesClass. + @map_array_anytype.setter + def map_array_anytype( + self, map_array_anytype): + """Sets the map_array_anytype of this AdditionalPropertiesClass. - :param map_of_map_property: The map_of_map_property of this AdditionalPropertiesClass. # noqa: E501 - :type: dict(str, dict(str, str)) + Returns: + ({str: ([(bool, date, datetime, dict, float, int, list, str)],)}): The map_array_anytype of this AdditionalPropertiesClass. # noqa: E501 """ - self._map_of_map_property = map_of_map_property + self.__setitem__( + 'map_array_anytype', + map_array_anytype + ) + + @property + def map_map_string(self): + """Gets the map_map_string of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + ({str: ({str: (str,)},)}): The map_map_string of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('map_map_string') + + @map_map_string.setter + def map_map_string( + self, map_map_string): + """Sets the map_map_string of this AdditionalPropertiesClass. + + + Returns: + ({str: ({str: (str,)},)}): The map_map_string of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'map_map_string', + map_map_string + ) + + @property + def map_map_anytype(self): + """Gets the map_map_anytype of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + ({str: ({str: (bool, date, datetime, dict, float, int, list, str)},)}): The map_map_anytype of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('map_map_anytype') + + @map_map_anytype.setter + def map_map_anytype( + self, map_map_anytype): + """Sets the map_map_anytype of this AdditionalPropertiesClass. + + + Returns: + ({str: ({str: (bool, date, datetime, dict, float, int, list, str)},)}): The map_map_anytype of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'map_map_anytype', + map_map_anytype + ) + + @property + def anytype_1(self): + """Gets the anytype_1 of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + (bool, date, datetime, dict, float, int, list, str): The anytype_1 of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('anytype_1') + + @anytype_1.setter + def anytype_1( + self, anytype_1): + """Sets the anytype_1 of this AdditionalPropertiesClass. + + + Returns: + (bool, date, datetime, dict, float, int, list, str): The anytype_1 of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'anytype_1', + anytype_1 + ) + + @property + def anytype_2(self): + """Gets the anytype_2 of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + (bool, date, datetime, dict, float, int, list, str): The anytype_2 of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('anytype_2') + + @anytype_2.setter + def anytype_2( + self, anytype_2): + """Sets the anytype_2 of this AdditionalPropertiesClass. + + + Returns: + (bool, date, datetime, dict, float, int, list, str): The anytype_2 of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'anytype_2', + anytype_2 + ) + + @property + def anytype_3(self): + """Gets the anytype_3 of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + (bool, date, datetime, dict, float, int, list, str): The anytype_3 of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('anytype_3') + + @anytype_3.setter + def anytype_3( + self, anytype_3): + """Sets the anytype_3 of this AdditionalPropertiesClass. + + + Returns: + (bool, date, datetime, dict, float, int, list, str): The anytype_3 of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'anytype_3', + anytype_3 + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_integer.py b/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_integer.py new file mode 100644 index 000000000000..50994b5859e2 --- /dev/null +++ b/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_integer.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesInteger(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [int] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesInteger - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesInteger. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesInteger. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesInteger. + + + Returns: + (str): The name of this AdditionalPropertiesInteger. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesInteger): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_number.py b/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_number.py new file mode 100644 index 000000000000..6005bf6a2f55 --- /dev/null +++ b/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_number.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesNumber(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [float] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesNumber - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesNumber. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesNumber. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesNumber. + + + Returns: + (str): The name of this AdditionalPropertiesNumber. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesNumber): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_object.py b/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_object.py new file mode 100644 index 000000000000..6b18c3e18f30 --- /dev/null +++ b/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_object.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesObject(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [{str: (bool, date, datetime, dict, float, int, list, str)}] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesObject - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesObject. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesObject. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesObject. + + + Returns: + (str): The name of this AdditionalPropertiesObject. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesObject): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_string.py b/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_string.py new file mode 100644 index 000000000000..61d7e0278d63 --- /dev/null +++ b/samples/client/petstore/python-asyncio/petstore_api/models/additional_properties_string.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesString(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [str] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesString - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesString. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesString. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesString. + + + Returns: + (str): The name of this AdditionalPropertiesString. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesString): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/animal.py b/samples/client/petstore/python-asyncio/petstore_api/models/animal.py index abd6f705e5e8..ba09d8520ca1 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/animal.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/animal.py @@ -15,8 +15,29 @@ import six - -class Animal(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.cat import Cat +from petstore_api.models.dog import Dog + + +class Animal(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,78 +48,167 @@ class Animal(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'class_name': 'str', - 'color': 'str' + 'class_name': [str], # noqa: E501 + 'color': [str] # noqa: E501 } - attribute_map = { - 'class_name': 'className', - 'color': 'color' + 'class_name': 'className', # noqa: E501 + 'color': 'color' # noqa: E501 } - discriminator_value_class_map = { - 'Dog': 'Dog', - 'Cat': 'Cat' + 'Dog': Dog, + 'Cat': Cat } - def __init__(self, class_name=None, color='red'): # noqa: E501 - """Animal - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, class_name, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Animal - a model defined in OpenAPI + + Args: + class_name (str): + + 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 False + _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 + _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. + color (str): [optional] if omitted the server will use the default value of 'red' # noqa: E501 + """ - self._class_name = None - self._color = None + self._data_store = {} self.discriminator = 'class_name' + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + # assign using .var_name to check against nullable and enums self.class_name = class_name - if color is not None: - self.color = color + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def class_name(self): """Gets the class_name of this Animal. # noqa: E501 - :return: The class_name of this Animal. # noqa: E501 - :rtype: str + Returns: + (str): The class_name of this Animal. # noqa: E501 """ - return self._class_name + return self._data_store.get('class_name') @class_name.setter - def class_name(self, class_name): + def class_name( + self, class_name): """Sets the class_name of this Animal. - :param class_name: The class_name of this Animal. # noqa: E501 - :type: str + Returns: + (str): The class_name of this Animal. # noqa: E501 """ if class_name is None: - raise ValueError("Invalid value for `class_name`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `class_name`, must not be `None`") # noqa: E501 - self._class_name = class_name + self.__setitem__( + 'class_name', + class_name + ) @property def color(self): """Gets the color of this Animal. # noqa: E501 - :return: The color of this Animal. # noqa: E501 - :rtype: str + Returns: + (str): The color of this Animal. # noqa: E501 """ - return self._color + return self._data_store.get('color') @color.setter - def color(self, color): + def color( + self, color): """Sets the color of this Animal. - :param color: The color of this Animal. # noqa: E501 - :type: str + Returns: + (str): The color of this Animal. # noqa: E501 """ - self._color = color + self.__setitem__( + 'color', + color + ) def get_real_child_model(self, data): """Returns the real base class specified by the discriminator""" @@ -108,27 +218,7 @@ def get_real_child_model(self, data): 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/api_response.py b/samples/client/petstore/python-asyncio/petstore_api/models/api_response.py index e62983030491..50fcf50f5207 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/api_response.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/api_response.py @@ -15,8 +15,27 @@ import six - -class ApiResponse(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ApiResponse(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,122 +46,191 @@ class ApiResponse(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'code': 'int', - 'type': 'str', - 'message': 'str' + 'code': [int], # noqa: E501 + 'type': [str], # noqa: E501 + 'message': [str] # noqa: E501 } - attribute_map = { - 'code': 'code', - 'type': 'type', - 'message': 'message' + 'code': 'code', # noqa: E501 + 'type': 'type', # noqa: E501 + 'message': 'message' # noqa: E501 } - def __init__(self, code=None, type=None, message=None): # noqa: E501 - """ApiResponse - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ApiResponse - 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 False + _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 + _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. + code (int): [optional] # noqa: E501 + type (str): [optional] # noqa: E501 + message (str): [optional] # noqa: E501 + """ - self._code = None - self._type = None - self._message = None + self._data_store = {} self.discriminator = None - - if code is not None: - self.code = code - if type is not None: - self.type = type - if message is not None: - self.message = message + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def code(self): """Gets the code of this ApiResponse. # noqa: E501 - :return: The code of this ApiResponse. # noqa: E501 - :rtype: int + Returns: + (int): The code of this ApiResponse. # noqa: E501 """ - return self._code + return self._data_store.get('code') @code.setter - def code(self, code): + def code( + self, code): """Sets the code of this ApiResponse. - :param code: The code of this ApiResponse. # noqa: E501 - :type: int + Returns: + (int): The code of this ApiResponse. # noqa: E501 """ - self._code = code + self.__setitem__( + 'code', + code + ) @property def type(self): """Gets the type of this ApiResponse. # noqa: E501 - :return: The type of this ApiResponse. # noqa: E501 - :rtype: str + Returns: + (str): The type of this ApiResponse. # noqa: E501 """ - return self._type + return self._data_store.get('type') @type.setter - def type(self, type): + def type( + self, type): """Sets the type of this ApiResponse. - :param type: The type of this ApiResponse. # noqa: E501 - :type: str + Returns: + (str): The type of this ApiResponse. # noqa: E501 """ - self._type = type + self.__setitem__( + 'type', + type + ) @property def message(self): """Gets the message of this ApiResponse. # noqa: E501 - :return: The message of this ApiResponse. # noqa: E501 - :rtype: str + Returns: + (str): The message of this ApiResponse. # noqa: E501 """ - return self._message + return self._data_store.get('message') @message.setter - def message(self, message): + def message( + self, message): """Sets the message of this ApiResponse. - :param message: The message of this ApiResponse. # noqa: E501 - :type: str + Returns: + (str): The message of this ApiResponse. # noqa: E501 """ - self._message = message + self.__setitem__( + 'message', + message + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/array_of_array_of_number_only.py b/samples/client/petstore/python-asyncio/petstore_api/models/array_of_array_of_number_only.py index fde218a4661c..407b261c7f34 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/array_of_array_of_number_only.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/array_of_array_of_number_only.py @@ -15,8 +15,27 @@ import six - -class ArrayOfArrayOfNumberOnly(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ArrayOfArrayOfNumberOnly(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class ArrayOfArrayOfNumberOnly(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'array_array_number': 'list[list[float]]' + 'array_array_number': [[([(float,)],)]] # noqa: E501 } - attribute_map = { - 'array_array_number': 'ArrayArrayNumber' + 'array_array_number': 'ArrayArrayNumber' # noqa: E501 } - def __init__(self, array_array_number=None): # noqa: E501 - """ArrayOfArrayOfNumberOnly - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ArrayOfArrayOfNumberOnly - a model defined in OpenAPI - self._array_array_number = None - self.discriminator = None - if array_array_number is not None: - self.array_array_number = array_array_number + + 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 False + _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 + _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. + array_array_number ([([(float,)],)]): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def array_array_number(self): """Gets the array_array_number of this ArrayOfArrayOfNumberOnly. # noqa: E501 - :return: The array_array_number of this ArrayOfArrayOfNumberOnly. # noqa: E501 - :rtype: list[list[float]] + Returns: + ([([(float,)],)]): The array_array_number of this ArrayOfArrayOfNumberOnly. # noqa: E501 """ - return self._array_array_number + return self._data_store.get('array_array_number') @array_array_number.setter - def array_array_number(self, array_array_number): + def array_array_number( + self, array_array_number): """Sets the array_array_number of this ArrayOfArrayOfNumberOnly. - :param array_array_number: The array_array_number of this ArrayOfArrayOfNumberOnly. # noqa: E501 - :type: list[list[float]] + Returns: + ([([(float,)],)]): The array_array_number of this ArrayOfArrayOfNumberOnly. # noqa: E501 """ - self._array_array_number = array_array_number + self.__setitem__( + 'array_array_number', + array_array_number + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/array_of_number_only.py b/samples/client/petstore/python-asyncio/petstore_api/models/array_of_number_only.py index 8999e563c4a6..790a6761dc06 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/array_of_number_only.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/array_of_number_only.py @@ -15,8 +15,27 @@ import six - -class ArrayOfNumberOnly(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ArrayOfNumberOnly(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class ArrayOfNumberOnly(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'array_number': 'list[float]' + 'array_number': [[(float,)]] # noqa: E501 } - attribute_map = { - 'array_number': 'ArrayNumber' + 'array_number': 'ArrayNumber' # noqa: E501 } - def __init__(self, array_number=None): # noqa: E501 - """ArrayOfNumberOnly - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ArrayOfNumberOnly - a model defined in OpenAPI - self._array_number = None - self.discriminator = None - if array_number is not None: - self.array_number = array_number + + 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 False + _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 + _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. + array_number ([(float,)]): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def array_number(self): """Gets the array_number of this ArrayOfNumberOnly. # noqa: E501 - :return: The array_number of this ArrayOfNumberOnly. # noqa: E501 - :rtype: list[float] + Returns: + ([(float,)]): The array_number of this ArrayOfNumberOnly. # noqa: E501 """ - return self._array_number + return self._data_store.get('array_number') @array_number.setter - def array_number(self, array_number): + def array_number( + self, array_number): """Sets the array_number of this ArrayOfNumberOnly. - :param array_number: The array_number of this ArrayOfNumberOnly. # noqa: E501 - :type: list[float] + Returns: + ([(float,)]): The array_number of this ArrayOfNumberOnly. # noqa: E501 """ - self._array_number = array_number + self.__setitem__( + 'array_number', + array_number + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/array_test.py b/samples/client/petstore/python-asyncio/petstore_api/models/array_test.py index 05cc108139a5..63e94762f367 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/array_test.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/array_test.py @@ -15,8 +15,28 @@ import six - -class ArrayTest(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.read_only_first import ReadOnlyFirst + + +class ArrayTest(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,122 +47,191 @@ class ArrayTest(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'array_of_string': 'list[str]', - 'array_array_of_integer': 'list[list[int]]', - 'array_array_of_model': 'list[list[ReadOnlyFirst]]' + 'array_of_string': [[(str,)]], # noqa: E501 + 'array_array_of_integer': [[([(int,)],)]], # noqa: E501 + 'array_array_of_model': [[([(ReadOnlyFirst,)],)]] # noqa: E501 } - attribute_map = { - 'array_of_string': 'array_of_string', - 'array_array_of_integer': 'array_array_of_integer', - 'array_array_of_model': 'array_array_of_model' + 'array_of_string': 'array_of_string', # noqa: E501 + 'array_array_of_integer': 'array_array_of_integer', # noqa: E501 + 'array_array_of_model': 'array_array_of_model' # noqa: E501 } - def __init__(self, array_of_string=None, array_array_of_integer=None, array_array_of_model=None): # noqa: E501 - """ArrayTest - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ArrayTest - 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 False + _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 + _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. + array_of_string ([(str,)]): [optional] # noqa: E501 + array_array_of_integer ([([(int,)],)]): [optional] # noqa: E501 + array_array_of_model ([([(ReadOnlyFirst,)],)]): [optional] # noqa: E501 + """ - self._array_of_string = None - self._array_array_of_integer = None - self._array_array_of_model = None + self._data_store = {} self.discriminator = None - - if array_of_string is not None: - self.array_of_string = array_of_string - if array_array_of_integer is not None: - self.array_array_of_integer = array_array_of_integer - if array_array_of_model is not None: - self.array_array_of_model = array_array_of_model + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def array_of_string(self): """Gets the array_of_string of this ArrayTest. # noqa: E501 - :return: The array_of_string of this ArrayTest. # noqa: E501 - :rtype: list[str] + Returns: + ([(str,)]): The array_of_string of this ArrayTest. # noqa: E501 """ - return self._array_of_string + return self._data_store.get('array_of_string') @array_of_string.setter - def array_of_string(self, array_of_string): + def array_of_string( + self, array_of_string): """Sets the array_of_string of this ArrayTest. - :param array_of_string: The array_of_string of this ArrayTest. # noqa: E501 - :type: list[str] + Returns: + ([(str,)]): The array_of_string of this ArrayTest. # noqa: E501 """ - self._array_of_string = array_of_string + self.__setitem__( + 'array_of_string', + array_of_string + ) @property def array_array_of_integer(self): """Gets the array_array_of_integer of this ArrayTest. # noqa: E501 - :return: The array_array_of_integer of this ArrayTest. # noqa: E501 - :rtype: list[list[int]] + Returns: + ([([(int,)],)]): The array_array_of_integer of this ArrayTest. # noqa: E501 """ - return self._array_array_of_integer + return self._data_store.get('array_array_of_integer') @array_array_of_integer.setter - def array_array_of_integer(self, array_array_of_integer): + def array_array_of_integer( + self, array_array_of_integer): """Sets the array_array_of_integer of this ArrayTest. - :param array_array_of_integer: The array_array_of_integer of this ArrayTest. # noqa: E501 - :type: list[list[int]] + Returns: + ([([(int,)],)]): The array_array_of_integer of this ArrayTest. # noqa: E501 """ - self._array_array_of_integer = array_array_of_integer + self.__setitem__( + 'array_array_of_integer', + array_array_of_integer + ) @property def array_array_of_model(self): """Gets the array_array_of_model of this ArrayTest. # noqa: E501 - :return: The array_array_of_model of this ArrayTest. # noqa: E501 - :rtype: list[list[ReadOnlyFirst]] + Returns: + ([([(ReadOnlyFirst,)],)]): The array_array_of_model of this ArrayTest. # noqa: E501 """ - return self._array_array_of_model + return self._data_store.get('array_array_of_model') @array_array_of_model.setter - def array_array_of_model(self, array_array_of_model): + def array_array_of_model( + self, array_array_of_model): """Sets the array_array_of_model of this ArrayTest. - :param array_array_of_model: The array_array_of_model of this ArrayTest. # noqa: E501 - :type: list[list[ReadOnlyFirst]] + Returns: + ([([(ReadOnlyFirst,)],)]): The array_array_of_model of this ArrayTest. # noqa: E501 """ - self._array_array_of_model = array_array_of_model + self.__setitem__( + 'array_array_of_model', + array_array_of_model + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/capitalization.py b/samples/client/petstore/python-asyncio/petstore_api/models/capitalization.py index 923f5c4aae86..97f1c86c1cbf 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/capitalization.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/capitalization.py @@ -15,8 +15,27 @@ import six - -class Capitalization(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Capitalization(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,155 +46,246 @@ class Capitalization(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'small_camel': 'str', - 'capital_camel': 'str', - 'small_snake': 'str', - 'capital_snake': 'str', - 'sca_eth_flow_points': 'str', - 'att_name': 'str' + 'small_camel': [str], # noqa: E501 + 'capital_camel': [str], # noqa: E501 + 'small_snake': [str], # noqa: E501 + 'capital_snake': [str], # noqa: E501 + 'sca_eth_flow_points': [str], # noqa: E501 + 'att_name': [str] # noqa: E501 } - attribute_map = { - 'small_camel': 'smallCamel', - 'capital_camel': 'CapitalCamel', - 'small_snake': 'small_Snake', - 'capital_snake': 'Capital_Snake', - 'sca_eth_flow_points': 'SCA_ETH_Flow_Points', - 'att_name': 'ATT_NAME' + 'small_camel': 'smallCamel', # noqa: E501 + 'capital_camel': 'CapitalCamel', # noqa: E501 + 'small_snake': 'small_Snake', # noqa: E501 + 'capital_snake': 'Capital_Snake', # noqa: E501 + 'sca_eth_flow_points': 'SCA_ETH_Flow_Points', # noqa: E501 + 'att_name': 'ATT_NAME' # noqa: E501 } - def __init__(self, small_camel=None, capital_camel=None, small_snake=None, capital_snake=None, sca_eth_flow_points=None, att_name=None): # noqa: E501 - """Capitalization - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Capitalization - 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 False + _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 + _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. + small_camel (str): [optional] # noqa: E501 + capital_camel (str): [optional] # noqa: E501 + small_snake (str): [optional] # noqa: E501 + capital_snake (str): [optional] # noqa: E501 + sca_eth_flow_points (str): [optional] # noqa: E501 + att_name (str): Name of the pet . [optional] # noqa: E501 + """ - self._small_camel = None - self._capital_camel = None - self._small_snake = None - self._capital_snake = None - self._sca_eth_flow_points = None - self._att_name = None + self._data_store = {} self.discriminator = None - - if small_camel is not None: - self.small_camel = small_camel - if capital_camel is not None: - self.capital_camel = capital_camel - if small_snake is not None: - self.small_snake = small_snake - if capital_snake is not None: - self.capital_snake = capital_snake - if sca_eth_flow_points is not None: - self.sca_eth_flow_points = sca_eth_flow_points - if att_name is not None: - self.att_name = att_name + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def small_camel(self): """Gets the small_camel of this Capitalization. # noqa: E501 - :return: The small_camel of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The small_camel of this Capitalization. # noqa: E501 """ - return self._small_camel + return self._data_store.get('small_camel') @small_camel.setter - def small_camel(self, small_camel): + def small_camel( + self, small_camel): """Sets the small_camel of this Capitalization. - :param small_camel: The small_camel of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The small_camel of this Capitalization. # noqa: E501 """ - self._small_camel = small_camel + self.__setitem__( + 'small_camel', + small_camel + ) @property def capital_camel(self): """Gets the capital_camel of this Capitalization. # noqa: E501 - :return: The capital_camel of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The capital_camel of this Capitalization. # noqa: E501 """ - return self._capital_camel + return self._data_store.get('capital_camel') @capital_camel.setter - def capital_camel(self, capital_camel): + def capital_camel( + self, capital_camel): """Sets the capital_camel of this Capitalization. - :param capital_camel: The capital_camel of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The capital_camel of this Capitalization. # noqa: E501 """ - self._capital_camel = capital_camel + self.__setitem__( + 'capital_camel', + capital_camel + ) @property def small_snake(self): """Gets the small_snake of this Capitalization. # noqa: E501 - :return: The small_snake of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The small_snake of this Capitalization. # noqa: E501 """ - return self._small_snake + return self._data_store.get('small_snake') @small_snake.setter - def small_snake(self, small_snake): + def small_snake( + self, small_snake): """Sets the small_snake of this Capitalization. - :param small_snake: The small_snake of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The small_snake of this Capitalization. # noqa: E501 """ - self._small_snake = small_snake + self.__setitem__( + 'small_snake', + small_snake + ) @property def capital_snake(self): """Gets the capital_snake of this Capitalization. # noqa: E501 - :return: The capital_snake of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The capital_snake of this Capitalization. # noqa: E501 """ - return self._capital_snake + return self._data_store.get('capital_snake') @capital_snake.setter - def capital_snake(self, capital_snake): + def capital_snake( + self, capital_snake): """Sets the capital_snake of this Capitalization. - :param capital_snake: The capital_snake of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The capital_snake of this Capitalization. # noqa: E501 """ - self._capital_snake = capital_snake + self.__setitem__( + 'capital_snake', + capital_snake + ) @property def sca_eth_flow_points(self): """Gets the sca_eth_flow_points of this Capitalization. # noqa: E501 - :return: The sca_eth_flow_points of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The sca_eth_flow_points of this Capitalization. # noqa: E501 """ - return self._sca_eth_flow_points + return self._data_store.get('sca_eth_flow_points') @sca_eth_flow_points.setter - def sca_eth_flow_points(self, sca_eth_flow_points): + def sca_eth_flow_points( + self, sca_eth_flow_points): """Sets the sca_eth_flow_points of this Capitalization. - :param sca_eth_flow_points: The sca_eth_flow_points of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The sca_eth_flow_points of this Capitalization. # noqa: E501 """ - self._sca_eth_flow_points = sca_eth_flow_points + self.__setitem__( + 'sca_eth_flow_points', + sca_eth_flow_points + ) @property def att_name(self): @@ -183,46 +293,30 @@ def att_name(self): Name of the pet # noqa: E501 - :return: The att_name of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The att_name of this Capitalization. # noqa: E501 """ - return self._att_name + return self._data_store.get('att_name') @att_name.setter - def att_name(self, att_name): + def att_name( + self, att_name): """Sets the att_name of this Capitalization. Name of the pet # noqa: E501 - :param att_name: The att_name of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The att_name of this Capitalization. # noqa: E501 """ - self._att_name = att_name + self.__setitem__( + 'att_name', + att_name + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/cat.py b/samples/client/petstore/python-asyncio/petstore_api/models/cat.py index c5c87a6b1118..49bec13ed39e 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/cat.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/cat.py @@ -15,8 +15,27 @@ import six +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) -class Cat(object): + +class Cat(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,195 @@ class Cat(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'declawed': 'bool' + 'class_name': [str], # noqa: E501 + 'color': [str], # noqa: E501 + 'declawed': [bool] # noqa: E501 } - attribute_map = { - 'declawed': 'declawed' + 'class_name': 'className', # noqa: E501 + 'color': 'color', # noqa: E501 + 'declawed': 'declawed' # noqa: E501 } - def __init__(self, declawed=None): # noqa: E501 - """Cat - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, class_name, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Cat - a model defined in OpenAPI + + Args: + class_name (str): + + 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 False + _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 + _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. + declawed (bool): [optional] # noqa: E501 + color (str): [optional] if omitted the server will use the default value of 'red' # noqa: E501 + """ - self._declawed = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + # assign using .var_name to check against nullable and enums + self.class_name = class_name + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def class_name(self): + """Gets the class_name of this Cat. # noqa: E501 + + + Returns: + (str): The class_name of this Cat. # noqa: E501 + """ + return self._data_store.get('class_name') + + @class_name.setter + def class_name( + self, class_name): + """Sets the class_name of this Cat. + + + Returns: + (str): The class_name of this Cat. # noqa: E501 + """ + if class_name is None: + raise ApiValueError("Invalid value for `class_name`, must not be `None`") # noqa: E501 - if declawed is not None: - self.declawed = declawed + self.__setitem__( + 'class_name', + class_name + ) + + @property + def color(self): + """Gets the color of this Cat. # noqa: E501 + + + Returns: + (str): The color of this Cat. # noqa: E501 + """ + return self._data_store.get('color') + + @color.setter + def color( + self, color): + """Sets the color of this Cat. + + + Returns: + (str): The color of this Cat. # noqa: E501 + """ + + self.__setitem__( + 'color', + color + ) @property def declawed(self): """Gets the declawed of this Cat. # noqa: E501 - :return: The declawed of this Cat. # noqa: E501 - :rtype: bool + Returns: + (bool): The declawed of this Cat. # noqa: E501 """ - return self._declawed + return self._data_store.get('declawed') @declawed.setter - def declawed(self, declawed): + def declawed( + self, declawed): """Sets the declawed of this Cat. - :param declawed: The declawed of this Cat. # noqa: E501 - :type: bool + Returns: + (bool): The declawed of this Cat. # noqa: E501 """ - self._declawed = declawed + self.__setitem__( + 'declawed', + declawed + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/category.py b/samples/client/petstore/python-asyncio/petstore_api/models/category.py index 5b2f79eaec8d..28b9f6ada0fa 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/category.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/category.py @@ -15,8 +15,27 @@ import six - -class Category(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Category(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,97 +46,167 @@ class Category(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'id': 'int', - 'name': 'str' + 'id': [int], # noqa: E501 + 'name': [str] # noqa: E501 } - attribute_map = { - 'id': 'id', - 'name': 'name' + 'id': 'id', # noqa: E501 + 'name': 'name' # noqa: E501 } - def __init__(self, id=None, name='default-name'): # noqa: E501 - """Category - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, name='default-name', _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Category - a model defined in OpenAPI + + Args: + name (str): defaults to 'default-name', must be one of ['default-name'] # noqa: E501 + + 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 False + _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 + _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. + id (int): [optional] # noqa: E501 + """ - self._id = None - self._name = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration - if id is not None: - self.id = id + # assign using .var_name to check against nullable and enums self.name = name + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def id(self): """Gets the id of this Category. # noqa: E501 - :return: The id of this Category. # noqa: E501 - :rtype: int + Returns: + (int): The id of this Category. # noqa: E501 """ - return self._id + return self._data_store.get('id') @id.setter - def id(self, id): + def id( + self, id): """Sets the id of this Category. - :param id: The id of this Category. # noqa: E501 - :type: int + Returns: + (int): The id of this Category. # noqa: E501 """ - self._id = id + self.__setitem__( + 'id', + id + ) @property def name(self): """Gets the name of this Category. # noqa: E501 - :return: The name of this Category. # noqa: E501 - :rtype: str + Returns: + (str): The name of this Category. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this Category. - :param name: The name of this Category. # noqa: E501 - :type: str + Returns: + (str): The name of this Category. # noqa: E501 """ if name is None: - raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `name`, must not be `None`") # noqa: E501 - self._name = name + self.__setitem__( + 'name', + name + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/class_model.py b/samples/client/petstore/python-asyncio/petstore_api/models/class_model.py index e207ba41ec92..d665edf7efd5 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/class_model.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/class_model.py @@ -15,8 +15,27 @@ import six - -class ClassModel(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ClassModel(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class ClassModel(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - '_class': 'str' + '_class': [str] # noqa: E501 } - attribute_map = { - '_class': '_class' + '_class': '_class' # noqa: E501 } - def __init__(self, _class=None): # noqa: E501 - """ClassModel - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ClassModel - a model defined in OpenAPI - self.__class = None - self.discriminator = None - if _class is not None: - self._class = _class + + 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 False + _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 + _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. + _class (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def _class(self): """Gets the _class of this ClassModel. # noqa: E501 - :return: The _class of this ClassModel. # noqa: E501 - :rtype: str + Returns: + (str): The _class of this ClassModel. # noqa: E501 """ - return self.__class + return self._data_store.get('_class') @_class.setter - def _class(self, _class): + def _class( + self, _class): """Sets the _class of this ClassModel. - :param _class: The _class of this ClassModel. # noqa: E501 - :type: str + Returns: + (str): The _class of this ClassModel. # noqa: E501 """ - self.__class = _class + self.__setitem__( + '_class', + _class + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/client.py b/samples/client/petstore/python-asyncio/petstore_api/models/client.py index e742468e7763..ea315bc1cadd 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/client.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/client.py @@ -15,8 +15,27 @@ import six - -class Client(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Client(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class Client(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'client': 'str' + 'client': [str] # noqa: E501 } - attribute_map = { - 'client': 'client' + 'client': 'client' # noqa: E501 } - def __init__(self, client=None): # noqa: E501 - """Client - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Client - a model defined in OpenAPI - self._client = None - self.discriminator = None - if client is not None: - self.client = client + + 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 False + _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 + _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. + client (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def client(self): """Gets the client of this Client. # noqa: E501 - :return: The client of this Client. # noqa: E501 - :rtype: str + Returns: + (str): The client of this Client. # noqa: E501 """ - return self._client + return self._data_store.get('client') @client.setter - def client(self, client): + def client( + self, client): """Sets the client of this Client. - :param client: The client of this Client. # noqa: E501 - :type: str + Returns: + (str): The client of this Client. # noqa: E501 """ - self._client = client + self.__setitem__( + 'client', + client + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/dog.py b/samples/client/petstore/python-asyncio/petstore_api/models/dog.py index c2bc8f745d15..0febcbab94ec 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/dog.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/dog.py @@ -15,8 +15,27 @@ import six +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) -class Dog(object): + +class Dog(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,195 @@ class Dog(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'breed': 'str' + 'class_name': [str], # noqa: E501 + 'color': [str], # noqa: E501 + 'breed': [str] # noqa: E501 } - attribute_map = { - 'breed': 'breed' + 'class_name': 'className', # noqa: E501 + 'color': 'color', # noqa: E501 + 'breed': 'breed' # noqa: E501 } - def __init__(self, breed=None): # noqa: E501 - """Dog - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, class_name, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Dog - a model defined in OpenAPI + + Args: + class_name (str): + + 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 False + _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 + _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. + breed (str): [optional] # noqa: E501 + color (str): [optional] if omitted the server will use the default value of 'red' # noqa: E501 + """ - self._breed = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + # assign using .var_name to check against nullable and enums + self.class_name = class_name + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def class_name(self): + """Gets the class_name of this Dog. # noqa: E501 + + + Returns: + (str): The class_name of this Dog. # noqa: E501 + """ + return self._data_store.get('class_name') + + @class_name.setter + def class_name( + self, class_name): + """Sets the class_name of this Dog. + + + Returns: + (str): The class_name of this Dog. # noqa: E501 + """ + if class_name is None: + raise ApiValueError("Invalid value for `class_name`, must not be `None`") # noqa: E501 - if breed is not None: - self.breed = breed + self.__setitem__( + 'class_name', + class_name + ) + + @property + def color(self): + """Gets the color of this Dog. # noqa: E501 + + + Returns: + (str): The color of this Dog. # noqa: E501 + """ + return self._data_store.get('color') + + @color.setter + def color( + self, color): + """Sets the color of this Dog. + + + Returns: + (str): The color of this Dog. # noqa: E501 + """ + + self.__setitem__( + 'color', + color + ) @property def breed(self): """Gets the breed of this Dog. # noqa: E501 - :return: The breed of this Dog. # noqa: E501 - :rtype: str + Returns: + (str): The breed of this Dog. # noqa: E501 """ - return self._breed + return self._data_store.get('breed') @breed.setter - def breed(self, breed): + def breed( + self, breed): """Sets the breed of this Dog. - :param breed: The breed of this Dog. # noqa: E501 - :type: str + Returns: + (str): The breed of this Dog. # noqa: E501 """ - self._breed = breed + self.__setitem__( + 'breed', + breed + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/enum_arrays.py b/samples/client/petstore/python-asyncio/petstore_api/models/enum_arrays.py index df4363c356c3..88e4f0a20751 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/enum_arrays.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/enum_arrays.py @@ -15,8 +15,27 @@ import six - -class EnumArrays(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class EnumArrays(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,109 +46,176 @@ class EnumArrays(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'just_symbol': 'str', - 'array_enum': 'list[str]' + 'just_symbol': [str], # noqa: E501 + 'array_enum': [[(str,)]] # noqa: E501 } - attribute_map = { - 'just_symbol': 'just_symbol', - 'array_enum': 'array_enum' + 'just_symbol': 'just_symbol', # noqa: E501 + 'array_enum': 'array_enum' # noqa: E501 } - def __init__(self, just_symbol=None, array_enum=None): # noqa: E501 - """EnumArrays - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """EnumArrays - 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 False + _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 + _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. + just_symbol (str): [optional] # noqa: E501 + array_enum ([(str,)]): [optional] # noqa: E501 + """ - self._just_symbol = None - self._array_enum = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) - if just_symbol is not None: - self.just_symbol = just_symbol - if array_enum is not None: - self.array_enum = array_enum + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def just_symbol(self): """Gets the just_symbol of this EnumArrays. # noqa: E501 - :return: The just_symbol of this EnumArrays. # noqa: E501 - :rtype: str + Returns: + (str): The just_symbol of this EnumArrays. # noqa: E501 """ - return self._just_symbol + return self._data_store.get('just_symbol') @just_symbol.setter - def just_symbol(self, just_symbol): + def just_symbol( + self, just_symbol): """Sets the just_symbol of this EnumArrays. - :param just_symbol: The just_symbol of this EnumArrays. # noqa: E501 - :type: str + Returns: + (str): The just_symbol of this EnumArrays. # noqa: E501 """ allowed_values = [">=", "$"] # noqa: E501 if just_symbol not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `just_symbol` ({0}), must be one of {1}" # noqa: E501 .format(just_symbol, allowed_values) ) - self._just_symbol = just_symbol + self.__setitem__( + 'just_symbol', + just_symbol + ) @property def array_enum(self): """Gets the array_enum of this EnumArrays. # noqa: E501 - :return: The array_enum of this EnumArrays. # noqa: E501 - :rtype: list[str] + Returns: + ([(str,)]): The array_enum of this EnumArrays. # noqa: E501 """ - return self._array_enum + return self._data_store.get('array_enum') @array_enum.setter - def array_enum(self, array_enum): + def array_enum( + self, array_enum): """Sets the array_enum of this EnumArrays. - :param array_enum: The array_enum of this EnumArrays. # noqa: E501 - :type: list[str] + Returns: + ([(str,)]): The array_enum of this EnumArrays. # noqa: E501 """ allowed_values = ["fish", "crab"] # noqa: E501 if not set(array_enum).issubset(set(allowed_values)): - raise ValueError( + raise ApiValueError( "Invalid values for `array_enum` [{0}], must be a subset of [{1}]" # noqa: E501 .format(", ".join(map(str, set(array_enum) - set(allowed_values))), # noqa: E501 ", ".join(map(str, allowed_values))) ) - self._array_enum = array_enum + self.__setitem__( + 'array_enum', + array_enum + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/enum_class.py b/samples/client/petstore/python-asyncio/petstore_api/models/enum_class.py index 182197d8aa6e..67731827fc1c 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/enum_class.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/enum_class.py @@ -15,8 +15,27 @@ import six - -class EnumClass(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class EnumClass(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -34,42 +53,107 @@ class EnumClass(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { } - attribute_map = { } - def __init__(self): # noqa: E501 - """EnumClass - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """EnumClass - 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 False + _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 + _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. + """ + + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/enum_test.py b/samples/client/petstore/python-asyncio/petstore_api/models/enum_test.py index 0fd60c4a351d..c229da414951 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/enum_test.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/enum_test.py @@ -15,8 +15,28 @@ import six - -class EnumTest(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.outer_enum import OuterEnum + + +class EnumTest(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,199 +47,275 @@ class EnumTest(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'enum_string': 'str', - 'enum_string_required': 'str', - 'enum_integer': 'int', - 'enum_number': 'float', - 'outer_enum': 'OuterEnum' + 'enum_string': [str], # noqa: E501 + 'enum_string_required': [str], # noqa: E501 + 'enum_integer': [int], # noqa: E501 + 'enum_number': [float], # noqa: E501 + 'outer_enum': [OuterEnum] # noqa: E501 } - attribute_map = { - 'enum_string': 'enum_string', - 'enum_string_required': 'enum_string_required', - 'enum_integer': 'enum_integer', - 'enum_number': 'enum_number', - 'outer_enum': 'outerEnum' + 'enum_string': 'enum_string', # noqa: E501 + 'enum_string_required': 'enum_string_required', # noqa: E501 + 'enum_integer': 'enum_integer', # noqa: E501 + 'enum_number': 'enum_number', # noqa: E501 + 'outer_enum': 'outerEnum' # noqa: E501 } - def __init__(self, enum_string=None, enum_string_required=None, enum_integer=None, enum_number=None, outer_enum=None): # noqa: E501 - """EnumTest - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, enum_string_required, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """EnumTest - a model defined in OpenAPI + + Args: + enum_string_required (str): + + 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 False + _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 + _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. + enum_string (str): [optional] # noqa: E501 + enum_integer (int): [optional] # noqa: E501 + enum_number (float): [optional] # noqa: E501 + outer_enum (OuterEnum): [optional] # noqa: E501 + """ - self._enum_string = None - self._enum_string_required = None - self._enum_integer = None - self._enum_number = None - self._outer_enum = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration - if enum_string is not None: - self.enum_string = enum_string + # assign using .var_name to check against nullable and enums self.enum_string_required = enum_string_required - if enum_integer is not None: - self.enum_integer = enum_integer - if enum_number is not None: - self.enum_number = enum_number - if outer_enum is not None: - self.outer_enum = outer_enum + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def enum_string(self): """Gets the enum_string of this EnumTest. # noqa: E501 - :return: The enum_string of this EnumTest. # noqa: E501 - :rtype: str + Returns: + (str): The enum_string of this EnumTest. # noqa: E501 """ - return self._enum_string + return self._data_store.get('enum_string') @enum_string.setter - def enum_string(self, enum_string): + def enum_string( + self, enum_string): """Sets the enum_string of this EnumTest. - :param enum_string: The enum_string of this EnumTest. # noqa: E501 - :type: str + Returns: + (str): The enum_string of this EnumTest. # noqa: E501 """ allowed_values = ["UPPER", "lower", ""] # noqa: E501 if enum_string not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `enum_string` ({0}), must be one of {1}" # noqa: E501 .format(enum_string, allowed_values) ) - self._enum_string = enum_string + self.__setitem__( + 'enum_string', + enum_string + ) @property def enum_string_required(self): """Gets the enum_string_required of this EnumTest. # noqa: E501 - :return: The enum_string_required of this EnumTest. # noqa: E501 - :rtype: str + Returns: + (str): The enum_string_required of this EnumTest. # noqa: E501 """ - return self._enum_string_required + return self._data_store.get('enum_string_required') @enum_string_required.setter - def enum_string_required(self, enum_string_required): + def enum_string_required( + self, enum_string_required): """Sets the enum_string_required of this EnumTest. - :param enum_string_required: The enum_string_required of this EnumTest. # noqa: E501 - :type: str + Returns: + (str): The enum_string_required of this EnumTest. # noqa: E501 """ if enum_string_required is None: - raise ValueError("Invalid value for `enum_string_required`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `enum_string_required`, must not be `None`") # noqa: E501 allowed_values = ["UPPER", "lower", ""] # noqa: E501 if enum_string_required not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `enum_string_required` ({0}), must be one of {1}" # noqa: E501 .format(enum_string_required, allowed_values) ) - self._enum_string_required = enum_string_required + self.__setitem__( + 'enum_string_required', + enum_string_required + ) @property def enum_integer(self): """Gets the enum_integer of this EnumTest. # noqa: E501 - :return: The enum_integer of this EnumTest. # noqa: E501 - :rtype: int + Returns: + (int): The enum_integer of this EnumTest. # noqa: E501 """ - return self._enum_integer + return self._data_store.get('enum_integer') @enum_integer.setter - def enum_integer(self, enum_integer): + def enum_integer( + self, enum_integer): """Sets the enum_integer of this EnumTest. - :param enum_integer: The enum_integer of this EnumTest. # noqa: E501 - :type: int + Returns: + (int): The enum_integer of this EnumTest. # noqa: E501 """ allowed_values = [1, -1] # noqa: E501 if enum_integer not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `enum_integer` ({0}), must be one of {1}" # noqa: E501 .format(enum_integer, allowed_values) ) - self._enum_integer = enum_integer + self.__setitem__( + 'enum_integer', + enum_integer + ) @property def enum_number(self): """Gets the enum_number of this EnumTest. # noqa: E501 - :return: The enum_number of this EnumTest. # noqa: E501 - :rtype: float + Returns: + (float): The enum_number of this EnumTest. # noqa: E501 """ - return self._enum_number + return self._data_store.get('enum_number') @enum_number.setter - def enum_number(self, enum_number): + def enum_number( + self, enum_number): """Sets the enum_number of this EnumTest. - :param enum_number: The enum_number of this EnumTest. # noqa: E501 - :type: float + Returns: + (float): The enum_number of this EnumTest. # noqa: E501 """ allowed_values = [1.1, -1.2] # noqa: E501 if enum_number not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `enum_number` ({0}), must be one of {1}" # noqa: E501 .format(enum_number, allowed_values) ) - self._enum_number = enum_number + self.__setitem__( + 'enum_number', + enum_number + ) @property def outer_enum(self): """Gets the outer_enum of this EnumTest. # noqa: E501 - :return: The outer_enum of this EnumTest. # noqa: E501 - :rtype: OuterEnum + Returns: + (OuterEnum): The outer_enum of this EnumTest. # noqa: E501 """ - return self._outer_enum + return self._data_store.get('outer_enum') @outer_enum.setter - def outer_enum(self, outer_enum): + def outer_enum( + self, outer_enum): """Sets the outer_enum of this EnumTest. - :param outer_enum: The outer_enum of this EnumTest. # noqa: E501 - :type: OuterEnum + Returns: + (OuterEnum): The outer_enum of this EnumTest. # noqa: E501 """ - self._outer_enum = outer_enum + self.__setitem__( + 'outer_enum', + outer_enum + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/file.py b/samples/client/petstore/python-asyncio/petstore_api/models/file.py index 34d77c3b4cf8..3fdc580d4198 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/file.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/file.py @@ -15,8 +15,27 @@ import six - -class File(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class File(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,25 +46,106 @@ class File(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'source_uri': 'str' + 'source_uri': [str] # noqa: E501 } - attribute_map = { - 'source_uri': 'sourceURI' + 'source_uri': 'sourceURI' # noqa: E501 } - def __init__(self, source_uri=None): # noqa: E501 - """File - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """File - a model defined in OpenAPI - self._source_uri = None - self.discriminator = None - if source_uri is not None: - self.source_uri = source_uri + + 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 False + _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 + _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. + source_uri (str): Test capitalization. [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def source_uri(self): @@ -53,46 +153,30 @@ def source_uri(self): Test capitalization # noqa: E501 - :return: The source_uri of this File. # noqa: E501 - :rtype: str + Returns: + (str): The source_uri of this File. # noqa: E501 """ - return self._source_uri + return self._data_store.get('source_uri') @source_uri.setter - def source_uri(self, source_uri): + def source_uri( + self, source_uri): """Sets the source_uri of this File. Test capitalization # noqa: E501 - :param source_uri: The source_uri of this File. # noqa: E501 - :type: str + Returns: + (str): The source_uri of this File. # noqa: E501 """ - self._source_uri = source_uri + self.__setitem__( + 'source_uri', + source_uri + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/file_schema_test_class.py b/samples/client/petstore/python-asyncio/petstore_api/models/file_schema_test_class.py index 026822dee749..ed77661a5bfe 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/file_schema_test_class.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/file_schema_test_class.py @@ -15,8 +15,28 @@ import six - -class FileSchemaTestClass(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.file import File + + +class FileSchemaTestClass(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +47,163 @@ class FileSchemaTestClass(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'file': 'File', - 'files': 'list[File]' + 'file': [File], # noqa: E501 + 'files': [[(File,)]] # noqa: E501 } - attribute_map = { - 'file': 'file', - 'files': 'files' + 'file': 'file', # noqa: E501 + 'files': 'files' # noqa: E501 } - def __init__(self, file=None, files=None): # noqa: E501 - """FileSchemaTestClass - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """FileSchemaTestClass - 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 False + _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 + _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. + file (File): [optional] # noqa: E501 + files ([(File,)]): [optional] # noqa: E501 + """ - self._file = None - self._files = None + self._data_store = {} self.discriminator = None - - if file is not None: - self.file = file - if files is not None: - self.files = files + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def file(self): """Gets the file of this FileSchemaTestClass. # noqa: E501 - :return: The file of this FileSchemaTestClass. # noqa: E501 - :rtype: File + Returns: + (File): The file of this FileSchemaTestClass. # noqa: E501 """ - return self._file + return self._data_store.get('file') @file.setter - def file(self, file): + def file( + self, file): """Sets the file of this FileSchemaTestClass. - :param file: The file of this FileSchemaTestClass. # noqa: E501 - :type: File + Returns: + (File): The file of this FileSchemaTestClass. # noqa: E501 """ - self._file = file + self.__setitem__( + 'file', + file + ) @property def files(self): """Gets the files of this FileSchemaTestClass. # noqa: E501 - :return: The files of this FileSchemaTestClass. # noqa: E501 - :rtype: list[File] + Returns: + ([(File,)]): The files of this FileSchemaTestClass. # noqa: E501 """ - return self._files + return self._data_store.get('files') @files.setter - def files(self, files): + def files( + self, files): """Sets the files of this FileSchemaTestClass. - :param files: The files of this FileSchemaTestClass. # noqa: E501 - :type: list[File] + Returns: + ([(File,)]): The files of this FileSchemaTestClass. # noqa: E501 """ - self._files = files + self.__setitem__( + 'files', + files + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/format_test.py b/samples/client/petstore/python-asyncio/petstore_api/models/format_test.py index c7703d166071..e7edaf2d3df6 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/format_test.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/format_test.py @@ -15,8 +15,27 @@ import six - -class FormatTest(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class FormatTest(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,414 +46,512 @@ class FormatTest(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'integer': 'int', - 'int32': 'int', - 'int64': 'int', - 'number': 'float', - 'float': 'float', - 'double': 'float', - 'string': 'str', - 'byte': 'str', - 'binary': 'file', - 'date': 'date', - 'date_time': 'datetime', - 'uuid': 'str', - 'password': 'str' + 'integer': [int], # noqa: E501 + 'int32': [int], # noqa: E501 + 'int64': [int], # noqa: E501 + 'number': [float], # noqa: E501 + 'float': [float], # noqa: E501 + 'double': [float], # noqa: E501 + 'string': [str], # noqa: E501 + 'byte': [str], # noqa: E501 + 'binary': [file_type], # noqa: E501 + 'date': [date], # noqa: E501 + 'date_time': [datetime], # noqa: E501 + 'uuid': [str], # noqa: E501 + 'password': [str] # noqa: E501 } - attribute_map = { - 'integer': 'integer', - 'int32': 'int32', - 'int64': 'int64', - 'number': 'number', - 'float': 'float', - 'double': 'double', - 'string': 'string', - 'byte': 'byte', - 'binary': 'binary', - 'date': 'date', - 'date_time': 'dateTime', - 'uuid': 'uuid', - 'password': 'password' + 'integer': 'integer', # noqa: E501 + 'int32': 'int32', # noqa: E501 + 'int64': 'int64', # noqa: E501 + 'number': 'number', # noqa: E501 + 'float': 'float', # noqa: E501 + 'double': 'double', # noqa: E501 + 'string': 'string', # noqa: E501 + 'byte': 'byte', # noqa: E501 + 'binary': 'binary', # noqa: E501 + 'date': 'date', # noqa: E501 + 'date_time': 'dateTime', # noqa: E501 + 'uuid': 'uuid', # noqa: E501 + 'password': 'password' # noqa: E501 } - def __init__(self, integer=None, int32=None, int64=None, number=None, float=None, double=None, string=None, byte=None, binary=None, date=None, date_time=None, uuid=None, password=None): # noqa: E501 - """FormatTest - a model defined in OpenAPI""" # noqa: E501 - - self._integer = None - self._int32 = None - self._int64 = None - self._number = None - self._float = None - self._double = None - self._string = None - self._byte = None - self._binary = None - self._date = None - self._date_time = None - self._uuid = None - self._password = None + def __init__(self, number, byte, date, password, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """FormatTest - a model defined in OpenAPI + + Args: + number (float): + byte (str): + date (date): + password (str): + + 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 False + _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 + _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. + integer (int): [optional] # noqa: E501 + int32 (int): [optional] # noqa: E501 + int64 (int): [optional] # noqa: E501 + float (float): [optional] # noqa: E501 + double (float): [optional] # noqa: E501 + string (str): [optional] # noqa: E501 + binary (file_type): [optional] # noqa: E501 + date_time (datetime): [optional] # noqa: E501 + uuid (str): [optional] # noqa: E501 + """ + + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration - if integer is not None: - self.integer = integer - if int32 is not None: - self.int32 = int32 - if int64 is not None: - self.int64 = int64 + # assign using .var_name to check against nullable and enums self.number = number - if float is not None: - self.float = float - if double is not None: - self.double = double - if string is not None: - self.string = string self.byte = byte - if binary is not None: - self.binary = binary self.date = date - if date_time is not None: - self.date_time = date_time - if uuid is not None: - self.uuid = uuid self.password = password + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def integer(self): """Gets the integer of this FormatTest. # noqa: E501 - :return: The integer of this FormatTest. # noqa: E501 - :rtype: int + Returns: + (int): The integer of this FormatTest. # noqa: E501 """ - return self._integer + return self._data_store.get('integer') @integer.setter - def integer(self, integer): + def integer( + self, integer): """Sets the integer of this FormatTest. - :param integer: The integer of this FormatTest. # noqa: E501 - :type: int + Returns: + (int): The integer of this FormatTest. # noqa: E501 """ if integer is not None and integer > 100: # noqa: E501 - raise ValueError("Invalid value for `integer`, must be a value less than or equal to `100`") # noqa: E501 + raise ApiValueError("Invalid value for `integer`, must be a value less than or equal to `100`") # noqa: E501 if integer is not None and integer < 10: # noqa: E501 - raise ValueError("Invalid value for `integer`, must be a value greater than or equal to `10`") # noqa: E501 + raise ApiValueError("Invalid value for `integer`, must be a value greater than or equal to `10`") # noqa: E501 - self._integer = integer + self.__setitem__( + 'integer', + integer + ) @property def int32(self): """Gets the int32 of this FormatTest. # noqa: E501 - :return: The int32 of this FormatTest. # noqa: E501 - :rtype: int + Returns: + (int): The int32 of this FormatTest. # noqa: E501 """ - return self._int32 + return self._data_store.get('int32') @int32.setter - def int32(self, int32): + def int32( + self, int32): """Sets the int32 of this FormatTest. - :param int32: The int32 of this FormatTest. # noqa: E501 - :type: int + Returns: + (int): The int32 of this FormatTest. # noqa: E501 """ if int32 is not None and int32 > 200: # noqa: E501 - raise ValueError("Invalid value for `int32`, must be a value less than or equal to `200`") # noqa: E501 + raise ApiValueError("Invalid value for `int32`, must be a value less than or equal to `200`") # noqa: E501 if int32 is not None and int32 < 20: # noqa: E501 - raise ValueError("Invalid value for `int32`, must be a value greater than or equal to `20`") # noqa: E501 + raise ApiValueError("Invalid value for `int32`, must be a value greater than or equal to `20`") # noqa: E501 - self._int32 = int32 + self.__setitem__( + 'int32', + int32 + ) @property def int64(self): """Gets the int64 of this FormatTest. # noqa: E501 - :return: The int64 of this FormatTest. # noqa: E501 - :rtype: int + Returns: + (int): The int64 of this FormatTest. # noqa: E501 """ - return self._int64 + return self._data_store.get('int64') @int64.setter - def int64(self, int64): + def int64( + self, int64): """Sets the int64 of this FormatTest. - :param int64: The int64 of this FormatTest. # noqa: E501 - :type: int + Returns: + (int): The int64 of this FormatTest. # noqa: E501 """ - self._int64 = int64 + self.__setitem__( + 'int64', + int64 + ) @property def number(self): """Gets the number of this FormatTest. # noqa: E501 - :return: The number of this FormatTest. # noqa: E501 - :rtype: float + Returns: + (float): The number of this FormatTest. # noqa: E501 """ - return self._number + return self._data_store.get('number') @number.setter - def number(self, number): + def number( + self, number): """Sets the number of this FormatTest. - :param number: The number of this FormatTest. # noqa: E501 - :type: float + Returns: + (float): The number of this FormatTest. # noqa: E501 """ if number is None: - raise ValueError("Invalid value for `number`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `number`, must not be `None`") # noqa: E501 if number is not None and number > 543.2: # noqa: E501 - raise ValueError("Invalid value for `number`, must be a value less than or equal to `543.2`") # noqa: E501 + raise ApiValueError("Invalid value for `number`, must be a value less than or equal to `543.2`") # noqa: E501 if number is not None and number < 32.1: # noqa: E501 - raise ValueError("Invalid value for `number`, must be a value greater than or equal to `32.1`") # noqa: E501 + raise ApiValueError("Invalid value for `number`, must be a value greater than or equal to `32.1`") # noqa: E501 - self._number = number + self.__setitem__( + 'number', + number + ) @property def float(self): """Gets the float of this FormatTest. # noqa: E501 - :return: The float of this FormatTest. # noqa: E501 - :rtype: float + Returns: + (float): The float of this FormatTest. # noqa: E501 """ - return self._float + return self._data_store.get('float') @float.setter - def float(self, float): + def float( + self, float): """Sets the float of this FormatTest. - :param float: The float of this FormatTest. # noqa: E501 - :type: float + Returns: + (float): The float of this FormatTest. # noqa: E501 """ if float is not None and float > 987.6: # noqa: E501 - raise ValueError("Invalid value for `float`, must be a value less than or equal to `987.6`") # noqa: E501 + raise ApiValueError("Invalid value for `float`, must be a value less than or equal to `987.6`") # noqa: E501 if float is not None and float < 54.3: # noqa: E501 - raise ValueError("Invalid value for `float`, must be a value greater than or equal to `54.3`") # noqa: E501 + raise ApiValueError("Invalid value for `float`, must be a value greater than or equal to `54.3`") # noqa: E501 - self._float = float + self.__setitem__( + 'float', + float + ) @property def double(self): """Gets the double of this FormatTest. # noqa: E501 - :return: The double of this FormatTest. # noqa: E501 - :rtype: float + Returns: + (float): The double of this FormatTest. # noqa: E501 """ - return self._double + return self._data_store.get('double') @double.setter - def double(self, double): + def double( + self, double): """Sets the double of this FormatTest. - :param double: The double of this FormatTest. # noqa: E501 - :type: float + Returns: + (float): The double of this FormatTest. # noqa: E501 """ if double is not None and double > 123.4: # noqa: E501 - raise ValueError("Invalid value for `double`, must be a value less than or equal to `123.4`") # noqa: E501 + raise ApiValueError("Invalid value for `double`, must be a value less than or equal to `123.4`") # noqa: E501 if double is not None and double < 67.8: # noqa: E501 - raise ValueError("Invalid value for `double`, must be a value greater than or equal to `67.8`") # noqa: E501 + raise ApiValueError("Invalid value for `double`, must be a value greater than or equal to `67.8`") # noqa: E501 - self._double = double + self.__setitem__( + 'double', + double + ) @property def string(self): """Gets the string of this FormatTest. # noqa: E501 - :return: The string of this FormatTest. # noqa: E501 - :rtype: str + Returns: + (str): The string of this FormatTest. # noqa: E501 """ - return self._string + return self._data_store.get('string') @string.setter - def string(self, string): + def string( + self, string): """Sets the string of this FormatTest. - :param string: The string of this FormatTest. # noqa: E501 - :type: str + Returns: + (str): The string of this FormatTest. # noqa: E501 """ - if string is not None and not re.search(r'[a-z]', string, flags=re.IGNORECASE): # noqa: E501 - raise ValueError(r"Invalid value for `string`, must be a follow pattern or equal to `/[a-z]/i`") # noqa: E501 + if string is not None and not re.search(r'', string): # noqa: E501 + raise ApiValueError(r"Invalid value for `string`, must be a follow pattern or equal to `/[a-z]/i`") # noqa: E501 - self._string = string + self.__setitem__( + 'string', + string + ) @property def byte(self): """Gets the byte of this FormatTest. # noqa: E501 - :return: The byte of this FormatTest. # noqa: E501 - :rtype: str + Returns: + (str): The byte of this FormatTest. # noqa: E501 """ - return self._byte + return self._data_store.get('byte') @byte.setter - def byte(self, byte): + def byte( + self, byte): """Sets the byte of this FormatTest. - :param byte: The byte of this FormatTest. # noqa: E501 - :type: str + Returns: + (str): The byte of this FormatTest. # noqa: E501 """ if byte is None: - raise ValueError("Invalid value for `byte`, must not be `None`") # noqa: E501 - if byte is not None and not re.search(r'^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$', byte): # noqa: E501 - raise ValueError(r"Invalid value for `byte`, must be a follow pattern or equal to `/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/`") # noqa: E501 + raise ApiValueError("Invalid value for `byte`, must not be `None`") # noqa: E501 + if byte is not None and not re.search(r'', byte): # noqa: E501 + raise ApiValueError(r"Invalid value for `byte`, must be a follow pattern or equal to `/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/`") # noqa: E501 - self._byte = byte + self.__setitem__( + 'byte', + byte + ) @property def binary(self): """Gets the binary of this FormatTest. # noqa: E501 - :return: The binary of this FormatTest. # noqa: E501 - :rtype: file + Returns: + (file_type): The binary of this FormatTest. # noqa: E501 """ - return self._binary + return self._data_store.get('binary') @binary.setter - def binary(self, binary): + def binary( + self, binary): """Sets the binary of this FormatTest. - :param binary: The binary of this FormatTest. # noqa: E501 - :type: file + Returns: + (file_type): The binary of this FormatTest. # noqa: E501 """ - self._binary = binary + self.__setitem__( + 'binary', + binary + ) @property def date(self): """Gets the date of this FormatTest. # noqa: E501 - :return: The date of this FormatTest. # noqa: E501 - :rtype: date + Returns: + (date): The date of this FormatTest. # noqa: E501 """ - return self._date + return self._data_store.get('date') @date.setter - def date(self, date): + def date( + self, date): """Sets the date of this FormatTest. - :param date: The date of this FormatTest. # noqa: E501 - :type: date + Returns: + (date): The date of this FormatTest. # noqa: E501 """ if date is None: - raise ValueError("Invalid value for `date`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `date`, must not be `None`") # noqa: E501 - self._date = date + self.__setitem__( + 'date', + date + ) @property def date_time(self): """Gets the date_time of this FormatTest. # noqa: E501 - :return: The date_time of this FormatTest. # noqa: E501 - :rtype: datetime + Returns: + (datetime): The date_time of this FormatTest. # noqa: E501 """ - return self._date_time + return self._data_store.get('date_time') @date_time.setter - def date_time(self, date_time): + def date_time( + self, date_time): """Sets the date_time of this FormatTest. - :param date_time: The date_time of this FormatTest. # noqa: E501 - :type: datetime + Returns: + (datetime): The date_time of this FormatTest. # noqa: E501 """ - self._date_time = date_time + self.__setitem__( + 'date_time', + date_time + ) @property def uuid(self): """Gets the uuid of this FormatTest. # noqa: E501 - :return: The uuid of this FormatTest. # noqa: E501 - :rtype: str + Returns: + (str): The uuid of this FormatTest. # noqa: E501 """ - return self._uuid + return self._data_store.get('uuid') @uuid.setter - def uuid(self, uuid): + def uuid( + self, uuid): """Sets the uuid of this FormatTest. - :param uuid: The uuid of this FormatTest. # noqa: E501 - :type: str + Returns: + (str): The uuid of this FormatTest. # noqa: E501 """ - self._uuid = uuid + self.__setitem__( + 'uuid', + uuid + ) @property def password(self): """Gets the password of this FormatTest. # noqa: E501 - :return: The password of this FormatTest. # noqa: E501 - :rtype: str + Returns: + (str): The password of this FormatTest. # noqa: E501 """ - return self._password + return self._data_store.get('password') @password.setter - def password(self, password): + def password( + self, password): """Sets the password of this FormatTest. - :param password: The password of this FormatTest. # noqa: E501 - :type: str + Returns: + (str): The password of this FormatTest. # noqa: E501 """ if password is None: - raise ValueError("Invalid value for `password`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `password`, must not be `None`") # noqa: E501 if password is not None and len(password) > 64: - raise ValueError("Invalid value for `password`, length must be less than or equal to `64`") # noqa: E501 + raise ApiValueError("Invalid value for `password`, length must be less than or equal to `64`") # noqa: E501 if password is not None and len(password) < 10: - raise ValueError("Invalid value for `password`, length must be greater than or equal to `10`") # noqa: E501 + raise ApiValueError("Invalid value for `password`, length must be greater than or equal to `10`") # noqa: E501 - self._password = password + self.__setitem__( + 'password', + password + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/has_only_read_only.py b/samples/client/petstore/python-asyncio/petstore_api/models/has_only_read_only.py index 41db3ff71958..eeff7da1fbaf 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/has_only_read_only.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/has_only_read_only.py @@ -15,8 +15,27 @@ import six - -class HasOnlyReadOnly(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class HasOnlyReadOnly(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +46,163 @@ class HasOnlyReadOnly(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'bar': 'str', - 'foo': 'str' + 'bar': [str], # noqa: E501 + 'foo': [str] # noqa: E501 } - attribute_map = { - 'bar': 'bar', - 'foo': 'foo' + 'bar': 'bar', # noqa: E501 + 'foo': 'foo' # noqa: E501 } - def __init__(self, bar=None, foo=None): # noqa: E501 - """HasOnlyReadOnly - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """HasOnlyReadOnly - 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 False + _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 + _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. + bar (str): [optional] # noqa: E501 + foo (str): [optional] # noqa: E501 + """ - self._bar = None - self._foo = None + self._data_store = {} self.discriminator = None - - if bar is not None: - self.bar = bar - if foo is not None: - self.foo = foo + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def bar(self): """Gets the bar of this HasOnlyReadOnly. # noqa: E501 - :return: The bar of this HasOnlyReadOnly. # noqa: E501 - :rtype: str + Returns: + (str): The bar of this HasOnlyReadOnly. # noqa: E501 """ - return self._bar + return self._data_store.get('bar') @bar.setter - def bar(self, bar): + def bar( + self, bar): """Sets the bar of this HasOnlyReadOnly. - :param bar: The bar of this HasOnlyReadOnly. # noqa: E501 - :type: str + Returns: + (str): The bar of this HasOnlyReadOnly. # noqa: E501 """ - self._bar = bar + self.__setitem__( + 'bar', + bar + ) @property def foo(self): """Gets the foo of this HasOnlyReadOnly. # noqa: E501 - :return: The foo of this HasOnlyReadOnly. # noqa: E501 - :rtype: str + Returns: + (str): The foo of this HasOnlyReadOnly. # noqa: E501 """ - return self._foo + return self._data_store.get('foo') @foo.setter - def foo(self, foo): + def foo( + self, foo): """Sets the foo of this HasOnlyReadOnly. - :param foo: The foo of this HasOnlyReadOnly. # noqa: E501 - :type: str + Returns: + (str): The foo of this HasOnlyReadOnly. # noqa: E501 """ - self._foo = foo + self.__setitem__( + 'foo', + foo + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/list.py b/samples/client/petstore/python-asyncio/petstore_api/models/list.py index 08e12ad53104..71b3c3ea4033 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/list.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/list.py @@ -15,8 +15,27 @@ import six - -class List(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class List(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class List(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - '_123_list': 'str' + '_123_list': [str] # noqa: E501 } - attribute_map = { - '_123_list': '123-list' + '_123_list': '123-list' # noqa: E501 } - def __init__(self, _123_list=None): # noqa: E501 - """List - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """List - a model defined in OpenAPI - self.__123_list = None - self.discriminator = None - if _123_list is not None: - self._123_list = _123_list + + 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 False + _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 + _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. + _123_list (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def _123_list(self): """Gets the _123_list of this List. # noqa: E501 - :return: The _123_list of this List. # noqa: E501 - :rtype: str + Returns: + (str): The _123_list of this List. # noqa: E501 """ - return self.__123_list + return self._data_store.get('_123_list') @_123_list.setter - def _123_list(self, _123_list): + def _123_list( + self, _123_list): """Sets the _123_list of this List. - :param _123_list: The _123_list of this List. # noqa: E501 - :type: str + Returns: + (str): The _123_list of this List. # noqa: E501 """ - self.__123_list = _123_list + self.__setitem__( + '_123_list', + _123_list + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/map_test.py b/samples/client/petstore/python-asyncio/petstore_api/models/map_test.py index f04bd2cc1421..c846484fb60f 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/map_test.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/map_test.py @@ -15,8 +15,27 @@ import six - -class MapTest(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class MapTest(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,155 +46,226 @@ class MapTest(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'map_map_of_string': 'dict(str, dict(str, str))', - 'map_of_enum_string': 'dict(str, str)', - 'direct_map': 'dict(str, bool)', - 'indirect_map': 'dict(str, bool)' + 'map_map_of_string': [{str: ({str: (str,)},)}], # noqa: E501 + 'map_of_enum_string': [{str: (str,)}], # noqa: E501 + 'direct_map': [{str: (bool,)}], # noqa: E501 + 'indirect_map': [{str: (bool,)}] # noqa: E501 } - attribute_map = { - 'map_map_of_string': 'map_map_of_string', - 'map_of_enum_string': 'map_of_enum_string', - 'direct_map': 'direct_map', - 'indirect_map': 'indirect_map' + 'map_map_of_string': 'map_map_of_string', # noqa: E501 + 'map_of_enum_string': 'map_of_enum_string', # noqa: E501 + 'direct_map': 'direct_map', # noqa: E501 + 'indirect_map': 'indirect_map' # noqa: E501 } - def __init__(self, map_map_of_string=None, map_of_enum_string=None, direct_map=None, indirect_map=None): # noqa: E501 - """MapTest - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """MapTest - 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 False + _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 + _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. + map_map_of_string ({str: ({str: (str,)},)}): [optional] # noqa: E501 + map_of_enum_string ({str: (str,)}): [optional] # noqa: E501 + direct_map ({str: (bool,)}): [optional] # noqa: E501 + indirect_map ({str: (bool,)}): [optional] # noqa: E501 + """ - self._map_map_of_string = None - self._map_of_enum_string = None - self._direct_map = None - self._indirect_map = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) - if map_map_of_string is not None: - self.map_map_of_string = map_map_of_string - if map_of_enum_string is not None: - self.map_of_enum_string = map_of_enum_string - if direct_map is not None: - self.direct_map = direct_map - if indirect_map is not None: - self.indirect_map = indirect_map + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def map_map_of_string(self): """Gets the map_map_of_string of this MapTest. # noqa: E501 - :return: The map_map_of_string of this MapTest. # noqa: E501 - :rtype: dict(str, dict(str, str)) + Returns: + ({str: ({str: (str,)},)}): The map_map_of_string of this MapTest. # noqa: E501 """ - return self._map_map_of_string + return self._data_store.get('map_map_of_string') @map_map_of_string.setter - def map_map_of_string(self, map_map_of_string): + def map_map_of_string( + self, map_map_of_string): """Sets the map_map_of_string of this MapTest. - :param map_map_of_string: The map_map_of_string of this MapTest. # noqa: E501 - :type: dict(str, dict(str, str)) + Returns: + ({str: ({str: (str,)},)}): The map_map_of_string of this MapTest. # noqa: E501 """ - self._map_map_of_string = map_map_of_string + self.__setitem__( + 'map_map_of_string', + map_map_of_string + ) @property def map_of_enum_string(self): """Gets the map_of_enum_string of this MapTest. # noqa: E501 - :return: The map_of_enum_string of this MapTest. # noqa: E501 - :rtype: dict(str, str) + Returns: + ({str: (str,)}): The map_of_enum_string of this MapTest. # noqa: E501 """ - return self._map_of_enum_string + return self._data_store.get('map_of_enum_string') @map_of_enum_string.setter - def map_of_enum_string(self, map_of_enum_string): + def map_of_enum_string( + self, map_of_enum_string): """Sets the map_of_enum_string of this MapTest. - :param map_of_enum_string: The map_of_enum_string of this MapTest. # noqa: E501 - :type: dict(str, str) + Returns: + ({str: (str,)}): The map_of_enum_string of this MapTest. # noqa: E501 """ allowed_values = ["UPPER", "lower"] # noqa: E501 if not set(map_of_enum_string.keys()).issubset(set(allowed_values)): - raise ValueError( + raise ApiValueError( "Invalid keys in `map_of_enum_string` [{0}], must be a subset of [{1}]" # noqa: E501 .format(", ".join(map(str, set(map_of_enum_string.keys()) - set(allowed_values))), # noqa: E501 ", ".join(map(str, allowed_values))) ) - self._map_of_enum_string = map_of_enum_string + self.__setitem__( + 'map_of_enum_string', + map_of_enum_string + ) @property def direct_map(self): """Gets the direct_map of this MapTest. # noqa: E501 - :return: The direct_map of this MapTest. # noqa: E501 - :rtype: dict(str, bool) + Returns: + ({str: (bool,)}): The direct_map of this MapTest. # noqa: E501 """ - return self._direct_map + return self._data_store.get('direct_map') @direct_map.setter - def direct_map(self, direct_map): + def direct_map( + self, direct_map): """Sets the direct_map of this MapTest. - :param direct_map: The direct_map of this MapTest. # noqa: E501 - :type: dict(str, bool) + Returns: + ({str: (bool,)}): The direct_map of this MapTest. # noqa: E501 """ - self._direct_map = direct_map + self.__setitem__( + 'direct_map', + direct_map + ) @property def indirect_map(self): """Gets the indirect_map of this MapTest. # noqa: E501 - :return: The indirect_map of this MapTest. # noqa: E501 - :rtype: dict(str, bool) + Returns: + ({str: (bool,)}): The indirect_map of this MapTest. # noqa: E501 """ - return self._indirect_map + return self._data_store.get('indirect_map') @indirect_map.setter - def indirect_map(self, indirect_map): + def indirect_map( + self, indirect_map): """Sets the indirect_map of this MapTest. - :param indirect_map: The indirect_map of this MapTest. # noqa: E501 - :type: dict(str, bool) + Returns: + ({str: (bool,)}): The indirect_map of this MapTest. # noqa: E501 """ - self._indirect_map = indirect_map + self.__setitem__( + 'indirect_map', + indirect_map + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/mixed_properties_and_additional_properties_class.py b/samples/client/petstore/python-asyncio/petstore_api/models/mixed_properties_and_additional_properties_class.py index ecf67acc5e95..1d61e2c659ff 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/mixed_properties_and_additional_properties_class.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/mixed_properties_and_additional_properties_class.py @@ -15,8 +15,28 @@ import six - -class MixedPropertiesAndAdditionalPropertiesClass(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.animal import Animal + + +class MixedPropertiesAndAdditionalPropertiesClass(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,122 +47,191 @@ class MixedPropertiesAndAdditionalPropertiesClass(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'uuid': 'str', - 'date_time': 'datetime', - 'map': 'dict(str, Animal)' + 'uuid': [str], # noqa: E501 + 'date_time': [datetime], # noqa: E501 + 'map': [{str: (Animal,)}] # noqa: E501 } - attribute_map = { - 'uuid': 'uuid', - 'date_time': 'dateTime', - 'map': 'map' + 'uuid': 'uuid', # noqa: E501 + 'date_time': 'dateTime', # noqa: E501 + 'map': 'map' # noqa: E501 } - def __init__(self, uuid=None, date_time=None, map=None): # noqa: E501 - """MixedPropertiesAndAdditionalPropertiesClass - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """MixedPropertiesAndAdditionalPropertiesClass - 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 False + _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 + _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. + uuid (str): [optional] # noqa: E501 + date_time (datetime): [optional] # noqa: E501 + map ({str: (Animal,)}): [optional] # noqa: E501 + """ - self._uuid = None - self._date_time = None - self._map = None + self._data_store = {} self.discriminator = None - - if uuid is not None: - self.uuid = uuid - if date_time is not None: - self.date_time = date_time - if map is not None: - self.map = map + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def uuid(self): """Gets the uuid of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :return: The uuid of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :rtype: str + Returns: + (str): The uuid of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - return self._uuid + return self._data_store.get('uuid') @uuid.setter - def uuid(self, uuid): + def uuid( + self, uuid): """Sets the uuid of this MixedPropertiesAndAdditionalPropertiesClass. - :param uuid: The uuid of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :type: str + Returns: + (str): The uuid of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - self._uuid = uuid + self.__setitem__( + 'uuid', + uuid + ) @property def date_time(self): """Gets the date_time of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :return: The date_time of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :rtype: datetime + Returns: + (datetime): The date_time of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - return self._date_time + return self._data_store.get('date_time') @date_time.setter - def date_time(self, date_time): + def date_time( + self, date_time): """Sets the date_time of this MixedPropertiesAndAdditionalPropertiesClass. - :param date_time: The date_time of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :type: datetime + Returns: + (datetime): The date_time of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - self._date_time = date_time + self.__setitem__( + 'date_time', + date_time + ) @property def map(self): """Gets the map of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :return: The map of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :rtype: dict(str, Animal) + Returns: + ({str: (Animal,)}): The map of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - return self._map + return self._data_store.get('map') @map.setter - def map(self, map): + def map( + self, map): """Sets the map of this MixedPropertiesAndAdditionalPropertiesClass. - :param map: The map of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :type: dict(str, Animal) + Returns: + ({str: (Animal,)}): The map of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - self._map = map + self.__setitem__( + 'map', + map + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/model200_response.py b/samples/client/petstore/python-asyncio/petstore_api/models/model200_response.py index ec778cdcb74b..e44d7f28022e 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/model200_response.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/model200_response.py @@ -15,8 +15,27 @@ import six - -class Model200Response(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Model200Response(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +46,163 @@ class Model200Response(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'name': 'int', - '_class': 'str' + 'name': [int], # noqa: E501 + '_class': [str] # noqa: E501 } - attribute_map = { - 'name': 'name', - '_class': 'class' + 'name': 'name', # noqa: E501 + '_class': 'class' # noqa: E501 } - def __init__(self, name=None, _class=None): # noqa: E501 - """Model200Response - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Model200Response - 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 False + _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 + _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. + name (int): [optional] # noqa: E501 + _class (str): [optional] # noqa: E501 + """ - self._name = None - self.__class = None + self._data_store = {} self.discriminator = None - - if name is not None: - self.name = name - if _class is not None: - self._class = _class + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def name(self): """Gets the name of this Model200Response. # noqa: E501 - :return: The name of this Model200Response. # noqa: E501 - :rtype: int + Returns: + (int): The name of this Model200Response. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this Model200Response. - :param name: The name of this Model200Response. # noqa: E501 - :type: int + Returns: + (int): The name of this Model200Response. # noqa: E501 """ - self._name = name + self.__setitem__( + 'name', + name + ) @property def _class(self): """Gets the _class of this Model200Response. # noqa: E501 - :return: The _class of this Model200Response. # noqa: E501 - :rtype: str + Returns: + (str): The _class of this Model200Response. # noqa: E501 """ - return self.__class + return self._data_store.get('_class') @_class.setter - def _class(self, _class): + def _class( + self, _class): """Sets the _class of this Model200Response. - :param _class: The _class of this Model200Response. # noqa: E501 - :type: str + Returns: + (str): The _class of this Model200Response. # noqa: E501 """ - self.__class = _class + self.__setitem__( + '_class', + _class + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/model_return.py b/samples/client/petstore/python-asyncio/petstore_api/models/model_return.py index 3862245ef71d..7f3e64a12ab5 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/model_return.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/model_return.py @@ -15,8 +15,27 @@ import six - -class ModelReturn(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ModelReturn(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class ModelReturn(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - '_return': 'int' + '_return': [int] # noqa: E501 } - attribute_map = { - '_return': 'return' + '_return': 'return' # noqa: E501 } - def __init__(self, _return=None): # noqa: E501 - """ModelReturn - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ModelReturn - a model defined in OpenAPI - self.__return = None - self.discriminator = None - if _return is not None: - self._return = _return + + 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 False + _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 + _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. + _return (int): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def _return(self): """Gets the _return of this ModelReturn. # noqa: E501 - :return: The _return of this ModelReturn. # noqa: E501 - :rtype: int + Returns: + (int): The _return of this ModelReturn. # noqa: E501 """ - return self.__return + return self._data_store.get('_return') @_return.setter - def _return(self, _return): + def _return( + self, _return): """Sets the _return of this ModelReturn. - :param _return: The _return of this ModelReturn. # noqa: E501 - :type: int + Returns: + (int): The _return of this ModelReturn. # noqa: E501 """ - self.__return = _return + self.__setitem__( + '_return', + _return + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/name.py b/samples/client/petstore/python-asyncio/petstore_api/models/name.py index b2e97e596a4d..1b06fe765b43 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/name.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/name.py @@ -15,8 +15,27 @@ import six - -class Name(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Name(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,149 +46,223 @@ class Name(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'name': 'int', - 'snake_case': 'int', - '_property': 'str', - '_123_number': 'int' + 'name': [int], # noqa: E501 + 'snake_case': [int], # noqa: E501 + '_property': [str], # noqa: E501 + '_123_number': [int] # noqa: E501 } - attribute_map = { - 'name': 'name', - 'snake_case': 'snake_case', - '_property': 'property', - '_123_number': '123Number' + 'name': 'name', # noqa: E501 + 'snake_case': 'snake_case', # noqa: E501 + '_property': 'property', # noqa: E501 + '_123_number': '123Number' # noqa: E501 } - def __init__(self, name=None, snake_case=None, _property=None, _123_number=None): # noqa: E501 - """Name - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, name, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Name - a model defined in OpenAPI + + Args: + name (int): + + 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 False + _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 + _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. + snake_case (int): [optional] # noqa: E501 + _property (str): [optional] # noqa: E501 + _123_number (int): [optional] # noqa: E501 + """ - self._name = None - self._snake_case = None - self.__property = None - self.__123_number = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + # assign using .var_name to check against nullable and enums self.name = name - if snake_case is not None: - self.snake_case = snake_case - if _property is not None: - self._property = _property - if _123_number is not None: - self._123_number = _123_number + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def name(self): """Gets the name of this Name. # noqa: E501 - :return: The name of this Name. # noqa: E501 - :rtype: int + Returns: + (int): The name of this Name. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this Name. - :param name: The name of this Name. # noqa: E501 - :type: int + Returns: + (int): The name of this Name. # noqa: E501 """ if name is None: - raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `name`, must not be `None`") # noqa: E501 - self._name = name + self.__setitem__( + 'name', + name + ) @property def snake_case(self): """Gets the snake_case of this Name. # noqa: E501 - :return: The snake_case of this Name. # noqa: E501 - :rtype: int + Returns: + (int): The snake_case of this Name. # noqa: E501 """ - return self._snake_case + return self._data_store.get('snake_case') @snake_case.setter - def snake_case(self, snake_case): + def snake_case( + self, snake_case): """Sets the snake_case of this Name. - :param snake_case: The snake_case of this Name. # noqa: E501 - :type: int + Returns: + (int): The snake_case of this Name. # noqa: E501 """ - self._snake_case = snake_case + self.__setitem__( + 'snake_case', + snake_case + ) @property def _property(self): """Gets the _property of this Name. # noqa: E501 - :return: The _property of this Name. # noqa: E501 - :rtype: str + Returns: + (str): The _property of this Name. # noqa: E501 """ - return self.__property + return self._data_store.get('_property') @_property.setter - def _property(self, _property): + def _property( + self, _property): """Sets the _property of this Name. - :param _property: The _property of this Name. # noqa: E501 - :type: str + Returns: + (str): The _property of this Name. # noqa: E501 """ - self.__property = _property + self.__setitem__( + '_property', + _property + ) @property def _123_number(self): """Gets the _123_number of this Name. # noqa: E501 - :return: The _123_number of this Name. # noqa: E501 - :rtype: int + Returns: + (int): The _123_number of this Name. # noqa: E501 """ - return self.__123_number + return self._data_store.get('_123_number') @_123_number.setter - def _123_number(self, _123_number): + def _123_number( + self, _123_number): """Sets the _123_number of this Name. - :param _123_number: The _123_number of this Name. # noqa: E501 - :type: int + Returns: + (int): The _123_number of this Name. # noqa: E501 """ - self.__123_number = _123_number + self.__setitem__( + '_123_number', + _123_number + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/number_only.py b/samples/client/petstore/python-asyncio/petstore_api/models/number_only.py index ab39ee8195d4..8cbc7054da0b 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/number_only.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/number_only.py @@ -15,8 +15,27 @@ import six - -class NumberOnly(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class NumberOnly(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class NumberOnly(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'just_number': 'float' + 'just_number': [float] # noqa: E501 } - attribute_map = { - 'just_number': 'JustNumber' + 'just_number': 'JustNumber' # noqa: E501 } - def __init__(self, just_number=None): # noqa: E501 - """NumberOnly - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """NumberOnly - a model defined in OpenAPI - self._just_number = None - self.discriminator = None - if just_number is not None: - self.just_number = just_number + + 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 False + _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 + _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. + just_number (float): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def just_number(self): """Gets the just_number of this NumberOnly. # noqa: E501 - :return: The just_number of this NumberOnly. # noqa: E501 - :rtype: float + Returns: + (float): The just_number of this NumberOnly. # noqa: E501 """ - return self._just_number + return self._data_store.get('just_number') @just_number.setter - def just_number(self, just_number): + def just_number( + self, just_number): """Sets the just_number of this NumberOnly. - :param just_number: The just_number of this NumberOnly. # noqa: E501 - :type: float + Returns: + (float): The just_number of this NumberOnly. # noqa: E501 """ - self._just_number = just_number + self.__setitem__( + 'just_number', + just_number + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/order.py b/samples/client/petstore/python-asyncio/petstore_api/models/order.py index 697d84447cdc..8f5e45a33be8 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/order.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/order.py @@ -15,8 +15,27 @@ import six - -class Order(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Order(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,134 +46,221 @@ class Order(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'id': 'int', - 'pet_id': 'int', - 'quantity': 'int', - 'ship_date': 'datetime', - 'status': 'str', - 'complete': 'bool' + 'id': [int], # noqa: E501 + 'pet_id': [int], # noqa: E501 + 'quantity': [int], # noqa: E501 + 'ship_date': [datetime], # noqa: E501 + 'status': [str], # noqa: E501 + 'complete': [bool] # noqa: E501 } - attribute_map = { - 'id': 'id', - 'pet_id': 'petId', - 'quantity': 'quantity', - 'ship_date': 'shipDate', - 'status': 'status', - 'complete': 'complete' + 'id': 'id', # noqa: E501 + 'pet_id': 'petId', # noqa: E501 + 'quantity': 'quantity', # noqa: E501 + 'ship_date': 'shipDate', # noqa: E501 + 'status': 'status', # noqa: E501 + 'complete': 'complete' # noqa: E501 } - def __init__(self, id=None, pet_id=None, quantity=None, ship_date=None, status=None, complete=False): # noqa: E501 - """Order - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Order - 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 False + _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 + _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. + id (int): [optional] # noqa: E501 + pet_id (int): [optional] # noqa: E501 + quantity (int): [optional] # noqa: E501 + ship_date (datetime): [optional] # noqa: E501 + status (str): Order Status. [optional] # noqa: E501 + complete (bool): [optional] if omitted the server will use the default value of False # noqa: E501 + """ - self._id = None - self._pet_id = None - self._quantity = None - self._ship_date = None - self._status = None - self._complete = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) - if id is not None: - self.id = id - if pet_id is not None: - self.pet_id = pet_id - if quantity is not None: - self.quantity = quantity - if ship_date is not None: - self.ship_date = ship_date - if status is not None: - self.status = status - if complete is not None: - self.complete = complete + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def id(self): """Gets the id of this Order. # noqa: E501 - :return: The id of this Order. # noqa: E501 - :rtype: int + Returns: + (int): The id of this Order. # noqa: E501 """ - return self._id + return self._data_store.get('id') @id.setter - def id(self, id): + def id( + self, id): """Sets the id of this Order. - :param id: The id of this Order. # noqa: E501 - :type: int + Returns: + (int): The id of this Order. # noqa: E501 """ - self._id = id + self.__setitem__( + 'id', + id + ) @property def pet_id(self): """Gets the pet_id of this Order. # noqa: E501 - :return: The pet_id of this Order. # noqa: E501 - :rtype: int + Returns: + (int): The pet_id of this Order. # noqa: E501 """ - return self._pet_id + return self._data_store.get('pet_id') @pet_id.setter - def pet_id(self, pet_id): + def pet_id( + self, pet_id): """Sets the pet_id of this Order. - :param pet_id: The pet_id of this Order. # noqa: E501 - :type: int + Returns: + (int): The pet_id of this Order. # noqa: E501 """ - self._pet_id = pet_id + self.__setitem__( + 'pet_id', + pet_id + ) @property def quantity(self): """Gets the quantity of this Order. # noqa: E501 - :return: The quantity of this Order. # noqa: E501 - :rtype: int + Returns: + (int): The quantity of this Order. # noqa: E501 """ - return self._quantity + return self._data_store.get('quantity') @quantity.setter - def quantity(self, quantity): + def quantity( + self, quantity): """Sets the quantity of this Order. - :param quantity: The quantity of this Order. # noqa: E501 - :type: int + Returns: + (int): The quantity of this Order. # noqa: E501 """ - self._quantity = quantity + self.__setitem__( + 'quantity', + quantity + ) @property def ship_date(self): """Gets the ship_date of this Order. # noqa: E501 - :return: The ship_date of this Order. # noqa: E501 - :rtype: datetime + Returns: + (datetime): The ship_date of this Order. # noqa: E501 """ - return self._ship_date + return self._data_store.get('ship_date') @ship_date.setter - def ship_date(self, ship_date): + def ship_date( + self, ship_date): """Sets the ship_date of this Order. - :param ship_date: The ship_date of this Order. # noqa: E501 - :type: datetime + Returns: + (datetime): The ship_date of this Order. # noqa: E501 """ - self._ship_date = ship_date + self.__setitem__( + 'ship_date', + ship_date + ) @property def status(self): @@ -162,73 +268,61 @@ def status(self): Order Status # noqa: E501 - :return: The status of this Order. # noqa: E501 - :rtype: str + Returns: + (str): The status of this Order. # noqa: E501 """ - return self._status + return self._data_store.get('status') @status.setter - def status(self, status): + def status( + self, status): """Sets the status of this Order. Order Status # noqa: E501 - :param status: The status of this Order. # noqa: E501 - :type: str + Returns: + (str): The status of this Order. # noqa: E501 """ allowed_values = ["placed", "approved", "delivered"] # noqa: E501 if status not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `status` ({0}), must be one of {1}" # noqa: E501 .format(status, allowed_values) ) - self._status = status + self.__setitem__( + 'status', + status + ) @property def complete(self): """Gets the complete of this Order. # noqa: E501 - :return: The complete of this Order. # noqa: E501 - :rtype: bool + Returns: + (bool): The complete of this Order. # noqa: E501 """ - return self._complete + return self._data_store.get('complete') @complete.setter - def complete(self, complete): + def complete( + self, complete): """Sets the complete of this Order. - :param complete: The complete of this Order. # noqa: E501 - :type: bool + Returns: + (bool): The complete of this Order. # noqa: E501 """ - self._complete = complete + self.__setitem__( + 'complete', + complete + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/outer_composite.py b/samples/client/petstore/python-asyncio/petstore_api/models/outer_composite.py index b22b16c6fdcd..3da4dfb6426d 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/outer_composite.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/outer_composite.py @@ -15,8 +15,27 @@ import six - -class OuterComposite(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class OuterComposite(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,122 +46,191 @@ class OuterComposite(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'my_number': 'float', - 'my_string': 'str', - 'my_boolean': 'bool' + 'my_number': [float], # noqa: E501 + 'my_string': [str], # noqa: E501 + 'my_boolean': [bool] # noqa: E501 } - attribute_map = { - 'my_number': 'my_number', - 'my_string': 'my_string', - 'my_boolean': 'my_boolean' + 'my_number': 'my_number', # noqa: E501 + 'my_string': 'my_string', # noqa: E501 + 'my_boolean': 'my_boolean' # noqa: E501 } - def __init__(self, my_number=None, my_string=None, my_boolean=None): # noqa: E501 - """OuterComposite - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """OuterComposite - 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 False + _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 + _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. + my_number (float): [optional] # noqa: E501 + my_string (str): [optional] # noqa: E501 + my_boolean (bool): [optional] # noqa: E501 + """ - self._my_number = None - self._my_string = None - self._my_boolean = None + self._data_store = {} self.discriminator = None - - if my_number is not None: - self.my_number = my_number - if my_string is not None: - self.my_string = my_string - if my_boolean is not None: - self.my_boolean = my_boolean + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def my_number(self): """Gets the my_number of this OuterComposite. # noqa: E501 - :return: The my_number of this OuterComposite. # noqa: E501 - :rtype: float + Returns: + (float): The my_number of this OuterComposite. # noqa: E501 """ - return self._my_number + return self._data_store.get('my_number') @my_number.setter - def my_number(self, my_number): + def my_number( + self, my_number): """Sets the my_number of this OuterComposite. - :param my_number: The my_number of this OuterComposite. # noqa: E501 - :type: float + Returns: + (float): The my_number of this OuterComposite. # noqa: E501 """ - self._my_number = my_number + self.__setitem__( + 'my_number', + my_number + ) @property def my_string(self): """Gets the my_string of this OuterComposite. # noqa: E501 - :return: The my_string of this OuterComposite. # noqa: E501 - :rtype: str + Returns: + (str): The my_string of this OuterComposite. # noqa: E501 """ - return self._my_string + return self._data_store.get('my_string') @my_string.setter - def my_string(self, my_string): + def my_string( + self, my_string): """Sets the my_string of this OuterComposite. - :param my_string: The my_string of this OuterComposite. # noqa: E501 - :type: str + Returns: + (str): The my_string of this OuterComposite. # noqa: E501 """ - self._my_string = my_string + self.__setitem__( + 'my_string', + my_string + ) @property def my_boolean(self): """Gets the my_boolean of this OuterComposite. # noqa: E501 - :return: The my_boolean of this OuterComposite. # noqa: E501 - :rtype: bool + Returns: + (bool): The my_boolean of this OuterComposite. # noqa: E501 """ - return self._my_boolean + return self._data_store.get('my_boolean') @my_boolean.setter - def my_boolean(self, my_boolean): + def my_boolean( + self, my_boolean): """Sets the my_boolean of this OuterComposite. - :param my_boolean: The my_boolean of this OuterComposite. # noqa: E501 - :type: bool + Returns: + (bool): The my_boolean of this OuterComposite. # noqa: E501 """ - self._my_boolean = my_boolean + self.__setitem__( + 'my_boolean', + my_boolean + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/outer_enum.py b/samples/client/petstore/python-asyncio/petstore_api/models/outer_enum.py index 10d6be19a4c9..9d4398b5188d 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/outer_enum.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/outer_enum.py @@ -15,8 +15,27 @@ import six - -class OuterEnum(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class OuterEnum(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -34,42 +53,107 @@ class OuterEnum(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { } - attribute_map = { } - def __init__(self): # noqa: E501 - """OuterEnum - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """OuterEnum - 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 False + _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 + _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. + """ + + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/pet.py b/samples/client/petstore/python-asyncio/petstore_api/models/pet.py index d3c412f4a82b..1b30f1186d6f 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/pet.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/pet.py @@ -15,8 +15,29 @@ import six - -class Pet(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.category import Category +from petstore_api.models.tag import Tag + + +class Pet(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,157 +48,253 @@ class Pet(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'id': 'int', - 'category': 'Category', - 'name': 'str', - 'photo_urls': 'list[str]', - 'tags': 'list[Tag]', - 'status': 'str' + 'id': [int], # noqa: E501 + 'category': [Category], # noqa: E501 + 'name': [str], # noqa: E501 + 'photo_urls': [[(str,)]], # noqa: E501 + 'tags': [[(Tag,)]], # noqa: E501 + 'status': [str] # noqa: E501 } - attribute_map = { - 'id': 'id', - 'category': 'category', - 'name': 'name', - 'photo_urls': 'photoUrls', - 'tags': 'tags', - 'status': 'status' + 'id': 'id', # noqa: E501 + 'category': 'category', # noqa: E501 + 'name': 'name', # noqa: E501 + 'photo_urls': 'photoUrls', # noqa: E501 + 'tags': 'tags', # noqa: E501 + 'status': 'status' # noqa: E501 } - def __init__(self, id=None, category=None, name=None, photo_urls=None, tags=None, status=None): # noqa: E501 - """Pet - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, name, photo_urls, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Pet - a model defined in OpenAPI + + Args: + name (str): + photo_urls ([(str,)]): + + 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 False + _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 + _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. + id (int): [optional] # noqa: E501 + category (Category): [optional] # noqa: E501 + tags ([(Tag,)]): [optional] # noqa: E501 + status (str): pet status in the store. [optional] # noqa: E501 + """ - self._id = None - self._category = None - self._name = None - self._photo_urls = None - self._tags = None - self._status = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration - if id is not None: - self.id = id - if category is not None: - self.category = category + # assign using .var_name to check against nullable and enums self.name = name self.photo_urls = photo_urls - if tags is not None: - self.tags = tags - if status is not None: - self.status = status + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def id(self): """Gets the id of this Pet. # noqa: E501 - :return: The id of this Pet. # noqa: E501 - :rtype: int + Returns: + (int): The id of this Pet. # noqa: E501 """ - return self._id + return self._data_store.get('id') @id.setter - def id(self, id): + def id( + self, id): """Sets the id of this Pet. - :param id: The id of this Pet. # noqa: E501 - :type: int + Returns: + (int): The id of this Pet. # noqa: E501 """ - self._id = id + self.__setitem__( + 'id', + id + ) @property def category(self): """Gets the category of this Pet. # noqa: E501 - :return: The category of this Pet. # noqa: E501 - :rtype: Category + Returns: + (Category): The category of this Pet. # noqa: E501 """ - return self._category + return self._data_store.get('category') @category.setter - def category(self, category): + def category( + self, category): """Sets the category of this Pet. - :param category: The category of this Pet. # noqa: E501 - :type: Category + Returns: + (Category): The category of this Pet. # noqa: E501 """ - self._category = category + self.__setitem__( + 'category', + category + ) @property def name(self): """Gets the name of this Pet. # noqa: E501 - :return: The name of this Pet. # noqa: E501 - :rtype: str + Returns: + (str): The name of this Pet. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this Pet. - :param name: The name of this Pet. # noqa: E501 - :type: str + Returns: + (str): The name of this Pet. # noqa: E501 """ if name is None: - raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `name`, must not be `None`") # noqa: E501 - self._name = name + self.__setitem__( + 'name', + name + ) @property def photo_urls(self): """Gets the photo_urls of this Pet. # noqa: E501 - :return: The photo_urls of this Pet. # noqa: E501 - :rtype: list[str] + Returns: + ([(str,)]): The photo_urls of this Pet. # noqa: E501 """ - return self._photo_urls + return self._data_store.get('photo_urls') @photo_urls.setter - def photo_urls(self, photo_urls): + def photo_urls( + self, photo_urls): """Sets the photo_urls of this Pet. - :param photo_urls: The photo_urls of this Pet. # noqa: E501 - :type: list[str] + Returns: + ([(str,)]): The photo_urls of this Pet. # noqa: E501 """ if photo_urls is None: - raise ValueError("Invalid value for `photo_urls`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `photo_urls`, must not be `None`") # noqa: E501 - self._photo_urls = photo_urls + self.__setitem__( + 'photo_urls', + photo_urls + ) @property def tags(self): """Gets the tags of this Pet. # noqa: E501 - :return: The tags of this Pet. # noqa: E501 - :rtype: list[Tag] + Returns: + ([(Tag,)]): The tags of this Pet. # noqa: E501 """ - return self._tags + return self._data_store.get('tags') @tags.setter - def tags(self, tags): + def tags( + self, tags): """Sets the tags of this Pet. - :param tags: The tags of this Pet. # noqa: E501 - :type: list[Tag] + Returns: + ([(Tag,)]): The tags of this Pet. # noqa: E501 """ - self._tags = tags + self.__setitem__( + 'tags', + tags + ) @property def status(self): @@ -185,52 +302,36 @@ def status(self): pet status in the store # noqa: E501 - :return: The status of this Pet. # noqa: E501 - :rtype: str + Returns: + (str): The status of this Pet. # noqa: E501 """ - return self._status + return self._data_store.get('status') @status.setter - def status(self, status): + def status( + self, status): """Sets the status of this Pet. pet status in the store # noqa: E501 - :param status: The status of this Pet. # noqa: E501 - :type: str + Returns: + (str): The status of this Pet. # noqa: E501 """ allowed_values = ["available", "pending", "sold"] # noqa: E501 if status not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `status` ({0}), must be one of {1}" # noqa: E501 .format(status, allowed_values) ) - self._status = status + self.__setitem__( + 'status', + status + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/read_only_first.py b/samples/client/petstore/python-asyncio/petstore_api/models/read_only_first.py index 2b257be18de4..0309488b3f37 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/read_only_first.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/read_only_first.py @@ -15,8 +15,27 @@ import six - -class ReadOnlyFirst(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ReadOnlyFirst(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +46,163 @@ class ReadOnlyFirst(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'bar': 'str', - 'baz': 'str' + 'bar': [str], # noqa: E501 + 'baz': [str] # noqa: E501 } - attribute_map = { - 'bar': 'bar', - 'baz': 'baz' + 'bar': 'bar', # noqa: E501 + 'baz': 'baz' # noqa: E501 } - def __init__(self, bar=None, baz=None): # noqa: E501 - """ReadOnlyFirst - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ReadOnlyFirst - 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 False + _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 + _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. + bar (str): [optional] # noqa: E501 + baz (str): [optional] # noqa: E501 + """ - self._bar = None - self._baz = None + self._data_store = {} self.discriminator = None - - if bar is not None: - self.bar = bar - if baz is not None: - self.baz = baz + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def bar(self): """Gets the bar of this ReadOnlyFirst. # noqa: E501 - :return: The bar of this ReadOnlyFirst. # noqa: E501 - :rtype: str + Returns: + (str): The bar of this ReadOnlyFirst. # noqa: E501 """ - return self._bar + return self._data_store.get('bar') @bar.setter - def bar(self, bar): + def bar( + self, bar): """Sets the bar of this ReadOnlyFirst. - :param bar: The bar of this ReadOnlyFirst. # noqa: E501 - :type: str + Returns: + (str): The bar of this ReadOnlyFirst. # noqa: E501 """ - self._bar = bar + self.__setitem__( + 'bar', + bar + ) @property def baz(self): """Gets the baz of this ReadOnlyFirst. # noqa: E501 - :return: The baz of this ReadOnlyFirst. # noqa: E501 - :rtype: str + Returns: + (str): The baz of this ReadOnlyFirst. # noqa: E501 """ - return self._baz + return self._data_store.get('baz') @baz.setter - def baz(self, baz): + def baz( + self, baz): """Sets the baz of this ReadOnlyFirst. - :param baz: The baz of this ReadOnlyFirst. # noqa: E501 - :type: str + Returns: + (str): The baz of this ReadOnlyFirst. # noqa: E501 """ - self._baz = baz + self.__setitem__( + 'baz', + baz + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/special_model_name.py b/samples/client/petstore/python-asyncio/petstore_api/models/special_model_name.py index fa59b887471b..9431157f2c3e 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/special_model_name.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/special_model_name.py @@ -15,8 +15,27 @@ import six - -class SpecialModelName(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class SpecialModelName(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class SpecialModelName(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'special_property_name': 'int' + 'special_property_name': [int] # noqa: E501 } - attribute_map = { - 'special_property_name': '$special[property.name]' + 'special_property_name': '$special[property.name]' # noqa: E501 } - def __init__(self, special_property_name=None): # noqa: E501 - """SpecialModelName - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """SpecialModelName - a model defined in OpenAPI - self._special_property_name = None - self.discriminator = None - if special_property_name is not None: - self.special_property_name = special_property_name + + 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 False + _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 + _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. + special_property_name (int): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def special_property_name(self): """Gets the special_property_name of this SpecialModelName. # noqa: E501 - :return: The special_property_name of this SpecialModelName. # noqa: E501 - :rtype: int + Returns: + (int): The special_property_name of this SpecialModelName. # noqa: E501 """ - return self._special_property_name + return self._data_store.get('special_property_name') @special_property_name.setter - def special_property_name(self, special_property_name): + def special_property_name( + self, special_property_name): """Sets the special_property_name of this SpecialModelName. - :param special_property_name: The special_property_name of this SpecialModelName. # noqa: E501 - :type: int + Returns: + (int): The special_property_name of this SpecialModelName. # noqa: E501 """ - self._special_property_name = special_property_name + self.__setitem__( + 'special_property_name', + special_property_name + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/tag.py b/samples/client/petstore/python-asyncio/petstore_api/models/tag.py index 8fcc8a848660..0c781dc5be7c 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/tag.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/tag.py @@ -15,8 +15,27 @@ import six - -class Tag(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Tag(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +46,163 @@ class Tag(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'id': 'int', - 'name': 'str' + 'id': [int], # noqa: E501 + 'name': [str] # noqa: E501 } - attribute_map = { - 'id': 'id', - 'name': 'name' + 'id': 'id', # noqa: E501 + 'name': 'name' # noqa: E501 } - def __init__(self, id=None, name=None): # noqa: E501 - """Tag - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Tag - 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 False + _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 + _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. + id (int): [optional] # noqa: E501 + name (str): [optional] # noqa: E501 + """ - self._id = None - self._name = None + self._data_store = {} self.discriminator = None - - if id is not None: - self.id = id - if name is not None: - self.name = name + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def id(self): """Gets the id of this Tag. # noqa: E501 - :return: The id of this Tag. # noqa: E501 - :rtype: int + Returns: + (int): The id of this Tag. # noqa: E501 """ - return self._id + return self._data_store.get('id') @id.setter - def id(self, id): + def id( + self, id): """Sets the id of this Tag. - :param id: The id of this Tag. # noqa: E501 - :type: int + Returns: + (int): The id of this Tag. # noqa: E501 """ - self._id = id + self.__setitem__( + 'id', + id + ) @property def name(self): """Gets the name of this Tag. # noqa: E501 - :return: The name of this Tag. # noqa: E501 - :rtype: str + Returns: + (str): The name of this Tag. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this Tag. - :param name: The name of this Tag. # noqa: E501 - :type: str + Returns: + (str): The name of this Tag. # noqa: E501 """ - self._name = name + self.__setitem__( + 'name', + name + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/type_holder_default.py b/samples/client/petstore/python-asyncio/petstore_api/models/type_holder_default.py index a0566f5d5fe6..88c3db03e30a 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/type_holder_default.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/type_holder_default.py @@ -15,8 +15,27 @@ import six - -class TypeHolderDefault(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class TypeHolderDefault(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,179 +46,263 @@ class TypeHolderDefault(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'string_item': 'str', - 'number_item': 'float', - 'integer_item': 'int', - 'bool_item': 'bool', - 'array_item': 'list[int]' + 'string_item': [str], # noqa: E501 + 'number_item': [float], # noqa: E501 + 'integer_item': [int], # noqa: E501 + 'bool_item': [bool], # noqa: E501 + 'array_item': [[(int,)]] # noqa: E501 } - attribute_map = { - 'string_item': 'string_item', - 'number_item': 'number_item', - 'integer_item': 'integer_item', - 'bool_item': 'bool_item', - 'array_item': 'array_item' + 'string_item': 'string_item', # noqa: E501 + 'number_item': 'number_item', # noqa: E501 + 'integer_item': 'integer_item', # noqa: E501 + 'bool_item': 'bool_item', # noqa: E501 + 'array_item': 'array_item' # noqa: E501 } - def __init__(self, string_item='what', number_item=None, integer_item=None, bool_item=True, array_item=None): # noqa: E501 - """TypeHolderDefault - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, number_item, integer_item, array_item, string_item='what', bool_item=True, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """TypeHolderDefault - a model defined in OpenAPI + + Args: + number_item (float): + integer_item (int): + array_item ([(int,)]): + string_item (str): defaults to 'what', must be one of ['what'] # noqa: E501 + bool_item (bool): defaults to True, must be one of [True] # noqa: E501 + + 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 False + _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 + _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. + """ - self._string_item = None - self._number_item = None - self._integer_item = None - self._bool_item = None - self._array_item = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + # assign using .var_name to check against nullable and enums self.string_item = string_item self.number_item = number_item self.integer_item = integer_item self.bool_item = bool_item self.array_item = array_item + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def string_item(self): """Gets the string_item of this TypeHolderDefault. # noqa: E501 - :return: The string_item of this TypeHolderDefault. # noqa: E501 - :rtype: str + Returns: + (str): The string_item of this TypeHolderDefault. # noqa: E501 """ - return self._string_item + return self._data_store.get('string_item') @string_item.setter - def string_item(self, string_item): + def string_item( + self, string_item): """Sets the string_item of this TypeHolderDefault. - :param string_item: The string_item of this TypeHolderDefault. # noqa: E501 - :type: str + Returns: + (str): The string_item of this TypeHolderDefault. # noqa: E501 """ if string_item is None: - raise ValueError("Invalid value for `string_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `string_item`, must not be `None`") # noqa: E501 - self._string_item = string_item + self.__setitem__( + 'string_item', + string_item + ) @property def number_item(self): """Gets the number_item of this TypeHolderDefault. # noqa: E501 - :return: The number_item of this TypeHolderDefault. # noqa: E501 - :rtype: float + Returns: + (float): The number_item of this TypeHolderDefault. # noqa: E501 """ - return self._number_item + return self._data_store.get('number_item') @number_item.setter - def number_item(self, number_item): + def number_item( + self, number_item): """Sets the number_item of this TypeHolderDefault. - :param number_item: The number_item of this TypeHolderDefault. # noqa: E501 - :type: float + Returns: + (float): The number_item of this TypeHolderDefault. # noqa: E501 """ if number_item is None: - raise ValueError("Invalid value for `number_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `number_item`, must not be `None`") # noqa: E501 - self._number_item = number_item + self.__setitem__( + 'number_item', + number_item + ) @property def integer_item(self): """Gets the integer_item of this TypeHolderDefault. # noqa: E501 - :return: The integer_item of this TypeHolderDefault. # noqa: E501 - :rtype: int + Returns: + (int): The integer_item of this TypeHolderDefault. # noqa: E501 """ - return self._integer_item + return self._data_store.get('integer_item') @integer_item.setter - def integer_item(self, integer_item): + def integer_item( + self, integer_item): """Sets the integer_item of this TypeHolderDefault. - :param integer_item: The integer_item of this TypeHolderDefault. # noqa: E501 - :type: int + Returns: + (int): The integer_item of this TypeHolderDefault. # noqa: E501 """ if integer_item is None: - raise ValueError("Invalid value for `integer_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `integer_item`, must not be `None`") # noqa: E501 - self._integer_item = integer_item + self.__setitem__( + 'integer_item', + integer_item + ) @property def bool_item(self): """Gets the bool_item of this TypeHolderDefault. # noqa: E501 - :return: The bool_item of this TypeHolderDefault. # noqa: E501 - :rtype: bool + Returns: + (bool): The bool_item of this TypeHolderDefault. # noqa: E501 """ - return self._bool_item + return self._data_store.get('bool_item') @bool_item.setter - def bool_item(self, bool_item): + def bool_item( + self, bool_item): """Sets the bool_item of this TypeHolderDefault. - :param bool_item: The bool_item of this TypeHolderDefault. # noqa: E501 - :type: bool + Returns: + (bool): The bool_item of this TypeHolderDefault. # noqa: E501 """ if bool_item is None: - raise ValueError("Invalid value for `bool_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `bool_item`, must not be `None`") # noqa: E501 - self._bool_item = bool_item + self.__setitem__( + 'bool_item', + bool_item + ) @property def array_item(self): """Gets the array_item of this TypeHolderDefault. # noqa: E501 - :return: The array_item of this TypeHolderDefault. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The array_item of this TypeHolderDefault. # noqa: E501 """ - return self._array_item + return self._data_store.get('array_item') @array_item.setter - def array_item(self, array_item): + def array_item( + self, array_item): """Sets the array_item of this TypeHolderDefault. - :param array_item: The array_item of this TypeHolderDefault. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The array_item of this TypeHolderDefault. # noqa: E501 """ if array_item is None: - raise ValueError("Invalid value for `array_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `array_item`, must not be `None`") # noqa: E501 - self._array_item = array_item + self.__setitem__( + 'array_item', + array_item + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/type_holder_example.py b/samples/client/petstore/python-asyncio/petstore_api/models/type_holder_example.py index c926f4e48489..02ea8681cb6f 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/type_holder_example.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/type_holder_example.py @@ -15,8 +15,27 @@ import six - -class TypeHolderExample(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class TypeHolderExample(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,179 +46,263 @@ class TypeHolderExample(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'string_item': 'str', - 'number_item': 'float', - 'integer_item': 'int', - 'bool_item': 'bool', - 'array_item': 'list[int]' + 'string_item': [str], # noqa: E501 + 'number_item': [float], # noqa: E501 + 'integer_item': [int], # noqa: E501 + 'bool_item': [bool], # noqa: E501 + 'array_item': [[(int,)]] # noqa: E501 } - attribute_map = { - 'string_item': 'string_item', - 'number_item': 'number_item', - 'integer_item': 'integer_item', - 'bool_item': 'bool_item', - 'array_item': 'array_item' + 'string_item': 'string_item', # noqa: E501 + 'number_item': 'number_item', # noqa: E501 + 'integer_item': 'integer_item', # noqa: E501 + 'bool_item': 'bool_item', # noqa: E501 + 'array_item': 'array_item' # noqa: E501 } - def __init__(self, string_item=None, number_item=None, integer_item=None, bool_item=None, array_item=None): # noqa: E501 - """TypeHolderExample - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, string_item, number_item, integer_item, bool_item, array_item, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """TypeHolderExample - a model defined in OpenAPI + + Args: + string_item (str): + number_item (float): + integer_item (int): + bool_item (bool): + array_item ([(int,)]): + + 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 False + _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 + _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. + """ - self._string_item = None - self._number_item = None - self._integer_item = None - self._bool_item = None - self._array_item = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + # assign using .var_name to check against nullable and enums self.string_item = string_item self.number_item = number_item self.integer_item = integer_item self.bool_item = bool_item self.array_item = array_item + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def string_item(self): """Gets the string_item of this TypeHolderExample. # noqa: E501 - :return: The string_item of this TypeHolderExample. # noqa: E501 - :rtype: str + Returns: + (str): The string_item of this TypeHolderExample. # noqa: E501 """ - return self._string_item + return self._data_store.get('string_item') @string_item.setter - def string_item(self, string_item): + def string_item( + self, string_item): """Sets the string_item of this TypeHolderExample. - :param string_item: The string_item of this TypeHolderExample. # noqa: E501 - :type: str + Returns: + (str): The string_item of this TypeHolderExample. # noqa: E501 """ if string_item is None: - raise ValueError("Invalid value for `string_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `string_item`, must not be `None`") # noqa: E501 - self._string_item = string_item + self.__setitem__( + 'string_item', + string_item + ) @property def number_item(self): """Gets the number_item of this TypeHolderExample. # noqa: E501 - :return: The number_item of this TypeHolderExample. # noqa: E501 - :rtype: float + Returns: + (float): The number_item of this TypeHolderExample. # noqa: E501 """ - return self._number_item + return self._data_store.get('number_item') @number_item.setter - def number_item(self, number_item): + def number_item( + self, number_item): """Sets the number_item of this TypeHolderExample. - :param number_item: The number_item of this TypeHolderExample. # noqa: E501 - :type: float + Returns: + (float): The number_item of this TypeHolderExample. # noqa: E501 """ if number_item is None: - raise ValueError("Invalid value for `number_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `number_item`, must not be `None`") # noqa: E501 - self._number_item = number_item + self.__setitem__( + 'number_item', + number_item + ) @property def integer_item(self): """Gets the integer_item of this TypeHolderExample. # noqa: E501 - :return: The integer_item of this TypeHolderExample. # noqa: E501 - :rtype: int + Returns: + (int): The integer_item of this TypeHolderExample. # noqa: E501 """ - return self._integer_item + return self._data_store.get('integer_item') @integer_item.setter - def integer_item(self, integer_item): + def integer_item( + self, integer_item): """Sets the integer_item of this TypeHolderExample. - :param integer_item: The integer_item of this TypeHolderExample. # noqa: E501 - :type: int + Returns: + (int): The integer_item of this TypeHolderExample. # noqa: E501 """ if integer_item is None: - raise ValueError("Invalid value for `integer_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `integer_item`, must not be `None`") # noqa: E501 - self._integer_item = integer_item + self.__setitem__( + 'integer_item', + integer_item + ) @property def bool_item(self): """Gets the bool_item of this TypeHolderExample. # noqa: E501 - :return: The bool_item of this TypeHolderExample. # noqa: E501 - :rtype: bool + Returns: + (bool): The bool_item of this TypeHolderExample. # noqa: E501 """ - return self._bool_item + return self._data_store.get('bool_item') @bool_item.setter - def bool_item(self, bool_item): + def bool_item( + self, bool_item): """Sets the bool_item of this TypeHolderExample. - :param bool_item: The bool_item of this TypeHolderExample. # noqa: E501 - :type: bool + Returns: + (bool): The bool_item of this TypeHolderExample. # noqa: E501 """ if bool_item is None: - raise ValueError("Invalid value for `bool_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `bool_item`, must not be `None`") # noqa: E501 - self._bool_item = bool_item + self.__setitem__( + 'bool_item', + bool_item + ) @property def array_item(self): """Gets the array_item of this TypeHolderExample. # noqa: E501 - :return: The array_item of this TypeHolderExample. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The array_item of this TypeHolderExample. # noqa: E501 """ - return self._array_item + return self._data_store.get('array_item') @array_item.setter - def array_item(self, array_item): + def array_item( + self, array_item): """Sets the array_item of this TypeHolderExample. - :param array_item: The array_item of this TypeHolderExample. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The array_item of this TypeHolderExample. # noqa: E501 """ if array_item is None: - raise ValueError("Invalid value for `array_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `array_item`, must not be `None`") # noqa: E501 - self._array_item = array_item + self.__setitem__( + 'array_item', + array_item + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/user.py b/samples/client/petstore/python-asyncio/petstore_api/models/user.py index 9736c47c1f87..33b99bfdb45c 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/user.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/user.py @@ -15,8 +15,27 @@ import six - -class User(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class User(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,207 +46,302 @@ class User(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'id': 'int', - 'username': 'str', - 'first_name': 'str', - 'last_name': 'str', - 'email': 'str', - 'password': 'str', - 'phone': 'str', - 'user_status': 'int' + 'id': [int], # noqa: E501 + 'username': [str], # noqa: E501 + 'first_name': [str], # noqa: E501 + 'last_name': [str], # noqa: E501 + 'email': [str], # noqa: E501 + 'password': [str], # noqa: E501 + 'phone': [str], # noqa: E501 + 'user_status': [int] # noqa: E501 } - attribute_map = { - 'id': 'id', - 'username': 'username', - 'first_name': 'firstName', - 'last_name': 'lastName', - 'email': 'email', - 'password': 'password', - 'phone': 'phone', - 'user_status': 'userStatus' + 'id': 'id', # noqa: E501 + 'username': 'username', # noqa: E501 + 'first_name': 'firstName', # noqa: E501 + 'last_name': 'lastName', # noqa: E501 + 'email': 'email', # noqa: E501 + 'password': 'password', # noqa: E501 + 'phone': 'phone', # noqa: E501 + 'user_status': 'userStatus' # noqa: E501 } - def __init__(self, id=None, username=None, first_name=None, last_name=None, email=None, password=None, phone=None, user_status=None): # noqa: E501 - """User - a model defined in OpenAPI""" # noqa: E501 - - self._id = None - self._username = None - self._first_name = None - self._last_name = None - self._email = None - self._password = None - self._phone = None - self._user_status = None - self.discriminator = None + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """User - 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 False + _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 + _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. + id (int): [optional] # noqa: E501 + username (str): [optional] # noqa: E501 + first_name (str): [optional] # noqa: E501 + last_name (str): [optional] # noqa: E501 + email (str): [optional] # noqa: E501 + password (str): [optional] # noqa: E501 + phone (str): [optional] # noqa: E501 + user_status (int): User Status. [optional] # noqa: E501 + """ - if id is not None: - self.id = id - if username is not None: - self.username = username - if first_name is not None: - self.first_name = first_name - if last_name is not None: - self.last_name = last_name - if email is not None: - self.email = email - if password is not None: - self.password = password - if phone is not None: - self.phone = phone - if user_status is not None: - self.user_status = user_status + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def id(self): """Gets the id of this User. # noqa: E501 - :return: The id of this User. # noqa: E501 - :rtype: int + Returns: + (int): The id of this User. # noqa: E501 """ - return self._id + return self._data_store.get('id') @id.setter - def id(self, id): + def id( + self, id): """Sets the id of this User. - :param id: The id of this User. # noqa: E501 - :type: int + Returns: + (int): The id of this User. # noqa: E501 """ - self._id = id + self.__setitem__( + 'id', + id + ) @property def username(self): """Gets the username of this User. # noqa: E501 - :return: The username of this User. # noqa: E501 - :rtype: str + Returns: + (str): The username of this User. # noqa: E501 """ - return self._username + return self._data_store.get('username') @username.setter - def username(self, username): + def username( + self, username): """Sets the username of this User. - :param username: The username of this User. # noqa: E501 - :type: str + Returns: + (str): The username of this User. # noqa: E501 """ - self._username = username + self.__setitem__( + 'username', + username + ) @property def first_name(self): """Gets the first_name of this User. # noqa: E501 - :return: The first_name of this User. # noqa: E501 - :rtype: str + Returns: + (str): The first_name of this User. # noqa: E501 """ - return self._first_name + return self._data_store.get('first_name') @first_name.setter - def first_name(self, first_name): + def first_name( + self, first_name): """Sets the first_name of this User. - :param first_name: The first_name of this User. # noqa: E501 - :type: str + Returns: + (str): The first_name of this User. # noqa: E501 """ - self._first_name = first_name + self.__setitem__( + 'first_name', + first_name + ) @property def last_name(self): """Gets the last_name of this User. # noqa: E501 - :return: The last_name of this User. # noqa: E501 - :rtype: str + Returns: + (str): The last_name of this User. # noqa: E501 """ - return self._last_name + return self._data_store.get('last_name') @last_name.setter - def last_name(self, last_name): + def last_name( + self, last_name): """Sets the last_name of this User. - :param last_name: The last_name of this User. # noqa: E501 - :type: str + Returns: + (str): The last_name of this User. # noqa: E501 """ - self._last_name = last_name + self.__setitem__( + 'last_name', + last_name + ) @property def email(self): """Gets the email of this User. # noqa: E501 - :return: The email of this User. # noqa: E501 - :rtype: str + Returns: + (str): The email of this User. # noqa: E501 """ - return self._email + return self._data_store.get('email') @email.setter - def email(self, email): + def email( + self, email): """Sets the email of this User. - :param email: The email of this User. # noqa: E501 - :type: str + Returns: + (str): The email of this User. # noqa: E501 """ - self._email = email + self.__setitem__( + 'email', + email + ) @property def password(self): """Gets the password of this User. # noqa: E501 - :return: The password of this User. # noqa: E501 - :rtype: str + Returns: + (str): The password of this User. # noqa: E501 """ - return self._password + return self._data_store.get('password') @password.setter - def password(self, password): + def password( + self, password): """Sets the password of this User. - :param password: The password of this User. # noqa: E501 - :type: str + Returns: + (str): The password of this User. # noqa: E501 """ - self._password = password + self.__setitem__( + 'password', + password + ) @property def phone(self): """Gets the phone of this User. # noqa: E501 - :return: The phone of this User. # noqa: E501 - :rtype: str + Returns: + (str): The phone of this User. # noqa: E501 """ - return self._phone + return self._data_store.get('phone') @phone.setter - def phone(self, phone): + def phone( + self, phone): """Sets the phone of this User. - :param phone: The phone of this User. # noqa: E501 - :type: str + Returns: + (str): The phone of this User. # noqa: E501 """ - self._phone = phone + self.__setitem__( + 'phone', + phone + ) @property def user_status(self): @@ -235,46 +349,30 @@ def user_status(self): User Status # noqa: E501 - :return: The user_status of this User. # noqa: E501 - :rtype: int + Returns: + (int): The user_status of this User. # noqa: E501 """ - return self._user_status + return self._data_store.get('user_status') @user_status.setter - def user_status(self, user_status): + def user_status( + self, user_status): """Sets the user_status of this User. User Status # noqa: E501 - :param user_status: The user_status of this User. # noqa: E501 - :type: int + Returns: + (int): The user_status of this User. # noqa: E501 """ - self._user_status = user_status + self.__setitem__( + 'user_status', + user_status + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/models/xml_item.py b/samples/client/petstore/python-asyncio/petstore_api/models/xml_item.py index 00872d531a88..86672dae2746 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/models/xml_item.py +++ b/samples/client/petstore/python-asyncio/petstore_api/models/xml_item.py @@ -15,8 +15,27 @@ import six - -class XmlItem(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class XmlItem(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,798 +46,919 @@ class XmlItem(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'attribute_string': 'str', - 'attribute_number': 'float', - 'attribute_integer': 'int', - 'attribute_boolean': 'bool', - 'wrapped_array': 'list[int]', - 'name_string': 'str', - 'name_number': 'float', - 'name_integer': 'int', - 'name_boolean': 'bool', - 'name_array': 'list[int]', - 'name_wrapped_array': 'list[int]', - 'prefix_string': 'str', - 'prefix_number': 'float', - 'prefix_integer': 'int', - 'prefix_boolean': 'bool', - 'prefix_array': 'list[int]', - 'prefix_wrapped_array': 'list[int]', - 'namespace_string': 'str', - 'namespace_number': 'float', - 'namespace_integer': 'int', - 'namespace_boolean': 'bool', - 'namespace_array': 'list[int]', - 'namespace_wrapped_array': 'list[int]', - 'prefix_ns_string': 'str', - 'prefix_ns_number': 'float', - 'prefix_ns_integer': 'int', - 'prefix_ns_boolean': 'bool', - 'prefix_ns_array': 'list[int]', - 'prefix_ns_wrapped_array': 'list[int]' + 'attribute_string': [str], # noqa: E501 + 'attribute_number': [float], # noqa: E501 + 'attribute_integer': [int], # noqa: E501 + 'attribute_boolean': [bool], # noqa: E501 + 'wrapped_array': [[(int,)]], # noqa: E501 + 'name_string': [str], # noqa: E501 + 'name_number': [float], # noqa: E501 + 'name_integer': [int], # noqa: E501 + 'name_boolean': [bool], # noqa: E501 + 'name_array': [[(int,)]], # noqa: E501 + 'name_wrapped_array': [[(int,)]], # noqa: E501 + 'prefix_string': [str], # noqa: E501 + 'prefix_number': [float], # noqa: E501 + 'prefix_integer': [int], # noqa: E501 + 'prefix_boolean': [bool], # noqa: E501 + 'prefix_array': [[(int,)]], # noqa: E501 + 'prefix_wrapped_array': [[(int,)]], # noqa: E501 + 'namespace_string': [str], # noqa: E501 + 'namespace_number': [float], # noqa: E501 + 'namespace_integer': [int], # noqa: E501 + 'namespace_boolean': [bool], # noqa: E501 + 'namespace_array': [[(int,)]], # noqa: E501 + 'namespace_wrapped_array': [[(int,)]], # noqa: E501 + 'prefix_ns_string': [str], # noqa: E501 + 'prefix_ns_number': [float], # noqa: E501 + 'prefix_ns_integer': [int], # noqa: E501 + 'prefix_ns_boolean': [bool], # noqa: E501 + 'prefix_ns_array': [[(int,)]], # noqa: E501 + 'prefix_ns_wrapped_array': [[(int,)]] # noqa: E501 } - attribute_map = { - 'attribute_string': 'attribute_string', - 'attribute_number': 'attribute_number', - 'attribute_integer': 'attribute_integer', - 'attribute_boolean': 'attribute_boolean', - 'wrapped_array': 'wrapped_array', - 'name_string': 'name_string', - 'name_number': 'name_number', - 'name_integer': 'name_integer', - 'name_boolean': 'name_boolean', - 'name_array': 'name_array', - 'name_wrapped_array': 'name_wrapped_array', - 'prefix_string': 'prefix_string', - 'prefix_number': 'prefix_number', - 'prefix_integer': 'prefix_integer', - 'prefix_boolean': 'prefix_boolean', - 'prefix_array': 'prefix_array', - 'prefix_wrapped_array': 'prefix_wrapped_array', - 'namespace_string': 'namespace_string', - 'namespace_number': 'namespace_number', - 'namespace_integer': 'namespace_integer', - 'namespace_boolean': 'namespace_boolean', - 'namespace_array': 'namespace_array', - 'namespace_wrapped_array': 'namespace_wrapped_array', - 'prefix_ns_string': 'prefix_ns_string', - 'prefix_ns_number': 'prefix_ns_number', - 'prefix_ns_integer': 'prefix_ns_integer', - 'prefix_ns_boolean': 'prefix_ns_boolean', - 'prefix_ns_array': 'prefix_ns_array', - 'prefix_ns_wrapped_array': 'prefix_ns_wrapped_array' + 'attribute_string': 'attribute_string', # noqa: E501 + 'attribute_number': 'attribute_number', # noqa: E501 + 'attribute_integer': 'attribute_integer', # noqa: E501 + 'attribute_boolean': 'attribute_boolean', # noqa: E501 + 'wrapped_array': 'wrapped_array', # noqa: E501 + 'name_string': 'name_string', # noqa: E501 + 'name_number': 'name_number', # noqa: E501 + 'name_integer': 'name_integer', # noqa: E501 + 'name_boolean': 'name_boolean', # noqa: E501 + 'name_array': 'name_array', # noqa: E501 + 'name_wrapped_array': 'name_wrapped_array', # noqa: E501 + 'prefix_string': 'prefix_string', # noqa: E501 + 'prefix_number': 'prefix_number', # noqa: E501 + 'prefix_integer': 'prefix_integer', # noqa: E501 + 'prefix_boolean': 'prefix_boolean', # noqa: E501 + 'prefix_array': 'prefix_array', # noqa: E501 + 'prefix_wrapped_array': 'prefix_wrapped_array', # noqa: E501 + 'namespace_string': 'namespace_string', # noqa: E501 + 'namespace_number': 'namespace_number', # noqa: E501 + 'namespace_integer': 'namespace_integer', # noqa: E501 + 'namespace_boolean': 'namespace_boolean', # noqa: E501 + 'namespace_array': 'namespace_array', # noqa: E501 + 'namespace_wrapped_array': 'namespace_wrapped_array', # noqa: E501 + 'prefix_ns_string': 'prefix_ns_string', # noqa: E501 + 'prefix_ns_number': 'prefix_ns_number', # noqa: E501 + 'prefix_ns_integer': 'prefix_ns_integer', # noqa: E501 + 'prefix_ns_boolean': 'prefix_ns_boolean', # noqa: E501 + 'prefix_ns_array': 'prefix_ns_array', # noqa: E501 + 'prefix_ns_wrapped_array': 'prefix_ns_wrapped_array' # noqa: E501 } - def __init__(self, attribute_string=None, attribute_number=None, attribute_integer=None, attribute_boolean=None, wrapped_array=None, name_string=None, name_number=None, name_integer=None, name_boolean=None, name_array=None, name_wrapped_array=None, prefix_string=None, prefix_number=None, prefix_integer=None, prefix_boolean=None, prefix_array=None, prefix_wrapped_array=None, namespace_string=None, namespace_number=None, namespace_integer=None, namespace_boolean=None, namespace_array=None, namespace_wrapped_array=None, prefix_ns_string=None, prefix_ns_number=None, prefix_ns_integer=None, prefix_ns_boolean=None, prefix_ns_array=None, prefix_ns_wrapped_array=None): # noqa: E501 - """XmlItem - a model defined in OpenAPI""" # noqa: E501 - - self._attribute_string = None - self._attribute_number = None - self._attribute_integer = None - self._attribute_boolean = None - self._wrapped_array = None - self._name_string = None - self._name_number = None - self._name_integer = None - self._name_boolean = None - self._name_array = None - self._name_wrapped_array = None - self._prefix_string = None - self._prefix_number = None - self._prefix_integer = None - self._prefix_boolean = None - self._prefix_array = None - self._prefix_wrapped_array = None - self._namespace_string = None - self._namespace_number = None - self._namespace_integer = None - self._namespace_boolean = None - self._namespace_array = None - self._namespace_wrapped_array = None - self._prefix_ns_string = None - self._prefix_ns_number = None - self._prefix_ns_integer = None - self._prefix_ns_boolean = None - self._prefix_ns_array = None - self._prefix_ns_wrapped_array = None + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """XmlItem - 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 False + _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 + _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. + attribute_string (str): [optional] # noqa: E501 + attribute_number (float): [optional] # noqa: E501 + attribute_integer (int): [optional] # noqa: E501 + attribute_boolean (bool): [optional] # noqa: E501 + wrapped_array ([(int,)]): [optional] # noqa: E501 + name_string (str): [optional] # noqa: E501 + name_number (float): [optional] # noqa: E501 + name_integer (int): [optional] # noqa: E501 + name_boolean (bool): [optional] # noqa: E501 + name_array ([(int,)]): [optional] # noqa: E501 + name_wrapped_array ([(int,)]): [optional] # noqa: E501 + prefix_string (str): [optional] # noqa: E501 + prefix_number (float): [optional] # noqa: E501 + prefix_integer (int): [optional] # noqa: E501 + prefix_boolean (bool): [optional] # noqa: E501 + prefix_array ([(int,)]): [optional] # noqa: E501 + prefix_wrapped_array ([(int,)]): [optional] # noqa: E501 + namespace_string (str): [optional] # noqa: E501 + namespace_number (float): [optional] # noqa: E501 + namespace_integer (int): [optional] # noqa: E501 + namespace_boolean (bool): [optional] # noqa: E501 + namespace_array ([(int,)]): [optional] # noqa: E501 + namespace_wrapped_array ([(int,)]): [optional] # noqa: E501 + prefix_ns_string (str): [optional] # noqa: E501 + prefix_ns_number (float): [optional] # noqa: E501 + prefix_ns_integer (int): [optional] # noqa: E501 + prefix_ns_boolean (bool): [optional] # noqa: E501 + prefix_ns_array ([(int,)]): [optional] # noqa: E501 + prefix_ns_wrapped_array ([(int,)]): [optional] # noqa: E501 + """ + + self._data_store = {} self.discriminator = None - - if attribute_string is not None: - self.attribute_string = attribute_string - if attribute_number is not None: - self.attribute_number = attribute_number - if attribute_integer is not None: - self.attribute_integer = attribute_integer - if attribute_boolean is not None: - self.attribute_boolean = attribute_boolean - if wrapped_array is not None: - self.wrapped_array = wrapped_array - if name_string is not None: - self.name_string = name_string - if name_number is not None: - self.name_number = name_number - if name_integer is not None: - self.name_integer = name_integer - if name_boolean is not None: - self.name_boolean = name_boolean - if name_array is not None: - self.name_array = name_array - if name_wrapped_array is not None: - self.name_wrapped_array = name_wrapped_array - if prefix_string is not None: - self.prefix_string = prefix_string - if prefix_number is not None: - self.prefix_number = prefix_number - if prefix_integer is not None: - self.prefix_integer = prefix_integer - if prefix_boolean is not None: - self.prefix_boolean = prefix_boolean - if prefix_array is not None: - self.prefix_array = prefix_array - if prefix_wrapped_array is not None: - self.prefix_wrapped_array = prefix_wrapped_array - if namespace_string is not None: - self.namespace_string = namespace_string - if namespace_number is not None: - self.namespace_number = namespace_number - if namespace_integer is not None: - self.namespace_integer = namespace_integer - if namespace_boolean is not None: - self.namespace_boolean = namespace_boolean - if namespace_array is not None: - self.namespace_array = namespace_array - if namespace_wrapped_array is not None: - self.namespace_wrapped_array = namespace_wrapped_array - if prefix_ns_string is not None: - self.prefix_ns_string = prefix_ns_string - if prefix_ns_number is not None: - self.prefix_ns_number = prefix_ns_number - if prefix_ns_integer is not None: - self.prefix_ns_integer = prefix_ns_integer - if prefix_ns_boolean is not None: - self.prefix_ns_boolean = prefix_ns_boolean - if prefix_ns_array is not None: - self.prefix_ns_array = prefix_ns_array - if prefix_ns_wrapped_array is not None: - self.prefix_ns_wrapped_array = prefix_ns_wrapped_array + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def attribute_string(self): """Gets the attribute_string of this XmlItem. # noqa: E501 - :return: The attribute_string of this XmlItem. # noqa: E501 - :rtype: str + Returns: + (str): The attribute_string of this XmlItem. # noqa: E501 """ - return self._attribute_string + return self._data_store.get('attribute_string') @attribute_string.setter - def attribute_string(self, attribute_string): + def attribute_string( + self, attribute_string): """Sets the attribute_string of this XmlItem. - :param attribute_string: The attribute_string of this XmlItem. # noqa: E501 - :type: str + Returns: + (str): The attribute_string of this XmlItem. # noqa: E501 """ - self._attribute_string = attribute_string + self.__setitem__( + 'attribute_string', + attribute_string + ) @property def attribute_number(self): """Gets the attribute_number of this XmlItem. # noqa: E501 - :return: The attribute_number of this XmlItem. # noqa: E501 - :rtype: float + Returns: + (float): The attribute_number of this XmlItem. # noqa: E501 """ - return self._attribute_number + return self._data_store.get('attribute_number') @attribute_number.setter - def attribute_number(self, attribute_number): + def attribute_number( + self, attribute_number): """Sets the attribute_number of this XmlItem. - :param attribute_number: The attribute_number of this XmlItem. # noqa: E501 - :type: float + Returns: + (float): The attribute_number of this XmlItem. # noqa: E501 """ - self._attribute_number = attribute_number + self.__setitem__( + 'attribute_number', + attribute_number + ) @property def attribute_integer(self): """Gets the attribute_integer of this XmlItem. # noqa: E501 - :return: The attribute_integer of this XmlItem. # noqa: E501 - :rtype: int + Returns: + (int): The attribute_integer of this XmlItem. # noqa: E501 """ - return self._attribute_integer + return self._data_store.get('attribute_integer') @attribute_integer.setter - def attribute_integer(self, attribute_integer): + def attribute_integer( + self, attribute_integer): """Sets the attribute_integer of this XmlItem. - :param attribute_integer: The attribute_integer of this XmlItem. # noqa: E501 - :type: int + Returns: + (int): The attribute_integer of this XmlItem. # noqa: E501 """ - self._attribute_integer = attribute_integer + self.__setitem__( + 'attribute_integer', + attribute_integer + ) @property def attribute_boolean(self): """Gets the attribute_boolean of this XmlItem. # noqa: E501 - :return: The attribute_boolean of this XmlItem. # noqa: E501 - :rtype: bool + Returns: + (bool): The attribute_boolean of this XmlItem. # noqa: E501 """ - return self._attribute_boolean + return self._data_store.get('attribute_boolean') @attribute_boolean.setter - def attribute_boolean(self, attribute_boolean): + def attribute_boolean( + self, attribute_boolean): """Sets the attribute_boolean of this XmlItem. - :param attribute_boolean: The attribute_boolean of this XmlItem. # noqa: E501 - :type: bool + Returns: + (bool): The attribute_boolean of this XmlItem. # noqa: E501 """ - self._attribute_boolean = attribute_boolean + self.__setitem__( + 'attribute_boolean', + attribute_boolean + ) @property def wrapped_array(self): """Gets the wrapped_array of this XmlItem. # noqa: E501 - :return: The wrapped_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The wrapped_array of this XmlItem. # noqa: E501 """ - return self._wrapped_array + return self._data_store.get('wrapped_array') @wrapped_array.setter - def wrapped_array(self, wrapped_array): + def wrapped_array( + self, wrapped_array): """Sets the wrapped_array of this XmlItem. - :param wrapped_array: The wrapped_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The wrapped_array of this XmlItem. # noqa: E501 """ - self._wrapped_array = wrapped_array + self.__setitem__( + 'wrapped_array', + wrapped_array + ) @property def name_string(self): """Gets the name_string of this XmlItem. # noqa: E501 - :return: The name_string of this XmlItem. # noqa: E501 - :rtype: str + Returns: + (str): The name_string of this XmlItem. # noqa: E501 """ - return self._name_string + return self._data_store.get('name_string') @name_string.setter - def name_string(self, name_string): + def name_string( + self, name_string): """Sets the name_string of this XmlItem. - :param name_string: The name_string of this XmlItem. # noqa: E501 - :type: str + Returns: + (str): The name_string of this XmlItem. # noqa: E501 """ - self._name_string = name_string + self.__setitem__( + 'name_string', + name_string + ) @property def name_number(self): """Gets the name_number of this XmlItem. # noqa: E501 - :return: The name_number of this XmlItem. # noqa: E501 - :rtype: float + Returns: + (float): The name_number of this XmlItem. # noqa: E501 """ - return self._name_number + return self._data_store.get('name_number') @name_number.setter - def name_number(self, name_number): + def name_number( + self, name_number): """Sets the name_number of this XmlItem. - :param name_number: The name_number of this XmlItem. # noqa: E501 - :type: float + Returns: + (float): The name_number of this XmlItem. # noqa: E501 """ - self._name_number = name_number + self.__setitem__( + 'name_number', + name_number + ) @property def name_integer(self): """Gets the name_integer of this XmlItem. # noqa: E501 - :return: The name_integer of this XmlItem. # noqa: E501 - :rtype: int + Returns: + (int): The name_integer of this XmlItem. # noqa: E501 """ - return self._name_integer + return self._data_store.get('name_integer') @name_integer.setter - def name_integer(self, name_integer): + def name_integer( + self, name_integer): """Sets the name_integer of this XmlItem. - :param name_integer: The name_integer of this XmlItem. # noqa: E501 - :type: int + Returns: + (int): The name_integer of this XmlItem. # noqa: E501 """ - self._name_integer = name_integer + self.__setitem__( + 'name_integer', + name_integer + ) @property def name_boolean(self): """Gets the name_boolean of this XmlItem. # noqa: E501 - :return: The name_boolean of this XmlItem. # noqa: E501 - :rtype: bool + Returns: + (bool): The name_boolean of this XmlItem. # noqa: E501 """ - return self._name_boolean + return self._data_store.get('name_boolean') @name_boolean.setter - def name_boolean(self, name_boolean): + def name_boolean( + self, name_boolean): """Sets the name_boolean of this XmlItem. - :param name_boolean: The name_boolean of this XmlItem. # noqa: E501 - :type: bool + Returns: + (bool): The name_boolean of this XmlItem. # noqa: E501 """ - self._name_boolean = name_boolean + self.__setitem__( + 'name_boolean', + name_boolean + ) @property def name_array(self): """Gets the name_array of this XmlItem. # noqa: E501 - :return: The name_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The name_array of this XmlItem. # noqa: E501 """ - return self._name_array + return self._data_store.get('name_array') @name_array.setter - def name_array(self, name_array): + def name_array( + self, name_array): """Sets the name_array of this XmlItem. - :param name_array: The name_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The name_array of this XmlItem. # noqa: E501 """ - self._name_array = name_array + self.__setitem__( + 'name_array', + name_array + ) @property def name_wrapped_array(self): """Gets the name_wrapped_array of this XmlItem. # noqa: E501 - :return: The name_wrapped_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The name_wrapped_array of this XmlItem. # noqa: E501 """ - return self._name_wrapped_array + return self._data_store.get('name_wrapped_array') @name_wrapped_array.setter - def name_wrapped_array(self, name_wrapped_array): + def name_wrapped_array( + self, name_wrapped_array): """Sets the name_wrapped_array of this XmlItem. - :param name_wrapped_array: The name_wrapped_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The name_wrapped_array of this XmlItem. # noqa: E501 """ - self._name_wrapped_array = name_wrapped_array + self.__setitem__( + 'name_wrapped_array', + name_wrapped_array + ) @property def prefix_string(self): """Gets the prefix_string of this XmlItem. # noqa: E501 - :return: The prefix_string of this XmlItem. # noqa: E501 - :rtype: str + Returns: + (str): The prefix_string of this XmlItem. # noqa: E501 """ - return self._prefix_string + return self._data_store.get('prefix_string') @prefix_string.setter - def prefix_string(self, prefix_string): + def prefix_string( + self, prefix_string): """Sets the prefix_string of this XmlItem. - :param prefix_string: The prefix_string of this XmlItem. # noqa: E501 - :type: str + Returns: + (str): The prefix_string of this XmlItem. # noqa: E501 """ - self._prefix_string = prefix_string + self.__setitem__( + 'prefix_string', + prefix_string + ) @property def prefix_number(self): """Gets the prefix_number of this XmlItem. # noqa: E501 - :return: The prefix_number of this XmlItem. # noqa: E501 - :rtype: float + Returns: + (float): The prefix_number of this XmlItem. # noqa: E501 """ - return self._prefix_number + return self._data_store.get('prefix_number') @prefix_number.setter - def prefix_number(self, prefix_number): + def prefix_number( + self, prefix_number): """Sets the prefix_number of this XmlItem. - :param prefix_number: The prefix_number of this XmlItem. # noqa: E501 - :type: float + Returns: + (float): The prefix_number of this XmlItem. # noqa: E501 """ - self._prefix_number = prefix_number + self.__setitem__( + 'prefix_number', + prefix_number + ) @property def prefix_integer(self): """Gets the prefix_integer of this XmlItem. # noqa: E501 - :return: The prefix_integer of this XmlItem. # noqa: E501 - :rtype: int + Returns: + (int): The prefix_integer of this XmlItem. # noqa: E501 """ - return self._prefix_integer + return self._data_store.get('prefix_integer') @prefix_integer.setter - def prefix_integer(self, prefix_integer): + def prefix_integer( + self, prefix_integer): """Sets the prefix_integer of this XmlItem. - :param prefix_integer: The prefix_integer of this XmlItem. # noqa: E501 - :type: int + Returns: + (int): The prefix_integer of this XmlItem. # noqa: E501 """ - self._prefix_integer = prefix_integer + self.__setitem__( + 'prefix_integer', + prefix_integer + ) @property def prefix_boolean(self): """Gets the prefix_boolean of this XmlItem. # noqa: E501 - :return: The prefix_boolean of this XmlItem. # noqa: E501 - :rtype: bool + Returns: + (bool): The prefix_boolean of this XmlItem. # noqa: E501 """ - return self._prefix_boolean + return self._data_store.get('prefix_boolean') @prefix_boolean.setter - def prefix_boolean(self, prefix_boolean): + def prefix_boolean( + self, prefix_boolean): """Sets the prefix_boolean of this XmlItem. - :param prefix_boolean: The prefix_boolean of this XmlItem. # noqa: E501 - :type: bool + Returns: + (bool): The prefix_boolean of this XmlItem. # noqa: E501 """ - self._prefix_boolean = prefix_boolean + self.__setitem__( + 'prefix_boolean', + prefix_boolean + ) @property def prefix_array(self): """Gets the prefix_array of this XmlItem. # noqa: E501 - :return: The prefix_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The prefix_array of this XmlItem. # noqa: E501 """ - return self._prefix_array + return self._data_store.get('prefix_array') @prefix_array.setter - def prefix_array(self, prefix_array): + def prefix_array( + self, prefix_array): """Sets the prefix_array of this XmlItem. - :param prefix_array: The prefix_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The prefix_array of this XmlItem. # noqa: E501 """ - self._prefix_array = prefix_array + self.__setitem__( + 'prefix_array', + prefix_array + ) @property def prefix_wrapped_array(self): """Gets the prefix_wrapped_array of this XmlItem. # noqa: E501 - :return: The prefix_wrapped_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The prefix_wrapped_array of this XmlItem. # noqa: E501 """ - return self._prefix_wrapped_array + return self._data_store.get('prefix_wrapped_array') @prefix_wrapped_array.setter - def prefix_wrapped_array(self, prefix_wrapped_array): + def prefix_wrapped_array( + self, prefix_wrapped_array): """Sets the prefix_wrapped_array of this XmlItem. - :param prefix_wrapped_array: The prefix_wrapped_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The prefix_wrapped_array of this XmlItem. # noqa: E501 """ - self._prefix_wrapped_array = prefix_wrapped_array + self.__setitem__( + 'prefix_wrapped_array', + prefix_wrapped_array + ) @property def namespace_string(self): """Gets the namespace_string of this XmlItem. # noqa: E501 - :return: The namespace_string of this XmlItem. # noqa: E501 - :rtype: str + Returns: + (str): The namespace_string of this XmlItem. # noqa: E501 """ - return self._namespace_string + return self._data_store.get('namespace_string') @namespace_string.setter - def namespace_string(self, namespace_string): + def namespace_string( + self, namespace_string): """Sets the namespace_string of this XmlItem. - :param namespace_string: The namespace_string of this XmlItem. # noqa: E501 - :type: str + Returns: + (str): The namespace_string of this XmlItem. # noqa: E501 """ - self._namespace_string = namespace_string + self.__setitem__( + 'namespace_string', + namespace_string + ) @property def namespace_number(self): """Gets the namespace_number of this XmlItem. # noqa: E501 - :return: The namespace_number of this XmlItem. # noqa: E501 - :rtype: float + Returns: + (float): The namespace_number of this XmlItem. # noqa: E501 """ - return self._namespace_number + return self._data_store.get('namespace_number') @namespace_number.setter - def namespace_number(self, namespace_number): + def namespace_number( + self, namespace_number): """Sets the namespace_number of this XmlItem. - :param namespace_number: The namespace_number of this XmlItem. # noqa: E501 - :type: float + Returns: + (float): The namespace_number of this XmlItem. # noqa: E501 """ - self._namespace_number = namespace_number + self.__setitem__( + 'namespace_number', + namespace_number + ) @property def namespace_integer(self): """Gets the namespace_integer of this XmlItem. # noqa: E501 - :return: The namespace_integer of this XmlItem. # noqa: E501 - :rtype: int + Returns: + (int): The namespace_integer of this XmlItem. # noqa: E501 """ - return self._namespace_integer + return self._data_store.get('namespace_integer') @namespace_integer.setter - def namespace_integer(self, namespace_integer): + def namespace_integer( + self, namespace_integer): """Sets the namespace_integer of this XmlItem. - :param namespace_integer: The namespace_integer of this XmlItem. # noqa: E501 - :type: int + Returns: + (int): The namespace_integer of this XmlItem. # noqa: E501 """ - self._namespace_integer = namespace_integer + self.__setitem__( + 'namespace_integer', + namespace_integer + ) @property def namespace_boolean(self): """Gets the namespace_boolean of this XmlItem. # noqa: E501 - :return: The namespace_boolean of this XmlItem. # noqa: E501 - :rtype: bool + Returns: + (bool): The namespace_boolean of this XmlItem. # noqa: E501 """ - return self._namespace_boolean + return self._data_store.get('namespace_boolean') @namespace_boolean.setter - def namespace_boolean(self, namespace_boolean): + def namespace_boolean( + self, namespace_boolean): """Sets the namespace_boolean of this XmlItem. - :param namespace_boolean: The namespace_boolean of this XmlItem. # noqa: E501 - :type: bool + Returns: + (bool): The namespace_boolean of this XmlItem. # noqa: E501 """ - self._namespace_boolean = namespace_boolean + self.__setitem__( + 'namespace_boolean', + namespace_boolean + ) @property def namespace_array(self): """Gets the namespace_array of this XmlItem. # noqa: E501 - :return: The namespace_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The namespace_array of this XmlItem. # noqa: E501 """ - return self._namespace_array + return self._data_store.get('namespace_array') @namespace_array.setter - def namespace_array(self, namespace_array): + def namespace_array( + self, namespace_array): """Sets the namespace_array of this XmlItem. - :param namespace_array: The namespace_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The namespace_array of this XmlItem. # noqa: E501 """ - self._namespace_array = namespace_array + self.__setitem__( + 'namespace_array', + namespace_array + ) @property def namespace_wrapped_array(self): """Gets the namespace_wrapped_array of this XmlItem. # noqa: E501 - :return: The namespace_wrapped_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The namespace_wrapped_array of this XmlItem. # noqa: E501 """ - return self._namespace_wrapped_array + return self._data_store.get('namespace_wrapped_array') @namespace_wrapped_array.setter - def namespace_wrapped_array(self, namespace_wrapped_array): + def namespace_wrapped_array( + self, namespace_wrapped_array): """Sets the namespace_wrapped_array of this XmlItem. - :param namespace_wrapped_array: The namespace_wrapped_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The namespace_wrapped_array of this XmlItem. # noqa: E501 """ - self._namespace_wrapped_array = namespace_wrapped_array + self.__setitem__( + 'namespace_wrapped_array', + namespace_wrapped_array + ) @property def prefix_ns_string(self): """Gets the prefix_ns_string of this XmlItem. # noqa: E501 - :return: The prefix_ns_string of this XmlItem. # noqa: E501 - :rtype: str + Returns: + (str): The prefix_ns_string of this XmlItem. # noqa: E501 """ - return self._prefix_ns_string + return self._data_store.get('prefix_ns_string') @prefix_ns_string.setter - def prefix_ns_string(self, prefix_ns_string): + def prefix_ns_string( + self, prefix_ns_string): """Sets the prefix_ns_string of this XmlItem. - :param prefix_ns_string: The prefix_ns_string of this XmlItem. # noqa: E501 - :type: str + Returns: + (str): The prefix_ns_string of this XmlItem. # noqa: E501 """ - self._prefix_ns_string = prefix_ns_string + self.__setitem__( + 'prefix_ns_string', + prefix_ns_string + ) @property def prefix_ns_number(self): """Gets the prefix_ns_number of this XmlItem. # noqa: E501 - :return: The prefix_ns_number of this XmlItem. # noqa: E501 - :rtype: float + Returns: + (float): The prefix_ns_number of this XmlItem. # noqa: E501 """ - return self._prefix_ns_number + return self._data_store.get('prefix_ns_number') @prefix_ns_number.setter - def prefix_ns_number(self, prefix_ns_number): + def prefix_ns_number( + self, prefix_ns_number): """Sets the prefix_ns_number of this XmlItem. - :param prefix_ns_number: The prefix_ns_number of this XmlItem. # noqa: E501 - :type: float + Returns: + (float): The prefix_ns_number of this XmlItem. # noqa: E501 """ - self._prefix_ns_number = prefix_ns_number + self.__setitem__( + 'prefix_ns_number', + prefix_ns_number + ) @property def prefix_ns_integer(self): """Gets the prefix_ns_integer of this XmlItem. # noqa: E501 - :return: The prefix_ns_integer of this XmlItem. # noqa: E501 - :rtype: int + Returns: + (int): The prefix_ns_integer of this XmlItem. # noqa: E501 """ - return self._prefix_ns_integer + return self._data_store.get('prefix_ns_integer') @prefix_ns_integer.setter - def prefix_ns_integer(self, prefix_ns_integer): + def prefix_ns_integer( + self, prefix_ns_integer): """Sets the prefix_ns_integer of this XmlItem. - :param prefix_ns_integer: The prefix_ns_integer of this XmlItem. # noqa: E501 - :type: int + Returns: + (int): The prefix_ns_integer of this XmlItem. # noqa: E501 """ - self._prefix_ns_integer = prefix_ns_integer + self.__setitem__( + 'prefix_ns_integer', + prefix_ns_integer + ) @property def prefix_ns_boolean(self): """Gets the prefix_ns_boolean of this XmlItem. # noqa: E501 - :return: The prefix_ns_boolean of this XmlItem. # noqa: E501 - :rtype: bool + Returns: + (bool): The prefix_ns_boolean of this XmlItem. # noqa: E501 """ - return self._prefix_ns_boolean + return self._data_store.get('prefix_ns_boolean') @prefix_ns_boolean.setter - def prefix_ns_boolean(self, prefix_ns_boolean): + def prefix_ns_boolean( + self, prefix_ns_boolean): """Sets the prefix_ns_boolean of this XmlItem. - :param prefix_ns_boolean: The prefix_ns_boolean of this XmlItem. # noqa: E501 - :type: bool + Returns: + (bool): The prefix_ns_boolean of this XmlItem. # noqa: E501 """ - self._prefix_ns_boolean = prefix_ns_boolean + self.__setitem__( + 'prefix_ns_boolean', + prefix_ns_boolean + ) @property def prefix_ns_array(self): """Gets the prefix_ns_array of this XmlItem. # noqa: E501 - :return: The prefix_ns_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The prefix_ns_array of this XmlItem. # noqa: E501 """ - return self._prefix_ns_array + return self._data_store.get('prefix_ns_array') @prefix_ns_array.setter - def prefix_ns_array(self, prefix_ns_array): + def prefix_ns_array( + self, prefix_ns_array): """Sets the prefix_ns_array of this XmlItem. - :param prefix_ns_array: The prefix_ns_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The prefix_ns_array of this XmlItem. # noqa: E501 """ - self._prefix_ns_array = prefix_ns_array + self.__setitem__( + 'prefix_ns_array', + prefix_ns_array + ) @property def prefix_ns_wrapped_array(self): """Gets the prefix_ns_wrapped_array of this XmlItem. # noqa: E501 - :return: The prefix_ns_wrapped_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The prefix_ns_wrapped_array of this XmlItem. # noqa: E501 """ - return self._prefix_ns_wrapped_array + return self._data_store.get('prefix_ns_wrapped_array') @prefix_ns_wrapped_array.setter - def prefix_ns_wrapped_array(self, prefix_ns_wrapped_array): + def prefix_ns_wrapped_array( + self, prefix_ns_wrapped_array): """Sets the prefix_ns_wrapped_array of this XmlItem. - :param prefix_ns_wrapped_array: The prefix_ns_wrapped_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The prefix_ns_wrapped_array of this XmlItem. # noqa: E501 """ - self._prefix_ns_wrapped_array = prefix_ns_wrapped_array + self.__setitem__( + 'prefix_ns_wrapped_array', + prefix_ns_wrapped_array + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-asyncio/petstore_api/rest.py b/samples/client/petstore/python-asyncio/petstore_api/rest.py index fdb9d73c80ea..fe10c556b62c 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/rest.py +++ b/samples/client/petstore/python-asyncio/petstore_api/rest.py @@ -22,6 +22,8 @@ # python 2 and python 3 compatibility library from six.moves.urllib.parse import urlencode +from petstore_api.exceptions import ApiException, ApiValueError + logger = logging.getLogger(__name__) @@ -108,7 +110,7 @@ async def request(self, method, url, query_params=None, headers=None, 'PATCH', 'OPTIONS'] if post_params and body: - raise ValueError( + raise ApiValueError( "body parameter cannot be used with post_params parameter." ) @@ -246,30 +248,3 @@ async def PATCH(self, url, headers=None, query_params=None, _preload_content=_preload_content, _request_timeout=_request_timeout, body=body)) - - -class ApiException(Exception): - - 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})\nReason: {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 diff --git a/samples/client/petstore/python-asyncio/requirements.txt b/samples/client/petstore/python-asyncio/requirements.txt index bafdc07532f5..2e252c8a0833 100644 --- a/samples/client/petstore/python-asyncio/requirements.txt +++ b/samples/client/petstore/python-asyncio/requirements.txt @@ -1,5 +1,6 @@ certifi >= 14.05.14 -six >= 1.10 +future; python_version<="2.7" python_dateutil >= 2.5.3 setuptools >= 21.0.0 +six >= 1.10 urllib3 >= 1.15.1 diff --git a/samples/client/petstore/python-asyncio/setup.py b/samples/client/petstore/python-asyncio/setup.py index cf456a759e66..ba7a1c2e0156 100644 --- a/samples/client/petstore/python-asyncio/setup.py +++ b/samples/client/petstore/python-asyncio/setup.py @@ -32,6 +32,11 @@ url="", keywords=["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"], install_requires=REQUIRES, + extras_require={ + ':python_version <= "2.7"': [ + 'future', + ], + }, packages=find_packages(), include_package_data=True, long_description="""\ diff --git a/samples/client/petstore/python-asyncio/test/test_additional_properties_any_type.py b/samples/client/petstore/python-asyncio/test/test_additional_properties_any_type.py new file mode 100644 index 000000000000..4b6739a1faf3 --- /dev/null +++ b/samples/client/petstore/python-asyncio/test/test_additional_properties_any_type.py @@ -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.additional_properties_any_type import AdditionalPropertiesAnyType # noqa: E501 +from petstore_api.rest import ApiException + + +class TestAdditionalPropertiesAnyType(unittest.TestCase): + """AdditionalPropertiesAnyType unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testAdditionalPropertiesAnyType(self): + """Test AdditionalPropertiesAnyType""" + # FIXME: construct object with mandatory attributes with example values + # model = petstore_api.models.additional_properties_any_type.AdditionalPropertiesAnyType() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python-asyncio/test/test_additional_properties_array.py b/samples/client/petstore/python-asyncio/test/test_additional_properties_array.py new file mode 100644 index 000000000000..c4cf43499cfa --- /dev/null +++ b/samples/client/petstore/python-asyncio/test/test_additional_properties_array.py @@ -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.additional_properties_array import AdditionalPropertiesArray # noqa: E501 +from petstore_api.rest import ApiException + + +class TestAdditionalPropertiesArray(unittest.TestCase): + """AdditionalPropertiesArray unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testAdditionalPropertiesArray(self): + """Test AdditionalPropertiesArray""" + # FIXME: construct object with mandatory attributes with example values + # model = petstore_api.models.additional_properties_array.AdditionalPropertiesArray() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python-asyncio/test/test_additional_properties_boolean.py b/samples/client/petstore/python-asyncio/test/test_additional_properties_boolean.py new file mode 100644 index 000000000000..cc3cecc8522f --- /dev/null +++ b/samples/client/petstore/python-asyncio/test/test_additional_properties_boolean.py @@ -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.additional_properties_boolean import AdditionalPropertiesBoolean # noqa: E501 +from petstore_api.rest import ApiException + + +class TestAdditionalPropertiesBoolean(unittest.TestCase): + """AdditionalPropertiesBoolean unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testAdditionalPropertiesBoolean(self): + """Test AdditionalPropertiesBoolean""" + # FIXME: construct object with mandatory attributes with example values + # model = petstore_api.models.additional_properties_boolean.AdditionalPropertiesBoolean() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python-asyncio/test/test_additional_properties_integer.py b/samples/client/petstore/python-asyncio/test/test_additional_properties_integer.py new file mode 100644 index 000000000000..774c367b2109 --- /dev/null +++ b/samples/client/petstore/python-asyncio/test/test_additional_properties_integer.py @@ -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.additional_properties_integer import AdditionalPropertiesInteger # noqa: E501 +from petstore_api.rest import ApiException + + +class TestAdditionalPropertiesInteger(unittest.TestCase): + """AdditionalPropertiesInteger unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testAdditionalPropertiesInteger(self): + """Test AdditionalPropertiesInteger""" + # FIXME: construct object with mandatory attributes with example values + # model = petstore_api.models.additional_properties_integer.AdditionalPropertiesInteger() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python-asyncio/test/test_additional_properties_number.py b/samples/client/petstore/python-asyncio/test/test_additional_properties_number.py new file mode 100644 index 000000000000..0d370e781b36 --- /dev/null +++ b/samples/client/petstore/python-asyncio/test/test_additional_properties_number.py @@ -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.additional_properties_number import AdditionalPropertiesNumber # noqa: E501 +from petstore_api.rest import ApiException + + +class TestAdditionalPropertiesNumber(unittest.TestCase): + """AdditionalPropertiesNumber unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testAdditionalPropertiesNumber(self): + """Test AdditionalPropertiesNumber""" + # FIXME: construct object with mandatory attributes with example values + # model = petstore_api.models.additional_properties_number.AdditionalPropertiesNumber() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python-asyncio/test/test_additional_properties_object.py b/samples/client/petstore/python-asyncio/test/test_additional_properties_object.py new file mode 100644 index 000000000000..6e718b28cdef --- /dev/null +++ b/samples/client/petstore/python-asyncio/test/test_additional_properties_object.py @@ -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.additional_properties_object import AdditionalPropertiesObject # noqa: E501 +from petstore_api.rest import ApiException + + +class TestAdditionalPropertiesObject(unittest.TestCase): + """AdditionalPropertiesObject unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testAdditionalPropertiesObject(self): + """Test AdditionalPropertiesObject""" + # FIXME: construct object with mandatory attributes with example values + # model = petstore_api.models.additional_properties_object.AdditionalPropertiesObject() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python-asyncio/test/test_additional_properties_string.py b/samples/client/petstore/python-asyncio/test/test_additional_properties_string.py new file mode 100644 index 000000000000..a46cb3e256dc --- /dev/null +++ b/samples/client/petstore/python-asyncio/test/test_additional_properties_string.py @@ -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.additional_properties_string import AdditionalPropertiesString # noqa: E501 +from petstore_api.rest import ApiException + + +class TestAdditionalPropertiesString(unittest.TestCase): + """AdditionalPropertiesString unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testAdditionalPropertiesString(self): + """Test AdditionalPropertiesString""" + # FIXME: construct object with mandatory attributes with example values + # model = petstore_api.models.additional_properties_string.AdditionalPropertiesString() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python-tornado/README.md b/samples/client/petstore/python-tornado/README.md index 4c67e17b44c8..ce1fcee98043 100644 --- a/samples/client/petstore/python-tornado/README.md +++ b/samples/client/petstore/python-tornado/README.md @@ -111,7 +111,14 @@ Class | Method | HTTP request | Description ## Documentation For Models + - [AdditionalPropertiesAnyType](docs/AdditionalPropertiesAnyType.md) + - [AdditionalPropertiesArray](docs/AdditionalPropertiesArray.md) + - [AdditionalPropertiesBoolean](docs/AdditionalPropertiesBoolean.md) - [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md) + - [AdditionalPropertiesInteger](docs/AdditionalPropertiesInteger.md) + - [AdditionalPropertiesNumber](docs/AdditionalPropertiesNumber.md) + - [AdditionalPropertiesObject](docs/AdditionalPropertiesObject.md) + - [AdditionalPropertiesString](docs/AdditionalPropertiesString.md) - [Animal](docs/Animal.md) - [ApiResponse](docs/ApiResponse.md) - [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md) diff --git a/samples/client/petstore/python-tornado/docs/AdditionalPropertiesAnyType.md b/samples/client/petstore/python-tornado/docs/AdditionalPropertiesAnyType.md new file mode 100644 index 000000000000..9843d35ab906 --- /dev/null +++ b/samples/client/petstore/python-tornado/docs/AdditionalPropertiesAnyType.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesAnyType + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/AdditionalPropertiesArray.md b/samples/client/petstore/python-tornado/docs/AdditionalPropertiesArray.md new file mode 100644 index 000000000000..cfe09d91c726 --- /dev/null +++ b/samples/client/petstore/python-tornado/docs/AdditionalPropertiesArray.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesArray + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/AdditionalPropertiesBoolean.md b/samples/client/petstore/python-tornado/docs/AdditionalPropertiesBoolean.md new file mode 100644 index 000000000000..74f009554a7f --- /dev/null +++ b/samples/client/petstore/python-tornado/docs/AdditionalPropertiesBoolean.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesBoolean + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/AdditionalPropertiesClass.md b/samples/client/petstore/python-tornado/docs/AdditionalPropertiesClass.md index 796a789d4c4b..56326055a412 100644 --- a/samples/client/petstore/python-tornado/docs/AdditionalPropertiesClass.md +++ b/samples/client/petstore/python-tornado/docs/AdditionalPropertiesClass.md @@ -3,8 +3,17 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**map_property** | **dict(str, str)** | | [optional] -**map_of_map_property** | **dict(str, dict(str, str))** | | [optional] +**map_string** | **{str: (str,)}** | | [optional] +**map_number** | **{str: (float,)}** | | [optional] +**map_integer** | **{str: (int,)}** | | [optional] +**map_boolean** | **{str: (bool,)}** | | [optional] +**map_array_integer** | **{str: ([(int,)],)}** | | [optional] +**map_array_anytype** | **{str: ([(bool, date, datetime, dict, float, int, list, str)],)}** | | [optional] +**map_map_string** | **{str: ({str: (str,)},)}** | | [optional] +**map_map_anytype** | **{str: ({str: (bool, date, datetime, dict, float, int, list, str)},)}** | | [optional] +**anytype_1** | [**bool, date, datetime, dict, float, int, list, str**](.md) | | [optional] +**anytype_2** | [**bool, date, datetime, dict, float, int, list, str**](.md) | | [optional] +**anytype_3** | [**bool, date, datetime, dict, float, int, list, str**](.md) | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-tornado/docs/AdditionalPropertiesInteger.md b/samples/client/petstore/python-tornado/docs/AdditionalPropertiesInteger.md new file mode 100644 index 000000000000..a3e58fd1b0bd --- /dev/null +++ b/samples/client/petstore/python-tornado/docs/AdditionalPropertiesInteger.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesInteger + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/AdditionalPropertiesNumber.md b/samples/client/petstore/python-tornado/docs/AdditionalPropertiesNumber.md new file mode 100644 index 000000000000..37eafe1ff031 --- /dev/null +++ b/samples/client/petstore/python-tornado/docs/AdditionalPropertiesNumber.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesNumber + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/AdditionalPropertiesObject.md b/samples/client/petstore/python-tornado/docs/AdditionalPropertiesObject.md new file mode 100644 index 000000000000..7f4d6713c758 --- /dev/null +++ b/samples/client/petstore/python-tornado/docs/AdditionalPropertiesObject.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesObject + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/AdditionalPropertiesString.md b/samples/client/petstore/python-tornado/docs/AdditionalPropertiesString.md new file mode 100644 index 000000000000..9317cfeee80b --- /dev/null +++ b/samples/client/petstore/python-tornado/docs/AdditionalPropertiesString.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesString + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/ArrayOfArrayOfNumberOnly.md b/samples/client/petstore/python-tornado/docs/ArrayOfArrayOfNumberOnly.md index aa3988ab1679..323b6edc56b9 100644 --- a/samples/client/petstore/python-tornado/docs/ArrayOfArrayOfNumberOnly.md +++ b/samples/client/petstore/python-tornado/docs/ArrayOfArrayOfNumberOnly.md @@ -3,7 +3,7 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**array_array_number** | **list[list[float]]** | | [optional] +**array_array_number** | **[([(float,)],)]** | | [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/ArrayOfNumberOnly.md b/samples/client/petstore/python-tornado/docs/ArrayOfNumberOnly.md index 2c3de967aec6..502d335fcfc3 100644 --- a/samples/client/petstore/python-tornado/docs/ArrayOfNumberOnly.md +++ b/samples/client/petstore/python-tornado/docs/ArrayOfNumberOnly.md @@ -3,7 +3,7 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**array_number** | **list[float]** | | [optional] +**array_number** | **[(float,)]** | | [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/ArrayTest.md b/samples/client/petstore/python-tornado/docs/ArrayTest.md index 6ab0d1378065..d3a915da27c1 100644 --- a/samples/client/petstore/python-tornado/docs/ArrayTest.md +++ b/samples/client/petstore/python-tornado/docs/ArrayTest.md @@ -3,9 +3,9 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**array_of_string** | **list[str]** | | [optional] -**array_array_of_integer** | **list[list[int]]** | | [optional] -**array_array_of_model** | **list[list[ReadOnlyFirst]]** | | [optional] +**array_of_string** | **[(str,)]** | | [optional] +**array_array_of_integer** | **[([(int,)],)]** | | [optional] +**array_array_of_model** | **[([(ReadOnlyFirst,)],)]** | | [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/Cat.md b/samples/client/petstore/python-tornado/docs/Cat.md index 8d30565d014e..d052c5615b84 100644 --- a/samples/client/petstore/python-tornado/docs/Cat.md +++ b/samples/client/petstore/python-tornado/docs/Cat.md @@ -3,6 +3,8 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**class_name** | **str** | | +**color** | **str** | | [optional] [default to 'red'] **declawed** | **bool** | | [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/Dog.md b/samples/client/petstore/python-tornado/docs/Dog.md index f727487975c4..ac70f17e668a 100644 --- a/samples/client/petstore/python-tornado/docs/Dog.md +++ b/samples/client/petstore/python-tornado/docs/Dog.md @@ -3,6 +3,8 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**class_name** | **str** | | +**color** | **str** | | [optional] [default to 'red'] **breed** | **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/EnumArrays.md b/samples/client/petstore/python-tornado/docs/EnumArrays.md index e15a5f1fd049..4a87d6a62ea2 100644 --- a/samples/client/petstore/python-tornado/docs/EnumArrays.md +++ b/samples/client/petstore/python-tornado/docs/EnumArrays.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **just_symbol** | **str** | | [optional] -**array_enum** | **list[str]** | | [optional] +**array_enum** | **[(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/FakeApi.md b/samples/client/petstore/python-tornado/docs/FakeApi.md index c46bf1e49748..2a72ffe650da 100644 --- a/samples/client/petstore/python-tornado/docs/FakeApi.md +++ b/samples/client/petstore/python-tornado/docs/FakeApi.md @@ -434,7 +434,7 @@ int32 = 56 # int | None (optional) int64 = 56 # int | None (optional) float = 3.4 # float | None (optional) string = 'string_example' # str | None (optional) -binary = '/path/to/file' # file | None (optional) +binary = '/path/to/file' # file_type | None (optional) date = '2013-10-20' # date | None (optional) date_time = '2013-10-20T19:20:30+01:00' # datetime | None (optional) password = 'password_example' # str | None (optional) @@ -460,7 +460,7 @@ Name | Type | Description | Notes **int64** | **int**| None | [optional] **float** | **float**| None | [optional] **string** | **str**| None | [optional] - **binary** | **file**| None | [optional] + **binary** | **file_type**| None | [optional] **date** | **date**| None | [optional] **date_time** | **datetime**| None | [optional] **password** | **str**| None | [optional] @@ -499,13 +499,13 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.FakeApi() -enum_header_string_array = ['enum_header_string_array_example'] # list[str] | Header parameter enum test (string array) (optional) +enum_header_string_array = ['enum_header_string_array_example'] # [(str,)] | Header parameter enum test (string array) (optional) enum_header_string = '-efg' # str | Header parameter enum test (string) (optional) (default to '-efg') -enum_query_string_array = ['enum_query_string_array_example'] # list[str] | Query parameter enum test (string array) (optional) +enum_query_string_array = ['enum_query_string_array_example'] # [(str,)] | Query parameter enum test (string array) (optional) enum_query_string = '-efg' # str | Query parameter enum test (string) (optional) (default to '-efg') enum_query_integer = 56 # int | Query parameter enum test (double) (optional) enum_query_double = 3.4 # float | Query parameter enum test (double) (optional) -enum_form_string_array = '$' # list[str] | Form parameter enum test (string array) (optional) (default to '$') +enum_form_string_array = '$' # [(str,)] | Form parameter enum test (string array) (optional) (default to '$') enum_form_string = '-efg' # str | Form parameter enum test (string) (optional) (default to '-efg') try: @@ -519,13 +519,13 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **enum_header_string_array** | [**list[str]**](str.md)| Header parameter enum test (string array) | [optional] + **enum_header_string_array** | [**[(str,)]**](str.md)| Header parameter enum test (string array) | [optional] **enum_header_string** | **str**| Header parameter enum test (string) | [optional] [default to '-efg'] - **enum_query_string_array** | [**list[str]**](str.md)| Query parameter enum test (string array) | [optional] + **enum_query_string_array** | [**[(str,)]**](str.md)| Query parameter enum test (string array) | [optional] **enum_query_string** | **str**| Query parameter enum test (string) | [optional] [default to '-efg'] **enum_query_integer** | **int**| Query parameter enum test (double) | [optional] **enum_query_double** | **float**| Query parameter enum test (double) | [optional] - **enum_form_string_array** | [**list[str]**](str.md)| Form parameter enum test (string array) | [optional] [default to '$'] + **enum_form_string_array** | [**[(str,)]**](str.md)| Form parameter enum test (string array) | [optional] [default to '$'] **enum_form_string** | **str**| Form parameter enum test (string) | [optional] [default to '-efg'] ### Return type @@ -617,7 +617,7 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.FakeApi() -param = {'key': 'param_example'} # dict(str, str) | request body +param = {'key': 'param_example'} # {str: (str,)} | request body try: # test inline additionalProperties @@ -630,7 +630,7 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **param** | [**dict(str, str)**](str.md)| request body | + **param** | [**{str: (str,)}**](str.md)| request body | ### Return type diff --git a/samples/client/petstore/python-tornado/docs/FileSchemaTestClass.md b/samples/client/petstore/python-tornado/docs/FileSchemaTestClass.md index dc3722289887..73009bdb1bfb 100644 --- a/samples/client/petstore/python-tornado/docs/FileSchemaTestClass.md +++ b/samples/client/petstore/python-tornado/docs/FileSchemaTestClass.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **file** | [**File**](File.md) | | [optional] -**files** | [**list[File]**](File.md) | | [optional] +**files** | [**[(File,)]**](File.md) | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-tornado/docs/FormatTest.md b/samples/client/petstore/python-tornado/docs/FormatTest.md index 31d92e2a750e..5431d4e7169b 100644 --- a/samples/client/petstore/python-tornado/docs/FormatTest.md +++ b/samples/client/petstore/python-tornado/docs/FormatTest.md @@ -11,7 +11,7 @@ Name | Type | Description | Notes **double** | **float** | | [optional] **string** | **str** | | [optional] **byte** | **str** | | -**binary** | **file** | | [optional] +**binary** | **file_type** | | [optional] **date** | **date** | | **date_time** | **datetime** | | [optional] **uuid** | **str** | | [optional] diff --git a/samples/client/petstore/python-tornado/docs/MapTest.md b/samples/client/petstore/python-tornado/docs/MapTest.md index a5601691f885..c88c578cf82e 100644 --- a/samples/client/petstore/python-tornado/docs/MapTest.md +++ b/samples/client/petstore/python-tornado/docs/MapTest.md @@ -3,10 +3,10 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**map_map_of_string** | **dict(str, dict(str, str))** | | [optional] -**map_of_enum_string** | **dict(str, str)** | | [optional] -**direct_map** | **dict(str, bool)** | | [optional] -**indirect_map** | **dict(str, bool)** | | [optional] +**map_map_of_string** | **{str: ({str: (str,)},)}** | | [optional] +**map_of_enum_string** | **{str: (str,)}** | | [optional] +**direct_map** | **{str: (bool,)}** | | [optional] +**indirect_map** | **{str: (bool,)}** | | [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/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/client/petstore/python-tornado/docs/MixedPropertiesAndAdditionalPropertiesClass.md index b9808d5275e5..1484c0638d83 100644 --- a/samples/client/petstore/python-tornado/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/client/petstore/python-tornado/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -5,7 +5,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **uuid** | **str** | | [optional] **date_time** | **datetime** | | [optional] -**map** | [**dict(str, Animal)**](Animal.md) | | [optional] +**map** | [**{str: (Animal,)}**](Animal.md) | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-tornado/docs/Pet.md b/samples/client/petstore/python-tornado/docs/Pet.md index 9e15090300f8..745d5da843e7 100644 --- a/samples/client/petstore/python-tornado/docs/Pet.md +++ b/samples/client/petstore/python-tornado/docs/Pet.md @@ -6,8 +6,8 @@ Name | Type | Description | Notes **id** | **int** | | [optional] **category** | [**Category**](Category.md) | | [optional] **name** | **str** | | -**photo_urls** | **list[str]** | | -**tags** | [**list[Tag]**](Tag.md) | | [optional] +**photo_urls** | **[(str,)]** | | +**tags** | [**[(Tag,)]**](Tag.md) | | [optional] **status** | **str** | pet status in the store | [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/PetApi.md b/samples/client/petstore/python-tornado/docs/PetApi.md index 227fa2ada134..07d1016f42bb 100644 --- a/samples/client/petstore/python-tornado/docs/PetApi.md +++ b/samples/client/petstore/python-tornado/docs/PetApi.md @@ -118,7 +118,7 @@ void (empty response body) [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **find_pets_by_status** -> list[Pet] find_pets_by_status(status) +> [(Pet,)] find_pets_by_status(status) Finds Pets by status @@ -139,7 +139,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN' # create an instance of the API class api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration)) -status = ['status_example'] # list[str] | Status values that need to be considered for filter +status = ['status_example'] # [(str,)] | Status values that need to be considered for filter try: # Finds Pets by status @@ -153,11 +153,11 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **status** | [**list[str]**](str.md)| Status values that need to be considered for filter | + **status** | [**[(str,)]**](str.md)| Status values that need to be considered for filter | ### Return type -[**list[Pet]**](Pet.md) +[**[(Pet,)]**](Pet.md) ### Authorization @@ -171,7 +171,7 @@ Name | Type | Description | Notes [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **find_pets_by_tags** -> list[Pet] find_pets_by_tags(tags) +> [(Pet,)] find_pets_by_tags(tags) Finds Pets by tags @@ -192,7 +192,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN' # create an instance of the API class api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration)) -tags = ['tags_example'] # list[str] | Tags to filter by +tags = ['tags_example'] # [(str,)] | Tags to filter by try: # Finds Pets by tags @@ -206,11 +206,11 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **tags** | [**list[str]**](str.md)| Tags to filter by | + **tags** | [**[(str,)]**](str.md)| Tags to filter by | ### Return type -[**list[Pet]**](Pet.md) +[**[(Pet,)]**](Pet.md) ### Authorization @@ -404,7 +404,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN' api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration)) pet_id = 56 # int | ID of pet to update additional_metadata = 'additional_metadata_example' # str | Additional data to pass to server (optional) -file = '/path/to/file' # file | file to upload (optional) +file = '/path/to/file' # file_type | file to upload (optional) try: # uploads an image @@ -420,7 +420,7 @@ Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **pet_id** | **int**| ID of pet to update | **additional_metadata** | **str**| Additional data to pass to server | [optional] - **file** | **file**| file to upload | [optional] + **file** | **file_type**| file to upload | [optional] ### Return type @@ -458,7 +458,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN' # create an instance of the API class api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration)) pet_id = 56 # int | ID of pet to update -required_file = '/path/to/file' # file | file to upload +required_file = '/path/to/file' # file_type | file to upload additional_metadata = 'additional_metadata_example' # str | Additional data to pass to server (optional) try: @@ -474,7 +474,7 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **pet_id** | **int**| ID of pet to update | - **required_file** | **file**| file to upload | + **required_file** | **file_type**| file to upload | **additional_metadata** | **str**| Additional data to pass to server | [optional] ### Return type diff --git a/samples/client/petstore/python-tornado/docs/StoreApi.md b/samples/client/petstore/python-tornado/docs/StoreApi.md index af190f931d2e..ce0ef54222f1 100644 --- a/samples/client/petstore/python-tornado/docs/StoreApi.md +++ b/samples/client/petstore/python-tornado/docs/StoreApi.md @@ -59,7 +59,7 @@ No authorization required [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **get_inventory** -> dict(str, int) get_inventory() +> {str: (int,)} get_inventory() Returns pet inventories by status @@ -96,7 +96,7 @@ This endpoint does not need any parameter. ### Return type -**dict(str, int)** +**{str: (int,)}** ### Authorization diff --git a/samples/client/petstore/python-tornado/docs/TypeHolderDefault.md b/samples/client/petstore/python-tornado/docs/TypeHolderDefault.md index 861da021826a..3a6ba43b37c7 100644 --- a/samples/client/petstore/python-tornado/docs/TypeHolderDefault.md +++ b/samples/client/petstore/python-tornado/docs/TypeHolderDefault.md @@ -7,7 +7,7 @@ Name | Type | Description | Notes **number_item** | **float** | | **integer_item** | **int** | | **bool_item** | **bool** | | [default to True] -**array_item** | **list[int]** | | +**array_item** | **[(int,)]** | | [[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/TypeHolderExample.md b/samples/client/petstore/python-tornado/docs/TypeHolderExample.md index d59718cdcb16..0daefd05c50e 100644 --- a/samples/client/petstore/python-tornado/docs/TypeHolderExample.md +++ b/samples/client/petstore/python-tornado/docs/TypeHolderExample.md @@ -7,7 +7,7 @@ Name | Type | Description | Notes **number_item** | **float** | | **integer_item** | **int** | | **bool_item** | **bool** | | -**array_item** | **list[int]** | | +**array_item** | **[(int,)]** | | [[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/UserApi.md b/samples/client/petstore/python-tornado/docs/UserApi.md index 33e86f9e8fd2..2e27cf02301d 100644 --- a/samples/client/petstore/python-tornado/docs/UserApi.md +++ b/samples/client/petstore/python-tornado/docs/UserApi.md @@ -78,7 +78,7 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.UserApi() -body = NULL # list[User] | List of user object +body = NULL # [(User,)] | List of user object try: # Creates list of users with given input array @@ -91,7 +91,7 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **body** | [**list[User]**](list.md)| List of user object | + **body** | [**[(User,)]**](list.md)| List of user object | ### Return type @@ -124,7 +124,7 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.UserApi() -body = NULL # list[User] | List of user object +body = NULL # [(User,)] | List of user object try: # Creates list of users with given input array @@ -137,7 +137,7 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **body** | [**list[User]**](list.md)| List of user object | + **body** | [**[(User,)]**](list.md)| List of user object | ### Return type diff --git a/samples/client/petstore/python-tornado/docs/XmlItem.md b/samples/client/petstore/python-tornado/docs/XmlItem.md index 3dd09833fe52..185da1eb0119 100644 --- a/samples/client/petstore/python-tornado/docs/XmlItem.md +++ b/samples/client/petstore/python-tornado/docs/XmlItem.md @@ -7,31 +7,31 @@ Name | Type | Description | Notes **attribute_number** | **float** | | [optional] **attribute_integer** | **int** | | [optional] **attribute_boolean** | **bool** | | [optional] -**wrapped_array** | **list[int]** | | [optional] +**wrapped_array** | **[(int,)]** | | [optional] **name_string** | **str** | | [optional] **name_number** | **float** | | [optional] **name_integer** | **int** | | [optional] **name_boolean** | **bool** | | [optional] -**name_array** | **list[int]** | | [optional] -**name_wrapped_array** | **list[int]** | | [optional] +**name_array** | **[(int,)]** | | [optional] +**name_wrapped_array** | **[(int,)]** | | [optional] **prefix_string** | **str** | | [optional] **prefix_number** | **float** | | [optional] **prefix_integer** | **int** | | [optional] **prefix_boolean** | **bool** | | [optional] -**prefix_array** | **list[int]** | | [optional] -**prefix_wrapped_array** | **list[int]** | | [optional] +**prefix_array** | **[(int,)]** | | [optional] +**prefix_wrapped_array** | **[(int,)]** | | [optional] **namespace_string** | **str** | | [optional] **namespace_number** | **float** | | [optional] **namespace_integer** | **int** | | [optional] **namespace_boolean** | **bool** | | [optional] -**namespace_array** | **list[int]** | | [optional] -**namespace_wrapped_array** | **list[int]** | | [optional] +**namespace_array** | **[(int,)]** | | [optional] +**namespace_wrapped_array** | **[(int,)]** | | [optional] **prefix_ns_string** | **str** | | [optional] **prefix_ns_number** | **float** | | [optional] **prefix_ns_integer** | **int** | | [optional] **prefix_ns_boolean** | **bool** | | [optional] -**prefix_ns_array** | **list[int]** | | [optional] -**prefix_ns_wrapped_array** | **list[int]** | | [optional] +**prefix_ns_array** | **[(int,)]** | | [optional] +**prefix_ns_wrapped_array** | **[(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/__init__.py b/samples/client/petstore/python-tornado/petstore_api/__init__.py index cf9b1b0db3f9..516f759d02c3 100644 --- a/samples/client/petstore/python-tornado/petstore_api/__init__.py +++ b/samples/client/petstore/python-tornado/petstore_api/__init__.py @@ -28,7 +28,14 @@ from petstore_api.api_client import ApiClient from petstore_api.configuration import Configuration # import models into sdk package +from petstore_api.models.additional_properties_any_type import AdditionalPropertiesAnyType +from petstore_api.models.additional_properties_array import AdditionalPropertiesArray +from petstore_api.models.additional_properties_boolean import AdditionalPropertiesBoolean from petstore_api.models.additional_properties_class import AdditionalPropertiesClass +from petstore_api.models.additional_properties_integer import AdditionalPropertiesInteger +from petstore_api.models.additional_properties_number import AdditionalPropertiesNumber +from petstore_api.models.additional_properties_object import AdditionalPropertiesObject +from petstore_api.models.additional_properties_string import AdditionalPropertiesString from petstore_api.models.animal import Animal from petstore_api.models.api_response import ApiResponse from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly diff --git a/samples/client/petstore/python-tornado/petstore_api/api/another_fake_api.py b/samples/client/petstore/python-tornado/petstore_api/api/another_fake_api.py index 9fd3f816b9ca..058210d0bd4d 100644 --- a/samples/client/petstore/python-tornado/petstore_api/api/another_fake_api.py +++ b/samples/client/petstore/python-tornado/petstore_api/api/another_fake_api.py @@ -18,6 +18,20 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.client import Client class AnotherFakeApi(object): @@ -32,7 +46,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def call_123_test_special_tags(self, body, **kwargs): # noqa: E501 + def call_123_test_special_tags(self, body, _check_type=False, **kwargs): # noqa: E501 """To test special tags # noqa: E501 To test special tags and operation ID starting with number # noqa: E501 @@ -49,12 +63,12 @@ def call_123_test_special_tags(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.call_123_test_special_tags_with_http_info(body, **kwargs) # noqa: E501 + return self.call_123_test_special_tags_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.call_123_test_special_tags_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.call_123_test_special_tags_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E501 + def call_123_test_special_tags_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """To test special tags # noqa: E501 To test special tags and operation ID starting with number # noqa: E501 @@ -80,16 +94,26 @@ def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E5 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method call_123_test_special_tags" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [Client], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `call_123_test_special_tags`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `call_123_test_special_tags`") # noqa: E501 collection_formats = {} @@ -124,7 +148,7 @@ def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E5 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types_mixed=[Client], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-tornado/petstore_api/api/fake_api.py b/samples/client/petstore/python-tornado/petstore_api/api/fake_api.py index c7405e51c381..9c4355a95c35 100644 --- a/samples/client/petstore/python-tornado/petstore_api/api/fake_api.py +++ b/samples/client/petstore/python-tornado/petstore_api/api/fake_api.py @@ -18,6 +18,24 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.client import Client +from petstore_api.models.file_schema_test_class import FileSchemaTestClass +from petstore_api.models.outer_composite import OuterComposite +from petstore_api.models.user import User +from petstore_api.models.xml_item import XmlItem class FakeApi(object): @@ -32,7 +50,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def create_xml_item(self, xml_item, **kwargs): # noqa: E501 + def create_xml_item(self, xml_item, _check_type=False, **kwargs): # noqa: E501 """creates an XmlItem # noqa: E501 this route creates an XmlItem # noqa: E501 @@ -49,12 +67,12 @@ def create_xml_item(self, xml_item, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.create_xml_item_with_http_info(xml_item, **kwargs) # noqa: E501 + return self.create_xml_item_with_http_info(xml_item, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.create_xml_item_with_http_info(xml_item, **kwargs) # noqa: E501 + (data) = self.create_xml_item_with_http_info(xml_item, _check_type=_check_type, **kwargs) # noqa: E501 return data - def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501 + def create_xml_item_with_http_info(self, xml_item, _check_type=False, **kwargs): # noqa: E501 """creates an XmlItem # noqa: E501 this route creates an XmlItem # noqa: E501 @@ -80,16 +98,26 @@ def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method create_xml_item" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'xml_item': [XmlItem], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'xml_item' is set if ('xml_item' not in local_var_params or local_var_params['xml_item'] is None): - raise ValueError("Missing the required parameter `xml_item` when calling `create_xml_item`") # noqa: E501 + raise ApiValueError("Missing the required parameter `xml_item` when calling `create_xml_item`") # noqa: E501 collection_formats = {} @@ -120,7 +148,7 @@ def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -128,7 +156,7 @@ def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def fake_outer_boolean_serialize(self, **kwargs): # noqa: E501 + def fake_outer_boolean_serialize(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_boolean_serialize # noqa: E501 Test serialization of outer boolean types # noqa: E501 @@ -145,12 +173,12 @@ def fake_outer_boolean_serialize(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.fake_outer_boolean_serialize_with_http_info(**kwargs) # noqa: E501 + return self.fake_outer_boolean_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.fake_outer_boolean_serialize_with_http_info(**kwargs) # noqa: E501 + (data) = self.fake_outer_boolean_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 + def fake_outer_boolean_serialize_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_boolean_serialize # noqa: E501 Test serialization of outer boolean types # noqa: E501 @@ -176,12 +204,22 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method fake_outer_boolean_serialize" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [bool], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) collection_formats = {} @@ -212,7 +250,7 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='bool', # noqa: E501 + response_types_mixed=[bool], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -220,7 +258,7 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def fake_outer_composite_serialize(self, **kwargs): # noqa: E501 + def fake_outer_composite_serialize(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_composite_serialize # noqa: E501 Test serialization of object with outer number type # noqa: E501 @@ -237,12 +275,12 @@ def fake_outer_composite_serialize(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.fake_outer_composite_serialize_with_http_info(**kwargs) # noqa: E501 + return self.fake_outer_composite_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.fake_outer_composite_serialize_with_http_info(**kwargs) # noqa: E501 + (data) = self.fake_outer_composite_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 + def fake_outer_composite_serialize_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_composite_serialize # noqa: E501 Test serialization of object with outer number type # noqa: E501 @@ -268,12 +306,22 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method fake_outer_composite_serialize" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [OuterComposite], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) collection_formats = {} @@ -304,7 +352,7 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='OuterComposite', # noqa: E501 + response_types_mixed=[OuterComposite], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -312,7 +360,7 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def fake_outer_number_serialize(self, **kwargs): # noqa: E501 + def fake_outer_number_serialize(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_number_serialize # noqa: E501 Test serialization of outer number types # noqa: E501 @@ -329,12 +377,12 @@ def fake_outer_number_serialize(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.fake_outer_number_serialize_with_http_info(**kwargs) # noqa: E501 + return self.fake_outer_number_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.fake_outer_number_serialize_with_http_info(**kwargs) # noqa: E501 + (data) = self.fake_outer_number_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 + def fake_outer_number_serialize_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_number_serialize # noqa: E501 Test serialization of outer number types # noqa: E501 @@ -360,12 +408,22 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method fake_outer_number_serialize" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [float], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) collection_formats = {} @@ -396,7 +454,7 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='float', # noqa: E501 + response_types_mixed=[float], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -404,7 +462,7 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def fake_outer_string_serialize(self, **kwargs): # noqa: E501 + def fake_outer_string_serialize(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_string_serialize # noqa: E501 Test serialization of outer string types # noqa: E501 @@ -421,12 +479,12 @@ def fake_outer_string_serialize(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.fake_outer_string_serialize_with_http_info(**kwargs) # noqa: E501 + return self.fake_outer_string_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.fake_outer_string_serialize_with_http_info(**kwargs) # noqa: E501 + (data) = self.fake_outer_string_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 + def fake_outer_string_serialize_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_string_serialize # noqa: E501 Test serialization of outer string types # noqa: E501 @@ -452,12 +510,22 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method fake_outer_string_serialize" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) collection_formats = {} @@ -488,7 +556,7 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='str', # noqa: E501 + response_types_mixed=[str], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -496,7 +564,7 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_body_with_file_schema(self, body, **kwargs): # noqa: E501 + def test_body_with_file_schema(self, body, _check_type=False, **kwargs): # noqa: E501 """test_body_with_file_schema # noqa: E501 For this test, the body for this request much reference a schema named `File`. # noqa: E501 @@ -513,12 +581,12 @@ def test_body_with_file_schema(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_body_with_file_schema_with_http_info(body, **kwargs) # noqa: E501 + return self.test_body_with_file_schema_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_body_with_file_schema_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.test_body_with_file_schema_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E501 + def test_body_with_file_schema_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """test_body_with_file_schema # noqa: E501 For this test, the body for this request much reference a schema named `File`. # noqa: E501 @@ -544,16 +612,26 @@ def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E5 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_body_with_file_schema" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [FileSchemaTestClass], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `test_body_with_file_schema`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `test_body_with_file_schema`") # noqa: E501 collection_formats = {} @@ -584,7 +662,7 @@ def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E5 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -592,7 +670,7 @@ def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E5 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_body_with_query_params(self, query, body, **kwargs): # noqa: E501 + def test_body_with_query_params(self, query, body, _check_type=False, **kwargs): # noqa: E501 """test_body_with_query_params # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -609,12 +687,12 @@ def test_body_with_query_params(self, query, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_body_with_query_params_with_http_info(query, body, **kwargs) # noqa: E501 + return self.test_body_with_query_params_with_http_info(query, body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_body_with_query_params_with_http_info(query, body, **kwargs) # noqa: E501 + (data) = self.test_body_with_query_params_with_http_info(query, body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_body_with_query_params_with_http_info(self, query, body, **kwargs): # noqa: E501 + def test_body_with_query_params_with_http_info(self, query, body, _check_type=False, **kwargs): # noqa: E501 """test_body_with_query_params # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -640,20 +718,31 @@ def test_body_with_query_params_with_http_info(self, query, body, **kwargs): # for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_body_with_query_params" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'query': [str], + 'body': [User], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'query' is set if ('query' not in local_var_params or local_var_params['query'] is None): - raise ValueError("Missing the required parameter `query` when calling `test_body_with_query_params`") # noqa: E501 + raise ApiValueError("Missing the required parameter `query` when calling `test_body_with_query_params`") # noqa: E501 # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `test_body_with_query_params`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `test_body_with_query_params`") # noqa: E501 collection_formats = {} @@ -686,7 +775,7 @@ def test_body_with_query_params_with_http_info(self, query, body, **kwargs): # body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -694,7 +783,7 @@ def test_body_with_query_params_with_http_info(self, query, body, **kwargs): # _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_client_model(self, body, **kwargs): # noqa: E501 + def test_client_model(self, body, _check_type=False, **kwargs): # noqa: E501 """To test \"client\" model # noqa: E501 To test \"client\" model # noqa: E501 @@ -711,12 +800,12 @@ def test_client_model(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_client_model_with_http_info(body, **kwargs) # noqa: E501 + return self.test_client_model_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_client_model_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.test_client_model_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501 + def test_client_model_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """To test \"client\" model # noqa: E501 To test \"client\" model # noqa: E501 @@ -742,16 +831,26 @@ def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_client_model" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [Client], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `test_client_model`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `test_client_model`") # noqa: E501 collection_formats = {} @@ -786,7 +885,7 @@ def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types_mixed=[Client], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -794,7 +893,7 @@ def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_endpoint_parameters(self, number, double, pattern_without_delimiter, byte, **kwargs): # noqa: E501 + def test_endpoint_parameters(self, number, double, pattern_without_delimiter, byte, _check_type=False, **kwargs): # noqa: E501 """Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 @@ -813,7 +912,7 @@ def test_endpoint_parameters(self, number, double, pattern_without_delimiter, by :param int int64: None :param float float: None :param str string: None - :param file binary: None + :param file_type binary: None :param date date: None :param datetime date_time: None :param str password: None @@ -824,12 +923,12 @@ def test_endpoint_parameters(self, number, double, pattern_without_delimiter, by """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_endpoint_parameters_with_http_info(number, double, pattern_without_delimiter, byte, **kwargs) # noqa: E501 + return self.test_endpoint_parameters_with_http_info(number, double, pattern_without_delimiter, byte, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_endpoint_parameters_with_http_info(number, double, pattern_without_delimiter, byte, **kwargs) # noqa: E501 + (data) = self.test_endpoint_parameters_with_http_info(number, double, pattern_without_delimiter, byte, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_endpoint_parameters_with_http_info(self, number, double, pattern_without_delimiter, byte, **kwargs): # noqa: E501 + def test_endpoint_parameters_with_http_info(self, number, double, pattern_without_delimiter, byte, _check_type=False, **kwargs): # noqa: E501 """Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 @@ -848,7 +947,7 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou :param int int64: None :param float float: None :param str string: None - :param file binary: None + :param file_type binary: None :param date date: None :param datetime date_time: None :param str password: None @@ -868,57 +967,80 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_endpoint_parameters" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'number': [float], + 'double': [float], + 'pattern_without_delimiter': [str], + 'byte': [str], + 'integer': [int], + 'int32': [int], + 'int64': [int], + 'float': [float], + 'string': [str], + 'binary': [file_type], + 'date': [date], + 'date_time': [datetime], + 'password': [str], + 'param_callback': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'number' is set if ('number' not in local_var_params or local_var_params['number'] is None): - raise ValueError("Missing the required parameter `number` when calling `test_endpoint_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `number` when calling `test_endpoint_parameters`") # noqa: E501 # verify the required parameter 'double' is set if ('double' not in local_var_params or local_var_params['double'] is None): - raise ValueError("Missing the required parameter `double` when calling `test_endpoint_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `double` when calling `test_endpoint_parameters`") # noqa: E501 # verify the required parameter 'pattern_without_delimiter' is set if ('pattern_without_delimiter' not in local_var_params or local_var_params['pattern_without_delimiter'] is None): - raise ValueError("Missing the required parameter `pattern_without_delimiter` when calling `test_endpoint_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pattern_without_delimiter` when calling `test_endpoint_parameters`") # noqa: E501 # verify the required parameter 'byte' is set if ('byte' not in local_var_params or local_var_params['byte'] is None): - raise ValueError("Missing the required parameter `byte` when calling `test_endpoint_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `byte` when calling `test_endpoint_parameters`") # noqa: E501 if 'number' in local_var_params and local_var_params['number'] > 543.2: # noqa: E501 - raise ValueError("Invalid value for parameter `number` when calling `test_endpoint_parameters`, must be a value less than or equal to `543.2`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `number` when calling `test_endpoint_parameters`, must be a value less than or equal to `543.2`") # noqa: E501 if 'number' in local_var_params and local_var_params['number'] < 32.1: # noqa: E501 - raise ValueError("Invalid value for parameter `number` when calling `test_endpoint_parameters`, must be a value greater than or equal to `32.1`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `number` when calling `test_endpoint_parameters`, must be a value greater than or equal to `32.1`") # noqa: E501 if 'double' in local_var_params and local_var_params['double'] > 123.4: # noqa: E501 - raise ValueError("Invalid value for parameter `double` when calling `test_endpoint_parameters`, must be a value less than or equal to `123.4`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `double` when calling `test_endpoint_parameters`, must be a value less than or equal to `123.4`") # noqa: E501 if 'double' in local_var_params and local_var_params['double'] < 67.8: # noqa: E501 - raise ValueError("Invalid value for parameter `double` when calling `test_endpoint_parameters`, must be a value greater than or equal to `67.8`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `double` when calling `test_endpoint_parameters`, must be a value greater than or equal to `67.8`") # noqa: E501 if 'pattern_without_delimiter' in local_var_params and not re.search(r'^[A-Z].*', local_var_params['pattern_without_delimiter']): # noqa: E501 - raise ValueError("Invalid value for parameter `pattern_without_delimiter` when calling `test_endpoint_parameters`, must conform to the pattern `/^[A-Z].*/`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `pattern_without_delimiter` when calling `test_endpoint_parameters`, must conform to the pattern `/^[A-Z].*/`") # noqa: E501 if 'integer' in local_var_params and local_var_params['integer'] > 100: # noqa: E501 - raise ValueError("Invalid value for parameter `integer` when calling `test_endpoint_parameters`, must be a value less than or equal to `100`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `integer` when calling `test_endpoint_parameters`, must be a value less than or equal to `100`") # noqa: E501 if 'integer' in local_var_params and local_var_params['integer'] < 10: # noqa: E501 - raise ValueError("Invalid value for parameter `integer` when calling `test_endpoint_parameters`, must be a value greater than or equal to `10`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `integer` when calling `test_endpoint_parameters`, must be a value greater than or equal to `10`") # noqa: E501 if 'int32' in local_var_params and local_var_params['int32'] > 200: # noqa: E501 - raise ValueError("Invalid value for parameter `int32` when calling `test_endpoint_parameters`, must be a value less than or equal to `200`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `int32` when calling `test_endpoint_parameters`, must be a value less than or equal to `200`") # noqa: E501 if 'int32' in local_var_params and local_var_params['int32'] < 20: # noqa: E501 - raise ValueError("Invalid value for parameter `int32` when calling `test_endpoint_parameters`, must be a value greater than or equal to `20`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `int32` when calling `test_endpoint_parameters`, must be a value greater than or equal to `20`") # noqa: E501 if 'float' in local_var_params and local_var_params['float'] > 987.6: # noqa: E501 - raise ValueError("Invalid value for parameter `float` when calling `test_endpoint_parameters`, must be a value less than or equal to `987.6`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `float` when calling `test_endpoint_parameters`, must be a value less than or equal to `987.6`") # noqa: E501 if 'string' in local_var_params and not re.search(r'[a-z]', local_var_params['string'], flags=re.IGNORECASE): # noqa: E501 - raise ValueError("Invalid value for parameter `string` when calling `test_endpoint_parameters`, must conform to the pattern `/[a-z]/i`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `string` when calling `test_endpoint_parameters`, must conform to the pattern `/[a-z]/i`") # noqa: E501 if ('password' in local_var_params and len(local_var_params['password']) > 64): - raise ValueError("Invalid value for parameter `password` when calling `test_endpoint_parameters`, length must be less than or equal to `64`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `password` when calling `test_endpoint_parameters`, length must be less than or equal to `64`") # noqa: E501 if ('password' in local_var_params and len(local_var_params['password']) < 10): - raise ValueError("Invalid value for parameter `password` when calling `test_endpoint_parameters`, length must be greater than or equal to `10`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `password` when calling `test_endpoint_parameters`, length must be greater than or equal to `10`") # noqa: E501 collection_formats = {} path_params = {} @@ -974,7 +1096,7 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -982,7 +1104,7 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_enum_parameters(self, **kwargs): # noqa: E501 + def test_enum_parameters(self, _check_type=False, **kwargs): # noqa: E501 """To test enum parameters # noqa: E501 To test enum parameters # noqa: E501 @@ -992,13 +1114,13 @@ def test_enum_parameters(self, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] enum_header_string_array: Header parameter enum test (string array) + :param [(str,)] enum_header_string_array: Header parameter enum test (string array) :param str enum_header_string: Header parameter enum test (string) - :param list[str] enum_query_string_array: Query parameter enum test (string array) + :param [(str,)] enum_query_string_array: Query parameter enum test (string array) :param str enum_query_string: Query parameter enum test (string) :param int enum_query_integer: Query parameter enum test (double) :param float enum_query_double: Query parameter enum test (double) - :param list[str] enum_form_string_array: Form parameter enum test (string array) + :param [(str,)] enum_form_string_array: Form parameter enum test (string array) :param str enum_form_string: Form parameter enum test (string) :return: None If the method is called asynchronously, @@ -1006,12 +1128,12 @@ def test_enum_parameters(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_enum_parameters_with_http_info(**kwargs) # noqa: E501 + return self.test_enum_parameters_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_enum_parameters_with_http_info(**kwargs) # noqa: E501 + (data) = self.test_enum_parameters_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 + def test_enum_parameters_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """To test enum parameters # noqa: E501 To test enum parameters # noqa: E501 @@ -1021,13 +1143,13 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] enum_header_string_array: Header parameter enum test (string array) + :param [(str,)] enum_header_string_array: Header parameter enum test (string array) :param str enum_header_string: Header parameter enum test (string) - :param list[str] enum_query_string_array: Query parameter enum test (string array) + :param [(str,)] enum_query_string_array: Query parameter enum test (string array) :param str enum_query_string: Query parameter enum test (string) :param int enum_query_integer: Query parameter enum test (double) :param float enum_query_double: Query parameter enum test (double) - :param list[str] enum_form_string_array: Form parameter enum test (string array) + :param [(str,)] enum_form_string_array: Form parameter enum test (string array) :param str enum_form_string: Form parameter enum test (string) :return: None If the method is called asynchronously, @@ -1044,12 +1166,29 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_enum_parameters" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'enum_header_string_array': [[(str,)]], + 'enum_header_string': [str], + 'enum_query_string_array': [[(str,)]], + 'enum_query_string': [str], + 'enum_query_integer': [int], + 'enum_query_double': [float], + 'enum_form_string_array': [[(str,)]], + 'enum_form_string': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) collection_formats = {} @@ -1097,7 +1236,7 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1105,7 +1244,7 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_group_parameters(self, required_string_group, required_boolean_group, required_int64_group, **kwargs): # noqa: E501 + def test_group_parameters(self, required_string_group, required_boolean_group, required_int64_group, _check_type=False, **kwargs): # noqa: E501 """Fake endpoint to test group parameters (optional) # noqa: E501 Fake endpoint to test group parameters (optional) # noqa: E501 @@ -1127,12 +1266,12 @@ def test_group_parameters(self, required_string_group, required_boolean_group, r """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_group_parameters_with_http_info(required_string_group, required_boolean_group, required_int64_group, **kwargs) # noqa: E501 + return self.test_group_parameters_with_http_info(required_string_group, required_boolean_group, required_int64_group, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_group_parameters_with_http_info(required_string_group, required_boolean_group, required_int64_group, **kwargs) # noqa: E501 + (data) = self.test_group_parameters_with_http_info(required_string_group, required_boolean_group, required_int64_group, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_group_parameters_with_http_info(self, required_string_group, required_boolean_group, required_int64_group, **kwargs): # noqa: E501 + def test_group_parameters_with_http_info(self, required_string_group, required_boolean_group, required_int64_group, _check_type=False, **kwargs): # noqa: E501 """Fake endpoint to test group parameters (optional) # noqa: E501 Fake endpoint to test group parameters (optional) # noqa: E501 @@ -1163,24 +1302,39 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_group_parameters" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'required_string_group': [int], + 'required_boolean_group': [bool], + 'required_int64_group': [int], + 'string_group': [int], + 'boolean_group': [bool], + 'int64_group': [int], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'required_string_group' is set if ('required_string_group' not in local_var_params or local_var_params['required_string_group'] is None): - raise ValueError("Missing the required parameter `required_string_group` when calling `test_group_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `required_string_group` when calling `test_group_parameters`") # noqa: E501 # verify the required parameter 'required_boolean_group' is set if ('required_boolean_group' not in local_var_params or local_var_params['required_boolean_group'] is None): - raise ValueError("Missing the required parameter `required_boolean_group` when calling `test_group_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `required_boolean_group` when calling `test_group_parameters`") # noqa: E501 # verify the required parameter 'required_int64_group' is set if ('required_int64_group' not in local_var_params or local_var_params['required_int64_group'] is None): - raise ValueError("Missing the required parameter `required_int64_group` when calling `test_group_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `required_int64_group` when calling `test_group_parameters`") # noqa: E501 collection_formats = {} @@ -1217,7 +1371,7 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1225,7 +1379,7 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_inline_additional_properties(self, param, **kwargs): # noqa: E501 + def test_inline_additional_properties(self, param, _check_type=False, **kwargs): # noqa: E501 """test inline additionalProperties # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -1234,19 +1388,19 @@ def test_inline_additional_properties(self, param, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param dict(str, str) param: request body (required) + :param {str: (str,)} param: request body (required) :return: None If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_inline_additional_properties_with_http_info(param, **kwargs) # noqa: E501 + return self.test_inline_additional_properties_with_http_info(param, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_inline_additional_properties_with_http_info(param, **kwargs) # noqa: E501 + (data) = self.test_inline_additional_properties_with_http_info(param, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_inline_additional_properties_with_http_info(self, param, **kwargs): # noqa: E501 + def test_inline_additional_properties_with_http_info(self, param, _check_type=False, **kwargs): # noqa: E501 """test inline additionalProperties # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -1255,7 +1409,7 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): # >>> result = thread.get() :param async_req bool - :param dict(str, str) param: request body (required) + :param {str: (str,)} param: request body (required) :return: None If the method is called asynchronously, returns the request thread. @@ -1271,16 +1425,26 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): # for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_inline_additional_properties" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'param': [{str: (str,)}], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'param' is set if ('param' not in local_var_params or local_var_params['param'] is None): - raise ValueError("Missing the required parameter `param` when calling `test_inline_additional_properties`") # noqa: E501 + raise ApiValueError("Missing the required parameter `param` when calling `test_inline_additional_properties`") # noqa: E501 collection_formats = {} @@ -1311,7 +1475,7 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): # body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1319,7 +1483,7 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): # _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_json_form_data(self, param, param2, **kwargs): # noqa: E501 + def test_json_form_data(self, param, param2, _check_type=False, **kwargs): # noqa: E501 """test json serialization of form data # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -1336,12 +1500,12 @@ def test_json_form_data(self, param, param2, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_json_form_data_with_http_info(param, param2, **kwargs) # noqa: E501 + return self.test_json_form_data_with_http_info(param, param2, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_json_form_data_with_http_info(param, param2, **kwargs) # noqa: E501 + (data) = self.test_json_form_data_with_http_info(param, param2, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa: E501 + def test_json_form_data_with_http_info(self, param, param2, _check_type=False, **kwargs): # noqa: E501 """test json serialization of form data # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -1367,20 +1531,31 @@ def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa: for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_json_form_data" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'param': [str], + 'param2': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'param' is set if ('param' not in local_var_params or local_var_params['param'] is None): - raise ValueError("Missing the required parameter `param` when calling `test_json_form_data`") # noqa: E501 + raise ApiValueError("Missing the required parameter `param` when calling `test_json_form_data`") # noqa: E501 # verify the required parameter 'param2' is set if ('param2' not in local_var_params or local_var_params['param2'] is None): - raise ValueError("Missing the required parameter `param2` when calling `test_json_form_data`") # noqa: E501 + raise ApiValueError("Missing the required parameter `param2` when calling `test_json_form_data`") # noqa: E501 collection_formats = {} @@ -1413,7 +1588,7 @@ def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-tornado/petstore_api/api/fake_classname_tags_123_api.py b/samples/client/petstore/python-tornado/petstore_api/api/fake_classname_tags_123_api.py index dbf6ef3dfb37..765a41b2827e 100644 --- a/samples/client/petstore/python-tornado/petstore_api/api/fake_classname_tags_123_api.py +++ b/samples/client/petstore/python-tornado/petstore_api/api/fake_classname_tags_123_api.py @@ -18,6 +18,20 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.client import Client class FakeClassnameTags123Api(object): @@ -32,7 +46,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def test_classname(self, body, **kwargs): # noqa: E501 + def test_classname(self, body, _check_type=False, **kwargs): # noqa: E501 """To test class name in snake case # noqa: E501 To test class name in snake case # noqa: E501 @@ -49,12 +63,12 @@ def test_classname(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_classname_with_http_info(body, **kwargs) # noqa: E501 + return self.test_classname_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_classname_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.test_classname_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_classname_with_http_info(self, body, **kwargs): # noqa: E501 + def test_classname_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """To test class name in snake case # noqa: E501 To test class name in snake case # noqa: E501 @@ -80,16 +94,26 @@ def test_classname_with_http_info(self, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_classname" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [Client], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `test_classname`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `test_classname`") # noqa: E501 collection_formats = {} @@ -124,7 +148,7 @@ def test_classname_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types_mixed=[Client], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-tornado/petstore_api/api/pet_api.py b/samples/client/petstore/python-tornado/petstore_api/api/pet_api.py index f29e7239666a..7e07c241e0e1 100644 --- a/samples/client/petstore/python-tornado/petstore_api/api/pet_api.py +++ b/samples/client/petstore/python-tornado/petstore_api/api/pet_api.py @@ -18,6 +18,21 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.api_response import ApiResponse +from petstore_api.models.pet import Pet class PetApi(object): @@ -32,7 +47,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def add_pet(self, body, **kwargs): # noqa: E501 + def add_pet(self, body, _check_type=False, **kwargs): # noqa: E501 """Add a new pet to the store # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -48,12 +63,12 @@ def add_pet(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.add_pet_with_http_info(body, **kwargs) # noqa: E501 + return self.add_pet_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.add_pet_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.add_pet_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def add_pet_with_http_info(self, body, **kwargs): # noqa: E501 + def add_pet_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """Add a new pet to the store # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -78,16 +93,26 @@ def add_pet_with_http_info(self, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method add_pet" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [Pet], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `add_pet`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `add_pet`") # noqa: E501 collection_formats = {} @@ -118,7 +143,7 @@ def add_pet_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -126,7 +151,7 @@ def add_pet_with_http_info(self, body, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def delete_pet(self, pet_id, **kwargs): # noqa: E501 + def delete_pet(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Deletes a pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -143,12 +168,12 @@ def delete_pet(self, pet_id, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.delete_pet_with_http_info(pet_id, **kwargs) # noqa: E501 + return self.delete_pet_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.delete_pet_with_http_info(pet_id, **kwargs) # noqa: E501 + (data) = self.delete_pet_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 + def delete_pet_with_http_info(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Deletes a pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -174,16 +199,27 @@ def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method delete_pet" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet_id': [int], + 'api_key': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet_id' is set if ('pet_id' not in local_var_params or local_var_params['pet_id'] is None): - raise ValueError("Missing the required parameter `pet_id` when calling `delete_pet`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet_id` when calling `delete_pet`") # noqa: E501 collection_formats = {} @@ -212,7 +248,7 @@ def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -220,7 +256,7 @@ def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def find_pets_by_status(self, status, **kwargs): # noqa: E501 + def find_pets_by_status(self, status, _check_type=False, **kwargs): # noqa: E501 """Finds Pets by status # noqa: E501 Multiple status values can be provided with comma separated strings # noqa: E501 @@ -230,19 +266,19 @@ def find_pets_by_status(self, status, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] status: Status values that need to be considered for filter (required) - :return: list[Pet] + :param [(str,)] status: Status values that need to be considered for filter (required) + :return: [(Pet,)] If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.find_pets_by_status_with_http_info(status, **kwargs) # noqa: E501 + return self.find_pets_by_status_with_http_info(status, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.find_pets_by_status_with_http_info(status, **kwargs) # noqa: E501 + (data) = self.find_pets_by_status_with_http_info(status, _check_type=_check_type, **kwargs) # noqa: E501 return data - def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 + def find_pets_by_status_with_http_info(self, status, _check_type=False, **kwargs): # noqa: E501 """Finds Pets by status # noqa: E501 Multiple status values can be provided with comma separated strings # noqa: E501 @@ -252,8 +288,8 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] status: Status values that need to be considered for filter (required) - :return: list[Pet] + :param [(str,)] status: Status values that need to be considered for filter (required) + :return: [(Pet,)] If the method is called asynchronously, returns the request thread. """ @@ -268,16 +304,26 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method find_pets_by_status" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'status': [[(str,)]], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'status' is set if ('status' not in local_var_params or local_var_params['status'] is None): - raise ValueError("Missing the required parameter `status` when calling `find_pets_by_status`") # noqa: E501 + raise ApiValueError("Missing the required parameter `status` when calling `find_pets_by_status`") # noqa: E501 collection_formats = {} @@ -309,7 +355,7 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='list[Pet]', # noqa: E501 + response_types_mixed=[[(Pet,)]], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -317,7 +363,7 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def find_pets_by_tags(self, tags, **kwargs): # noqa: E501 + def find_pets_by_tags(self, tags, _check_type=False, **kwargs): # noqa: E501 """Finds Pets by tags # noqa: E501 Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. # noqa: E501 @@ -327,19 +373,19 @@ def find_pets_by_tags(self, tags, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] tags: Tags to filter by (required) - :return: list[Pet] + :param [(str,)] tags: Tags to filter by (required) + :return: [(Pet,)] If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.find_pets_by_tags_with_http_info(tags, **kwargs) # noqa: E501 + return self.find_pets_by_tags_with_http_info(tags, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.find_pets_by_tags_with_http_info(tags, **kwargs) # noqa: E501 + (data) = self.find_pets_by_tags_with_http_info(tags, _check_type=_check_type, **kwargs) # noqa: E501 return data - def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 + def find_pets_by_tags_with_http_info(self, tags, _check_type=False, **kwargs): # noqa: E501 """Finds Pets by tags # noqa: E501 Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. # noqa: E501 @@ -349,8 +395,8 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] tags: Tags to filter by (required) - :return: list[Pet] + :param [(str,)] tags: Tags to filter by (required) + :return: [(Pet,)] If the method is called asynchronously, returns the request thread. """ @@ -365,16 +411,26 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method find_pets_by_tags" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'tags': [[(str,)]], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'tags' is set if ('tags' not in local_var_params or local_var_params['tags'] is None): - raise ValueError("Missing the required parameter `tags` when calling `find_pets_by_tags`") # noqa: E501 + raise ApiValueError("Missing the required parameter `tags` when calling `find_pets_by_tags`") # noqa: E501 collection_formats = {} @@ -406,7 +462,7 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='list[Pet]', # noqa: E501 + response_types_mixed=[[(Pet,)]], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -414,7 +470,7 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def get_pet_by_id(self, pet_id, **kwargs): # noqa: E501 + def get_pet_by_id(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Find pet by ID # noqa: E501 Returns a single pet # noqa: E501 @@ -431,12 +487,12 @@ def get_pet_by_id(self, pet_id, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.get_pet_by_id_with_http_info(pet_id, **kwargs) # noqa: E501 + return self.get_pet_by_id_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.get_pet_by_id_with_http_info(pet_id, **kwargs) # noqa: E501 + (data) = self.get_pet_by_id_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 + def get_pet_by_id_with_http_info(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Find pet by ID # noqa: E501 Returns a single pet # noqa: E501 @@ -462,16 +518,26 @@ def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method get_pet_by_id" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet_id': [int], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet_id' is set if ('pet_id' not in local_var_params or local_var_params['pet_id'] is None): - raise ValueError("Missing the required parameter `pet_id` when calling `get_pet_by_id`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet_id` when calling `get_pet_by_id`") # noqa: E501 collection_formats = {} @@ -502,7 +568,7 @@ def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Pet', # noqa: E501 + response_types_mixed=[Pet], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -510,7 +576,7 @@ def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def update_pet(self, body, **kwargs): # noqa: E501 + def update_pet(self, body, _check_type=False, **kwargs): # noqa: E501 """Update an existing pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -526,12 +592,12 @@ def update_pet(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.update_pet_with_http_info(body, **kwargs) # noqa: E501 + return self.update_pet_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.update_pet_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.update_pet_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def update_pet_with_http_info(self, body, **kwargs): # noqa: E501 + def update_pet_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """Update an existing pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -556,16 +622,26 @@ def update_pet_with_http_info(self, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method update_pet" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [Pet], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `update_pet`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `update_pet`") # noqa: E501 collection_formats = {} @@ -596,7 +672,7 @@ def update_pet_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -604,7 +680,7 @@ def update_pet_with_http_info(self, body, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def update_pet_with_form(self, pet_id, **kwargs): # noqa: E501 + def update_pet_with_form(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Updates a pet in the store with form data # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -622,12 +698,12 @@ def update_pet_with_form(self, pet_id, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.update_pet_with_form_with_http_info(pet_id, **kwargs) # noqa: E501 + return self.update_pet_with_form_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.update_pet_with_form_with_http_info(pet_id, **kwargs) # noqa: E501 + (data) = self.update_pet_with_form_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 + def update_pet_with_form_with_http_info(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Updates a pet in the store with form data # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -654,16 +730,28 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method update_pet_with_form" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet_id': [int], + 'name': [str], + 'status': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet_id' is set if ('pet_id' not in local_var_params or local_var_params['pet_id'] is None): - raise ValueError("Missing the required parameter `pet_id` when calling `update_pet_with_form`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet_id` when calling `update_pet_with_form`") # noqa: E501 collection_formats = {} @@ -698,7 +786,7 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -706,7 +794,7 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def upload_file(self, pet_id, **kwargs): # noqa: E501 + def upload_file(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """uploads an image # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -717,19 +805,19 @@ def upload_file(self, pet_id, **kwargs): # noqa: E501 :param async_req bool :param int pet_id: ID of pet to update (required) :param str additional_metadata: Additional data to pass to server - :param file file: file to upload + :param file_type file: file to upload :return: ApiResponse If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.upload_file_with_http_info(pet_id, **kwargs) # noqa: E501 + return self.upload_file_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.upload_file_with_http_info(pet_id, **kwargs) # noqa: E501 + (data) = self.upload_file_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 + def upload_file_with_http_info(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """uploads an image # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -740,7 +828,7 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 :param async_req bool :param int pet_id: ID of pet to update (required) :param str additional_metadata: Additional data to pass to server - :param file file: file to upload + :param file_type file: file to upload :return: ApiResponse If the method is called asynchronously, returns the request thread. @@ -756,16 +844,28 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method upload_file" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet_id': [int], + 'additional_metadata': [str], + 'file': [file_type], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet_id' is set if ('pet_id' not in local_var_params or local_var_params['pet_id'] is None): - raise ValueError("Missing the required parameter `pet_id` when calling `upload_file`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet_id` when calling `upload_file`") # noqa: E501 collection_formats = {} @@ -804,7 +904,7 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='ApiResponse', # noqa: E501 + response_types_mixed=[ApiResponse], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -812,7 +912,7 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def upload_file_with_required_file(self, pet_id, required_file, **kwargs): # noqa: E501 + def upload_file_with_required_file(self, pet_id, required_file, _check_type=False, **kwargs): # noqa: E501 """uploads an image (required) # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -822,7 +922,7 @@ def upload_file_with_required_file(self, pet_id, required_file, **kwargs): # no :param async_req bool :param int pet_id: ID of pet to update (required) - :param file required_file: file to upload (required) + :param file_type required_file: file to upload (required) :param str additional_metadata: Additional data to pass to server :return: ApiResponse If the method is called asynchronously, @@ -830,12 +930,12 @@ def upload_file_with_required_file(self, pet_id, required_file, **kwargs): # no """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.upload_file_with_required_file_with_http_info(pet_id, required_file, **kwargs) # noqa: E501 + return self.upload_file_with_required_file_with_http_info(pet_id, required_file, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.upload_file_with_required_file_with_http_info(pet_id, required_file, **kwargs) # noqa: E501 + (data) = self.upload_file_with_required_file_with_http_info(pet_id, required_file, _check_type=_check_type, **kwargs) # noqa: E501 return data - def upload_file_with_required_file_with_http_info(self, pet_id, required_file, **kwargs): # noqa: E501 + def upload_file_with_required_file_with_http_info(self, pet_id, required_file, _check_type=False, **kwargs): # noqa: E501 """uploads an image (required) # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -845,7 +945,7 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, * :param async_req bool :param int pet_id: ID of pet to update (required) - :param file required_file: file to upload (required) + :param file_type required_file: file to upload (required) :param str additional_metadata: Additional data to pass to server :return: ApiResponse If the method is called asynchronously, @@ -862,20 +962,32 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, * for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method upload_file_with_required_file" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet_id': [int], + 'required_file': [file_type], + 'additional_metadata': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet_id' is set if ('pet_id' not in local_var_params or local_var_params['pet_id'] is None): - raise ValueError("Missing the required parameter `pet_id` when calling `upload_file_with_required_file`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet_id` when calling `upload_file_with_required_file`") # noqa: E501 # verify the required parameter 'required_file' is set if ('required_file' not in local_var_params or local_var_params['required_file'] is None): - raise ValueError("Missing the required parameter `required_file` when calling `upload_file_with_required_file`") # noqa: E501 + raise ApiValueError("Missing the required parameter `required_file` when calling `upload_file_with_required_file`") # noqa: E501 collection_formats = {} @@ -914,7 +1026,7 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, * body=body_params, post_params=form_params, files=local_var_files, - response_type='ApiResponse', # noqa: E501 + response_types_mixed=[ApiResponse], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-tornado/petstore_api/api/store_api.py b/samples/client/petstore/python-tornado/petstore_api/api/store_api.py index bd2677ef92bc..6a8bba9ac620 100644 --- a/samples/client/petstore/python-tornado/petstore_api/api/store_api.py +++ b/samples/client/petstore/python-tornado/petstore_api/api/store_api.py @@ -18,6 +18,20 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.order import Order class StoreApi(object): @@ -32,7 +46,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def delete_order(self, order_id, **kwargs): # noqa: E501 + def delete_order(self, order_id, _check_type=False, **kwargs): # noqa: E501 """Delete purchase order by ID # noqa: E501 For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors # noqa: E501 @@ -49,12 +63,12 @@ def delete_order(self, order_id, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.delete_order_with_http_info(order_id, **kwargs) # noqa: E501 + return self.delete_order_with_http_info(order_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.delete_order_with_http_info(order_id, **kwargs) # noqa: E501 + (data) = self.delete_order_with_http_info(order_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 + def delete_order_with_http_info(self, order_id, _check_type=False, **kwargs): # noqa: E501 """Delete purchase order by ID # noqa: E501 For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors # noqa: E501 @@ -80,16 +94,26 @@ def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method delete_order" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'order_id': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'order_id' is set if ('order_id' not in local_var_params or local_var_params['order_id'] is None): - raise ValueError("Missing the required parameter `order_id` when calling `delete_order`") # noqa: E501 + raise ApiValueError("Missing the required parameter `order_id` when calling `delete_order`") # noqa: E501 collection_formats = {} @@ -116,7 +140,7 @@ def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -124,7 +148,7 @@ def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def get_inventory(self, **kwargs): # noqa: E501 + def get_inventory(self, _check_type=False, **kwargs): # noqa: E501 """Returns pet inventories by status # noqa: E501 Returns a map of status codes to quantities # noqa: E501 @@ -134,18 +158,18 @@ def get_inventory(self, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :return: dict(str, int) + :return: {str: (int,)} If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.get_inventory_with_http_info(**kwargs) # noqa: E501 + return self.get_inventory_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.get_inventory_with_http_info(**kwargs) # noqa: E501 + (data) = self.get_inventory_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def get_inventory_with_http_info(self, **kwargs): # noqa: E501 + def get_inventory_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """Returns pet inventories by status # noqa: E501 Returns a map of status codes to quantities # noqa: E501 @@ -155,7 +179,7 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :return: dict(str, int) + :return: {str: (int,)} If the method is called asynchronously, returns the request thread. """ @@ -170,7 +194,7 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method get_inventory" % key ) @@ -204,7 +228,7 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='dict(str, int)', # noqa: E501 + response_types_mixed=[{str: (int,)}], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -212,7 +236,7 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def get_order_by_id(self, order_id, **kwargs): # noqa: E501 + def get_order_by_id(self, order_id, _check_type=False, **kwargs): # noqa: E501 """Find purchase order by ID # noqa: E501 For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions # noqa: E501 @@ -229,12 +253,12 @@ def get_order_by_id(self, order_id, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.get_order_by_id_with_http_info(order_id, **kwargs) # noqa: E501 + return self.get_order_by_id_with_http_info(order_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.get_order_by_id_with_http_info(order_id, **kwargs) # noqa: E501 + (data) = self.get_order_by_id_with_http_info(order_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 + def get_order_by_id_with_http_info(self, order_id, _check_type=False, **kwargs): # noqa: E501 """Find purchase order by ID # noqa: E501 For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions # noqa: E501 @@ -260,21 +284,31 @@ def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method get_order_by_id" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'order_id': [int], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'order_id' is set if ('order_id' not in local_var_params or local_var_params['order_id'] is None): - raise ValueError("Missing the required parameter `order_id` when calling `get_order_by_id`") # noqa: E501 + raise ApiValueError("Missing the required parameter `order_id` when calling `get_order_by_id`") # noqa: E501 if 'order_id' in local_var_params and local_var_params['order_id'] > 5: # noqa: E501 - raise ValueError("Invalid value for parameter `order_id` when calling `get_order_by_id`, must be a value less than or equal to `5`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `order_id` when calling `get_order_by_id`, must be a value less than or equal to `5`") # noqa: E501 if 'order_id' in local_var_params and local_var_params['order_id'] < 1: # noqa: E501 - raise ValueError("Invalid value for parameter `order_id` when calling `get_order_by_id`, must be a value greater than or equal to `1`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `order_id` when calling `get_order_by_id`, must be a value greater than or equal to `1`") # noqa: E501 collection_formats = {} path_params = {} @@ -304,7 +338,7 @@ def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Order', # noqa: E501 + response_types_mixed=[Order], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -312,7 +346,7 @@ def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def place_order(self, body, **kwargs): # noqa: E501 + def place_order(self, body, _check_type=False, **kwargs): # noqa: E501 """Place an order for a pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -328,12 +362,12 @@ def place_order(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.place_order_with_http_info(body, **kwargs) # noqa: E501 + return self.place_order_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.place_order_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.place_order_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def place_order_with_http_info(self, body, **kwargs): # noqa: E501 + def place_order_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """Place an order for a pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -358,16 +392,26 @@ def place_order_with_http_info(self, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method place_order" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [Order], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `place_order`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `place_order`") # noqa: E501 collection_formats = {} @@ -398,7 +442,7 @@ def place_order_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Order', # noqa: E501 + response_types_mixed=[Order], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-tornado/petstore_api/api/user_api.py b/samples/client/petstore/python-tornado/petstore_api/api/user_api.py index c27299309a6d..672bbc57b59e 100644 --- a/samples/client/petstore/python-tornado/petstore_api/api/user_api.py +++ b/samples/client/petstore/python-tornado/petstore_api/api/user_api.py @@ -18,6 +18,20 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.user import User class UserApi(object): @@ -32,7 +46,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def create_user(self, body, **kwargs): # noqa: E501 + def create_user(self, body, _check_type=False, **kwargs): # noqa: E501 """Create user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -49,12 +63,12 @@ def create_user(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.create_user_with_http_info(body, **kwargs) # noqa: E501 + return self.create_user_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.create_user_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.create_user_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def create_user_with_http_info(self, body, **kwargs): # noqa: E501 + def create_user_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """Create user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -80,16 +94,26 @@ def create_user_with_http_info(self, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method create_user" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [User], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `create_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `create_user`") # noqa: E501 collection_formats = {} @@ -116,7 +140,7 @@ def create_user_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -124,7 +148,7 @@ def create_user_with_http_info(self, body, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def create_users_with_array_input(self, body, **kwargs): # noqa: E501 + def create_users_with_array_input(self, body, _check_type=False, **kwargs): # noqa: E501 """Creates list of users with given input array # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -133,19 +157,19 @@ def create_users_with_array_input(self, body, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[User] body: List of user object (required) + :param [(User,)] body: List of user object (required) :return: None If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.create_users_with_array_input_with_http_info(body, **kwargs) # noqa: E501 + return self.create_users_with_array_input_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.create_users_with_array_input_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.create_users_with_array_input_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: E501 + def create_users_with_array_input_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """Creates list of users with given input array # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -154,7 +178,7 @@ def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: >>> result = thread.get() :param async_req bool - :param list[User] body: List of user object (required) + :param [(User,)] body: List of user object (required) :return: None If the method is called asynchronously, returns the request thread. @@ -170,16 +194,26 @@ def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method create_users_with_array_input" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [[(User,)]], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `create_users_with_array_input`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `create_users_with_array_input`") # noqa: E501 collection_formats = {} @@ -206,7 +240,7 @@ def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -214,7 +248,7 @@ def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def create_users_with_list_input(self, body, **kwargs): # noqa: E501 + def create_users_with_list_input(self, body, _check_type=False, **kwargs): # noqa: E501 """Creates list of users with given input array # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -223,19 +257,19 @@ def create_users_with_list_input(self, body, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[User] body: List of user object (required) + :param [(User,)] body: List of user object (required) :return: None If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.create_users_with_list_input_with_http_info(body, **kwargs) # noqa: E501 + return self.create_users_with_list_input_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.create_users_with_list_input_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.create_users_with_list_input_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: E501 + def create_users_with_list_input_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """Creates list of users with given input array # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -244,7 +278,7 @@ def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: >>> result = thread.get() :param async_req bool - :param list[User] body: List of user object (required) + :param [(User,)] body: List of user object (required) :return: None If the method is called asynchronously, returns the request thread. @@ -260,16 +294,26 @@ def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method create_users_with_list_input" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [[(User,)]], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `create_users_with_list_input`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `create_users_with_list_input`") # noqa: E501 collection_formats = {} @@ -296,7 +340,7 @@ def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -304,7 +348,7 @@ def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def delete_user(self, username, **kwargs): # noqa: E501 + def delete_user(self, username, _check_type=False, **kwargs): # noqa: E501 """Delete user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -321,12 +365,12 @@ def delete_user(self, username, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.delete_user_with_http_info(username, **kwargs) # noqa: E501 + return self.delete_user_with_http_info(username, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.delete_user_with_http_info(username, **kwargs) # noqa: E501 + (data) = self.delete_user_with_http_info(username, _check_type=_check_type, **kwargs) # noqa: E501 return data - def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 + def delete_user_with_http_info(self, username, _check_type=False, **kwargs): # noqa: E501 """Delete user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -352,16 +396,26 @@ def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method delete_user" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'username': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'username' is set if ('username' not in local_var_params or local_var_params['username'] is None): - raise ValueError("Missing the required parameter `username` when calling `delete_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `username` when calling `delete_user`") # noqa: E501 collection_formats = {} @@ -388,7 +442,7 @@ def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -396,7 +450,7 @@ def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def get_user_by_name(self, username, **kwargs): # noqa: E501 + def get_user_by_name(self, username, _check_type=False, **kwargs): # noqa: E501 """Get user by user name # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -412,12 +466,12 @@ def get_user_by_name(self, username, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.get_user_by_name_with_http_info(username, **kwargs) # noqa: E501 + return self.get_user_by_name_with_http_info(username, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.get_user_by_name_with_http_info(username, **kwargs) # noqa: E501 + (data) = self.get_user_by_name_with_http_info(username, _check_type=_check_type, **kwargs) # noqa: E501 return data - def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 + def get_user_by_name_with_http_info(self, username, _check_type=False, **kwargs): # noqa: E501 """Get user by user name # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -442,16 +496,26 @@ def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method get_user_by_name" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'username': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'username' is set if ('username' not in local_var_params or local_var_params['username'] is None): - raise ValueError("Missing the required parameter `username` when calling `get_user_by_name`") # noqa: E501 + raise ApiValueError("Missing the required parameter `username` when calling `get_user_by_name`") # noqa: E501 collection_formats = {} @@ -482,7 +546,7 @@ def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='User', # noqa: E501 + response_types_mixed=[User], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -490,7 +554,7 @@ def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def login_user(self, username, password, **kwargs): # noqa: E501 + def login_user(self, username, password, _check_type=False, **kwargs): # noqa: E501 """Logs user into the system # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -507,12 +571,12 @@ def login_user(self, username, password, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.login_user_with_http_info(username, password, **kwargs) # noqa: E501 + return self.login_user_with_http_info(username, password, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.login_user_with_http_info(username, password, **kwargs) # noqa: E501 + (data) = self.login_user_with_http_info(username, password, _check_type=_check_type, **kwargs) # noqa: E501 return data - def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 + def login_user_with_http_info(self, username, password, _check_type=False, **kwargs): # noqa: E501 """Logs user into the system # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -538,20 +602,31 @@ def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method login_user" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'username': [str], + 'password': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'username' is set if ('username' not in local_var_params or local_var_params['username'] is None): - raise ValueError("Missing the required parameter `username` when calling `login_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `username` when calling `login_user`") # noqa: E501 # verify the required parameter 'password' is set if ('password' not in local_var_params or local_var_params['password'] is None): - raise ValueError("Missing the required parameter `password` when calling `login_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `password` when calling `login_user`") # noqa: E501 collection_formats = {} @@ -584,7 +659,7 @@ def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='str', # noqa: E501 + response_types_mixed=[str], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -592,7 +667,7 @@ def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def logout_user(self, **kwargs): # noqa: E501 + def logout_user(self, _check_type=False, **kwargs): # noqa: E501 """Logs out current logged in user session # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -607,12 +682,12 @@ def logout_user(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.logout_user_with_http_info(**kwargs) # noqa: E501 + return self.logout_user_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.logout_user_with_http_info(**kwargs) # noqa: E501 + (data) = self.logout_user_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def logout_user_with_http_info(self, **kwargs): # noqa: E501 + def logout_user_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """Logs out current logged in user session # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -636,7 +711,7 @@ def logout_user_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method logout_user" % key ) @@ -666,7 +741,7 @@ def logout_user_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -674,7 +749,7 @@ def logout_user_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def update_user(self, username, body, **kwargs): # noqa: E501 + def update_user(self, username, body, _check_type=False, **kwargs): # noqa: E501 """Updated user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -692,12 +767,12 @@ def update_user(self, username, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.update_user_with_http_info(username, body, **kwargs) # noqa: E501 + return self.update_user_with_http_info(username, body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.update_user_with_http_info(username, body, **kwargs) # noqa: E501 + (data) = self.update_user_with_http_info(username, body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def update_user_with_http_info(self, username, body, **kwargs): # noqa: E501 + def update_user_with_http_info(self, username, body, _check_type=False, **kwargs): # noqa: E501 """Updated user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -724,20 +799,31 @@ def update_user_with_http_info(self, username, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method update_user" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'username': [str], + 'body': [User], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'username' is set if ('username' not in local_var_params or local_var_params['username'] is None): - raise ValueError("Missing the required parameter `username` when calling `update_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `username` when calling `update_user`") # noqa: E501 # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `update_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `update_user`") # noqa: E501 collection_formats = {} @@ -766,7 +852,7 @@ def update_user_with_http_info(self, username, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-tornado/petstore_api/api_client.py b/samples/client/petstore/python-tornado/petstore_api/api_client.py index debb463cf16f..5733df2ce5bd 100644 --- a/samples/client/petstore/python-tornado/petstore_api/api_client.py +++ b/samples/client/petstore/python-tornado/petstore_api/api_client.py @@ -10,7 +10,7 @@ from __future__ import absolute_import -import datetime +import copy import json import mimetypes from multiprocessing.pool import ThreadPool @@ -24,6 +24,22 @@ import tornado.gen from petstore_api.configuration import Configuration +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( + OpenApiModel, + date, + datetime, + deserialize_file, + file_type, + model_to_dict, + none_type, + str, + validate_and_convert_types +) import petstore_api.models from petstore_api import rest @@ -50,17 +66,11 @@ class ApiClient(object): to the API. More threads means more concurrent API requests. """ - PRIMITIVE_TYPES = (float, bool, bytes, six.text_type) + six.integer_types - NATIVE_TYPES_MAPPING = { - 'int': int, - 'long': int if six.PY3 else long, # noqa: F821 - 'float': float, - 'str': str, - 'bool': bool, - 'date': datetime.date, - 'datetime': datetime.datetime, - 'object': object, - } + # six.binary_type python2=str, python3=bytes + # six.text_type python2=unicode, python3=str + PRIMITIVE_TYPES = ( + (float, bool, six.binary_type, six.text_type) + six.integer_types + ) _pool = None def __init__(self, configuration=None, header_name=None, header_value=None, @@ -109,7 +119,7 @@ def set_default_header(self, header_name, header_value): def __call_api( self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, - files=None, response_type=None, auth_settings=None, + files=None, response_types_mixed=None, auth_settings=None, _return_http_data_only=None, collection_formats=None, _preload_content=True, _request_timeout=None, _host=None): @@ -176,8 +186,9 @@ def __call_api( return_data = response_data if _preload_content: # deserialize response data - if response_type: - return_data = self.deserialize(response_data, response_type) + if response_types_mixed: + return_data = self.deserialize(response_data, + response_types_mixed) else: return_data = None @@ -211,89 +222,59 @@ def sanitize_for_serialization(self, obj): elif isinstance(obj, tuple): return tuple(self.sanitize_for_serialization(sub_obj) for sub_obj in obj) - elif isinstance(obj, (datetime.datetime, datetime.date)): + elif isinstance(obj, (datetime, date)): return obj.isoformat() if isinstance(obj, dict): obj_dict = obj else: - # Convert model obj to dict except - # attributes `openapi_types`, `attribute_map` - # and attributes which value is not None. + # Convert model obj to dict # Convert attribute name to json key in # model definition for request. - obj_dict = {obj.attribute_map[attr]: getattr(obj, attr) - for attr, _ in six.iteritems(obj.openapi_types) - if getattr(obj, attr) is not None} + obj_dict = model_to_dict(obj, serialize=True) return {key: self.sanitize_for_serialization(val) for key, val in six.iteritems(obj_dict)} - def deserialize(self, response, response_type): + def deserialize(self, response, response_types_mixed): """Deserializes response into an object. :param response: RESTResponse object to be deserialized. - :param response_type: class literal for - deserialized object, or string of class name. + :param response_types_mixed: For the response, a list of + valid classes, or a list tuples of valid classes, or a dict where + the value is a tuple of value classes. :return: deserialized object. """ # handle file downloading # save response body into a tmp file and return the instance - if response_type == "file": - return self.__deserialize_file(response) + if response_types_mixed == [file_type]: + content_disposition = response.getheader("Content-Disposition") + return deserialize_file(response.data, self.configuration, + content_disposition=content_disposition) # fetch data from response object try: - data = json.loads(response.data) + received_data = json.loads(response.data) except ValueError: - data = response.data + # this path is used if we are deserializing string data + received_data = response.data - return self.__deserialize(data, response_type) + # store our data under the key of 'received_data' so users have some + # context if they are deserializing a string and the data type is wrong + deserialized_data = validate_and_convert_types( + received_data, + response_types_mixed, + ['received_data'], + configuration=self.configuration + ) + return deserialized_data - def __deserialize(self, data, klass): - """Deserializes dict, list, str into an object. - - :param data: dict, list or str. - :param klass: class literal, or string of class name. - - :return: object. - """ - if data is None: - return None - - if type(klass) == str: - if klass.startswith('list['): - sub_kls = re.match(r'list\[(.*)\]', klass).group(1) - return [self.__deserialize(sub_data, sub_kls) - for sub_data in data] - - if klass.startswith('dict('): - sub_kls = re.match(r'dict\(([^,]*), (.*)\)', klass).group(2) - return {k: self.__deserialize(v, sub_kls) - for k, v in six.iteritems(data)} - - # convert str to class - if klass in self.NATIVE_TYPES_MAPPING: - klass = self.NATIVE_TYPES_MAPPING[klass] - else: - klass = getattr(petstore_api.models, klass) - - if klass in self.PRIMITIVE_TYPES: - return self.__deserialize_primitive(data, klass) - elif klass == object: - return self.__deserialize_object(data) - elif klass == datetime.date: - return self.__deserialize_date(data) - elif klass == datetime.datetime: - return self.__deserialize_datatime(data) - else: - return self.__deserialize_model(data, klass) def call_api(self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, files=None, - response_type=None, auth_settings=None, async_req=None, + response_types_mixed=None, auth_settings=None, async_req=None, _return_http_data_only=None, collection_formats=None, _preload_content=True, _request_timeout=None, _host=None): """Makes the HTTP request (synchronous) and returns deserialized data. @@ -310,7 +291,15 @@ def call_api(self, resource_path, method, :param post_params dict: Request post form parameters, for `application/x-www-form-urlencoded`, `multipart/form-data`. :param auth_settings list: Auth Settings names for the request. - :param response: Response data type. + :param response_types_mixed: For the response, a list of + valid classes, or a list tuples of valid classes, or a dict where + the value is a tuple of value classes. + Example values: + [str] + [Pet] + [float, none_type], + [[(int, none_type)]], + [{str: (bool, str, int, float, date, datetime, str, none_type)}] :param files dict: key -> filename, value -> filepath, for `multipart/form-data`. :param async_req bool: execute request asynchronously @@ -336,7 +325,7 @@ def call_api(self, resource_path, method, return self.__call_api(resource_path, method, path_params, query_params, header_params, body, post_params, files, - response_type, auth_settings, + response_types_mixed, auth_settings, _return_http_data_only, collection_formats, _preload_content, _request_timeout, _host) else: @@ -344,7 +333,7 @@ def call_api(self, resource_path, method, method, path_params, query_params, header_params, body, post_params, files, - response_type, auth_settings, + response_types_mixed, auth_settings, _return_http_data_only, collection_formats, _preload_content, @@ -408,7 +397,7 @@ def request(self, method, url, query_params=None, headers=None, _request_timeout=_request_timeout, body=body) else: - raise ValueError( + raise ApiValueError( "http method must be `GET`, `HEAD`, `OPTIONS`," " `POST`, `PATCH`, `PUT` or `DELETE`." ) @@ -523,120 +512,6 @@ def update_params_for_auth(self, headers, querys, auth_settings): elif auth_setting['in'] == 'query': querys.append((auth_setting['key'], auth_setting['value'])) else: - raise ValueError( + raise ApiValueError( 'Authentication token must be in `query` or `header`' ) - - def __deserialize_file(self, response): - """Deserializes body to file - - Saves response body into a file in a temporary folder, - using the filename from the `Content-Disposition` header if provided. - - :param response: RESTResponse. - :return: file path. - """ - fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path) - os.close(fd) - os.remove(path) - - content_disposition = response.getheader("Content-Disposition") - if content_disposition: - filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?', - content_disposition).group(1) - path = os.path.join(os.path.dirname(path), filename) - - with open(path, "wb") as f: - f.write(response.data) - - return path - - def __deserialize_primitive(self, data, klass): - """Deserializes string to primitive type. - - :param data: str. - :param klass: class literal. - - :return: int, long, float, str, bool. - """ - try: - return klass(data) - except UnicodeEncodeError: - return six.text_type(data) - except TypeError: - return data - - def __deserialize_object(self, value): - """Return an original value. - - :return: object. - """ - return value - - def __deserialize_date(self, string): - """Deserializes string to date. - - :param string: str. - :return: date. - """ - try: - from dateutil.parser import parse - return parse(string).date() - except ImportError: - return string - except ValueError: - raise rest.ApiException( - status=0, - reason="Failed to parse `{0}` as date object".format(string) - ) - - def __deserialize_datatime(self, string): - """Deserializes string to datetime. - - The string should be in iso8601 datetime format. - - :param string: str. - :return: datetime. - """ - try: - from dateutil.parser import parse - return parse(string) - except ImportError: - return string - except ValueError: - raise rest.ApiException( - status=0, - reason=( - "Failed to parse `{0}` as datetime object" - .format(string) - ) - ) - - def __deserialize_model(self, data, klass): - """Deserializes list or dict to model. - - :param data: dict, list. - :param klass: class literal. - :return: model object. - """ - - if not klass.openapi_types and not hasattr(klass, - 'get_real_child_model'): - return data - - kwargs = {} - if klass.openapi_types is not None: - for attr, attr_type in six.iteritems(klass.openapi_types): - if (data is not None and - klass.attribute_map[attr] in data and - isinstance(data, (list, dict))): - value = data[klass.attribute_map[attr]] - kwargs[attr] = self.__deserialize(value, attr_type) - - instance = klass(**kwargs) - - if hasattr(instance, 'get_real_child_model'): - klass_name = instance.get_real_child_model(data) - if klass_name: - instance = self.__deserialize(data, klass_name) - return instance diff --git a/samples/client/petstore/python-tornado/petstore_api/exceptions.py b/samples/client/petstore/python-tornado/petstore_api/exceptions.py new file mode 100644 index 000000000000..6bf34b3f9fa7 --- /dev/null +++ b/samples/client/petstore/python-tornado/petstore_api/exceptions.py @@ -0,0 +1,121 @@ +# 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: + is_int = isinstance(pth, int) + if six.PY2 and isinstance(pth, long) and is_int == False: + is_int = True + if is_int: + result += "[{0}]".format(pth) + else: + result += "['{0}']".format(pth) + return result diff --git a/samples/client/petstore/python-tornado/petstore_api/model_utils.py b/samples/client/petstore/python-tornado/petstore_api/model_utils.py new file mode 100644 index 000000000000..148a9cf683ea --- /dev/null +++ b/samples/client/petstore/python-tornado/petstore_api/model_utils.py @@ -0,0 +1,605 @@ +# 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 copy +from datetime import date, datetime # noqa: F401 +import os +import re +import tempfile + +from dateutil.parser import parse +import six + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) + +none_type = type(None) +if six.PY3: + import io + file_type = io.IOBase + # these are needed for when other modules import str and int from here + str = str + int = int +else: + file_type = file # noqa: F821 + str_py2 = str + unicode_py2 = unicode + long_py2 = long + int_py2 = int + # this requires that the future library is installed + from builtins import int, str + + +class OpenApiModel(object): + """The base class for all OpenAPIModels""" + + +def get_simple_class(input_value): + """Returns an input_value's simple class that we will use for type checking + Python2: + float and int will return int, where int is the python3 int backport + str and unicode will return str, where str is the python3 str backport + Note: float and int ARE both instances of int backport + Note: str_py2 and unicode_py2 are NOT both instances of str backport + + Args: + input_value (class/class_instance): the item for which we will return + the simple class + """ + if isinstance(input_value, type): + # input_value is a class + return input_value + elif isinstance(input_value, list): + return list + elif isinstance(input_value, dict): + return dict + elif isinstance(input_value, none_type): + return none_type + elif isinstance(input_value, file_type): + return file_type + elif isinstance(input_value, bool): + # this must be higher than the int check because + # isinstance(True, int) == True + return bool + elif isinstance(input_value, int): + # for python2 input_value==long_instance -> return int + # where int is the python3 int backport + return int + elif isinstance(input_value, datetime): + # this must be higher than the date check because + # isinstance(datetime_instance, date) == True + return datetime + elif isinstance(input_value, date): + return datetime + elif (six.PY2 and isinstance(input_value, (str_py2, unicode_py2, str)) or + isinstance(input_value, str)): + return str + return type(input_value) + + +COERCION_INDEX_BY_TYPE = { + none_type: 0, + list: 1, + OpenApiModel: 2, + dict: 3, + float: 4, + int: 5, + bool: 6, + datetime: 7, + date: 8, + str: 9 +} + +# these are used to limit what type conversions we try to do +# when we have a valid type already and we want to try converting +# to another type +UPCONVERSION_TYPE_PAIRS = ( + (str, datetime), + (str, date), + (list, OpenApiModel), + (dict, OpenApiModel), +) + +COERCIBLE_TYPE_PAIRS = ( + (dict, OpenApiModel), + (list, OpenApiModel), + (str, int), + (str, float), + (str, datetime), + (str, date), + (int, str), + (float, str), + (str, file_type) +) + + +def order_response_types(required_types): + """Returns the required types sorted in coercion order + + Args: + required_types (list/tuple): collection of classes or instance of + list or dict with classs information inside it + + Returns: + (list): coercion order sorted collection of classes or instance + of list or dict with classs information inside it + """ + + def index_getter(class_or_instance): + if isinstance(class_or_instance, list): + return COERCION_INDEX_BY_TYPE[list] + elif isinstance(class_or_instance, dict): + return COERCION_INDEX_BY_TYPE[dict] + elif issubclass(class_or_instance, OpenApiModel): + return COERCION_INDEX_BY_TYPE[OpenApiModel] + return COERCION_INDEX_BY_TYPE[class_or_instance] + + sorted_types = sorted( + required_types, + key=lambda class_or_instance: index_getter(class_or_instance) + ) + return sorted_types + + +def remove_uncoercible(required_types_classes, current_item, must_convert=True): + """Only keeps the type conversions that are possible + + Args: + required_types_classes (tuple): tuple of classes that are required + these should be ordered by COERCION_INDEX_BY_TYPE + current_item (any): the current item to be converted + + Keyword Args: + must_convert (bool): if True the item to convert is of the wrong + type and we want a big list of coercibles + if False, we want a limited list of coercibles + + Returns: + (list): the remaining coercible required types, classes only + """ + current_type_simple = get_simple_class(current_item) + + results_classes = [] + for required_type_class in required_types_classes: + # convert our models to OpenApiModel + required_type_class_simplified = required_type_class + if isinstance(required_type_class_simplified, type): + if issubclass(required_type_class_simplified, OpenApiModel): + required_type_class_simplified = OpenApiModel + + if required_type_class_simplified == current_type_simple: + # don't consider converting to one's own class + continue + + class_pair = (current_type_simple, required_type_class_simplified) + if must_convert and class_pair in COERCIBLE_TYPE_PAIRS: + results_classes.append(required_type_class) + elif class_pair in UPCONVERSION_TYPE_PAIRS: + results_classes.append(required_type_class) + return results_classes + + +def get_required_type_classes(required_types_mixed): + """Converts the tuple required_types into a tuple and a dict described + below + + Args: + required_types_mixed (tuple/list): will contain either classes or + instance of list or dict + + Returns: + (valid_classes, dict_valid_class_to_child_types_mixed): + valid_classes (tuple): the valid classes that the current item + should be + dict_valid_class_to_child_types_mixed (doct): + valid_class (class): this is the key + child_types_mixed (list/dict/tuple): describes the valid child + types + """ + valid_classes = [] + child_req_types_by_current_type = {} + for required_type in required_types_mixed: + if isinstance(required_type, list): + valid_classes.append(list) + child_req_types_by_current_type[list] = required_type[0] + elif isinstance(required_type, dict): + valid_classes.append(dict) + child_req_types_by_current_type[dict] = required_type[str] + else: + valid_classes.append(required_type) + return tuple(valid_classes), child_req_types_by_current_type + + +def change_keys_js_to_python(input_dict, model_class): + """ + Converts from javascript_key keys in the input_dict to python_keys in + the output dict using the mapping in model_class + """ + + output_dict = {} + reversed_attr_map = {value: key for key, value in + six.iteritems(model_class.attribute_map)} + for javascript_key, value in six.iteritems(input_dict): + python_key = reversed_attr_map.get(javascript_key) + if python_key is None: + # if the key is unknown, it is in error or it is an + # additionalProperties variable + python_key = javascript_key + output_dict[python_key] = value + return output_dict + + +def get_type_error(var_value, path_to_item, valid_classes, key_type=False): + error_msg = type_error_message( + var_name=path_to_item[-1], + var_value=var_value, + valid_classes=valid_classes, + key_type=key_type + ) + return ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=valid_classes, + key_type=key_type + ) + + +def deserialize_primitive(data, klass, path_to_item): + """Deserializes string to primitive type. + + :param data: str/int/float + :param klass: str/class the class to convert to + + :return: int, float, str, bool, date, datetime + """ + additional_message = "" + try: + if klass in {datetime, date}: + additional_message = ( + "If you need your parameter to have a fallback " + "string value, please set its type as `type: {}` in your " + "spec. That allows the value to be any type. " + ) + if klass == datetime: + if len(data) < 8: + raise ValueError("This is not a datetime") + # The string should be in iso8601 datetime format. + parsed_datetime = parse(data) + date_only = (parsed_datetime.hour == 0 and + parsed_datetime.minute == 0 and + parsed_datetime.second == 0 and + parsed_datetime.tzinfo == None and + 8 <= len(data) <= 10) + if date_only: + raise ValueError("This is a date, not a datetime") + return parsed_datetime + elif klass == date: + if len(data) < 8: + raise ValueError("This is not a date") + return parse(data).date() + else: + converted_value = klass(data) + if isinstance(data, str) and klass == float: + if str(converted_value) != data: + # '7' -> 7.0 -> '7.0' != '7' + raise ValueError('This is not a float') + return converted_value + except (OverflowError, ValueError): + # parse can raise OverflowError + raise ApiValueError( + "{0}Failed to parse {1} as {2}".format( + additional_message, repr(data), get_py3_class_name(klass) + ), + path_to_item=path_to_item + ) + + +def deserialize_model(model_data, model_class, path_to_item, configuration): + """Deserializes model_data to model instance. + + Args: + model_data (list/dict): data to instantiate the model + model_class (OpenApiModel): the model class + path_to_item (list): path to the model in the received data + configuration (Configuration): the instance to use to convert files + + Returns: + model instance + + Raise: + ApiTypeError + ApiValueError + ApiKeyError + """ + fixed_model_data = copy.deepcopy(model_data) + + if isinstance(fixed_model_data, dict): + fixed_model_data = change_keys_js_to_python(fixed_model_data, + model_class) + + kw_args = dict(_check_type=True, + _path_to_item=path_to_item, + _configuration=configuration) + if isinstance(model_data, list): + instance = model_class(*model_data, **kw_args) + elif isinstance(model_data, dict): + kw_args.update(fixed_model_data) + instance = model_class(**kw_args) + + if hasattr(instance, 'get_real_child_model'): + discriminator_class = instance.get_real_child_model(model_data) + if discriminator_class: + if isinstance(model_data, list): + instance = discriminator_class(*model_data, **kw_args) + elif isinstance(model_data, dict): + instance = discriminator_class(**kw_args) + + return instance + + +def deserialize_file(response_data, configuration, content_disposition=None): + """Deserializes body to file + + Saves response body into a file in a temporary folder, + using the filename from the `Content-Disposition` header if provided. + + Args: + param response_data (str): the file data to write + configuration (Configuration): the instance to use to convert files + + Keyword Args: + content_disposition (str): the value of the Content-Disposition + header + + Returns: + (str): the deserialized file path + """ + fd, path = tempfile.mkstemp(dir=configuration.temp_folder_path) + os.close(fd) + os.remove(path) + + if content_disposition: + filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?', + content_disposition).group(1) + path = os.path.join(os.path.dirname(path), filename) + + with open(path, "wb") as f: + if six.PY3 and isisinstance(response_data, str): + # in python3 change str to bytes so we can write it + response_data = response_data.encode('utf-8') + f.write(response_data) + + return path + + +def attempt_convert_item(input_value, valid_classes, path_to_item, + configuration, key_type=False, must_convert=False): + """ + Args: + input_value (any): the data to convert + valid_classes (any): the classes that are valid + path_to_item (list): the path to the item to convert + configuration (Configuration): the instance to use to convert files + key_type (bool): if True we need to convert a key type (not supported) + must_convert (bool): if True we must convert + + Returns: + instance (any) the fixed item + + Raises: + ApiTypeError + ApiValueError + ApiKeyError + """ + valid_classes_ordered = order_response_types(valid_classes) + valid_classes_coercible = remove_uncoercible( + valid_classes_ordered, input_value) + if not valid_classes_coercible or key_type: + # we do not handle keytype errors, json will take care + # of this for us + raise get_type_error(input_value, path_to_item, valid_classes, + key_type=key_type) + deserialized_item = None + for valid_class in valid_classes_coercible: + try: + if issubclass(valid_class, OpenApiModel): + return deserialize_model(input_value, valid_class, + path_to_item, configuration) + elif valid_class == file_type: + return deserialize_file(input_value, configuration) + return deserialize_primitive(input_value, valid_class, + path_to_item) + except (ApiTypeError, ApiValueError, ApiKeyError) as conversion_exc: + if must_convert: + raise conversion_exc + # if we have conversion errors when must_convert == False + # we ignore the exception and move on to the next class + continue + # we were unable to convert, must_convert == False + return input_value + + +def validate_and_convert_types(input_value, required_types_mixed, path_to_item, + configuration=None): + """Raises a TypeError is there is a problem, otherwise returns value + + Args: + input_value (any): the data to validate/convert + required_types_mixed (list/dict/tuple): A list of + valid classes, or a list tuples of valid classes, or a dict where + the value is a tuple of value classes + path_to_item: (list) the path to the data being validated + this stores a list of keys or indices to get to the data being + validated + configuration: (Configuration): the configuration class to use + when converting file_type items. + If passed, conversion will be attempted when possible + If not passed, no conversions will be attempted and + exceptions will be raised + + Returns: + the correctly typed value + + Raises: + ApiTypeError + """ + results = get_required_type_classes(required_types_mixed) + valid_classes, child_req_types_by_current_type = results + + input_class_simple = get_simple_class(input_value) + valid_type = input_class_simple in set(valid_classes) + if not valid_type: + if configuration: + # if input_value is not valid_type try to convert it + converted_instance = attempt_convert_item(input_value, + valid_classes, path_to_item, configuration, key_type=False, + must_convert=True) + return converted_instance + else: + raise get_type_error(input_value, path_to_item, valid_classes, + key_type=False) + + # input_value's type is in valid_classes + if len(valid_classes) > 1 and configuration: + # there are valid classes which are not the current class + valid_classes_coercible = remove_uncoercible( + valid_classes, input_value, must_convert=False) + if valid_classes_coercible: + converted_instance = attempt_convert_item(input_value, + valid_classes_coercible, path_to_item, configuration, + key_type=False, must_convert=False) + return converted_instance + + if child_req_types_by_current_type == {}: + # all types are of the required types and there are no more inner + # variables left to look at + return input_value + inner_required_types = child_req_types_by_current_type.get( + type(input_value) + ) + if inner_required_types is None: + # for this type, there are not more inner variables left to look at + return input_value + if isinstance(input_value, list): + if input_value == []: + # allow an empty list + return input_value + for index, inner_value in enumerate(input_value): + inner_path = list(path_to_item) + inner_path.append(index) + input_value[index] = validate_and_convert_types(inner_value, + inner_required_types, inner_path, configuration=configuration) + elif isinstance(input_value, dict): + if input_value == {}: + # allow an empty dict + return input_value + for inner_key, inner_val in six.iteritems(input_value): + inner_path = list(path_to_item) + inner_path.append(inner_key) + if get_simple_class(inner_key) != str: + raise get_type_error(inner_key, inner_path, valid_classes, + key_type=True) + input_value[inner_key] = validate_and_convert_types(inner_val, + inner_required_types, inner_path, configuration=configuration) + return input_value + + +def model_to_dict(model_instance, serialize=True): + """Returns the model properties as a dict + + Args: + model_instance (one of your model instances): the model instance that + will be converted to a dict. + + Keyword Args: + serialize (bool): if True, the keys in the dict will be values from + attribute_map + """ + result = {} + + for attr, value in six.iteritems(model_instance._data_store): + if serialize: + attr = model_instance.attribute_map[attr] + if isinstance(value, list): + result[attr] = list(map( + lambda x: model_to_dict(x, serialize=serialize) + if hasattr(x, '_data_store') else x, value + )) + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], + model_to_dict(item[1], serialize=serialize)) + if hasattr(item[1], '_data_store') else item, + value.items() + )) + elif hasattr(value, '_data_store'): + result[attr] = model_to_dict(value, serialize=serialize) + else: + result[attr] = value + + return result + + +def type_error_message(var_value=None, var_name=None, valid_classes=None, + key_type=None): + """ + Keyword Args: + var_value (any): the variable which has the type_error + var_name (str): the name of the variable which has the typ error + valid_classes (tuple): the accepted classes for current_item's + value + 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 + """ + key_or_value = 'value' + if key_type: + key_or_value = 'key' + valid_classes_phrase = get_valid_classes_phrase(valid_classes) + msg = ( + "Invalid type for variable '{0}'. Required {1} type {2} and " + "passed type was {3}".format( + var_name, + key_or_value, + valid_classes_phrase, + type(var_value).__name__, + ) + ) + return msg + + +def get_valid_classes_phrase(input_classes): + """Returns a string phrase describing what types are allowed + Note: Adds the extra valid classes in python2 + """ + all_classes = list(input_classes) + if six.PY2 and str in input_classes: + all_classes.extend([str_py2, unicode_py2]) + if six.PY2 and int in input_classes: + all_classes.extend([int_py2, long_py2]) + all_classes = sorted(all_classes, key=lambda cls: cls.__name__) + all_class_names = [cls.__name__ for cls in all_classes] + if len(all_class_names) == 1: + return 'is {0}'.format(all_class_names[0]) + return "is one of [{0}]".format(", ".join(all_class_names)) + + +def get_py3_class_name(input_class): + if six.PY2: + if input_class == str: + return 'str' + elif input_class == int: + return 'int' + return input_class.__name__ diff --git a/samples/client/petstore/python-tornado/petstore_api/models/__init__.py b/samples/client/petstore/python-tornado/petstore_api/models/__init__.py index 3a39467a63ac..9c318d971f6f 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/__init__.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/__init__.py @@ -14,7 +14,14 @@ from __future__ import absolute_import # import models into model package +from petstore_api.models.additional_properties_any_type import AdditionalPropertiesAnyType +from petstore_api.models.additional_properties_array import AdditionalPropertiesArray +from petstore_api.models.additional_properties_boolean import AdditionalPropertiesBoolean from petstore_api.models.additional_properties_class import AdditionalPropertiesClass +from petstore_api.models.additional_properties_integer import AdditionalPropertiesInteger +from petstore_api.models.additional_properties_number import AdditionalPropertiesNumber +from petstore_api.models.additional_properties_object import AdditionalPropertiesObject +from petstore_api.models.additional_properties_string import AdditionalPropertiesString from petstore_api.models.animal import Animal from petstore_api.models.api_response import ApiResponse from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly diff --git a/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_any_type.py b/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_any_type.py new file mode 100644 index 000000000000..2438b307cf8b --- /dev/null +++ b/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_any_type.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesAnyType(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [bool, date, datetime, dict, float, int, list, str] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesAnyType - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesAnyType. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesAnyType. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesAnyType. + + + Returns: + (str): The name of this AdditionalPropertiesAnyType. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesAnyType): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_array.py b/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_array.py new file mode 100644 index 000000000000..ba0306157ff9 --- /dev/null +++ b/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_array.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesArray(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [[(bool, date, datetime, dict, float, int, list, str)]] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesArray - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesArray. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesArray. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesArray. + + + Returns: + (str): The name of this AdditionalPropertiesArray. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesArray): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_boolean.py b/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_boolean.py new file mode 100644 index 000000000000..4d59de6fe53b --- /dev/null +++ b/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_boolean.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesBoolean(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [bool] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesBoolean - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesBoolean. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesBoolean. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesBoolean. + + + Returns: + (str): The name of this AdditionalPropertiesBoolean. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesBoolean): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_class.py b/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_class.py index dc4648ae1c7f..a38defb2045e 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_class.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_class.py @@ -15,8 +15,27 @@ import six - -class AdditionalPropertiesClass(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesClass(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +46,415 @@ class AdditionalPropertiesClass(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'map_property': 'dict(str, str)', - 'map_of_map_property': 'dict(str, dict(str, str))' + 'map_string': [{str: (str,)}], # noqa: E501 + 'map_number': [{str: (float,)}], # noqa: E501 + 'map_integer': [{str: (int,)}], # noqa: E501 + 'map_boolean': [{str: (bool,)}], # noqa: E501 + 'map_array_integer': [{str: ([(int,)],)}], # noqa: E501 + 'map_array_anytype': [{str: ([(bool, date, datetime, dict, float, int, list, str)],)}], # noqa: E501 + 'map_map_string': [{str: ({str: (str,)},)}], # noqa: E501 + 'map_map_anytype': [{str: ({str: (bool, date, datetime, dict, float, int, list, str)},)}], # noqa: E501 + 'anytype_1': [bool, date, datetime, dict, float, int, list, str], # noqa: E501 + 'anytype_2': [bool, date, datetime, dict, float, int, list, str], # noqa: E501 + 'anytype_3': [bool, date, datetime, dict, float, int, list, str] # noqa: E501 } - attribute_map = { - 'map_property': 'map_property', - 'map_of_map_property': 'map_of_map_property' + 'map_string': 'map_string', # noqa: E501 + 'map_number': 'map_number', # noqa: E501 + 'map_integer': 'map_integer', # noqa: E501 + 'map_boolean': 'map_boolean', # noqa: E501 + 'map_array_integer': 'map_array_integer', # noqa: E501 + 'map_array_anytype': 'map_array_anytype', # noqa: E501 + 'map_map_string': 'map_map_string', # noqa: E501 + 'map_map_anytype': 'map_map_anytype', # noqa: E501 + 'anytype_1': 'anytype_1', # noqa: E501 + 'anytype_2': 'anytype_2', # noqa: E501 + 'anytype_3': 'anytype_3' # noqa: E501 } - def __init__(self, map_property=None, map_of_map_property=None): # noqa: E501 - """AdditionalPropertiesClass - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesClass - 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 False + _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 + _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. + map_string ({str: (str,)}): [optional] # noqa: E501 + map_number ({str: (float,)}): [optional] # noqa: E501 + map_integer ({str: (int,)}): [optional] # noqa: E501 + map_boolean ({str: (bool,)}): [optional] # noqa: E501 + map_array_integer ({str: ([(int,)],)}): [optional] # noqa: E501 + map_array_anytype ({str: ([(bool, date, datetime, dict, float, int, list, str)],)}): [optional] # noqa: E501 + map_map_string ({str: ({str: (str,)},)}): [optional] # noqa: E501 + map_map_anytype ({str: ({str: (bool, date, datetime, dict, float, int, list, str)},)}): [optional] # noqa: E501 + anytype_1 (bool, date, datetime, dict, float, int, list, str): [optional] # noqa: E501 + anytype_2 (bool, date, datetime, dict, float, int, list, str): [optional] # noqa: E501 + anytype_3 (bool, date, datetime, dict, float, int, list, str): [optional] # noqa: E501 + """ - self._map_property = None - self._map_of_map_property = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def map_string(self): + """Gets the map_string of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + ({str: (str,)}): The map_string of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('map_string') + + @map_string.setter + def map_string( + self, map_string): + """Sets the map_string of this AdditionalPropertiesClass. + + + Returns: + ({str: (str,)}): The map_string of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'map_string', + map_string + ) + + @property + def map_number(self): + """Gets the map_number of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + ({str: (float,)}): The map_number of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('map_number') + + @map_number.setter + def map_number( + self, map_number): + """Sets the map_number of this AdditionalPropertiesClass. + + + Returns: + ({str: (float,)}): The map_number of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'map_number', + map_number + ) + + @property + def map_integer(self): + """Gets the map_integer of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + ({str: (int,)}): The map_integer of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('map_integer') + + @map_integer.setter + def map_integer( + self, map_integer): + """Sets the map_integer of this AdditionalPropertiesClass. + + + Returns: + ({str: (int,)}): The map_integer of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'map_integer', + map_integer + ) + + @property + def map_boolean(self): + """Gets the map_boolean of this AdditionalPropertiesClass. # noqa: E501 - if map_property is not None: - self.map_property = map_property - if map_of_map_property is not None: - self.map_of_map_property = map_of_map_property + + Returns: + ({str: (bool,)}): The map_boolean of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('map_boolean') + + @map_boolean.setter + def map_boolean( + self, map_boolean): + """Sets the map_boolean of this AdditionalPropertiesClass. + + + Returns: + ({str: (bool,)}): The map_boolean of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'map_boolean', + map_boolean + ) @property - def map_property(self): - """Gets the map_property of this AdditionalPropertiesClass. # noqa: E501 + def map_array_integer(self): + """Gets the map_array_integer of this AdditionalPropertiesClass. # noqa: E501 - :return: The map_property of this AdditionalPropertiesClass. # noqa: E501 - :rtype: dict(str, str) + Returns: + ({str: ([(int,)],)}): The map_array_integer of this AdditionalPropertiesClass. # noqa: E501 """ - return self._map_property + return self._data_store.get('map_array_integer') - @map_property.setter - def map_property(self, map_property): - """Sets the map_property of this AdditionalPropertiesClass. + @map_array_integer.setter + def map_array_integer( + self, map_array_integer): + """Sets the map_array_integer of this AdditionalPropertiesClass. - :param map_property: The map_property of this AdditionalPropertiesClass. # noqa: E501 - :type: dict(str, str) + Returns: + ({str: ([(int,)],)}): The map_array_integer of this AdditionalPropertiesClass. # noqa: E501 """ - self._map_property = map_property + self.__setitem__( + 'map_array_integer', + map_array_integer + ) @property - def map_of_map_property(self): - """Gets the map_of_map_property of this AdditionalPropertiesClass. # noqa: E501 + def map_array_anytype(self): + """Gets the map_array_anytype of this AdditionalPropertiesClass. # noqa: E501 - :return: The map_of_map_property of this AdditionalPropertiesClass. # noqa: E501 - :rtype: dict(str, dict(str, str)) + Returns: + ({str: ([(bool, date, datetime, dict, float, int, list, str)],)}): The map_array_anytype of this AdditionalPropertiesClass. # noqa: E501 """ - return self._map_of_map_property + return self._data_store.get('map_array_anytype') - @map_of_map_property.setter - def map_of_map_property(self, map_of_map_property): - """Sets the map_of_map_property of this AdditionalPropertiesClass. + @map_array_anytype.setter + def map_array_anytype( + self, map_array_anytype): + """Sets the map_array_anytype of this AdditionalPropertiesClass. - :param map_of_map_property: The map_of_map_property of this AdditionalPropertiesClass. # noqa: E501 - :type: dict(str, dict(str, str)) + Returns: + ({str: ([(bool, date, datetime, dict, float, int, list, str)],)}): The map_array_anytype of this AdditionalPropertiesClass. # noqa: E501 """ - self._map_of_map_property = map_of_map_property + self.__setitem__( + 'map_array_anytype', + map_array_anytype + ) + + @property + def map_map_string(self): + """Gets the map_map_string of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + ({str: ({str: (str,)},)}): The map_map_string of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('map_map_string') + + @map_map_string.setter + def map_map_string( + self, map_map_string): + """Sets the map_map_string of this AdditionalPropertiesClass. + + + Returns: + ({str: ({str: (str,)},)}): The map_map_string of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'map_map_string', + map_map_string + ) + + @property + def map_map_anytype(self): + """Gets the map_map_anytype of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + ({str: ({str: (bool, date, datetime, dict, float, int, list, str)},)}): The map_map_anytype of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('map_map_anytype') + + @map_map_anytype.setter + def map_map_anytype( + self, map_map_anytype): + """Sets the map_map_anytype of this AdditionalPropertiesClass. + + + Returns: + ({str: ({str: (bool, date, datetime, dict, float, int, list, str)},)}): The map_map_anytype of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'map_map_anytype', + map_map_anytype + ) + + @property + def anytype_1(self): + """Gets the anytype_1 of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + (bool, date, datetime, dict, float, int, list, str): The anytype_1 of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('anytype_1') + + @anytype_1.setter + def anytype_1( + self, anytype_1): + """Sets the anytype_1 of this AdditionalPropertiesClass. + + + Returns: + (bool, date, datetime, dict, float, int, list, str): The anytype_1 of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'anytype_1', + anytype_1 + ) + + @property + def anytype_2(self): + """Gets the anytype_2 of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + (bool, date, datetime, dict, float, int, list, str): The anytype_2 of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('anytype_2') + + @anytype_2.setter + def anytype_2( + self, anytype_2): + """Sets the anytype_2 of this AdditionalPropertiesClass. + + + Returns: + (bool, date, datetime, dict, float, int, list, str): The anytype_2 of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'anytype_2', + anytype_2 + ) + + @property + def anytype_3(self): + """Gets the anytype_3 of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + (bool, date, datetime, dict, float, int, list, str): The anytype_3 of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('anytype_3') + + @anytype_3.setter + def anytype_3( + self, anytype_3): + """Sets the anytype_3 of this AdditionalPropertiesClass. + + + Returns: + (bool, date, datetime, dict, float, int, list, str): The anytype_3 of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'anytype_3', + anytype_3 + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_integer.py b/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_integer.py new file mode 100644 index 000000000000..50994b5859e2 --- /dev/null +++ b/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_integer.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesInteger(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [int] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesInteger - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesInteger. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesInteger. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesInteger. + + + Returns: + (str): The name of this AdditionalPropertiesInteger. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesInteger): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_number.py b/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_number.py new file mode 100644 index 000000000000..6005bf6a2f55 --- /dev/null +++ b/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_number.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesNumber(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [float] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesNumber - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesNumber. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesNumber. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesNumber. + + + Returns: + (str): The name of this AdditionalPropertiesNumber. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesNumber): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_object.py b/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_object.py new file mode 100644 index 000000000000..6b18c3e18f30 --- /dev/null +++ b/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_object.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesObject(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [{str: (bool, date, datetime, dict, float, int, list, str)}] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesObject - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesObject. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesObject. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesObject. + + + Returns: + (str): The name of this AdditionalPropertiesObject. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesObject): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_string.py b/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_string.py new file mode 100644 index 000000000000..61d7e0278d63 --- /dev/null +++ b/samples/client/petstore/python-tornado/petstore_api/models/additional_properties_string.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesString(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [str] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesString - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesString. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesString. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesString. + + + Returns: + (str): The name of this AdditionalPropertiesString. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesString): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python-tornado/petstore_api/models/animal.py b/samples/client/petstore/python-tornado/petstore_api/models/animal.py index abd6f705e5e8..ba09d8520ca1 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/animal.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/animal.py @@ -15,8 +15,29 @@ import six - -class Animal(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.cat import Cat +from petstore_api.models.dog import Dog + + +class Animal(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,78 +48,167 @@ class Animal(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'class_name': 'str', - 'color': 'str' + 'class_name': [str], # noqa: E501 + 'color': [str] # noqa: E501 } - attribute_map = { - 'class_name': 'className', - 'color': 'color' + 'class_name': 'className', # noqa: E501 + 'color': 'color' # noqa: E501 } - discriminator_value_class_map = { - 'Dog': 'Dog', - 'Cat': 'Cat' + 'Dog': Dog, + 'Cat': Cat } - def __init__(self, class_name=None, color='red'): # noqa: E501 - """Animal - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, class_name, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Animal - a model defined in OpenAPI + + Args: + class_name (str): + + 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 False + _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 + _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. + color (str): [optional] if omitted the server will use the default value of 'red' # noqa: E501 + """ - self._class_name = None - self._color = None + self._data_store = {} self.discriminator = 'class_name' + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + # assign using .var_name to check against nullable and enums self.class_name = class_name - if color is not None: - self.color = color + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def class_name(self): """Gets the class_name of this Animal. # noqa: E501 - :return: The class_name of this Animal. # noqa: E501 - :rtype: str + Returns: + (str): The class_name of this Animal. # noqa: E501 """ - return self._class_name + return self._data_store.get('class_name') @class_name.setter - def class_name(self, class_name): + def class_name( + self, class_name): """Sets the class_name of this Animal. - :param class_name: The class_name of this Animal. # noqa: E501 - :type: str + Returns: + (str): The class_name of this Animal. # noqa: E501 """ if class_name is None: - raise ValueError("Invalid value for `class_name`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `class_name`, must not be `None`") # noqa: E501 - self._class_name = class_name + self.__setitem__( + 'class_name', + class_name + ) @property def color(self): """Gets the color of this Animal. # noqa: E501 - :return: The color of this Animal. # noqa: E501 - :rtype: str + Returns: + (str): The color of this Animal. # noqa: E501 """ - return self._color + return self._data_store.get('color') @color.setter - def color(self, color): + def color( + self, color): """Sets the color of this Animal. - :param color: The color of this Animal. # noqa: E501 - :type: str + Returns: + (str): The color of this Animal. # noqa: E501 """ - self._color = color + self.__setitem__( + 'color', + color + ) def get_real_child_model(self, data): """Returns the real base class specified by the discriminator""" @@ -108,27 +218,7 @@ def get_real_child_model(self, data): 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/api_response.py b/samples/client/petstore/python-tornado/petstore_api/models/api_response.py index e62983030491..50fcf50f5207 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/api_response.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/api_response.py @@ -15,8 +15,27 @@ import six - -class ApiResponse(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ApiResponse(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,122 +46,191 @@ class ApiResponse(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'code': 'int', - 'type': 'str', - 'message': 'str' + 'code': [int], # noqa: E501 + 'type': [str], # noqa: E501 + 'message': [str] # noqa: E501 } - attribute_map = { - 'code': 'code', - 'type': 'type', - 'message': 'message' + 'code': 'code', # noqa: E501 + 'type': 'type', # noqa: E501 + 'message': 'message' # noqa: E501 } - def __init__(self, code=None, type=None, message=None): # noqa: E501 - """ApiResponse - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ApiResponse - 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 False + _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 + _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. + code (int): [optional] # noqa: E501 + type (str): [optional] # noqa: E501 + message (str): [optional] # noqa: E501 + """ - self._code = None - self._type = None - self._message = None + self._data_store = {} self.discriminator = None - - if code is not None: - self.code = code - if type is not None: - self.type = type - if message is not None: - self.message = message + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def code(self): """Gets the code of this ApiResponse. # noqa: E501 - :return: The code of this ApiResponse. # noqa: E501 - :rtype: int + Returns: + (int): The code of this ApiResponse. # noqa: E501 """ - return self._code + return self._data_store.get('code') @code.setter - def code(self, code): + def code( + self, code): """Sets the code of this ApiResponse. - :param code: The code of this ApiResponse. # noqa: E501 - :type: int + Returns: + (int): The code of this ApiResponse. # noqa: E501 """ - self._code = code + self.__setitem__( + 'code', + code + ) @property def type(self): """Gets the type of this ApiResponse. # noqa: E501 - :return: The type of this ApiResponse. # noqa: E501 - :rtype: str + Returns: + (str): The type of this ApiResponse. # noqa: E501 """ - return self._type + return self._data_store.get('type') @type.setter - def type(self, type): + def type( + self, type): """Sets the type of this ApiResponse. - :param type: The type of this ApiResponse. # noqa: E501 - :type: str + Returns: + (str): The type of this ApiResponse. # noqa: E501 """ - self._type = type + self.__setitem__( + 'type', + type + ) @property def message(self): """Gets the message of this ApiResponse. # noqa: E501 - :return: The message of this ApiResponse. # noqa: E501 - :rtype: str + Returns: + (str): The message of this ApiResponse. # noqa: E501 """ - return self._message + return self._data_store.get('message') @message.setter - def message(self, message): + def message( + self, message): """Sets the message of this ApiResponse. - :param message: The message of this ApiResponse. # noqa: E501 - :type: str + Returns: + (str): The message of this ApiResponse. # noqa: E501 """ - self._message = message + self.__setitem__( + 'message', + message + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/array_of_array_of_number_only.py b/samples/client/petstore/python-tornado/petstore_api/models/array_of_array_of_number_only.py index fde218a4661c..407b261c7f34 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/array_of_array_of_number_only.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/array_of_array_of_number_only.py @@ -15,8 +15,27 @@ import six - -class ArrayOfArrayOfNumberOnly(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ArrayOfArrayOfNumberOnly(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class ArrayOfArrayOfNumberOnly(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'array_array_number': 'list[list[float]]' + 'array_array_number': [[([(float,)],)]] # noqa: E501 } - attribute_map = { - 'array_array_number': 'ArrayArrayNumber' + 'array_array_number': 'ArrayArrayNumber' # noqa: E501 } - def __init__(self, array_array_number=None): # noqa: E501 - """ArrayOfArrayOfNumberOnly - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ArrayOfArrayOfNumberOnly - a model defined in OpenAPI - self._array_array_number = None - self.discriminator = None - if array_array_number is not None: - self.array_array_number = array_array_number + + 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 False + _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 + _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. + array_array_number ([([(float,)],)]): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def array_array_number(self): """Gets the array_array_number of this ArrayOfArrayOfNumberOnly. # noqa: E501 - :return: The array_array_number of this ArrayOfArrayOfNumberOnly. # noqa: E501 - :rtype: list[list[float]] + Returns: + ([([(float,)],)]): The array_array_number of this ArrayOfArrayOfNumberOnly. # noqa: E501 """ - return self._array_array_number + return self._data_store.get('array_array_number') @array_array_number.setter - def array_array_number(self, array_array_number): + def array_array_number( + self, array_array_number): """Sets the array_array_number of this ArrayOfArrayOfNumberOnly. - :param array_array_number: The array_array_number of this ArrayOfArrayOfNumberOnly. # noqa: E501 - :type: list[list[float]] + Returns: + ([([(float,)],)]): The array_array_number of this ArrayOfArrayOfNumberOnly. # noqa: E501 """ - self._array_array_number = array_array_number + self.__setitem__( + 'array_array_number', + array_array_number + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/array_of_number_only.py b/samples/client/petstore/python-tornado/petstore_api/models/array_of_number_only.py index 8999e563c4a6..790a6761dc06 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/array_of_number_only.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/array_of_number_only.py @@ -15,8 +15,27 @@ import six - -class ArrayOfNumberOnly(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ArrayOfNumberOnly(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class ArrayOfNumberOnly(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'array_number': 'list[float]' + 'array_number': [[(float,)]] # noqa: E501 } - attribute_map = { - 'array_number': 'ArrayNumber' + 'array_number': 'ArrayNumber' # noqa: E501 } - def __init__(self, array_number=None): # noqa: E501 - """ArrayOfNumberOnly - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ArrayOfNumberOnly - a model defined in OpenAPI - self._array_number = None - self.discriminator = None - if array_number is not None: - self.array_number = array_number + + 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 False + _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 + _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. + array_number ([(float,)]): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def array_number(self): """Gets the array_number of this ArrayOfNumberOnly. # noqa: E501 - :return: The array_number of this ArrayOfNumberOnly. # noqa: E501 - :rtype: list[float] + Returns: + ([(float,)]): The array_number of this ArrayOfNumberOnly. # noqa: E501 """ - return self._array_number + return self._data_store.get('array_number') @array_number.setter - def array_number(self, array_number): + def array_number( + self, array_number): """Sets the array_number of this ArrayOfNumberOnly. - :param array_number: The array_number of this ArrayOfNumberOnly. # noqa: E501 - :type: list[float] + Returns: + ([(float,)]): The array_number of this ArrayOfNumberOnly. # noqa: E501 """ - self._array_number = array_number + self.__setitem__( + 'array_number', + array_number + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/array_test.py b/samples/client/petstore/python-tornado/petstore_api/models/array_test.py index 05cc108139a5..63e94762f367 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/array_test.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/array_test.py @@ -15,8 +15,28 @@ import six - -class ArrayTest(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.read_only_first import ReadOnlyFirst + + +class ArrayTest(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,122 +47,191 @@ class ArrayTest(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'array_of_string': 'list[str]', - 'array_array_of_integer': 'list[list[int]]', - 'array_array_of_model': 'list[list[ReadOnlyFirst]]' + 'array_of_string': [[(str,)]], # noqa: E501 + 'array_array_of_integer': [[([(int,)],)]], # noqa: E501 + 'array_array_of_model': [[([(ReadOnlyFirst,)],)]] # noqa: E501 } - attribute_map = { - 'array_of_string': 'array_of_string', - 'array_array_of_integer': 'array_array_of_integer', - 'array_array_of_model': 'array_array_of_model' + 'array_of_string': 'array_of_string', # noqa: E501 + 'array_array_of_integer': 'array_array_of_integer', # noqa: E501 + 'array_array_of_model': 'array_array_of_model' # noqa: E501 } - def __init__(self, array_of_string=None, array_array_of_integer=None, array_array_of_model=None): # noqa: E501 - """ArrayTest - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ArrayTest - 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 False + _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 + _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. + array_of_string ([(str,)]): [optional] # noqa: E501 + array_array_of_integer ([([(int,)],)]): [optional] # noqa: E501 + array_array_of_model ([([(ReadOnlyFirst,)],)]): [optional] # noqa: E501 + """ - self._array_of_string = None - self._array_array_of_integer = None - self._array_array_of_model = None + self._data_store = {} self.discriminator = None - - if array_of_string is not None: - self.array_of_string = array_of_string - if array_array_of_integer is not None: - self.array_array_of_integer = array_array_of_integer - if array_array_of_model is not None: - self.array_array_of_model = array_array_of_model + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def array_of_string(self): """Gets the array_of_string of this ArrayTest. # noqa: E501 - :return: The array_of_string of this ArrayTest. # noqa: E501 - :rtype: list[str] + Returns: + ([(str,)]): The array_of_string of this ArrayTest. # noqa: E501 """ - return self._array_of_string + return self._data_store.get('array_of_string') @array_of_string.setter - def array_of_string(self, array_of_string): + def array_of_string( + self, array_of_string): """Sets the array_of_string of this ArrayTest. - :param array_of_string: The array_of_string of this ArrayTest. # noqa: E501 - :type: list[str] + Returns: + ([(str,)]): The array_of_string of this ArrayTest. # noqa: E501 """ - self._array_of_string = array_of_string + self.__setitem__( + 'array_of_string', + array_of_string + ) @property def array_array_of_integer(self): """Gets the array_array_of_integer of this ArrayTest. # noqa: E501 - :return: The array_array_of_integer of this ArrayTest. # noqa: E501 - :rtype: list[list[int]] + Returns: + ([([(int,)],)]): The array_array_of_integer of this ArrayTest. # noqa: E501 """ - return self._array_array_of_integer + return self._data_store.get('array_array_of_integer') @array_array_of_integer.setter - def array_array_of_integer(self, array_array_of_integer): + def array_array_of_integer( + self, array_array_of_integer): """Sets the array_array_of_integer of this ArrayTest. - :param array_array_of_integer: The array_array_of_integer of this ArrayTest. # noqa: E501 - :type: list[list[int]] + Returns: + ([([(int,)],)]): The array_array_of_integer of this ArrayTest. # noqa: E501 """ - self._array_array_of_integer = array_array_of_integer + self.__setitem__( + 'array_array_of_integer', + array_array_of_integer + ) @property def array_array_of_model(self): """Gets the array_array_of_model of this ArrayTest. # noqa: E501 - :return: The array_array_of_model of this ArrayTest. # noqa: E501 - :rtype: list[list[ReadOnlyFirst]] + Returns: + ([([(ReadOnlyFirst,)],)]): The array_array_of_model of this ArrayTest. # noqa: E501 """ - return self._array_array_of_model + return self._data_store.get('array_array_of_model') @array_array_of_model.setter - def array_array_of_model(self, array_array_of_model): + def array_array_of_model( + self, array_array_of_model): """Sets the array_array_of_model of this ArrayTest. - :param array_array_of_model: The array_array_of_model of this ArrayTest. # noqa: E501 - :type: list[list[ReadOnlyFirst]] + Returns: + ([([(ReadOnlyFirst,)],)]): The array_array_of_model of this ArrayTest. # noqa: E501 """ - self._array_array_of_model = array_array_of_model + self.__setitem__( + 'array_array_of_model', + array_array_of_model + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/capitalization.py b/samples/client/petstore/python-tornado/petstore_api/models/capitalization.py index 923f5c4aae86..97f1c86c1cbf 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/capitalization.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/capitalization.py @@ -15,8 +15,27 @@ import six - -class Capitalization(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Capitalization(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,155 +46,246 @@ class Capitalization(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'small_camel': 'str', - 'capital_camel': 'str', - 'small_snake': 'str', - 'capital_snake': 'str', - 'sca_eth_flow_points': 'str', - 'att_name': 'str' + 'small_camel': [str], # noqa: E501 + 'capital_camel': [str], # noqa: E501 + 'small_snake': [str], # noqa: E501 + 'capital_snake': [str], # noqa: E501 + 'sca_eth_flow_points': [str], # noqa: E501 + 'att_name': [str] # noqa: E501 } - attribute_map = { - 'small_camel': 'smallCamel', - 'capital_camel': 'CapitalCamel', - 'small_snake': 'small_Snake', - 'capital_snake': 'Capital_Snake', - 'sca_eth_flow_points': 'SCA_ETH_Flow_Points', - 'att_name': 'ATT_NAME' + 'small_camel': 'smallCamel', # noqa: E501 + 'capital_camel': 'CapitalCamel', # noqa: E501 + 'small_snake': 'small_Snake', # noqa: E501 + 'capital_snake': 'Capital_Snake', # noqa: E501 + 'sca_eth_flow_points': 'SCA_ETH_Flow_Points', # noqa: E501 + 'att_name': 'ATT_NAME' # noqa: E501 } - def __init__(self, small_camel=None, capital_camel=None, small_snake=None, capital_snake=None, sca_eth_flow_points=None, att_name=None): # noqa: E501 - """Capitalization - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Capitalization - 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 False + _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 + _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. + small_camel (str): [optional] # noqa: E501 + capital_camel (str): [optional] # noqa: E501 + small_snake (str): [optional] # noqa: E501 + capital_snake (str): [optional] # noqa: E501 + sca_eth_flow_points (str): [optional] # noqa: E501 + att_name (str): Name of the pet . [optional] # noqa: E501 + """ - self._small_camel = None - self._capital_camel = None - self._small_snake = None - self._capital_snake = None - self._sca_eth_flow_points = None - self._att_name = None + self._data_store = {} self.discriminator = None - - if small_camel is not None: - self.small_camel = small_camel - if capital_camel is not None: - self.capital_camel = capital_camel - if small_snake is not None: - self.small_snake = small_snake - if capital_snake is not None: - self.capital_snake = capital_snake - if sca_eth_flow_points is not None: - self.sca_eth_flow_points = sca_eth_flow_points - if att_name is not None: - self.att_name = att_name + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def small_camel(self): """Gets the small_camel of this Capitalization. # noqa: E501 - :return: The small_camel of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The small_camel of this Capitalization. # noqa: E501 """ - return self._small_camel + return self._data_store.get('small_camel') @small_camel.setter - def small_camel(self, small_camel): + def small_camel( + self, small_camel): """Sets the small_camel of this Capitalization. - :param small_camel: The small_camel of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The small_camel of this Capitalization. # noqa: E501 """ - self._small_camel = small_camel + self.__setitem__( + 'small_camel', + small_camel + ) @property def capital_camel(self): """Gets the capital_camel of this Capitalization. # noqa: E501 - :return: The capital_camel of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The capital_camel of this Capitalization. # noqa: E501 """ - return self._capital_camel + return self._data_store.get('capital_camel') @capital_camel.setter - def capital_camel(self, capital_camel): + def capital_camel( + self, capital_camel): """Sets the capital_camel of this Capitalization. - :param capital_camel: The capital_camel of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The capital_camel of this Capitalization. # noqa: E501 """ - self._capital_camel = capital_camel + self.__setitem__( + 'capital_camel', + capital_camel + ) @property def small_snake(self): """Gets the small_snake of this Capitalization. # noqa: E501 - :return: The small_snake of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The small_snake of this Capitalization. # noqa: E501 """ - return self._small_snake + return self._data_store.get('small_snake') @small_snake.setter - def small_snake(self, small_snake): + def small_snake( + self, small_snake): """Sets the small_snake of this Capitalization. - :param small_snake: The small_snake of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The small_snake of this Capitalization. # noqa: E501 """ - self._small_snake = small_snake + self.__setitem__( + 'small_snake', + small_snake + ) @property def capital_snake(self): """Gets the capital_snake of this Capitalization. # noqa: E501 - :return: The capital_snake of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The capital_snake of this Capitalization. # noqa: E501 """ - return self._capital_snake + return self._data_store.get('capital_snake') @capital_snake.setter - def capital_snake(self, capital_snake): + def capital_snake( + self, capital_snake): """Sets the capital_snake of this Capitalization. - :param capital_snake: The capital_snake of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The capital_snake of this Capitalization. # noqa: E501 """ - self._capital_snake = capital_snake + self.__setitem__( + 'capital_snake', + capital_snake + ) @property def sca_eth_flow_points(self): """Gets the sca_eth_flow_points of this Capitalization. # noqa: E501 - :return: The sca_eth_flow_points of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The sca_eth_flow_points of this Capitalization. # noqa: E501 """ - return self._sca_eth_flow_points + return self._data_store.get('sca_eth_flow_points') @sca_eth_flow_points.setter - def sca_eth_flow_points(self, sca_eth_flow_points): + def sca_eth_flow_points( + self, sca_eth_flow_points): """Sets the sca_eth_flow_points of this Capitalization. - :param sca_eth_flow_points: The sca_eth_flow_points of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The sca_eth_flow_points of this Capitalization. # noqa: E501 """ - self._sca_eth_flow_points = sca_eth_flow_points + self.__setitem__( + 'sca_eth_flow_points', + sca_eth_flow_points + ) @property def att_name(self): @@ -183,46 +293,30 @@ def att_name(self): Name of the pet # noqa: E501 - :return: The att_name of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The att_name of this Capitalization. # noqa: E501 """ - return self._att_name + return self._data_store.get('att_name') @att_name.setter - def att_name(self, att_name): + def att_name( + self, att_name): """Sets the att_name of this Capitalization. Name of the pet # noqa: E501 - :param att_name: The att_name of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The att_name of this Capitalization. # noqa: E501 """ - self._att_name = att_name + self.__setitem__( + 'att_name', + att_name + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/cat.py b/samples/client/petstore/python-tornado/petstore_api/models/cat.py index c5c87a6b1118..49bec13ed39e 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/cat.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/cat.py @@ -15,8 +15,27 @@ import six +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) -class Cat(object): + +class Cat(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,195 @@ class Cat(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'declawed': 'bool' + 'class_name': [str], # noqa: E501 + 'color': [str], # noqa: E501 + 'declawed': [bool] # noqa: E501 } - attribute_map = { - 'declawed': 'declawed' + 'class_name': 'className', # noqa: E501 + 'color': 'color', # noqa: E501 + 'declawed': 'declawed' # noqa: E501 } - def __init__(self, declawed=None): # noqa: E501 - """Cat - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, class_name, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Cat - a model defined in OpenAPI + + Args: + class_name (str): + + 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 False + _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 + _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. + declawed (bool): [optional] # noqa: E501 + color (str): [optional] if omitted the server will use the default value of 'red' # noqa: E501 + """ - self._declawed = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + # assign using .var_name to check against nullable and enums + self.class_name = class_name + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def class_name(self): + """Gets the class_name of this Cat. # noqa: E501 + + + Returns: + (str): The class_name of this Cat. # noqa: E501 + """ + return self._data_store.get('class_name') + + @class_name.setter + def class_name( + self, class_name): + """Sets the class_name of this Cat. + + + Returns: + (str): The class_name of this Cat. # noqa: E501 + """ + if class_name is None: + raise ApiValueError("Invalid value for `class_name`, must not be `None`") # noqa: E501 - if declawed is not None: - self.declawed = declawed + self.__setitem__( + 'class_name', + class_name + ) + + @property + def color(self): + """Gets the color of this Cat. # noqa: E501 + + + Returns: + (str): The color of this Cat. # noqa: E501 + """ + return self._data_store.get('color') + + @color.setter + def color( + self, color): + """Sets the color of this Cat. + + + Returns: + (str): The color of this Cat. # noqa: E501 + """ + + self.__setitem__( + 'color', + color + ) @property def declawed(self): """Gets the declawed of this Cat. # noqa: E501 - :return: The declawed of this Cat. # noqa: E501 - :rtype: bool + Returns: + (bool): The declawed of this Cat. # noqa: E501 """ - return self._declawed + return self._data_store.get('declawed') @declawed.setter - def declawed(self, declawed): + def declawed( + self, declawed): """Sets the declawed of this Cat. - :param declawed: The declawed of this Cat. # noqa: E501 - :type: bool + Returns: + (bool): The declawed of this Cat. # noqa: E501 """ - self._declawed = declawed + self.__setitem__( + 'declawed', + declawed + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/category.py b/samples/client/petstore/python-tornado/petstore_api/models/category.py index 5b2f79eaec8d..28b9f6ada0fa 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/category.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/category.py @@ -15,8 +15,27 @@ import six - -class Category(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Category(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,97 +46,167 @@ class Category(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'id': 'int', - 'name': 'str' + 'id': [int], # noqa: E501 + 'name': [str] # noqa: E501 } - attribute_map = { - 'id': 'id', - 'name': 'name' + 'id': 'id', # noqa: E501 + 'name': 'name' # noqa: E501 } - def __init__(self, id=None, name='default-name'): # noqa: E501 - """Category - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, name='default-name', _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Category - a model defined in OpenAPI + + Args: + name (str): defaults to 'default-name', must be one of ['default-name'] # noqa: E501 + + 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 False + _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 + _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. + id (int): [optional] # noqa: E501 + """ - self._id = None - self._name = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration - if id is not None: - self.id = id + # assign using .var_name to check against nullable and enums self.name = name + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def id(self): """Gets the id of this Category. # noqa: E501 - :return: The id of this Category. # noqa: E501 - :rtype: int + Returns: + (int): The id of this Category. # noqa: E501 """ - return self._id + return self._data_store.get('id') @id.setter - def id(self, id): + def id( + self, id): """Sets the id of this Category. - :param id: The id of this Category. # noqa: E501 - :type: int + Returns: + (int): The id of this Category. # noqa: E501 """ - self._id = id + self.__setitem__( + 'id', + id + ) @property def name(self): """Gets the name of this Category. # noqa: E501 - :return: The name of this Category. # noqa: E501 - :rtype: str + Returns: + (str): The name of this Category. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this Category. - :param name: The name of this Category. # noqa: E501 - :type: str + Returns: + (str): The name of this Category. # noqa: E501 """ if name is None: - raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `name`, must not be `None`") # noqa: E501 - self._name = name + self.__setitem__( + 'name', + name + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/class_model.py b/samples/client/petstore/python-tornado/petstore_api/models/class_model.py index e207ba41ec92..d665edf7efd5 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/class_model.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/class_model.py @@ -15,8 +15,27 @@ import six - -class ClassModel(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ClassModel(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class ClassModel(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - '_class': 'str' + '_class': [str] # noqa: E501 } - attribute_map = { - '_class': '_class' + '_class': '_class' # noqa: E501 } - def __init__(self, _class=None): # noqa: E501 - """ClassModel - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ClassModel - a model defined in OpenAPI - self.__class = None - self.discriminator = None - if _class is not None: - self._class = _class + + 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 False + _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 + _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. + _class (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def _class(self): """Gets the _class of this ClassModel. # noqa: E501 - :return: The _class of this ClassModel. # noqa: E501 - :rtype: str + Returns: + (str): The _class of this ClassModel. # noqa: E501 """ - return self.__class + return self._data_store.get('_class') @_class.setter - def _class(self, _class): + def _class( + self, _class): """Sets the _class of this ClassModel. - :param _class: The _class of this ClassModel. # noqa: E501 - :type: str + Returns: + (str): The _class of this ClassModel. # noqa: E501 """ - self.__class = _class + self.__setitem__( + '_class', + _class + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/client.py b/samples/client/petstore/python-tornado/petstore_api/models/client.py index e742468e7763..ea315bc1cadd 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/client.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/client.py @@ -15,8 +15,27 @@ import six - -class Client(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Client(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class Client(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'client': 'str' + 'client': [str] # noqa: E501 } - attribute_map = { - 'client': 'client' + 'client': 'client' # noqa: E501 } - def __init__(self, client=None): # noqa: E501 - """Client - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Client - a model defined in OpenAPI - self._client = None - self.discriminator = None - if client is not None: - self.client = client + + 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 False + _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 + _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. + client (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def client(self): """Gets the client of this Client. # noqa: E501 - :return: The client of this Client. # noqa: E501 - :rtype: str + Returns: + (str): The client of this Client. # noqa: E501 """ - return self._client + return self._data_store.get('client') @client.setter - def client(self, client): + def client( + self, client): """Sets the client of this Client. - :param client: The client of this Client. # noqa: E501 - :type: str + Returns: + (str): The client of this Client. # noqa: E501 """ - self._client = client + self.__setitem__( + 'client', + client + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/dog.py b/samples/client/petstore/python-tornado/petstore_api/models/dog.py index c2bc8f745d15..0febcbab94ec 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/dog.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/dog.py @@ -15,8 +15,27 @@ import six +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) -class Dog(object): + +class Dog(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,195 @@ class Dog(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'breed': 'str' + 'class_name': [str], # noqa: E501 + 'color': [str], # noqa: E501 + 'breed': [str] # noqa: E501 } - attribute_map = { - 'breed': 'breed' + 'class_name': 'className', # noqa: E501 + 'color': 'color', # noqa: E501 + 'breed': 'breed' # noqa: E501 } - def __init__(self, breed=None): # noqa: E501 - """Dog - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, class_name, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Dog - a model defined in OpenAPI + + Args: + class_name (str): + + 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 False + _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 + _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. + breed (str): [optional] # noqa: E501 + color (str): [optional] if omitted the server will use the default value of 'red' # noqa: E501 + """ - self._breed = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + # assign using .var_name to check against nullable and enums + self.class_name = class_name + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def class_name(self): + """Gets the class_name of this Dog. # noqa: E501 + + + Returns: + (str): The class_name of this Dog. # noqa: E501 + """ + return self._data_store.get('class_name') + + @class_name.setter + def class_name( + self, class_name): + """Sets the class_name of this Dog. + + + Returns: + (str): The class_name of this Dog. # noqa: E501 + """ + if class_name is None: + raise ApiValueError("Invalid value for `class_name`, must not be `None`") # noqa: E501 - if breed is not None: - self.breed = breed + self.__setitem__( + 'class_name', + class_name + ) + + @property + def color(self): + """Gets the color of this Dog. # noqa: E501 + + + Returns: + (str): The color of this Dog. # noqa: E501 + """ + return self._data_store.get('color') + + @color.setter + def color( + self, color): + """Sets the color of this Dog. + + + Returns: + (str): The color of this Dog. # noqa: E501 + """ + + self.__setitem__( + 'color', + color + ) @property def breed(self): """Gets the breed of this Dog. # noqa: E501 - :return: The breed of this Dog. # noqa: E501 - :rtype: str + Returns: + (str): The breed of this Dog. # noqa: E501 """ - return self._breed + return self._data_store.get('breed') @breed.setter - def breed(self, breed): + def breed( + self, breed): """Sets the breed of this Dog. - :param breed: The breed of this Dog. # noqa: E501 - :type: str + Returns: + (str): The breed of this Dog. # noqa: E501 """ - self._breed = breed + self.__setitem__( + 'breed', + breed + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/enum_arrays.py b/samples/client/petstore/python-tornado/petstore_api/models/enum_arrays.py index df4363c356c3..88e4f0a20751 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/enum_arrays.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/enum_arrays.py @@ -15,8 +15,27 @@ import six - -class EnumArrays(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class EnumArrays(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,109 +46,176 @@ class EnumArrays(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'just_symbol': 'str', - 'array_enum': 'list[str]' + 'just_symbol': [str], # noqa: E501 + 'array_enum': [[(str,)]] # noqa: E501 } - attribute_map = { - 'just_symbol': 'just_symbol', - 'array_enum': 'array_enum' + 'just_symbol': 'just_symbol', # noqa: E501 + 'array_enum': 'array_enum' # noqa: E501 } - def __init__(self, just_symbol=None, array_enum=None): # noqa: E501 - """EnumArrays - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """EnumArrays - 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 False + _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 + _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. + just_symbol (str): [optional] # noqa: E501 + array_enum ([(str,)]): [optional] # noqa: E501 + """ - self._just_symbol = None - self._array_enum = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) - if just_symbol is not None: - self.just_symbol = just_symbol - if array_enum is not None: - self.array_enum = array_enum + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def just_symbol(self): """Gets the just_symbol of this EnumArrays. # noqa: E501 - :return: The just_symbol of this EnumArrays. # noqa: E501 - :rtype: str + Returns: + (str): The just_symbol of this EnumArrays. # noqa: E501 """ - return self._just_symbol + return self._data_store.get('just_symbol') @just_symbol.setter - def just_symbol(self, just_symbol): + def just_symbol( + self, just_symbol): """Sets the just_symbol of this EnumArrays. - :param just_symbol: The just_symbol of this EnumArrays. # noqa: E501 - :type: str + Returns: + (str): The just_symbol of this EnumArrays. # noqa: E501 """ allowed_values = [">=", "$"] # noqa: E501 if just_symbol not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `just_symbol` ({0}), must be one of {1}" # noqa: E501 .format(just_symbol, allowed_values) ) - self._just_symbol = just_symbol + self.__setitem__( + 'just_symbol', + just_symbol + ) @property def array_enum(self): """Gets the array_enum of this EnumArrays. # noqa: E501 - :return: The array_enum of this EnumArrays. # noqa: E501 - :rtype: list[str] + Returns: + ([(str,)]): The array_enum of this EnumArrays. # noqa: E501 """ - return self._array_enum + return self._data_store.get('array_enum') @array_enum.setter - def array_enum(self, array_enum): + def array_enum( + self, array_enum): """Sets the array_enum of this EnumArrays. - :param array_enum: The array_enum of this EnumArrays. # noqa: E501 - :type: list[str] + Returns: + ([(str,)]): The array_enum of this EnumArrays. # noqa: E501 """ allowed_values = ["fish", "crab"] # noqa: E501 if not set(array_enum).issubset(set(allowed_values)): - raise ValueError( + raise ApiValueError( "Invalid values for `array_enum` [{0}], must be a subset of [{1}]" # noqa: E501 .format(", ".join(map(str, set(array_enum) - set(allowed_values))), # noqa: E501 ", ".join(map(str, allowed_values))) ) - self._array_enum = array_enum + self.__setitem__( + 'array_enum', + array_enum + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/enum_class.py b/samples/client/petstore/python-tornado/petstore_api/models/enum_class.py index 182197d8aa6e..67731827fc1c 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/enum_class.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/enum_class.py @@ -15,8 +15,27 @@ import six - -class EnumClass(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class EnumClass(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -34,42 +53,107 @@ class EnumClass(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { } - attribute_map = { } - def __init__(self): # noqa: E501 - """EnumClass - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """EnumClass - 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 False + _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 + _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. + """ + + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/enum_test.py b/samples/client/petstore/python-tornado/petstore_api/models/enum_test.py index 0fd60c4a351d..c229da414951 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/enum_test.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/enum_test.py @@ -15,8 +15,28 @@ import six - -class EnumTest(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.outer_enum import OuterEnum + + +class EnumTest(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,199 +47,275 @@ class EnumTest(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'enum_string': 'str', - 'enum_string_required': 'str', - 'enum_integer': 'int', - 'enum_number': 'float', - 'outer_enum': 'OuterEnum' + 'enum_string': [str], # noqa: E501 + 'enum_string_required': [str], # noqa: E501 + 'enum_integer': [int], # noqa: E501 + 'enum_number': [float], # noqa: E501 + 'outer_enum': [OuterEnum] # noqa: E501 } - attribute_map = { - 'enum_string': 'enum_string', - 'enum_string_required': 'enum_string_required', - 'enum_integer': 'enum_integer', - 'enum_number': 'enum_number', - 'outer_enum': 'outerEnum' + 'enum_string': 'enum_string', # noqa: E501 + 'enum_string_required': 'enum_string_required', # noqa: E501 + 'enum_integer': 'enum_integer', # noqa: E501 + 'enum_number': 'enum_number', # noqa: E501 + 'outer_enum': 'outerEnum' # noqa: E501 } - def __init__(self, enum_string=None, enum_string_required=None, enum_integer=None, enum_number=None, outer_enum=None): # noqa: E501 - """EnumTest - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, enum_string_required, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """EnumTest - a model defined in OpenAPI + + Args: + enum_string_required (str): + + 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 False + _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 + _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. + enum_string (str): [optional] # noqa: E501 + enum_integer (int): [optional] # noqa: E501 + enum_number (float): [optional] # noqa: E501 + outer_enum (OuterEnum): [optional] # noqa: E501 + """ - self._enum_string = None - self._enum_string_required = None - self._enum_integer = None - self._enum_number = None - self._outer_enum = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration - if enum_string is not None: - self.enum_string = enum_string + # assign using .var_name to check against nullable and enums self.enum_string_required = enum_string_required - if enum_integer is not None: - self.enum_integer = enum_integer - if enum_number is not None: - self.enum_number = enum_number - if outer_enum is not None: - self.outer_enum = outer_enum + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def enum_string(self): """Gets the enum_string of this EnumTest. # noqa: E501 - :return: The enum_string of this EnumTest. # noqa: E501 - :rtype: str + Returns: + (str): The enum_string of this EnumTest. # noqa: E501 """ - return self._enum_string + return self._data_store.get('enum_string') @enum_string.setter - def enum_string(self, enum_string): + def enum_string( + self, enum_string): """Sets the enum_string of this EnumTest. - :param enum_string: The enum_string of this EnumTest. # noqa: E501 - :type: str + Returns: + (str): The enum_string of this EnumTest. # noqa: E501 """ allowed_values = ["UPPER", "lower", ""] # noqa: E501 if enum_string not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `enum_string` ({0}), must be one of {1}" # noqa: E501 .format(enum_string, allowed_values) ) - self._enum_string = enum_string + self.__setitem__( + 'enum_string', + enum_string + ) @property def enum_string_required(self): """Gets the enum_string_required of this EnumTest. # noqa: E501 - :return: The enum_string_required of this EnumTest. # noqa: E501 - :rtype: str + Returns: + (str): The enum_string_required of this EnumTest. # noqa: E501 """ - return self._enum_string_required + return self._data_store.get('enum_string_required') @enum_string_required.setter - def enum_string_required(self, enum_string_required): + def enum_string_required( + self, enum_string_required): """Sets the enum_string_required of this EnumTest. - :param enum_string_required: The enum_string_required of this EnumTest. # noqa: E501 - :type: str + Returns: + (str): The enum_string_required of this EnumTest. # noqa: E501 """ if enum_string_required is None: - raise ValueError("Invalid value for `enum_string_required`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `enum_string_required`, must not be `None`") # noqa: E501 allowed_values = ["UPPER", "lower", ""] # noqa: E501 if enum_string_required not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `enum_string_required` ({0}), must be one of {1}" # noqa: E501 .format(enum_string_required, allowed_values) ) - self._enum_string_required = enum_string_required + self.__setitem__( + 'enum_string_required', + enum_string_required + ) @property def enum_integer(self): """Gets the enum_integer of this EnumTest. # noqa: E501 - :return: The enum_integer of this EnumTest. # noqa: E501 - :rtype: int + Returns: + (int): The enum_integer of this EnumTest. # noqa: E501 """ - return self._enum_integer + return self._data_store.get('enum_integer') @enum_integer.setter - def enum_integer(self, enum_integer): + def enum_integer( + self, enum_integer): """Sets the enum_integer of this EnumTest. - :param enum_integer: The enum_integer of this EnumTest. # noqa: E501 - :type: int + Returns: + (int): The enum_integer of this EnumTest. # noqa: E501 """ allowed_values = [1, -1] # noqa: E501 if enum_integer not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `enum_integer` ({0}), must be one of {1}" # noqa: E501 .format(enum_integer, allowed_values) ) - self._enum_integer = enum_integer + self.__setitem__( + 'enum_integer', + enum_integer + ) @property def enum_number(self): """Gets the enum_number of this EnumTest. # noqa: E501 - :return: The enum_number of this EnumTest. # noqa: E501 - :rtype: float + Returns: + (float): The enum_number of this EnumTest. # noqa: E501 """ - return self._enum_number + return self._data_store.get('enum_number') @enum_number.setter - def enum_number(self, enum_number): + def enum_number( + self, enum_number): """Sets the enum_number of this EnumTest. - :param enum_number: The enum_number of this EnumTest. # noqa: E501 - :type: float + Returns: + (float): The enum_number of this EnumTest. # noqa: E501 """ allowed_values = [1.1, -1.2] # noqa: E501 if enum_number not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `enum_number` ({0}), must be one of {1}" # noqa: E501 .format(enum_number, allowed_values) ) - self._enum_number = enum_number + self.__setitem__( + 'enum_number', + enum_number + ) @property def outer_enum(self): """Gets the outer_enum of this EnumTest. # noqa: E501 - :return: The outer_enum of this EnumTest. # noqa: E501 - :rtype: OuterEnum + Returns: + (OuterEnum): The outer_enum of this EnumTest. # noqa: E501 """ - return self._outer_enum + return self._data_store.get('outer_enum') @outer_enum.setter - def outer_enum(self, outer_enum): + def outer_enum( + self, outer_enum): """Sets the outer_enum of this EnumTest. - :param outer_enum: The outer_enum of this EnumTest. # noqa: E501 - :type: OuterEnum + Returns: + (OuterEnum): The outer_enum of this EnumTest. # noqa: E501 """ - self._outer_enum = outer_enum + self.__setitem__( + 'outer_enum', + outer_enum + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/file.py b/samples/client/petstore/python-tornado/petstore_api/models/file.py index 34d77c3b4cf8..3fdc580d4198 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/file.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/file.py @@ -15,8 +15,27 @@ import six - -class File(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class File(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,25 +46,106 @@ class File(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'source_uri': 'str' + 'source_uri': [str] # noqa: E501 } - attribute_map = { - 'source_uri': 'sourceURI' + 'source_uri': 'sourceURI' # noqa: E501 } - def __init__(self, source_uri=None): # noqa: E501 - """File - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """File - a model defined in OpenAPI - self._source_uri = None - self.discriminator = None - if source_uri is not None: - self.source_uri = source_uri + + 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 False + _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 + _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. + source_uri (str): Test capitalization. [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def source_uri(self): @@ -53,46 +153,30 @@ def source_uri(self): Test capitalization # noqa: E501 - :return: The source_uri of this File. # noqa: E501 - :rtype: str + Returns: + (str): The source_uri of this File. # noqa: E501 """ - return self._source_uri + return self._data_store.get('source_uri') @source_uri.setter - def source_uri(self, source_uri): + def source_uri( + self, source_uri): """Sets the source_uri of this File. Test capitalization # noqa: E501 - :param source_uri: The source_uri of this File. # noqa: E501 - :type: str + Returns: + (str): The source_uri of this File. # noqa: E501 """ - self._source_uri = source_uri + self.__setitem__( + 'source_uri', + source_uri + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/file_schema_test_class.py b/samples/client/petstore/python-tornado/petstore_api/models/file_schema_test_class.py index 026822dee749..ed77661a5bfe 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/file_schema_test_class.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/file_schema_test_class.py @@ -15,8 +15,28 @@ import six - -class FileSchemaTestClass(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.file import File + + +class FileSchemaTestClass(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +47,163 @@ class FileSchemaTestClass(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'file': 'File', - 'files': 'list[File]' + 'file': [File], # noqa: E501 + 'files': [[(File,)]] # noqa: E501 } - attribute_map = { - 'file': 'file', - 'files': 'files' + 'file': 'file', # noqa: E501 + 'files': 'files' # noqa: E501 } - def __init__(self, file=None, files=None): # noqa: E501 - """FileSchemaTestClass - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """FileSchemaTestClass - 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 False + _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 + _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. + file (File): [optional] # noqa: E501 + files ([(File,)]): [optional] # noqa: E501 + """ - self._file = None - self._files = None + self._data_store = {} self.discriminator = None - - if file is not None: - self.file = file - if files is not None: - self.files = files + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def file(self): """Gets the file of this FileSchemaTestClass. # noqa: E501 - :return: The file of this FileSchemaTestClass. # noqa: E501 - :rtype: File + Returns: + (File): The file of this FileSchemaTestClass. # noqa: E501 """ - return self._file + return self._data_store.get('file') @file.setter - def file(self, file): + def file( + self, file): """Sets the file of this FileSchemaTestClass. - :param file: The file of this FileSchemaTestClass. # noqa: E501 - :type: File + Returns: + (File): The file of this FileSchemaTestClass. # noqa: E501 """ - self._file = file + self.__setitem__( + 'file', + file + ) @property def files(self): """Gets the files of this FileSchemaTestClass. # noqa: E501 - :return: The files of this FileSchemaTestClass. # noqa: E501 - :rtype: list[File] + Returns: + ([(File,)]): The files of this FileSchemaTestClass. # noqa: E501 """ - return self._files + return self._data_store.get('files') @files.setter - def files(self, files): + def files( + self, files): """Sets the files of this FileSchemaTestClass. - :param files: The files of this FileSchemaTestClass. # noqa: E501 - :type: list[File] + Returns: + ([(File,)]): The files of this FileSchemaTestClass. # noqa: E501 """ - self._files = files + self.__setitem__( + 'files', + files + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/format_test.py b/samples/client/petstore/python-tornado/petstore_api/models/format_test.py index c7703d166071..e7edaf2d3df6 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/format_test.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/format_test.py @@ -15,8 +15,27 @@ import six - -class FormatTest(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class FormatTest(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,414 +46,512 @@ class FormatTest(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'integer': 'int', - 'int32': 'int', - 'int64': 'int', - 'number': 'float', - 'float': 'float', - 'double': 'float', - 'string': 'str', - 'byte': 'str', - 'binary': 'file', - 'date': 'date', - 'date_time': 'datetime', - 'uuid': 'str', - 'password': 'str' + 'integer': [int], # noqa: E501 + 'int32': [int], # noqa: E501 + 'int64': [int], # noqa: E501 + 'number': [float], # noqa: E501 + 'float': [float], # noqa: E501 + 'double': [float], # noqa: E501 + 'string': [str], # noqa: E501 + 'byte': [str], # noqa: E501 + 'binary': [file_type], # noqa: E501 + 'date': [date], # noqa: E501 + 'date_time': [datetime], # noqa: E501 + 'uuid': [str], # noqa: E501 + 'password': [str] # noqa: E501 } - attribute_map = { - 'integer': 'integer', - 'int32': 'int32', - 'int64': 'int64', - 'number': 'number', - 'float': 'float', - 'double': 'double', - 'string': 'string', - 'byte': 'byte', - 'binary': 'binary', - 'date': 'date', - 'date_time': 'dateTime', - 'uuid': 'uuid', - 'password': 'password' + 'integer': 'integer', # noqa: E501 + 'int32': 'int32', # noqa: E501 + 'int64': 'int64', # noqa: E501 + 'number': 'number', # noqa: E501 + 'float': 'float', # noqa: E501 + 'double': 'double', # noqa: E501 + 'string': 'string', # noqa: E501 + 'byte': 'byte', # noqa: E501 + 'binary': 'binary', # noqa: E501 + 'date': 'date', # noqa: E501 + 'date_time': 'dateTime', # noqa: E501 + 'uuid': 'uuid', # noqa: E501 + 'password': 'password' # noqa: E501 } - def __init__(self, integer=None, int32=None, int64=None, number=None, float=None, double=None, string=None, byte=None, binary=None, date=None, date_time=None, uuid=None, password=None): # noqa: E501 - """FormatTest - a model defined in OpenAPI""" # noqa: E501 - - self._integer = None - self._int32 = None - self._int64 = None - self._number = None - self._float = None - self._double = None - self._string = None - self._byte = None - self._binary = None - self._date = None - self._date_time = None - self._uuid = None - self._password = None + def __init__(self, number, byte, date, password, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """FormatTest - a model defined in OpenAPI + + Args: + number (float): + byte (str): + date (date): + password (str): + + 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 False + _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 + _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. + integer (int): [optional] # noqa: E501 + int32 (int): [optional] # noqa: E501 + int64 (int): [optional] # noqa: E501 + float (float): [optional] # noqa: E501 + double (float): [optional] # noqa: E501 + string (str): [optional] # noqa: E501 + binary (file_type): [optional] # noqa: E501 + date_time (datetime): [optional] # noqa: E501 + uuid (str): [optional] # noqa: E501 + """ + + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration - if integer is not None: - self.integer = integer - if int32 is not None: - self.int32 = int32 - if int64 is not None: - self.int64 = int64 + # assign using .var_name to check against nullable and enums self.number = number - if float is not None: - self.float = float - if double is not None: - self.double = double - if string is not None: - self.string = string self.byte = byte - if binary is not None: - self.binary = binary self.date = date - if date_time is not None: - self.date_time = date_time - if uuid is not None: - self.uuid = uuid self.password = password + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def integer(self): """Gets the integer of this FormatTest. # noqa: E501 - :return: The integer of this FormatTest. # noqa: E501 - :rtype: int + Returns: + (int): The integer of this FormatTest. # noqa: E501 """ - return self._integer + return self._data_store.get('integer') @integer.setter - def integer(self, integer): + def integer( + self, integer): """Sets the integer of this FormatTest. - :param integer: The integer of this FormatTest. # noqa: E501 - :type: int + Returns: + (int): The integer of this FormatTest. # noqa: E501 """ if integer is not None and integer > 100: # noqa: E501 - raise ValueError("Invalid value for `integer`, must be a value less than or equal to `100`") # noqa: E501 + raise ApiValueError("Invalid value for `integer`, must be a value less than or equal to `100`") # noqa: E501 if integer is not None and integer < 10: # noqa: E501 - raise ValueError("Invalid value for `integer`, must be a value greater than or equal to `10`") # noqa: E501 + raise ApiValueError("Invalid value for `integer`, must be a value greater than or equal to `10`") # noqa: E501 - self._integer = integer + self.__setitem__( + 'integer', + integer + ) @property def int32(self): """Gets the int32 of this FormatTest. # noqa: E501 - :return: The int32 of this FormatTest. # noqa: E501 - :rtype: int + Returns: + (int): The int32 of this FormatTest. # noqa: E501 """ - return self._int32 + return self._data_store.get('int32') @int32.setter - def int32(self, int32): + def int32( + self, int32): """Sets the int32 of this FormatTest. - :param int32: The int32 of this FormatTest. # noqa: E501 - :type: int + Returns: + (int): The int32 of this FormatTest. # noqa: E501 """ if int32 is not None and int32 > 200: # noqa: E501 - raise ValueError("Invalid value for `int32`, must be a value less than or equal to `200`") # noqa: E501 + raise ApiValueError("Invalid value for `int32`, must be a value less than or equal to `200`") # noqa: E501 if int32 is not None and int32 < 20: # noqa: E501 - raise ValueError("Invalid value for `int32`, must be a value greater than or equal to `20`") # noqa: E501 + raise ApiValueError("Invalid value for `int32`, must be a value greater than or equal to `20`") # noqa: E501 - self._int32 = int32 + self.__setitem__( + 'int32', + int32 + ) @property def int64(self): """Gets the int64 of this FormatTest. # noqa: E501 - :return: The int64 of this FormatTest. # noqa: E501 - :rtype: int + Returns: + (int): The int64 of this FormatTest. # noqa: E501 """ - return self._int64 + return self._data_store.get('int64') @int64.setter - def int64(self, int64): + def int64( + self, int64): """Sets the int64 of this FormatTest. - :param int64: The int64 of this FormatTest. # noqa: E501 - :type: int + Returns: + (int): The int64 of this FormatTest. # noqa: E501 """ - self._int64 = int64 + self.__setitem__( + 'int64', + int64 + ) @property def number(self): """Gets the number of this FormatTest. # noqa: E501 - :return: The number of this FormatTest. # noqa: E501 - :rtype: float + Returns: + (float): The number of this FormatTest. # noqa: E501 """ - return self._number + return self._data_store.get('number') @number.setter - def number(self, number): + def number( + self, number): """Sets the number of this FormatTest. - :param number: The number of this FormatTest. # noqa: E501 - :type: float + Returns: + (float): The number of this FormatTest. # noqa: E501 """ if number is None: - raise ValueError("Invalid value for `number`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `number`, must not be `None`") # noqa: E501 if number is not None and number > 543.2: # noqa: E501 - raise ValueError("Invalid value for `number`, must be a value less than or equal to `543.2`") # noqa: E501 + raise ApiValueError("Invalid value for `number`, must be a value less than or equal to `543.2`") # noqa: E501 if number is not None and number < 32.1: # noqa: E501 - raise ValueError("Invalid value for `number`, must be a value greater than or equal to `32.1`") # noqa: E501 + raise ApiValueError("Invalid value for `number`, must be a value greater than or equal to `32.1`") # noqa: E501 - self._number = number + self.__setitem__( + 'number', + number + ) @property def float(self): """Gets the float of this FormatTest. # noqa: E501 - :return: The float of this FormatTest. # noqa: E501 - :rtype: float + Returns: + (float): The float of this FormatTest. # noqa: E501 """ - return self._float + return self._data_store.get('float') @float.setter - def float(self, float): + def float( + self, float): """Sets the float of this FormatTest. - :param float: The float of this FormatTest. # noqa: E501 - :type: float + Returns: + (float): The float of this FormatTest. # noqa: E501 """ if float is not None and float > 987.6: # noqa: E501 - raise ValueError("Invalid value for `float`, must be a value less than or equal to `987.6`") # noqa: E501 + raise ApiValueError("Invalid value for `float`, must be a value less than or equal to `987.6`") # noqa: E501 if float is not None and float < 54.3: # noqa: E501 - raise ValueError("Invalid value for `float`, must be a value greater than or equal to `54.3`") # noqa: E501 + raise ApiValueError("Invalid value for `float`, must be a value greater than or equal to `54.3`") # noqa: E501 - self._float = float + self.__setitem__( + 'float', + float + ) @property def double(self): """Gets the double of this FormatTest. # noqa: E501 - :return: The double of this FormatTest. # noqa: E501 - :rtype: float + Returns: + (float): The double of this FormatTest. # noqa: E501 """ - return self._double + return self._data_store.get('double') @double.setter - def double(self, double): + def double( + self, double): """Sets the double of this FormatTest. - :param double: The double of this FormatTest. # noqa: E501 - :type: float + Returns: + (float): The double of this FormatTest. # noqa: E501 """ if double is not None and double > 123.4: # noqa: E501 - raise ValueError("Invalid value for `double`, must be a value less than or equal to `123.4`") # noqa: E501 + raise ApiValueError("Invalid value for `double`, must be a value less than or equal to `123.4`") # noqa: E501 if double is not None and double < 67.8: # noqa: E501 - raise ValueError("Invalid value for `double`, must be a value greater than or equal to `67.8`") # noqa: E501 + raise ApiValueError("Invalid value for `double`, must be a value greater than or equal to `67.8`") # noqa: E501 - self._double = double + self.__setitem__( + 'double', + double + ) @property def string(self): """Gets the string of this FormatTest. # noqa: E501 - :return: The string of this FormatTest. # noqa: E501 - :rtype: str + Returns: + (str): The string of this FormatTest. # noqa: E501 """ - return self._string + return self._data_store.get('string') @string.setter - def string(self, string): + def string( + self, string): """Sets the string of this FormatTest. - :param string: The string of this FormatTest. # noqa: E501 - :type: str + Returns: + (str): The string of this FormatTest. # noqa: E501 """ - if string is not None and not re.search(r'[a-z]', string, flags=re.IGNORECASE): # noqa: E501 - raise ValueError(r"Invalid value for `string`, must be a follow pattern or equal to `/[a-z]/i`") # noqa: E501 + if string is not None and not re.search(r'', string): # noqa: E501 + raise ApiValueError(r"Invalid value for `string`, must be a follow pattern or equal to `/[a-z]/i`") # noqa: E501 - self._string = string + self.__setitem__( + 'string', + string + ) @property def byte(self): """Gets the byte of this FormatTest. # noqa: E501 - :return: The byte of this FormatTest. # noqa: E501 - :rtype: str + Returns: + (str): The byte of this FormatTest. # noqa: E501 """ - return self._byte + return self._data_store.get('byte') @byte.setter - def byte(self, byte): + def byte( + self, byte): """Sets the byte of this FormatTest. - :param byte: The byte of this FormatTest. # noqa: E501 - :type: str + Returns: + (str): The byte of this FormatTest. # noqa: E501 """ if byte is None: - raise ValueError("Invalid value for `byte`, must not be `None`") # noqa: E501 - if byte is not None and not re.search(r'^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$', byte): # noqa: E501 - raise ValueError(r"Invalid value for `byte`, must be a follow pattern or equal to `/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/`") # noqa: E501 + raise ApiValueError("Invalid value for `byte`, must not be `None`") # noqa: E501 + if byte is not None and not re.search(r'', byte): # noqa: E501 + raise ApiValueError(r"Invalid value for `byte`, must be a follow pattern or equal to `/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/`") # noqa: E501 - self._byte = byte + self.__setitem__( + 'byte', + byte + ) @property def binary(self): """Gets the binary of this FormatTest. # noqa: E501 - :return: The binary of this FormatTest. # noqa: E501 - :rtype: file + Returns: + (file_type): The binary of this FormatTest. # noqa: E501 """ - return self._binary + return self._data_store.get('binary') @binary.setter - def binary(self, binary): + def binary( + self, binary): """Sets the binary of this FormatTest. - :param binary: The binary of this FormatTest. # noqa: E501 - :type: file + Returns: + (file_type): The binary of this FormatTest. # noqa: E501 """ - self._binary = binary + self.__setitem__( + 'binary', + binary + ) @property def date(self): """Gets the date of this FormatTest. # noqa: E501 - :return: The date of this FormatTest. # noqa: E501 - :rtype: date + Returns: + (date): The date of this FormatTest. # noqa: E501 """ - return self._date + return self._data_store.get('date') @date.setter - def date(self, date): + def date( + self, date): """Sets the date of this FormatTest. - :param date: The date of this FormatTest. # noqa: E501 - :type: date + Returns: + (date): The date of this FormatTest. # noqa: E501 """ if date is None: - raise ValueError("Invalid value for `date`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `date`, must not be `None`") # noqa: E501 - self._date = date + self.__setitem__( + 'date', + date + ) @property def date_time(self): """Gets the date_time of this FormatTest. # noqa: E501 - :return: The date_time of this FormatTest. # noqa: E501 - :rtype: datetime + Returns: + (datetime): The date_time of this FormatTest. # noqa: E501 """ - return self._date_time + return self._data_store.get('date_time') @date_time.setter - def date_time(self, date_time): + def date_time( + self, date_time): """Sets the date_time of this FormatTest. - :param date_time: The date_time of this FormatTest. # noqa: E501 - :type: datetime + Returns: + (datetime): The date_time of this FormatTest. # noqa: E501 """ - self._date_time = date_time + self.__setitem__( + 'date_time', + date_time + ) @property def uuid(self): """Gets the uuid of this FormatTest. # noqa: E501 - :return: The uuid of this FormatTest. # noqa: E501 - :rtype: str + Returns: + (str): The uuid of this FormatTest. # noqa: E501 """ - return self._uuid + return self._data_store.get('uuid') @uuid.setter - def uuid(self, uuid): + def uuid( + self, uuid): """Sets the uuid of this FormatTest. - :param uuid: The uuid of this FormatTest. # noqa: E501 - :type: str + Returns: + (str): The uuid of this FormatTest. # noqa: E501 """ - self._uuid = uuid + self.__setitem__( + 'uuid', + uuid + ) @property def password(self): """Gets the password of this FormatTest. # noqa: E501 - :return: The password of this FormatTest. # noqa: E501 - :rtype: str + Returns: + (str): The password of this FormatTest. # noqa: E501 """ - return self._password + return self._data_store.get('password') @password.setter - def password(self, password): + def password( + self, password): """Sets the password of this FormatTest. - :param password: The password of this FormatTest. # noqa: E501 - :type: str + Returns: + (str): The password of this FormatTest. # noqa: E501 """ if password is None: - raise ValueError("Invalid value for `password`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `password`, must not be `None`") # noqa: E501 if password is not None and len(password) > 64: - raise ValueError("Invalid value for `password`, length must be less than or equal to `64`") # noqa: E501 + raise ApiValueError("Invalid value for `password`, length must be less than or equal to `64`") # noqa: E501 if password is not None and len(password) < 10: - raise ValueError("Invalid value for `password`, length must be greater than or equal to `10`") # noqa: E501 + raise ApiValueError("Invalid value for `password`, length must be greater than or equal to `10`") # noqa: E501 - self._password = password + self.__setitem__( + 'password', + password + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/has_only_read_only.py b/samples/client/petstore/python-tornado/petstore_api/models/has_only_read_only.py index 41db3ff71958..eeff7da1fbaf 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/has_only_read_only.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/has_only_read_only.py @@ -15,8 +15,27 @@ import six - -class HasOnlyReadOnly(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class HasOnlyReadOnly(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +46,163 @@ class HasOnlyReadOnly(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'bar': 'str', - 'foo': 'str' + 'bar': [str], # noqa: E501 + 'foo': [str] # noqa: E501 } - attribute_map = { - 'bar': 'bar', - 'foo': 'foo' + 'bar': 'bar', # noqa: E501 + 'foo': 'foo' # noqa: E501 } - def __init__(self, bar=None, foo=None): # noqa: E501 - """HasOnlyReadOnly - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """HasOnlyReadOnly - 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 False + _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 + _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. + bar (str): [optional] # noqa: E501 + foo (str): [optional] # noqa: E501 + """ - self._bar = None - self._foo = None + self._data_store = {} self.discriminator = None - - if bar is not None: - self.bar = bar - if foo is not None: - self.foo = foo + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def bar(self): """Gets the bar of this HasOnlyReadOnly. # noqa: E501 - :return: The bar of this HasOnlyReadOnly. # noqa: E501 - :rtype: str + Returns: + (str): The bar of this HasOnlyReadOnly. # noqa: E501 """ - return self._bar + return self._data_store.get('bar') @bar.setter - def bar(self, bar): + def bar( + self, bar): """Sets the bar of this HasOnlyReadOnly. - :param bar: The bar of this HasOnlyReadOnly. # noqa: E501 - :type: str + Returns: + (str): The bar of this HasOnlyReadOnly. # noqa: E501 """ - self._bar = bar + self.__setitem__( + 'bar', + bar + ) @property def foo(self): """Gets the foo of this HasOnlyReadOnly. # noqa: E501 - :return: The foo of this HasOnlyReadOnly. # noqa: E501 - :rtype: str + Returns: + (str): The foo of this HasOnlyReadOnly. # noqa: E501 """ - return self._foo + return self._data_store.get('foo') @foo.setter - def foo(self, foo): + def foo( + self, foo): """Sets the foo of this HasOnlyReadOnly. - :param foo: The foo of this HasOnlyReadOnly. # noqa: E501 - :type: str + Returns: + (str): The foo of this HasOnlyReadOnly. # noqa: E501 """ - self._foo = foo + self.__setitem__( + 'foo', + foo + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/list.py b/samples/client/petstore/python-tornado/petstore_api/models/list.py index 08e12ad53104..71b3c3ea4033 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/list.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/list.py @@ -15,8 +15,27 @@ import six - -class List(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class List(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class List(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - '_123_list': 'str' + '_123_list': [str] # noqa: E501 } - attribute_map = { - '_123_list': '123-list' + '_123_list': '123-list' # noqa: E501 } - def __init__(self, _123_list=None): # noqa: E501 - """List - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """List - a model defined in OpenAPI - self.__123_list = None - self.discriminator = None - if _123_list is not None: - self._123_list = _123_list + + 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 False + _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 + _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. + _123_list (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def _123_list(self): """Gets the _123_list of this List. # noqa: E501 - :return: The _123_list of this List. # noqa: E501 - :rtype: str + Returns: + (str): The _123_list of this List. # noqa: E501 """ - return self.__123_list + return self._data_store.get('_123_list') @_123_list.setter - def _123_list(self, _123_list): + def _123_list( + self, _123_list): """Sets the _123_list of this List. - :param _123_list: The _123_list of this List. # noqa: E501 - :type: str + Returns: + (str): The _123_list of this List. # noqa: E501 """ - self.__123_list = _123_list + self.__setitem__( + '_123_list', + _123_list + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/map_test.py b/samples/client/petstore/python-tornado/petstore_api/models/map_test.py index f04bd2cc1421..c846484fb60f 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/map_test.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/map_test.py @@ -15,8 +15,27 @@ import six - -class MapTest(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class MapTest(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,155 +46,226 @@ class MapTest(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'map_map_of_string': 'dict(str, dict(str, str))', - 'map_of_enum_string': 'dict(str, str)', - 'direct_map': 'dict(str, bool)', - 'indirect_map': 'dict(str, bool)' + 'map_map_of_string': [{str: ({str: (str,)},)}], # noqa: E501 + 'map_of_enum_string': [{str: (str,)}], # noqa: E501 + 'direct_map': [{str: (bool,)}], # noqa: E501 + 'indirect_map': [{str: (bool,)}] # noqa: E501 } - attribute_map = { - 'map_map_of_string': 'map_map_of_string', - 'map_of_enum_string': 'map_of_enum_string', - 'direct_map': 'direct_map', - 'indirect_map': 'indirect_map' + 'map_map_of_string': 'map_map_of_string', # noqa: E501 + 'map_of_enum_string': 'map_of_enum_string', # noqa: E501 + 'direct_map': 'direct_map', # noqa: E501 + 'indirect_map': 'indirect_map' # noqa: E501 } - def __init__(self, map_map_of_string=None, map_of_enum_string=None, direct_map=None, indirect_map=None): # noqa: E501 - """MapTest - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """MapTest - 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 False + _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 + _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. + map_map_of_string ({str: ({str: (str,)},)}): [optional] # noqa: E501 + map_of_enum_string ({str: (str,)}): [optional] # noqa: E501 + direct_map ({str: (bool,)}): [optional] # noqa: E501 + indirect_map ({str: (bool,)}): [optional] # noqa: E501 + """ - self._map_map_of_string = None - self._map_of_enum_string = None - self._direct_map = None - self._indirect_map = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) - if map_map_of_string is not None: - self.map_map_of_string = map_map_of_string - if map_of_enum_string is not None: - self.map_of_enum_string = map_of_enum_string - if direct_map is not None: - self.direct_map = direct_map - if indirect_map is not None: - self.indirect_map = indirect_map + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def map_map_of_string(self): """Gets the map_map_of_string of this MapTest. # noqa: E501 - :return: The map_map_of_string of this MapTest. # noqa: E501 - :rtype: dict(str, dict(str, str)) + Returns: + ({str: ({str: (str,)},)}): The map_map_of_string of this MapTest. # noqa: E501 """ - return self._map_map_of_string + return self._data_store.get('map_map_of_string') @map_map_of_string.setter - def map_map_of_string(self, map_map_of_string): + def map_map_of_string( + self, map_map_of_string): """Sets the map_map_of_string of this MapTest. - :param map_map_of_string: The map_map_of_string of this MapTest. # noqa: E501 - :type: dict(str, dict(str, str)) + Returns: + ({str: ({str: (str,)},)}): The map_map_of_string of this MapTest. # noqa: E501 """ - self._map_map_of_string = map_map_of_string + self.__setitem__( + 'map_map_of_string', + map_map_of_string + ) @property def map_of_enum_string(self): """Gets the map_of_enum_string of this MapTest. # noqa: E501 - :return: The map_of_enum_string of this MapTest. # noqa: E501 - :rtype: dict(str, str) + Returns: + ({str: (str,)}): The map_of_enum_string of this MapTest. # noqa: E501 """ - return self._map_of_enum_string + return self._data_store.get('map_of_enum_string') @map_of_enum_string.setter - def map_of_enum_string(self, map_of_enum_string): + def map_of_enum_string( + self, map_of_enum_string): """Sets the map_of_enum_string of this MapTest. - :param map_of_enum_string: The map_of_enum_string of this MapTest. # noqa: E501 - :type: dict(str, str) + Returns: + ({str: (str,)}): The map_of_enum_string of this MapTest. # noqa: E501 """ allowed_values = ["UPPER", "lower"] # noqa: E501 if not set(map_of_enum_string.keys()).issubset(set(allowed_values)): - raise ValueError( + raise ApiValueError( "Invalid keys in `map_of_enum_string` [{0}], must be a subset of [{1}]" # noqa: E501 .format(", ".join(map(str, set(map_of_enum_string.keys()) - set(allowed_values))), # noqa: E501 ", ".join(map(str, allowed_values))) ) - self._map_of_enum_string = map_of_enum_string + self.__setitem__( + 'map_of_enum_string', + map_of_enum_string + ) @property def direct_map(self): """Gets the direct_map of this MapTest. # noqa: E501 - :return: The direct_map of this MapTest. # noqa: E501 - :rtype: dict(str, bool) + Returns: + ({str: (bool,)}): The direct_map of this MapTest. # noqa: E501 """ - return self._direct_map + return self._data_store.get('direct_map') @direct_map.setter - def direct_map(self, direct_map): + def direct_map( + self, direct_map): """Sets the direct_map of this MapTest. - :param direct_map: The direct_map of this MapTest. # noqa: E501 - :type: dict(str, bool) + Returns: + ({str: (bool,)}): The direct_map of this MapTest. # noqa: E501 """ - self._direct_map = direct_map + self.__setitem__( + 'direct_map', + direct_map + ) @property def indirect_map(self): """Gets the indirect_map of this MapTest. # noqa: E501 - :return: The indirect_map of this MapTest. # noqa: E501 - :rtype: dict(str, bool) + Returns: + ({str: (bool,)}): The indirect_map of this MapTest. # noqa: E501 """ - return self._indirect_map + return self._data_store.get('indirect_map') @indirect_map.setter - def indirect_map(self, indirect_map): + def indirect_map( + self, indirect_map): """Sets the indirect_map of this MapTest. - :param indirect_map: The indirect_map of this MapTest. # noqa: E501 - :type: dict(str, bool) + Returns: + ({str: (bool,)}): The indirect_map of this MapTest. # noqa: E501 """ - self._indirect_map = indirect_map + self.__setitem__( + 'indirect_map', + indirect_map + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/mixed_properties_and_additional_properties_class.py b/samples/client/petstore/python-tornado/petstore_api/models/mixed_properties_and_additional_properties_class.py index ecf67acc5e95..1d61e2c659ff 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/mixed_properties_and_additional_properties_class.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/mixed_properties_and_additional_properties_class.py @@ -15,8 +15,28 @@ import six - -class MixedPropertiesAndAdditionalPropertiesClass(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.animal import Animal + + +class MixedPropertiesAndAdditionalPropertiesClass(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,122 +47,191 @@ class MixedPropertiesAndAdditionalPropertiesClass(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'uuid': 'str', - 'date_time': 'datetime', - 'map': 'dict(str, Animal)' + 'uuid': [str], # noqa: E501 + 'date_time': [datetime], # noqa: E501 + 'map': [{str: (Animal,)}] # noqa: E501 } - attribute_map = { - 'uuid': 'uuid', - 'date_time': 'dateTime', - 'map': 'map' + 'uuid': 'uuid', # noqa: E501 + 'date_time': 'dateTime', # noqa: E501 + 'map': 'map' # noqa: E501 } - def __init__(self, uuid=None, date_time=None, map=None): # noqa: E501 - """MixedPropertiesAndAdditionalPropertiesClass - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """MixedPropertiesAndAdditionalPropertiesClass - 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 False + _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 + _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. + uuid (str): [optional] # noqa: E501 + date_time (datetime): [optional] # noqa: E501 + map ({str: (Animal,)}): [optional] # noqa: E501 + """ - self._uuid = None - self._date_time = None - self._map = None + self._data_store = {} self.discriminator = None - - if uuid is not None: - self.uuid = uuid - if date_time is not None: - self.date_time = date_time - if map is not None: - self.map = map + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def uuid(self): """Gets the uuid of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :return: The uuid of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :rtype: str + Returns: + (str): The uuid of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - return self._uuid + return self._data_store.get('uuid') @uuid.setter - def uuid(self, uuid): + def uuid( + self, uuid): """Sets the uuid of this MixedPropertiesAndAdditionalPropertiesClass. - :param uuid: The uuid of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :type: str + Returns: + (str): The uuid of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - self._uuid = uuid + self.__setitem__( + 'uuid', + uuid + ) @property def date_time(self): """Gets the date_time of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :return: The date_time of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :rtype: datetime + Returns: + (datetime): The date_time of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - return self._date_time + return self._data_store.get('date_time') @date_time.setter - def date_time(self, date_time): + def date_time( + self, date_time): """Sets the date_time of this MixedPropertiesAndAdditionalPropertiesClass. - :param date_time: The date_time of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :type: datetime + Returns: + (datetime): The date_time of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - self._date_time = date_time + self.__setitem__( + 'date_time', + date_time + ) @property def map(self): """Gets the map of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :return: The map of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :rtype: dict(str, Animal) + Returns: + ({str: (Animal,)}): The map of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - return self._map + return self._data_store.get('map') @map.setter - def map(self, map): + def map( + self, map): """Sets the map of this MixedPropertiesAndAdditionalPropertiesClass. - :param map: The map of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :type: dict(str, Animal) + Returns: + ({str: (Animal,)}): The map of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - self._map = map + self.__setitem__( + 'map', + map + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/model200_response.py b/samples/client/petstore/python-tornado/petstore_api/models/model200_response.py index ec778cdcb74b..e44d7f28022e 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/model200_response.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/model200_response.py @@ -15,8 +15,27 @@ import six - -class Model200Response(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Model200Response(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +46,163 @@ class Model200Response(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'name': 'int', - '_class': 'str' + 'name': [int], # noqa: E501 + '_class': [str] # noqa: E501 } - attribute_map = { - 'name': 'name', - '_class': 'class' + 'name': 'name', # noqa: E501 + '_class': 'class' # noqa: E501 } - def __init__(self, name=None, _class=None): # noqa: E501 - """Model200Response - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Model200Response - 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 False + _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 + _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. + name (int): [optional] # noqa: E501 + _class (str): [optional] # noqa: E501 + """ - self._name = None - self.__class = None + self._data_store = {} self.discriminator = None - - if name is not None: - self.name = name - if _class is not None: - self._class = _class + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def name(self): """Gets the name of this Model200Response. # noqa: E501 - :return: The name of this Model200Response. # noqa: E501 - :rtype: int + Returns: + (int): The name of this Model200Response. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this Model200Response. - :param name: The name of this Model200Response. # noqa: E501 - :type: int + Returns: + (int): The name of this Model200Response. # noqa: E501 """ - self._name = name + self.__setitem__( + 'name', + name + ) @property def _class(self): """Gets the _class of this Model200Response. # noqa: E501 - :return: The _class of this Model200Response. # noqa: E501 - :rtype: str + Returns: + (str): The _class of this Model200Response. # noqa: E501 """ - return self.__class + return self._data_store.get('_class') @_class.setter - def _class(self, _class): + def _class( + self, _class): """Sets the _class of this Model200Response. - :param _class: The _class of this Model200Response. # noqa: E501 - :type: str + Returns: + (str): The _class of this Model200Response. # noqa: E501 """ - self.__class = _class + self.__setitem__( + '_class', + _class + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/model_return.py b/samples/client/petstore/python-tornado/petstore_api/models/model_return.py index 3862245ef71d..7f3e64a12ab5 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/model_return.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/model_return.py @@ -15,8 +15,27 @@ import six - -class ModelReturn(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ModelReturn(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class ModelReturn(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - '_return': 'int' + '_return': [int] # noqa: E501 } - attribute_map = { - '_return': 'return' + '_return': 'return' # noqa: E501 } - def __init__(self, _return=None): # noqa: E501 - """ModelReturn - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ModelReturn - a model defined in OpenAPI - self.__return = None - self.discriminator = None - if _return is not None: - self._return = _return + + 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 False + _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 + _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. + _return (int): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def _return(self): """Gets the _return of this ModelReturn. # noqa: E501 - :return: The _return of this ModelReturn. # noqa: E501 - :rtype: int + Returns: + (int): The _return of this ModelReturn. # noqa: E501 """ - return self.__return + return self._data_store.get('_return') @_return.setter - def _return(self, _return): + def _return( + self, _return): """Sets the _return of this ModelReturn. - :param _return: The _return of this ModelReturn. # noqa: E501 - :type: int + Returns: + (int): The _return of this ModelReturn. # noqa: E501 """ - self.__return = _return + self.__setitem__( + '_return', + _return + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/name.py b/samples/client/petstore/python-tornado/petstore_api/models/name.py index b2e97e596a4d..1b06fe765b43 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/name.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/name.py @@ -15,8 +15,27 @@ import six - -class Name(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Name(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,149 +46,223 @@ class Name(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'name': 'int', - 'snake_case': 'int', - '_property': 'str', - '_123_number': 'int' + 'name': [int], # noqa: E501 + 'snake_case': [int], # noqa: E501 + '_property': [str], # noqa: E501 + '_123_number': [int] # noqa: E501 } - attribute_map = { - 'name': 'name', - 'snake_case': 'snake_case', - '_property': 'property', - '_123_number': '123Number' + 'name': 'name', # noqa: E501 + 'snake_case': 'snake_case', # noqa: E501 + '_property': 'property', # noqa: E501 + '_123_number': '123Number' # noqa: E501 } - def __init__(self, name=None, snake_case=None, _property=None, _123_number=None): # noqa: E501 - """Name - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, name, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Name - a model defined in OpenAPI + + Args: + name (int): + + 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 False + _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 + _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. + snake_case (int): [optional] # noqa: E501 + _property (str): [optional] # noqa: E501 + _123_number (int): [optional] # noqa: E501 + """ - self._name = None - self._snake_case = None - self.__property = None - self.__123_number = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + # assign using .var_name to check against nullable and enums self.name = name - if snake_case is not None: - self.snake_case = snake_case - if _property is not None: - self._property = _property - if _123_number is not None: - self._123_number = _123_number + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def name(self): """Gets the name of this Name. # noqa: E501 - :return: The name of this Name. # noqa: E501 - :rtype: int + Returns: + (int): The name of this Name. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this Name. - :param name: The name of this Name. # noqa: E501 - :type: int + Returns: + (int): The name of this Name. # noqa: E501 """ if name is None: - raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `name`, must not be `None`") # noqa: E501 - self._name = name + self.__setitem__( + 'name', + name + ) @property def snake_case(self): """Gets the snake_case of this Name. # noqa: E501 - :return: The snake_case of this Name. # noqa: E501 - :rtype: int + Returns: + (int): The snake_case of this Name. # noqa: E501 """ - return self._snake_case + return self._data_store.get('snake_case') @snake_case.setter - def snake_case(self, snake_case): + def snake_case( + self, snake_case): """Sets the snake_case of this Name. - :param snake_case: The snake_case of this Name. # noqa: E501 - :type: int + Returns: + (int): The snake_case of this Name. # noqa: E501 """ - self._snake_case = snake_case + self.__setitem__( + 'snake_case', + snake_case + ) @property def _property(self): """Gets the _property of this Name. # noqa: E501 - :return: The _property of this Name. # noqa: E501 - :rtype: str + Returns: + (str): The _property of this Name. # noqa: E501 """ - return self.__property + return self._data_store.get('_property') @_property.setter - def _property(self, _property): + def _property( + self, _property): """Sets the _property of this Name. - :param _property: The _property of this Name. # noqa: E501 - :type: str + Returns: + (str): The _property of this Name. # noqa: E501 """ - self.__property = _property + self.__setitem__( + '_property', + _property + ) @property def _123_number(self): """Gets the _123_number of this Name. # noqa: E501 - :return: The _123_number of this Name. # noqa: E501 - :rtype: int + Returns: + (int): The _123_number of this Name. # noqa: E501 """ - return self.__123_number + return self._data_store.get('_123_number') @_123_number.setter - def _123_number(self, _123_number): + def _123_number( + self, _123_number): """Sets the _123_number of this Name. - :param _123_number: The _123_number of this Name. # noqa: E501 - :type: int + Returns: + (int): The _123_number of this Name. # noqa: E501 """ - self.__123_number = _123_number + self.__setitem__( + '_123_number', + _123_number + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/number_only.py b/samples/client/petstore/python-tornado/petstore_api/models/number_only.py index ab39ee8195d4..8cbc7054da0b 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/number_only.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/number_only.py @@ -15,8 +15,27 @@ import six - -class NumberOnly(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class NumberOnly(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class NumberOnly(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'just_number': 'float' + 'just_number': [float] # noqa: E501 } - attribute_map = { - 'just_number': 'JustNumber' + 'just_number': 'JustNumber' # noqa: E501 } - def __init__(self, just_number=None): # noqa: E501 - """NumberOnly - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """NumberOnly - a model defined in OpenAPI - self._just_number = None - self.discriminator = None - if just_number is not None: - self.just_number = just_number + + 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 False + _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 + _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. + just_number (float): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def just_number(self): """Gets the just_number of this NumberOnly. # noqa: E501 - :return: The just_number of this NumberOnly. # noqa: E501 - :rtype: float + Returns: + (float): The just_number of this NumberOnly. # noqa: E501 """ - return self._just_number + return self._data_store.get('just_number') @just_number.setter - def just_number(self, just_number): + def just_number( + self, just_number): """Sets the just_number of this NumberOnly. - :param just_number: The just_number of this NumberOnly. # noqa: E501 - :type: float + Returns: + (float): The just_number of this NumberOnly. # noqa: E501 """ - self._just_number = just_number + self.__setitem__( + 'just_number', + just_number + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/order.py b/samples/client/petstore/python-tornado/petstore_api/models/order.py index 697d84447cdc..8f5e45a33be8 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/order.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/order.py @@ -15,8 +15,27 @@ import six - -class Order(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Order(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,134 +46,221 @@ class Order(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'id': 'int', - 'pet_id': 'int', - 'quantity': 'int', - 'ship_date': 'datetime', - 'status': 'str', - 'complete': 'bool' + 'id': [int], # noqa: E501 + 'pet_id': [int], # noqa: E501 + 'quantity': [int], # noqa: E501 + 'ship_date': [datetime], # noqa: E501 + 'status': [str], # noqa: E501 + 'complete': [bool] # noqa: E501 } - attribute_map = { - 'id': 'id', - 'pet_id': 'petId', - 'quantity': 'quantity', - 'ship_date': 'shipDate', - 'status': 'status', - 'complete': 'complete' + 'id': 'id', # noqa: E501 + 'pet_id': 'petId', # noqa: E501 + 'quantity': 'quantity', # noqa: E501 + 'ship_date': 'shipDate', # noqa: E501 + 'status': 'status', # noqa: E501 + 'complete': 'complete' # noqa: E501 } - def __init__(self, id=None, pet_id=None, quantity=None, ship_date=None, status=None, complete=False): # noqa: E501 - """Order - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Order - 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 False + _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 + _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. + id (int): [optional] # noqa: E501 + pet_id (int): [optional] # noqa: E501 + quantity (int): [optional] # noqa: E501 + ship_date (datetime): [optional] # noqa: E501 + status (str): Order Status. [optional] # noqa: E501 + complete (bool): [optional] if omitted the server will use the default value of False # noqa: E501 + """ - self._id = None - self._pet_id = None - self._quantity = None - self._ship_date = None - self._status = None - self._complete = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) - if id is not None: - self.id = id - if pet_id is not None: - self.pet_id = pet_id - if quantity is not None: - self.quantity = quantity - if ship_date is not None: - self.ship_date = ship_date - if status is not None: - self.status = status - if complete is not None: - self.complete = complete + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def id(self): """Gets the id of this Order. # noqa: E501 - :return: The id of this Order. # noqa: E501 - :rtype: int + Returns: + (int): The id of this Order. # noqa: E501 """ - return self._id + return self._data_store.get('id') @id.setter - def id(self, id): + def id( + self, id): """Sets the id of this Order. - :param id: The id of this Order. # noqa: E501 - :type: int + Returns: + (int): The id of this Order. # noqa: E501 """ - self._id = id + self.__setitem__( + 'id', + id + ) @property def pet_id(self): """Gets the pet_id of this Order. # noqa: E501 - :return: The pet_id of this Order. # noqa: E501 - :rtype: int + Returns: + (int): The pet_id of this Order. # noqa: E501 """ - return self._pet_id + return self._data_store.get('pet_id') @pet_id.setter - def pet_id(self, pet_id): + def pet_id( + self, pet_id): """Sets the pet_id of this Order. - :param pet_id: The pet_id of this Order. # noqa: E501 - :type: int + Returns: + (int): The pet_id of this Order. # noqa: E501 """ - self._pet_id = pet_id + self.__setitem__( + 'pet_id', + pet_id + ) @property def quantity(self): """Gets the quantity of this Order. # noqa: E501 - :return: The quantity of this Order. # noqa: E501 - :rtype: int + Returns: + (int): The quantity of this Order. # noqa: E501 """ - return self._quantity + return self._data_store.get('quantity') @quantity.setter - def quantity(self, quantity): + def quantity( + self, quantity): """Sets the quantity of this Order. - :param quantity: The quantity of this Order. # noqa: E501 - :type: int + Returns: + (int): The quantity of this Order. # noqa: E501 """ - self._quantity = quantity + self.__setitem__( + 'quantity', + quantity + ) @property def ship_date(self): """Gets the ship_date of this Order. # noqa: E501 - :return: The ship_date of this Order. # noqa: E501 - :rtype: datetime + Returns: + (datetime): The ship_date of this Order. # noqa: E501 """ - return self._ship_date + return self._data_store.get('ship_date') @ship_date.setter - def ship_date(self, ship_date): + def ship_date( + self, ship_date): """Sets the ship_date of this Order. - :param ship_date: The ship_date of this Order. # noqa: E501 - :type: datetime + Returns: + (datetime): The ship_date of this Order. # noqa: E501 """ - self._ship_date = ship_date + self.__setitem__( + 'ship_date', + ship_date + ) @property def status(self): @@ -162,73 +268,61 @@ def status(self): Order Status # noqa: E501 - :return: The status of this Order. # noqa: E501 - :rtype: str + Returns: + (str): The status of this Order. # noqa: E501 """ - return self._status + return self._data_store.get('status') @status.setter - def status(self, status): + def status( + self, status): """Sets the status of this Order. Order Status # noqa: E501 - :param status: The status of this Order. # noqa: E501 - :type: str + Returns: + (str): The status of this Order. # noqa: E501 """ allowed_values = ["placed", "approved", "delivered"] # noqa: E501 if status not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `status` ({0}), must be one of {1}" # noqa: E501 .format(status, allowed_values) ) - self._status = status + self.__setitem__( + 'status', + status + ) @property def complete(self): """Gets the complete of this Order. # noqa: E501 - :return: The complete of this Order. # noqa: E501 - :rtype: bool + Returns: + (bool): The complete of this Order. # noqa: E501 """ - return self._complete + return self._data_store.get('complete') @complete.setter - def complete(self, complete): + def complete( + self, complete): """Sets the complete of this Order. - :param complete: The complete of this Order. # noqa: E501 - :type: bool + Returns: + (bool): The complete of this Order. # noqa: E501 """ - self._complete = complete + self.__setitem__( + 'complete', + complete + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/outer_composite.py b/samples/client/petstore/python-tornado/petstore_api/models/outer_composite.py index b22b16c6fdcd..3da4dfb6426d 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/outer_composite.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/outer_composite.py @@ -15,8 +15,27 @@ import six - -class OuterComposite(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class OuterComposite(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,122 +46,191 @@ class OuterComposite(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'my_number': 'float', - 'my_string': 'str', - 'my_boolean': 'bool' + 'my_number': [float], # noqa: E501 + 'my_string': [str], # noqa: E501 + 'my_boolean': [bool] # noqa: E501 } - attribute_map = { - 'my_number': 'my_number', - 'my_string': 'my_string', - 'my_boolean': 'my_boolean' + 'my_number': 'my_number', # noqa: E501 + 'my_string': 'my_string', # noqa: E501 + 'my_boolean': 'my_boolean' # noqa: E501 } - def __init__(self, my_number=None, my_string=None, my_boolean=None): # noqa: E501 - """OuterComposite - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """OuterComposite - 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 False + _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 + _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. + my_number (float): [optional] # noqa: E501 + my_string (str): [optional] # noqa: E501 + my_boolean (bool): [optional] # noqa: E501 + """ - self._my_number = None - self._my_string = None - self._my_boolean = None + self._data_store = {} self.discriminator = None - - if my_number is not None: - self.my_number = my_number - if my_string is not None: - self.my_string = my_string - if my_boolean is not None: - self.my_boolean = my_boolean + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def my_number(self): """Gets the my_number of this OuterComposite. # noqa: E501 - :return: The my_number of this OuterComposite. # noqa: E501 - :rtype: float + Returns: + (float): The my_number of this OuterComposite. # noqa: E501 """ - return self._my_number + return self._data_store.get('my_number') @my_number.setter - def my_number(self, my_number): + def my_number( + self, my_number): """Sets the my_number of this OuterComposite. - :param my_number: The my_number of this OuterComposite. # noqa: E501 - :type: float + Returns: + (float): The my_number of this OuterComposite. # noqa: E501 """ - self._my_number = my_number + self.__setitem__( + 'my_number', + my_number + ) @property def my_string(self): """Gets the my_string of this OuterComposite. # noqa: E501 - :return: The my_string of this OuterComposite. # noqa: E501 - :rtype: str + Returns: + (str): The my_string of this OuterComposite. # noqa: E501 """ - return self._my_string + return self._data_store.get('my_string') @my_string.setter - def my_string(self, my_string): + def my_string( + self, my_string): """Sets the my_string of this OuterComposite. - :param my_string: The my_string of this OuterComposite. # noqa: E501 - :type: str + Returns: + (str): The my_string of this OuterComposite. # noqa: E501 """ - self._my_string = my_string + self.__setitem__( + 'my_string', + my_string + ) @property def my_boolean(self): """Gets the my_boolean of this OuterComposite. # noqa: E501 - :return: The my_boolean of this OuterComposite. # noqa: E501 - :rtype: bool + Returns: + (bool): The my_boolean of this OuterComposite. # noqa: E501 """ - return self._my_boolean + return self._data_store.get('my_boolean') @my_boolean.setter - def my_boolean(self, my_boolean): + def my_boolean( + self, my_boolean): """Sets the my_boolean of this OuterComposite. - :param my_boolean: The my_boolean of this OuterComposite. # noqa: E501 - :type: bool + Returns: + (bool): The my_boolean of this OuterComposite. # noqa: E501 """ - self._my_boolean = my_boolean + self.__setitem__( + 'my_boolean', + my_boolean + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/outer_enum.py b/samples/client/petstore/python-tornado/petstore_api/models/outer_enum.py index 10d6be19a4c9..9d4398b5188d 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/outer_enum.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/outer_enum.py @@ -15,8 +15,27 @@ import six - -class OuterEnum(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class OuterEnum(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -34,42 +53,107 @@ class OuterEnum(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { } - attribute_map = { } - def __init__(self): # noqa: E501 - """OuterEnum - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """OuterEnum - 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 False + _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 + _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. + """ + + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/pet.py b/samples/client/petstore/python-tornado/petstore_api/models/pet.py index d3c412f4a82b..1b30f1186d6f 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/pet.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/pet.py @@ -15,8 +15,29 @@ import six - -class Pet(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.category import Category +from petstore_api.models.tag import Tag + + +class Pet(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,157 +48,253 @@ class Pet(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'id': 'int', - 'category': 'Category', - 'name': 'str', - 'photo_urls': 'list[str]', - 'tags': 'list[Tag]', - 'status': 'str' + 'id': [int], # noqa: E501 + 'category': [Category], # noqa: E501 + 'name': [str], # noqa: E501 + 'photo_urls': [[(str,)]], # noqa: E501 + 'tags': [[(Tag,)]], # noqa: E501 + 'status': [str] # noqa: E501 } - attribute_map = { - 'id': 'id', - 'category': 'category', - 'name': 'name', - 'photo_urls': 'photoUrls', - 'tags': 'tags', - 'status': 'status' + 'id': 'id', # noqa: E501 + 'category': 'category', # noqa: E501 + 'name': 'name', # noqa: E501 + 'photo_urls': 'photoUrls', # noqa: E501 + 'tags': 'tags', # noqa: E501 + 'status': 'status' # noqa: E501 } - def __init__(self, id=None, category=None, name=None, photo_urls=None, tags=None, status=None): # noqa: E501 - """Pet - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, name, photo_urls, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Pet - a model defined in OpenAPI + + Args: + name (str): + photo_urls ([(str,)]): + + 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 False + _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 + _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. + id (int): [optional] # noqa: E501 + category (Category): [optional] # noqa: E501 + tags ([(Tag,)]): [optional] # noqa: E501 + status (str): pet status in the store. [optional] # noqa: E501 + """ - self._id = None - self._category = None - self._name = None - self._photo_urls = None - self._tags = None - self._status = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration - if id is not None: - self.id = id - if category is not None: - self.category = category + # assign using .var_name to check against nullable and enums self.name = name self.photo_urls = photo_urls - if tags is not None: - self.tags = tags - if status is not None: - self.status = status + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def id(self): """Gets the id of this Pet. # noqa: E501 - :return: The id of this Pet. # noqa: E501 - :rtype: int + Returns: + (int): The id of this Pet. # noqa: E501 """ - return self._id + return self._data_store.get('id') @id.setter - def id(self, id): + def id( + self, id): """Sets the id of this Pet. - :param id: The id of this Pet. # noqa: E501 - :type: int + Returns: + (int): The id of this Pet. # noqa: E501 """ - self._id = id + self.__setitem__( + 'id', + id + ) @property def category(self): """Gets the category of this Pet. # noqa: E501 - :return: The category of this Pet. # noqa: E501 - :rtype: Category + Returns: + (Category): The category of this Pet. # noqa: E501 """ - return self._category + return self._data_store.get('category') @category.setter - def category(self, category): + def category( + self, category): """Sets the category of this Pet. - :param category: The category of this Pet. # noqa: E501 - :type: Category + Returns: + (Category): The category of this Pet. # noqa: E501 """ - self._category = category + self.__setitem__( + 'category', + category + ) @property def name(self): """Gets the name of this Pet. # noqa: E501 - :return: The name of this Pet. # noqa: E501 - :rtype: str + Returns: + (str): The name of this Pet. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this Pet. - :param name: The name of this Pet. # noqa: E501 - :type: str + Returns: + (str): The name of this Pet. # noqa: E501 """ if name is None: - raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `name`, must not be `None`") # noqa: E501 - self._name = name + self.__setitem__( + 'name', + name + ) @property def photo_urls(self): """Gets the photo_urls of this Pet. # noqa: E501 - :return: The photo_urls of this Pet. # noqa: E501 - :rtype: list[str] + Returns: + ([(str,)]): The photo_urls of this Pet. # noqa: E501 """ - return self._photo_urls + return self._data_store.get('photo_urls') @photo_urls.setter - def photo_urls(self, photo_urls): + def photo_urls( + self, photo_urls): """Sets the photo_urls of this Pet. - :param photo_urls: The photo_urls of this Pet. # noqa: E501 - :type: list[str] + Returns: + ([(str,)]): The photo_urls of this Pet. # noqa: E501 """ if photo_urls is None: - raise ValueError("Invalid value for `photo_urls`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `photo_urls`, must not be `None`") # noqa: E501 - self._photo_urls = photo_urls + self.__setitem__( + 'photo_urls', + photo_urls + ) @property def tags(self): """Gets the tags of this Pet. # noqa: E501 - :return: The tags of this Pet. # noqa: E501 - :rtype: list[Tag] + Returns: + ([(Tag,)]): The tags of this Pet. # noqa: E501 """ - return self._tags + return self._data_store.get('tags') @tags.setter - def tags(self, tags): + def tags( + self, tags): """Sets the tags of this Pet. - :param tags: The tags of this Pet. # noqa: E501 - :type: list[Tag] + Returns: + ([(Tag,)]): The tags of this Pet. # noqa: E501 """ - self._tags = tags + self.__setitem__( + 'tags', + tags + ) @property def status(self): @@ -185,52 +302,36 @@ def status(self): pet status in the store # noqa: E501 - :return: The status of this Pet. # noqa: E501 - :rtype: str + Returns: + (str): The status of this Pet. # noqa: E501 """ - return self._status + return self._data_store.get('status') @status.setter - def status(self, status): + def status( + self, status): """Sets the status of this Pet. pet status in the store # noqa: E501 - :param status: The status of this Pet. # noqa: E501 - :type: str + Returns: + (str): The status of this Pet. # noqa: E501 """ allowed_values = ["available", "pending", "sold"] # noqa: E501 if status not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `status` ({0}), must be one of {1}" # noqa: E501 .format(status, allowed_values) ) - self._status = status + self.__setitem__( + 'status', + status + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/read_only_first.py b/samples/client/petstore/python-tornado/petstore_api/models/read_only_first.py index 2b257be18de4..0309488b3f37 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/read_only_first.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/read_only_first.py @@ -15,8 +15,27 @@ import six - -class ReadOnlyFirst(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ReadOnlyFirst(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +46,163 @@ class ReadOnlyFirst(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'bar': 'str', - 'baz': 'str' + 'bar': [str], # noqa: E501 + 'baz': [str] # noqa: E501 } - attribute_map = { - 'bar': 'bar', - 'baz': 'baz' + 'bar': 'bar', # noqa: E501 + 'baz': 'baz' # noqa: E501 } - def __init__(self, bar=None, baz=None): # noqa: E501 - """ReadOnlyFirst - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ReadOnlyFirst - 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 False + _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 + _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. + bar (str): [optional] # noqa: E501 + baz (str): [optional] # noqa: E501 + """ - self._bar = None - self._baz = None + self._data_store = {} self.discriminator = None - - if bar is not None: - self.bar = bar - if baz is not None: - self.baz = baz + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def bar(self): """Gets the bar of this ReadOnlyFirst. # noqa: E501 - :return: The bar of this ReadOnlyFirst. # noqa: E501 - :rtype: str + Returns: + (str): The bar of this ReadOnlyFirst. # noqa: E501 """ - return self._bar + return self._data_store.get('bar') @bar.setter - def bar(self, bar): + def bar( + self, bar): """Sets the bar of this ReadOnlyFirst. - :param bar: The bar of this ReadOnlyFirst. # noqa: E501 - :type: str + Returns: + (str): The bar of this ReadOnlyFirst. # noqa: E501 """ - self._bar = bar + self.__setitem__( + 'bar', + bar + ) @property def baz(self): """Gets the baz of this ReadOnlyFirst. # noqa: E501 - :return: The baz of this ReadOnlyFirst. # noqa: E501 - :rtype: str + Returns: + (str): The baz of this ReadOnlyFirst. # noqa: E501 """ - return self._baz + return self._data_store.get('baz') @baz.setter - def baz(self, baz): + def baz( + self, baz): """Sets the baz of this ReadOnlyFirst. - :param baz: The baz of this ReadOnlyFirst. # noqa: E501 - :type: str + Returns: + (str): The baz of this ReadOnlyFirst. # noqa: E501 """ - self._baz = baz + self.__setitem__( + 'baz', + baz + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/special_model_name.py b/samples/client/petstore/python-tornado/petstore_api/models/special_model_name.py index fa59b887471b..9431157f2c3e 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/special_model_name.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/special_model_name.py @@ -15,8 +15,27 @@ import six - -class SpecialModelName(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class SpecialModelName(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class SpecialModelName(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'special_property_name': 'int' + 'special_property_name': [int] # noqa: E501 } - attribute_map = { - 'special_property_name': '$special[property.name]' + 'special_property_name': '$special[property.name]' # noqa: E501 } - def __init__(self, special_property_name=None): # noqa: E501 - """SpecialModelName - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """SpecialModelName - a model defined in OpenAPI - self._special_property_name = None - self.discriminator = None - if special_property_name is not None: - self.special_property_name = special_property_name + + 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 False + _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 + _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. + special_property_name (int): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def special_property_name(self): """Gets the special_property_name of this SpecialModelName. # noqa: E501 - :return: The special_property_name of this SpecialModelName. # noqa: E501 - :rtype: int + Returns: + (int): The special_property_name of this SpecialModelName. # noqa: E501 """ - return self._special_property_name + return self._data_store.get('special_property_name') @special_property_name.setter - def special_property_name(self, special_property_name): + def special_property_name( + self, special_property_name): """Sets the special_property_name of this SpecialModelName. - :param special_property_name: The special_property_name of this SpecialModelName. # noqa: E501 - :type: int + Returns: + (int): The special_property_name of this SpecialModelName. # noqa: E501 """ - self._special_property_name = special_property_name + self.__setitem__( + 'special_property_name', + special_property_name + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/tag.py b/samples/client/petstore/python-tornado/petstore_api/models/tag.py index 8fcc8a848660..0c781dc5be7c 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/tag.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/tag.py @@ -15,8 +15,27 @@ import six - -class Tag(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Tag(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +46,163 @@ class Tag(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'id': 'int', - 'name': 'str' + 'id': [int], # noqa: E501 + 'name': [str] # noqa: E501 } - attribute_map = { - 'id': 'id', - 'name': 'name' + 'id': 'id', # noqa: E501 + 'name': 'name' # noqa: E501 } - def __init__(self, id=None, name=None): # noqa: E501 - """Tag - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Tag - 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 False + _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 + _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. + id (int): [optional] # noqa: E501 + name (str): [optional] # noqa: E501 + """ - self._id = None - self._name = None + self._data_store = {} self.discriminator = None - - if id is not None: - self.id = id - if name is not None: - self.name = name + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def id(self): """Gets the id of this Tag. # noqa: E501 - :return: The id of this Tag. # noqa: E501 - :rtype: int + Returns: + (int): The id of this Tag. # noqa: E501 """ - return self._id + return self._data_store.get('id') @id.setter - def id(self, id): + def id( + self, id): """Sets the id of this Tag. - :param id: The id of this Tag. # noqa: E501 - :type: int + Returns: + (int): The id of this Tag. # noqa: E501 """ - self._id = id + self.__setitem__( + 'id', + id + ) @property def name(self): """Gets the name of this Tag. # noqa: E501 - :return: The name of this Tag. # noqa: E501 - :rtype: str + Returns: + (str): The name of this Tag. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this Tag. - :param name: The name of this Tag. # noqa: E501 - :type: str + Returns: + (str): The name of this Tag. # noqa: E501 """ - self._name = name + self.__setitem__( + 'name', + name + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/type_holder_default.py b/samples/client/petstore/python-tornado/petstore_api/models/type_holder_default.py index a0566f5d5fe6..88c3db03e30a 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/type_holder_default.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/type_holder_default.py @@ -15,8 +15,27 @@ import six - -class TypeHolderDefault(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class TypeHolderDefault(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,179 +46,263 @@ class TypeHolderDefault(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'string_item': 'str', - 'number_item': 'float', - 'integer_item': 'int', - 'bool_item': 'bool', - 'array_item': 'list[int]' + 'string_item': [str], # noqa: E501 + 'number_item': [float], # noqa: E501 + 'integer_item': [int], # noqa: E501 + 'bool_item': [bool], # noqa: E501 + 'array_item': [[(int,)]] # noqa: E501 } - attribute_map = { - 'string_item': 'string_item', - 'number_item': 'number_item', - 'integer_item': 'integer_item', - 'bool_item': 'bool_item', - 'array_item': 'array_item' + 'string_item': 'string_item', # noqa: E501 + 'number_item': 'number_item', # noqa: E501 + 'integer_item': 'integer_item', # noqa: E501 + 'bool_item': 'bool_item', # noqa: E501 + 'array_item': 'array_item' # noqa: E501 } - def __init__(self, string_item='what', number_item=None, integer_item=None, bool_item=True, array_item=None): # noqa: E501 - """TypeHolderDefault - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, number_item, integer_item, array_item, string_item='what', bool_item=True, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """TypeHolderDefault - a model defined in OpenAPI + + Args: + number_item (float): + integer_item (int): + array_item ([(int,)]): + string_item (str): defaults to 'what', must be one of ['what'] # noqa: E501 + bool_item (bool): defaults to True, must be one of [True] # noqa: E501 + + 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 False + _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 + _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. + """ - self._string_item = None - self._number_item = None - self._integer_item = None - self._bool_item = None - self._array_item = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + # assign using .var_name to check against nullable and enums self.string_item = string_item self.number_item = number_item self.integer_item = integer_item self.bool_item = bool_item self.array_item = array_item + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def string_item(self): """Gets the string_item of this TypeHolderDefault. # noqa: E501 - :return: The string_item of this TypeHolderDefault. # noqa: E501 - :rtype: str + Returns: + (str): The string_item of this TypeHolderDefault. # noqa: E501 """ - return self._string_item + return self._data_store.get('string_item') @string_item.setter - def string_item(self, string_item): + def string_item( + self, string_item): """Sets the string_item of this TypeHolderDefault. - :param string_item: The string_item of this TypeHolderDefault. # noqa: E501 - :type: str + Returns: + (str): The string_item of this TypeHolderDefault. # noqa: E501 """ if string_item is None: - raise ValueError("Invalid value for `string_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `string_item`, must not be `None`") # noqa: E501 - self._string_item = string_item + self.__setitem__( + 'string_item', + string_item + ) @property def number_item(self): """Gets the number_item of this TypeHolderDefault. # noqa: E501 - :return: The number_item of this TypeHolderDefault. # noqa: E501 - :rtype: float + Returns: + (float): The number_item of this TypeHolderDefault. # noqa: E501 """ - return self._number_item + return self._data_store.get('number_item') @number_item.setter - def number_item(self, number_item): + def number_item( + self, number_item): """Sets the number_item of this TypeHolderDefault. - :param number_item: The number_item of this TypeHolderDefault. # noqa: E501 - :type: float + Returns: + (float): The number_item of this TypeHolderDefault. # noqa: E501 """ if number_item is None: - raise ValueError("Invalid value for `number_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `number_item`, must not be `None`") # noqa: E501 - self._number_item = number_item + self.__setitem__( + 'number_item', + number_item + ) @property def integer_item(self): """Gets the integer_item of this TypeHolderDefault. # noqa: E501 - :return: The integer_item of this TypeHolderDefault. # noqa: E501 - :rtype: int + Returns: + (int): The integer_item of this TypeHolderDefault. # noqa: E501 """ - return self._integer_item + return self._data_store.get('integer_item') @integer_item.setter - def integer_item(self, integer_item): + def integer_item( + self, integer_item): """Sets the integer_item of this TypeHolderDefault. - :param integer_item: The integer_item of this TypeHolderDefault. # noqa: E501 - :type: int + Returns: + (int): The integer_item of this TypeHolderDefault. # noqa: E501 """ if integer_item is None: - raise ValueError("Invalid value for `integer_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `integer_item`, must not be `None`") # noqa: E501 - self._integer_item = integer_item + self.__setitem__( + 'integer_item', + integer_item + ) @property def bool_item(self): """Gets the bool_item of this TypeHolderDefault. # noqa: E501 - :return: The bool_item of this TypeHolderDefault. # noqa: E501 - :rtype: bool + Returns: + (bool): The bool_item of this TypeHolderDefault. # noqa: E501 """ - return self._bool_item + return self._data_store.get('bool_item') @bool_item.setter - def bool_item(self, bool_item): + def bool_item( + self, bool_item): """Sets the bool_item of this TypeHolderDefault. - :param bool_item: The bool_item of this TypeHolderDefault. # noqa: E501 - :type: bool + Returns: + (bool): The bool_item of this TypeHolderDefault. # noqa: E501 """ if bool_item is None: - raise ValueError("Invalid value for `bool_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `bool_item`, must not be `None`") # noqa: E501 - self._bool_item = bool_item + self.__setitem__( + 'bool_item', + bool_item + ) @property def array_item(self): """Gets the array_item of this TypeHolderDefault. # noqa: E501 - :return: The array_item of this TypeHolderDefault. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The array_item of this TypeHolderDefault. # noqa: E501 """ - return self._array_item + return self._data_store.get('array_item') @array_item.setter - def array_item(self, array_item): + def array_item( + self, array_item): """Sets the array_item of this TypeHolderDefault. - :param array_item: The array_item of this TypeHolderDefault. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The array_item of this TypeHolderDefault. # noqa: E501 """ if array_item is None: - raise ValueError("Invalid value for `array_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `array_item`, must not be `None`") # noqa: E501 - self._array_item = array_item + self.__setitem__( + 'array_item', + array_item + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/type_holder_example.py b/samples/client/petstore/python-tornado/petstore_api/models/type_holder_example.py index c926f4e48489..02ea8681cb6f 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/type_holder_example.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/type_holder_example.py @@ -15,8 +15,27 @@ import six - -class TypeHolderExample(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class TypeHolderExample(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,179 +46,263 @@ class TypeHolderExample(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'string_item': 'str', - 'number_item': 'float', - 'integer_item': 'int', - 'bool_item': 'bool', - 'array_item': 'list[int]' + 'string_item': [str], # noqa: E501 + 'number_item': [float], # noqa: E501 + 'integer_item': [int], # noqa: E501 + 'bool_item': [bool], # noqa: E501 + 'array_item': [[(int,)]] # noqa: E501 } - attribute_map = { - 'string_item': 'string_item', - 'number_item': 'number_item', - 'integer_item': 'integer_item', - 'bool_item': 'bool_item', - 'array_item': 'array_item' + 'string_item': 'string_item', # noqa: E501 + 'number_item': 'number_item', # noqa: E501 + 'integer_item': 'integer_item', # noqa: E501 + 'bool_item': 'bool_item', # noqa: E501 + 'array_item': 'array_item' # noqa: E501 } - def __init__(self, string_item=None, number_item=None, integer_item=None, bool_item=None, array_item=None): # noqa: E501 - """TypeHolderExample - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, string_item, number_item, integer_item, bool_item, array_item, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """TypeHolderExample - a model defined in OpenAPI + + Args: + string_item (str): + number_item (float): + integer_item (int): + bool_item (bool): + array_item ([(int,)]): + + 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 False + _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 + _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. + """ - self._string_item = None - self._number_item = None - self._integer_item = None - self._bool_item = None - self._array_item = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + # assign using .var_name to check against nullable and enums self.string_item = string_item self.number_item = number_item self.integer_item = integer_item self.bool_item = bool_item self.array_item = array_item + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def string_item(self): """Gets the string_item of this TypeHolderExample. # noqa: E501 - :return: The string_item of this TypeHolderExample. # noqa: E501 - :rtype: str + Returns: + (str): The string_item of this TypeHolderExample. # noqa: E501 """ - return self._string_item + return self._data_store.get('string_item') @string_item.setter - def string_item(self, string_item): + def string_item( + self, string_item): """Sets the string_item of this TypeHolderExample. - :param string_item: The string_item of this TypeHolderExample. # noqa: E501 - :type: str + Returns: + (str): The string_item of this TypeHolderExample. # noqa: E501 """ if string_item is None: - raise ValueError("Invalid value for `string_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `string_item`, must not be `None`") # noqa: E501 - self._string_item = string_item + self.__setitem__( + 'string_item', + string_item + ) @property def number_item(self): """Gets the number_item of this TypeHolderExample. # noqa: E501 - :return: The number_item of this TypeHolderExample. # noqa: E501 - :rtype: float + Returns: + (float): The number_item of this TypeHolderExample. # noqa: E501 """ - return self._number_item + return self._data_store.get('number_item') @number_item.setter - def number_item(self, number_item): + def number_item( + self, number_item): """Sets the number_item of this TypeHolderExample. - :param number_item: The number_item of this TypeHolderExample. # noqa: E501 - :type: float + Returns: + (float): The number_item of this TypeHolderExample. # noqa: E501 """ if number_item is None: - raise ValueError("Invalid value for `number_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `number_item`, must not be `None`") # noqa: E501 - self._number_item = number_item + self.__setitem__( + 'number_item', + number_item + ) @property def integer_item(self): """Gets the integer_item of this TypeHolderExample. # noqa: E501 - :return: The integer_item of this TypeHolderExample. # noqa: E501 - :rtype: int + Returns: + (int): The integer_item of this TypeHolderExample. # noqa: E501 """ - return self._integer_item + return self._data_store.get('integer_item') @integer_item.setter - def integer_item(self, integer_item): + def integer_item( + self, integer_item): """Sets the integer_item of this TypeHolderExample. - :param integer_item: The integer_item of this TypeHolderExample. # noqa: E501 - :type: int + Returns: + (int): The integer_item of this TypeHolderExample. # noqa: E501 """ if integer_item is None: - raise ValueError("Invalid value for `integer_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `integer_item`, must not be `None`") # noqa: E501 - self._integer_item = integer_item + self.__setitem__( + 'integer_item', + integer_item + ) @property def bool_item(self): """Gets the bool_item of this TypeHolderExample. # noqa: E501 - :return: The bool_item of this TypeHolderExample. # noqa: E501 - :rtype: bool + Returns: + (bool): The bool_item of this TypeHolderExample. # noqa: E501 """ - return self._bool_item + return self._data_store.get('bool_item') @bool_item.setter - def bool_item(self, bool_item): + def bool_item( + self, bool_item): """Sets the bool_item of this TypeHolderExample. - :param bool_item: The bool_item of this TypeHolderExample. # noqa: E501 - :type: bool + Returns: + (bool): The bool_item of this TypeHolderExample. # noqa: E501 """ if bool_item is None: - raise ValueError("Invalid value for `bool_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `bool_item`, must not be `None`") # noqa: E501 - self._bool_item = bool_item + self.__setitem__( + 'bool_item', + bool_item + ) @property def array_item(self): """Gets the array_item of this TypeHolderExample. # noqa: E501 - :return: The array_item of this TypeHolderExample. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The array_item of this TypeHolderExample. # noqa: E501 """ - return self._array_item + return self._data_store.get('array_item') @array_item.setter - def array_item(self, array_item): + def array_item( + self, array_item): """Sets the array_item of this TypeHolderExample. - :param array_item: The array_item of this TypeHolderExample. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The array_item of this TypeHolderExample. # noqa: E501 """ if array_item is None: - raise ValueError("Invalid value for `array_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `array_item`, must not be `None`") # noqa: E501 - self._array_item = array_item + self.__setitem__( + 'array_item', + array_item + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/user.py b/samples/client/petstore/python-tornado/petstore_api/models/user.py index 9736c47c1f87..33b99bfdb45c 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/user.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/user.py @@ -15,8 +15,27 @@ import six - -class User(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class User(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,207 +46,302 @@ class User(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'id': 'int', - 'username': 'str', - 'first_name': 'str', - 'last_name': 'str', - 'email': 'str', - 'password': 'str', - 'phone': 'str', - 'user_status': 'int' + 'id': [int], # noqa: E501 + 'username': [str], # noqa: E501 + 'first_name': [str], # noqa: E501 + 'last_name': [str], # noqa: E501 + 'email': [str], # noqa: E501 + 'password': [str], # noqa: E501 + 'phone': [str], # noqa: E501 + 'user_status': [int] # noqa: E501 } - attribute_map = { - 'id': 'id', - 'username': 'username', - 'first_name': 'firstName', - 'last_name': 'lastName', - 'email': 'email', - 'password': 'password', - 'phone': 'phone', - 'user_status': 'userStatus' + 'id': 'id', # noqa: E501 + 'username': 'username', # noqa: E501 + 'first_name': 'firstName', # noqa: E501 + 'last_name': 'lastName', # noqa: E501 + 'email': 'email', # noqa: E501 + 'password': 'password', # noqa: E501 + 'phone': 'phone', # noqa: E501 + 'user_status': 'userStatus' # noqa: E501 } - def __init__(self, id=None, username=None, first_name=None, last_name=None, email=None, password=None, phone=None, user_status=None): # noqa: E501 - """User - a model defined in OpenAPI""" # noqa: E501 - - self._id = None - self._username = None - self._first_name = None - self._last_name = None - self._email = None - self._password = None - self._phone = None - self._user_status = None - self.discriminator = None + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """User - 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 False + _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 + _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. + id (int): [optional] # noqa: E501 + username (str): [optional] # noqa: E501 + first_name (str): [optional] # noqa: E501 + last_name (str): [optional] # noqa: E501 + email (str): [optional] # noqa: E501 + password (str): [optional] # noqa: E501 + phone (str): [optional] # noqa: E501 + user_status (int): User Status. [optional] # noqa: E501 + """ - if id is not None: - self.id = id - if username is not None: - self.username = username - if first_name is not None: - self.first_name = first_name - if last_name is not None: - self.last_name = last_name - if email is not None: - self.email = email - if password is not None: - self.password = password - if phone is not None: - self.phone = phone - if user_status is not None: - self.user_status = user_status + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def id(self): """Gets the id of this User. # noqa: E501 - :return: The id of this User. # noqa: E501 - :rtype: int + Returns: + (int): The id of this User. # noqa: E501 """ - return self._id + return self._data_store.get('id') @id.setter - def id(self, id): + def id( + self, id): """Sets the id of this User. - :param id: The id of this User. # noqa: E501 - :type: int + Returns: + (int): The id of this User. # noqa: E501 """ - self._id = id + self.__setitem__( + 'id', + id + ) @property def username(self): """Gets the username of this User. # noqa: E501 - :return: The username of this User. # noqa: E501 - :rtype: str + Returns: + (str): The username of this User. # noqa: E501 """ - return self._username + return self._data_store.get('username') @username.setter - def username(self, username): + def username( + self, username): """Sets the username of this User. - :param username: The username of this User. # noqa: E501 - :type: str + Returns: + (str): The username of this User. # noqa: E501 """ - self._username = username + self.__setitem__( + 'username', + username + ) @property def first_name(self): """Gets the first_name of this User. # noqa: E501 - :return: The first_name of this User. # noqa: E501 - :rtype: str + Returns: + (str): The first_name of this User. # noqa: E501 """ - return self._first_name + return self._data_store.get('first_name') @first_name.setter - def first_name(self, first_name): + def first_name( + self, first_name): """Sets the first_name of this User. - :param first_name: The first_name of this User. # noqa: E501 - :type: str + Returns: + (str): The first_name of this User. # noqa: E501 """ - self._first_name = first_name + self.__setitem__( + 'first_name', + first_name + ) @property def last_name(self): """Gets the last_name of this User. # noqa: E501 - :return: The last_name of this User. # noqa: E501 - :rtype: str + Returns: + (str): The last_name of this User. # noqa: E501 """ - return self._last_name + return self._data_store.get('last_name') @last_name.setter - def last_name(self, last_name): + def last_name( + self, last_name): """Sets the last_name of this User. - :param last_name: The last_name of this User. # noqa: E501 - :type: str + Returns: + (str): The last_name of this User. # noqa: E501 """ - self._last_name = last_name + self.__setitem__( + 'last_name', + last_name + ) @property def email(self): """Gets the email of this User. # noqa: E501 - :return: The email of this User. # noqa: E501 - :rtype: str + Returns: + (str): The email of this User. # noqa: E501 """ - return self._email + return self._data_store.get('email') @email.setter - def email(self, email): + def email( + self, email): """Sets the email of this User. - :param email: The email of this User. # noqa: E501 - :type: str + Returns: + (str): The email of this User. # noqa: E501 """ - self._email = email + self.__setitem__( + 'email', + email + ) @property def password(self): """Gets the password of this User. # noqa: E501 - :return: The password of this User. # noqa: E501 - :rtype: str + Returns: + (str): The password of this User. # noqa: E501 """ - return self._password + return self._data_store.get('password') @password.setter - def password(self, password): + def password( + self, password): """Sets the password of this User. - :param password: The password of this User. # noqa: E501 - :type: str + Returns: + (str): The password of this User. # noqa: E501 """ - self._password = password + self.__setitem__( + 'password', + password + ) @property def phone(self): """Gets the phone of this User. # noqa: E501 - :return: The phone of this User. # noqa: E501 - :rtype: str + Returns: + (str): The phone of this User. # noqa: E501 """ - return self._phone + return self._data_store.get('phone') @phone.setter - def phone(self, phone): + def phone( + self, phone): """Sets the phone of this User. - :param phone: The phone of this User. # noqa: E501 - :type: str + Returns: + (str): The phone of this User. # noqa: E501 """ - self._phone = phone + self.__setitem__( + 'phone', + phone + ) @property def user_status(self): @@ -235,46 +349,30 @@ def user_status(self): User Status # noqa: E501 - :return: The user_status of this User. # noqa: E501 - :rtype: int + Returns: + (int): The user_status of this User. # noqa: E501 """ - return self._user_status + return self._data_store.get('user_status') @user_status.setter - def user_status(self, user_status): + def user_status( + self, user_status): """Sets the user_status of this User. User Status # noqa: E501 - :param user_status: The user_status of this User. # noqa: E501 - :type: int + Returns: + (int): The user_status of this User. # noqa: E501 """ - self._user_status = user_status + self.__setitem__( + 'user_status', + user_status + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/models/xml_item.py b/samples/client/petstore/python-tornado/petstore_api/models/xml_item.py index 00872d531a88..86672dae2746 100644 --- a/samples/client/petstore/python-tornado/petstore_api/models/xml_item.py +++ b/samples/client/petstore/python-tornado/petstore_api/models/xml_item.py @@ -15,8 +15,27 @@ import six - -class XmlItem(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class XmlItem(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,798 +46,919 @@ class XmlItem(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'attribute_string': 'str', - 'attribute_number': 'float', - 'attribute_integer': 'int', - 'attribute_boolean': 'bool', - 'wrapped_array': 'list[int]', - 'name_string': 'str', - 'name_number': 'float', - 'name_integer': 'int', - 'name_boolean': 'bool', - 'name_array': 'list[int]', - 'name_wrapped_array': 'list[int]', - 'prefix_string': 'str', - 'prefix_number': 'float', - 'prefix_integer': 'int', - 'prefix_boolean': 'bool', - 'prefix_array': 'list[int]', - 'prefix_wrapped_array': 'list[int]', - 'namespace_string': 'str', - 'namespace_number': 'float', - 'namespace_integer': 'int', - 'namespace_boolean': 'bool', - 'namespace_array': 'list[int]', - 'namespace_wrapped_array': 'list[int]', - 'prefix_ns_string': 'str', - 'prefix_ns_number': 'float', - 'prefix_ns_integer': 'int', - 'prefix_ns_boolean': 'bool', - 'prefix_ns_array': 'list[int]', - 'prefix_ns_wrapped_array': 'list[int]' + 'attribute_string': [str], # noqa: E501 + 'attribute_number': [float], # noqa: E501 + 'attribute_integer': [int], # noqa: E501 + 'attribute_boolean': [bool], # noqa: E501 + 'wrapped_array': [[(int,)]], # noqa: E501 + 'name_string': [str], # noqa: E501 + 'name_number': [float], # noqa: E501 + 'name_integer': [int], # noqa: E501 + 'name_boolean': [bool], # noqa: E501 + 'name_array': [[(int,)]], # noqa: E501 + 'name_wrapped_array': [[(int,)]], # noqa: E501 + 'prefix_string': [str], # noqa: E501 + 'prefix_number': [float], # noqa: E501 + 'prefix_integer': [int], # noqa: E501 + 'prefix_boolean': [bool], # noqa: E501 + 'prefix_array': [[(int,)]], # noqa: E501 + 'prefix_wrapped_array': [[(int,)]], # noqa: E501 + 'namespace_string': [str], # noqa: E501 + 'namespace_number': [float], # noqa: E501 + 'namespace_integer': [int], # noqa: E501 + 'namespace_boolean': [bool], # noqa: E501 + 'namespace_array': [[(int,)]], # noqa: E501 + 'namespace_wrapped_array': [[(int,)]], # noqa: E501 + 'prefix_ns_string': [str], # noqa: E501 + 'prefix_ns_number': [float], # noqa: E501 + 'prefix_ns_integer': [int], # noqa: E501 + 'prefix_ns_boolean': [bool], # noqa: E501 + 'prefix_ns_array': [[(int,)]], # noqa: E501 + 'prefix_ns_wrapped_array': [[(int,)]] # noqa: E501 } - attribute_map = { - 'attribute_string': 'attribute_string', - 'attribute_number': 'attribute_number', - 'attribute_integer': 'attribute_integer', - 'attribute_boolean': 'attribute_boolean', - 'wrapped_array': 'wrapped_array', - 'name_string': 'name_string', - 'name_number': 'name_number', - 'name_integer': 'name_integer', - 'name_boolean': 'name_boolean', - 'name_array': 'name_array', - 'name_wrapped_array': 'name_wrapped_array', - 'prefix_string': 'prefix_string', - 'prefix_number': 'prefix_number', - 'prefix_integer': 'prefix_integer', - 'prefix_boolean': 'prefix_boolean', - 'prefix_array': 'prefix_array', - 'prefix_wrapped_array': 'prefix_wrapped_array', - 'namespace_string': 'namespace_string', - 'namespace_number': 'namespace_number', - 'namespace_integer': 'namespace_integer', - 'namespace_boolean': 'namespace_boolean', - 'namespace_array': 'namespace_array', - 'namespace_wrapped_array': 'namespace_wrapped_array', - 'prefix_ns_string': 'prefix_ns_string', - 'prefix_ns_number': 'prefix_ns_number', - 'prefix_ns_integer': 'prefix_ns_integer', - 'prefix_ns_boolean': 'prefix_ns_boolean', - 'prefix_ns_array': 'prefix_ns_array', - 'prefix_ns_wrapped_array': 'prefix_ns_wrapped_array' + 'attribute_string': 'attribute_string', # noqa: E501 + 'attribute_number': 'attribute_number', # noqa: E501 + 'attribute_integer': 'attribute_integer', # noqa: E501 + 'attribute_boolean': 'attribute_boolean', # noqa: E501 + 'wrapped_array': 'wrapped_array', # noqa: E501 + 'name_string': 'name_string', # noqa: E501 + 'name_number': 'name_number', # noqa: E501 + 'name_integer': 'name_integer', # noqa: E501 + 'name_boolean': 'name_boolean', # noqa: E501 + 'name_array': 'name_array', # noqa: E501 + 'name_wrapped_array': 'name_wrapped_array', # noqa: E501 + 'prefix_string': 'prefix_string', # noqa: E501 + 'prefix_number': 'prefix_number', # noqa: E501 + 'prefix_integer': 'prefix_integer', # noqa: E501 + 'prefix_boolean': 'prefix_boolean', # noqa: E501 + 'prefix_array': 'prefix_array', # noqa: E501 + 'prefix_wrapped_array': 'prefix_wrapped_array', # noqa: E501 + 'namespace_string': 'namespace_string', # noqa: E501 + 'namespace_number': 'namespace_number', # noqa: E501 + 'namespace_integer': 'namespace_integer', # noqa: E501 + 'namespace_boolean': 'namespace_boolean', # noqa: E501 + 'namespace_array': 'namespace_array', # noqa: E501 + 'namespace_wrapped_array': 'namespace_wrapped_array', # noqa: E501 + 'prefix_ns_string': 'prefix_ns_string', # noqa: E501 + 'prefix_ns_number': 'prefix_ns_number', # noqa: E501 + 'prefix_ns_integer': 'prefix_ns_integer', # noqa: E501 + 'prefix_ns_boolean': 'prefix_ns_boolean', # noqa: E501 + 'prefix_ns_array': 'prefix_ns_array', # noqa: E501 + 'prefix_ns_wrapped_array': 'prefix_ns_wrapped_array' # noqa: E501 } - def __init__(self, attribute_string=None, attribute_number=None, attribute_integer=None, attribute_boolean=None, wrapped_array=None, name_string=None, name_number=None, name_integer=None, name_boolean=None, name_array=None, name_wrapped_array=None, prefix_string=None, prefix_number=None, prefix_integer=None, prefix_boolean=None, prefix_array=None, prefix_wrapped_array=None, namespace_string=None, namespace_number=None, namespace_integer=None, namespace_boolean=None, namespace_array=None, namespace_wrapped_array=None, prefix_ns_string=None, prefix_ns_number=None, prefix_ns_integer=None, prefix_ns_boolean=None, prefix_ns_array=None, prefix_ns_wrapped_array=None): # noqa: E501 - """XmlItem - a model defined in OpenAPI""" # noqa: E501 - - self._attribute_string = None - self._attribute_number = None - self._attribute_integer = None - self._attribute_boolean = None - self._wrapped_array = None - self._name_string = None - self._name_number = None - self._name_integer = None - self._name_boolean = None - self._name_array = None - self._name_wrapped_array = None - self._prefix_string = None - self._prefix_number = None - self._prefix_integer = None - self._prefix_boolean = None - self._prefix_array = None - self._prefix_wrapped_array = None - self._namespace_string = None - self._namespace_number = None - self._namespace_integer = None - self._namespace_boolean = None - self._namespace_array = None - self._namespace_wrapped_array = None - self._prefix_ns_string = None - self._prefix_ns_number = None - self._prefix_ns_integer = None - self._prefix_ns_boolean = None - self._prefix_ns_array = None - self._prefix_ns_wrapped_array = None + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """XmlItem - 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 False + _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 + _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. + attribute_string (str): [optional] # noqa: E501 + attribute_number (float): [optional] # noqa: E501 + attribute_integer (int): [optional] # noqa: E501 + attribute_boolean (bool): [optional] # noqa: E501 + wrapped_array ([(int,)]): [optional] # noqa: E501 + name_string (str): [optional] # noqa: E501 + name_number (float): [optional] # noqa: E501 + name_integer (int): [optional] # noqa: E501 + name_boolean (bool): [optional] # noqa: E501 + name_array ([(int,)]): [optional] # noqa: E501 + name_wrapped_array ([(int,)]): [optional] # noqa: E501 + prefix_string (str): [optional] # noqa: E501 + prefix_number (float): [optional] # noqa: E501 + prefix_integer (int): [optional] # noqa: E501 + prefix_boolean (bool): [optional] # noqa: E501 + prefix_array ([(int,)]): [optional] # noqa: E501 + prefix_wrapped_array ([(int,)]): [optional] # noqa: E501 + namespace_string (str): [optional] # noqa: E501 + namespace_number (float): [optional] # noqa: E501 + namespace_integer (int): [optional] # noqa: E501 + namespace_boolean (bool): [optional] # noqa: E501 + namespace_array ([(int,)]): [optional] # noqa: E501 + namespace_wrapped_array ([(int,)]): [optional] # noqa: E501 + prefix_ns_string (str): [optional] # noqa: E501 + prefix_ns_number (float): [optional] # noqa: E501 + prefix_ns_integer (int): [optional] # noqa: E501 + prefix_ns_boolean (bool): [optional] # noqa: E501 + prefix_ns_array ([(int,)]): [optional] # noqa: E501 + prefix_ns_wrapped_array ([(int,)]): [optional] # noqa: E501 + """ + + self._data_store = {} self.discriminator = None - - if attribute_string is not None: - self.attribute_string = attribute_string - if attribute_number is not None: - self.attribute_number = attribute_number - if attribute_integer is not None: - self.attribute_integer = attribute_integer - if attribute_boolean is not None: - self.attribute_boolean = attribute_boolean - if wrapped_array is not None: - self.wrapped_array = wrapped_array - if name_string is not None: - self.name_string = name_string - if name_number is not None: - self.name_number = name_number - if name_integer is not None: - self.name_integer = name_integer - if name_boolean is not None: - self.name_boolean = name_boolean - if name_array is not None: - self.name_array = name_array - if name_wrapped_array is not None: - self.name_wrapped_array = name_wrapped_array - if prefix_string is not None: - self.prefix_string = prefix_string - if prefix_number is not None: - self.prefix_number = prefix_number - if prefix_integer is not None: - self.prefix_integer = prefix_integer - if prefix_boolean is not None: - self.prefix_boolean = prefix_boolean - if prefix_array is not None: - self.prefix_array = prefix_array - if prefix_wrapped_array is not None: - self.prefix_wrapped_array = prefix_wrapped_array - if namespace_string is not None: - self.namespace_string = namespace_string - if namespace_number is not None: - self.namespace_number = namespace_number - if namespace_integer is not None: - self.namespace_integer = namespace_integer - if namespace_boolean is not None: - self.namespace_boolean = namespace_boolean - if namespace_array is not None: - self.namespace_array = namespace_array - if namespace_wrapped_array is not None: - self.namespace_wrapped_array = namespace_wrapped_array - if prefix_ns_string is not None: - self.prefix_ns_string = prefix_ns_string - if prefix_ns_number is not None: - self.prefix_ns_number = prefix_ns_number - if prefix_ns_integer is not None: - self.prefix_ns_integer = prefix_ns_integer - if prefix_ns_boolean is not None: - self.prefix_ns_boolean = prefix_ns_boolean - if prefix_ns_array is not None: - self.prefix_ns_array = prefix_ns_array - if prefix_ns_wrapped_array is not None: - self.prefix_ns_wrapped_array = prefix_ns_wrapped_array + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def attribute_string(self): """Gets the attribute_string of this XmlItem. # noqa: E501 - :return: The attribute_string of this XmlItem. # noqa: E501 - :rtype: str + Returns: + (str): The attribute_string of this XmlItem. # noqa: E501 """ - return self._attribute_string + return self._data_store.get('attribute_string') @attribute_string.setter - def attribute_string(self, attribute_string): + def attribute_string( + self, attribute_string): """Sets the attribute_string of this XmlItem. - :param attribute_string: The attribute_string of this XmlItem. # noqa: E501 - :type: str + Returns: + (str): The attribute_string of this XmlItem. # noqa: E501 """ - self._attribute_string = attribute_string + self.__setitem__( + 'attribute_string', + attribute_string + ) @property def attribute_number(self): """Gets the attribute_number of this XmlItem. # noqa: E501 - :return: The attribute_number of this XmlItem. # noqa: E501 - :rtype: float + Returns: + (float): The attribute_number of this XmlItem. # noqa: E501 """ - return self._attribute_number + return self._data_store.get('attribute_number') @attribute_number.setter - def attribute_number(self, attribute_number): + def attribute_number( + self, attribute_number): """Sets the attribute_number of this XmlItem. - :param attribute_number: The attribute_number of this XmlItem. # noqa: E501 - :type: float + Returns: + (float): The attribute_number of this XmlItem. # noqa: E501 """ - self._attribute_number = attribute_number + self.__setitem__( + 'attribute_number', + attribute_number + ) @property def attribute_integer(self): """Gets the attribute_integer of this XmlItem. # noqa: E501 - :return: The attribute_integer of this XmlItem. # noqa: E501 - :rtype: int + Returns: + (int): The attribute_integer of this XmlItem. # noqa: E501 """ - return self._attribute_integer + return self._data_store.get('attribute_integer') @attribute_integer.setter - def attribute_integer(self, attribute_integer): + def attribute_integer( + self, attribute_integer): """Sets the attribute_integer of this XmlItem. - :param attribute_integer: The attribute_integer of this XmlItem. # noqa: E501 - :type: int + Returns: + (int): The attribute_integer of this XmlItem. # noqa: E501 """ - self._attribute_integer = attribute_integer + self.__setitem__( + 'attribute_integer', + attribute_integer + ) @property def attribute_boolean(self): """Gets the attribute_boolean of this XmlItem. # noqa: E501 - :return: The attribute_boolean of this XmlItem. # noqa: E501 - :rtype: bool + Returns: + (bool): The attribute_boolean of this XmlItem. # noqa: E501 """ - return self._attribute_boolean + return self._data_store.get('attribute_boolean') @attribute_boolean.setter - def attribute_boolean(self, attribute_boolean): + def attribute_boolean( + self, attribute_boolean): """Sets the attribute_boolean of this XmlItem. - :param attribute_boolean: The attribute_boolean of this XmlItem. # noqa: E501 - :type: bool + Returns: + (bool): The attribute_boolean of this XmlItem. # noqa: E501 """ - self._attribute_boolean = attribute_boolean + self.__setitem__( + 'attribute_boolean', + attribute_boolean + ) @property def wrapped_array(self): """Gets the wrapped_array of this XmlItem. # noqa: E501 - :return: The wrapped_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The wrapped_array of this XmlItem. # noqa: E501 """ - return self._wrapped_array + return self._data_store.get('wrapped_array') @wrapped_array.setter - def wrapped_array(self, wrapped_array): + def wrapped_array( + self, wrapped_array): """Sets the wrapped_array of this XmlItem. - :param wrapped_array: The wrapped_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The wrapped_array of this XmlItem. # noqa: E501 """ - self._wrapped_array = wrapped_array + self.__setitem__( + 'wrapped_array', + wrapped_array + ) @property def name_string(self): """Gets the name_string of this XmlItem. # noqa: E501 - :return: The name_string of this XmlItem. # noqa: E501 - :rtype: str + Returns: + (str): The name_string of this XmlItem. # noqa: E501 """ - return self._name_string + return self._data_store.get('name_string') @name_string.setter - def name_string(self, name_string): + def name_string( + self, name_string): """Sets the name_string of this XmlItem. - :param name_string: The name_string of this XmlItem. # noqa: E501 - :type: str + Returns: + (str): The name_string of this XmlItem. # noqa: E501 """ - self._name_string = name_string + self.__setitem__( + 'name_string', + name_string + ) @property def name_number(self): """Gets the name_number of this XmlItem. # noqa: E501 - :return: The name_number of this XmlItem. # noqa: E501 - :rtype: float + Returns: + (float): The name_number of this XmlItem. # noqa: E501 """ - return self._name_number + return self._data_store.get('name_number') @name_number.setter - def name_number(self, name_number): + def name_number( + self, name_number): """Sets the name_number of this XmlItem. - :param name_number: The name_number of this XmlItem. # noqa: E501 - :type: float + Returns: + (float): The name_number of this XmlItem. # noqa: E501 """ - self._name_number = name_number + self.__setitem__( + 'name_number', + name_number + ) @property def name_integer(self): """Gets the name_integer of this XmlItem. # noqa: E501 - :return: The name_integer of this XmlItem. # noqa: E501 - :rtype: int + Returns: + (int): The name_integer of this XmlItem. # noqa: E501 """ - return self._name_integer + return self._data_store.get('name_integer') @name_integer.setter - def name_integer(self, name_integer): + def name_integer( + self, name_integer): """Sets the name_integer of this XmlItem. - :param name_integer: The name_integer of this XmlItem. # noqa: E501 - :type: int + Returns: + (int): The name_integer of this XmlItem. # noqa: E501 """ - self._name_integer = name_integer + self.__setitem__( + 'name_integer', + name_integer + ) @property def name_boolean(self): """Gets the name_boolean of this XmlItem. # noqa: E501 - :return: The name_boolean of this XmlItem. # noqa: E501 - :rtype: bool + Returns: + (bool): The name_boolean of this XmlItem. # noqa: E501 """ - return self._name_boolean + return self._data_store.get('name_boolean') @name_boolean.setter - def name_boolean(self, name_boolean): + def name_boolean( + self, name_boolean): """Sets the name_boolean of this XmlItem. - :param name_boolean: The name_boolean of this XmlItem. # noqa: E501 - :type: bool + Returns: + (bool): The name_boolean of this XmlItem. # noqa: E501 """ - self._name_boolean = name_boolean + self.__setitem__( + 'name_boolean', + name_boolean + ) @property def name_array(self): """Gets the name_array of this XmlItem. # noqa: E501 - :return: The name_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The name_array of this XmlItem. # noqa: E501 """ - return self._name_array + return self._data_store.get('name_array') @name_array.setter - def name_array(self, name_array): + def name_array( + self, name_array): """Sets the name_array of this XmlItem. - :param name_array: The name_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The name_array of this XmlItem. # noqa: E501 """ - self._name_array = name_array + self.__setitem__( + 'name_array', + name_array + ) @property def name_wrapped_array(self): """Gets the name_wrapped_array of this XmlItem. # noqa: E501 - :return: The name_wrapped_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The name_wrapped_array of this XmlItem. # noqa: E501 """ - return self._name_wrapped_array + return self._data_store.get('name_wrapped_array') @name_wrapped_array.setter - def name_wrapped_array(self, name_wrapped_array): + def name_wrapped_array( + self, name_wrapped_array): """Sets the name_wrapped_array of this XmlItem. - :param name_wrapped_array: The name_wrapped_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The name_wrapped_array of this XmlItem. # noqa: E501 """ - self._name_wrapped_array = name_wrapped_array + self.__setitem__( + 'name_wrapped_array', + name_wrapped_array + ) @property def prefix_string(self): """Gets the prefix_string of this XmlItem. # noqa: E501 - :return: The prefix_string of this XmlItem. # noqa: E501 - :rtype: str + Returns: + (str): The prefix_string of this XmlItem. # noqa: E501 """ - return self._prefix_string + return self._data_store.get('prefix_string') @prefix_string.setter - def prefix_string(self, prefix_string): + def prefix_string( + self, prefix_string): """Sets the prefix_string of this XmlItem. - :param prefix_string: The prefix_string of this XmlItem. # noqa: E501 - :type: str + Returns: + (str): The prefix_string of this XmlItem. # noqa: E501 """ - self._prefix_string = prefix_string + self.__setitem__( + 'prefix_string', + prefix_string + ) @property def prefix_number(self): """Gets the prefix_number of this XmlItem. # noqa: E501 - :return: The prefix_number of this XmlItem. # noqa: E501 - :rtype: float + Returns: + (float): The prefix_number of this XmlItem. # noqa: E501 """ - return self._prefix_number + return self._data_store.get('prefix_number') @prefix_number.setter - def prefix_number(self, prefix_number): + def prefix_number( + self, prefix_number): """Sets the prefix_number of this XmlItem. - :param prefix_number: The prefix_number of this XmlItem. # noqa: E501 - :type: float + Returns: + (float): The prefix_number of this XmlItem. # noqa: E501 """ - self._prefix_number = prefix_number + self.__setitem__( + 'prefix_number', + prefix_number + ) @property def prefix_integer(self): """Gets the prefix_integer of this XmlItem. # noqa: E501 - :return: The prefix_integer of this XmlItem. # noqa: E501 - :rtype: int + Returns: + (int): The prefix_integer of this XmlItem. # noqa: E501 """ - return self._prefix_integer + return self._data_store.get('prefix_integer') @prefix_integer.setter - def prefix_integer(self, prefix_integer): + def prefix_integer( + self, prefix_integer): """Sets the prefix_integer of this XmlItem. - :param prefix_integer: The prefix_integer of this XmlItem. # noqa: E501 - :type: int + Returns: + (int): The prefix_integer of this XmlItem. # noqa: E501 """ - self._prefix_integer = prefix_integer + self.__setitem__( + 'prefix_integer', + prefix_integer + ) @property def prefix_boolean(self): """Gets the prefix_boolean of this XmlItem. # noqa: E501 - :return: The prefix_boolean of this XmlItem. # noqa: E501 - :rtype: bool + Returns: + (bool): The prefix_boolean of this XmlItem. # noqa: E501 """ - return self._prefix_boolean + return self._data_store.get('prefix_boolean') @prefix_boolean.setter - def prefix_boolean(self, prefix_boolean): + def prefix_boolean( + self, prefix_boolean): """Sets the prefix_boolean of this XmlItem. - :param prefix_boolean: The prefix_boolean of this XmlItem. # noqa: E501 - :type: bool + Returns: + (bool): The prefix_boolean of this XmlItem. # noqa: E501 """ - self._prefix_boolean = prefix_boolean + self.__setitem__( + 'prefix_boolean', + prefix_boolean + ) @property def prefix_array(self): """Gets the prefix_array of this XmlItem. # noqa: E501 - :return: The prefix_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The prefix_array of this XmlItem. # noqa: E501 """ - return self._prefix_array + return self._data_store.get('prefix_array') @prefix_array.setter - def prefix_array(self, prefix_array): + def prefix_array( + self, prefix_array): """Sets the prefix_array of this XmlItem. - :param prefix_array: The prefix_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The prefix_array of this XmlItem. # noqa: E501 """ - self._prefix_array = prefix_array + self.__setitem__( + 'prefix_array', + prefix_array + ) @property def prefix_wrapped_array(self): """Gets the prefix_wrapped_array of this XmlItem. # noqa: E501 - :return: The prefix_wrapped_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The prefix_wrapped_array of this XmlItem. # noqa: E501 """ - return self._prefix_wrapped_array + return self._data_store.get('prefix_wrapped_array') @prefix_wrapped_array.setter - def prefix_wrapped_array(self, prefix_wrapped_array): + def prefix_wrapped_array( + self, prefix_wrapped_array): """Sets the prefix_wrapped_array of this XmlItem. - :param prefix_wrapped_array: The prefix_wrapped_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The prefix_wrapped_array of this XmlItem. # noqa: E501 """ - self._prefix_wrapped_array = prefix_wrapped_array + self.__setitem__( + 'prefix_wrapped_array', + prefix_wrapped_array + ) @property def namespace_string(self): """Gets the namespace_string of this XmlItem. # noqa: E501 - :return: The namespace_string of this XmlItem. # noqa: E501 - :rtype: str + Returns: + (str): The namespace_string of this XmlItem. # noqa: E501 """ - return self._namespace_string + return self._data_store.get('namespace_string') @namespace_string.setter - def namespace_string(self, namespace_string): + def namespace_string( + self, namespace_string): """Sets the namespace_string of this XmlItem. - :param namespace_string: The namespace_string of this XmlItem. # noqa: E501 - :type: str + Returns: + (str): The namespace_string of this XmlItem. # noqa: E501 """ - self._namespace_string = namespace_string + self.__setitem__( + 'namespace_string', + namespace_string + ) @property def namespace_number(self): """Gets the namespace_number of this XmlItem. # noqa: E501 - :return: The namespace_number of this XmlItem. # noqa: E501 - :rtype: float + Returns: + (float): The namespace_number of this XmlItem. # noqa: E501 """ - return self._namespace_number + return self._data_store.get('namespace_number') @namespace_number.setter - def namespace_number(self, namespace_number): + def namespace_number( + self, namespace_number): """Sets the namespace_number of this XmlItem. - :param namespace_number: The namespace_number of this XmlItem. # noqa: E501 - :type: float + Returns: + (float): The namespace_number of this XmlItem. # noqa: E501 """ - self._namespace_number = namespace_number + self.__setitem__( + 'namespace_number', + namespace_number + ) @property def namespace_integer(self): """Gets the namespace_integer of this XmlItem. # noqa: E501 - :return: The namespace_integer of this XmlItem. # noqa: E501 - :rtype: int + Returns: + (int): The namespace_integer of this XmlItem. # noqa: E501 """ - return self._namespace_integer + return self._data_store.get('namespace_integer') @namespace_integer.setter - def namespace_integer(self, namespace_integer): + def namespace_integer( + self, namespace_integer): """Sets the namespace_integer of this XmlItem. - :param namespace_integer: The namespace_integer of this XmlItem. # noqa: E501 - :type: int + Returns: + (int): The namespace_integer of this XmlItem. # noqa: E501 """ - self._namespace_integer = namespace_integer + self.__setitem__( + 'namespace_integer', + namespace_integer + ) @property def namespace_boolean(self): """Gets the namespace_boolean of this XmlItem. # noqa: E501 - :return: The namespace_boolean of this XmlItem. # noqa: E501 - :rtype: bool + Returns: + (bool): The namespace_boolean of this XmlItem. # noqa: E501 """ - return self._namespace_boolean + return self._data_store.get('namespace_boolean') @namespace_boolean.setter - def namespace_boolean(self, namespace_boolean): + def namespace_boolean( + self, namespace_boolean): """Sets the namespace_boolean of this XmlItem. - :param namespace_boolean: The namespace_boolean of this XmlItem. # noqa: E501 - :type: bool + Returns: + (bool): The namespace_boolean of this XmlItem. # noqa: E501 """ - self._namespace_boolean = namespace_boolean + self.__setitem__( + 'namespace_boolean', + namespace_boolean + ) @property def namespace_array(self): """Gets the namespace_array of this XmlItem. # noqa: E501 - :return: The namespace_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The namespace_array of this XmlItem. # noqa: E501 """ - return self._namespace_array + return self._data_store.get('namespace_array') @namespace_array.setter - def namespace_array(self, namespace_array): + def namespace_array( + self, namespace_array): """Sets the namespace_array of this XmlItem. - :param namespace_array: The namespace_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The namespace_array of this XmlItem. # noqa: E501 """ - self._namespace_array = namespace_array + self.__setitem__( + 'namespace_array', + namespace_array + ) @property def namespace_wrapped_array(self): """Gets the namespace_wrapped_array of this XmlItem. # noqa: E501 - :return: The namespace_wrapped_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The namespace_wrapped_array of this XmlItem. # noqa: E501 """ - return self._namespace_wrapped_array + return self._data_store.get('namespace_wrapped_array') @namespace_wrapped_array.setter - def namespace_wrapped_array(self, namespace_wrapped_array): + def namespace_wrapped_array( + self, namespace_wrapped_array): """Sets the namespace_wrapped_array of this XmlItem. - :param namespace_wrapped_array: The namespace_wrapped_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The namespace_wrapped_array of this XmlItem. # noqa: E501 """ - self._namespace_wrapped_array = namespace_wrapped_array + self.__setitem__( + 'namespace_wrapped_array', + namespace_wrapped_array + ) @property def prefix_ns_string(self): """Gets the prefix_ns_string of this XmlItem. # noqa: E501 - :return: The prefix_ns_string of this XmlItem. # noqa: E501 - :rtype: str + Returns: + (str): The prefix_ns_string of this XmlItem. # noqa: E501 """ - return self._prefix_ns_string + return self._data_store.get('prefix_ns_string') @prefix_ns_string.setter - def prefix_ns_string(self, prefix_ns_string): + def prefix_ns_string( + self, prefix_ns_string): """Sets the prefix_ns_string of this XmlItem. - :param prefix_ns_string: The prefix_ns_string of this XmlItem. # noqa: E501 - :type: str + Returns: + (str): The prefix_ns_string of this XmlItem. # noqa: E501 """ - self._prefix_ns_string = prefix_ns_string + self.__setitem__( + 'prefix_ns_string', + prefix_ns_string + ) @property def prefix_ns_number(self): """Gets the prefix_ns_number of this XmlItem. # noqa: E501 - :return: The prefix_ns_number of this XmlItem. # noqa: E501 - :rtype: float + Returns: + (float): The prefix_ns_number of this XmlItem. # noqa: E501 """ - return self._prefix_ns_number + return self._data_store.get('prefix_ns_number') @prefix_ns_number.setter - def prefix_ns_number(self, prefix_ns_number): + def prefix_ns_number( + self, prefix_ns_number): """Sets the prefix_ns_number of this XmlItem. - :param prefix_ns_number: The prefix_ns_number of this XmlItem. # noqa: E501 - :type: float + Returns: + (float): The prefix_ns_number of this XmlItem. # noqa: E501 """ - self._prefix_ns_number = prefix_ns_number + self.__setitem__( + 'prefix_ns_number', + prefix_ns_number + ) @property def prefix_ns_integer(self): """Gets the prefix_ns_integer of this XmlItem. # noqa: E501 - :return: The prefix_ns_integer of this XmlItem. # noqa: E501 - :rtype: int + Returns: + (int): The prefix_ns_integer of this XmlItem. # noqa: E501 """ - return self._prefix_ns_integer + return self._data_store.get('prefix_ns_integer') @prefix_ns_integer.setter - def prefix_ns_integer(self, prefix_ns_integer): + def prefix_ns_integer( + self, prefix_ns_integer): """Sets the prefix_ns_integer of this XmlItem. - :param prefix_ns_integer: The prefix_ns_integer of this XmlItem. # noqa: E501 - :type: int + Returns: + (int): The prefix_ns_integer of this XmlItem. # noqa: E501 """ - self._prefix_ns_integer = prefix_ns_integer + self.__setitem__( + 'prefix_ns_integer', + prefix_ns_integer + ) @property def prefix_ns_boolean(self): """Gets the prefix_ns_boolean of this XmlItem. # noqa: E501 - :return: The prefix_ns_boolean of this XmlItem. # noqa: E501 - :rtype: bool + Returns: + (bool): The prefix_ns_boolean of this XmlItem. # noqa: E501 """ - return self._prefix_ns_boolean + return self._data_store.get('prefix_ns_boolean') @prefix_ns_boolean.setter - def prefix_ns_boolean(self, prefix_ns_boolean): + def prefix_ns_boolean( + self, prefix_ns_boolean): """Sets the prefix_ns_boolean of this XmlItem. - :param prefix_ns_boolean: The prefix_ns_boolean of this XmlItem. # noqa: E501 - :type: bool + Returns: + (bool): The prefix_ns_boolean of this XmlItem. # noqa: E501 """ - self._prefix_ns_boolean = prefix_ns_boolean + self.__setitem__( + 'prefix_ns_boolean', + prefix_ns_boolean + ) @property def prefix_ns_array(self): """Gets the prefix_ns_array of this XmlItem. # noqa: E501 - :return: The prefix_ns_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The prefix_ns_array of this XmlItem. # noqa: E501 """ - return self._prefix_ns_array + return self._data_store.get('prefix_ns_array') @prefix_ns_array.setter - def prefix_ns_array(self, prefix_ns_array): + def prefix_ns_array( + self, prefix_ns_array): """Sets the prefix_ns_array of this XmlItem. - :param prefix_ns_array: The prefix_ns_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The prefix_ns_array of this XmlItem. # noqa: E501 """ - self._prefix_ns_array = prefix_ns_array + self.__setitem__( + 'prefix_ns_array', + prefix_ns_array + ) @property def prefix_ns_wrapped_array(self): """Gets the prefix_ns_wrapped_array of this XmlItem. # noqa: E501 - :return: The prefix_ns_wrapped_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The prefix_ns_wrapped_array of this XmlItem. # noqa: E501 """ - return self._prefix_ns_wrapped_array + return self._data_store.get('prefix_ns_wrapped_array') @prefix_ns_wrapped_array.setter - def prefix_ns_wrapped_array(self, prefix_ns_wrapped_array): + def prefix_ns_wrapped_array( + self, prefix_ns_wrapped_array): """Sets the prefix_ns_wrapped_array of this XmlItem. - :param prefix_ns_wrapped_array: The prefix_ns_wrapped_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The prefix_ns_wrapped_array of this XmlItem. # noqa: E501 """ - self._prefix_ns_wrapped_array = prefix_ns_wrapped_array + self.__setitem__( + 'prefix_ns_wrapped_array', + prefix_ns_wrapped_array + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python-tornado/petstore_api/rest.py b/samples/client/petstore/python-tornado/petstore_api/rest.py index e65cc9975e33..936ea64d1cda 100644 --- a/samples/client/petstore/python-tornado/petstore_api/rest.py +++ b/samples/client/petstore/python-tornado/petstore_api/rest.py @@ -23,6 +23,8 @@ from tornado import httpclient from urllib3.filepost import encode_multipart_formdata +from petstore_api.exceptions import ApiException, ApiValueError + logger = logging.getLogger(__name__) @@ -95,7 +97,7 @@ def request(self, method, url, query_params=None, headers=None, body=None, 'PATCH', 'OPTIONS'] if post_params and body: - raise ValueError( + raise ApiValueError( "body parameter cannot be used with post_params parameter." ) @@ -233,31 +235,3 @@ def PATCH(self, url, headers=None, query_params=None, post_params=None, _request_timeout=_request_timeout, body=body) raise tornado.gen.Return(result) - - -class ApiException(Exception): - - 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})\nReason: {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 diff --git a/samples/client/petstore/python-tornado/requirements.txt b/samples/client/petstore/python-tornado/requirements.txt index bafdc07532f5..2e252c8a0833 100644 --- a/samples/client/petstore/python-tornado/requirements.txt +++ b/samples/client/petstore/python-tornado/requirements.txt @@ -1,5 +1,6 @@ certifi >= 14.05.14 -six >= 1.10 +future; python_version<="2.7" python_dateutil >= 2.5.3 setuptools >= 21.0.0 +six >= 1.10 urllib3 >= 1.15.1 diff --git a/samples/client/petstore/python-tornado/setup.py b/samples/client/petstore/python-tornado/setup.py index c55611d5d2fe..64911687b4ec 100644 --- a/samples/client/petstore/python-tornado/setup.py +++ b/samples/client/petstore/python-tornado/setup.py @@ -32,6 +32,11 @@ url="", keywords=["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"], install_requires=REQUIRES, + extras_require={ + ':python_version <= "2.7"': [ + 'future', + ], + }, packages=find_packages(), include_package_data=True, long_description="""\ diff --git a/samples/client/petstore/python-tornado/test/test_additional_properties_any_type.py b/samples/client/petstore/python-tornado/test/test_additional_properties_any_type.py new file mode 100644 index 000000000000..4b6739a1faf3 --- /dev/null +++ b/samples/client/petstore/python-tornado/test/test_additional_properties_any_type.py @@ -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.additional_properties_any_type import AdditionalPropertiesAnyType # noqa: E501 +from petstore_api.rest import ApiException + + +class TestAdditionalPropertiesAnyType(unittest.TestCase): + """AdditionalPropertiesAnyType unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testAdditionalPropertiesAnyType(self): + """Test AdditionalPropertiesAnyType""" + # FIXME: construct object with mandatory attributes with example values + # model = petstore_api.models.additional_properties_any_type.AdditionalPropertiesAnyType() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python-tornado/test/test_additional_properties_array.py b/samples/client/petstore/python-tornado/test/test_additional_properties_array.py new file mode 100644 index 000000000000..c4cf43499cfa --- /dev/null +++ b/samples/client/petstore/python-tornado/test/test_additional_properties_array.py @@ -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.additional_properties_array import AdditionalPropertiesArray # noqa: E501 +from petstore_api.rest import ApiException + + +class TestAdditionalPropertiesArray(unittest.TestCase): + """AdditionalPropertiesArray unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testAdditionalPropertiesArray(self): + """Test AdditionalPropertiesArray""" + # FIXME: construct object with mandatory attributes with example values + # model = petstore_api.models.additional_properties_array.AdditionalPropertiesArray() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python-tornado/test/test_additional_properties_boolean.py b/samples/client/petstore/python-tornado/test/test_additional_properties_boolean.py new file mode 100644 index 000000000000..cc3cecc8522f --- /dev/null +++ b/samples/client/petstore/python-tornado/test/test_additional_properties_boolean.py @@ -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.additional_properties_boolean import AdditionalPropertiesBoolean # noqa: E501 +from petstore_api.rest import ApiException + + +class TestAdditionalPropertiesBoolean(unittest.TestCase): + """AdditionalPropertiesBoolean unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testAdditionalPropertiesBoolean(self): + """Test AdditionalPropertiesBoolean""" + # FIXME: construct object with mandatory attributes with example values + # model = petstore_api.models.additional_properties_boolean.AdditionalPropertiesBoolean() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python-tornado/test/test_additional_properties_integer.py b/samples/client/petstore/python-tornado/test/test_additional_properties_integer.py new file mode 100644 index 000000000000..774c367b2109 --- /dev/null +++ b/samples/client/petstore/python-tornado/test/test_additional_properties_integer.py @@ -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.additional_properties_integer import AdditionalPropertiesInteger # noqa: E501 +from petstore_api.rest import ApiException + + +class TestAdditionalPropertiesInteger(unittest.TestCase): + """AdditionalPropertiesInteger unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testAdditionalPropertiesInteger(self): + """Test AdditionalPropertiesInteger""" + # FIXME: construct object with mandatory attributes with example values + # model = petstore_api.models.additional_properties_integer.AdditionalPropertiesInteger() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python-tornado/test/test_additional_properties_number.py b/samples/client/petstore/python-tornado/test/test_additional_properties_number.py new file mode 100644 index 000000000000..0d370e781b36 --- /dev/null +++ b/samples/client/petstore/python-tornado/test/test_additional_properties_number.py @@ -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.additional_properties_number import AdditionalPropertiesNumber # noqa: E501 +from petstore_api.rest import ApiException + + +class TestAdditionalPropertiesNumber(unittest.TestCase): + """AdditionalPropertiesNumber unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testAdditionalPropertiesNumber(self): + """Test AdditionalPropertiesNumber""" + # FIXME: construct object with mandatory attributes with example values + # model = petstore_api.models.additional_properties_number.AdditionalPropertiesNumber() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python-tornado/test/test_additional_properties_object.py b/samples/client/petstore/python-tornado/test/test_additional_properties_object.py new file mode 100644 index 000000000000..6e718b28cdef --- /dev/null +++ b/samples/client/petstore/python-tornado/test/test_additional_properties_object.py @@ -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.additional_properties_object import AdditionalPropertiesObject # noqa: E501 +from petstore_api.rest import ApiException + + +class TestAdditionalPropertiesObject(unittest.TestCase): + """AdditionalPropertiesObject unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testAdditionalPropertiesObject(self): + """Test AdditionalPropertiesObject""" + # FIXME: construct object with mandatory attributes with example values + # model = petstore_api.models.additional_properties_object.AdditionalPropertiesObject() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python-tornado/test/test_additional_properties_string.py b/samples/client/petstore/python-tornado/test/test_additional_properties_string.py new file mode 100644 index 000000000000..a46cb3e256dc --- /dev/null +++ b/samples/client/petstore/python-tornado/test/test_additional_properties_string.py @@ -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.additional_properties_string import AdditionalPropertiesString # noqa: E501 +from petstore_api.rest import ApiException + + +class TestAdditionalPropertiesString(unittest.TestCase): + """AdditionalPropertiesString unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testAdditionalPropertiesString(self): + """Test AdditionalPropertiesString""" + # FIXME: construct object with mandatory attributes with example values + # model = petstore_api.models.additional_properties_string.AdditionalPropertiesString() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python/README.md b/samples/client/petstore/python/README.md index 4c67e17b44c8..ce1fcee98043 100644 --- a/samples/client/petstore/python/README.md +++ b/samples/client/petstore/python/README.md @@ -111,7 +111,14 @@ Class | Method | HTTP request | Description ## Documentation For Models + - [AdditionalPropertiesAnyType](docs/AdditionalPropertiesAnyType.md) + - [AdditionalPropertiesArray](docs/AdditionalPropertiesArray.md) + - [AdditionalPropertiesBoolean](docs/AdditionalPropertiesBoolean.md) - [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md) + - [AdditionalPropertiesInteger](docs/AdditionalPropertiesInteger.md) + - [AdditionalPropertiesNumber](docs/AdditionalPropertiesNumber.md) + - [AdditionalPropertiesObject](docs/AdditionalPropertiesObject.md) + - [AdditionalPropertiesString](docs/AdditionalPropertiesString.md) - [Animal](docs/Animal.md) - [ApiResponse](docs/ApiResponse.md) - [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md) diff --git a/samples/client/petstore/python/docs/AdditionalPropertiesAnyType.md b/samples/client/petstore/python/docs/AdditionalPropertiesAnyType.md new file mode 100644 index 000000000000..9843d35ab906 --- /dev/null +++ b/samples/client/petstore/python/docs/AdditionalPropertiesAnyType.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesAnyType + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/docs/AdditionalPropertiesArray.md b/samples/client/petstore/python/docs/AdditionalPropertiesArray.md new file mode 100644 index 000000000000..cfe09d91c726 --- /dev/null +++ b/samples/client/petstore/python/docs/AdditionalPropertiesArray.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesArray + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/docs/AdditionalPropertiesBoolean.md b/samples/client/petstore/python/docs/AdditionalPropertiesBoolean.md new file mode 100644 index 000000000000..74f009554a7f --- /dev/null +++ b/samples/client/petstore/python/docs/AdditionalPropertiesBoolean.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesBoolean + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/docs/AdditionalPropertiesClass.md b/samples/client/petstore/python/docs/AdditionalPropertiesClass.md index 796a789d4c4b..56326055a412 100644 --- a/samples/client/petstore/python/docs/AdditionalPropertiesClass.md +++ b/samples/client/petstore/python/docs/AdditionalPropertiesClass.md @@ -3,8 +3,17 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**map_property** | **dict(str, str)** | | [optional] -**map_of_map_property** | **dict(str, dict(str, str))** | | [optional] +**map_string** | **{str: (str,)}** | | [optional] +**map_number** | **{str: (float,)}** | | [optional] +**map_integer** | **{str: (int,)}** | | [optional] +**map_boolean** | **{str: (bool,)}** | | [optional] +**map_array_integer** | **{str: ([(int,)],)}** | | [optional] +**map_array_anytype** | **{str: ([(bool, date, datetime, dict, float, int, list, str)],)}** | | [optional] +**map_map_string** | **{str: ({str: (str,)},)}** | | [optional] +**map_map_anytype** | **{str: ({str: (bool, date, datetime, dict, float, int, list, str)},)}** | | [optional] +**anytype_1** | [**bool, date, datetime, dict, float, int, list, str**](.md) | | [optional] +**anytype_2** | [**bool, date, datetime, dict, float, int, list, str**](.md) | | [optional] +**anytype_3** | [**bool, date, datetime, dict, float, int, list, str**](.md) | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python/docs/AdditionalPropertiesInteger.md b/samples/client/petstore/python/docs/AdditionalPropertiesInteger.md new file mode 100644 index 000000000000..a3e58fd1b0bd --- /dev/null +++ b/samples/client/petstore/python/docs/AdditionalPropertiesInteger.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesInteger + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/docs/AdditionalPropertiesNumber.md b/samples/client/petstore/python/docs/AdditionalPropertiesNumber.md new file mode 100644 index 000000000000..37eafe1ff031 --- /dev/null +++ b/samples/client/petstore/python/docs/AdditionalPropertiesNumber.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesNumber + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/docs/AdditionalPropertiesObject.md b/samples/client/petstore/python/docs/AdditionalPropertiesObject.md new file mode 100644 index 000000000000..7f4d6713c758 --- /dev/null +++ b/samples/client/petstore/python/docs/AdditionalPropertiesObject.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesObject + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/docs/AdditionalPropertiesString.md b/samples/client/petstore/python/docs/AdditionalPropertiesString.md new file mode 100644 index 000000000000..9317cfeee80b --- /dev/null +++ b/samples/client/petstore/python/docs/AdditionalPropertiesString.md @@ -0,0 +1,10 @@ +# AdditionalPropertiesString + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**name** | **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/docs/ArrayOfArrayOfNumberOnly.md b/samples/client/petstore/python/docs/ArrayOfArrayOfNumberOnly.md index aa3988ab1679..323b6edc56b9 100644 --- a/samples/client/petstore/python/docs/ArrayOfArrayOfNumberOnly.md +++ b/samples/client/petstore/python/docs/ArrayOfArrayOfNumberOnly.md @@ -3,7 +3,7 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**array_array_number** | **list[list[float]]** | | [optional] +**array_array_number** | **[([(float,)],)]** | | [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/ArrayOfNumberOnly.md b/samples/client/petstore/python/docs/ArrayOfNumberOnly.md index 2c3de967aec6..502d335fcfc3 100644 --- a/samples/client/petstore/python/docs/ArrayOfNumberOnly.md +++ b/samples/client/petstore/python/docs/ArrayOfNumberOnly.md @@ -3,7 +3,7 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**array_number** | **list[float]** | | [optional] +**array_number** | **[(float,)]** | | [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/ArrayTest.md b/samples/client/petstore/python/docs/ArrayTest.md index 6ab0d1378065..d3a915da27c1 100644 --- a/samples/client/petstore/python/docs/ArrayTest.md +++ b/samples/client/petstore/python/docs/ArrayTest.md @@ -3,9 +3,9 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**array_of_string** | **list[str]** | | [optional] -**array_array_of_integer** | **list[list[int]]** | | [optional] -**array_array_of_model** | **list[list[ReadOnlyFirst]]** | | [optional] +**array_of_string** | **[(str,)]** | | [optional] +**array_array_of_integer** | **[([(int,)],)]** | | [optional] +**array_array_of_model** | **[([(ReadOnlyFirst,)],)]** | | [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/Cat.md b/samples/client/petstore/python/docs/Cat.md index 8d30565d014e..d052c5615b84 100644 --- a/samples/client/petstore/python/docs/Cat.md +++ b/samples/client/petstore/python/docs/Cat.md @@ -3,6 +3,8 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**class_name** | **str** | | +**color** | **str** | | [optional] [default to 'red'] **declawed** | **bool** | | [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/Dog.md b/samples/client/petstore/python/docs/Dog.md index f727487975c4..ac70f17e668a 100644 --- a/samples/client/petstore/python/docs/Dog.md +++ b/samples/client/petstore/python/docs/Dog.md @@ -3,6 +3,8 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**class_name** | **str** | | +**color** | **str** | | [optional] [default to 'red'] **breed** | **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/docs/EnumArrays.md b/samples/client/petstore/python/docs/EnumArrays.md index e15a5f1fd049..4a87d6a62ea2 100644 --- a/samples/client/petstore/python/docs/EnumArrays.md +++ b/samples/client/petstore/python/docs/EnumArrays.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **just_symbol** | **str** | | [optional] -**array_enum** | **list[str]** | | [optional] +**array_enum** | **[(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/docs/FakeApi.md b/samples/client/petstore/python/docs/FakeApi.md index c46bf1e49748..2a72ffe650da 100644 --- a/samples/client/petstore/python/docs/FakeApi.md +++ b/samples/client/petstore/python/docs/FakeApi.md @@ -434,7 +434,7 @@ int32 = 56 # int | None (optional) int64 = 56 # int | None (optional) float = 3.4 # float | None (optional) string = 'string_example' # str | None (optional) -binary = '/path/to/file' # file | None (optional) +binary = '/path/to/file' # file_type | None (optional) date = '2013-10-20' # date | None (optional) date_time = '2013-10-20T19:20:30+01:00' # datetime | None (optional) password = 'password_example' # str | None (optional) @@ -460,7 +460,7 @@ Name | Type | Description | Notes **int64** | **int**| None | [optional] **float** | **float**| None | [optional] **string** | **str**| None | [optional] - **binary** | **file**| None | [optional] + **binary** | **file_type**| None | [optional] **date** | **date**| None | [optional] **date_time** | **datetime**| None | [optional] **password** | **str**| None | [optional] @@ -499,13 +499,13 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.FakeApi() -enum_header_string_array = ['enum_header_string_array_example'] # list[str] | Header parameter enum test (string array) (optional) +enum_header_string_array = ['enum_header_string_array_example'] # [(str,)] | Header parameter enum test (string array) (optional) enum_header_string = '-efg' # str | Header parameter enum test (string) (optional) (default to '-efg') -enum_query_string_array = ['enum_query_string_array_example'] # list[str] | Query parameter enum test (string array) (optional) +enum_query_string_array = ['enum_query_string_array_example'] # [(str,)] | Query parameter enum test (string array) (optional) enum_query_string = '-efg' # str | Query parameter enum test (string) (optional) (default to '-efg') enum_query_integer = 56 # int | Query parameter enum test (double) (optional) enum_query_double = 3.4 # float | Query parameter enum test (double) (optional) -enum_form_string_array = '$' # list[str] | Form parameter enum test (string array) (optional) (default to '$') +enum_form_string_array = '$' # [(str,)] | Form parameter enum test (string array) (optional) (default to '$') enum_form_string = '-efg' # str | Form parameter enum test (string) (optional) (default to '-efg') try: @@ -519,13 +519,13 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **enum_header_string_array** | [**list[str]**](str.md)| Header parameter enum test (string array) | [optional] + **enum_header_string_array** | [**[(str,)]**](str.md)| Header parameter enum test (string array) | [optional] **enum_header_string** | **str**| Header parameter enum test (string) | [optional] [default to '-efg'] - **enum_query_string_array** | [**list[str]**](str.md)| Query parameter enum test (string array) | [optional] + **enum_query_string_array** | [**[(str,)]**](str.md)| Query parameter enum test (string array) | [optional] **enum_query_string** | **str**| Query parameter enum test (string) | [optional] [default to '-efg'] **enum_query_integer** | **int**| Query parameter enum test (double) | [optional] **enum_query_double** | **float**| Query parameter enum test (double) | [optional] - **enum_form_string_array** | [**list[str]**](str.md)| Form parameter enum test (string array) | [optional] [default to '$'] + **enum_form_string_array** | [**[(str,)]**](str.md)| Form parameter enum test (string array) | [optional] [default to '$'] **enum_form_string** | **str**| Form parameter enum test (string) | [optional] [default to '-efg'] ### Return type @@ -617,7 +617,7 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.FakeApi() -param = {'key': 'param_example'} # dict(str, str) | request body +param = {'key': 'param_example'} # {str: (str,)} | request body try: # test inline additionalProperties @@ -630,7 +630,7 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **param** | [**dict(str, str)**](str.md)| request body | + **param** | [**{str: (str,)}**](str.md)| request body | ### Return type diff --git a/samples/client/petstore/python/docs/FileSchemaTestClass.md b/samples/client/petstore/python/docs/FileSchemaTestClass.md index dc3722289887..73009bdb1bfb 100644 --- a/samples/client/petstore/python/docs/FileSchemaTestClass.md +++ b/samples/client/petstore/python/docs/FileSchemaTestClass.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **file** | [**File**](File.md) | | [optional] -**files** | [**list[File]**](File.md) | | [optional] +**files** | [**[(File,)]**](File.md) | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python/docs/FormatTest.md b/samples/client/petstore/python/docs/FormatTest.md index 31d92e2a750e..5431d4e7169b 100644 --- a/samples/client/petstore/python/docs/FormatTest.md +++ b/samples/client/petstore/python/docs/FormatTest.md @@ -11,7 +11,7 @@ Name | Type | Description | Notes **double** | **float** | | [optional] **string** | **str** | | [optional] **byte** | **str** | | -**binary** | **file** | | [optional] +**binary** | **file_type** | | [optional] **date** | **date** | | **date_time** | **datetime** | | [optional] **uuid** | **str** | | [optional] diff --git a/samples/client/petstore/python/docs/MapTest.md b/samples/client/petstore/python/docs/MapTest.md index a5601691f885..c88c578cf82e 100644 --- a/samples/client/petstore/python/docs/MapTest.md +++ b/samples/client/petstore/python/docs/MapTest.md @@ -3,10 +3,10 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**map_map_of_string** | **dict(str, dict(str, str))** | | [optional] -**map_of_enum_string** | **dict(str, str)** | | [optional] -**direct_map** | **dict(str, bool)** | | [optional] -**indirect_map** | **dict(str, bool)** | | [optional] +**map_map_of_string** | **{str: ({str: (str,)},)}** | | [optional] +**map_of_enum_string** | **{str: (str,)}** | | [optional] +**direct_map** | **{str: (bool,)}** | | [optional] +**indirect_map** | **{str: (bool,)}** | | [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/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/client/petstore/python/docs/MixedPropertiesAndAdditionalPropertiesClass.md index b9808d5275e5..1484c0638d83 100644 --- a/samples/client/petstore/python/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/client/petstore/python/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -5,7 +5,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **uuid** | **str** | | [optional] **date_time** | **datetime** | | [optional] -**map** | [**dict(str, Animal)**](Animal.md) | | [optional] +**map** | [**{str: (Animal,)}**](Animal.md) | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python/docs/Pet.md b/samples/client/petstore/python/docs/Pet.md index 9e15090300f8..745d5da843e7 100644 --- a/samples/client/petstore/python/docs/Pet.md +++ b/samples/client/petstore/python/docs/Pet.md @@ -6,8 +6,8 @@ Name | Type | Description | Notes **id** | **int** | | [optional] **category** | [**Category**](Category.md) | | [optional] **name** | **str** | | -**photo_urls** | **list[str]** | | -**tags** | [**list[Tag]**](Tag.md) | | [optional] +**photo_urls** | **[(str,)]** | | +**tags** | [**[(Tag,)]**](Tag.md) | | [optional] **status** | **str** | pet status in the store | [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/PetApi.md b/samples/client/petstore/python/docs/PetApi.md index 227fa2ada134..07d1016f42bb 100644 --- a/samples/client/petstore/python/docs/PetApi.md +++ b/samples/client/petstore/python/docs/PetApi.md @@ -118,7 +118,7 @@ void (empty response body) [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **find_pets_by_status** -> list[Pet] find_pets_by_status(status) +> [(Pet,)] find_pets_by_status(status) Finds Pets by status @@ -139,7 +139,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN' # create an instance of the API class api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration)) -status = ['status_example'] # list[str] | Status values that need to be considered for filter +status = ['status_example'] # [(str,)] | Status values that need to be considered for filter try: # Finds Pets by status @@ -153,11 +153,11 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **status** | [**list[str]**](str.md)| Status values that need to be considered for filter | + **status** | [**[(str,)]**](str.md)| Status values that need to be considered for filter | ### Return type -[**list[Pet]**](Pet.md) +[**[(Pet,)]**](Pet.md) ### Authorization @@ -171,7 +171,7 @@ Name | Type | Description | Notes [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **find_pets_by_tags** -> list[Pet] find_pets_by_tags(tags) +> [(Pet,)] find_pets_by_tags(tags) Finds Pets by tags @@ -192,7 +192,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN' # create an instance of the API class api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration)) -tags = ['tags_example'] # list[str] | Tags to filter by +tags = ['tags_example'] # [(str,)] | Tags to filter by try: # Finds Pets by tags @@ -206,11 +206,11 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **tags** | [**list[str]**](str.md)| Tags to filter by | + **tags** | [**[(str,)]**](str.md)| Tags to filter by | ### Return type -[**list[Pet]**](Pet.md) +[**[(Pet,)]**](Pet.md) ### Authorization @@ -404,7 +404,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN' api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration)) pet_id = 56 # int | ID of pet to update additional_metadata = 'additional_metadata_example' # str | Additional data to pass to server (optional) -file = '/path/to/file' # file | file to upload (optional) +file = '/path/to/file' # file_type | file to upload (optional) try: # uploads an image @@ -420,7 +420,7 @@ Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **pet_id** | **int**| ID of pet to update | **additional_metadata** | **str**| Additional data to pass to server | [optional] - **file** | **file**| file to upload | [optional] + **file** | **file_type**| file to upload | [optional] ### Return type @@ -458,7 +458,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN' # create an instance of the API class api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration)) pet_id = 56 # int | ID of pet to update -required_file = '/path/to/file' # file | file to upload +required_file = '/path/to/file' # file_type | file to upload additional_metadata = 'additional_metadata_example' # str | Additional data to pass to server (optional) try: @@ -474,7 +474,7 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **pet_id** | **int**| ID of pet to update | - **required_file** | **file**| file to upload | + **required_file** | **file_type**| file to upload | **additional_metadata** | **str**| Additional data to pass to server | [optional] ### Return type diff --git a/samples/client/petstore/python/docs/StoreApi.md b/samples/client/petstore/python/docs/StoreApi.md index af190f931d2e..ce0ef54222f1 100644 --- a/samples/client/petstore/python/docs/StoreApi.md +++ b/samples/client/petstore/python/docs/StoreApi.md @@ -59,7 +59,7 @@ No authorization required [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **get_inventory** -> dict(str, int) get_inventory() +> {str: (int,)} get_inventory() Returns pet inventories by status @@ -96,7 +96,7 @@ This endpoint does not need any parameter. ### Return type -**dict(str, int)** +**{str: (int,)}** ### Authorization diff --git a/samples/client/petstore/python/docs/TypeHolderDefault.md b/samples/client/petstore/python/docs/TypeHolderDefault.md index 861da021826a..3a6ba43b37c7 100644 --- a/samples/client/petstore/python/docs/TypeHolderDefault.md +++ b/samples/client/petstore/python/docs/TypeHolderDefault.md @@ -7,7 +7,7 @@ Name | Type | Description | Notes **number_item** | **float** | | **integer_item** | **int** | | **bool_item** | **bool** | | [default to True] -**array_item** | **list[int]** | | +**array_item** | **[(int,)]** | | [[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/TypeHolderExample.md b/samples/client/petstore/python/docs/TypeHolderExample.md index d59718cdcb16..0daefd05c50e 100644 --- a/samples/client/petstore/python/docs/TypeHolderExample.md +++ b/samples/client/petstore/python/docs/TypeHolderExample.md @@ -7,7 +7,7 @@ Name | Type | Description | Notes **number_item** | **float** | | **integer_item** | **int** | | **bool_item** | **bool** | | -**array_item** | **list[int]** | | +**array_item** | **[(int,)]** | | [[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/UserApi.md b/samples/client/petstore/python/docs/UserApi.md index 33e86f9e8fd2..2e27cf02301d 100644 --- a/samples/client/petstore/python/docs/UserApi.md +++ b/samples/client/petstore/python/docs/UserApi.md @@ -78,7 +78,7 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.UserApi() -body = NULL # list[User] | List of user object +body = NULL # [(User,)] | List of user object try: # Creates list of users with given input array @@ -91,7 +91,7 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **body** | [**list[User]**](list.md)| List of user object | + **body** | [**[(User,)]**](list.md)| List of user object | ### Return type @@ -124,7 +124,7 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.UserApi() -body = NULL # list[User] | List of user object +body = NULL # [(User,)] | List of user object try: # Creates list of users with given input array @@ -137,7 +137,7 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **body** | [**list[User]**](list.md)| List of user object | + **body** | [**[(User,)]**](list.md)| List of user object | ### Return type diff --git a/samples/client/petstore/python/docs/XmlItem.md b/samples/client/petstore/python/docs/XmlItem.md index 3dd09833fe52..185da1eb0119 100644 --- a/samples/client/petstore/python/docs/XmlItem.md +++ b/samples/client/petstore/python/docs/XmlItem.md @@ -7,31 +7,31 @@ Name | Type | Description | Notes **attribute_number** | **float** | | [optional] **attribute_integer** | **int** | | [optional] **attribute_boolean** | **bool** | | [optional] -**wrapped_array** | **list[int]** | | [optional] +**wrapped_array** | **[(int,)]** | | [optional] **name_string** | **str** | | [optional] **name_number** | **float** | | [optional] **name_integer** | **int** | | [optional] **name_boolean** | **bool** | | [optional] -**name_array** | **list[int]** | | [optional] -**name_wrapped_array** | **list[int]** | | [optional] +**name_array** | **[(int,)]** | | [optional] +**name_wrapped_array** | **[(int,)]** | | [optional] **prefix_string** | **str** | | [optional] **prefix_number** | **float** | | [optional] **prefix_integer** | **int** | | [optional] **prefix_boolean** | **bool** | | [optional] -**prefix_array** | **list[int]** | | [optional] -**prefix_wrapped_array** | **list[int]** | | [optional] +**prefix_array** | **[(int,)]** | | [optional] +**prefix_wrapped_array** | **[(int,)]** | | [optional] **namespace_string** | **str** | | [optional] **namespace_number** | **float** | | [optional] **namespace_integer** | **int** | | [optional] **namespace_boolean** | **bool** | | [optional] -**namespace_array** | **list[int]** | | [optional] -**namespace_wrapped_array** | **list[int]** | | [optional] +**namespace_array** | **[(int,)]** | | [optional] +**namespace_wrapped_array** | **[(int,)]** | | [optional] **prefix_ns_string** | **str** | | [optional] **prefix_ns_number** | **float** | | [optional] **prefix_ns_integer** | **int** | | [optional] **prefix_ns_boolean** | **bool** | | [optional] -**prefix_ns_array** | **list[int]** | | [optional] -**prefix_ns_wrapped_array** | **list[int]** | | [optional] +**prefix_ns_array** | **[(int,)]** | | [optional] +**prefix_ns_wrapped_array** | **[(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/petstore_api/__init__.py b/samples/client/petstore/python/petstore_api/__init__.py index cf9b1b0db3f9..516f759d02c3 100644 --- a/samples/client/petstore/python/petstore_api/__init__.py +++ b/samples/client/petstore/python/petstore_api/__init__.py @@ -28,7 +28,14 @@ from petstore_api.api_client import ApiClient from petstore_api.configuration import Configuration # import models into sdk package +from petstore_api.models.additional_properties_any_type import AdditionalPropertiesAnyType +from petstore_api.models.additional_properties_array import AdditionalPropertiesArray +from petstore_api.models.additional_properties_boolean import AdditionalPropertiesBoolean from petstore_api.models.additional_properties_class import AdditionalPropertiesClass +from petstore_api.models.additional_properties_integer import AdditionalPropertiesInteger +from petstore_api.models.additional_properties_number import AdditionalPropertiesNumber +from petstore_api.models.additional_properties_object import AdditionalPropertiesObject +from petstore_api.models.additional_properties_string import AdditionalPropertiesString from petstore_api.models.animal import Animal from petstore_api.models.api_response import ApiResponse from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly diff --git a/samples/client/petstore/python/petstore_api/api/another_fake_api.py b/samples/client/petstore/python/petstore_api/api/another_fake_api.py index 9fd3f816b9ca..058210d0bd4d 100644 --- a/samples/client/petstore/python/petstore_api/api/another_fake_api.py +++ b/samples/client/petstore/python/petstore_api/api/another_fake_api.py @@ -18,6 +18,20 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.client import Client class AnotherFakeApi(object): @@ -32,7 +46,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def call_123_test_special_tags(self, body, **kwargs): # noqa: E501 + def call_123_test_special_tags(self, body, _check_type=False, **kwargs): # noqa: E501 """To test special tags # noqa: E501 To test special tags and operation ID starting with number # noqa: E501 @@ -49,12 +63,12 @@ def call_123_test_special_tags(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.call_123_test_special_tags_with_http_info(body, **kwargs) # noqa: E501 + return self.call_123_test_special_tags_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.call_123_test_special_tags_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.call_123_test_special_tags_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E501 + def call_123_test_special_tags_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """To test special tags # noqa: E501 To test special tags and operation ID starting with number # noqa: E501 @@ -80,16 +94,26 @@ def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E5 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method call_123_test_special_tags" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [Client], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `call_123_test_special_tags`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `call_123_test_special_tags`") # noqa: E501 collection_formats = {} @@ -124,7 +148,7 @@ def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E5 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types_mixed=[Client], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python/petstore_api/api/fake_api.py b/samples/client/petstore/python/petstore_api/api/fake_api.py index c7405e51c381..9c4355a95c35 100644 --- a/samples/client/petstore/python/petstore_api/api/fake_api.py +++ b/samples/client/petstore/python/petstore_api/api/fake_api.py @@ -18,6 +18,24 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.client import Client +from petstore_api.models.file_schema_test_class import FileSchemaTestClass +from petstore_api.models.outer_composite import OuterComposite +from petstore_api.models.user import User +from petstore_api.models.xml_item import XmlItem class FakeApi(object): @@ -32,7 +50,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def create_xml_item(self, xml_item, **kwargs): # noqa: E501 + def create_xml_item(self, xml_item, _check_type=False, **kwargs): # noqa: E501 """creates an XmlItem # noqa: E501 this route creates an XmlItem # noqa: E501 @@ -49,12 +67,12 @@ def create_xml_item(self, xml_item, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.create_xml_item_with_http_info(xml_item, **kwargs) # noqa: E501 + return self.create_xml_item_with_http_info(xml_item, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.create_xml_item_with_http_info(xml_item, **kwargs) # noqa: E501 + (data) = self.create_xml_item_with_http_info(xml_item, _check_type=_check_type, **kwargs) # noqa: E501 return data - def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501 + def create_xml_item_with_http_info(self, xml_item, _check_type=False, **kwargs): # noqa: E501 """creates an XmlItem # noqa: E501 this route creates an XmlItem # noqa: E501 @@ -80,16 +98,26 @@ def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method create_xml_item" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'xml_item': [XmlItem], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'xml_item' is set if ('xml_item' not in local_var_params or local_var_params['xml_item'] is None): - raise ValueError("Missing the required parameter `xml_item` when calling `create_xml_item`") # noqa: E501 + raise ApiValueError("Missing the required parameter `xml_item` when calling `create_xml_item`") # noqa: E501 collection_formats = {} @@ -120,7 +148,7 @@ def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -128,7 +156,7 @@ def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def fake_outer_boolean_serialize(self, **kwargs): # noqa: E501 + def fake_outer_boolean_serialize(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_boolean_serialize # noqa: E501 Test serialization of outer boolean types # noqa: E501 @@ -145,12 +173,12 @@ def fake_outer_boolean_serialize(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.fake_outer_boolean_serialize_with_http_info(**kwargs) # noqa: E501 + return self.fake_outer_boolean_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.fake_outer_boolean_serialize_with_http_info(**kwargs) # noqa: E501 + (data) = self.fake_outer_boolean_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 + def fake_outer_boolean_serialize_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_boolean_serialize # noqa: E501 Test serialization of outer boolean types # noqa: E501 @@ -176,12 +204,22 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method fake_outer_boolean_serialize" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [bool], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) collection_formats = {} @@ -212,7 +250,7 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='bool', # noqa: E501 + response_types_mixed=[bool], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -220,7 +258,7 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def fake_outer_composite_serialize(self, **kwargs): # noqa: E501 + def fake_outer_composite_serialize(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_composite_serialize # noqa: E501 Test serialization of object with outer number type # noqa: E501 @@ -237,12 +275,12 @@ def fake_outer_composite_serialize(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.fake_outer_composite_serialize_with_http_info(**kwargs) # noqa: E501 + return self.fake_outer_composite_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.fake_outer_composite_serialize_with_http_info(**kwargs) # noqa: E501 + (data) = self.fake_outer_composite_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 + def fake_outer_composite_serialize_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_composite_serialize # noqa: E501 Test serialization of object with outer number type # noqa: E501 @@ -268,12 +306,22 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method fake_outer_composite_serialize" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [OuterComposite], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) collection_formats = {} @@ -304,7 +352,7 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='OuterComposite', # noqa: E501 + response_types_mixed=[OuterComposite], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -312,7 +360,7 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def fake_outer_number_serialize(self, **kwargs): # noqa: E501 + def fake_outer_number_serialize(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_number_serialize # noqa: E501 Test serialization of outer number types # noqa: E501 @@ -329,12 +377,12 @@ def fake_outer_number_serialize(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.fake_outer_number_serialize_with_http_info(**kwargs) # noqa: E501 + return self.fake_outer_number_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.fake_outer_number_serialize_with_http_info(**kwargs) # noqa: E501 + (data) = self.fake_outer_number_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 + def fake_outer_number_serialize_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_number_serialize # noqa: E501 Test serialization of outer number types # noqa: E501 @@ -360,12 +408,22 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method fake_outer_number_serialize" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [float], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) collection_formats = {} @@ -396,7 +454,7 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='float', # noqa: E501 + response_types_mixed=[float], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -404,7 +462,7 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def fake_outer_string_serialize(self, **kwargs): # noqa: E501 + def fake_outer_string_serialize(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_string_serialize # noqa: E501 Test serialization of outer string types # noqa: E501 @@ -421,12 +479,12 @@ def fake_outer_string_serialize(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.fake_outer_string_serialize_with_http_info(**kwargs) # noqa: E501 + return self.fake_outer_string_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.fake_outer_string_serialize_with_http_info(**kwargs) # noqa: E501 + (data) = self.fake_outer_string_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 + def fake_outer_string_serialize_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_string_serialize # noqa: E501 Test serialization of outer string types # noqa: E501 @@ -452,12 +510,22 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method fake_outer_string_serialize" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) collection_formats = {} @@ -488,7 +556,7 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='str', # noqa: E501 + response_types_mixed=[str], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -496,7 +564,7 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_body_with_file_schema(self, body, **kwargs): # noqa: E501 + def test_body_with_file_schema(self, body, _check_type=False, **kwargs): # noqa: E501 """test_body_with_file_schema # noqa: E501 For this test, the body for this request much reference a schema named `File`. # noqa: E501 @@ -513,12 +581,12 @@ def test_body_with_file_schema(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_body_with_file_schema_with_http_info(body, **kwargs) # noqa: E501 + return self.test_body_with_file_schema_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_body_with_file_schema_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.test_body_with_file_schema_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E501 + def test_body_with_file_schema_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """test_body_with_file_schema # noqa: E501 For this test, the body for this request much reference a schema named `File`. # noqa: E501 @@ -544,16 +612,26 @@ def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E5 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_body_with_file_schema" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [FileSchemaTestClass], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `test_body_with_file_schema`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `test_body_with_file_schema`") # noqa: E501 collection_formats = {} @@ -584,7 +662,7 @@ def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E5 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -592,7 +670,7 @@ def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E5 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_body_with_query_params(self, query, body, **kwargs): # noqa: E501 + def test_body_with_query_params(self, query, body, _check_type=False, **kwargs): # noqa: E501 """test_body_with_query_params # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -609,12 +687,12 @@ def test_body_with_query_params(self, query, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_body_with_query_params_with_http_info(query, body, **kwargs) # noqa: E501 + return self.test_body_with_query_params_with_http_info(query, body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_body_with_query_params_with_http_info(query, body, **kwargs) # noqa: E501 + (data) = self.test_body_with_query_params_with_http_info(query, body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_body_with_query_params_with_http_info(self, query, body, **kwargs): # noqa: E501 + def test_body_with_query_params_with_http_info(self, query, body, _check_type=False, **kwargs): # noqa: E501 """test_body_with_query_params # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -640,20 +718,31 @@ def test_body_with_query_params_with_http_info(self, query, body, **kwargs): # for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_body_with_query_params" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'query': [str], + 'body': [User], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'query' is set if ('query' not in local_var_params or local_var_params['query'] is None): - raise ValueError("Missing the required parameter `query` when calling `test_body_with_query_params`") # noqa: E501 + raise ApiValueError("Missing the required parameter `query` when calling `test_body_with_query_params`") # noqa: E501 # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `test_body_with_query_params`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `test_body_with_query_params`") # noqa: E501 collection_formats = {} @@ -686,7 +775,7 @@ def test_body_with_query_params_with_http_info(self, query, body, **kwargs): # body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -694,7 +783,7 @@ def test_body_with_query_params_with_http_info(self, query, body, **kwargs): # _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_client_model(self, body, **kwargs): # noqa: E501 + def test_client_model(self, body, _check_type=False, **kwargs): # noqa: E501 """To test \"client\" model # noqa: E501 To test \"client\" model # noqa: E501 @@ -711,12 +800,12 @@ def test_client_model(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_client_model_with_http_info(body, **kwargs) # noqa: E501 + return self.test_client_model_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_client_model_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.test_client_model_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501 + def test_client_model_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """To test \"client\" model # noqa: E501 To test \"client\" model # noqa: E501 @@ -742,16 +831,26 @@ def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_client_model" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [Client], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `test_client_model`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `test_client_model`") # noqa: E501 collection_formats = {} @@ -786,7 +885,7 @@ def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types_mixed=[Client], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -794,7 +893,7 @@ def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_endpoint_parameters(self, number, double, pattern_without_delimiter, byte, **kwargs): # noqa: E501 + def test_endpoint_parameters(self, number, double, pattern_without_delimiter, byte, _check_type=False, **kwargs): # noqa: E501 """Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 @@ -813,7 +912,7 @@ def test_endpoint_parameters(self, number, double, pattern_without_delimiter, by :param int int64: None :param float float: None :param str string: None - :param file binary: None + :param file_type binary: None :param date date: None :param datetime date_time: None :param str password: None @@ -824,12 +923,12 @@ def test_endpoint_parameters(self, number, double, pattern_without_delimiter, by """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_endpoint_parameters_with_http_info(number, double, pattern_without_delimiter, byte, **kwargs) # noqa: E501 + return self.test_endpoint_parameters_with_http_info(number, double, pattern_without_delimiter, byte, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_endpoint_parameters_with_http_info(number, double, pattern_without_delimiter, byte, **kwargs) # noqa: E501 + (data) = self.test_endpoint_parameters_with_http_info(number, double, pattern_without_delimiter, byte, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_endpoint_parameters_with_http_info(self, number, double, pattern_without_delimiter, byte, **kwargs): # noqa: E501 + def test_endpoint_parameters_with_http_info(self, number, double, pattern_without_delimiter, byte, _check_type=False, **kwargs): # noqa: E501 """Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 @@ -848,7 +947,7 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou :param int int64: None :param float float: None :param str string: None - :param file binary: None + :param file_type binary: None :param date date: None :param datetime date_time: None :param str password: None @@ -868,57 +967,80 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_endpoint_parameters" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'number': [float], + 'double': [float], + 'pattern_without_delimiter': [str], + 'byte': [str], + 'integer': [int], + 'int32': [int], + 'int64': [int], + 'float': [float], + 'string': [str], + 'binary': [file_type], + 'date': [date], + 'date_time': [datetime], + 'password': [str], + 'param_callback': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'number' is set if ('number' not in local_var_params or local_var_params['number'] is None): - raise ValueError("Missing the required parameter `number` when calling `test_endpoint_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `number` when calling `test_endpoint_parameters`") # noqa: E501 # verify the required parameter 'double' is set if ('double' not in local_var_params or local_var_params['double'] is None): - raise ValueError("Missing the required parameter `double` when calling `test_endpoint_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `double` when calling `test_endpoint_parameters`") # noqa: E501 # verify the required parameter 'pattern_without_delimiter' is set if ('pattern_without_delimiter' not in local_var_params or local_var_params['pattern_without_delimiter'] is None): - raise ValueError("Missing the required parameter `pattern_without_delimiter` when calling `test_endpoint_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pattern_without_delimiter` when calling `test_endpoint_parameters`") # noqa: E501 # verify the required parameter 'byte' is set if ('byte' not in local_var_params or local_var_params['byte'] is None): - raise ValueError("Missing the required parameter `byte` when calling `test_endpoint_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `byte` when calling `test_endpoint_parameters`") # noqa: E501 if 'number' in local_var_params and local_var_params['number'] > 543.2: # noqa: E501 - raise ValueError("Invalid value for parameter `number` when calling `test_endpoint_parameters`, must be a value less than or equal to `543.2`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `number` when calling `test_endpoint_parameters`, must be a value less than or equal to `543.2`") # noqa: E501 if 'number' in local_var_params and local_var_params['number'] < 32.1: # noqa: E501 - raise ValueError("Invalid value for parameter `number` when calling `test_endpoint_parameters`, must be a value greater than or equal to `32.1`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `number` when calling `test_endpoint_parameters`, must be a value greater than or equal to `32.1`") # noqa: E501 if 'double' in local_var_params and local_var_params['double'] > 123.4: # noqa: E501 - raise ValueError("Invalid value for parameter `double` when calling `test_endpoint_parameters`, must be a value less than or equal to `123.4`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `double` when calling `test_endpoint_parameters`, must be a value less than or equal to `123.4`") # noqa: E501 if 'double' in local_var_params and local_var_params['double'] < 67.8: # noqa: E501 - raise ValueError("Invalid value for parameter `double` when calling `test_endpoint_parameters`, must be a value greater than or equal to `67.8`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `double` when calling `test_endpoint_parameters`, must be a value greater than or equal to `67.8`") # noqa: E501 if 'pattern_without_delimiter' in local_var_params and not re.search(r'^[A-Z].*', local_var_params['pattern_without_delimiter']): # noqa: E501 - raise ValueError("Invalid value for parameter `pattern_without_delimiter` when calling `test_endpoint_parameters`, must conform to the pattern `/^[A-Z].*/`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `pattern_without_delimiter` when calling `test_endpoint_parameters`, must conform to the pattern `/^[A-Z].*/`") # noqa: E501 if 'integer' in local_var_params and local_var_params['integer'] > 100: # noqa: E501 - raise ValueError("Invalid value for parameter `integer` when calling `test_endpoint_parameters`, must be a value less than or equal to `100`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `integer` when calling `test_endpoint_parameters`, must be a value less than or equal to `100`") # noqa: E501 if 'integer' in local_var_params and local_var_params['integer'] < 10: # noqa: E501 - raise ValueError("Invalid value for parameter `integer` when calling `test_endpoint_parameters`, must be a value greater than or equal to `10`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `integer` when calling `test_endpoint_parameters`, must be a value greater than or equal to `10`") # noqa: E501 if 'int32' in local_var_params and local_var_params['int32'] > 200: # noqa: E501 - raise ValueError("Invalid value for parameter `int32` when calling `test_endpoint_parameters`, must be a value less than or equal to `200`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `int32` when calling `test_endpoint_parameters`, must be a value less than or equal to `200`") # noqa: E501 if 'int32' in local_var_params and local_var_params['int32'] < 20: # noqa: E501 - raise ValueError("Invalid value for parameter `int32` when calling `test_endpoint_parameters`, must be a value greater than or equal to `20`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `int32` when calling `test_endpoint_parameters`, must be a value greater than or equal to `20`") # noqa: E501 if 'float' in local_var_params and local_var_params['float'] > 987.6: # noqa: E501 - raise ValueError("Invalid value for parameter `float` when calling `test_endpoint_parameters`, must be a value less than or equal to `987.6`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `float` when calling `test_endpoint_parameters`, must be a value less than or equal to `987.6`") # noqa: E501 if 'string' in local_var_params and not re.search(r'[a-z]', local_var_params['string'], flags=re.IGNORECASE): # noqa: E501 - raise ValueError("Invalid value for parameter `string` when calling `test_endpoint_parameters`, must conform to the pattern `/[a-z]/i`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `string` when calling `test_endpoint_parameters`, must conform to the pattern `/[a-z]/i`") # noqa: E501 if ('password' in local_var_params and len(local_var_params['password']) > 64): - raise ValueError("Invalid value for parameter `password` when calling `test_endpoint_parameters`, length must be less than or equal to `64`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `password` when calling `test_endpoint_parameters`, length must be less than or equal to `64`") # noqa: E501 if ('password' in local_var_params and len(local_var_params['password']) < 10): - raise ValueError("Invalid value for parameter `password` when calling `test_endpoint_parameters`, length must be greater than or equal to `10`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `password` when calling `test_endpoint_parameters`, length must be greater than or equal to `10`") # noqa: E501 collection_formats = {} path_params = {} @@ -974,7 +1096,7 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -982,7 +1104,7 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_enum_parameters(self, **kwargs): # noqa: E501 + def test_enum_parameters(self, _check_type=False, **kwargs): # noqa: E501 """To test enum parameters # noqa: E501 To test enum parameters # noqa: E501 @@ -992,13 +1114,13 @@ def test_enum_parameters(self, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] enum_header_string_array: Header parameter enum test (string array) + :param [(str,)] enum_header_string_array: Header parameter enum test (string array) :param str enum_header_string: Header parameter enum test (string) - :param list[str] enum_query_string_array: Query parameter enum test (string array) + :param [(str,)] enum_query_string_array: Query parameter enum test (string array) :param str enum_query_string: Query parameter enum test (string) :param int enum_query_integer: Query parameter enum test (double) :param float enum_query_double: Query parameter enum test (double) - :param list[str] enum_form_string_array: Form parameter enum test (string array) + :param [(str,)] enum_form_string_array: Form parameter enum test (string array) :param str enum_form_string: Form parameter enum test (string) :return: None If the method is called asynchronously, @@ -1006,12 +1128,12 @@ def test_enum_parameters(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_enum_parameters_with_http_info(**kwargs) # noqa: E501 + return self.test_enum_parameters_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_enum_parameters_with_http_info(**kwargs) # noqa: E501 + (data) = self.test_enum_parameters_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 + def test_enum_parameters_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """To test enum parameters # noqa: E501 To test enum parameters # noqa: E501 @@ -1021,13 +1143,13 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] enum_header_string_array: Header parameter enum test (string array) + :param [(str,)] enum_header_string_array: Header parameter enum test (string array) :param str enum_header_string: Header parameter enum test (string) - :param list[str] enum_query_string_array: Query parameter enum test (string array) + :param [(str,)] enum_query_string_array: Query parameter enum test (string array) :param str enum_query_string: Query parameter enum test (string) :param int enum_query_integer: Query parameter enum test (double) :param float enum_query_double: Query parameter enum test (double) - :param list[str] enum_form_string_array: Form parameter enum test (string array) + :param [(str,)] enum_form_string_array: Form parameter enum test (string array) :param str enum_form_string: Form parameter enum test (string) :return: None If the method is called asynchronously, @@ -1044,12 +1166,29 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_enum_parameters" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'enum_header_string_array': [[(str,)]], + 'enum_header_string': [str], + 'enum_query_string_array': [[(str,)]], + 'enum_query_string': [str], + 'enum_query_integer': [int], + 'enum_query_double': [float], + 'enum_form_string_array': [[(str,)]], + 'enum_form_string': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) collection_formats = {} @@ -1097,7 +1236,7 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1105,7 +1244,7 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_group_parameters(self, required_string_group, required_boolean_group, required_int64_group, **kwargs): # noqa: E501 + def test_group_parameters(self, required_string_group, required_boolean_group, required_int64_group, _check_type=False, **kwargs): # noqa: E501 """Fake endpoint to test group parameters (optional) # noqa: E501 Fake endpoint to test group parameters (optional) # noqa: E501 @@ -1127,12 +1266,12 @@ def test_group_parameters(self, required_string_group, required_boolean_group, r """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_group_parameters_with_http_info(required_string_group, required_boolean_group, required_int64_group, **kwargs) # noqa: E501 + return self.test_group_parameters_with_http_info(required_string_group, required_boolean_group, required_int64_group, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_group_parameters_with_http_info(required_string_group, required_boolean_group, required_int64_group, **kwargs) # noqa: E501 + (data) = self.test_group_parameters_with_http_info(required_string_group, required_boolean_group, required_int64_group, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_group_parameters_with_http_info(self, required_string_group, required_boolean_group, required_int64_group, **kwargs): # noqa: E501 + def test_group_parameters_with_http_info(self, required_string_group, required_boolean_group, required_int64_group, _check_type=False, **kwargs): # noqa: E501 """Fake endpoint to test group parameters (optional) # noqa: E501 Fake endpoint to test group parameters (optional) # noqa: E501 @@ -1163,24 +1302,39 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_group_parameters" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'required_string_group': [int], + 'required_boolean_group': [bool], + 'required_int64_group': [int], + 'string_group': [int], + 'boolean_group': [bool], + 'int64_group': [int], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'required_string_group' is set if ('required_string_group' not in local_var_params or local_var_params['required_string_group'] is None): - raise ValueError("Missing the required parameter `required_string_group` when calling `test_group_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `required_string_group` when calling `test_group_parameters`") # noqa: E501 # verify the required parameter 'required_boolean_group' is set if ('required_boolean_group' not in local_var_params or local_var_params['required_boolean_group'] is None): - raise ValueError("Missing the required parameter `required_boolean_group` when calling `test_group_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `required_boolean_group` when calling `test_group_parameters`") # noqa: E501 # verify the required parameter 'required_int64_group' is set if ('required_int64_group' not in local_var_params or local_var_params['required_int64_group'] is None): - raise ValueError("Missing the required parameter `required_int64_group` when calling `test_group_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `required_int64_group` when calling `test_group_parameters`") # noqa: E501 collection_formats = {} @@ -1217,7 +1371,7 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1225,7 +1379,7 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_inline_additional_properties(self, param, **kwargs): # noqa: E501 + def test_inline_additional_properties(self, param, _check_type=False, **kwargs): # noqa: E501 """test inline additionalProperties # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -1234,19 +1388,19 @@ def test_inline_additional_properties(self, param, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param dict(str, str) param: request body (required) + :param {str: (str,)} param: request body (required) :return: None If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_inline_additional_properties_with_http_info(param, **kwargs) # noqa: E501 + return self.test_inline_additional_properties_with_http_info(param, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_inline_additional_properties_with_http_info(param, **kwargs) # noqa: E501 + (data) = self.test_inline_additional_properties_with_http_info(param, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_inline_additional_properties_with_http_info(self, param, **kwargs): # noqa: E501 + def test_inline_additional_properties_with_http_info(self, param, _check_type=False, **kwargs): # noqa: E501 """test inline additionalProperties # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -1255,7 +1409,7 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): # >>> result = thread.get() :param async_req bool - :param dict(str, str) param: request body (required) + :param {str: (str,)} param: request body (required) :return: None If the method is called asynchronously, returns the request thread. @@ -1271,16 +1425,26 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): # for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_inline_additional_properties" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'param': [{str: (str,)}], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'param' is set if ('param' not in local_var_params or local_var_params['param'] is None): - raise ValueError("Missing the required parameter `param` when calling `test_inline_additional_properties`") # noqa: E501 + raise ApiValueError("Missing the required parameter `param` when calling `test_inline_additional_properties`") # noqa: E501 collection_formats = {} @@ -1311,7 +1475,7 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): # body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1319,7 +1483,7 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): # _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_json_form_data(self, param, param2, **kwargs): # noqa: E501 + def test_json_form_data(self, param, param2, _check_type=False, **kwargs): # noqa: E501 """test json serialization of form data # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -1336,12 +1500,12 @@ def test_json_form_data(self, param, param2, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_json_form_data_with_http_info(param, param2, **kwargs) # noqa: E501 + return self.test_json_form_data_with_http_info(param, param2, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_json_form_data_with_http_info(param, param2, **kwargs) # noqa: E501 + (data) = self.test_json_form_data_with_http_info(param, param2, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa: E501 + def test_json_form_data_with_http_info(self, param, param2, _check_type=False, **kwargs): # noqa: E501 """test json serialization of form data # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -1367,20 +1531,31 @@ def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa: for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_json_form_data" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'param': [str], + 'param2': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'param' is set if ('param' not in local_var_params or local_var_params['param'] is None): - raise ValueError("Missing the required parameter `param` when calling `test_json_form_data`") # noqa: E501 + raise ApiValueError("Missing the required parameter `param` when calling `test_json_form_data`") # noqa: E501 # verify the required parameter 'param2' is set if ('param2' not in local_var_params or local_var_params['param2'] is None): - raise ValueError("Missing the required parameter `param2` when calling `test_json_form_data`") # noqa: E501 + raise ApiValueError("Missing the required parameter `param2` when calling `test_json_form_data`") # noqa: E501 collection_formats = {} @@ -1413,7 +1588,7 @@ def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python/petstore_api/api/fake_classname_tags_123_api.py b/samples/client/petstore/python/petstore_api/api/fake_classname_tags_123_api.py index dbf6ef3dfb37..765a41b2827e 100644 --- a/samples/client/petstore/python/petstore_api/api/fake_classname_tags_123_api.py +++ b/samples/client/petstore/python/petstore_api/api/fake_classname_tags_123_api.py @@ -18,6 +18,20 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.client import Client class FakeClassnameTags123Api(object): @@ -32,7 +46,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def test_classname(self, body, **kwargs): # noqa: E501 + def test_classname(self, body, _check_type=False, **kwargs): # noqa: E501 """To test class name in snake case # noqa: E501 To test class name in snake case # noqa: E501 @@ -49,12 +63,12 @@ def test_classname(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_classname_with_http_info(body, **kwargs) # noqa: E501 + return self.test_classname_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_classname_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.test_classname_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_classname_with_http_info(self, body, **kwargs): # noqa: E501 + def test_classname_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """To test class name in snake case # noqa: E501 To test class name in snake case # noqa: E501 @@ -80,16 +94,26 @@ def test_classname_with_http_info(self, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_classname" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [Client], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `test_classname`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `test_classname`") # noqa: E501 collection_formats = {} @@ -124,7 +148,7 @@ def test_classname_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types_mixed=[Client], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python/petstore_api/api/pet_api.py b/samples/client/petstore/python/petstore_api/api/pet_api.py index f29e7239666a..7e07c241e0e1 100644 --- a/samples/client/petstore/python/petstore_api/api/pet_api.py +++ b/samples/client/petstore/python/petstore_api/api/pet_api.py @@ -18,6 +18,21 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.api_response import ApiResponse +from petstore_api.models.pet import Pet class PetApi(object): @@ -32,7 +47,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def add_pet(self, body, **kwargs): # noqa: E501 + def add_pet(self, body, _check_type=False, **kwargs): # noqa: E501 """Add a new pet to the store # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -48,12 +63,12 @@ def add_pet(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.add_pet_with_http_info(body, **kwargs) # noqa: E501 + return self.add_pet_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.add_pet_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.add_pet_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def add_pet_with_http_info(self, body, **kwargs): # noqa: E501 + def add_pet_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """Add a new pet to the store # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -78,16 +93,26 @@ def add_pet_with_http_info(self, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method add_pet" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [Pet], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `add_pet`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `add_pet`") # noqa: E501 collection_formats = {} @@ -118,7 +143,7 @@ def add_pet_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -126,7 +151,7 @@ def add_pet_with_http_info(self, body, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def delete_pet(self, pet_id, **kwargs): # noqa: E501 + def delete_pet(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Deletes a pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -143,12 +168,12 @@ def delete_pet(self, pet_id, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.delete_pet_with_http_info(pet_id, **kwargs) # noqa: E501 + return self.delete_pet_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.delete_pet_with_http_info(pet_id, **kwargs) # noqa: E501 + (data) = self.delete_pet_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 + def delete_pet_with_http_info(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Deletes a pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -174,16 +199,27 @@ def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method delete_pet" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet_id': [int], + 'api_key': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet_id' is set if ('pet_id' not in local_var_params or local_var_params['pet_id'] is None): - raise ValueError("Missing the required parameter `pet_id` when calling `delete_pet`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet_id` when calling `delete_pet`") # noqa: E501 collection_formats = {} @@ -212,7 +248,7 @@ def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -220,7 +256,7 @@ def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def find_pets_by_status(self, status, **kwargs): # noqa: E501 + def find_pets_by_status(self, status, _check_type=False, **kwargs): # noqa: E501 """Finds Pets by status # noqa: E501 Multiple status values can be provided with comma separated strings # noqa: E501 @@ -230,19 +266,19 @@ def find_pets_by_status(self, status, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] status: Status values that need to be considered for filter (required) - :return: list[Pet] + :param [(str,)] status: Status values that need to be considered for filter (required) + :return: [(Pet,)] If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.find_pets_by_status_with_http_info(status, **kwargs) # noqa: E501 + return self.find_pets_by_status_with_http_info(status, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.find_pets_by_status_with_http_info(status, **kwargs) # noqa: E501 + (data) = self.find_pets_by_status_with_http_info(status, _check_type=_check_type, **kwargs) # noqa: E501 return data - def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 + def find_pets_by_status_with_http_info(self, status, _check_type=False, **kwargs): # noqa: E501 """Finds Pets by status # noqa: E501 Multiple status values can be provided with comma separated strings # noqa: E501 @@ -252,8 +288,8 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] status: Status values that need to be considered for filter (required) - :return: list[Pet] + :param [(str,)] status: Status values that need to be considered for filter (required) + :return: [(Pet,)] If the method is called asynchronously, returns the request thread. """ @@ -268,16 +304,26 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method find_pets_by_status" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'status': [[(str,)]], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'status' is set if ('status' not in local_var_params or local_var_params['status'] is None): - raise ValueError("Missing the required parameter `status` when calling `find_pets_by_status`") # noqa: E501 + raise ApiValueError("Missing the required parameter `status` when calling `find_pets_by_status`") # noqa: E501 collection_formats = {} @@ -309,7 +355,7 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='list[Pet]', # noqa: E501 + response_types_mixed=[[(Pet,)]], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -317,7 +363,7 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def find_pets_by_tags(self, tags, **kwargs): # noqa: E501 + def find_pets_by_tags(self, tags, _check_type=False, **kwargs): # noqa: E501 """Finds Pets by tags # noqa: E501 Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. # noqa: E501 @@ -327,19 +373,19 @@ def find_pets_by_tags(self, tags, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] tags: Tags to filter by (required) - :return: list[Pet] + :param [(str,)] tags: Tags to filter by (required) + :return: [(Pet,)] If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.find_pets_by_tags_with_http_info(tags, **kwargs) # noqa: E501 + return self.find_pets_by_tags_with_http_info(tags, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.find_pets_by_tags_with_http_info(tags, **kwargs) # noqa: E501 + (data) = self.find_pets_by_tags_with_http_info(tags, _check_type=_check_type, **kwargs) # noqa: E501 return data - def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 + def find_pets_by_tags_with_http_info(self, tags, _check_type=False, **kwargs): # noqa: E501 """Finds Pets by tags # noqa: E501 Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. # noqa: E501 @@ -349,8 +395,8 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] tags: Tags to filter by (required) - :return: list[Pet] + :param [(str,)] tags: Tags to filter by (required) + :return: [(Pet,)] If the method is called asynchronously, returns the request thread. """ @@ -365,16 +411,26 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method find_pets_by_tags" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'tags': [[(str,)]], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'tags' is set if ('tags' not in local_var_params or local_var_params['tags'] is None): - raise ValueError("Missing the required parameter `tags` when calling `find_pets_by_tags`") # noqa: E501 + raise ApiValueError("Missing the required parameter `tags` when calling `find_pets_by_tags`") # noqa: E501 collection_formats = {} @@ -406,7 +462,7 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='list[Pet]', # noqa: E501 + response_types_mixed=[[(Pet,)]], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -414,7 +470,7 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def get_pet_by_id(self, pet_id, **kwargs): # noqa: E501 + def get_pet_by_id(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Find pet by ID # noqa: E501 Returns a single pet # noqa: E501 @@ -431,12 +487,12 @@ def get_pet_by_id(self, pet_id, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.get_pet_by_id_with_http_info(pet_id, **kwargs) # noqa: E501 + return self.get_pet_by_id_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.get_pet_by_id_with_http_info(pet_id, **kwargs) # noqa: E501 + (data) = self.get_pet_by_id_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 + def get_pet_by_id_with_http_info(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Find pet by ID # noqa: E501 Returns a single pet # noqa: E501 @@ -462,16 +518,26 @@ def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method get_pet_by_id" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet_id': [int], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet_id' is set if ('pet_id' not in local_var_params or local_var_params['pet_id'] is None): - raise ValueError("Missing the required parameter `pet_id` when calling `get_pet_by_id`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet_id` when calling `get_pet_by_id`") # noqa: E501 collection_formats = {} @@ -502,7 +568,7 @@ def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Pet', # noqa: E501 + response_types_mixed=[Pet], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -510,7 +576,7 @@ def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def update_pet(self, body, **kwargs): # noqa: E501 + def update_pet(self, body, _check_type=False, **kwargs): # noqa: E501 """Update an existing pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -526,12 +592,12 @@ def update_pet(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.update_pet_with_http_info(body, **kwargs) # noqa: E501 + return self.update_pet_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.update_pet_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.update_pet_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def update_pet_with_http_info(self, body, **kwargs): # noqa: E501 + def update_pet_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """Update an existing pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -556,16 +622,26 @@ def update_pet_with_http_info(self, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method update_pet" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [Pet], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `update_pet`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `update_pet`") # noqa: E501 collection_formats = {} @@ -596,7 +672,7 @@ def update_pet_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -604,7 +680,7 @@ def update_pet_with_http_info(self, body, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def update_pet_with_form(self, pet_id, **kwargs): # noqa: E501 + def update_pet_with_form(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Updates a pet in the store with form data # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -622,12 +698,12 @@ def update_pet_with_form(self, pet_id, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.update_pet_with_form_with_http_info(pet_id, **kwargs) # noqa: E501 + return self.update_pet_with_form_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.update_pet_with_form_with_http_info(pet_id, **kwargs) # noqa: E501 + (data) = self.update_pet_with_form_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 + def update_pet_with_form_with_http_info(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Updates a pet in the store with form data # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -654,16 +730,28 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method update_pet_with_form" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet_id': [int], + 'name': [str], + 'status': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet_id' is set if ('pet_id' not in local_var_params or local_var_params['pet_id'] is None): - raise ValueError("Missing the required parameter `pet_id` when calling `update_pet_with_form`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet_id` when calling `update_pet_with_form`") # noqa: E501 collection_formats = {} @@ -698,7 +786,7 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -706,7 +794,7 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def upload_file(self, pet_id, **kwargs): # noqa: E501 + def upload_file(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """uploads an image # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -717,19 +805,19 @@ def upload_file(self, pet_id, **kwargs): # noqa: E501 :param async_req bool :param int pet_id: ID of pet to update (required) :param str additional_metadata: Additional data to pass to server - :param file file: file to upload + :param file_type file: file to upload :return: ApiResponse If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.upload_file_with_http_info(pet_id, **kwargs) # noqa: E501 + return self.upload_file_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.upload_file_with_http_info(pet_id, **kwargs) # noqa: E501 + (data) = self.upload_file_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 + def upload_file_with_http_info(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """uploads an image # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -740,7 +828,7 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 :param async_req bool :param int pet_id: ID of pet to update (required) :param str additional_metadata: Additional data to pass to server - :param file file: file to upload + :param file_type file: file to upload :return: ApiResponse If the method is called asynchronously, returns the request thread. @@ -756,16 +844,28 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method upload_file" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet_id': [int], + 'additional_metadata': [str], + 'file': [file_type], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet_id' is set if ('pet_id' not in local_var_params or local_var_params['pet_id'] is None): - raise ValueError("Missing the required parameter `pet_id` when calling `upload_file`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet_id` when calling `upload_file`") # noqa: E501 collection_formats = {} @@ -804,7 +904,7 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='ApiResponse', # noqa: E501 + response_types_mixed=[ApiResponse], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -812,7 +912,7 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def upload_file_with_required_file(self, pet_id, required_file, **kwargs): # noqa: E501 + def upload_file_with_required_file(self, pet_id, required_file, _check_type=False, **kwargs): # noqa: E501 """uploads an image (required) # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -822,7 +922,7 @@ def upload_file_with_required_file(self, pet_id, required_file, **kwargs): # no :param async_req bool :param int pet_id: ID of pet to update (required) - :param file required_file: file to upload (required) + :param file_type required_file: file to upload (required) :param str additional_metadata: Additional data to pass to server :return: ApiResponse If the method is called asynchronously, @@ -830,12 +930,12 @@ def upload_file_with_required_file(self, pet_id, required_file, **kwargs): # no """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.upload_file_with_required_file_with_http_info(pet_id, required_file, **kwargs) # noqa: E501 + return self.upload_file_with_required_file_with_http_info(pet_id, required_file, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.upload_file_with_required_file_with_http_info(pet_id, required_file, **kwargs) # noqa: E501 + (data) = self.upload_file_with_required_file_with_http_info(pet_id, required_file, _check_type=_check_type, **kwargs) # noqa: E501 return data - def upload_file_with_required_file_with_http_info(self, pet_id, required_file, **kwargs): # noqa: E501 + def upload_file_with_required_file_with_http_info(self, pet_id, required_file, _check_type=False, **kwargs): # noqa: E501 """uploads an image (required) # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -845,7 +945,7 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, * :param async_req bool :param int pet_id: ID of pet to update (required) - :param file required_file: file to upload (required) + :param file_type required_file: file to upload (required) :param str additional_metadata: Additional data to pass to server :return: ApiResponse If the method is called asynchronously, @@ -862,20 +962,32 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, * for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method upload_file_with_required_file" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet_id': [int], + 'required_file': [file_type], + 'additional_metadata': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet_id' is set if ('pet_id' not in local_var_params or local_var_params['pet_id'] is None): - raise ValueError("Missing the required parameter `pet_id` when calling `upload_file_with_required_file`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet_id` when calling `upload_file_with_required_file`") # noqa: E501 # verify the required parameter 'required_file' is set if ('required_file' not in local_var_params or local_var_params['required_file'] is None): - raise ValueError("Missing the required parameter `required_file` when calling `upload_file_with_required_file`") # noqa: E501 + raise ApiValueError("Missing the required parameter `required_file` when calling `upload_file_with_required_file`") # noqa: E501 collection_formats = {} @@ -914,7 +1026,7 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, * body=body_params, post_params=form_params, files=local_var_files, - response_type='ApiResponse', # noqa: E501 + response_types_mixed=[ApiResponse], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python/petstore_api/api/store_api.py b/samples/client/petstore/python/petstore_api/api/store_api.py index bd2677ef92bc..6a8bba9ac620 100644 --- a/samples/client/petstore/python/petstore_api/api/store_api.py +++ b/samples/client/petstore/python/petstore_api/api/store_api.py @@ -18,6 +18,20 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.order import Order class StoreApi(object): @@ -32,7 +46,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def delete_order(self, order_id, **kwargs): # noqa: E501 + def delete_order(self, order_id, _check_type=False, **kwargs): # noqa: E501 """Delete purchase order by ID # noqa: E501 For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors # noqa: E501 @@ -49,12 +63,12 @@ def delete_order(self, order_id, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.delete_order_with_http_info(order_id, **kwargs) # noqa: E501 + return self.delete_order_with_http_info(order_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.delete_order_with_http_info(order_id, **kwargs) # noqa: E501 + (data) = self.delete_order_with_http_info(order_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 + def delete_order_with_http_info(self, order_id, _check_type=False, **kwargs): # noqa: E501 """Delete purchase order by ID # noqa: E501 For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors # noqa: E501 @@ -80,16 +94,26 @@ def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method delete_order" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'order_id': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'order_id' is set if ('order_id' not in local_var_params or local_var_params['order_id'] is None): - raise ValueError("Missing the required parameter `order_id` when calling `delete_order`") # noqa: E501 + raise ApiValueError("Missing the required parameter `order_id` when calling `delete_order`") # noqa: E501 collection_formats = {} @@ -116,7 +140,7 @@ def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -124,7 +148,7 @@ def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def get_inventory(self, **kwargs): # noqa: E501 + def get_inventory(self, _check_type=False, **kwargs): # noqa: E501 """Returns pet inventories by status # noqa: E501 Returns a map of status codes to quantities # noqa: E501 @@ -134,18 +158,18 @@ def get_inventory(self, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :return: dict(str, int) + :return: {str: (int,)} If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.get_inventory_with_http_info(**kwargs) # noqa: E501 + return self.get_inventory_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.get_inventory_with_http_info(**kwargs) # noqa: E501 + (data) = self.get_inventory_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def get_inventory_with_http_info(self, **kwargs): # noqa: E501 + def get_inventory_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """Returns pet inventories by status # noqa: E501 Returns a map of status codes to quantities # noqa: E501 @@ -155,7 +179,7 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :return: dict(str, int) + :return: {str: (int,)} If the method is called asynchronously, returns the request thread. """ @@ -170,7 +194,7 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method get_inventory" % key ) @@ -204,7 +228,7 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='dict(str, int)', # noqa: E501 + response_types_mixed=[{str: (int,)}], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -212,7 +236,7 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def get_order_by_id(self, order_id, **kwargs): # noqa: E501 + def get_order_by_id(self, order_id, _check_type=False, **kwargs): # noqa: E501 """Find purchase order by ID # noqa: E501 For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions # noqa: E501 @@ -229,12 +253,12 @@ def get_order_by_id(self, order_id, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.get_order_by_id_with_http_info(order_id, **kwargs) # noqa: E501 + return self.get_order_by_id_with_http_info(order_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.get_order_by_id_with_http_info(order_id, **kwargs) # noqa: E501 + (data) = self.get_order_by_id_with_http_info(order_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 + def get_order_by_id_with_http_info(self, order_id, _check_type=False, **kwargs): # noqa: E501 """Find purchase order by ID # noqa: E501 For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions # noqa: E501 @@ -260,21 +284,31 @@ def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method get_order_by_id" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'order_id': [int], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'order_id' is set if ('order_id' not in local_var_params or local_var_params['order_id'] is None): - raise ValueError("Missing the required parameter `order_id` when calling `get_order_by_id`") # noqa: E501 + raise ApiValueError("Missing the required parameter `order_id` when calling `get_order_by_id`") # noqa: E501 if 'order_id' in local_var_params and local_var_params['order_id'] > 5: # noqa: E501 - raise ValueError("Invalid value for parameter `order_id` when calling `get_order_by_id`, must be a value less than or equal to `5`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `order_id` when calling `get_order_by_id`, must be a value less than or equal to `5`") # noqa: E501 if 'order_id' in local_var_params and local_var_params['order_id'] < 1: # noqa: E501 - raise ValueError("Invalid value for parameter `order_id` when calling `get_order_by_id`, must be a value greater than or equal to `1`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `order_id` when calling `get_order_by_id`, must be a value greater than or equal to `1`") # noqa: E501 collection_formats = {} path_params = {} @@ -304,7 +338,7 @@ def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Order', # noqa: E501 + response_types_mixed=[Order], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -312,7 +346,7 @@ def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def place_order(self, body, **kwargs): # noqa: E501 + def place_order(self, body, _check_type=False, **kwargs): # noqa: E501 """Place an order for a pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -328,12 +362,12 @@ def place_order(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.place_order_with_http_info(body, **kwargs) # noqa: E501 + return self.place_order_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.place_order_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.place_order_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def place_order_with_http_info(self, body, **kwargs): # noqa: E501 + def place_order_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """Place an order for a pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -358,16 +392,26 @@ def place_order_with_http_info(self, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method place_order" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [Order], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `place_order`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `place_order`") # noqa: E501 collection_formats = {} @@ -398,7 +442,7 @@ def place_order_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Order', # noqa: E501 + response_types_mixed=[Order], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python/petstore_api/api/user_api.py b/samples/client/petstore/python/petstore_api/api/user_api.py index c27299309a6d..672bbc57b59e 100644 --- a/samples/client/petstore/python/petstore_api/api/user_api.py +++ b/samples/client/petstore/python/petstore_api/api/user_api.py @@ -18,6 +18,20 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.user import User class UserApi(object): @@ -32,7 +46,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def create_user(self, body, **kwargs): # noqa: E501 + def create_user(self, body, _check_type=False, **kwargs): # noqa: E501 """Create user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -49,12 +63,12 @@ def create_user(self, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.create_user_with_http_info(body, **kwargs) # noqa: E501 + return self.create_user_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.create_user_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.create_user_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def create_user_with_http_info(self, body, **kwargs): # noqa: E501 + def create_user_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """Create user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -80,16 +94,26 @@ def create_user_with_http_info(self, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method create_user" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [User], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `create_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `create_user`") # noqa: E501 collection_formats = {} @@ -116,7 +140,7 @@ def create_user_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -124,7 +148,7 @@ def create_user_with_http_info(self, body, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def create_users_with_array_input(self, body, **kwargs): # noqa: E501 + def create_users_with_array_input(self, body, _check_type=False, **kwargs): # noqa: E501 """Creates list of users with given input array # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -133,19 +157,19 @@ def create_users_with_array_input(self, body, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[User] body: List of user object (required) + :param [(User,)] body: List of user object (required) :return: None If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.create_users_with_array_input_with_http_info(body, **kwargs) # noqa: E501 + return self.create_users_with_array_input_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.create_users_with_array_input_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.create_users_with_array_input_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: E501 + def create_users_with_array_input_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """Creates list of users with given input array # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -154,7 +178,7 @@ def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: >>> result = thread.get() :param async_req bool - :param list[User] body: List of user object (required) + :param [(User,)] body: List of user object (required) :return: None If the method is called asynchronously, returns the request thread. @@ -170,16 +194,26 @@ def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method create_users_with_array_input" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [[(User,)]], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `create_users_with_array_input`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `create_users_with_array_input`") # noqa: E501 collection_formats = {} @@ -206,7 +240,7 @@ def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -214,7 +248,7 @@ def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def create_users_with_list_input(self, body, **kwargs): # noqa: E501 + def create_users_with_list_input(self, body, _check_type=False, **kwargs): # noqa: E501 """Creates list of users with given input array # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -223,19 +257,19 @@ def create_users_with_list_input(self, body, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[User] body: List of user object (required) + :param [(User,)] body: List of user object (required) :return: None If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.create_users_with_list_input_with_http_info(body, **kwargs) # noqa: E501 + return self.create_users_with_list_input_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.create_users_with_list_input_with_http_info(body, **kwargs) # noqa: E501 + (data) = self.create_users_with_list_input_with_http_info(body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: E501 + def create_users_with_list_input_with_http_info(self, body, _check_type=False, **kwargs): # noqa: E501 """Creates list of users with given input array # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -244,7 +278,7 @@ def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: >>> result = thread.get() :param async_req bool - :param list[User] body: List of user object (required) + :param [(User,)] body: List of user object (required) :return: None If the method is called asynchronously, returns the request thread. @@ -260,16 +294,26 @@ def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method create_users_with_list_input" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [[(User,)]], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `create_users_with_list_input`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `create_users_with_list_input`") # noqa: E501 collection_formats = {} @@ -296,7 +340,7 @@ def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -304,7 +348,7 @@ def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def delete_user(self, username, **kwargs): # noqa: E501 + def delete_user(self, username, _check_type=False, **kwargs): # noqa: E501 """Delete user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -321,12 +365,12 @@ def delete_user(self, username, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.delete_user_with_http_info(username, **kwargs) # noqa: E501 + return self.delete_user_with_http_info(username, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.delete_user_with_http_info(username, **kwargs) # noqa: E501 + (data) = self.delete_user_with_http_info(username, _check_type=_check_type, **kwargs) # noqa: E501 return data - def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 + def delete_user_with_http_info(self, username, _check_type=False, **kwargs): # noqa: E501 """Delete user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -352,16 +396,26 @@ def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method delete_user" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'username': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'username' is set if ('username' not in local_var_params or local_var_params['username'] is None): - raise ValueError("Missing the required parameter `username` when calling `delete_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `username` when calling `delete_user`") # noqa: E501 collection_formats = {} @@ -388,7 +442,7 @@ def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -396,7 +450,7 @@ def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def get_user_by_name(self, username, **kwargs): # noqa: E501 + def get_user_by_name(self, username, _check_type=False, **kwargs): # noqa: E501 """Get user by user name # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -412,12 +466,12 @@ def get_user_by_name(self, username, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.get_user_by_name_with_http_info(username, **kwargs) # noqa: E501 + return self.get_user_by_name_with_http_info(username, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.get_user_by_name_with_http_info(username, **kwargs) # noqa: E501 + (data) = self.get_user_by_name_with_http_info(username, _check_type=_check_type, **kwargs) # noqa: E501 return data - def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 + def get_user_by_name_with_http_info(self, username, _check_type=False, **kwargs): # noqa: E501 """Get user by user name # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -442,16 +496,26 @@ def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method get_user_by_name" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'username': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'username' is set if ('username' not in local_var_params or local_var_params['username'] is None): - raise ValueError("Missing the required parameter `username` when calling `get_user_by_name`") # noqa: E501 + raise ApiValueError("Missing the required parameter `username` when calling `get_user_by_name`") # noqa: E501 collection_formats = {} @@ -482,7 +546,7 @@ def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='User', # noqa: E501 + response_types_mixed=[User], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -490,7 +554,7 @@ def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def login_user(self, username, password, **kwargs): # noqa: E501 + def login_user(self, username, password, _check_type=False, **kwargs): # noqa: E501 """Logs user into the system # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -507,12 +571,12 @@ def login_user(self, username, password, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.login_user_with_http_info(username, password, **kwargs) # noqa: E501 + return self.login_user_with_http_info(username, password, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.login_user_with_http_info(username, password, **kwargs) # noqa: E501 + (data) = self.login_user_with_http_info(username, password, _check_type=_check_type, **kwargs) # noqa: E501 return data - def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 + def login_user_with_http_info(self, username, password, _check_type=False, **kwargs): # noqa: E501 """Logs user into the system # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -538,20 +602,31 @@ def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method login_user" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'username': [str], + 'password': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'username' is set if ('username' not in local_var_params or local_var_params['username'] is None): - raise ValueError("Missing the required parameter `username` when calling `login_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `username` when calling `login_user`") # noqa: E501 # verify the required parameter 'password' is set if ('password' not in local_var_params or local_var_params['password'] is None): - raise ValueError("Missing the required parameter `password` when calling `login_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `password` when calling `login_user`") # noqa: E501 collection_formats = {} @@ -584,7 +659,7 @@ def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='str', # noqa: E501 + response_types_mixed=[str], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -592,7 +667,7 @@ def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def logout_user(self, **kwargs): # noqa: E501 + def logout_user(self, _check_type=False, **kwargs): # noqa: E501 """Logs out current logged in user session # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -607,12 +682,12 @@ def logout_user(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.logout_user_with_http_info(**kwargs) # noqa: E501 + return self.logout_user_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.logout_user_with_http_info(**kwargs) # noqa: E501 + (data) = self.logout_user_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def logout_user_with_http_info(self, **kwargs): # noqa: E501 + def logout_user_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """Logs out current logged in user session # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -636,7 +711,7 @@ def logout_user_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method logout_user" % key ) @@ -666,7 +741,7 @@ def logout_user_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -674,7 +749,7 @@ def logout_user_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def update_user(self, username, body, **kwargs): # noqa: E501 + def update_user(self, username, body, _check_type=False, **kwargs): # noqa: E501 """Updated user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -692,12 +767,12 @@ def update_user(self, username, body, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.update_user_with_http_info(username, body, **kwargs) # noqa: E501 + return self.update_user_with_http_info(username, body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.update_user_with_http_info(username, body, **kwargs) # noqa: E501 + (data) = self.update_user_with_http_info(username, body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def update_user_with_http_info(self, username, body, **kwargs): # noqa: E501 + def update_user_with_http_info(self, username, body, _check_type=False, **kwargs): # noqa: E501 """Updated user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -724,20 +799,31 @@ def update_user_with_http_info(self, username, body, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method update_user" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'username': [str], + 'body': [User], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'username' is set if ('username' not in local_var_params or local_var_params['username'] is None): - raise ValueError("Missing the required parameter `username` when calling `update_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `username` when calling `update_user`") # noqa: E501 # verify the required parameter 'body' is set if ('body' not in local_var_params or local_var_params['body'] is None): - raise ValueError("Missing the required parameter `body` when calling `update_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `body` when calling `update_user`") # noqa: E501 collection_formats = {} @@ -766,7 +852,7 @@ def update_user_with_http_info(self, username, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python/petstore_api/api_client.py b/samples/client/petstore/python/petstore_api/api_client.py index a8f86aecf393..2be258b82b13 100644 --- a/samples/client/petstore/python/petstore_api/api_client.py +++ b/samples/client/petstore/python/petstore_api/api_client.py @@ -10,7 +10,7 @@ from __future__ import absolute_import -import datetime +import copy import json import mimetypes from multiprocessing.pool import ThreadPool @@ -23,6 +23,22 @@ from six.moves.urllib.parse import quote from petstore_api.configuration import Configuration +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( + OpenApiModel, + date, + datetime, + deserialize_file, + file_type, + model_to_dict, + none_type, + str, + validate_and_convert_types +) import petstore_api.models from petstore_api import rest @@ -49,17 +65,11 @@ class ApiClient(object): to the API. More threads means more concurrent API requests. """ - PRIMITIVE_TYPES = (float, bool, bytes, six.text_type) + six.integer_types - NATIVE_TYPES_MAPPING = { - 'int': int, - 'long': int if six.PY3 else long, # noqa: F821 - 'float': float, - 'str': str, - 'bool': bool, - 'date': datetime.date, - 'datetime': datetime.datetime, - 'object': object, - } + # six.binary_type python2=str, python3=bytes + # six.text_type python2=unicode, python3=str + PRIMITIVE_TYPES = ( + (float, bool, six.binary_type, six.text_type) + six.integer_types + ) _pool = None def __init__(self, configuration=None, header_name=None, header_value=None, @@ -107,7 +117,7 @@ def set_default_header(self, header_name, header_value): def __call_api( self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, - files=None, response_type=None, auth_settings=None, + files=None, response_types_mixed=None, auth_settings=None, _return_http_data_only=None, collection_formats=None, _preload_content=True, _request_timeout=None, _host=None): @@ -174,8 +184,9 @@ def __call_api( return_data = response_data if _preload_content: # deserialize response data - if response_type: - return_data = self.deserialize(response_data, response_type) + if response_types_mixed: + return_data = self.deserialize(response_data, + response_types_mixed) else: return_data = None @@ -209,89 +220,59 @@ def sanitize_for_serialization(self, obj): elif isinstance(obj, tuple): return tuple(self.sanitize_for_serialization(sub_obj) for sub_obj in obj) - elif isinstance(obj, (datetime.datetime, datetime.date)): + elif isinstance(obj, (datetime, date)): return obj.isoformat() if isinstance(obj, dict): obj_dict = obj else: - # Convert model obj to dict except - # attributes `openapi_types`, `attribute_map` - # and attributes which value is not None. + # Convert model obj to dict # Convert attribute name to json key in # model definition for request. - obj_dict = {obj.attribute_map[attr]: getattr(obj, attr) - for attr, _ in six.iteritems(obj.openapi_types) - if getattr(obj, attr) is not None} + obj_dict = model_to_dict(obj, serialize=True) return {key: self.sanitize_for_serialization(val) for key, val in six.iteritems(obj_dict)} - def deserialize(self, response, response_type): + def deserialize(self, response, response_types_mixed): """Deserializes response into an object. :param response: RESTResponse object to be deserialized. - :param response_type: class literal for - deserialized object, or string of class name. + :param response_types_mixed: For the response, a list of + valid classes, or a list tuples of valid classes, or a dict where + the value is a tuple of value classes. :return: deserialized object. """ # handle file downloading # save response body into a tmp file and return the instance - if response_type == "file": - return self.__deserialize_file(response) + if response_types_mixed == [file_type]: + content_disposition = response.getheader("Content-Disposition") + return deserialize_file(response.data, self.configuration, + content_disposition=content_disposition) # fetch data from response object try: - data = json.loads(response.data) + received_data = json.loads(response.data) except ValueError: - data = response.data + # this path is used if we are deserializing string data + received_data = response.data - return self.__deserialize(data, response_type) + # store our data under the key of 'received_data' so users have some + # context if they are deserializing a string and the data type is wrong + deserialized_data = validate_and_convert_types( + received_data, + response_types_mixed, + ['received_data'], + configuration=self.configuration + ) + return deserialized_data - def __deserialize(self, data, klass): - """Deserializes dict, list, str into an object. - - :param data: dict, list or str. - :param klass: class literal, or string of class name. - - :return: object. - """ - if data is None: - return None - - if type(klass) == str: - if klass.startswith('list['): - sub_kls = re.match(r'list\[(.*)\]', klass).group(1) - return [self.__deserialize(sub_data, sub_kls) - for sub_data in data] - - if klass.startswith('dict('): - sub_kls = re.match(r'dict\(([^,]*), (.*)\)', klass).group(2) - return {k: self.__deserialize(v, sub_kls) - for k, v in six.iteritems(data)} - - # convert str to class - if klass in self.NATIVE_TYPES_MAPPING: - klass = self.NATIVE_TYPES_MAPPING[klass] - else: - klass = getattr(petstore_api.models, klass) - - if klass in self.PRIMITIVE_TYPES: - return self.__deserialize_primitive(data, klass) - elif klass == object: - return self.__deserialize_object(data) - elif klass == datetime.date: - return self.__deserialize_date(data) - elif klass == datetime.datetime: - return self.__deserialize_datatime(data) - else: - return self.__deserialize_model(data, klass) def call_api(self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, files=None, - response_type=None, auth_settings=None, async_req=None, + response_types_mixed=None, auth_settings=None, async_req=None, _return_http_data_only=None, collection_formats=None, _preload_content=True, _request_timeout=None, _host=None): """Makes the HTTP request (synchronous) and returns deserialized data. @@ -308,7 +289,15 @@ def call_api(self, resource_path, method, :param post_params dict: Request post form parameters, for `application/x-www-form-urlencoded`, `multipart/form-data`. :param auth_settings list: Auth Settings names for the request. - :param response: Response data type. + :param response_types_mixed: For the response, a list of + valid classes, or a list tuples of valid classes, or a dict where + the value is a tuple of value classes. + Example values: + [str] + [Pet] + [float, none_type], + [[(int, none_type)]], + [{str: (bool, str, int, float, date, datetime, str, none_type)}] :param files dict: key -> filename, value -> filepath, for `multipart/form-data`. :param async_req bool: execute request asynchronously @@ -334,7 +323,7 @@ def call_api(self, resource_path, method, return self.__call_api(resource_path, method, path_params, query_params, header_params, body, post_params, files, - response_type, auth_settings, + response_types_mixed, auth_settings, _return_http_data_only, collection_formats, _preload_content, _request_timeout, _host) else: @@ -342,7 +331,7 @@ def call_api(self, resource_path, method, method, path_params, query_params, header_params, body, post_params, files, - response_type, auth_settings, + response_types_mixed, auth_settings, _return_http_data_only, collection_formats, _preload_content, @@ -406,7 +395,7 @@ def request(self, method, url, query_params=None, headers=None, _request_timeout=_request_timeout, body=body) else: - raise ValueError( + raise ApiValueError( "http method must be `GET`, `HEAD`, `OPTIONS`," " `POST`, `PATCH`, `PUT` or `DELETE`." ) @@ -521,120 +510,6 @@ def update_params_for_auth(self, headers, querys, auth_settings): elif auth_setting['in'] == 'query': querys.append((auth_setting['key'], auth_setting['value'])) else: - raise ValueError( + raise ApiValueError( 'Authentication token must be in `query` or `header`' ) - - def __deserialize_file(self, response): - """Deserializes body to file - - Saves response body into a file in a temporary folder, - using the filename from the `Content-Disposition` header if provided. - - :param response: RESTResponse. - :return: file path. - """ - fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path) - os.close(fd) - os.remove(path) - - content_disposition = response.getheader("Content-Disposition") - if content_disposition: - filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?', - content_disposition).group(1) - path = os.path.join(os.path.dirname(path), filename) - - with open(path, "wb") as f: - f.write(response.data) - - return path - - def __deserialize_primitive(self, data, klass): - """Deserializes string to primitive type. - - :param data: str. - :param klass: class literal. - - :return: int, long, float, str, bool. - """ - try: - return klass(data) - except UnicodeEncodeError: - return six.text_type(data) - except TypeError: - return data - - def __deserialize_object(self, value): - """Return an original value. - - :return: object. - """ - return value - - def __deserialize_date(self, string): - """Deserializes string to date. - - :param string: str. - :return: date. - """ - try: - from dateutil.parser import parse - return parse(string).date() - except ImportError: - return string - except ValueError: - raise rest.ApiException( - status=0, - reason="Failed to parse `{0}` as date object".format(string) - ) - - def __deserialize_datatime(self, string): - """Deserializes string to datetime. - - The string should be in iso8601 datetime format. - - :param string: str. - :return: datetime. - """ - try: - from dateutil.parser import parse - return parse(string) - except ImportError: - return string - except ValueError: - raise rest.ApiException( - status=0, - reason=( - "Failed to parse `{0}` as datetime object" - .format(string) - ) - ) - - def __deserialize_model(self, data, klass): - """Deserializes list or dict to model. - - :param data: dict, list. - :param klass: class literal. - :return: model object. - """ - - if not klass.openapi_types and not hasattr(klass, - 'get_real_child_model'): - return data - - kwargs = {} - if klass.openapi_types is not None: - for attr, attr_type in six.iteritems(klass.openapi_types): - if (data is not None and - klass.attribute_map[attr] in data and - isinstance(data, (list, dict))): - value = data[klass.attribute_map[attr]] - kwargs[attr] = self.__deserialize(value, attr_type) - - instance = klass(**kwargs) - - if hasattr(instance, 'get_real_child_model'): - klass_name = instance.get_real_child_model(data) - if klass_name: - instance = self.__deserialize(data, klass_name) - return instance diff --git a/samples/client/petstore/python/petstore_api/exceptions.py b/samples/client/petstore/python/petstore_api/exceptions.py new file mode 100644 index 000000000000..6bf34b3f9fa7 --- /dev/null +++ b/samples/client/petstore/python/petstore_api/exceptions.py @@ -0,0 +1,121 @@ +# 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: + is_int = isinstance(pth, int) + if six.PY2 and isinstance(pth, long) and is_int == False: + is_int = True + if is_int: + result += "[{0}]".format(pth) + else: + result += "['{0}']".format(pth) + return result diff --git a/samples/client/petstore/python/petstore_api/model_utils.py b/samples/client/petstore/python/petstore_api/model_utils.py new file mode 100644 index 000000000000..148a9cf683ea --- /dev/null +++ b/samples/client/petstore/python/petstore_api/model_utils.py @@ -0,0 +1,605 @@ +# 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 copy +from datetime import date, datetime # noqa: F401 +import os +import re +import tempfile + +from dateutil.parser import parse +import six + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) + +none_type = type(None) +if six.PY3: + import io + file_type = io.IOBase + # these are needed for when other modules import str and int from here + str = str + int = int +else: + file_type = file # noqa: F821 + str_py2 = str + unicode_py2 = unicode + long_py2 = long + int_py2 = int + # this requires that the future library is installed + from builtins import int, str + + +class OpenApiModel(object): + """The base class for all OpenAPIModels""" + + +def get_simple_class(input_value): + """Returns an input_value's simple class that we will use for type checking + Python2: + float and int will return int, where int is the python3 int backport + str and unicode will return str, where str is the python3 str backport + Note: float and int ARE both instances of int backport + Note: str_py2 and unicode_py2 are NOT both instances of str backport + + Args: + input_value (class/class_instance): the item for which we will return + the simple class + """ + if isinstance(input_value, type): + # input_value is a class + return input_value + elif isinstance(input_value, list): + return list + elif isinstance(input_value, dict): + return dict + elif isinstance(input_value, none_type): + return none_type + elif isinstance(input_value, file_type): + return file_type + elif isinstance(input_value, bool): + # this must be higher than the int check because + # isinstance(True, int) == True + return bool + elif isinstance(input_value, int): + # for python2 input_value==long_instance -> return int + # where int is the python3 int backport + return int + elif isinstance(input_value, datetime): + # this must be higher than the date check because + # isinstance(datetime_instance, date) == True + return datetime + elif isinstance(input_value, date): + return datetime + elif (six.PY2 and isinstance(input_value, (str_py2, unicode_py2, str)) or + isinstance(input_value, str)): + return str + return type(input_value) + + +COERCION_INDEX_BY_TYPE = { + none_type: 0, + list: 1, + OpenApiModel: 2, + dict: 3, + float: 4, + int: 5, + bool: 6, + datetime: 7, + date: 8, + str: 9 +} + +# these are used to limit what type conversions we try to do +# when we have a valid type already and we want to try converting +# to another type +UPCONVERSION_TYPE_PAIRS = ( + (str, datetime), + (str, date), + (list, OpenApiModel), + (dict, OpenApiModel), +) + +COERCIBLE_TYPE_PAIRS = ( + (dict, OpenApiModel), + (list, OpenApiModel), + (str, int), + (str, float), + (str, datetime), + (str, date), + (int, str), + (float, str), + (str, file_type) +) + + +def order_response_types(required_types): + """Returns the required types sorted in coercion order + + Args: + required_types (list/tuple): collection of classes or instance of + list or dict with classs information inside it + + Returns: + (list): coercion order sorted collection of classes or instance + of list or dict with classs information inside it + """ + + def index_getter(class_or_instance): + if isinstance(class_or_instance, list): + return COERCION_INDEX_BY_TYPE[list] + elif isinstance(class_or_instance, dict): + return COERCION_INDEX_BY_TYPE[dict] + elif issubclass(class_or_instance, OpenApiModel): + return COERCION_INDEX_BY_TYPE[OpenApiModel] + return COERCION_INDEX_BY_TYPE[class_or_instance] + + sorted_types = sorted( + required_types, + key=lambda class_or_instance: index_getter(class_or_instance) + ) + return sorted_types + + +def remove_uncoercible(required_types_classes, current_item, must_convert=True): + """Only keeps the type conversions that are possible + + Args: + required_types_classes (tuple): tuple of classes that are required + these should be ordered by COERCION_INDEX_BY_TYPE + current_item (any): the current item to be converted + + Keyword Args: + must_convert (bool): if True the item to convert is of the wrong + type and we want a big list of coercibles + if False, we want a limited list of coercibles + + Returns: + (list): the remaining coercible required types, classes only + """ + current_type_simple = get_simple_class(current_item) + + results_classes = [] + for required_type_class in required_types_classes: + # convert our models to OpenApiModel + required_type_class_simplified = required_type_class + if isinstance(required_type_class_simplified, type): + if issubclass(required_type_class_simplified, OpenApiModel): + required_type_class_simplified = OpenApiModel + + if required_type_class_simplified == current_type_simple: + # don't consider converting to one's own class + continue + + class_pair = (current_type_simple, required_type_class_simplified) + if must_convert and class_pair in COERCIBLE_TYPE_PAIRS: + results_classes.append(required_type_class) + elif class_pair in UPCONVERSION_TYPE_PAIRS: + results_classes.append(required_type_class) + return results_classes + + +def get_required_type_classes(required_types_mixed): + """Converts the tuple required_types into a tuple and a dict described + below + + Args: + required_types_mixed (tuple/list): will contain either classes or + instance of list or dict + + Returns: + (valid_classes, dict_valid_class_to_child_types_mixed): + valid_classes (tuple): the valid classes that the current item + should be + dict_valid_class_to_child_types_mixed (doct): + valid_class (class): this is the key + child_types_mixed (list/dict/tuple): describes the valid child + types + """ + valid_classes = [] + child_req_types_by_current_type = {} + for required_type in required_types_mixed: + if isinstance(required_type, list): + valid_classes.append(list) + child_req_types_by_current_type[list] = required_type[0] + elif isinstance(required_type, dict): + valid_classes.append(dict) + child_req_types_by_current_type[dict] = required_type[str] + else: + valid_classes.append(required_type) + return tuple(valid_classes), child_req_types_by_current_type + + +def change_keys_js_to_python(input_dict, model_class): + """ + Converts from javascript_key keys in the input_dict to python_keys in + the output dict using the mapping in model_class + """ + + output_dict = {} + reversed_attr_map = {value: key for key, value in + six.iteritems(model_class.attribute_map)} + for javascript_key, value in six.iteritems(input_dict): + python_key = reversed_attr_map.get(javascript_key) + if python_key is None: + # if the key is unknown, it is in error or it is an + # additionalProperties variable + python_key = javascript_key + output_dict[python_key] = value + return output_dict + + +def get_type_error(var_value, path_to_item, valid_classes, key_type=False): + error_msg = type_error_message( + var_name=path_to_item[-1], + var_value=var_value, + valid_classes=valid_classes, + key_type=key_type + ) + return ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=valid_classes, + key_type=key_type + ) + + +def deserialize_primitive(data, klass, path_to_item): + """Deserializes string to primitive type. + + :param data: str/int/float + :param klass: str/class the class to convert to + + :return: int, float, str, bool, date, datetime + """ + additional_message = "" + try: + if klass in {datetime, date}: + additional_message = ( + "If you need your parameter to have a fallback " + "string value, please set its type as `type: {}` in your " + "spec. That allows the value to be any type. " + ) + if klass == datetime: + if len(data) < 8: + raise ValueError("This is not a datetime") + # The string should be in iso8601 datetime format. + parsed_datetime = parse(data) + date_only = (parsed_datetime.hour == 0 and + parsed_datetime.minute == 0 and + parsed_datetime.second == 0 and + parsed_datetime.tzinfo == None and + 8 <= len(data) <= 10) + if date_only: + raise ValueError("This is a date, not a datetime") + return parsed_datetime + elif klass == date: + if len(data) < 8: + raise ValueError("This is not a date") + return parse(data).date() + else: + converted_value = klass(data) + if isinstance(data, str) and klass == float: + if str(converted_value) != data: + # '7' -> 7.0 -> '7.0' != '7' + raise ValueError('This is not a float') + return converted_value + except (OverflowError, ValueError): + # parse can raise OverflowError + raise ApiValueError( + "{0}Failed to parse {1} as {2}".format( + additional_message, repr(data), get_py3_class_name(klass) + ), + path_to_item=path_to_item + ) + + +def deserialize_model(model_data, model_class, path_to_item, configuration): + """Deserializes model_data to model instance. + + Args: + model_data (list/dict): data to instantiate the model + model_class (OpenApiModel): the model class + path_to_item (list): path to the model in the received data + configuration (Configuration): the instance to use to convert files + + Returns: + model instance + + Raise: + ApiTypeError + ApiValueError + ApiKeyError + """ + fixed_model_data = copy.deepcopy(model_data) + + if isinstance(fixed_model_data, dict): + fixed_model_data = change_keys_js_to_python(fixed_model_data, + model_class) + + kw_args = dict(_check_type=True, + _path_to_item=path_to_item, + _configuration=configuration) + if isinstance(model_data, list): + instance = model_class(*model_data, **kw_args) + elif isinstance(model_data, dict): + kw_args.update(fixed_model_data) + instance = model_class(**kw_args) + + if hasattr(instance, 'get_real_child_model'): + discriminator_class = instance.get_real_child_model(model_data) + if discriminator_class: + if isinstance(model_data, list): + instance = discriminator_class(*model_data, **kw_args) + elif isinstance(model_data, dict): + instance = discriminator_class(**kw_args) + + return instance + + +def deserialize_file(response_data, configuration, content_disposition=None): + """Deserializes body to file + + Saves response body into a file in a temporary folder, + using the filename from the `Content-Disposition` header if provided. + + Args: + param response_data (str): the file data to write + configuration (Configuration): the instance to use to convert files + + Keyword Args: + content_disposition (str): the value of the Content-Disposition + header + + Returns: + (str): the deserialized file path + """ + fd, path = tempfile.mkstemp(dir=configuration.temp_folder_path) + os.close(fd) + os.remove(path) + + if content_disposition: + filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?', + content_disposition).group(1) + path = os.path.join(os.path.dirname(path), filename) + + with open(path, "wb") as f: + if six.PY3 and isisinstance(response_data, str): + # in python3 change str to bytes so we can write it + response_data = response_data.encode('utf-8') + f.write(response_data) + + return path + + +def attempt_convert_item(input_value, valid_classes, path_to_item, + configuration, key_type=False, must_convert=False): + """ + Args: + input_value (any): the data to convert + valid_classes (any): the classes that are valid + path_to_item (list): the path to the item to convert + configuration (Configuration): the instance to use to convert files + key_type (bool): if True we need to convert a key type (not supported) + must_convert (bool): if True we must convert + + Returns: + instance (any) the fixed item + + Raises: + ApiTypeError + ApiValueError + ApiKeyError + """ + valid_classes_ordered = order_response_types(valid_classes) + valid_classes_coercible = remove_uncoercible( + valid_classes_ordered, input_value) + if not valid_classes_coercible or key_type: + # we do not handle keytype errors, json will take care + # of this for us + raise get_type_error(input_value, path_to_item, valid_classes, + key_type=key_type) + deserialized_item = None + for valid_class in valid_classes_coercible: + try: + if issubclass(valid_class, OpenApiModel): + return deserialize_model(input_value, valid_class, + path_to_item, configuration) + elif valid_class == file_type: + return deserialize_file(input_value, configuration) + return deserialize_primitive(input_value, valid_class, + path_to_item) + except (ApiTypeError, ApiValueError, ApiKeyError) as conversion_exc: + if must_convert: + raise conversion_exc + # if we have conversion errors when must_convert == False + # we ignore the exception and move on to the next class + continue + # we were unable to convert, must_convert == False + return input_value + + +def validate_and_convert_types(input_value, required_types_mixed, path_to_item, + configuration=None): + """Raises a TypeError is there is a problem, otherwise returns value + + Args: + input_value (any): the data to validate/convert + required_types_mixed (list/dict/tuple): A list of + valid classes, or a list tuples of valid classes, or a dict where + the value is a tuple of value classes + path_to_item: (list) the path to the data being validated + this stores a list of keys or indices to get to the data being + validated + configuration: (Configuration): the configuration class to use + when converting file_type items. + If passed, conversion will be attempted when possible + If not passed, no conversions will be attempted and + exceptions will be raised + + Returns: + the correctly typed value + + Raises: + ApiTypeError + """ + results = get_required_type_classes(required_types_mixed) + valid_classes, child_req_types_by_current_type = results + + input_class_simple = get_simple_class(input_value) + valid_type = input_class_simple in set(valid_classes) + if not valid_type: + if configuration: + # if input_value is not valid_type try to convert it + converted_instance = attempt_convert_item(input_value, + valid_classes, path_to_item, configuration, key_type=False, + must_convert=True) + return converted_instance + else: + raise get_type_error(input_value, path_to_item, valid_classes, + key_type=False) + + # input_value's type is in valid_classes + if len(valid_classes) > 1 and configuration: + # there are valid classes which are not the current class + valid_classes_coercible = remove_uncoercible( + valid_classes, input_value, must_convert=False) + if valid_classes_coercible: + converted_instance = attempt_convert_item(input_value, + valid_classes_coercible, path_to_item, configuration, + key_type=False, must_convert=False) + return converted_instance + + if child_req_types_by_current_type == {}: + # all types are of the required types and there are no more inner + # variables left to look at + return input_value + inner_required_types = child_req_types_by_current_type.get( + type(input_value) + ) + if inner_required_types is None: + # for this type, there are not more inner variables left to look at + return input_value + if isinstance(input_value, list): + if input_value == []: + # allow an empty list + return input_value + for index, inner_value in enumerate(input_value): + inner_path = list(path_to_item) + inner_path.append(index) + input_value[index] = validate_and_convert_types(inner_value, + inner_required_types, inner_path, configuration=configuration) + elif isinstance(input_value, dict): + if input_value == {}: + # allow an empty dict + return input_value + for inner_key, inner_val in six.iteritems(input_value): + inner_path = list(path_to_item) + inner_path.append(inner_key) + if get_simple_class(inner_key) != str: + raise get_type_error(inner_key, inner_path, valid_classes, + key_type=True) + input_value[inner_key] = validate_and_convert_types(inner_val, + inner_required_types, inner_path, configuration=configuration) + return input_value + + +def model_to_dict(model_instance, serialize=True): + """Returns the model properties as a dict + + Args: + model_instance (one of your model instances): the model instance that + will be converted to a dict. + + Keyword Args: + serialize (bool): if True, the keys in the dict will be values from + attribute_map + """ + result = {} + + for attr, value in six.iteritems(model_instance._data_store): + if serialize: + attr = model_instance.attribute_map[attr] + if isinstance(value, list): + result[attr] = list(map( + lambda x: model_to_dict(x, serialize=serialize) + if hasattr(x, '_data_store') else x, value + )) + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], + model_to_dict(item[1], serialize=serialize)) + if hasattr(item[1], '_data_store') else item, + value.items() + )) + elif hasattr(value, '_data_store'): + result[attr] = model_to_dict(value, serialize=serialize) + else: + result[attr] = value + + return result + + +def type_error_message(var_value=None, var_name=None, valid_classes=None, + key_type=None): + """ + Keyword Args: + var_value (any): the variable which has the type_error + var_name (str): the name of the variable which has the typ error + valid_classes (tuple): the accepted classes for current_item's + value + 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 + """ + key_or_value = 'value' + if key_type: + key_or_value = 'key' + valid_classes_phrase = get_valid_classes_phrase(valid_classes) + msg = ( + "Invalid type for variable '{0}'. Required {1} type {2} and " + "passed type was {3}".format( + var_name, + key_or_value, + valid_classes_phrase, + type(var_value).__name__, + ) + ) + return msg + + +def get_valid_classes_phrase(input_classes): + """Returns a string phrase describing what types are allowed + Note: Adds the extra valid classes in python2 + """ + all_classes = list(input_classes) + if six.PY2 and str in input_classes: + all_classes.extend([str_py2, unicode_py2]) + if six.PY2 and int in input_classes: + all_classes.extend([int_py2, long_py2]) + all_classes = sorted(all_classes, key=lambda cls: cls.__name__) + all_class_names = [cls.__name__ for cls in all_classes] + if len(all_class_names) == 1: + return 'is {0}'.format(all_class_names[0]) + return "is one of [{0}]".format(", ".join(all_class_names)) + + +def get_py3_class_name(input_class): + if six.PY2: + if input_class == str: + return 'str' + elif input_class == int: + return 'int' + return input_class.__name__ diff --git a/samples/client/petstore/python/petstore_api/models/__init__.py b/samples/client/petstore/python/petstore_api/models/__init__.py index 3a39467a63ac..9c318d971f6f 100644 --- a/samples/client/petstore/python/petstore_api/models/__init__.py +++ b/samples/client/petstore/python/petstore_api/models/__init__.py @@ -14,7 +14,14 @@ from __future__ import absolute_import # import models into model package +from petstore_api.models.additional_properties_any_type import AdditionalPropertiesAnyType +from petstore_api.models.additional_properties_array import AdditionalPropertiesArray +from petstore_api.models.additional_properties_boolean import AdditionalPropertiesBoolean from petstore_api.models.additional_properties_class import AdditionalPropertiesClass +from petstore_api.models.additional_properties_integer import AdditionalPropertiesInteger +from petstore_api.models.additional_properties_number import AdditionalPropertiesNumber +from petstore_api.models.additional_properties_object import AdditionalPropertiesObject +from petstore_api.models.additional_properties_string import AdditionalPropertiesString from petstore_api.models.animal import Animal from petstore_api.models.api_response import ApiResponse from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly diff --git a/samples/client/petstore/python/petstore_api/models/additional_properties_any_type.py b/samples/client/petstore/python/petstore_api/models/additional_properties_any_type.py new file mode 100644 index 000000000000..2438b307cf8b --- /dev/null +++ b/samples/client/petstore/python/petstore_api/models/additional_properties_any_type.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesAnyType(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [bool, date, datetime, dict, float, int, list, str] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesAnyType - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesAnyType. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesAnyType. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesAnyType. + + + Returns: + (str): The name of this AdditionalPropertiesAnyType. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesAnyType): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python/petstore_api/models/additional_properties_array.py b/samples/client/petstore/python/petstore_api/models/additional_properties_array.py new file mode 100644 index 000000000000..ba0306157ff9 --- /dev/null +++ b/samples/client/petstore/python/petstore_api/models/additional_properties_array.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesArray(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [[(bool, date, datetime, dict, float, int, list, str)]] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesArray - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesArray. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesArray. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesArray. + + + Returns: + (str): The name of this AdditionalPropertiesArray. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesArray): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python/petstore_api/models/additional_properties_boolean.py b/samples/client/petstore/python/petstore_api/models/additional_properties_boolean.py new file mode 100644 index 000000000000..4d59de6fe53b --- /dev/null +++ b/samples/client/petstore/python/petstore_api/models/additional_properties_boolean.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesBoolean(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [bool] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesBoolean - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesBoolean. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesBoolean. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesBoolean. + + + Returns: + (str): The name of this AdditionalPropertiesBoolean. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesBoolean): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python/petstore_api/models/additional_properties_class.py b/samples/client/petstore/python/petstore_api/models/additional_properties_class.py index dc4648ae1c7f..a38defb2045e 100644 --- a/samples/client/petstore/python/petstore_api/models/additional_properties_class.py +++ b/samples/client/petstore/python/petstore_api/models/additional_properties_class.py @@ -15,8 +15,27 @@ import six - -class AdditionalPropertiesClass(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesClass(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +46,415 @@ class AdditionalPropertiesClass(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'map_property': 'dict(str, str)', - 'map_of_map_property': 'dict(str, dict(str, str))' + 'map_string': [{str: (str,)}], # noqa: E501 + 'map_number': [{str: (float,)}], # noqa: E501 + 'map_integer': [{str: (int,)}], # noqa: E501 + 'map_boolean': [{str: (bool,)}], # noqa: E501 + 'map_array_integer': [{str: ([(int,)],)}], # noqa: E501 + 'map_array_anytype': [{str: ([(bool, date, datetime, dict, float, int, list, str)],)}], # noqa: E501 + 'map_map_string': [{str: ({str: (str,)},)}], # noqa: E501 + 'map_map_anytype': [{str: ({str: (bool, date, datetime, dict, float, int, list, str)},)}], # noqa: E501 + 'anytype_1': [bool, date, datetime, dict, float, int, list, str], # noqa: E501 + 'anytype_2': [bool, date, datetime, dict, float, int, list, str], # noqa: E501 + 'anytype_3': [bool, date, datetime, dict, float, int, list, str] # noqa: E501 } - attribute_map = { - 'map_property': 'map_property', - 'map_of_map_property': 'map_of_map_property' + 'map_string': 'map_string', # noqa: E501 + 'map_number': 'map_number', # noqa: E501 + 'map_integer': 'map_integer', # noqa: E501 + 'map_boolean': 'map_boolean', # noqa: E501 + 'map_array_integer': 'map_array_integer', # noqa: E501 + 'map_array_anytype': 'map_array_anytype', # noqa: E501 + 'map_map_string': 'map_map_string', # noqa: E501 + 'map_map_anytype': 'map_map_anytype', # noqa: E501 + 'anytype_1': 'anytype_1', # noqa: E501 + 'anytype_2': 'anytype_2', # noqa: E501 + 'anytype_3': 'anytype_3' # noqa: E501 } - def __init__(self, map_property=None, map_of_map_property=None): # noqa: E501 - """AdditionalPropertiesClass - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesClass - 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 False + _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 + _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. + map_string ({str: (str,)}): [optional] # noqa: E501 + map_number ({str: (float,)}): [optional] # noqa: E501 + map_integer ({str: (int,)}): [optional] # noqa: E501 + map_boolean ({str: (bool,)}): [optional] # noqa: E501 + map_array_integer ({str: ([(int,)],)}): [optional] # noqa: E501 + map_array_anytype ({str: ([(bool, date, datetime, dict, float, int, list, str)],)}): [optional] # noqa: E501 + map_map_string ({str: ({str: (str,)},)}): [optional] # noqa: E501 + map_map_anytype ({str: ({str: (bool, date, datetime, dict, float, int, list, str)},)}): [optional] # noqa: E501 + anytype_1 (bool, date, datetime, dict, float, int, list, str): [optional] # noqa: E501 + anytype_2 (bool, date, datetime, dict, float, int, list, str): [optional] # noqa: E501 + anytype_3 (bool, date, datetime, dict, float, int, list, str): [optional] # noqa: E501 + """ - self._map_property = None - self._map_of_map_property = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def map_string(self): + """Gets the map_string of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + ({str: (str,)}): The map_string of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('map_string') + + @map_string.setter + def map_string( + self, map_string): + """Sets the map_string of this AdditionalPropertiesClass. + + + Returns: + ({str: (str,)}): The map_string of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'map_string', + map_string + ) + + @property + def map_number(self): + """Gets the map_number of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + ({str: (float,)}): The map_number of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('map_number') + + @map_number.setter + def map_number( + self, map_number): + """Sets the map_number of this AdditionalPropertiesClass. + + + Returns: + ({str: (float,)}): The map_number of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'map_number', + map_number + ) + + @property + def map_integer(self): + """Gets the map_integer of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + ({str: (int,)}): The map_integer of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('map_integer') + + @map_integer.setter + def map_integer( + self, map_integer): + """Sets the map_integer of this AdditionalPropertiesClass. + + + Returns: + ({str: (int,)}): The map_integer of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'map_integer', + map_integer + ) + + @property + def map_boolean(self): + """Gets the map_boolean of this AdditionalPropertiesClass. # noqa: E501 - if map_property is not None: - self.map_property = map_property - if map_of_map_property is not None: - self.map_of_map_property = map_of_map_property + + Returns: + ({str: (bool,)}): The map_boolean of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('map_boolean') + + @map_boolean.setter + def map_boolean( + self, map_boolean): + """Sets the map_boolean of this AdditionalPropertiesClass. + + + Returns: + ({str: (bool,)}): The map_boolean of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'map_boolean', + map_boolean + ) @property - def map_property(self): - """Gets the map_property of this AdditionalPropertiesClass. # noqa: E501 + def map_array_integer(self): + """Gets the map_array_integer of this AdditionalPropertiesClass. # noqa: E501 - :return: The map_property of this AdditionalPropertiesClass. # noqa: E501 - :rtype: dict(str, str) + Returns: + ({str: ([(int,)],)}): The map_array_integer of this AdditionalPropertiesClass. # noqa: E501 """ - return self._map_property + return self._data_store.get('map_array_integer') - @map_property.setter - def map_property(self, map_property): - """Sets the map_property of this AdditionalPropertiesClass. + @map_array_integer.setter + def map_array_integer( + self, map_array_integer): + """Sets the map_array_integer of this AdditionalPropertiesClass. - :param map_property: The map_property of this AdditionalPropertiesClass. # noqa: E501 - :type: dict(str, str) + Returns: + ({str: ([(int,)],)}): The map_array_integer of this AdditionalPropertiesClass. # noqa: E501 """ - self._map_property = map_property + self.__setitem__( + 'map_array_integer', + map_array_integer + ) @property - def map_of_map_property(self): - """Gets the map_of_map_property of this AdditionalPropertiesClass. # noqa: E501 + def map_array_anytype(self): + """Gets the map_array_anytype of this AdditionalPropertiesClass. # noqa: E501 - :return: The map_of_map_property of this AdditionalPropertiesClass. # noqa: E501 - :rtype: dict(str, dict(str, str)) + Returns: + ({str: ([(bool, date, datetime, dict, float, int, list, str)],)}): The map_array_anytype of this AdditionalPropertiesClass. # noqa: E501 """ - return self._map_of_map_property + return self._data_store.get('map_array_anytype') - @map_of_map_property.setter - def map_of_map_property(self, map_of_map_property): - """Sets the map_of_map_property of this AdditionalPropertiesClass. + @map_array_anytype.setter + def map_array_anytype( + self, map_array_anytype): + """Sets the map_array_anytype of this AdditionalPropertiesClass. - :param map_of_map_property: The map_of_map_property of this AdditionalPropertiesClass. # noqa: E501 - :type: dict(str, dict(str, str)) + Returns: + ({str: ([(bool, date, datetime, dict, float, int, list, str)],)}): The map_array_anytype of this AdditionalPropertiesClass. # noqa: E501 """ - self._map_of_map_property = map_of_map_property + self.__setitem__( + 'map_array_anytype', + map_array_anytype + ) + + @property + def map_map_string(self): + """Gets the map_map_string of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + ({str: ({str: (str,)},)}): The map_map_string of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('map_map_string') + + @map_map_string.setter + def map_map_string( + self, map_map_string): + """Sets the map_map_string of this AdditionalPropertiesClass. + + + Returns: + ({str: ({str: (str,)},)}): The map_map_string of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'map_map_string', + map_map_string + ) + + @property + def map_map_anytype(self): + """Gets the map_map_anytype of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + ({str: ({str: (bool, date, datetime, dict, float, int, list, str)},)}): The map_map_anytype of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('map_map_anytype') + + @map_map_anytype.setter + def map_map_anytype( + self, map_map_anytype): + """Sets the map_map_anytype of this AdditionalPropertiesClass. + + + Returns: + ({str: ({str: (bool, date, datetime, dict, float, int, list, str)},)}): The map_map_anytype of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'map_map_anytype', + map_map_anytype + ) + + @property + def anytype_1(self): + """Gets the anytype_1 of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + (bool, date, datetime, dict, float, int, list, str): The anytype_1 of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('anytype_1') + + @anytype_1.setter + def anytype_1( + self, anytype_1): + """Sets the anytype_1 of this AdditionalPropertiesClass. + + + Returns: + (bool, date, datetime, dict, float, int, list, str): The anytype_1 of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'anytype_1', + anytype_1 + ) + + @property + def anytype_2(self): + """Gets the anytype_2 of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + (bool, date, datetime, dict, float, int, list, str): The anytype_2 of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('anytype_2') + + @anytype_2.setter + def anytype_2( + self, anytype_2): + """Sets the anytype_2 of this AdditionalPropertiesClass. + + + Returns: + (bool, date, datetime, dict, float, int, list, str): The anytype_2 of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'anytype_2', + anytype_2 + ) + + @property + def anytype_3(self): + """Gets the anytype_3 of this AdditionalPropertiesClass. # noqa: E501 + + + Returns: + (bool, date, datetime, dict, float, int, list, str): The anytype_3 of this AdditionalPropertiesClass. # noqa: E501 + """ + return self._data_store.get('anytype_3') + + @anytype_3.setter + def anytype_3( + self, anytype_3): + """Sets the anytype_3 of this AdditionalPropertiesClass. + + + Returns: + (bool, date, datetime, dict, float, int, list, str): The anytype_3 of this AdditionalPropertiesClass. # noqa: E501 + """ + + self.__setitem__( + 'anytype_3', + anytype_3 + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/additional_properties_integer.py b/samples/client/petstore/python/petstore_api/models/additional_properties_integer.py new file mode 100644 index 000000000000..50994b5859e2 --- /dev/null +++ b/samples/client/petstore/python/petstore_api/models/additional_properties_integer.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesInteger(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [int] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesInteger - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesInteger. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesInteger. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesInteger. + + + Returns: + (str): The name of this AdditionalPropertiesInteger. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesInteger): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python/petstore_api/models/additional_properties_number.py b/samples/client/petstore/python/petstore_api/models/additional_properties_number.py new file mode 100644 index 000000000000..6005bf6a2f55 --- /dev/null +++ b/samples/client/petstore/python/petstore_api/models/additional_properties_number.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesNumber(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [float] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesNumber - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesNumber. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesNumber. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesNumber. + + + Returns: + (str): The name of this AdditionalPropertiesNumber. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesNumber): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python/petstore_api/models/additional_properties_object.py b/samples/client/petstore/python/petstore_api/models/additional_properties_object.py new file mode 100644 index 000000000000..6b18c3e18f30 --- /dev/null +++ b/samples/client/petstore/python/petstore_api/models/additional_properties_object.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesObject(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [{str: (bool, date, datetime, dict, float, int, list, str)}] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesObject - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesObject. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesObject. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesObject. + + + Returns: + (str): The name of this AdditionalPropertiesObject. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesObject): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python/petstore_api/models/additional_properties_string.py b/samples/client/petstore/python/petstore_api/models/additional_properties_string.py new file mode 100644 index 000000000000..61d7e0278d63 --- /dev/null +++ b/samples/client/petstore/python/petstore_api/models/additional_properties_string.py @@ -0,0 +1,198 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesString(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'name': [str] # noqa: E501 + } + attribute_map = { + 'name': 'name' # noqa: E501 + } + additional_properties_type = [str] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesString - 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 False + _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 + _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. + name (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def name(self): + """Gets the name of this AdditionalPropertiesString. # noqa: E501 + + + Returns: + (str): The name of this AdditionalPropertiesString. # noqa: E501 + """ + return self._data_store.get('name') + + @name.setter + def name( + self, name): + """Sets the name of this AdditionalPropertiesString. + + + Returns: + (str): The name of this AdditionalPropertiesString. # noqa: E501 + """ + + self.__setitem__( + 'name', + name + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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, AdditionalPropertiesString): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other diff --git a/samples/client/petstore/python/petstore_api/models/animal.py b/samples/client/petstore/python/petstore_api/models/animal.py index abd6f705e5e8..ba09d8520ca1 100644 --- a/samples/client/petstore/python/petstore_api/models/animal.py +++ b/samples/client/petstore/python/petstore_api/models/animal.py @@ -15,8 +15,29 @@ import six - -class Animal(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.cat import Cat +from petstore_api.models.dog import Dog + + +class Animal(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,78 +48,167 @@ class Animal(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'class_name': 'str', - 'color': 'str' + 'class_name': [str], # noqa: E501 + 'color': [str] # noqa: E501 } - attribute_map = { - 'class_name': 'className', - 'color': 'color' + 'class_name': 'className', # noqa: E501 + 'color': 'color' # noqa: E501 } - discriminator_value_class_map = { - 'Dog': 'Dog', - 'Cat': 'Cat' + 'Dog': Dog, + 'Cat': Cat } - def __init__(self, class_name=None, color='red'): # noqa: E501 - """Animal - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, class_name, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Animal - a model defined in OpenAPI + + Args: + class_name (str): + + 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 False + _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 + _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. + color (str): [optional] if omitted the server will use the default value of 'red' # noqa: E501 + """ - self._class_name = None - self._color = None + self._data_store = {} self.discriminator = 'class_name' + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + # assign using .var_name to check against nullable and enums self.class_name = class_name - if color is not None: - self.color = color + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def class_name(self): """Gets the class_name of this Animal. # noqa: E501 - :return: The class_name of this Animal. # noqa: E501 - :rtype: str + Returns: + (str): The class_name of this Animal. # noqa: E501 """ - return self._class_name + return self._data_store.get('class_name') @class_name.setter - def class_name(self, class_name): + def class_name( + self, class_name): """Sets the class_name of this Animal. - :param class_name: The class_name of this Animal. # noqa: E501 - :type: str + Returns: + (str): The class_name of this Animal. # noqa: E501 """ if class_name is None: - raise ValueError("Invalid value for `class_name`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `class_name`, must not be `None`") # noqa: E501 - self._class_name = class_name + self.__setitem__( + 'class_name', + class_name + ) @property def color(self): """Gets the color of this Animal. # noqa: E501 - :return: The color of this Animal. # noqa: E501 - :rtype: str + Returns: + (str): The color of this Animal. # noqa: E501 """ - return self._color + return self._data_store.get('color') @color.setter - def color(self, color): + def color( + self, color): """Sets the color of this Animal. - :param color: The color of this Animal. # noqa: E501 - :type: str + Returns: + (str): The color of this Animal. # noqa: E501 """ - self._color = color + self.__setitem__( + 'color', + color + ) def get_real_child_model(self, data): """Returns the real base class specified by the discriminator""" @@ -108,27 +218,7 @@ def get_real_child_model(self, data): 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/api_response.py b/samples/client/petstore/python/petstore_api/models/api_response.py index e62983030491..50fcf50f5207 100644 --- a/samples/client/petstore/python/petstore_api/models/api_response.py +++ b/samples/client/petstore/python/petstore_api/models/api_response.py @@ -15,8 +15,27 @@ import six - -class ApiResponse(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ApiResponse(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,122 +46,191 @@ class ApiResponse(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'code': 'int', - 'type': 'str', - 'message': 'str' + 'code': [int], # noqa: E501 + 'type': [str], # noqa: E501 + 'message': [str] # noqa: E501 } - attribute_map = { - 'code': 'code', - 'type': 'type', - 'message': 'message' + 'code': 'code', # noqa: E501 + 'type': 'type', # noqa: E501 + 'message': 'message' # noqa: E501 } - def __init__(self, code=None, type=None, message=None): # noqa: E501 - """ApiResponse - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ApiResponse - 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 False + _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 + _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. + code (int): [optional] # noqa: E501 + type (str): [optional] # noqa: E501 + message (str): [optional] # noqa: E501 + """ - self._code = None - self._type = None - self._message = None + self._data_store = {} self.discriminator = None - - if code is not None: - self.code = code - if type is not None: - self.type = type - if message is not None: - self.message = message + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def code(self): """Gets the code of this ApiResponse. # noqa: E501 - :return: The code of this ApiResponse. # noqa: E501 - :rtype: int + Returns: + (int): The code of this ApiResponse. # noqa: E501 """ - return self._code + return self._data_store.get('code') @code.setter - def code(self, code): + def code( + self, code): """Sets the code of this ApiResponse. - :param code: The code of this ApiResponse. # noqa: E501 - :type: int + Returns: + (int): The code of this ApiResponse. # noqa: E501 """ - self._code = code + self.__setitem__( + 'code', + code + ) @property def type(self): """Gets the type of this ApiResponse. # noqa: E501 - :return: The type of this ApiResponse. # noqa: E501 - :rtype: str + Returns: + (str): The type of this ApiResponse. # noqa: E501 """ - return self._type + return self._data_store.get('type') @type.setter - def type(self, type): + def type( + self, type): """Sets the type of this ApiResponse. - :param type: The type of this ApiResponse. # noqa: E501 - :type: str + Returns: + (str): The type of this ApiResponse. # noqa: E501 """ - self._type = type + self.__setitem__( + 'type', + type + ) @property def message(self): """Gets the message of this ApiResponse. # noqa: E501 - :return: The message of this ApiResponse. # noqa: E501 - :rtype: str + Returns: + (str): The message of this ApiResponse. # noqa: E501 """ - return self._message + return self._data_store.get('message') @message.setter - def message(self, message): + def message( + self, message): """Sets the message of this ApiResponse. - :param message: The message of this ApiResponse. # noqa: E501 - :type: str + Returns: + (str): The message of this ApiResponse. # noqa: E501 """ - self._message = message + self.__setitem__( + 'message', + message + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/array_of_array_of_number_only.py b/samples/client/petstore/python/petstore_api/models/array_of_array_of_number_only.py index fde218a4661c..407b261c7f34 100644 --- a/samples/client/petstore/python/petstore_api/models/array_of_array_of_number_only.py +++ b/samples/client/petstore/python/petstore_api/models/array_of_array_of_number_only.py @@ -15,8 +15,27 @@ import six - -class ArrayOfArrayOfNumberOnly(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ArrayOfArrayOfNumberOnly(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class ArrayOfArrayOfNumberOnly(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'array_array_number': 'list[list[float]]' + 'array_array_number': [[([(float,)],)]] # noqa: E501 } - attribute_map = { - 'array_array_number': 'ArrayArrayNumber' + 'array_array_number': 'ArrayArrayNumber' # noqa: E501 } - def __init__(self, array_array_number=None): # noqa: E501 - """ArrayOfArrayOfNumberOnly - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ArrayOfArrayOfNumberOnly - a model defined in OpenAPI - self._array_array_number = None - self.discriminator = None - if array_array_number is not None: - self.array_array_number = array_array_number + + 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 False + _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 + _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. + array_array_number ([([(float,)],)]): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def array_array_number(self): """Gets the array_array_number of this ArrayOfArrayOfNumberOnly. # noqa: E501 - :return: The array_array_number of this ArrayOfArrayOfNumberOnly. # noqa: E501 - :rtype: list[list[float]] + Returns: + ([([(float,)],)]): The array_array_number of this ArrayOfArrayOfNumberOnly. # noqa: E501 """ - return self._array_array_number + return self._data_store.get('array_array_number') @array_array_number.setter - def array_array_number(self, array_array_number): + def array_array_number( + self, array_array_number): """Sets the array_array_number of this ArrayOfArrayOfNumberOnly. - :param array_array_number: The array_array_number of this ArrayOfArrayOfNumberOnly. # noqa: E501 - :type: list[list[float]] + Returns: + ([([(float,)],)]): The array_array_number of this ArrayOfArrayOfNumberOnly. # noqa: E501 """ - self._array_array_number = array_array_number + self.__setitem__( + 'array_array_number', + array_array_number + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/array_of_number_only.py b/samples/client/petstore/python/petstore_api/models/array_of_number_only.py index 8999e563c4a6..790a6761dc06 100644 --- a/samples/client/petstore/python/petstore_api/models/array_of_number_only.py +++ b/samples/client/petstore/python/petstore_api/models/array_of_number_only.py @@ -15,8 +15,27 @@ import six - -class ArrayOfNumberOnly(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ArrayOfNumberOnly(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class ArrayOfNumberOnly(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'array_number': 'list[float]' + 'array_number': [[(float,)]] # noqa: E501 } - attribute_map = { - 'array_number': 'ArrayNumber' + 'array_number': 'ArrayNumber' # noqa: E501 } - def __init__(self, array_number=None): # noqa: E501 - """ArrayOfNumberOnly - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ArrayOfNumberOnly - a model defined in OpenAPI - self._array_number = None - self.discriminator = None - if array_number is not None: - self.array_number = array_number + + 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 False + _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 + _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. + array_number ([(float,)]): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def array_number(self): """Gets the array_number of this ArrayOfNumberOnly. # noqa: E501 - :return: The array_number of this ArrayOfNumberOnly. # noqa: E501 - :rtype: list[float] + Returns: + ([(float,)]): The array_number of this ArrayOfNumberOnly. # noqa: E501 """ - return self._array_number + return self._data_store.get('array_number') @array_number.setter - def array_number(self, array_number): + def array_number( + self, array_number): """Sets the array_number of this ArrayOfNumberOnly. - :param array_number: The array_number of this ArrayOfNumberOnly. # noqa: E501 - :type: list[float] + Returns: + ([(float,)]): The array_number of this ArrayOfNumberOnly. # noqa: E501 """ - self._array_number = array_number + self.__setitem__( + 'array_number', + array_number + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/array_test.py b/samples/client/petstore/python/petstore_api/models/array_test.py index 05cc108139a5..63e94762f367 100644 --- a/samples/client/petstore/python/petstore_api/models/array_test.py +++ b/samples/client/petstore/python/petstore_api/models/array_test.py @@ -15,8 +15,28 @@ import six - -class ArrayTest(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.read_only_first import ReadOnlyFirst + + +class ArrayTest(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,122 +47,191 @@ class ArrayTest(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'array_of_string': 'list[str]', - 'array_array_of_integer': 'list[list[int]]', - 'array_array_of_model': 'list[list[ReadOnlyFirst]]' + 'array_of_string': [[(str,)]], # noqa: E501 + 'array_array_of_integer': [[([(int,)],)]], # noqa: E501 + 'array_array_of_model': [[([(ReadOnlyFirst,)],)]] # noqa: E501 } - attribute_map = { - 'array_of_string': 'array_of_string', - 'array_array_of_integer': 'array_array_of_integer', - 'array_array_of_model': 'array_array_of_model' + 'array_of_string': 'array_of_string', # noqa: E501 + 'array_array_of_integer': 'array_array_of_integer', # noqa: E501 + 'array_array_of_model': 'array_array_of_model' # noqa: E501 } - def __init__(self, array_of_string=None, array_array_of_integer=None, array_array_of_model=None): # noqa: E501 - """ArrayTest - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ArrayTest - 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 False + _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 + _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. + array_of_string ([(str,)]): [optional] # noqa: E501 + array_array_of_integer ([([(int,)],)]): [optional] # noqa: E501 + array_array_of_model ([([(ReadOnlyFirst,)],)]): [optional] # noqa: E501 + """ - self._array_of_string = None - self._array_array_of_integer = None - self._array_array_of_model = None + self._data_store = {} self.discriminator = None - - if array_of_string is not None: - self.array_of_string = array_of_string - if array_array_of_integer is not None: - self.array_array_of_integer = array_array_of_integer - if array_array_of_model is not None: - self.array_array_of_model = array_array_of_model + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def array_of_string(self): """Gets the array_of_string of this ArrayTest. # noqa: E501 - :return: The array_of_string of this ArrayTest. # noqa: E501 - :rtype: list[str] + Returns: + ([(str,)]): The array_of_string of this ArrayTest. # noqa: E501 """ - return self._array_of_string + return self._data_store.get('array_of_string') @array_of_string.setter - def array_of_string(self, array_of_string): + def array_of_string( + self, array_of_string): """Sets the array_of_string of this ArrayTest. - :param array_of_string: The array_of_string of this ArrayTest. # noqa: E501 - :type: list[str] + Returns: + ([(str,)]): The array_of_string of this ArrayTest. # noqa: E501 """ - self._array_of_string = array_of_string + self.__setitem__( + 'array_of_string', + array_of_string + ) @property def array_array_of_integer(self): """Gets the array_array_of_integer of this ArrayTest. # noqa: E501 - :return: The array_array_of_integer of this ArrayTest. # noqa: E501 - :rtype: list[list[int]] + Returns: + ([([(int,)],)]): The array_array_of_integer of this ArrayTest. # noqa: E501 """ - return self._array_array_of_integer + return self._data_store.get('array_array_of_integer') @array_array_of_integer.setter - def array_array_of_integer(self, array_array_of_integer): + def array_array_of_integer( + self, array_array_of_integer): """Sets the array_array_of_integer of this ArrayTest. - :param array_array_of_integer: The array_array_of_integer of this ArrayTest. # noqa: E501 - :type: list[list[int]] + Returns: + ([([(int,)],)]): The array_array_of_integer of this ArrayTest. # noqa: E501 """ - self._array_array_of_integer = array_array_of_integer + self.__setitem__( + 'array_array_of_integer', + array_array_of_integer + ) @property def array_array_of_model(self): """Gets the array_array_of_model of this ArrayTest. # noqa: E501 - :return: The array_array_of_model of this ArrayTest. # noqa: E501 - :rtype: list[list[ReadOnlyFirst]] + Returns: + ([([(ReadOnlyFirst,)],)]): The array_array_of_model of this ArrayTest. # noqa: E501 """ - return self._array_array_of_model + return self._data_store.get('array_array_of_model') @array_array_of_model.setter - def array_array_of_model(self, array_array_of_model): + def array_array_of_model( + self, array_array_of_model): """Sets the array_array_of_model of this ArrayTest. - :param array_array_of_model: The array_array_of_model of this ArrayTest. # noqa: E501 - :type: list[list[ReadOnlyFirst]] + Returns: + ([([(ReadOnlyFirst,)],)]): The array_array_of_model of this ArrayTest. # noqa: E501 """ - self._array_array_of_model = array_array_of_model + self.__setitem__( + 'array_array_of_model', + array_array_of_model + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/capitalization.py b/samples/client/petstore/python/petstore_api/models/capitalization.py index 923f5c4aae86..97f1c86c1cbf 100644 --- a/samples/client/petstore/python/petstore_api/models/capitalization.py +++ b/samples/client/petstore/python/petstore_api/models/capitalization.py @@ -15,8 +15,27 @@ import six - -class Capitalization(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Capitalization(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,155 +46,246 @@ class Capitalization(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'small_camel': 'str', - 'capital_camel': 'str', - 'small_snake': 'str', - 'capital_snake': 'str', - 'sca_eth_flow_points': 'str', - 'att_name': 'str' + 'small_camel': [str], # noqa: E501 + 'capital_camel': [str], # noqa: E501 + 'small_snake': [str], # noqa: E501 + 'capital_snake': [str], # noqa: E501 + 'sca_eth_flow_points': [str], # noqa: E501 + 'att_name': [str] # noqa: E501 } - attribute_map = { - 'small_camel': 'smallCamel', - 'capital_camel': 'CapitalCamel', - 'small_snake': 'small_Snake', - 'capital_snake': 'Capital_Snake', - 'sca_eth_flow_points': 'SCA_ETH_Flow_Points', - 'att_name': 'ATT_NAME' + 'small_camel': 'smallCamel', # noqa: E501 + 'capital_camel': 'CapitalCamel', # noqa: E501 + 'small_snake': 'small_Snake', # noqa: E501 + 'capital_snake': 'Capital_Snake', # noqa: E501 + 'sca_eth_flow_points': 'SCA_ETH_Flow_Points', # noqa: E501 + 'att_name': 'ATT_NAME' # noqa: E501 } - def __init__(self, small_camel=None, capital_camel=None, small_snake=None, capital_snake=None, sca_eth_flow_points=None, att_name=None): # noqa: E501 - """Capitalization - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Capitalization - 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 False + _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 + _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. + small_camel (str): [optional] # noqa: E501 + capital_camel (str): [optional] # noqa: E501 + small_snake (str): [optional] # noqa: E501 + capital_snake (str): [optional] # noqa: E501 + sca_eth_flow_points (str): [optional] # noqa: E501 + att_name (str): Name of the pet . [optional] # noqa: E501 + """ - self._small_camel = None - self._capital_camel = None - self._small_snake = None - self._capital_snake = None - self._sca_eth_flow_points = None - self._att_name = None + self._data_store = {} self.discriminator = None - - if small_camel is not None: - self.small_camel = small_camel - if capital_camel is not None: - self.capital_camel = capital_camel - if small_snake is not None: - self.small_snake = small_snake - if capital_snake is not None: - self.capital_snake = capital_snake - if sca_eth_flow_points is not None: - self.sca_eth_flow_points = sca_eth_flow_points - if att_name is not None: - self.att_name = att_name + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def small_camel(self): """Gets the small_camel of this Capitalization. # noqa: E501 - :return: The small_camel of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The small_camel of this Capitalization. # noqa: E501 """ - return self._small_camel + return self._data_store.get('small_camel') @small_camel.setter - def small_camel(self, small_camel): + def small_camel( + self, small_camel): """Sets the small_camel of this Capitalization. - :param small_camel: The small_camel of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The small_camel of this Capitalization. # noqa: E501 """ - self._small_camel = small_camel + self.__setitem__( + 'small_camel', + small_camel + ) @property def capital_camel(self): """Gets the capital_camel of this Capitalization. # noqa: E501 - :return: The capital_camel of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The capital_camel of this Capitalization. # noqa: E501 """ - return self._capital_camel + return self._data_store.get('capital_camel') @capital_camel.setter - def capital_camel(self, capital_camel): + def capital_camel( + self, capital_camel): """Sets the capital_camel of this Capitalization. - :param capital_camel: The capital_camel of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The capital_camel of this Capitalization. # noqa: E501 """ - self._capital_camel = capital_camel + self.__setitem__( + 'capital_camel', + capital_camel + ) @property def small_snake(self): """Gets the small_snake of this Capitalization. # noqa: E501 - :return: The small_snake of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The small_snake of this Capitalization. # noqa: E501 """ - return self._small_snake + return self._data_store.get('small_snake') @small_snake.setter - def small_snake(self, small_snake): + def small_snake( + self, small_snake): """Sets the small_snake of this Capitalization. - :param small_snake: The small_snake of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The small_snake of this Capitalization. # noqa: E501 """ - self._small_snake = small_snake + self.__setitem__( + 'small_snake', + small_snake + ) @property def capital_snake(self): """Gets the capital_snake of this Capitalization. # noqa: E501 - :return: The capital_snake of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The capital_snake of this Capitalization. # noqa: E501 """ - return self._capital_snake + return self._data_store.get('capital_snake') @capital_snake.setter - def capital_snake(self, capital_snake): + def capital_snake( + self, capital_snake): """Sets the capital_snake of this Capitalization. - :param capital_snake: The capital_snake of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The capital_snake of this Capitalization. # noqa: E501 """ - self._capital_snake = capital_snake + self.__setitem__( + 'capital_snake', + capital_snake + ) @property def sca_eth_flow_points(self): """Gets the sca_eth_flow_points of this Capitalization. # noqa: E501 - :return: The sca_eth_flow_points of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The sca_eth_flow_points of this Capitalization. # noqa: E501 """ - return self._sca_eth_flow_points + return self._data_store.get('sca_eth_flow_points') @sca_eth_flow_points.setter - def sca_eth_flow_points(self, sca_eth_flow_points): + def sca_eth_flow_points( + self, sca_eth_flow_points): """Sets the sca_eth_flow_points of this Capitalization. - :param sca_eth_flow_points: The sca_eth_flow_points of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The sca_eth_flow_points of this Capitalization. # noqa: E501 """ - self._sca_eth_flow_points = sca_eth_flow_points + self.__setitem__( + 'sca_eth_flow_points', + sca_eth_flow_points + ) @property def att_name(self): @@ -183,46 +293,30 @@ def att_name(self): Name of the pet # noqa: E501 - :return: The att_name of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The att_name of this Capitalization. # noqa: E501 """ - return self._att_name + return self._data_store.get('att_name') @att_name.setter - def att_name(self, att_name): + def att_name( + self, att_name): """Sets the att_name of this Capitalization. Name of the pet # noqa: E501 - :param att_name: The att_name of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The att_name of this Capitalization. # noqa: E501 """ - self._att_name = att_name + self.__setitem__( + 'att_name', + att_name + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/cat.py b/samples/client/petstore/python/petstore_api/models/cat.py index c5c87a6b1118..49bec13ed39e 100644 --- a/samples/client/petstore/python/petstore_api/models/cat.py +++ b/samples/client/petstore/python/petstore_api/models/cat.py @@ -15,8 +15,27 @@ import six +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) -class Cat(object): + +class Cat(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,195 @@ class Cat(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'declawed': 'bool' + 'class_name': [str], # noqa: E501 + 'color': [str], # noqa: E501 + 'declawed': [bool] # noqa: E501 } - attribute_map = { - 'declawed': 'declawed' + 'class_name': 'className', # noqa: E501 + 'color': 'color', # noqa: E501 + 'declawed': 'declawed' # noqa: E501 } - def __init__(self, declawed=None): # noqa: E501 - """Cat - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, class_name, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Cat - a model defined in OpenAPI + + Args: + class_name (str): + + 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 False + _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 + _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. + declawed (bool): [optional] # noqa: E501 + color (str): [optional] if omitted the server will use the default value of 'red' # noqa: E501 + """ - self._declawed = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + # assign using .var_name to check against nullable and enums + self.class_name = class_name + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def class_name(self): + """Gets the class_name of this Cat. # noqa: E501 + + + Returns: + (str): The class_name of this Cat. # noqa: E501 + """ + return self._data_store.get('class_name') + + @class_name.setter + def class_name( + self, class_name): + """Sets the class_name of this Cat. + + + Returns: + (str): The class_name of this Cat. # noqa: E501 + """ + if class_name is None: + raise ApiValueError("Invalid value for `class_name`, must not be `None`") # noqa: E501 - if declawed is not None: - self.declawed = declawed + self.__setitem__( + 'class_name', + class_name + ) + + @property + def color(self): + """Gets the color of this Cat. # noqa: E501 + + + Returns: + (str): The color of this Cat. # noqa: E501 + """ + return self._data_store.get('color') + + @color.setter + def color( + self, color): + """Sets the color of this Cat. + + + Returns: + (str): The color of this Cat. # noqa: E501 + """ + + self.__setitem__( + 'color', + color + ) @property def declawed(self): """Gets the declawed of this Cat. # noqa: E501 - :return: The declawed of this Cat. # noqa: E501 - :rtype: bool + Returns: + (bool): The declawed of this Cat. # noqa: E501 """ - return self._declawed + return self._data_store.get('declawed') @declawed.setter - def declawed(self, declawed): + def declawed( + self, declawed): """Sets the declawed of this Cat. - :param declawed: The declawed of this Cat. # noqa: E501 - :type: bool + Returns: + (bool): The declawed of this Cat. # noqa: E501 """ - self._declawed = declawed + self.__setitem__( + 'declawed', + declawed + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/category.py b/samples/client/petstore/python/petstore_api/models/category.py index 5b2f79eaec8d..28b9f6ada0fa 100644 --- a/samples/client/petstore/python/petstore_api/models/category.py +++ b/samples/client/petstore/python/petstore_api/models/category.py @@ -15,8 +15,27 @@ import six - -class Category(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Category(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,97 +46,167 @@ class Category(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'id': 'int', - 'name': 'str' + 'id': [int], # noqa: E501 + 'name': [str] # noqa: E501 } - attribute_map = { - 'id': 'id', - 'name': 'name' + 'id': 'id', # noqa: E501 + 'name': 'name' # noqa: E501 } - def __init__(self, id=None, name='default-name'): # noqa: E501 - """Category - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, name='default-name', _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Category - a model defined in OpenAPI + + Args: + name (str): defaults to 'default-name', must be one of ['default-name'] # noqa: E501 + + 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 False + _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 + _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. + id (int): [optional] # noqa: E501 + """ - self._id = None - self._name = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration - if id is not None: - self.id = id + # assign using .var_name to check against nullable and enums self.name = name + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def id(self): """Gets the id of this Category. # noqa: E501 - :return: The id of this Category. # noqa: E501 - :rtype: int + Returns: + (int): The id of this Category. # noqa: E501 """ - return self._id + return self._data_store.get('id') @id.setter - def id(self, id): + def id( + self, id): """Sets the id of this Category. - :param id: The id of this Category. # noqa: E501 - :type: int + Returns: + (int): The id of this Category. # noqa: E501 """ - self._id = id + self.__setitem__( + 'id', + id + ) @property def name(self): """Gets the name of this Category. # noqa: E501 - :return: The name of this Category. # noqa: E501 - :rtype: str + Returns: + (str): The name of this Category. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this Category. - :param name: The name of this Category. # noqa: E501 - :type: str + Returns: + (str): The name of this Category. # noqa: E501 """ if name is None: - raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `name`, must not be `None`") # noqa: E501 - self._name = name + self.__setitem__( + 'name', + name + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/class_model.py b/samples/client/petstore/python/petstore_api/models/class_model.py index e207ba41ec92..d665edf7efd5 100644 --- a/samples/client/petstore/python/petstore_api/models/class_model.py +++ b/samples/client/petstore/python/petstore_api/models/class_model.py @@ -15,8 +15,27 @@ import six - -class ClassModel(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ClassModel(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class ClassModel(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - '_class': 'str' + '_class': [str] # noqa: E501 } - attribute_map = { - '_class': '_class' + '_class': '_class' # noqa: E501 } - def __init__(self, _class=None): # noqa: E501 - """ClassModel - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ClassModel - a model defined in OpenAPI - self.__class = None - self.discriminator = None - if _class is not None: - self._class = _class + + 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 False + _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 + _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. + _class (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def _class(self): """Gets the _class of this ClassModel. # noqa: E501 - :return: The _class of this ClassModel. # noqa: E501 - :rtype: str + Returns: + (str): The _class of this ClassModel. # noqa: E501 """ - return self.__class + return self._data_store.get('_class') @_class.setter - def _class(self, _class): + def _class( + self, _class): """Sets the _class of this ClassModel. - :param _class: The _class of this ClassModel. # noqa: E501 - :type: str + Returns: + (str): The _class of this ClassModel. # noqa: E501 """ - self.__class = _class + self.__setitem__( + '_class', + _class + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/client.py b/samples/client/petstore/python/petstore_api/models/client.py index e742468e7763..ea315bc1cadd 100644 --- a/samples/client/petstore/python/petstore_api/models/client.py +++ b/samples/client/petstore/python/petstore_api/models/client.py @@ -15,8 +15,27 @@ import six - -class Client(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Client(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class Client(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'client': 'str' + 'client': [str] # noqa: E501 } - attribute_map = { - 'client': 'client' + 'client': 'client' # noqa: E501 } - def __init__(self, client=None): # noqa: E501 - """Client - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Client - a model defined in OpenAPI - self._client = None - self.discriminator = None - if client is not None: - self.client = client + + 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 False + _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 + _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. + client (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def client(self): """Gets the client of this Client. # noqa: E501 - :return: The client of this Client. # noqa: E501 - :rtype: str + Returns: + (str): The client of this Client. # noqa: E501 """ - return self._client + return self._data_store.get('client') @client.setter - def client(self, client): + def client( + self, client): """Sets the client of this Client. - :param client: The client of this Client. # noqa: E501 - :type: str + Returns: + (str): The client of this Client. # noqa: E501 """ - self._client = client + self.__setitem__( + 'client', + client + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/dog.py b/samples/client/petstore/python/petstore_api/models/dog.py index c2bc8f745d15..0febcbab94ec 100644 --- a/samples/client/petstore/python/petstore_api/models/dog.py +++ b/samples/client/petstore/python/petstore_api/models/dog.py @@ -15,8 +15,27 @@ import six +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) -class Dog(object): + +class Dog(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,195 @@ class Dog(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'breed': 'str' + 'class_name': [str], # noqa: E501 + 'color': [str], # noqa: E501 + 'breed': [str] # noqa: E501 } - attribute_map = { - 'breed': 'breed' + 'class_name': 'className', # noqa: E501 + 'color': 'color', # noqa: E501 + 'breed': 'breed' # noqa: E501 } - def __init__(self, breed=None): # noqa: E501 - """Dog - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, class_name, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Dog - a model defined in OpenAPI + + Args: + class_name (str): + + 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 False + _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 + _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. + breed (str): [optional] # noqa: E501 + color (str): [optional] if omitted the server will use the default value of 'red' # noqa: E501 + """ - self._breed = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + # assign using .var_name to check against nullable and enums + self.class_name = class_name + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def class_name(self): + """Gets the class_name of this Dog. # noqa: E501 + + + Returns: + (str): The class_name of this Dog. # noqa: E501 + """ + return self._data_store.get('class_name') + + @class_name.setter + def class_name( + self, class_name): + """Sets the class_name of this Dog. + + + Returns: + (str): The class_name of this Dog. # noqa: E501 + """ + if class_name is None: + raise ApiValueError("Invalid value for `class_name`, must not be `None`") # noqa: E501 - if breed is not None: - self.breed = breed + self.__setitem__( + 'class_name', + class_name + ) + + @property + def color(self): + """Gets the color of this Dog. # noqa: E501 + + + Returns: + (str): The color of this Dog. # noqa: E501 + """ + return self._data_store.get('color') + + @color.setter + def color( + self, color): + """Sets the color of this Dog. + + + Returns: + (str): The color of this Dog. # noqa: E501 + """ + + self.__setitem__( + 'color', + color + ) @property def breed(self): """Gets the breed of this Dog. # noqa: E501 - :return: The breed of this Dog. # noqa: E501 - :rtype: str + Returns: + (str): The breed of this Dog. # noqa: E501 """ - return self._breed + return self._data_store.get('breed') @breed.setter - def breed(self, breed): + def breed( + self, breed): """Sets the breed of this Dog. - :param breed: The breed of this Dog. # noqa: E501 - :type: str + Returns: + (str): The breed of this Dog. # noqa: E501 """ - self._breed = breed + self.__setitem__( + 'breed', + breed + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/enum_arrays.py b/samples/client/petstore/python/petstore_api/models/enum_arrays.py index df4363c356c3..88e4f0a20751 100644 --- a/samples/client/petstore/python/petstore_api/models/enum_arrays.py +++ b/samples/client/petstore/python/petstore_api/models/enum_arrays.py @@ -15,8 +15,27 @@ import six - -class EnumArrays(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class EnumArrays(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,109 +46,176 @@ class EnumArrays(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'just_symbol': 'str', - 'array_enum': 'list[str]' + 'just_symbol': [str], # noqa: E501 + 'array_enum': [[(str,)]] # noqa: E501 } - attribute_map = { - 'just_symbol': 'just_symbol', - 'array_enum': 'array_enum' + 'just_symbol': 'just_symbol', # noqa: E501 + 'array_enum': 'array_enum' # noqa: E501 } - def __init__(self, just_symbol=None, array_enum=None): # noqa: E501 - """EnumArrays - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """EnumArrays - 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 False + _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 + _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. + just_symbol (str): [optional] # noqa: E501 + array_enum ([(str,)]): [optional] # noqa: E501 + """ - self._just_symbol = None - self._array_enum = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) - if just_symbol is not None: - self.just_symbol = just_symbol - if array_enum is not None: - self.array_enum = array_enum + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def just_symbol(self): """Gets the just_symbol of this EnumArrays. # noqa: E501 - :return: The just_symbol of this EnumArrays. # noqa: E501 - :rtype: str + Returns: + (str): The just_symbol of this EnumArrays. # noqa: E501 """ - return self._just_symbol + return self._data_store.get('just_symbol') @just_symbol.setter - def just_symbol(self, just_symbol): + def just_symbol( + self, just_symbol): """Sets the just_symbol of this EnumArrays. - :param just_symbol: The just_symbol of this EnumArrays. # noqa: E501 - :type: str + Returns: + (str): The just_symbol of this EnumArrays. # noqa: E501 """ allowed_values = [">=", "$"] # noqa: E501 if just_symbol not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `just_symbol` ({0}), must be one of {1}" # noqa: E501 .format(just_symbol, allowed_values) ) - self._just_symbol = just_symbol + self.__setitem__( + 'just_symbol', + just_symbol + ) @property def array_enum(self): """Gets the array_enum of this EnumArrays. # noqa: E501 - :return: The array_enum of this EnumArrays. # noqa: E501 - :rtype: list[str] + Returns: + ([(str,)]): The array_enum of this EnumArrays. # noqa: E501 """ - return self._array_enum + return self._data_store.get('array_enum') @array_enum.setter - def array_enum(self, array_enum): + def array_enum( + self, array_enum): """Sets the array_enum of this EnumArrays. - :param array_enum: The array_enum of this EnumArrays. # noqa: E501 - :type: list[str] + Returns: + ([(str,)]): The array_enum of this EnumArrays. # noqa: E501 """ allowed_values = ["fish", "crab"] # noqa: E501 if not set(array_enum).issubset(set(allowed_values)): - raise ValueError( + raise ApiValueError( "Invalid values for `array_enum` [{0}], must be a subset of [{1}]" # noqa: E501 .format(", ".join(map(str, set(array_enum) - set(allowed_values))), # noqa: E501 ", ".join(map(str, allowed_values))) ) - self._array_enum = array_enum + self.__setitem__( + 'array_enum', + array_enum + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/enum_class.py b/samples/client/petstore/python/petstore_api/models/enum_class.py index 182197d8aa6e..67731827fc1c 100644 --- a/samples/client/petstore/python/petstore_api/models/enum_class.py +++ b/samples/client/petstore/python/petstore_api/models/enum_class.py @@ -15,8 +15,27 @@ import six - -class EnumClass(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class EnumClass(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -34,42 +53,107 @@ class EnumClass(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { } - attribute_map = { } - def __init__(self): # noqa: E501 - """EnumClass - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """EnumClass - 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 False + _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 + _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. + """ + + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/enum_test.py b/samples/client/petstore/python/petstore_api/models/enum_test.py index 0fd60c4a351d..c229da414951 100644 --- a/samples/client/petstore/python/petstore_api/models/enum_test.py +++ b/samples/client/petstore/python/petstore_api/models/enum_test.py @@ -15,8 +15,28 @@ import six - -class EnumTest(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.outer_enum import OuterEnum + + +class EnumTest(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,199 +47,275 @@ class EnumTest(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'enum_string': 'str', - 'enum_string_required': 'str', - 'enum_integer': 'int', - 'enum_number': 'float', - 'outer_enum': 'OuterEnum' + 'enum_string': [str], # noqa: E501 + 'enum_string_required': [str], # noqa: E501 + 'enum_integer': [int], # noqa: E501 + 'enum_number': [float], # noqa: E501 + 'outer_enum': [OuterEnum] # noqa: E501 } - attribute_map = { - 'enum_string': 'enum_string', - 'enum_string_required': 'enum_string_required', - 'enum_integer': 'enum_integer', - 'enum_number': 'enum_number', - 'outer_enum': 'outerEnum' + 'enum_string': 'enum_string', # noqa: E501 + 'enum_string_required': 'enum_string_required', # noqa: E501 + 'enum_integer': 'enum_integer', # noqa: E501 + 'enum_number': 'enum_number', # noqa: E501 + 'outer_enum': 'outerEnum' # noqa: E501 } - def __init__(self, enum_string=None, enum_string_required=None, enum_integer=None, enum_number=None, outer_enum=None): # noqa: E501 - """EnumTest - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, enum_string_required, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """EnumTest - a model defined in OpenAPI + + Args: + enum_string_required (str): + + 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 False + _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 + _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. + enum_string (str): [optional] # noqa: E501 + enum_integer (int): [optional] # noqa: E501 + enum_number (float): [optional] # noqa: E501 + outer_enum (OuterEnum): [optional] # noqa: E501 + """ - self._enum_string = None - self._enum_string_required = None - self._enum_integer = None - self._enum_number = None - self._outer_enum = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration - if enum_string is not None: - self.enum_string = enum_string + # assign using .var_name to check against nullable and enums self.enum_string_required = enum_string_required - if enum_integer is not None: - self.enum_integer = enum_integer - if enum_number is not None: - self.enum_number = enum_number - if outer_enum is not None: - self.outer_enum = outer_enum + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def enum_string(self): """Gets the enum_string of this EnumTest. # noqa: E501 - :return: The enum_string of this EnumTest. # noqa: E501 - :rtype: str + Returns: + (str): The enum_string of this EnumTest. # noqa: E501 """ - return self._enum_string + return self._data_store.get('enum_string') @enum_string.setter - def enum_string(self, enum_string): + def enum_string( + self, enum_string): """Sets the enum_string of this EnumTest. - :param enum_string: The enum_string of this EnumTest. # noqa: E501 - :type: str + Returns: + (str): The enum_string of this EnumTest. # noqa: E501 """ allowed_values = ["UPPER", "lower", ""] # noqa: E501 if enum_string not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `enum_string` ({0}), must be one of {1}" # noqa: E501 .format(enum_string, allowed_values) ) - self._enum_string = enum_string + self.__setitem__( + 'enum_string', + enum_string + ) @property def enum_string_required(self): """Gets the enum_string_required of this EnumTest. # noqa: E501 - :return: The enum_string_required of this EnumTest. # noqa: E501 - :rtype: str + Returns: + (str): The enum_string_required of this EnumTest. # noqa: E501 """ - return self._enum_string_required + return self._data_store.get('enum_string_required') @enum_string_required.setter - def enum_string_required(self, enum_string_required): + def enum_string_required( + self, enum_string_required): """Sets the enum_string_required of this EnumTest. - :param enum_string_required: The enum_string_required of this EnumTest. # noqa: E501 - :type: str + Returns: + (str): The enum_string_required of this EnumTest. # noqa: E501 """ if enum_string_required is None: - raise ValueError("Invalid value for `enum_string_required`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `enum_string_required`, must not be `None`") # noqa: E501 allowed_values = ["UPPER", "lower", ""] # noqa: E501 if enum_string_required not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `enum_string_required` ({0}), must be one of {1}" # noqa: E501 .format(enum_string_required, allowed_values) ) - self._enum_string_required = enum_string_required + self.__setitem__( + 'enum_string_required', + enum_string_required + ) @property def enum_integer(self): """Gets the enum_integer of this EnumTest. # noqa: E501 - :return: The enum_integer of this EnumTest. # noqa: E501 - :rtype: int + Returns: + (int): The enum_integer of this EnumTest. # noqa: E501 """ - return self._enum_integer + return self._data_store.get('enum_integer') @enum_integer.setter - def enum_integer(self, enum_integer): + def enum_integer( + self, enum_integer): """Sets the enum_integer of this EnumTest. - :param enum_integer: The enum_integer of this EnumTest. # noqa: E501 - :type: int + Returns: + (int): The enum_integer of this EnumTest. # noqa: E501 """ allowed_values = [1, -1] # noqa: E501 if enum_integer not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `enum_integer` ({0}), must be one of {1}" # noqa: E501 .format(enum_integer, allowed_values) ) - self._enum_integer = enum_integer + self.__setitem__( + 'enum_integer', + enum_integer + ) @property def enum_number(self): """Gets the enum_number of this EnumTest. # noqa: E501 - :return: The enum_number of this EnumTest. # noqa: E501 - :rtype: float + Returns: + (float): The enum_number of this EnumTest. # noqa: E501 """ - return self._enum_number + return self._data_store.get('enum_number') @enum_number.setter - def enum_number(self, enum_number): + def enum_number( + self, enum_number): """Sets the enum_number of this EnumTest. - :param enum_number: The enum_number of this EnumTest. # noqa: E501 - :type: float + Returns: + (float): The enum_number of this EnumTest. # noqa: E501 """ allowed_values = [1.1, -1.2] # noqa: E501 if enum_number not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `enum_number` ({0}), must be one of {1}" # noqa: E501 .format(enum_number, allowed_values) ) - self._enum_number = enum_number + self.__setitem__( + 'enum_number', + enum_number + ) @property def outer_enum(self): """Gets the outer_enum of this EnumTest. # noqa: E501 - :return: The outer_enum of this EnumTest. # noqa: E501 - :rtype: OuterEnum + Returns: + (OuterEnum): The outer_enum of this EnumTest. # noqa: E501 """ - return self._outer_enum + return self._data_store.get('outer_enum') @outer_enum.setter - def outer_enum(self, outer_enum): + def outer_enum( + self, outer_enum): """Sets the outer_enum of this EnumTest. - :param outer_enum: The outer_enum of this EnumTest. # noqa: E501 - :type: OuterEnum + Returns: + (OuterEnum): The outer_enum of this EnumTest. # noqa: E501 """ - self._outer_enum = outer_enum + self.__setitem__( + 'outer_enum', + outer_enum + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/file.py b/samples/client/petstore/python/petstore_api/models/file.py index 34d77c3b4cf8..3fdc580d4198 100644 --- a/samples/client/petstore/python/petstore_api/models/file.py +++ b/samples/client/petstore/python/petstore_api/models/file.py @@ -15,8 +15,27 @@ import six - -class File(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class File(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,25 +46,106 @@ class File(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'source_uri': 'str' + 'source_uri': [str] # noqa: E501 } - attribute_map = { - 'source_uri': 'sourceURI' + 'source_uri': 'sourceURI' # noqa: E501 } - def __init__(self, source_uri=None): # noqa: E501 - """File - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """File - a model defined in OpenAPI - self._source_uri = None - self.discriminator = None - if source_uri is not None: - self.source_uri = source_uri + + 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 False + _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 + _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. + source_uri (str): Test capitalization. [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def source_uri(self): @@ -53,46 +153,30 @@ def source_uri(self): Test capitalization # noqa: E501 - :return: The source_uri of this File. # noqa: E501 - :rtype: str + Returns: + (str): The source_uri of this File. # noqa: E501 """ - return self._source_uri + return self._data_store.get('source_uri') @source_uri.setter - def source_uri(self, source_uri): + def source_uri( + self, source_uri): """Sets the source_uri of this File. Test capitalization # noqa: E501 - :param source_uri: The source_uri of this File. # noqa: E501 - :type: str + Returns: + (str): The source_uri of this File. # noqa: E501 """ - self._source_uri = source_uri + self.__setitem__( + 'source_uri', + source_uri + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/file_schema_test_class.py b/samples/client/petstore/python/petstore_api/models/file_schema_test_class.py index 026822dee749..ed77661a5bfe 100644 --- a/samples/client/petstore/python/petstore_api/models/file_schema_test_class.py +++ b/samples/client/petstore/python/petstore_api/models/file_schema_test_class.py @@ -15,8 +15,28 @@ import six - -class FileSchemaTestClass(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.file import File + + +class FileSchemaTestClass(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +47,163 @@ class FileSchemaTestClass(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'file': 'File', - 'files': 'list[File]' + 'file': [File], # noqa: E501 + 'files': [[(File,)]] # noqa: E501 } - attribute_map = { - 'file': 'file', - 'files': 'files' + 'file': 'file', # noqa: E501 + 'files': 'files' # noqa: E501 } - def __init__(self, file=None, files=None): # noqa: E501 - """FileSchemaTestClass - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """FileSchemaTestClass - 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 False + _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 + _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. + file (File): [optional] # noqa: E501 + files ([(File,)]): [optional] # noqa: E501 + """ - self._file = None - self._files = None + self._data_store = {} self.discriminator = None - - if file is not None: - self.file = file - if files is not None: - self.files = files + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def file(self): """Gets the file of this FileSchemaTestClass. # noqa: E501 - :return: The file of this FileSchemaTestClass. # noqa: E501 - :rtype: File + Returns: + (File): The file of this FileSchemaTestClass. # noqa: E501 """ - return self._file + return self._data_store.get('file') @file.setter - def file(self, file): + def file( + self, file): """Sets the file of this FileSchemaTestClass. - :param file: The file of this FileSchemaTestClass. # noqa: E501 - :type: File + Returns: + (File): The file of this FileSchemaTestClass. # noqa: E501 """ - self._file = file + self.__setitem__( + 'file', + file + ) @property def files(self): """Gets the files of this FileSchemaTestClass. # noqa: E501 - :return: The files of this FileSchemaTestClass. # noqa: E501 - :rtype: list[File] + Returns: + ([(File,)]): The files of this FileSchemaTestClass. # noqa: E501 """ - return self._files + return self._data_store.get('files') @files.setter - def files(self, files): + def files( + self, files): """Sets the files of this FileSchemaTestClass. - :param files: The files of this FileSchemaTestClass. # noqa: E501 - :type: list[File] + Returns: + ([(File,)]): The files of this FileSchemaTestClass. # noqa: E501 """ - self._files = files + self.__setitem__( + 'files', + files + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/format_test.py b/samples/client/petstore/python/petstore_api/models/format_test.py index c7703d166071..e7edaf2d3df6 100644 --- a/samples/client/petstore/python/petstore_api/models/format_test.py +++ b/samples/client/petstore/python/petstore_api/models/format_test.py @@ -15,8 +15,27 @@ import six - -class FormatTest(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class FormatTest(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,414 +46,512 @@ class FormatTest(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'integer': 'int', - 'int32': 'int', - 'int64': 'int', - 'number': 'float', - 'float': 'float', - 'double': 'float', - 'string': 'str', - 'byte': 'str', - 'binary': 'file', - 'date': 'date', - 'date_time': 'datetime', - 'uuid': 'str', - 'password': 'str' + 'integer': [int], # noqa: E501 + 'int32': [int], # noqa: E501 + 'int64': [int], # noqa: E501 + 'number': [float], # noqa: E501 + 'float': [float], # noqa: E501 + 'double': [float], # noqa: E501 + 'string': [str], # noqa: E501 + 'byte': [str], # noqa: E501 + 'binary': [file_type], # noqa: E501 + 'date': [date], # noqa: E501 + 'date_time': [datetime], # noqa: E501 + 'uuid': [str], # noqa: E501 + 'password': [str] # noqa: E501 } - attribute_map = { - 'integer': 'integer', - 'int32': 'int32', - 'int64': 'int64', - 'number': 'number', - 'float': 'float', - 'double': 'double', - 'string': 'string', - 'byte': 'byte', - 'binary': 'binary', - 'date': 'date', - 'date_time': 'dateTime', - 'uuid': 'uuid', - 'password': 'password' + 'integer': 'integer', # noqa: E501 + 'int32': 'int32', # noqa: E501 + 'int64': 'int64', # noqa: E501 + 'number': 'number', # noqa: E501 + 'float': 'float', # noqa: E501 + 'double': 'double', # noqa: E501 + 'string': 'string', # noqa: E501 + 'byte': 'byte', # noqa: E501 + 'binary': 'binary', # noqa: E501 + 'date': 'date', # noqa: E501 + 'date_time': 'dateTime', # noqa: E501 + 'uuid': 'uuid', # noqa: E501 + 'password': 'password' # noqa: E501 } - def __init__(self, integer=None, int32=None, int64=None, number=None, float=None, double=None, string=None, byte=None, binary=None, date=None, date_time=None, uuid=None, password=None): # noqa: E501 - """FormatTest - a model defined in OpenAPI""" # noqa: E501 - - self._integer = None - self._int32 = None - self._int64 = None - self._number = None - self._float = None - self._double = None - self._string = None - self._byte = None - self._binary = None - self._date = None - self._date_time = None - self._uuid = None - self._password = None + def __init__(self, number, byte, date, password, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """FormatTest - a model defined in OpenAPI + + Args: + number (float): + byte (str): + date (date): + password (str): + + 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 False + _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 + _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. + integer (int): [optional] # noqa: E501 + int32 (int): [optional] # noqa: E501 + int64 (int): [optional] # noqa: E501 + float (float): [optional] # noqa: E501 + double (float): [optional] # noqa: E501 + string (str): [optional] # noqa: E501 + binary (file_type): [optional] # noqa: E501 + date_time (datetime): [optional] # noqa: E501 + uuid (str): [optional] # noqa: E501 + """ + + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration - if integer is not None: - self.integer = integer - if int32 is not None: - self.int32 = int32 - if int64 is not None: - self.int64 = int64 + # assign using .var_name to check against nullable and enums self.number = number - if float is not None: - self.float = float - if double is not None: - self.double = double - if string is not None: - self.string = string self.byte = byte - if binary is not None: - self.binary = binary self.date = date - if date_time is not None: - self.date_time = date_time - if uuid is not None: - self.uuid = uuid self.password = password + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def integer(self): """Gets the integer of this FormatTest. # noqa: E501 - :return: The integer of this FormatTest. # noqa: E501 - :rtype: int + Returns: + (int): The integer of this FormatTest. # noqa: E501 """ - return self._integer + return self._data_store.get('integer') @integer.setter - def integer(self, integer): + def integer( + self, integer): """Sets the integer of this FormatTest. - :param integer: The integer of this FormatTest. # noqa: E501 - :type: int + Returns: + (int): The integer of this FormatTest. # noqa: E501 """ if integer is not None and integer > 100: # noqa: E501 - raise ValueError("Invalid value for `integer`, must be a value less than or equal to `100`") # noqa: E501 + raise ApiValueError("Invalid value for `integer`, must be a value less than or equal to `100`") # noqa: E501 if integer is not None and integer < 10: # noqa: E501 - raise ValueError("Invalid value for `integer`, must be a value greater than or equal to `10`") # noqa: E501 + raise ApiValueError("Invalid value for `integer`, must be a value greater than or equal to `10`") # noqa: E501 - self._integer = integer + self.__setitem__( + 'integer', + integer + ) @property def int32(self): """Gets the int32 of this FormatTest. # noqa: E501 - :return: The int32 of this FormatTest. # noqa: E501 - :rtype: int + Returns: + (int): The int32 of this FormatTest. # noqa: E501 """ - return self._int32 + return self._data_store.get('int32') @int32.setter - def int32(self, int32): + def int32( + self, int32): """Sets the int32 of this FormatTest. - :param int32: The int32 of this FormatTest. # noqa: E501 - :type: int + Returns: + (int): The int32 of this FormatTest. # noqa: E501 """ if int32 is not None and int32 > 200: # noqa: E501 - raise ValueError("Invalid value for `int32`, must be a value less than or equal to `200`") # noqa: E501 + raise ApiValueError("Invalid value for `int32`, must be a value less than or equal to `200`") # noqa: E501 if int32 is not None and int32 < 20: # noqa: E501 - raise ValueError("Invalid value for `int32`, must be a value greater than or equal to `20`") # noqa: E501 + raise ApiValueError("Invalid value for `int32`, must be a value greater than or equal to `20`") # noqa: E501 - self._int32 = int32 + self.__setitem__( + 'int32', + int32 + ) @property def int64(self): """Gets the int64 of this FormatTest. # noqa: E501 - :return: The int64 of this FormatTest. # noqa: E501 - :rtype: int + Returns: + (int): The int64 of this FormatTest. # noqa: E501 """ - return self._int64 + return self._data_store.get('int64') @int64.setter - def int64(self, int64): + def int64( + self, int64): """Sets the int64 of this FormatTest. - :param int64: The int64 of this FormatTest. # noqa: E501 - :type: int + Returns: + (int): The int64 of this FormatTest. # noqa: E501 """ - self._int64 = int64 + self.__setitem__( + 'int64', + int64 + ) @property def number(self): """Gets the number of this FormatTest. # noqa: E501 - :return: The number of this FormatTest. # noqa: E501 - :rtype: float + Returns: + (float): The number of this FormatTest. # noqa: E501 """ - return self._number + return self._data_store.get('number') @number.setter - def number(self, number): + def number( + self, number): """Sets the number of this FormatTest. - :param number: The number of this FormatTest. # noqa: E501 - :type: float + Returns: + (float): The number of this FormatTest. # noqa: E501 """ if number is None: - raise ValueError("Invalid value for `number`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `number`, must not be `None`") # noqa: E501 if number is not None and number > 543.2: # noqa: E501 - raise ValueError("Invalid value for `number`, must be a value less than or equal to `543.2`") # noqa: E501 + raise ApiValueError("Invalid value for `number`, must be a value less than or equal to `543.2`") # noqa: E501 if number is not None and number < 32.1: # noqa: E501 - raise ValueError("Invalid value for `number`, must be a value greater than or equal to `32.1`") # noqa: E501 + raise ApiValueError("Invalid value for `number`, must be a value greater than or equal to `32.1`") # noqa: E501 - self._number = number + self.__setitem__( + 'number', + number + ) @property def float(self): """Gets the float of this FormatTest. # noqa: E501 - :return: The float of this FormatTest. # noqa: E501 - :rtype: float + Returns: + (float): The float of this FormatTest. # noqa: E501 """ - return self._float + return self._data_store.get('float') @float.setter - def float(self, float): + def float( + self, float): """Sets the float of this FormatTest. - :param float: The float of this FormatTest. # noqa: E501 - :type: float + Returns: + (float): The float of this FormatTest. # noqa: E501 """ if float is not None and float > 987.6: # noqa: E501 - raise ValueError("Invalid value for `float`, must be a value less than or equal to `987.6`") # noqa: E501 + raise ApiValueError("Invalid value for `float`, must be a value less than or equal to `987.6`") # noqa: E501 if float is not None and float < 54.3: # noqa: E501 - raise ValueError("Invalid value for `float`, must be a value greater than or equal to `54.3`") # noqa: E501 + raise ApiValueError("Invalid value for `float`, must be a value greater than or equal to `54.3`") # noqa: E501 - self._float = float + self.__setitem__( + 'float', + float + ) @property def double(self): """Gets the double of this FormatTest. # noqa: E501 - :return: The double of this FormatTest. # noqa: E501 - :rtype: float + Returns: + (float): The double of this FormatTest. # noqa: E501 """ - return self._double + return self._data_store.get('double') @double.setter - def double(self, double): + def double( + self, double): """Sets the double of this FormatTest. - :param double: The double of this FormatTest. # noqa: E501 - :type: float + Returns: + (float): The double of this FormatTest. # noqa: E501 """ if double is not None and double > 123.4: # noqa: E501 - raise ValueError("Invalid value for `double`, must be a value less than or equal to `123.4`") # noqa: E501 + raise ApiValueError("Invalid value for `double`, must be a value less than or equal to `123.4`") # noqa: E501 if double is not None and double < 67.8: # noqa: E501 - raise ValueError("Invalid value for `double`, must be a value greater than or equal to `67.8`") # noqa: E501 + raise ApiValueError("Invalid value for `double`, must be a value greater than or equal to `67.8`") # noqa: E501 - self._double = double + self.__setitem__( + 'double', + double + ) @property def string(self): """Gets the string of this FormatTest. # noqa: E501 - :return: The string of this FormatTest. # noqa: E501 - :rtype: str + Returns: + (str): The string of this FormatTest. # noqa: E501 """ - return self._string + return self._data_store.get('string') @string.setter - def string(self, string): + def string( + self, string): """Sets the string of this FormatTest. - :param string: The string of this FormatTest. # noqa: E501 - :type: str + Returns: + (str): The string of this FormatTest. # noqa: E501 """ - if string is not None and not re.search(r'[a-z]', string, flags=re.IGNORECASE): # noqa: E501 - raise ValueError(r"Invalid value for `string`, must be a follow pattern or equal to `/[a-z]/i`") # noqa: E501 + if string is not None and not re.search(r'', string): # noqa: E501 + raise ApiValueError(r"Invalid value for `string`, must be a follow pattern or equal to `/[a-z]/i`") # noqa: E501 - self._string = string + self.__setitem__( + 'string', + string + ) @property def byte(self): """Gets the byte of this FormatTest. # noqa: E501 - :return: The byte of this FormatTest. # noqa: E501 - :rtype: str + Returns: + (str): The byte of this FormatTest. # noqa: E501 """ - return self._byte + return self._data_store.get('byte') @byte.setter - def byte(self, byte): + def byte( + self, byte): """Sets the byte of this FormatTest. - :param byte: The byte of this FormatTest. # noqa: E501 - :type: str + Returns: + (str): The byte of this FormatTest. # noqa: E501 """ if byte is None: - raise ValueError("Invalid value for `byte`, must not be `None`") # noqa: E501 - if byte is not None and not re.search(r'^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$', byte): # noqa: E501 - raise ValueError(r"Invalid value for `byte`, must be a follow pattern or equal to `/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/`") # noqa: E501 + raise ApiValueError("Invalid value for `byte`, must not be `None`") # noqa: E501 + if byte is not None and not re.search(r'', byte): # noqa: E501 + raise ApiValueError(r"Invalid value for `byte`, must be a follow pattern or equal to `/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/`") # noqa: E501 - self._byte = byte + self.__setitem__( + 'byte', + byte + ) @property def binary(self): """Gets the binary of this FormatTest. # noqa: E501 - :return: The binary of this FormatTest. # noqa: E501 - :rtype: file + Returns: + (file_type): The binary of this FormatTest. # noqa: E501 """ - return self._binary + return self._data_store.get('binary') @binary.setter - def binary(self, binary): + def binary( + self, binary): """Sets the binary of this FormatTest. - :param binary: The binary of this FormatTest. # noqa: E501 - :type: file + Returns: + (file_type): The binary of this FormatTest. # noqa: E501 """ - self._binary = binary + self.__setitem__( + 'binary', + binary + ) @property def date(self): """Gets the date of this FormatTest. # noqa: E501 - :return: The date of this FormatTest. # noqa: E501 - :rtype: date + Returns: + (date): The date of this FormatTest. # noqa: E501 """ - return self._date + return self._data_store.get('date') @date.setter - def date(self, date): + def date( + self, date): """Sets the date of this FormatTest. - :param date: The date of this FormatTest. # noqa: E501 - :type: date + Returns: + (date): The date of this FormatTest. # noqa: E501 """ if date is None: - raise ValueError("Invalid value for `date`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `date`, must not be `None`") # noqa: E501 - self._date = date + self.__setitem__( + 'date', + date + ) @property def date_time(self): """Gets the date_time of this FormatTest. # noqa: E501 - :return: The date_time of this FormatTest. # noqa: E501 - :rtype: datetime + Returns: + (datetime): The date_time of this FormatTest. # noqa: E501 """ - return self._date_time + return self._data_store.get('date_time') @date_time.setter - def date_time(self, date_time): + def date_time( + self, date_time): """Sets the date_time of this FormatTest. - :param date_time: The date_time of this FormatTest. # noqa: E501 - :type: datetime + Returns: + (datetime): The date_time of this FormatTest. # noqa: E501 """ - self._date_time = date_time + self.__setitem__( + 'date_time', + date_time + ) @property def uuid(self): """Gets the uuid of this FormatTest. # noqa: E501 - :return: The uuid of this FormatTest. # noqa: E501 - :rtype: str + Returns: + (str): The uuid of this FormatTest. # noqa: E501 """ - return self._uuid + return self._data_store.get('uuid') @uuid.setter - def uuid(self, uuid): + def uuid( + self, uuid): """Sets the uuid of this FormatTest. - :param uuid: The uuid of this FormatTest. # noqa: E501 - :type: str + Returns: + (str): The uuid of this FormatTest. # noqa: E501 """ - self._uuid = uuid + self.__setitem__( + 'uuid', + uuid + ) @property def password(self): """Gets the password of this FormatTest. # noqa: E501 - :return: The password of this FormatTest. # noqa: E501 - :rtype: str + Returns: + (str): The password of this FormatTest. # noqa: E501 """ - return self._password + return self._data_store.get('password') @password.setter - def password(self, password): + def password( + self, password): """Sets the password of this FormatTest. - :param password: The password of this FormatTest. # noqa: E501 - :type: str + Returns: + (str): The password of this FormatTest. # noqa: E501 """ if password is None: - raise ValueError("Invalid value for `password`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `password`, must not be `None`") # noqa: E501 if password is not None and len(password) > 64: - raise ValueError("Invalid value for `password`, length must be less than or equal to `64`") # noqa: E501 + raise ApiValueError("Invalid value for `password`, length must be less than or equal to `64`") # noqa: E501 if password is not None and len(password) < 10: - raise ValueError("Invalid value for `password`, length must be greater than or equal to `10`") # noqa: E501 + raise ApiValueError("Invalid value for `password`, length must be greater than or equal to `10`") # noqa: E501 - self._password = password + self.__setitem__( + 'password', + password + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/has_only_read_only.py b/samples/client/petstore/python/petstore_api/models/has_only_read_only.py index 41db3ff71958..eeff7da1fbaf 100644 --- a/samples/client/petstore/python/petstore_api/models/has_only_read_only.py +++ b/samples/client/petstore/python/petstore_api/models/has_only_read_only.py @@ -15,8 +15,27 @@ import six - -class HasOnlyReadOnly(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class HasOnlyReadOnly(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +46,163 @@ class HasOnlyReadOnly(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'bar': 'str', - 'foo': 'str' + 'bar': [str], # noqa: E501 + 'foo': [str] # noqa: E501 } - attribute_map = { - 'bar': 'bar', - 'foo': 'foo' + 'bar': 'bar', # noqa: E501 + 'foo': 'foo' # noqa: E501 } - def __init__(self, bar=None, foo=None): # noqa: E501 - """HasOnlyReadOnly - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """HasOnlyReadOnly - 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 False + _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 + _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. + bar (str): [optional] # noqa: E501 + foo (str): [optional] # noqa: E501 + """ - self._bar = None - self._foo = None + self._data_store = {} self.discriminator = None - - if bar is not None: - self.bar = bar - if foo is not None: - self.foo = foo + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def bar(self): """Gets the bar of this HasOnlyReadOnly. # noqa: E501 - :return: The bar of this HasOnlyReadOnly. # noqa: E501 - :rtype: str + Returns: + (str): The bar of this HasOnlyReadOnly. # noqa: E501 """ - return self._bar + return self._data_store.get('bar') @bar.setter - def bar(self, bar): + def bar( + self, bar): """Sets the bar of this HasOnlyReadOnly. - :param bar: The bar of this HasOnlyReadOnly. # noqa: E501 - :type: str + Returns: + (str): The bar of this HasOnlyReadOnly. # noqa: E501 """ - self._bar = bar + self.__setitem__( + 'bar', + bar + ) @property def foo(self): """Gets the foo of this HasOnlyReadOnly. # noqa: E501 - :return: The foo of this HasOnlyReadOnly. # noqa: E501 - :rtype: str + Returns: + (str): The foo of this HasOnlyReadOnly. # noqa: E501 """ - return self._foo + return self._data_store.get('foo') @foo.setter - def foo(self, foo): + def foo( + self, foo): """Sets the foo of this HasOnlyReadOnly. - :param foo: The foo of this HasOnlyReadOnly. # noqa: E501 - :type: str + Returns: + (str): The foo of this HasOnlyReadOnly. # noqa: E501 """ - self._foo = foo + self.__setitem__( + 'foo', + foo + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/list.py b/samples/client/petstore/python/petstore_api/models/list.py index 08e12ad53104..71b3c3ea4033 100644 --- a/samples/client/petstore/python/petstore_api/models/list.py +++ b/samples/client/petstore/python/petstore_api/models/list.py @@ -15,8 +15,27 @@ import six - -class List(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class List(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class List(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - '_123_list': 'str' + '_123_list': [str] # noqa: E501 } - attribute_map = { - '_123_list': '123-list' + '_123_list': '123-list' # noqa: E501 } - def __init__(self, _123_list=None): # noqa: E501 - """List - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """List - a model defined in OpenAPI - self.__123_list = None - self.discriminator = None - if _123_list is not None: - self._123_list = _123_list + + 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 False + _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 + _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. + _123_list (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def _123_list(self): """Gets the _123_list of this List. # noqa: E501 - :return: The _123_list of this List. # noqa: E501 - :rtype: str + Returns: + (str): The _123_list of this List. # noqa: E501 """ - return self.__123_list + return self._data_store.get('_123_list') @_123_list.setter - def _123_list(self, _123_list): + def _123_list( + self, _123_list): """Sets the _123_list of this List. - :param _123_list: The _123_list of this List. # noqa: E501 - :type: str + Returns: + (str): The _123_list of this List. # noqa: E501 """ - self.__123_list = _123_list + self.__setitem__( + '_123_list', + _123_list + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/map_test.py b/samples/client/petstore/python/petstore_api/models/map_test.py index f04bd2cc1421..c846484fb60f 100644 --- a/samples/client/petstore/python/petstore_api/models/map_test.py +++ b/samples/client/petstore/python/petstore_api/models/map_test.py @@ -15,8 +15,27 @@ import six - -class MapTest(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class MapTest(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,155 +46,226 @@ class MapTest(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'map_map_of_string': 'dict(str, dict(str, str))', - 'map_of_enum_string': 'dict(str, str)', - 'direct_map': 'dict(str, bool)', - 'indirect_map': 'dict(str, bool)' + 'map_map_of_string': [{str: ({str: (str,)},)}], # noqa: E501 + 'map_of_enum_string': [{str: (str,)}], # noqa: E501 + 'direct_map': [{str: (bool,)}], # noqa: E501 + 'indirect_map': [{str: (bool,)}] # noqa: E501 } - attribute_map = { - 'map_map_of_string': 'map_map_of_string', - 'map_of_enum_string': 'map_of_enum_string', - 'direct_map': 'direct_map', - 'indirect_map': 'indirect_map' + 'map_map_of_string': 'map_map_of_string', # noqa: E501 + 'map_of_enum_string': 'map_of_enum_string', # noqa: E501 + 'direct_map': 'direct_map', # noqa: E501 + 'indirect_map': 'indirect_map' # noqa: E501 } - def __init__(self, map_map_of_string=None, map_of_enum_string=None, direct_map=None, indirect_map=None): # noqa: E501 - """MapTest - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """MapTest - 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 False + _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 + _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. + map_map_of_string ({str: ({str: (str,)},)}): [optional] # noqa: E501 + map_of_enum_string ({str: (str,)}): [optional] # noqa: E501 + direct_map ({str: (bool,)}): [optional] # noqa: E501 + indirect_map ({str: (bool,)}): [optional] # noqa: E501 + """ - self._map_map_of_string = None - self._map_of_enum_string = None - self._direct_map = None - self._indirect_map = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) - if map_map_of_string is not None: - self.map_map_of_string = map_map_of_string - if map_of_enum_string is not None: - self.map_of_enum_string = map_of_enum_string - if direct_map is not None: - self.direct_map = direct_map - if indirect_map is not None: - self.indirect_map = indirect_map + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def map_map_of_string(self): """Gets the map_map_of_string of this MapTest. # noqa: E501 - :return: The map_map_of_string of this MapTest. # noqa: E501 - :rtype: dict(str, dict(str, str)) + Returns: + ({str: ({str: (str,)},)}): The map_map_of_string of this MapTest. # noqa: E501 """ - return self._map_map_of_string + return self._data_store.get('map_map_of_string') @map_map_of_string.setter - def map_map_of_string(self, map_map_of_string): + def map_map_of_string( + self, map_map_of_string): """Sets the map_map_of_string of this MapTest. - :param map_map_of_string: The map_map_of_string of this MapTest. # noqa: E501 - :type: dict(str, dict(str, str)) + Returns: + ({str: ({str: (str,)},)}): The map_map_of_string of this MapTest. # noqa: E501 """ - self._map_map_of_string = map_map_of_string + self.__setitem__( + 'map_map_of_string', + map_map_of_string + ) @property def map_of_enum_string(self): """Gets the map_of_enum_string of this MapTest. # noqa: E501 - :return: The map_of_enum_string of this MapTest. # noqa: E501 - :rtype: dict(str, str) + Returns: + ({str: (str,)}): The map_of_enum_string of this MapTest. # noqa: E501 """ - return self._map_of_enum_string + return self._data_store.get('map_of_enum_string') @map_of_enum_string.setter - def map_of_enum_string(self, map_of_enum_string): + def map_of_enum_string( + self, map_of_enum_string): """Sets the map_of_enum_string of this MapTest. - :param map_of_enum_string: The map_of_enum_string of this MapTest. # noqa: E501 - :type: dict(str, str) + Returns: + ({str: (str,)}): The map_of_enum_string of this MapTest. # noqa: E501 """ allowed_values = ["UPPER", "lower"] # noqa: E501 if not set(map_of_enum_string.keys()).issubset(set(allowed_values)): - raise ValueError( + raise ApiValueError( "Invalid keys in `map_of_enum_string` [{0}], must be a subset of [{1}]" # noqa: E501 .format(", ".join(map(str, set(map_of_enum_string.keys()) - set(allowed_values))), # noqa: E501 ", ".join(map(str, allowed_values))) ) - self._map_of_enum_string = map_of_enum_string + self.__setitem__( + 'map_of_enum_string', + map_of_enum_string + ) @property def direct_map(self): """Gets the direct_map of this MapTest. # noqa: E501 - :return: The direct_map of this MapTest. # noqa: E501 - :rtype: dict(str, bool) + Returns: + ({str: (bool,)}): The direct_map of this MapTest. # noqa: E501 """ - return self._direct_map + return self._data_store.get('direct_map') @direct_map.setter - def direct_map(self, direct_map): + def direct_map( + self, direct_map): """Sets the direct_map of this MapTest. - :param direct_map: The direct_map of this MapTest. # noqa: E501 - :type: dict(str, bool) + Returns: + ({str: (bool,)}): The direct_map of this MapTest. # noqa: E501 """ - self._direct_map = direct_map + self.__setitem__( + 'direct_map', + direct_map + ) @property def indirect_map(self): """Gets the indirect_map of this MapTest. # noqa: E501 - :return: The indirect_map of this MapTest. # noqa: E501 - :rtype: dict(str, bool) + Returns: + ({str: (bool,)}): The indirect_map of this MapTest. # noqa: E501 """ - return self._indirect_map + return self._data_store.get('indirect_map') @indirect_map.setter - def indirect_map(self, indirect_map): + def indirect_map( + self, indirect_map): """Sets the indirect_map of this MapTest. - :param indirect_map: The indirect_map of this MapTest. # noqa: E501 - :type: dict(str, bool) + Returns: + ({str: (bool,)}): The indirect_map of this MapTest. # noqa: E501 """ - self._indirect_map = indirect_map + self.__setitem__( + 'indirect_map', + indirect_map + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/mixed_properties_and_additional_properties_class.py b/samples/client/petstore/python/petstore_api/models/mixed_properties_and_additional_properties_class.py index ecf67acc5e95..1d61e2c659ff 100644 --- a/samples/client/petstore/python/petstore_api/models/mixed_properties_and_additional_properties_class.py +++ b/samples/client/petstore/python/petstore_api/models/mixed_properties_and_additional_properties_class.py @@ -15,8 +15,28 @@ import six - -class MixedPropertiesAndAdditionalPropertiesClass(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.animal import Animal + + +class MixedPropertiesAndAdditionalPropertiesClass(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,122 +47,191 @@ class MixedPropertiesAndAdditionalPropertiesClass(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'uuid': 'str', - 'date_time': 'datetime', - 'map': 'dict(str, Animal)' + 'uuid': [str], # noqa: E501 + 'date_time': [datetime], # noqa: E501 + 'map': [{str: (Animal,)}] # noqa: E501 } - attribute_map = { - 'uuid': 'uuid', - 'date_time': 'dateTime', - 'map': 'map' + 'uuid': 'uuid', # noqa: E501 + 'date_time': 'dateTime', # noqa: E501 + 'map': 'map' # noqa: E501 } - def __init__(self, uuid=None, date_time=None, map=None): # noqa: E501 - """MixedPropertiesAndAdditionalPropertiesClass - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """MixedPropertiesAndAdditionalPropertiesClass - 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 False + _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 + _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. + uuid (str): [optional] # noqa: E501 + date_time (datetime): [optional] # noqa: E501 + map ({str: (Animal,)}): [optional] # noqa: E501 + """ - self._uuid = None - self._date_time = None - self._map = None + self._data_store = {} self.discriminator = None - - if uuid is not None: - self.uuid = uuid - if date_time is not None: - self.date_time = date_time - if map is not None: - self.map = map + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def uuid(self): """Gets the uuid of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :return: The uuid of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :rtype: str + Returns: + (str): The uuid of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - return self._uuid + return self._data_store.get('uuid') @uuid.setter - def uuid(self, uuid): + def uuid( + self, uuid): """Sets the uuid of this MixedPropertiesAndAdditionalPropertiesClass. - :param uuid: The uuid of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :type: str + Returns: + (str): The uuid of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - self._uuid = uuid + self.__setitem__( + 'uuid', + uuid + ) @property def date_time(self): """Gets the date_time of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :return: The date_time of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :rtype: datetime + Returns: + (datetime): The date_time of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - return self._date_time + return self._data_store.get('date_time') @date_time.setter - def date_time(self, date_time): + def date_time( + self, date_time): """Sets the date_time of this MixedPropertiesAndAdditionalPropertiesClass. - :param date_time: The date_time of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :type: datetime + Returns: + (datetime): The date_time of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - self._date_time = date_time + self.__setitem__( + 'date_time', + date_time + ) @property def map(self): """Gets the map of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :return: The map of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :rtype: dict(str, Animal) + Returns: + ({str: (Animal,)}): The map of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - return self._map + return self._data_store.get('map') @map.setter - def map(self, map): + def map( + self, map): """Sets the map of this MixedPropertiesAndAdditionalPropertiesClass. - :param map: The map of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :type: dict(str, Animal) + Returns: + ({str: (Animal,)}): The map of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - self._map = map + self.__setitem__( + 'map', + map + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/model200_response.py b/samples/client/petstore/python/petstore_api/models/model200_response.py index ec778cdcb74b..e44d7f28022e 100644 --- a/samples/client/petstore/python/petstore_api/models/model200_response.py +++ b/samples/client/petstore/python/petstore_api/models/model200_response.py @@ -15,8 +15,27 @@ import six - -class Model200Response(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Model200Response(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +46,163 @@ class Model200Response(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'name': 'int', - '_class': 'str' + 'name': [int], # noqa: E501 + '_class': [str] # noqa: E501 } - attribute_map = { - 'name': 'name', - '_class': 'class' + 'name': 'name', # noqa: E501 + '_class': 'class' # noqa: E501 } - def __init__(self, name=None, _class=None): # noqa: E501 - """Model200Response - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Model200Response - 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 False + _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 + _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. + name (int): [optional] # noqa: E501 + _class (str): [optional] # noqa: E501 + """ - self._name = None - self.__class = None + self._data_store = {} self.discriminator = None - - if name is not None: - self.name = name - if _class is not None: - self._class = _class + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def name(self): """Gets the name of this Model200Response. # noqa: E501 - :return: The name of this Model200Response. # noqa: E501 - :rtype: int + Returns: + (int): The name of this Model200Response. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this Model200Response. - :param name: The name of this Model200Response. # noqa: E501 - :type: int + Returns: + (int): The name of this Model200Response. # noqa: E501 """ - self._name = name + self.__setitem__( + 'name', + name + ) @property def _class(self): """Gets the _class of this Model200Response. # noqa: E501 - :return: The _class of this Model200Response. # noqa: E501 - :rtype: str + Returns: + (str): The _class of this Model200Response. # noqa: E501 """ - return self.__class + return self._data_store.get('_class') @_class.setter - def _class(self, _class): + def _class( + self, _class): """Sets the _class of this Model200Response. - :param _class: The _class of this Model200Response. # noqa: E501 - :type: str + Returns: + (str): The _class of this Model200Response. # noqa: E501 """ - self.__class = _class + self.__setitem__( + '_class', + _class + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/model_return.py b/samples/client/petstore/python/petstore_api/models/model_return.py index 3862245ef71d..7f3e64a12ab5 100644 --- a/samples/client/petstore/python/petstore_api/models/model_return.py +++ b/samples/client/petstore/python/petstore_api/models/model_return.py @@ -15,8 +15,27 @@ import six - -class ModelReturn(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ModelReturn(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class ModelReturn(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - '_return': 'int' + '_return': [int] # noqa: E501 } - attribute_map = { - '_return': 'return' + '_return': 'return' # noqa: E501 } - def __init__(self, _return=None): # noqa: E501 - """ModelReturn - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ModelReturn - a model defined in OpenAPI - self.__return = None - self.discriminator = None - if _return is not None: - self._return = _return + + 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 False + _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 + _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. + _return (int): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def _return(self): """Gets the _return of this ModelReturn. # noqa: E501 - :return: The _return of this ModelReturn. # noqa: E501 - :rtype: int + Returns: + (int): The _return of this ModelReturn. # noqa: E501 """ - return self.__return + return self._data_store.get('_return') @_return.setter - def _return(self, _return): + def _return( + self, _return): """Sets the _return of this ModelReturn. - :param _return: The _return of this ModelReturn. # noqa: E501 - :type: int + Returns: + (int): The _return of this ModelReturn. # noqa: E501 """ - self.__return = _return + self.__setitem__( + '_return', + _return + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/name.py b/samples/client/petstore/python/petstore_api/models/name.py index b2e97e596a4d..1b06fe765b43 100644 --- a/samples/client/petstore/python/petstore_api/models/name.py +++ b/samples/client/petstore/python/petstore_api/models/name.py @@ -15,8 +15,27 @@ import six - -class Name(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Name(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,149 +46,223 @@ class Name(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'name': 'int', - 'snake_case': 'int', - '_property': 'str', - '_123_number': 'int' + 'name': [int], # noqa: E501 + 'snake_case': [int], # noqa: E501 + '_property': [str], # noqa: E501 + '_123_number': [int] # noqa: E501 } - attribute_map = { - 'name': 'name', - 'snake_case': 'snake_case', - '_property': 'property', - '_123_number': '123Number' + 'name': 'name', # noqa: E501 + 'snake_case': 'snake_case', # noqa: E501 + '_property': 'property', # noqa: E501 + '_123_number': '123Number' # noqa: E501 } - def __init__(self, name=None, snake_case=None, _property=None, _123_number=None): # noqa: E501 - """Name - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, name, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Name - a model defined in OpenAPI + + Args: + name (int): + + 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 False + _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 + _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. + snake_case (int): [optional] # noqa: E501 + _property (str): [optional] # noqa: E501 + _123_number (int): [optional] # noqa: E501 + """ - self._name = None - self._snake_case = None - self.__property = None - self.__123_number = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + # assign using .var_name to check against nullable and enums self.name = name - if snake_case is not None: - self.snake_case = snake_case - if _property is not None: - self._property = _property - if _123_number is not None: - self._123_number = _123_number + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def name(self): """Gets the name of this Name. # noqa: E501 - :return: The name of this Name. # noqa: E501 - :rtype: int + Returns: + (int): The name of this Name. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this Name. - :param name: The name of this Name. # noqa: E501 - :type: int + Returns: + (int): The name of this Name. # noqa: E501 """ if name is None: - raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `name`, must not be `None`") # noqa: E501 - self._name = name + self.__setitem__( + 'name', + name + ) @property def snake_case(self): """Gets the snake_case of this Name. # noqa: E501 - :return: The snake_case of this Name. # noqa: E501 - :rtype: int + Returns: + (int): The snake_case of this Name. # noqa: E501 """ - return self._snake_case + return self._data_store.get('snake_case') @snake_case.setter - def snake_case(self, snake_case): + def snake_case( + self, snake_case): """Sets the snake_case of this Name. - :param snake_case: The snake_case of this Name. # noqa: E501 - :type: int + Returns: + (int): The snake_case of this Name. # noqa: E501 """ - self._snake_case = snake_case + self.__setitem__( + 'snake_case', + snake_case + ) @property def _property(self): """Gets the _property of this Name. # noqa: E501 - :return: The _property of this Name. # noqa: E501 - :rtype: str + Returns: + (str): The _property of this Name. # noqa: E501 """ - return self.__property + return self._data_store.get('_property') @_property.setter - def _property(self, _property): + def _property( + self, _property): """Sets the _property of this Name. - :param _property: The _property of this Name. # noqa: E501 - :type: str + Returns: + (str): The _property of this Name. # noqa: E501 """ - self.__property = _property + self.__setitem__( + '_property', + _property + ) @property def _123_number(self): """Gets the _123_number of this Name. # noqa: E501 - :return: The _123_number of this Name. # noqa: E501 - :rtype: int + Returns: + (int): The _123_number of this Name. # noqa: E501 """ - return self.__123_number + return self._data_store.get('_123_number') @_123_number.setter - def _123_number(self, _123_number): + def _123_number( + self, _123_number): """Sets the _123_number of this Name. - :param _123_number: The _123_number of this Name. # noqa: E501 - :type: int + Returns: + (int): The _123_number of this Name. # noqa: E501 """ - self.__123_number = _123_number + self.__setitem__( + '_123_number', + _123_number + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/number_only.py b/samples/client/petstore/python/petstore_api/models/number_only.py index ab39ee8195d4..8cbc7054da0b 100644 --- a/samples/client/petstore/python/petstore_api/models/number_only.py +++ b/samples/client/petstore/python/petstore_api/models/number_only.py @@ -15,8 +15,27 @@ import six - -class NumberOnly(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class NumberOnly(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class NumberOnly(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'just_number': 'float' + 'just_number': [float] # noqa: E501 } - attribute_map = { - 'just_number': 'JustNumber' + 'just_number': 'JustNumber' # noqa: E501 } - def __init__(self, just_number=None): # noqa: E501 - """NumberOnly - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """NumberOnly - a model defined in OpenAPI - self._just_number = None - self.discriminator = None - if just_number is not None: - self.just_number = just_number + + 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 False + _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 + _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. + just_number (float): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def just_number(self): """Gets the just_number of this NumberOnly. # noqa: E501 - :return: The just_number of this NumberOnly. # noqa: E501 - :rtype: float + Returns: + (float): The just_number of this NumberOnly. # noqa: E501 """ - return self._just_number + return self._data_store.get('just_number') @just_number.setter - def just_number(self, just_number): + def just_number( + self, just_number): """Sets the just_number of this NumberOnly. - :param just_number: The just_number of this NumberOnly. # noqa: E501 - :type: float + Returns: + (float): The just_number of this NumberOnly. # noqa: E501 """ - self._just_number = just_number + self.__setitem__( + 'just_number', + just_number + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/order.py b/samples/client/petstore/python/petstore_api/models/order.py index 697d84447cdc..8f5e45a33be8 100644 --- a/samples/client/petstore/python/petstore_api/models/order.py +++ b/samples/client/petstore/python/petstore_api/models/order.py @@ -15,8 +15,27 @@ import six - -class Order(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Order(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,134 +46,221 @@ class Order(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'id': 'int', - 'pet_id': 'int', - 'quantity': 'int', - 'ship_date': 'datetime', - 'status': 'str', - 'complete': 'bool' + 'id': [int], # noqa: E501 + 'pet_id': [int], # noqa: E501 + 'quantity': [int], # noqa: E501 + 'ship_date': [datetime], # noqa: E501 + 'status': [str], # noqa: E501 + 'complete': [bool] # noqa: E501 } - attribute_map = { - 'id': 'id', - 'pet_id': 'petId', - 'quantity': 'quantity', - 'ship_date': 'shipDate', - 'status': 'status', - 'complete': 'complete' + 'id': 'id', # noqa: E501 + 'pet_id': 'petId', # noqa: E501 + 'quantity': 'quantity', # noqa: E501 + 'ship_date': 'shipDate', # noqa: E501 + 'status': 'status', # noqa: E501 + 'complete': 'complete' # noqa: E501 } - def __init__(self, id=None, pet_id=None, quantity=None, ship_date=None, status=None, complete=False): # noqa: E501 - """Order - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Order - 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 False + _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 + _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. + id (int): [optional] # noqa: E501 + pet_id (int): [optional] # noqa: E501 + quantity (int): [optional] # noqa: E501 + ship_date (datetime): [optional] # noqa: E501 + status (str): Order Status. [optional] # noqa: E501 + complete (bool): [optional] if omitted the server will use the default value of False # noqa: E501 + """ - self._id = None - self._pet_id = None - self._quantity = None - self._ship_date = None - self._status = None - self._complete = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) - if id is not None: - self.id = id - if pet_id is not None: - self.pet_id = pet_id - if quantity is not None: - self.quantity = quantity - if ship_date is not None: - self.ship_date = ship_date - if status is not None: - self.status = status - if complete is not None: - self.complete = complete + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def id(self): """Gets the id of this Order. # noqa: E501 - :return: The id of this Order. # noqa: E501 - :rtype: int + Returns: + (int): The id of this Order. # noqa: E501 """ - return self._id + return self._data_store.get('id') @id.setter - def id(self, id): + def id( + self, id): """Sets the id of this Order. - :param id: The id of this Order. # noqa: E501 - :type: int + Returns: + (int): The id of this Order. # noqa: E501 """ - self._id = id + self.__setitem__( + 'id', + id + ) @property def pet_id(self): """Gets the pet_id of this Order. # noqa: E501 - :return: The pet_id of this Order. # noqa: E501 - :rtype: int + Returns: + (int): The pet_id of this Order. # noqa: E501 """ - return self._pet_id + return self._data_store.get('pet_id') @pet_id.setter - def pet_id(self, pet_id): + def pet_id( + self, pet_id): """Sets the pet_id of this Order. - :param pet_id: The pet_id of this Order. # noqa: E501 - :type: int + Returns: + (int): The pet_id of this Order. # noqa: E501 """ - self._pet_id = pet_id + self.__setitem__( + 'pet_id', + pet_id + ) @property def quantity(self): """Gets the quantity of this Order. # noqa: E501 - :return: The quantity of this Order. # noqa: E501 - :rtype: int + Returns: + (int): The quantity of this Order. # noqa: E501 """ - return self._quantity + return self._data_store.get('quantity') @quantity.setter - def quantity(self, quantity): + def quantity( + self, quantity): """Sets the quantity of this Order. - :param quantity: The quantity of this Order. # noqa: E501 - :type: int + Returns: + (int): The quantity of this Order. # noqa: E501 """ - self._quantity = quantity + self.__setitem__( + 'quantity', + quantity + ) @property def ship_date(self): """Gets the ship_date of this Order. # noqa: E501 - :return: The ship_date of this Order. # noqa: E501 - :rtype: datetime + Returns: + (datetime): The ship_date of this Order. # noqa: E501 """ - return self._ship_date + return self._data_store.get('ship_date') @ship_date.setter - def ship_date(self, ship_date): + def ship_date( + self, ship_date): """Sets the ship_date of this Order. - :param ship_date: The ship_date of this Order. # noqa: E501 - :type: datetime + Returns: + (datetime): The ship_date of this Order. # noqa: E501 """ - self._ship_date = ship_date + self.__setitem__( + 'ship_date', + ship_date + ) @property def status(self): @@ -162,73 +268,61 @@ def status(self): Order Status # noqa: E501 - :return: The status of this Order. # noqa: E501 - :rtype: str + Returns: + (str): The status of this Order. # noqa: E501 """ - return self._status + return self._data_store.get('status') @status.setter - def status(self, status): + def status( + self, status): """Sets the status of this Order. Order Status # noqa: E501 - :param status: The status of this Order. # noqa: E501 - :type: str + Returns: + (str): The status of this Order. # noqa: E501 """ allowed_values = ["placed", "approved", "delivered"] # noqa: E501 if status not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `status` ({0}), must be one of {1}" # noqa: E501 .format(status, allowed_values) ) - self._status = status + self.__setitem__( + 'status', + status + ) @property def complete(self): """Gets the complete of this Order. # noqa: E501 - :return: The complete of this Order. # noqa: E501 - :rtype: bool + Returns: + (bool): The complete of this Order. # noqa: E501 """ - return self._complete + return self._data_store.get('complete') @complete.setter - def complete(self, complete): + def complete( + self, complete): """Sets the complete of this Order. - :param complete: The complete of this Order. # noqa: E501 - :type: bool + Returns: + (bool): The complete of this Order. # noqa: E501 """ - self._complete = complete + self.__setitem__( + 'complete', + complete + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/outer_composite.py b/samples/client/petstore/python/petstore_api/models/outer_composite.py index b22b16c6fdcd..3da4dfb6426d 100644 --- a/samples/client/petstore/python/petstore_api/models/outer_composite.py +++ b/samples/client/petstore/python/petstore_api/models/outer_composite.py @@ -15,8 +15,27 @@ import six - -class OuterComposite(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class OuterComposite(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,122 +46,191 @@ class OuterComposite(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'my_number': 'float', - 'my_string': 'str', - 'my_boolean': 'bool' + 'my_number': [float], # noqa: E501 + 'my_string': [str], # noqa: E501 + 'my_boolean': [bool] # noqa: E501 } - attribute_map = { - 'my_number': 'my_number', - 'my_string': 'my_string', - 'my_boolean': 'my_boolean' + 'my_number': 'my_number', # noqa: E501 + 'my_string': 'my_string', # noqa: E501 + 'my_boolean': 'my_boolean' # noqa: E501 } - def __init__(self, my_number=None, my_string=None, my_boolean=None): # noqa: E501 - """OuterComposite - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """OuterComposite - 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 False + _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 + _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. + my_number (float): [optional] # noqa: E501 + my_string (str): [optional] # noqa: E501 + my_boolean (bool): [optional] # noqa: E501 + """ - self._my_number = None - self._my_string = None - self._my_boolean = None + self._data_store = {} self.discriminator = None - - if my_number is not None: - self.my_number = my_number - if my_string is not None: - self.my_string = my_string - if my_boolean is not None: - self.my_boolean = my_boolean + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def my_number(self): """Gets the my_number of this OuterComposite. # noqa: E501 - :return: The my_number of this OuterComposite. # noqa: E501 - :rtype: float + Returns: + (float): The my_number of this OuterComposite. # noqa: E501 """ - return self._my_number + return self._data_store.get('my_number') @my_number.setter - def my_number(self, my_number): + def my_number( + self, my_number): """Sets the my_number of this OuterComposite. - :param my_number: The my_number of this OuterComposite. # noqa: E501 - :type: float + Returns: + (float): The my_number of this OuterComposite. # noqa: E501 """ - self._my_number = my_number + self.__setitem__( + 'my_number', + my_number + ) @property def my_string(self): """Gets the my_string of this OuterComposite. # noqa: E501 - :return: The my_string of this OuterComposite. # noqa: E501 - :rtype: str + Returns: + (str): The my_string of this OuterComposite. # noqa: E501 """ - return self._my_string + return self._data_store.get('my_string') @my_string.setter - def my_string(self, my_string): + def my_string( + self, my_string): """Sets the my_string of this OuterComposite. - :param my_string: The my_string of this OuterComposite. # noqa: E501 - :type: str + Returns: + (str): The my_string of this OuterComposite. # noqa: E501 """ - self._my_string = my_string + self.__setitem__( + 'my_string', + my_string + ) @property def my_boolean(self): """Gets the my_boolean of this OuterComposite. # noqa: E501 - :return: The my_boolean of this OuterComposite. # noqa: E501 - :rtype: bool + Returns: + (bool): The my_boolean of this OuterComposite. # noqa: E501 """ - return self._my_boolean + return self._data_store.get('my_boolean') @my_boolean.setter - def my_boolean(self, my_boolean): + def my_boolean( + self, my_boolean): """Sets the my_boolean of this OuterComposite. - :param my_boolean: The my_boolean of this OuterComposite. # noqa: E501 - :type: bool + Returns: + (bool): The my_boolean of this OuterComposite. # noqa: E501 """ - self._my_boolean = my_boolean + self.__setitem__( + 'my_boolean', + my_boolean + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/outer_enum.py b/samples/client/petstore/python/petstore_api/models/outer_enum.py index 10d6be19a4c9..9d4398b5188d 100644 --- a/samples/client/petstore/python/petstore_api/models/outer_enum.py +++ b/samples/client/petstore/python/petstore_api/models/outer_enum.py @@ -15,8 +15,27 @@ import six - -class OuterEnum(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class OuterEnum(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -34,42 +53,107 @@ class OuterEnum(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { } - attribute_map = { } - def __init__(self): # noqa: E501 - """OuterEnum - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """OuterEnum - 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 False + _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 + _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. + """ + + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/pet.py b/samples/client/petstore/python/petstore_api/models/pet.py index d3c412f4a82b..1b30f1186d6f 100644 --- a/samples/client/petstore/python/petstore_api/models/pet.py +++ b/samples/client/petstore/python/petstore_api/models/pet.py @@ -15,8 +15,29 @@ import six - -class Pet(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.category import Category +from petstore_api.models.tag import Tag + + +class Pet(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,157 +48,253 @@ class Pet(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'id': 'int', - 'category': 'Category', - 'name': 'str', - 'photo_urls': 'list[str]', - 'tags': 'list[Tag]', - 'status': 'str' + 'id': [int], # noqa: E501 + 'category': [Category], # noqa: E501 + 'name': [str], # noqa: E501 + 'photo_urls': [[(str,)]], # noqa: E501 + 'tags': [[(Tag,)]], # noqa: E501 + 'status': [str] # noqa: E501 } - attribute_map = { - 'id': 'id', - 'category': 'category', - 'name': 'name', - 'photo_urls': 'photoUrls', - 'tags': 'tags', - 'status': 'status' + 'id': 'id', # noqa: E501 + 'category': 'category', # noqa: E501 + 'name': 'name', # noqa: E501 + 'photo_urls': 'photoUrls', # noqa: E501 + 'tags': 'tags', # noqa: E501 + 'status': 'status' # noqa: E501 } - def __init__(self, id=None, category=None, name=None, photo_urls=None, tags=None, status=None): # noqa: E501 - """Pet - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, name, photo_urls, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Pet - a model defined in OpenAPI + + Args: + name (str): + photo_urls ([(str,)]): + + 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 False + _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 + _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. + id (int): [optional] # noqa: E501 + category (Category): [optional] # noqa: E501 + tags ([(Tag,)]): [optional] # noqa: E501 + status (str): pet status in the store. [optional] # noqa: E501 + """ - self._id = None - self._category = None - self._name = None - self._photo_urls = None - self._tags = None - self._status = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration - if id is not None: - self.id = id - if category is not None: - self.category = category + # assign using .var_name to check against nullable and enums self.name = name self.photo_urls = photo_urls - if tags is not None: - self.tags = tags - if status is not None: - self.status = status + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def id(self): """Gets the id of this Pet. # noqa: E501 - :return: The id of this Pet. # noqa: E501 - :rtype: int + Returns: + (int): The id of this Pet. # noqa: E501 """ - return self._id + return self._data_store.get('id') @id.setter - def id(self, id): + def id( + self, id): """Sets the id of this Pet. - :param id: The id of this Pet. # noqa: E501 - :type: int + Returns: + (int): The id of this Pet. # noqa: E501 """ - self._id = id + self.__setitem__( + 'id', + id + ) @property def category(self): """Gets the category of this Pet. # noqa: E501 - :return: The category of this Pet. # noqa: E501 - :rtype: Category + Returns: + (Category): The category of this Pet. # noqa: E501 """ - return self._category + return self._data_store.get('category') @category.setter - def category(self, category): + def category( + self, category): """Sets the category of this Pet. - :param category: The category of this Pet. # noqa: E501 - :type: Category + Returns: + (Category): The category of this Pet. # noqa: E501 """ - self._category = category + self.__setitem__( + 'category', + category + ) @property def name(self): """Gets the name of this Pet. # noqa: E501 - :return: The name of this Pet. # noqa: E501 - :rtype: str + Returns: + (str): The name of this Pet. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this Pet. - :param name: The name of this Pet. # noqa: E501 - :type: str + Returns: + (str): The name of this Pet. # noqa: E501 """ if name is None: - raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `name`, must not be `None`") # noqa: E501 - self._name = name + self.__setitem__( + 'name', + name + ) @property def photo_urls(self): """Gets the photo_urls of this Pet. # noqa: E501 - :return: The photo_urls of this Pet. # noqa: E501 - :rtype: list[str] + Returns: + ([(str,)]): The photo_urls of this Pet. # noqa: E501 """ - return self._photo_urls + return self._data_store.get('photo_urls') @photo_urls.setter - def photo_urls(self, photo_urls): + def photo_urls( + self, photo_urls): """Sets the photo_urls of this Pet. - :param photo_urls: The photo_urls of this Pet. # noqa: E501 - :type: list[str] + Returns: + ([(str,)]): The photo_urls of this Pet. # noqa: E501 """ if photo_urls is None: - raise ValueError("Invalid value for `photo_urls`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `photo_urls`, must not be `None`") # noqa: E501 - self._photo_urls = photo_urls + self.__setitem__( + 'photo_urls', + photo_urls + ) @property def tags(self): """Gets the tags of this Pet. # noqa: E501 - :return: The tags of this Pet. # noqa: E501 - :rtype: list[Tag] + Returns: + ([(Tag,)]): The tags of this Pet. # noqa: E501 """ - return self._tags + return self._data_store.get('tags') @tags.setter - def tags(self, tags): + def tags( + self, tags): """Sets the tags of this Pet. - :param tags: The tags of this Pet. # noqa: E501 - :type: list[Tag] + Returns: + ([(Tag,)]): The tags of this Pet. # noqa: E501 """ - self._tags = tags + self.__setitem__( + 'tags', + tags + ) @property def status(self): @@ -185,52 +302,36 @@ def status(self): pet status in the store # noqa: E501 - :return: The status of this Pet. # noqa: E501 - :rtype: str + Returns: + (str): The status of this Pet. # noqa: E501 """ - return self._status + return self._data_store.get('status') @status.setter - def status(self, status): + def status( + self, status): """Sets the status of this Pet. pet status in the store # noqa: E501 - :param status: The status of this Pet. # noqa: E501 - :type: str + Returns: + (str): The status of this Pet. # noqa: E501 """ allowed_values = ["available", "pending", "sold"] # noqa: E501 if status not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `status` ({0}), must be one of {1}" # noqa: E501 .format(status, allowed_values) ) - self._status = status + self.__setitem__( + 'status', + status + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/read_only_first.py b/samples/client/petstore/python/petstore_api/models/read_only_first.py index 2b257be18de4..0309488b3f37 100644 --- a/samples/client/petstore/python/petstore_api/models/read_only_first.py +++ b/samples/client/petstore/python/petstore_api/models/read_only_first.py @@ -15,8 +15,27 @@ import six - -class ReadOnlyFirst(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ReadOnlyFirst(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +46,163 @@ class ReadOnlyFirst(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'bar': 'str', - 'baz': 'str' + 'bar': [str], # noqa: E501 + 'baz': [str] # noqa: E501 } - attribute_map = { - 'bar': 'bar', - 'baz': 'baz' + 'bar': 'bar', # noqa: E501 + 'baz': 'baz' # noqa: E501 } - def __init__(self, bar=None, baz=None): # noqa: E501 - """ReadOnlyFirst - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ReadOnlyFirst - 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 False + _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 + _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. + bar (str): [optional] # noqa: E501 + baz (str): [optional] # noqa: E501 + """ - self._bar = None - self._baz = None + self._data_store = {} self.discriminator = None - - if bar is not None: - self.bar = bar - if baz is not None: - self.baz = baz + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def bar(self): """Gets the bar of this ReadOnlyFirst. # noqa: E501 - :return: The bar of this ReadOnlyFirst. # noqa: E501 - :rtype: str + Returns: + (str): The bar of this ReadOnlyFirst. # noqa: E501 """ - return self._bar + return self._data_store.get('bar') @bar.setter - def bar(self, bar): + def bar( + self, bar): """Sets the bar of this ReadOnlyFirst. - :param bar: The bar of this ReadOnlyFirst. # noqa: E501 - :type: str + Returns: + (str): The bar of this ReadOnlyFirst. # noqa: E501 """ - self._bar = bar + self.__setitem__( + 'bar', + bar + ) @property def baz(self): """Gets the baz of this ReadOnlyFirst. # noqa: E501 - :return: The baz of this ReadOnlyFirst. # noqa: E501 - :rtype: str + Returns: + (str): The baz of this ReadOnlyFirst. # noqa: E501 """ - return self._baz + return self._data_store.get('baz') @baz.setter - def baz(self, baz): + def baz( + self, baz): """Sets the baz of this ReadOnlyFirst. - :param baz: The baz of this ReadOnlyFirst. # noqa: E501 - :type: str + Returns: + (str): The baz of this ReadOnlyFirst. # noqa: E501 """ - self._baz = baz + self.__setitem__( + 'baz', + baz + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/special_model_name.py b/samples/client/petstore/python/petstore_api/models/special_model_name.py index fa59b887471b..9431157f2c3e 100644 --- a/samples/client/petstore/python/petstore_api/models/special_model_name.py +++ b/samples/client/petstore/python/petstore_api/models/special_model_name.py @@ -15,8 +15,27 @@ import six - -class SpecialModelName(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class SpecialModelName(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class SpecialModelName(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'special_property_name': 'int' + 'special_property_name': [int] # noqa: E501 } - attribute_map = { - 'special_property_name': '$special[property.name]' + 'special_property_name': '$special[property.name]' # noqa: E501 } - def __init__(self, special_property_name=None): # noqa: E501 - """SpecialModelName - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """SpecialModelName - a model defined in OpenAPI - self._special_property_name = None - self.discriminator = None - if special_property_name is not None: - self.special_property_name = special_property_name + + 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 False + _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 + _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. + special_property_name (int): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def special_property_name(self): """Gets the special_property_name of this SpecialModelName. # noqa: E501 - :return: The special_property_name of this SpecialModelName. # noqa: E501 - :rtype: int + Returns: + (int): The special_property_name of this SpecialModelName. # noqa: E501 """ - return self._special_property_name + return self._data_store.get('special_property_name') @special_property_name.setter - def special_property_name(self, special_property_name): + def special_property_name( + self, special_property_name): """Sets the special_property_name of this SpecialModelName. - :param special_property_name: The special_property_name of this SpecialModelName. # noqa: E501 - :type: int + Returns: + (int): The special_property_name of this SpecialModelName. # noqa: E501 """ - self._special_property_name = special_property_name + self.__setitem__( + 'special_property_name', + special_property_name + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/tag.py b/samples/client/petstore/python/petstore_api/models/tag.py index 8fcc8a848660..0c781dc5be7c 100644 --- a/samples/client/petstore/python/petstore_api/models/tag.py +++ b/samples/client/petstore/python/petstore_api/models/tag.py @@ -15,8 +15,27 @@ import six - -class Tag(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Tag(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +46,163 @@ class Tag(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'id': 'int', - 'name': 'str' + 'id': [int], # noqa: E501 + 'name': [str] # noqa: E501 } - attribute_map = { - 'id': 'id', - 'name': 'name' + 'id': 'id', # noqa: E501 + 'name': 'name' # noqa: E501 } - def __init__(self, id=None, name=None): # noqa: E501 - """Tag - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Tag - 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 False + _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 + _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. + id (int): [optional] # noqa: E501 + name (str): [optional] # noqa: E501 + """ - self._id = None - self._name = None + self._data_store = {} self.discriminator = None - - if id is not None: - self.id = id - if name is not None: - self.name = name + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def id(self): """Gets the id of this Tag. # noqa: E501 - :return: The id of this Tag. # noqa: E501 - :rtype: int + Returns: + (int): The id of this Tag. # noqa: E501 """ - return self._id + return self._data_store.get('id') @id.setter - def id(self, id): + def id( + self, id): """Sets the id of this Tag. - :param id: The id of this Tag. # noqa: E501 - :type: int + Returns: + (int): The id of this Tag. # noqa: E501 """ - self._id = id + self.__setitem__( + 'id', + id + ) @property def name(self): """Gets the name of this Tag. # noqa: E501 - :return: The name of this Tag. # noqa: E501 - :rtype: str + Returns: + (str): The name of this Tag. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this Tag. - :param name: The name of this Tag. # noqa: E501 - :type: str + Returns: + (str): The name of this Tag. # noqa: E501 """ - self._name = name + self.__setitem__( + 'name', + name + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/type_holder_default.py b/samples/client/petstore/python/petstore_api/models/type_holder_default.py index a0566f5d5fe6..88c3db03e30a 100644 --- a/samples/client/petstore/python/petstore_api/models/type_holder_default.py +++ b/samples/client/petstore/python/petstore_api/models/type_holder_default.py @@ -15,8 +15,27 @@ import six - -class TypeHolderDefault(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class TypeHolderDefault(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,179 +46,263 @@ class TypeHolderDefault(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'string_item': 'str', - 'number_item': 'float', - 'integer_item': 'int', - 'bool_item': 'bool', - 'array_item': 'list[int]' + 'string_item': [str], # noqa: E501 + 'number_item': [float], # noqa: E501 + 'integer_item': [int], # noqa: E501 + 'bool_item': [bool], # noqa: E501 + 'array_item': [[(int,)]] # noqa: E501 } - attribute_map = { - 'string_item': 'string_item', - 'number_item': 'number_item', - 'integer_item': 'integer_item', - 'bool_item': 'bool_item', - 'array_item': 'array_item' + 'string_item': 'string_item', # noqa: E501 + 'number_item': 'number_item', # noqa: E501 + 'integer_item': 'integer_item', # noqa: E501 + 'bool_item': 'bool_item', # noqa: E501 + 'array_item': 'array_item' # noqa: E501 } - def __init__(self, string_item='what', number_item=None, integer_item=None, bool_item=True, array_item=None): # noqa: E501 - """TypeHolderDefault - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, number_item, integer_item, array_item, string_item='what', bool_item=True, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """TypeHolderDefault - a model defined in OpenAPI + + Args: + number_item (float): + integer_item (int): + array_item ([(int,)]): + string_item (str): defaults to 'what', must be one of ['what'] # noqa: E501 + bool_item (bool): defaults to True, must be one of [True] # noqa: E501 + + 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 False + _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 + _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. + """ - self._string_item = None - self._number_item = None - self._integer_item = None - self._bool_item = None - self._array_item = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + # assign using .var_name to check against nullable and enums self.string_item = string_item self.number_item = number_item self.integer_item = integer_item self.bool_item = bool_item self.array_item = array_item + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def string_item(self): """Gets the string_item of this TypeHolderDefault. # noqa: E501 - :return: The string_item of this TypeHolderDefault. # noqa: E501 - :rtype: str + Returns: + (str): The string_item of this TypeHolderDefault. # noqa: E501 """ - return self._string_item + return self._data_store.get('string_item') @string_item.setter - def string_item(self, string_item): + def string_item( + self, string_item): """Sets the string_item of this TypeHolderDefault. - :param string_item: The string_item of this TypeHolderDefault. # noqa: E501 - :type: str + Returns: + (str): The string_item of this TypeHolderDefault. # noqa: E501 """ if string_item is None: - raise ValueError("Invalid value for `string_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `string_item`, must not be `None`") # noqa: E501 - self._string_item = string_item + self.__setitem__( + 'string_item', + string_item + ) @property def number_item(self): """Gets the number_item of this TypeHolderDefault. # noqa: E501 - :return: The number_item of this TypeHolderDefault. # noqa: E501 - :rtype: float + Returns: + (float): The number_item of this TypeHolderDefault. # noqa: E501 """ - return self._number_item + return self._data_store.get('number_item') @number_item.setter - def number_item(self, number_item): + def number_item( + self, number_item): """Sets the number_item of this TypeHolderDefault. - :param number_item: The number_item of this TypeHolderDefault. # noqa: E501 - :type: float + Returns: + (float): The number_item of this TypeHolderDefault. # noqa: E501 """ if number_item is None: - raise ValueError("Invalid value for `number_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `number_item`, must not be `None`") # noqa: E501 - self._number_item = number_item + self.__setitem__( + 'number_item', + number_item + ) @property def integer_item(self): """Gets the integer_item of this TypeHolderDefault. # noqa: E501 - :return: The integer_item of this TypeHolderDefault. # noqa: E501 - :rtype: int + Returns: + (int): The integer_item of this TypeHolderDefault. # noqa: E501 """ - return self._integer_item + return self._data_store.get('integer_item') @integer_item.setter - def integer_item(self, integer_item): + def integer_item( + self, integer_item): """Sets the integer_item of this TypeHolderDefault. - :param integer_item: The integer_item of this TypeHolderDefault. # noqa: E501 - :type: int + Returns: + (int): The integer_item of this TypeHolderDefault. # noqa: E501 """ if integer_item is None: - raise ValueError("Invalid value for `integer_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `integer_item`, must not be `None`") # noqa: E501 - self._integer_item = integer_item + self.__setitem__( + 'integer_item', + integer_item + ) @property def bool_item(self): """Gets the bool_item of this TypeHolderDefault. # noqa: E501 - :return: The bool_item of this TypeHolderDefault. # noqa: E501 - :rtype: bool + Returns: + (bool): The bool_item of this TypeHolderDefault. # noqa: E501 """ - return self._bool_item + return self._data_store.get('bool_item') @bool_item.setter - def bool_item(self, bool_item): + def bool_item( + self, bool_item): """Sets the bool_item of this TypeHolderDefault. - :param bool_item: The bool_item of this TypeHolderDefault. # noqa: E501 - :type: bool + Returns: + (bool): The bool_item of this TypeHolderDefault. # noqa: E501 """ if bool_item is None: - raise ValueError("Invalid value for `bool_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `bool_item`, must not be `None`") # noqa: E501 - self._bool_item = bool_item + self.__setitem__( + 'bool_item', + bool_item + ) @property def array_item(self): """Gets the array_item of this TypeHolderDefault. # noqa: E501 - :return: The array_item of this TypeHolderDefault. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The array_item of this TypeHolderDefault. # noqa: E501 """ - return self._array_item + return self._data_store.get('array_item') @array_item.setter - def array_item(self, array_item): + def array_item( + self, array_item): """Sets the array_item of this TypeHolderDefault. - :param array_item: The array_item of this TypeHolderDefault. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The array_item of this TypeHolderDefault. # noqa: E501 """ if array_item is None: - raise ValueError("Invalid value for `array_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `array_item`, must not be `None`") # noqa: E501 - self._array_item = array_item + self.__setitem__( + 'array_item', + array_item + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/type_holder_example.py b/samples/client/petstore/python/petstore_api/models/type_holder_example.py index c926f4e48489..02ea8681cb6f 100644 --- a/samples/client/petstore/python/petstore_api/models/type_holder_example.py +++ b/samples/client/petstore/python/petstore_api/models/type_holder_example.py @@ -15,8 +15,27 @@ import six - -class TypeHolderExample(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class TypeHolderExample(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,179 +46,263 @@ class TypeHolderExample(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'string_item': 'str', - 'number_item': 'float', - 'integer_item': 'int', - 'bool_item': 'bool', - 'array_item': 'list[int]' + 'string_item': [str], # noqa: E501 + 'number_item': [float], # noqa: E501 + 'integer_item': [int], # noqa: E501 + 'bool_item': [bool], # noqa: E501 + 'array_item': [[(int,)]] # noqa: E501 } - attribute_map = { - 'string_item': 'string_item', - 'number_item': 'number_item', - 'integer_item': 'integer_item', - 'bool_item': 'bool_item', - 'array_item': 'array_item' + 'string_item': 'string_item', # noqa: E501 + 'number_item': 'number_item', # noqa: E501 + 'integer_item': 'integer_item', # noqa: E501 + 'bool_item': 'bool_item', # noqa: E501 + 'array_item': 'array_item' # noqa: E501 } - def __init__(self, string_item=None, number_item=None, integer_item=None, bool_item=None, array_item=None): # noqa: E501 - """TypeHolderExample - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, string_item, number_item, integer_item, bool_item, array_item, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """TypeHolderExample - a model defined in OpenAPI + + Args: + string_item (str): + number_item (float): + integer_item (int): + bool_item (bool): + array_item ([(int,)]): + + 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 False + _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 + _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. + """ - self._string_item = None - self._number_item = None - self._integer_item = None - self._bool_item = None - self._array_item = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + # assign using .var_name to check against nullable and enums self.string_item = string_item self.number_item = number_item self.integer_item = integer_item self.bool_item = bool_item self.array_item = array_item + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def string_item(self): """Gets the string_item of this TypeHolderExample. # noqa: E501 - :return: The string_item of this TypeHolderExample. # noqa: E501 - :rtype: str + Returns: + (str): The string_item of this TypeHolderExample. # noqa: E501 """ - return self._string_item + return self._data_store.get('string_item') @string_item.setter - def string_item(self, string_item): + def string_item( + self, string_item): """Sets the string_item of this TypeHolderExample. - :param string_item: The string_item of this TypeHolderExample. # noqa: E501 - :type: str + Returns: + (str): The string_item of this TypeHolderExample. # noqa: E501 """ if string_item is None: - raise ValueError("Invalid value for `string_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `string_item`, must not be `None`") # noqa: E501 - self._string_item = string_item + self.__setitem__( + 'string_item', + string_item + ) @property def number_item(self): """Gets the number_item of this TypeHolderExample. # noqa: E501 - :return: The number_item of this TypeHolderExample. # noqa: E501 - :rtype: float + Returns: + (float): The number_item of this TypeHolderExample. # noqa: E501 """ - return self._number_item + return self._data_store.get('number_item') @number_item.setter - def number_item(self, number_item): + def number_item( + self, number_item): """Sets the number_item of this TypeHolderExample. - :param number_item: The number_item of this TypeHolderExample. # noqa: E501 - :type: float + Returns: + (float): The number_item of this TypeHolderExample. # noqa: E501 """ if number_item is None: - raise ValueError("Invalid value for `number_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `number_item`, must not be `None`") # noqa: E501 - self._number_item = number_item + self.__setitem__( + 'number_item', + number_item + ) @property def integer_item(self): """Gets the integer_item of this TypeHolderExample. # noqa: E501 - :return: The integer_item of this TypeHolderExample. # noqa: E501 - :rtype: int + Returns: + (int): The integer_item of this TypeHolderExample. # noqa: E501 """ - return self._integer_item + return self._data_store.get('integer_item') @integer_item.setter - def integer_item(self, integer_item): + def integer_item( + self, integer_item): """Sets the integer_item of this TypeHolderExample. - :param integer_item: The integer_item of this TypeHolderExample. # noqa: E501 - :type: int + Returns: + (int): The integer_item of this TypeHolderExample. # noqa: E501 """ if integer_item is None: - raise ValueError("Invalid value for `integer_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `integer_item`, must not be `None`") # noqa: E501 - self._integer_item = integer_item + self.__setitem__( + 'integer_item', + integer_item + ) @property def bool_item(self): """Gets the bool_item of this TypeHolderExample. # noqa: E501 - :return: The bool_item of this TypeHolderExample. # noqa: E501 - :rtype: bool + Returns: + (bool): The bool_item of this TypeHolderExample. # noqa: E501 """ - return self._bool_item + return self._data_store.get('bool_item') @bool_item.setter - def bool_item(self, bool_item): + def bool_item( + self, bool_item): """Sets the bool_item of this TypeHolderExample. - :param bool_item: The bool_item of this TypeHolderExample. # noqa: E501 - :type: bool + Returns: + (bool): The bool_item of this TypeHolderExample. # noqa: E501 """ if bool_item is None: - raise ValueError("Invalid value for `bool_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `bool_item`, must not be `None`") # noqa: E501 - self._bool_item = bool_item + self.__setitem__( + 'bool_item', + bool_item + ) @property def array_item(self): """Gets the array_item of this TypeHolderExample. # noqa: E501 - :return: The array_item of this TypeHolderExample. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The array_item of this TypeHolderExample. # noqa: E501 """ - return self._array_item + return self._data_store.get('array_item') @array_item.setter - def array_item(self, array_item): + def array_item( + self, array_item): """Sets the array_item of this TypeHolderExample. - :param array_item: The array_item of this TypeHolderExample. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The array_item of this TypeHolderExample. # noqa: E501 """ if array_item is None: - raise ValueError("Invalid value for `array_item`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `array_item`, must not be `None`") # noqa: E501 - self._array_item = array_item + self.__setitem__( + 'array_item', + array_item + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/user.py b/samples/client/petstore/python/petstore_api/models/user.py index 9736c47c1f87..33b99bfdb45c 100644 --- a/samples/client/petstore/python/petstore_api/models/user.py +++ b/samples/client/petstore/python/petstore_api/models/user.py @@ -15,8 +15,27 @@ import six - -class User(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class User(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,207 +46,302 @@ class User(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'id': 'int', - 'username': 'str', - 'first_name': 'str', - 'last_name': 'str', - 'email': 'str', - 'password': 'str', - 'phone': 'str', - 'user_status': 'int' + 'id': [int], # noqa: E501 + 'username': [str], # noqa: E501 + 'first_name': [str], # noqa: E501 + 'last_name': [str], # noqa: E501 + 'email': [str], # noqa: E501 + 'password': [str], # noqa: E501 + 'phone': [str], # noqa: E501 + 'user_status': [int] # noqa: E501 } - attribute_map = { - 'id': 'id', - 'username': 'username', - 'first_name': 'firstName', - 'last_name': 'lastName', - 'email': 'email', - 'password': 'password', - 'phone': 'phone', - 'user_status': 'userStatus' + 'id': 'id', # noqa: E501 + 'username': 'username', # noqa: E501 + 'first_name': 'firstName', # noqa: E501 + 'last_name': 'lastName', # noqa: E501 + 'email': 'email', # noqa: E501 + 'password': 'password', # noqa: E501 + 'phone': 'phone', # noqa: E501 + 'user_status': 'userStatus' # noqa: E501 } - def __init__(self, id=None, username=None, first_name=None, last_name=None, email=None, password=None, phone=None, user_status=None): # noqa: E501 - """User - a model defined in OpenAPI""" # noqa: E501 - - self._id = None - self._username = None - self._first_name = None - self._last_name = None - self._email = None - self._password = None - self._phone = None - self._user_status = None - self.discriminator = None + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """User - 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 False + _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 + _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. + id (int): [optional] # noqa: E501 + username (str): [optional] # noqa: E501 + first_name (str): [optional] # noqa: E501 + last_name (str): [optional] # noqa: E501 + email (str): [optional] # noqa: E501 + password (str): [optional] # noqa: E501 + phone (str): [optional] # noqa: E501 + user_status (int): User Status. [optional] # noqa: E501 + """ - if id is not None: - self.id = id - if username is not None: - self.username = username - if first_name is not None: - self.first_name = first_name - if last_name is not None: - self.last_name = last_name - if email is not None: - self.email = email - if password is not None: - self.password = password - if phone is not None: - self.phone = phone - if user_status is not None: - self.user_status = user_status + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def id(self): """Gets the id of this User. # noqa: E501 - :return: The id of this User. # noqa: E501 - :rtype: int + Returns: + (int): The id of this User. # noqa: E501 """ - return self._id + return self._data_store.get('id') @id.setter - def id(self, id): + def id( + self, id): """Sets the id of this User. - :param id: The id of this User. # noqa: E501 - :type: int + Returns: + (int): The id of this User. # noqa: E501 """ - self._id = id + self.__setitem__( + 'id', + id + ) @property def username(self): """Gets the username of this User. # noqa: E501 - :return: The username of this User. # noqa: E501 - :rtype: str + Returns: + (str): The username of this User. # noqa: E501 """ - return self._username + return self._data_store.get('username') @username.setter - def username(self, username): + def username( + self, username): """Sets the username of this User. - :param username: The username of this User. # noqa: E501 - :type: str + Returns: + (str): The username of this User. # noqa: E501 """ - self._username = username + self.__setitem__( + 'username', + username + ) @property def first_name(self): """Gets the first_name of this User. # noqa: E501 - :return: The first_name of this User. # noqa: E501 - :rtype: str + Returns: + (str): The first_name of this User. # noqa: E501 """ - return self._first_name + return self._data_store.get('first_name') @first_name.setter - def first_name(self, first_name): + def first_name( + self, first_name): """Sets the first_name of this User. - :param first_name: The first_name of this User. # noqa: E501 - :type: str + Returns: + (str): The first_name of this User. # noqa: E501 """ - self._first_name = first_name + self.__setitem__( + 'first_name', + first_name + ) @property def last_name(self): """Gets the last_name of this User. # noqa: E501 - :return: The last_name of this User. # noqa: E501 - :rtype: str + Returns: + (str): The last_name of this User. # noqa: E501 """ - return self._last_name + return self._data_store.get('last_name') @last_name.setter - def last_name(self, last_name): + def last_name( + self, last_name): """Sets the last_name of this User. - :param last_name: The last_name of this User. # noqa: E501 - :type: str + Returns: + (str): The last_name of this User. # noqa: E501 """ - self._last_name = last_name + self.__setitem__( + 'last_name', + last_name + ) @property def email(self): """Gets the email of this User. # noqa: E501 - :return: The email of this User. # noqa: E501 - :rtype: str + Returns: + (str): The email of this User. # noqa: E501 """ - return self._email + return self._data_store.get('email') @email.setter - def email(self, email): + def email( + self, email): """Sets the email of this User. - :param email: The email of this User. # noqa: E501 - :type: str + Returns: + (str): The email of this User. # noqa: E501 """ - self._email = email + self.__setitem__( + 'email', + email + ) @property def password(self): """Gets the password of this User. # noqa: E501 - :return: The password of this User. # noqa: E501 - :rtype: str + Returns: + (str): The password of this User. # noqa: E501 """ - return self._password + return self._data_store.get('password') @password.setter - def password(self, password): + def password( + self, password): """Sets the password of this User. - :param password: The password of this User. # noqa: E501 - :type: str + Returns: + (str): The password of this User. # noqa: E501 """ - self._password = password + self.__setitem__( + 'password', + password + ) @property def phone(self): """Gets the phone of this User. # noqa: E501 - :return: The phone of this User. # noqa: E501 - :rtype: str + Returns: + (str): The phone of this User. # noqa: E501 """ - return self._phone + return self._data_store.get('phone') @phone.setter - def phone(self, phone): + def phone( + self, phone): """Sets the phone of this User. - :param phone: The phone of this User. # noqa: E501 - :type: str + Returns: + (str): The phone of this User. # noqa: E501 """ - self._phone = phone + self.__setitem__( + 'phone', + phone + ) @property def user_status(self): @@ -235,46 +349,30 @@ def user_status(self): User Status # noqa: E501 - :return: The user_status of this User. # noqa: E501 - :rtype: int + Returns: + (int): The user_status of this User. # noqa: E501 """ - return self._user_status + return self._data_store.get('user_status') @user_status.setter - def user_status(self, user_status): + def user_status( + self, user_status): """Sets the user_status of this User. User Status # noqa: E501 - :param user_status: The user_status of this User. # noqa: E501 - :type: int + Returns: + (int): The user_status of this User. # noqa: E501 """ - self._user_status = user_status + self.__setitem__( + 'user_status', + user_status + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/models/xml_item.py b/samples/client/petstore/python/petstore_api/models/xml_item.py index 00872d531a88..86672dae2746 100644 --- a/samples/client/petstore/python/petstore_api/models/xml_item.py +++ b/samples/client/petstore/python/petstore_api/models/xml_item.py @@ -15,8 +15,27 @@ import six - -class XmlItem(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class XmlItem(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,798 +46,919 @@ class XmlItem(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'attribute_string': 'str', - 'attribute_number': 'float', - 'attribute_integer': 'int', - 'attribute_boolean': 'bool', - 'wrapped_array': 'list[int]', - 'name_string': 'str', - 'name_number': 'float', - 'name_integer': 'int', - 'name_boolean': 'bool', - 'name_array': 'list[int]', - 'name_wrapped_array': 'list[int]', - 'prefix_string': 'str', - 'prefix_number': 'float', - 'prefix_integer': 'int', - 'prefix_boolean': 'bool', - 'prefix_array': 'list[int]', - 'prefix_wrapped_array': 'list[int]', - 'namespace_string': 'str', - 'namespace_number': 'float', - 'namespace_integer': 'int', - 'namespace_boolean': 'bool', - 'namespace_array': 'list[int]', - 'namespace_wrapped_array': 'list[int]', - 'prefix_ns_string': 'str', - 'prefix_ns_number': 'float', - 'prefix_ns_integer': 'int', - 'prefix_ns_boolean': 'bool', - 'prefix_ns_array': 'list[int]', - 'prefix_ns_wrapped_array': 'list[int]' + 'attribute_string': [str], # noqa: E501 + 'attribute_number': [float], # noqa: E501 + 'attribute_integer': [int], # noqa: E501 + 'attribute_boolean': [bool], # noqa: E501 + 'wrapped_array': [[(int,)]], # noqa: E501 + 'name_string': [str], # noqa: E501 + 'name_number': [float], # noqa: E501 + 'name_integer': [int], # noqa: E501 + 'name_boolean': [bool], # noqa: E501 + 'name_array': [[(int,)]], # noqa: E501 + 'name_wrapped_array': [[(int,)]], # noqa: E501 + 'prefix_string': [str], # noqa: E501 + 'prefix_number': [float], # noqa: E501 + 'prefix_integer': [int], # noqa: E501 + 'prefix_boolean': [bool], # noqa: E501 + 'prefix_array': [[(int,)]], # noqa: E501 + 'prefix_wrapped_array': [[(int,)]], # noqa: E501 + 'namespace_string': [str], # noqa: E501 + 'namespace_number': [float], # noqa: E501 + 'namespace_integer': [int], # noqa: E501 + 'namespace_boolean': [bool], # noqa: E501 + 'namespace_array': [[(int,)]], # noqa: E501 + 'namespace_wrapped_array': [[(int,)]], # noqa: E501 + 'prefix_ns_string': [str], # noqa: E501 + 'prefix_ns_number': [float], # noqa: E501 + 'prefix_ns_integer': [int], # noqa: E501 + 'prefix_ns_boolean': [bool], # noqa: E501 + 'prefix_ns_array': [[(int,)]], # noqa: E501 + 'prefix_ns_wrapped_array': [[(int,)]] # noqa: E501 } - attribute_map = { - 'attribute_string': 'attribute_string', - 'attribute_number': 'attribute_number', - 'attribute_integer': 'attribute_integer', - 'attribute_boolean': 'attribute_boolean', - 'wrapped_array': 'wrapped_array', - 'name_string': 'name_string', - 'name_number': 'name_number', - 'name_integer': 'name_integer', - 'name_boolean': 'name_boolean', - 'name_array': 'name_array', - 'name_wrapped_array': 'name_wrapped_array', - 'prefix_string': 'prefix_string', - 'prefix_number': 'prefix_number', - 'prefix_integer': 'prefix_integer', - 'prefix_boolean': 'prefix_boolean', - 'prefix_array': 'prefix_array', - 'prefix_wrapped_array': 'prefix_wrapped_array', - 'namespace_string': 'namespace_string', - 'namespace_number': 'namespace_number', - 'namespace_integer': 'namespace_integer', - 'namespace_boolean': 'namespace_boolean', - 'namespace_array': 'namespace_array', - 'namespace_wrapped_array': 'namespace_wrapped_array', - 'prefix_ns_string': 'prefix_ns_string', - 'prefix_ns_number': 'prefix_ns_number', - 'prefix_ns_integer': 'prefix_ns_integer', - 'prefix_ns_boolean': 'prefix_ns_boolean', - 'prefix_ns_array': 'prefix_ns_array', - 'prefix_ns_wrapped_array': 'prefix_ns_wrapped_array' + 'attribute_string': 'attribute_string', # noqa: E501 + 'attribute_number': 'attribute_number', # noqa: E501 + 'attribute_integer': 'attribute_integer', # noqa: E501 + 'attribute_boolean': 'attribute_boolean', # noqa: E501 + 'wrapped_array': 'wrapped_array', # noqa: E501 + 'name_string': 'name_string', # noqa: E501 + 'name_number': 'name_number', # noqa: E501 + 'name_integer': 'name_integer', # noqa: E501 + 'name_boolean': 'name_boolean', # noqa: E501 + 'name_array': 'name_array', # noqa: E501 + 'name_wrapped_array': 'name_wrapped_array', # noqa: E501 + 'prefix_string': 'prefix_string', # noqa: E501 + 'prefix_number': 'prefix_number', # noqa: E501 + 'prefix_integer': 'prefix_integer', # noqa: E501 + 'prefix_boolean': 'prefix_boolean', # noqa: E501 + 'prefix_array': 'prefix_array', # noqa: E501 + 'prefix_wrapped_array': 'prefix_wrapped_array', # noqa: E501 + 'namespace_string': 'namespace_string', # noqa: E501 + 'namespace_number': 'namespace_number', # noqa: E501 + 'namespace_integer': 'namespace_integer', # noqa: E501 + 'namespace_boolean': 'namespace_boolean', # noqa: E501 + 'namespace_array': 'namespace_array', # noqa: E501 + 'namespace_wrapped_array': 'namespace_wrapped_array', # noqa: E501 + 'prefix_ns_string': 'prefix_ns_string', # noqa: E501 + 'prefix_ns_number': 'prefix_ns_number', # noqa: E501 + 'prefix_ns_integer': 'prefix_ns_integer', # noqa: E501 + 'prefix_ns_boolean': 'prefix_ns_boolean', # noqa: E501 + 'prefix_ns_array': 'prefix_ns_array', # noqa: E501 + 'prefix_ns_wrapped_array': 'prefix_ns_wrapped_array' # noqa: E501 } - def __init__(self, attribute_string=None, attribute_number=None, attribute_integer=None, attribute_boolean=None, wrapped_array=None, name_string=None, name_number=None, name_integer=None, name_boolean=None, name_array=None, name_wrapped_array=None, prefix_string=None, prefix_number=None, prefix_integer=None, prefix_boolean=None, prefix_array=None, prefix_wrapped_array=None, namespace_string=None, namespace_number=None, namespace_integer=None, namespace_boolean=None, namespace_array=None, namespace_wrapped_array=None, prefix_ns_string=None, prefix_ns_number=None, prefix_ns_integer=None, prefix_ns_boolean=None, prefix_ns_array=None, prefix_ns_wrapped_array=None): # noqa: E501 - """XmlItem - a model defined in OpenAPI""" # noqa: E501 - - self._attribute_string = None - self._attribute_number = None - self._attribute_integer = None - self._attribute_boolean = None - self._wrapped_array = None - self._name_string = None - self._name_number = None - self._name_integer = None - self._name_boolean = None - self._name_array = None - self._name_wrapped_array = None - self._prefix_string = None - self._prefix_number = None - self._prefix_integer = None - self._prefix_boolean = None - self._prefix_array = None - self._prefix_wrapped_array = None - self._namespace_string = None - self._namespace_number = None - self._namespace_integer = None - self._namespace_boolean = None - self._namespace_array = None - self._namespace_wrapped_array = None - self._prefix_ns_string = None - self._prefix_ns_number = None - self._prefix_ns_integer = None - self._prefix_ns_boolean = None - self._prefix_ns_array = None - self._prefix_ns_wrapped_array = None + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """XmlItem - 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 False + _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 + _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. + attribute_string (str): [optional] # noqa: E501 + attribute_number (float): [optional] # noqa: E501 + attribute_integer (int): [optional] # noqa: E501 + attribute_boolean (bool): [optional] # noqa: E501 + wrapped_array ([(int,)]): [optional] # noqa: E501 + name_string (str): [optional] # noqa: E501 + name_number (float): [optional] # noqa: E501 + name_integer (int): [optional] # noqa: E501 + name_boolean (bool): [optional] # noqa: E501 + name_array ([(int,)]): [optional] # noqa: E501 + name_wrapped_array ([(int,)]): [optional] # noqa: E501 + prefix_string (str): [optional] # noqa: E501 + prefix_number (float): [optional] # noqa: E501 + prefix_integer (int): [optional] # noqa: E501 + prefix_boolean (bool): [optional] # noqa: E501 + prefix_array ([(int,)]): [optional] # noqa: E501 + prefix_wrapped_array ([(int,)]): [optional] # noqa: E501 + namespace_string (str): [optional] # noqa: E501 + namespace_number (float): [optional] # noqa: E501 + namespace_integer (int): [optional] # noqa: E501 + namespace_boolean (bool): [optional] # noqa: E501 + namespace_array ([(int,)]): [optional] # noqa: E501 + namespace_wrapped_array ([(int,)]): [optional] # noqa: E501 + prefix_ns_string (str): [optional] # noqa: E501 + prefix_ns_number (float): [optional] # noqa: E501 + prefix_ns_integer (int): [optional] # noqa: E501 + prefix_ns_boolean (bool): [optional] # noqa: E501 + prefix_ns_array ([(int,)]): [optional] # noqa: E501 + prefix_ns_wrapped_array ([(int,)]): [optional] # noqa: E501 + """ + + self._data_store = {} self.discriminator = None - - if attribute_string is not None: - self.attribute_string = attribute_string - if attribute_number is not None: - self.attribute_number = attribute_number - if attribute_integer is not None: - self.attribute_integer = attribute_integer - if attribute_boolean is not None: - self.attribute_boolean = attribute_boolean - if wrapped_array is not None: - self.wrapped_array = wrapped_array - if name_string is not None: - self.name_string = name_string - if name_number is not None: - self.name_number = name_number - if name_integer is not None: - self.name_integer = name_integer - if name_boolean is not None: - self.name_boolean = name_boolean - if name_array is not None: - self.name_array = name_array - if name_wrapped_array is not None: - self.name_wrapped_array = name_wrapped_array - if prefix_string is not None: - self.prefix_string = prefix_string - if prefix_number is not None: - self.prefix_number = prefix_number - if prefix_integer is not None: - self.prefix_integer = prefix_integer - if prefix_boolean is not None: - self.prefix_boolean = prefix_boolean - if prefix_array is not None: - self.prefix_array = prefix_array - if prefix_wrapped_array is not None: - self.prefix_wrapped_array = prefix_wrapped_array - if namespace_string is not None: - self.namespace_string = namespace_string - if namespace_number is not None: - self.namespace_number = namespace_number - if namespace_integer is not None: - self.namespace_integer = namespace_integer - if namespace_boolean is not None: - self.namespace_boolean = namespace_boolean - if namespace_array is not None: - self.namespace_array = namespace_array - if namespace_wrapped_array is not None: - self.namespace_wrapped_array = namespace_wrapped_array - if prefix_ns_string is not None: - self.prefix_ns_string = prefix_ns_string - if prefix_ns_number is not None: - self.prefix_ns_number = prefix_ns_number - if prefix_ns_integer is not None: - self.prefix_ns_integer = prefix_ns_integer - if prefix_ns_boolean is not None: - self.prefix_ns_boolean = prefix_ns_boolean - if prefix_ns_array is not None: - self.prefix_ns_array = prefix_ns_array - if prefix_ns_wrapped_array is not None: - self.prefix_ns_wrapped_array = prefix_ns_wrapped_array + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def attribute_string(self): """Gets the attribute_string of this XmlItem. # noqa: E501 - :return: The attribute_string of this XmlItem. # noqa: E501 - :rtype: str + Returns: + (str): The attribute_string of this XmlItem. # noqa: E501 """ - return self._attribute_string + return self._data_store.get('attribute_string') @attribute_string.setter - def attribute_string(self, attribute_string): + def attribute_string( + self, attribute_string): """Sets the attribute_string of this XmlItem. - :param attribute_string: The attribute_string of this XmlItem. # noqa: E501 - :type: str + Returns: + (str): The attribute_string of this XmlItem. # noqa: E501 """ - self._attribute_string = attribute_string + self.__setitem__( + 'attribute_string', + attribute_string + ) @property def attribute_number(self): """Gets the attribute_number of this XmlItem. # noqa: E501 - :return: The attribute_number of this XmlItem. # noqa: E501 - :rtype: float + Returns: + (float): The attribute_number of this XmlItem. # noqa: E501 """ - return self._attribute_number + return self._data_store.get('attribute_number') @attribute_number.setter - def attribute_number(self, attribute_number): + def attribute_number( + self, attribute_number): """Sets the attribute_number of this XmlItem. - :param attribute_number: The attribute_number of this XmlItem. # noqa: E501 - :type: float + Returns: + (float): The attribute_number of this XmlItem. # noqa: E501 """ - self._attribute_number = attribute_number + self.__setitem__( + 'attribute_number', + attribute_number + ) @property def attribute_integer(self): """Gets the attribute_integer of this XmlItem. # noqa: E501 - :return: The attribute_integer of this XmlItem. # noqa: E501 - :rtype: int + Returns: + (int): The attribute_integer of this XmlItem. # noqa: E501 """ - return self._attribute_integer + return self._data_store.get('attribute_integer') @attribute_integer.setter - def attribute_integer(self, attribute_integer): + def attribute_integer( + self, attribute_integer): """Sets the attribute_integer of this XmlItem. - :param attribute_integer: The attribute_integer of this XmlItem. # noqa: E501 - :type: int + Returns: + (int): The attribute_integer of this XmlItem. # noqa: E501 """ - self._attribute_integer = attribute_integer + self.__setitem__( + 'attribute_integer', + attribute_integer + ) @property def attribute_boolean(self): """Gets the attribute_boolean of this XmlItem. # noqa: E501 - :return: The attribute_boolean of this XmlItem. # noqa: E501 - :rtype: bool + Returns: + (bool): The attribute_boolean of this XmlItem. # noqa: E501 """ - return self._attribute_boolean + return self._data_store.get('attribute_boolean') @attribute_boolean.setter - def attribute_boolean(self, attribute_boolean): + def attribute_boolean( + self, attribute_boolean): """Sets the attribute_boolean of this XmlItem. - :param attribute_boolean: The attribute_boolean of this XmlItem. # noqa: E501 - :type: bool + Returns: + (bool): The attribute_boolean of this XmlItem. # noqa: E501 """ - self._attribute_boolean = attribute_boolean + self.__setitem__( + 'attribute_boolean', + attribute_boolean + ) @property def wrapped_array(self): """Gets the wrapped_array of this XmlItem. # noqa: E501 - :return: The wrapped_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The wrapped_array of this XmlItem. # noqa: E501 """ - return self._wrapped_array + return self._data_store.get('wrapped_array') @wrapped_array.setter - def wrapped_array(self, wrapped_array): + def wrapped_array( + self, wrapped_array): """Sets the wrapped_array of this XmlItem. - :param wrapped_array: The wrapped_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The wrapped_array of this XmlItem. # noqa: E501 """ - self._wrapped_array = wrapped_array + self.__setitem__( + 'wrapped_array', + wrapped_array + ) @property def name_string(self): """Gets the name_string of this XmlItem. # noqa: E501 - :return: The name_string of this XmlItem. # noqa: E501 - :rtype: str + Returns: + (str): The name_string of this XmlItem. # noqa: E501 """ - return self._name_string + return self._data_store.get('name_string') @name_string.setter - def name_string(self, name_string): + def name_string( + self, name_string): """Sets the name_string of this XmlItem. - :param name_string: The name_string of this XmlItem. # noqa: E501 - :type: str + Returns: + (str): The name_string of this XmlItem. # noqa: E501 """ - self._name_string = name_string + self.__setitem__( + 'name_string', + name_string + ) @property def name_number(self): """Gets the name_number of this XmlItem. # noqa: E501 - :return: The name_number of this XmlItem. # noqa: E501 - :rtype: float + Returns: + (float): The name_number of this XmlItem. # noqa: E501 """ - return self._name_number + return self._data_store.get('name_number') @name_number.setter - def name_number(self, name_number): + def name_number( + self, name_number): """Sets the name_number of this XmlItem. - :param name_number: The name_number of this XmlItem. # noqa: E501 - :type: float + Returns: + (float): The name_number of this XmlItem. # noqa: E501 """ - self._name_number = name_number + self.__setitem__( + 'name_number', + name_number + ) @property def name_integer(self): """Gets the name_integer of this XmlItem. # noqa: E501 - :return: The name_integer of this XmlItem. # noqa: E501 - :rtype: int + Returns: + (int): The name_integer of this XmlItem. # noqa: E501 """ - return self._name_integer + return self._data_store.get('name_integer') @name_integer.setter - def name_integer(self, name_integer): + def name_integer( + self, name_integer): """Sets the name_integer of this XmlItem. - :param name_integer: The name_integer of this XmlItem. # noqa: E501 - :type: int + Returns: + (int): The name_integer of this XmlItem. # noqa: E501 """ - self._name_integer = name_integer + self.__setitem__( + 'name_integer', + name_integer + ) @property def name_boolean(self): """Gets the name_boolean of this XmlItem. # noqa: E501 - :return: The name_boolean of this XmlItem. # noqa: E501 - :rtype: bool + Returns: + (bool): The name_boolean of this XmlItem. # noqa: E501 """ - return self._name_boolean + return self._data_store.get('name_boolean') @name_boolean.setter - def name_boolean(self, name_boolean): + def name_boolean( + self, name_boolean): """Sets the name_boolean of this XmlItem. - :param name_boolean: The name_boolean of this XmlItem. # noqa: E501 - :type: bool + Returns: + (bool): The name_boolean of this XmlItem. # noqa: E501 """ - self._name_boolean = name_boolean + self.__setitem__( + 'name_boolean', + name_boolean + ) @property def name_array(self): """Gets the name_array of this XmlItem. # noqa: E501 - :return: The name_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The name_array of this XmlItem. # noqa: E501 """ - return self._name_array + return self._data_store.get('name_array') @name_array.setter - def name_array(self, name_array): + def name_array( + self, name_array): """Sets the name_array of this XmlItem. - :param name_array: The name_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The name_array of this XmlItem. # noqa: E501 """ - self._name_array = name_array + self.__setitem__( + 'name_array', + name_array + ) @property def name_wrapped_array(self): """Gets the name_wrapped_array of this XmlItem. # noqa: E501 - :return: The name_wrapped_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The name_wrapped_array of this XmlItem. # noqa: E501 """ - return self._name_wrapped_array + return self._data_store.get('name_wrapped_array') @name_wrapped_array.setter - def name_wrapped_array(self, name_wrapped_array): + def name_wrapped_array( + self, name_wrapped_array): """Sets the name_wrapped_array of this XmlItem. - :param name_wrapped_array: The name_wrapped_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The name_wrapped_array of this XmlItem. # noqa: E501 """ - self._name_wrapped_array = name_wrapped_array + self.__setitem__( + 'name_wrapped_array', + name_wrapped_array + ) @property def prefix_string(self): """Gets the prefix_string of this XmlItem. # noqa: E501 - :return: The prefix_string of this XmlItem. # noqa: E501 - :rtype: str + Returns: + (str): The prefix_string of this XmlItem. # noqa: E501 """ - return self._prefix_string + return self._data_store.get('prefix_string') @prefix_string.setter - def prefix_string(self, prefix_string): + def prefix_string( + self, prefix_string): """Sets the prefix_string of this XmlItem. - :param prefix_string: The prefix_string of this XmlItem. # noqa: E501 - :type: str + Returns: + (str): The prefix_string of this XmlItem. # noqa: E501 """ - self._prefix_string = prefix_string + self.__setitem__( + 'prefix_string', + prefix_string + ) @property def prefix_number(self): """Gets the prefix_number of this XmlItem. # noqa: E501 - :return: The prefix_number of this XmlItem. # noqa: E501 - :rtype: float + Returns: + (float): The prefix_number of this XmlItem. # noqa: E501 """ - return self._prefix_number + return self._data_store.get('prefix_number') @prefix_number.setter - def prefix_number(self, prefix_number): + def prefix_number( + self, prefix_number): """Sets the prefix_number of this XmlItem. - :param prefix_number: The prefix_number of this XmlItem. # noqa: E501 - :type: float + Returns: + (float): The prefix_number of this XmlItem. # noqa: E501 """ - self._prefix_number = prefix_number + self.__setitem__( + 'prefix_number', + prefix_number + ) @property def prefix_integer(self): """Gets the prefix_integer of this XmlItem. # noqa: E501 - :return: The prefix_integer of this XmlItem. # noqa: E501 - :rtype: int + Returns: + (int): The prefix_integer of this XmlItem. # noqa: E501 """ - return self._prefix_integer + return self._data_store.get('prefix_integer') @prefix_integer.setter - def prefix_integer(self, prefix_integer): + def prefix_integer( + self, prefix_integer): """Sets the prefix_integer of this XmlItem. - :param prefix_integer: The prefix_integer of this XmlItem. # noqa: E501 - :type: int + Returns: + (int): The prefix_integer of this XmlItem. # noqa: E501 """ - self._prefix_integer = prefix_integer + self.__setitem__( + 'prefix_integer', + prefix_integer + ) @property def prefix_boolean(self): """Gets the prefix_boolean of this XmlItem. # noqa: E501 - :return: The prefix_boolean of this XmlItem. # noqa: E501 - :rtype: bool + Returns: + (bool): The prefix_boolean of this XmlItem. # noqa: E501 """ - return self._prefix_boolean + return self._data_store.get('prefix_boolean') @prefix_boolean.setter - def prefix_boolean(self, prefix_boolean): + def prefix_boolean( + self, prefix_boolean): """Sets the prefix_boolean of this XmlItem. - :param prefix_boolean: The prefix_boolean of this XmlItem. # noqa: E501 - :type: bool + Returns: + (bool): The prefix_boolean of this XmlItem. # noqa: E501 """ - self._prefix_boolean = prefix_boolean + self.__setitem__( + 'prefix_boolean', + prefix_boolean + ) @property def prefix_array(self): """Gets the prefix_array of this XmlItem. # noqa: E501 - :return: The prefix_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The prefix_array of this XmlItem. # noqa: E501 """ - return self._prefix_array + return self._data_store.get('prefix_array') @prefix_array.setter - def prefix_array(self, prefix_array): + def prefix_array( + self, prefix_array): """Sets the prefix_array of this XmlItem. - :param prefix_array: The prefix_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The prefix_array of this XmlItem. # noqa: E501 """ - self._prefix_array = prefix_array + self.__setitem__( + 'prefix_array', + prefix_array + ) @property def prefix_wrapped_array(self): """Gets the prefix_wrapped_array of this XmlItem. # noqa: E501 - :return: The prefix_wrapped_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The prefix_wrapped_array of this XmlItem. # noqa: E501 """ - return self._prefix_wrapped_array + return self._data_store.get('prefix_wrapped_array') @prefix_wrapped_array.setter - def prefix_wrapped_array(self, prefix_wrapped_array): + def prefix_wrapped_array( + self, prefix_wrapped_array): """Sets the prefix_wrapped_array of this XmlItem. - :param prefix_wrapped_array: The prefix_wrapped_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The prefix_wrapped_array of this XmlItem. # noqa: E501 """ - self._prefix_wrapped_array = prefix_wrapped_array + self.__setitem__( + 'prefix_wrapped_array', + prefix_wrapped_array + ) @property def namespace_string(self): """Gets the namespace_string of this XmlItem. # noqa: E501 - :return: The namespace_string of this XmlItem. # noqa: E501 - :rtype: str + Returns: + (str): The namespace_string of this XmlItem. # noqa: E501 """ - return self._namespace_string + return self._data_store.get('namespace_string') @namespace_string.setter - def namespace_string(self, namespace_string): + def namespace_string( + self, namespace_string): """Sets the namespace_string of this XmlItem. - :param namespace_string: The namespace_string of this XmlItem. # noqa: E501 - :type: str + Returns: + (str): The namespace_string of this XmlItem. # noqa: E501 """ - self._namespace_string = namespace_string + self.__setitem__( + 'namespace_string', + namespace_string + ) @property def namespace_number(self): """Gets the namespace_number of this XmlItem. # noqa: E501 - :return: The namespace_number of this XmlItem. # noqa: E501 - :rtype: float + Returns: + (float): The namespace_number of this XmlItem. # noqa: E501 """ - return self._namespace_number + return self._data_store.get('namespace_number') @namespace_number.setter - def namespace_number(self, namespace_number): + def namespace_number( + self, namespace_number): """Sets the namespace_number of this XmlItem. - :param namespace_number: The namespace_number of this XmlItem. # noqa: E501 - :type: float + Returns: + (float): The namespace_number of this XmlItem. # noqa: E501 """ - self._namespace_number = namespace_number + self.__setitem__( + 'namespace_number', + namespace_number + ) @property def namespace_integer(self): """Gets the namespace_integer of this XmlItem. # noqa: E501 - :return: The namespace_integer of this XmlItem. # noqa: E501 - :rtype: int + Returns: + (int): The namespace_integer of this XmlItem. # noqa: E501 """ - return self._namespace_integer + return self._data_store.get('namespace_integer') @namespace_integer.setter - def namespace_integer(self, namespace_integer): + def namespace_integer( + self, namespace_integer): """Sets the namespace_integer of this XmlItem. - :param namespace_integer: The namespace_integer of this XmlItem. # noqa: E501 - :type: int + Returns: + (int): The namespace_integer of this XmlItem. # noqa: E501 """ - self._namespace_integer = namespace_integer + self.__setitem__( + 'namespace_integer', + namespace_integer + ) @property def namespace_boolean(self): """Gets the namespace_boolean of this XmlItem. # noqa: E501 - :return: The namespace_boolean of this XmlItem. # noqa: E501 - :rtype: bool + Returns: + (bool): The namespace_boolean of this XmlItem. # noqa: E501 """ - return self._namespace_boolean + return self._data_store.get('namespace_boolean') @namespace_boolean.setter - def namespace_boolean(self, namespace_boolean): + def namespace_boolean( + self, namespace_boolean): """Sets the namespace_boolean of this XmlItem. - :param namespace_boolean: The namespace_boolean of this XmlItem. # noqa: E501 - :type: bool + Returns: + (bool): The namespace_boolean of this XmlItem. # noqa: E501 """ - self._namespace_boolean = namespace_boolean + self.__setitem__( + 'namespace_boolean', + namespace_boolean + ) @property def namespace_array(self): """Gets the namespace_array of this XmlItem. # noqa: E501 - :return: The namespace_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The namespace_array of this XmlItem. # noqa: E501 """ - return self._namespace_array + return self._data_store.get('namespace_array') @namespace_array.setter - def namespace_array(self, namespace_array): + def namespace_array( + self, namespace_array): """Sets the namespace_array of this XmlItem. - :param namespace_array: The namespace_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The namespace_array of this XmlItem. # noqa: E501 """ - self._namespace_array = namespace_array + self.__setitem__( + 'namespace_array', + namespace_array + ) @property def namespace_wrapped_array(self): """Gets the namespace_wrapped_array of this XmlItem. # noqa: E501 - :return: The namespace_wrapped_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The namespace_wrapped_array of this XmlItem. # noqa: E501 """ - return self._namespace_wrapped_array + return self._data_store.get('namespace_wrapped_array') @namespace_wrapped_array.setter - def namespace_wrapped_array(self, namespace_wrapped_array): + def namespace_wrapped_array( + self, namespace_wrapped_array): """Sets the namespace_wrapped_array of this XmlItem. - :param namespace_wrapped_array: The namespace_wrapped_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The namespace_wrapped_array of this XmlItem. # noqa: E501 """ - self._namespace_wrapped_array = namespace_wrapped_array + self.__setitem__( + 'namespace_wrapped_array', + namespace_wrapped_array + ) @property def prefix_ns_string(self): """Gets the prefix_ns_string of this XmlItem. # noqa: E501 - :return: The prefix_ns_string of this XmlItem. # noqa: E501 - :rtype: str + Returns: + (str): The prefix_ns_string of this XmlItem. # noqa: E501 """ - return self._prefix_ns_string + return self._data_store.get('prefix_ns_string') @prefix_ns_string.setter - def prefix_ns_string(self, prefix_ns_string): + def prefix_ns_string( + self, prefix_ns_string): """Sets the prefix_ns_string of this XmlItem. - :param prefix_ns_string: The prefix_ns_string of this XmlItem. # noqa: E501 - :type: str + Returns: + (str): The prefix_ns_string of this XmlItem. # noqa: E501 """ - self._prefix_ns_string = prefix_ns_string + self.__setitem__( + 'prefix_ns_string', + prefix_ns_string + ) @property def prefix_ns_number(self): """Gets the prefix_ns_number of this XmlItem. # noqa: E501 - :return: The prefix_ns_number of this XmlItem. # noqa: E501 - :rtype: float + Returns: + (float): The prefix_ns_number of this XmlItem. # noqa: E501 """ - return self._prefix_ns_number + return self._data_store.get('prefix_ns_number') @prefix_ns_number.setter - def prefix_ns_number(self, prefix_ns_number): + def prefix_ns_number( + self, prefix_ns_number): """Sets the prefix_ns_number of this XmlItem. - :param prefix_ns_number: The prefix_ns_number of this XmlItem. # noqa: E501 - :type: float + Returns: + (float): The prefix_ns_number of this XmlItem. # noqa: E501 """ - self._prefix_ns_number = prefix_ns_number + self.__setitem__( + 'prefix_ns_number', + prefix_ns_number + ) @property def prefix_ns_integer(self): """Gets the prefix_ns_integer of this XmlItem. # noqa: E501 - :return: The prefix_ns_integer of this XmlItem. # noqa: E501 - :rtype: int + Returns: + (int): The prefix_ns_integer of this XmlItem. # noqa: E501 """ - return self._prefix_ns_integer + return self._data_store.get('prefix_ns_integer') @prefix_ns_integer.setter - def prefix_ns_integer(self, prefix_ns_integer): + def prefix_ns_integer( + self, prefix_ns_integer): """Sets the prefix_ns_integer of this XmlItem. - :param prefix_ns_integer: The prefix_ns_integer of this XmlItem. # noqa: E501 - :type: int + Returns: + (int): The prefix_ns_integer of this XmlItem. # noqa: E501 """ - self._prefix_ns_integer = prefix_ns_integer + self.__setitem__( + 'prefix_ns_integer', + prefix_ns_integer + ) @property def prefix_ns_boolean(self): """Gets the prefix_ns_boolean of this XmlItem. # noqa: E501 - :return: The prefix_ns_boolean of this XmlItem. # noqa: E501 - :rtype: bool + Returns: + (bool): The prefix_ns_boolean of this XmlItem. # noqa: E501 """ - return self._prefix_ns_boolean + return self._data_store.get('prefix_ns_boolean') @prefix_ns_boolean.setter - def prefix_ns_boolean(self, prefix_ns_boolean): + def prefix_ns_boolean( + self, prefix_ns_boolean): """Sets the prefix_ns_boolean of this XmlItem. - :param prefix_ns_boolean: The prefix_ns_boolean of this XmlItem. # noqa: E501 - :type: bool + Returns: + (bool): The prefix_ns_boolean of this XmlItem. # noqa: E501 """ - self._prefix_ns_boolean = prefix_ns_boolean + self.__setitem__( + 'prefix_ns_boolean', + prefix_ns_boolean + ) @property def prefix_ns_array(self): """Gets the prefix_ns_array of this XmlItem. # noqa: E501 - :return: The prefix_ns_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The prefix_ns_array of this XmlItem. # noqa: E501 """ - return self._prefix_ns_array + return self._data_store.get('prefix_ns_array') @prefix_ns_array.setter - def prefix_ns_array(self, prefix_ns_array): + def prefix_ns_array( + self, prefix_ns_array): """Sets the prefix_ns_array of this XmlItem. - :param prefix_ns_array: The prefix_ns_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The prefix_ns_array of this XmlItem. # noqa: E501 """ - self._prefix_ns_array = prefix_ns_array + self.__setitem__( + 'prefix_ns_array', + prefix_ns_array + ) @property def prefix_ns_wrapped_array(self): """Gets the prefix_ns_wrapped_array of this XmlItem. # noqa: E501 - :return: The prefix_ns_wrapped_array of this XmlItem. # noqa: E501 - :rtype: list[int] + Returns: + ([(int,)]): The prefix_ns_wrapped_array of this XmlItem. # noqa: E501 """ - return self._prefix_ns_wrapped_array + return self._data_store.get('prefix_ns_wrapped_array') @prefix_ns_wrapped_array.setter - def prefix_ns_wrapped_array(self, prefix_ns_wrapped_array): + def prefix_ns_wrapped_array( + self, prefix_ns_wrapped_array): """Sets the prefix_ns_wrapped_array of this XmlItem. - :param prefix_ns_wrapped_array: The prefix_ns_wrapped_array of this XmlItem. # noqa: E501 - :type: list[int] + Returns: + ([(int,)]): The prefix_ns_wrapped_array of this XmlItem. # noqa: E501 """ - self._prefix_ns_wrapped_array = prefix_ns_wrapped_array + self.__setitem__( + 'prefix_ns_wrapped_array', + prefix_ns_wrapped_array + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/client/petstore/python/petstore_api/rest.py b/samples/client/petstore/python/petstore_api/rest.py index 30ba5fb8d3f5..7f44af7113fd 100644 --- a/samples/client/petstore/python/petstore_api/rest.py +++ b/samples/client/petstore/python/petstore_api/rest.py @@ -22,12 +22,9 @@ # python 2 and python 3 compatibility library import six from six.moves.urllib.parse import urlencode +import urllib3 -try: - import urllib3 -except ImportError: - raise ImportError('OpenAPI Python client requires urllib3.') - +from petstore_api.exceptions import ApiException, ApiValueError logger = logging.getLogger(__name__) @@ -130,7 +127,7 @@ def request(self, method, url, query_params=None, headers=None, 'PATCH', 'OPTIONS'] if post_params and body: - raise ValueError( + raise ApiValueError( "body parameter cannot be used with post_params parameter." ) @@ -292,31 +289,3 @@ def PATCH(self, url, headers=None, query_params=None, post_params=None, _preload_content=_preload_content, _request_timeout=_request_timeout, body=body) - - -class ApiException(Exception): - - 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 diff --git a/samples/client/petstore/python/requirements.txt b/samples/client/petstore/python/requirements.txt index bafdc07532f5..2e252c8a0833 100644 --- a/samples/client/petstore/python/requirements.txt +++ b/samples/client/petstore/python/requirements.txt @@ -1,5 +1,6 @@ certifi >= 14.05.14 -six >= 1.10 +future; python_version<="2.7" python_dateutil >= 2.5.3 setuptools >= 21.0.0 +six >= 1.10 urllib3 >= 1.15.1 diff --git a/samples/client/petstore/python/setup.py b/samples/client/petstore/python/setup.py index 3cfa069e2047..7655bd0faa12 100644 --- a/samples/client/petstore/python/setup.py +++ b/samples/client/petstore/python/setup.py @@ -31,6 +31,11 @@ url="", keywords=["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"], install_requires=REQUIRES, + extras_require={ + ':python_version <= "2.7"': [ + 'future', + ], + }, packages=find_packages(), include_package_data=True, long_description="""\ diff --git a/samples/client/petstore/python/test/test_additional_properties_any_type.py b/samples/client/petstore/python/test/test_additional_properties_any_type.py new file mode 100644 index 000000000000..5f8b8ef01d69 --- /dev/null +++ b/samples/client/petstore/python/test/test_additional_properties_any_type.py @@ -0,0 +1,62 @@ +# 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.additional_properties_any_type import AdditionalPropertiesAnyType # noqa: E501 +from petstore_api.rest import ApiException +from test.utils import EXAMPLES, VAR_NAME_INVALID_TYPES, get_examples + +ADDL_PROPS_VALUE_TYPES = [ + val for val in EXAMPLES.keys() if val != 'None' +] +ADDL_PROPS_INVALID_VALUE_TYPES = ['None'] + + +class TestAdditionalPropertiesAnyType(unittest.TestCase): + """AdditionalPropertiesObject unit test stubs""" + + def test_addl_props_invalid_var_value_fails(self): + for var_name in EXAMPLES['str']: + var_values = get_examples(ADDL_PROPS_INVALID_VALUE_TYPES) + for var_value in var_values: + keyword_args = {var_name: var_value} + with self.assertRaises(TypeError): + AdditionalPropertiesAnyType(**keyword_args) + + with self.assertRaises(TypeError): + a = AdditionalPropertiesAnyType() + a[var_name] = var_value + + def test_addl_props_invalid_var_name_fails(self): + var_names = get_examples(VAR_NAME_INVALID_TYPES) + for var_name in var_names: + for var_value in EXAMPLES['str']: + with self.assertRaises(TypeError): + a = AdditionalPropertiesAnyType() + a[var_name] = var_value + + def test_addl_props_valid_value_type_succeeds(self): + for var_name in EXAMPLES['str']: + for var_value in get_examples(ADDL_PROPS_VALUE_TYPES): + keyword_args = {var_name: var_value} + a = AdditionalPropertiesAnyType(**keyword_args) + b = AdditionalPropertiesAnyType() + b[var_name] = var_value + assert True + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python/test/test_additional_properties_array.py b/samples/client/petstore/python/test/test_additional_properties_array.py new file mode 100644 index 000000000000..ae9d9cc96100 --- /dev/null +++ b/samples/client/petstore/python/test/test_additional_properties_array.py @@ -0,0 +1,62 @@ +# 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.additional_properties_array import AdditionalPropertiesArray # noqa: E501 +from petstore_api.rest import ApiException +from test.utils import EXAMPLES, VAR_NAME_INVALID_TYPES, get_examples + +ADDL_PROPS_VALUE_TYPE = 'list' +ADDL_PROPS_INVALID_VALUE_TYPES = [ + val for val in EXAMPLES.keys() if val != ADDL_PROPS_VALUE_TYPE +] + + +class TestAdditionalPropertiesArray(unittest.TestCase): + """AdditionalPropertiesArray unit test stubs""" + + def test_addl_props_invalid_var_value_fails(self): + for var_name in EXAMPLES['str']: + var_values = get_examples(ADDL_PROPS_INVALID_VALUE_TYPES) + for var_value in var_values: + keyword_args = {var_name: var_value} + with self.assertRaises(TypeError): + AdditionalPropertiesArray(**keyword_args) + + with self.assertRaises(TypeError): + a = AdditionalPropertiesArray() + a[var_name] = var_value + + def test_addl_props_invalid_var_name_fails(self): + var_names = get_examples(VAR_NAME_INVALID_TYPES) + for var_name in var_names: + for var_value in EXAMPLES[ADDL_PROPS_VALUE_TYPE]: + with self.assertRaises(TypeError): + a = AdditionalPropertiesArray() + a[var_name] = var_value + + def test_addl_props_valid_value_type_succeeds(self): + for var_name in EXAMPLES['str']: + for var_value in EXAMPLES[ADDL_PROPS_VALUE_TYPE]: + keyword_args = {var_name: var_value} + a = AdditionalPropertiesArray(**keyword_args) + b = AdditionalPropertiesArray() + b[var_name] = var_value + assert True + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python/test/test_additional_properties_boolean.py b/samples/client/petstore/python/test/test_additional_properties_boolean.py new file mode 100644 index 000000000000..7718bedacb08 --- /dev/null +++ b/samples/client/petstore/python/test/test_additional_properties_boolean.py @@ -0,0 +1,62 @@ +# 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.additional_properties_boolean import AdditionalPropertiesBoolean # noqa: E501 +from petstore_api.rest import ApiException +from test.utils import EXAMPLES, VAR_NAME_INVALID_TYPES, get_examples + +ADDL_PROPS_VALUE_TYPE = 'bool' +ADDL_PROPS_INVALID_VALUE_TYPES = [ + val for val in EXAMPLES.keys() if val != ADDL_PROPS_VALUE_TYPE +] + + +class TestAdditionalPropertiesBoolean(unittest.TestCase): + """AdditionalPropertiesBoolean unit test stubs""" + + def test_addl_props_invalid_var_value_fails(self): + for var_name in EXAMPLES['str']: + var_values = get_examples(ADDL_PROPS_INVALID_VALUE_TYPES) + for var_value in var_values: + keyword_args = {var_name: var_value} + with self.assertRaises(TypeError): + AdditionalPropertiesBoolean(**keyword_args) + + with self.assertRaises(TypeError): + a = AdditionalPropertiesBoolean() + a[var_name] = var_value + + def test_addl_props_invalid_var_name_fails(self): + var_names = get_examples(VAR_NAME_INVALID_TYPES) + for var_name in var_names: + for var_value in EXAMPLES[ADDL_PROPS_VALUE_TYPE]: + with self.assertRaises(TypeError): + a = AdditionalPropertiesBoolean() + a[var_name] = var_value + + def test_addl_props_valid_value_type_succeeds(self): + for var_name in EXAMPLES['str']: + for var_value in EXAMPLES[ADDL_PROPS_VALUE_TYPE]: + keyword_args = {var_name: var_value} + a = AdditionalPropertiesBoolean(**keyword_args) + b = AdditionalPropertiesBoolean() + b[var_name] = var_value + assert True + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python/test/test_additional_properties_class.py b/samples/client/petstore/python/test/test_additional_properties_class.py index fc9df3bbb505..37fb826f5d97 100644 --- a/samples/client/petstore/python/test/test_additional_properties_class.py +++ b/samples/client/petstore/python/test/test_additional_properties_class.py @@ -17,22 +17,286 @@ import petstore_api from petstore_api.models.additional_properties_class import AdditionalPropertiesClass # noqa: E501 from petstore_api.rest import ApiException - +from test.utils import EXAMPLES, get_examples class TestAdditionalPropertiesClass(unittest.TestCase): """AdditionalPropertiesClass unit test stubs""" - def setUp(self): - pass + def test_map_string_invalid_var_value_fails(self): + invalid_value_types = [ + val for val in EXAMPLES.keys() if val != 'str' + ] + var_values = get_examples(invalid_value_types) + for var_name in EXAMPLES['str']: + for var_value in var_values: + with self.assertRaises(TypeError): + AdditionalPropertiesClass( + map_string={var_name: var_value}, + _check_type=True + ) + + with self.assertRaises(TypeError): + a = AdditionalPropertiesClass(_check_type=True) + a['map_string'] = {var_name: var_value} + + def test_map_string_valid_value_type_succeeds(self): + for var_name in EXAMPLES['str']: + for var_value in EXAMPLES['str']: + a = AdditionalPropertiesClass( + map_string={var_name: var_value}, + _check_type=True + ) + b = AdditionalPropertiesClass(_check_type=True) + b['map_string'] = {var_name: var_value} + assert True + + def test_map_number_invalid_var_value_fails(self): + invalid_value_types = [ + val for val in EXAMPLES.keys() if val != 'float' + ] + for var_name in EXAMPLES['str']: + var_values = get_examples(invalid_value_types) + for var_value in var_values: + with self.assertRaises(TypeError): + AdditionalPropertiesClass( + map_number={var_name: var_value}, + _check_type=True + ) + + with self.assertRaises(TypeError): + a = AdditionalPropertiesClass(_check_type=True) + a['map_number'] = {var_name: var_value} + + def test_map_number_valid_value_type_succeeds(self): + for var_name in EXAMPLES['str']: + for var_value in EXAMPLES['float']: + a = AdditionalPropertiesClass( + map_number={var_name: var_value}, + _check_type=True + ) + b = AdditionalPropertiesClass(_check_type=True) + b['map_number'] = {var_name: var_value} + assert True + + def test_map_integer_invalid_var_value_fails(self): + invalid_value_types = [ + val for val in EXAMPLES.keys() if val != 'int' + ] + for var_name in EXAMPLES['str']: + var_values = get_examples(invalid_value_types) + for var_value in var_values: + with self.assertRaises(TypeError): + AdditionalPropertiesClass( + map_integer={var_name: var_value}, + _check_type=True + ) + + with self.assertRaises(TypeError): + a = AdditionalPropertiesClass(_check_type=True) + a['map_integer'] = {var_name: var_value} + + def test_map_integer_valid_value_type_succeeds(self): + for var_name in EXAMPLES['str']: + for var_value in EXAMPLES['int']: + a = AdditionalPropertiesClass( + map_integer={var_name: var_value}, + _check_type=True + ) + b = AdditionalPropertiesClass(_check_type=True) + b['map_integer'] = {var_name: var_value} + assert True + + def test_map_boolean_invalid_var_value_fails(self): + invalid_value_types = [ + val for val in EXAMPLES.keys() if val != 'bool' + ] + for var_name in EXAMPLES['str']: + var_values = get_examples(invalid_value_types) + for var_value in var_values: + with self.assertRaises(TypeError): + AdditionalPropertiesClass( + map_boolean={var_name: var_value}, + _check_type=True + ) + + with self.assertRaises(TypeError): + a = AdditionalPropertiesClass(_check_type=True) + a['map_boolean'] = {var_name: var_value} + + def test_map_boolean_valid_value_type_succeeds(self): + for var_name in EXAMPLES['str']: + for var_value in EXAMPLES['bool']: + a = AdditionalPropertiesClass( + map_boolean={var_name: var_value}, + _check_type=True + ) + b = AdditionalPropertiesClass(_check_type=True) + b['map_boolean'] = {var_name: var_value} + assert True + + def test_map_array_integer_invalid_var_value_fails(self): + invalid_value_types = [ + val for val in EXAMPLES.keys() if val != 'int' + ] + examples = get_examples(invalid_value_types) + var_values = [[example] for example in examples] + # add arrays with mixed types, some valid + invalid + for example in examples: + var_values.append([1, 2, example]) + for var_name in EXAMPLES['str']: + for var_value in var_values: + with self.assertRaises(TypeError): + AdditionalPropertiesClass( + map_array_integer={var_name: var_value}, + _check_type=True + ) + + with self.assertRaises(TypeError): + a = AdditionalPropertiesClass(_check_type=True) + a['map_array_integer'] = {var_name: var_value} + + def test_map_array_integer_valid_value_type_succeeds(self): + for var_name in EXAMPLES['str']: + for var_value in EXAMPLES['int']: + a = AdditionalPropertiesClass( + map_array_integer={var_name: [var_value]}, + _check_type=True + ) + b = AdditionalPropertiesClass(_check_type=True) + b['map_array_integer'] = {var_name: [var_value]} + assert True + + def test_map_array_anytype_invalid_var_value_fails(self): + invalid_value_types = [ + val for val in EXAMPLES.keys() if val != 'list' + ] + for var_name in EXAMPLES['str']: + var_values = get_examples(invalid_value_types) + for var_value in var_values: + with self.assertRaises(TypeError): + AdditionalPropertiesClass( + map_array_anytype={var_name: var_value}, + _check_type=True + ) + + with self.assertRaises(TypeError): + a = AdditionalPropertiesClass(_check_type=True) + a['map_array_anytype'] = {var_name: var_value} + + def test_map_array_anytype_valid_value_type_succeeds(self): + for var_name in EXAMPLES['str']: + for var_value in EXAMPLES['list']: + a = AdditionalPropertiesClass( + map_array_anytype={var_name: var_value}, + _check_type=True + ) + b = AdditionalPropertiesClass(_check_type=True) + b['map_array_anytype'] = {var_name: var_value} + assert True + + def test_map_map_string_invalid_var_value_fails(self): + invalid_value_types = [ + val for val in EXAMPLES.keys() if val != 'str' + ] + var_values = get_examples(invalid_value_types) + for var_name in EXAMPLES['str']: + for var_key in EXAMPLES['str']: + for var_value in var_values: + with self.assertRaises(TypeError): + AdditionalPropertiesClass( + map_map_string={var_name: {var_key: var_value}}, + _check_type=True + ) + + with self.assertRaises(TypeError): + a = AdditionalPropertiesClass(_check_type=True) + a['map_map_string'] = {var_name: {var_key: var_value}} + # add dict with mixed types, some valid + invalid + for var_value in var_values: + with self.assertRaises(TypeError): + AdditionalPropertiesClass( + map_map_string={ + 'a': { + 'b': 'e', + 'c': 'f', + 'd': var_value + } + }, + _check_type=True + ) + + def test_map_map_string_valid_value_type_succeeds(self): + for var_name in EXAMPLES['str']: + for var_key in EXAMPLES['str']: + for var_value in EXAMPLES['str']: + a = AdditionalPropertiesClass( + map_map_string={var_name: {var_key: var_value}}, + _check_type=True + ) + b = AdditionalPropertiesClass(_check_type=True) + b['map_map_string'] = {var_name: {var_key: var_value}} + assert True + + def test_map_map_anytype_invalid_var_value_fails(self): + invalid_value_types = ['None'] + for var_name in EXAMPLES['str']: + for var_key in EXAMPLES['str']: + var_values = get_examples(invalid_value_types) + for var_value in var_values: + with self.assertRaises(TypeError): + AdditionalPropertiesClass( + map_map_anytype={var_name: {var_key: var_value}}, + _check_type=True + ) + + with self.assertRaises(TypeError): + a = AdditionalPropertiesClass(_check_type=True) + a['map_map_anytype'] = {var_name: {var_key: var_value}} + + def test_map_map_anytype_valid_value_type_succeeds(self): + for var_name in EXAMPLES['str']: + for var_key in EXAMPLES['str']: + for var_value in EXAMPLES['dict']: + a = AdditionalPropertiesClass( + map_map_anytype={var_name: {var_key: var_value}}, + _check_type=True + ) + b = AdditionalPropertiesClass(_check_type=True) + b['map_map_anytype'] = {var_name: {var_key: var_value}} + assert True + + def test_anytypes_invalid_var_value_fails(self): + invalid_value_types = ['None'] + anytype_vars = ['anytype_1', 'anytype_2', 'anytype_2'] + for anytype_var in anytype_vars: + var_values = get_examples(invalid_value_types) + for var_value in var_values: + with self.assertRaises(TypeError): + keyword_args = { + anytype_var: var_value, + '_check_type': True + } + AdditionalPropertiesClass(**keyword_args) - def tearDown(self): - pass + with self.assertRaises(TypeError): + a = AdditionalPropertiesClass(_check_type=True) + a[anytype_var] = var_value - def testAdditionalPropertiesClass(self): - """Test AdditionalPropertiesClass""" - # FIXME: construct object with mandatory attributes with example values - # model = petstore_api.models.additional_properties_class.AdditionalPropertiesClass() # noqa: E501 - pass + def test_anytypes_valid_value_type_succeeds(self): + anytype_vars = ['anytype_1', 'anytype_2', 'anytype_2'] + valid_value_types = [ + val for val in EXAMPLES.keys() if val != 'None' + ] + for anytype_var in anytype_vars: + for var_value in get_examples(valid_value_types): + keyword_args = { + anytype_var: var_value, + '_check_type': True + } + a = AdditionalPropertiesClass(**keyword_args) + b = AdditionalPropertiesClass(_check_type=True) + b[anytype_var] = var_value + assert True if __name__ == '__main__': diff --git a/samples/client/petstore/python/test/test_additional_properties_integer.py b/samples/client/petstore/python/test/test_additional_properties_integer.py new file mode 100644 index 000000000000..a1382379d794 --- /dev/null +++ b/samples/client/petstore/python/test/test_additional_properties_integer.py @@ -0,0 +1,62 @@ +# 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.additional_properties_integer import AdditionalPropertiesInteger # noqa: E501 +from petstore_api.rest import ApiException +from test.utils import EXAMPLES, VAR_NAME_INVALID_TYPES, get_examples + +ADDL_PROPS_VALUE_TYPE = 'int' +ADDL_PROPS_INVALID_VALUE_TYPES = [ + val for val in EXAMPLES.keys() if val != ADDL_PROPS_VALUE_TYPE +] + + +class TestAdditionalPropertiesInteger(unittest.TestCase): + """AdditionalPropertiesInteger unit test stubs""" + + def test_addl_props_invalid_var_value_fails(self): + for var_name in EXAMPLES['str']: + var_values = get_examples(ADDL_PROPS_INVALID_VALUE_TYPES) + for var_value in var_values: + keyword_args = {var_name: var_value} + with self.assertRaises(TypeError): + AdditionalPropertiesInteger(**keyword_args) + + with self.assertRaises(TypeError): + a = AdditionalPropertiesInteger() + a[var_name] = var_value + + def test_addl_props_invalid_var_name_fails(self): + var_names = get_examples(VAR_NAME_INVALID_TYPES) + for var_name in var_names: + for var_value in EXAMPLES[ADDL_PROPS_VALUE_TYPE]: + with self.assertRaises(TypeError): + a = AdditionalPropertiesInteger() + a[var_name] = var_value + + def test_addl_props_valid_value_type_succeeds(self): + for var_name in EXAMPLES['str']: + for var_value in EXAMPLES[ADDL_PROPS_VALUE_TYPE]: + keyword_args = {var_name: var_value} + a = AdditionalPropertiesInteger(**keyword_args) + b = AdditionalPropertiesInteger() + b[var_name] = var_value + assert True + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python/test/test_additional_properties_number.py b/samples/client/petstore/python/test/test_additional_properties_number.py new file mode 100644 index 000000000000..5d74a9539820 --- /dev/null +++ b/samples/client/petstore/python/test/test_additional_properties_number.py @@ -0,0 +1,62 @@ +# 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.additional_properties_number import AdditionalPropertiesNumber # noqa: E501 +from petstore_api.rest import ApiException +from test.utils import EXAMPLES, VAR_NAME_INVALID_TYPES, get_examples + +ADDL_PROPS_VALUE_TYPE = 'float' +ADDL_PROPS_INVALID_VALUE_TYPES = [ + val for val in EXAMPLES.keys() if val != ADDL_PROPS_VALUE_TYPE +] + + +class TestAdditionalPropertiesNumber(unittest.TestCase): + """AdditionalPropertiesNumber unit test stubs""" + + def test_addl_props_invalid_var_value_fails(self): + for var_name in EXAMPLES['str']: + var_values = get_examples(ADDL_PROPS_INVALID_VALUE_TYPES) + for var_value in var_values: + keyword_args = {var_name: var_value} + with self.assertRaises(TypeError): + AdditionalPropertiesNumber(**keyword_args) + + with self.assertRaises(TypeError): + a = AdditionalPropertiesNumber() + a[var_name] = var_value + + def test_addl_props_invalid_var_name_fails(self): + var_names = get_examples(VAR_NAME_INVALID_TYPES) + for var_name in var_names: + for var_value in EXAMPLES[ADDL_PROPS_VALUE_TYPE]: + with self.assertRaises(TypeError): + a = AdditionalPropertiesNumber() + a[var_name] = var_value + + def test_addl_props_valid_value_type_succeeds(self): + for var_name in EXAMPLES['str']: + for var_value in EXAMPLES[ADDL_PROPS_VALUE_TYPE]: + keyword_args = {var_name: var_value} + a = AdditionalPropertiesNumber(**keyword_args) + b = AdditionalPropertiesNumber() + b[var_name] = var_value + assert True + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python/test/test_additional_properties_object.py b/samples/client/petstore/python/test/test_additional_properties_object.py new file mode 100644 index 000000000000..4dacd0cf7ae4 --- /dev/null +++ b/samples/client/petstore/python/test/test_additional_properties_object.py @@ -0,0 +1,62 @@ +# 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.additional_properties_object import AdditionalPropertiesObject # noqa: E501 +from petstore_api.rest import ApiException +from test.utils import EXAMPLES, VAR_NAME_INVALID_TYPES, get_examples + +ADDL_PROPS_VALUE_TYPE = 'dict' +ADDL_PROPS_INVALID_VALUE_TYPES = [ + val for val in EXAMPLES.keys() if val != ADDL_PROPS_VALUE_TYPE +] + + +class TestAdditionalPropertiesObject(unittest.TestCase): + """AdditionalPropertiesObject unit test stubs""" + + def test_addl_props_invalid_var_value_fails(self): + for var_name in EXAMPLES['str']: + var_values = get_examples(ADDL_PROPS_INVALID_VALUE_TYPES) + for var_value in var_values: + keyword_args = {var_name: var_value} + with self.assertRaises(TypeError): + AdditionalPropertiesObject(**keyword_args) + + with self.assertRaises(TypeError): + a = AdditionalPropertiesObject() + a[var_name] = var_value + + def test_addl_props_invalid_var_name_fails(self): + var_names = get_examples(VAR_NAME_INVALID_TYPES) + for var_name in var_names: + for var_value in EXAMPLES[ADDL_PROPS_VALUE_TYPE]: + with self.assertRaises(TypeError): + a = AdditionalPropertiesObject() + a[var_name] = var_value + + def test_addl_props_valid_value_type_succeeds(self): + for var_name in EXAMPLES['str']: + for var_value in EXAMPLES[ADDL_PROPS_VALUE_TYPE]: + keyword_args = {var_name: var_value} + a = AdditionalPropertiesObject(**keyword_args) + b = AdditionalPropertiesObject() + b[var_name] = var_value + assert True + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python/test/test_additional_properties_string.py b/samples/client/petstore/python/test/test_additional_properties_string.py new file mode 100644 index 000000000000..ef87a389c47f --- /dev/null +++ b/samples/client/petstore/python/test/test_additional_properties_string.py @@ -0,0 +1,83 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + 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.additional_properties_string import AdditionalPropertiesString # noqa: E501 +from petstore_api.rest import ApiException +from test.utils import EXAMPLES, VAR_NAME_INVALID_TYPES, get_examples + +ADDL_PROPS_VALUE_TYPE = 'str' +ADDL_PROPS_INVALID_VALUE_TYPES = [ + val for val in EXAMPLES.keys() if val != ADDL_PROPS_VALUE_TYPE +] + + +class TestAdditionalPropertiesString(unittest.TestCase): + """AdditionalPropertiesString unit test stubs""" + + def test_empty_instance(self): + a = AdditionalPropertiesString() + self.assertEqual(a.to_dict(), {}) + + def test_set_get_additional_property(self): + a = AdditionalPropertiesString(var_1='value_1') + self.assertEqual(a.to_dict(), {'var_1': 'value_1'}) + self.assertEqual(a['var_1'], 'value_1') + + def test_set_change_get_additional_property(self): + a = AdditionalPropertiesString(var_1='value_1') + a['var_1'] = 'new value' + self.assertEqual(a['var_1'], 'new value') + + def test_access_both_props_with_brackets(self): + var_1_val = 'value_1' + name_val = 'Jen' + a = AdditionalPropertiesString(var_1=var_1_val, name=name_val) + self.assertEqual(a['var_1'], var_1_val) + self.assertEqual(a['name'], name_val) + + def test_addl_props_invalid_var_value_fails(self): + for var_name in EXAMPLES['str']: + var_values = get_examples(ADDL_PROPS_INVALID_VALUE_TYPES) + for var_value in var_values: + keyword_args = {var_name: var_value} + with self.assertRaises(TypeError): + AdditionalPropertiesString(**keyword_args) + + with self.assertRaises(TypeError): + a = AdditionalPropertiesString() + a[var_name] = var_value + + def test_addl_props_invalid_var_name_fails(self): + var_names = get_examples(VAR_NAME_INVALID_TYPES) + for var_name in var_names: + for var_value in EXAMPLES[ADDL_PROPS_VALUE_TYPE]: + with self.assertRaises(TypeError): + a = AdditionalPropertiesString() + a[var_name] = var_value + + def test_addl_props_valid_value_type_succeeds(self): + for var_name in EXAMPLES['str']: + for var_value in EXAMPLES[ADDL_PROPS_VALUE_TYPE]: + keyword_args = {var_name: var_value} + a = AdditionalPropertiesString(**keyword_args) + b = AdditionalPropertiesString() + b[var_name] = var_value + assert True + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/client/petstore/python/test/test_pet.py b/samples/client/petstore/python/test/test_pet.py index bc5cc30fac0d..f5b66f7b1c50 100644 --- a/samples/client/petstore/python/test/test_pet.py +++ b/samples/client/petstore/python/test/test_pet.py @@ -15,8 +15,8 @@ import unittest import petstore_api -from petstore_api.models.pet import Pet # noqa: E501 -from petstore_api.rest import ApiException +from petstore_api.models import Pet, Category, Tag, Dog +from petstore_api.exceptions import ApiTypeError class TestPet(unittest.TestCase): @@ -28,12 +28,40 @@ def setUp(self): def tearDown(self): pass - def testPet(self): - """Test Pet""" - # FIXME: construct object with mandatory attributes with example values - # model = petstore_api.models.pet.Pet() # noqa: E501 - pass + def testPet_valid_inputs(self): + """Test Pet with valid arguments""" + keyword_args = dict( + id=3, + category=Category(id=0, name='poodle'), + name='Samantha', + photo_urls=['http://www.example.com/image.jpg'], + tags=[Tag(id=3, name='black')], + status='available', + _check_type=True + ) + pet = Pet(**keyword_args) + assert True + + def testPet_invalid_inputs(self): + """Test Pet where we pass an invalid class in""" + keyword_args = dict( + id=3, + category=Dog(class_name='large dogs', color='black', + breed='poodle'), + name='Samantha', + photo_urls=['http://www.example.com/image.jpg'], + tags=[Tag(id=3, name='black')], + status='available', + _check_type=True + ) + with self.assertRaises(ApiTypeError) as exc: + pet = Pet(**keyword_args) + self.assertEqual( + str(exc.exception), + ("Invalid type for variable 'category'. Required value type is " + "Category and passed type was Dog at ['category']") + ) if __name__ == '__main__': unittest.main() diff --git a/samples/client/petstore/python/test/test_type_holder_default.py b/samples/client/petstore/python/test/test_type_holder_default.py index e23ab2a32fc7..0a024827a59a 100644 --- a/samples/client/petstore/python/test/test_type_holder_default.py +++ b/samples/client/petstore/python/test/test_type_holder_default.py @@ -36,7 +36,7 @@ def testTypeHolderDefault(self): sample_values = [5.67, 4, [-5, 2, -6]] assigned_variables = {} for index, required_var in enumerate(required_vars): - with self.assertRaises(ValueError): + with self.assertRaises(TypeError): model = TypeHolderDefault(**assigned_variables) assigned_variables[required_var] = sample_values[index] # assigned_variables is fully set, all required variables passed in diff --git a/samples/client/petstore/python/test/utils.py b/samples/client/petstore/python/test/utils.py new file mode 100644 index 000000000000..ce5613e16497 --- /dev/null +++ b/samples/client/petstore/python/test/utils.py @@ -0,0 +1,115 @@ +# coding: utf-8 + +from datetime import date, datetime, timedelta, tzinfo + + +class TimeZone(tzinfo): + def __init__(self, hours_offset): + self.time_delta = timedelta(hours=hours_offset) + def utcoffset(self, dt): + return self.time_delta + +exmple_simple = { + 'int': [ + 2, + -5, + 0, + 2147483647, # int32 max + -2147483648, # int32 min + 9223372036854775807, # int64 max + -9223372036854775808 # int64 min + ], + 'str': ['مرحبا كيف حالك', 'fancy\nstring', 'hey there'], + 'float': [3.14159, -12.4, 0.0], + 'bool': [True, False], + 'None': [None], + 'date': [date(1000, 7, 31), date(1970, 1, 1), date(2396, 2, 29)], + 'datetime': [ + datetime(1000, 7, 31, 13, 32, 57, tzinfo=None), + datetime(1970, 1, 1, 2, 12, 41, tzinfo=TimeZone(0)), + datetime(2396, 2, 29, 23, 57, 6, tzinfo=TimeZone(-6)) + ] +} + +example_list_monotypes = [ + [], + [exmple_simple['int'][0]], + exmple_simple['int'], + [exmple_simple['str'][0]], + exmple_simple['str'], + [exmple_simple['float'][0]], + exmple_simple['float'], + [exmple_simple['bool'][0]], + exmple_simple['bool'], + [exmple_simple['date'][0]], + exmple_simple['date'], + [exmple_simple['datetime'][0]], + exmple_simple['datetime'] +] + +example_dict_monotypes = [ + {}, + {exmple_simple['str'][0]: exmple_simple['str'][0]}, + {exmple_simple['str'][0]: exmple_simple['int'][0]}, + {exmple_simple['str'][0]: exmple_simple['float'][0]}, + {exmple_simple['str'][0]: exmple_simple['bool'][0]}, + {exmple_simple['str'][0]: exmple_simple['date'][0]}, + {exmple_simple['str'][0]: exmple_simple['datetime'][0]}, + {exmple_simple['str'][1]: exmple_simple['str'][1]}, + {exmple_simple['str'][1]: exmple_simple['int'][1]}, + {exmple_simple['str'][1]: exmple_simple['float'][1]}, + {exmple_simple['str'][1]: exmple_simple['bool'][1]}, + {exmple_simple['str'][1]: exmple_simple['date'][1]}, + {exmple_simple['str'][1]: exmple_simple['datetime'][1]}, + {exmple_simple['str'][2]: exmple_simple['str'][2]}, + {exmple_simple['str'][2]: exmple_simple['int'][2]}, + {exmple_simple['str'][2]: exmple_simple['float'][2]}, + {exmple_simple['str'][2]: exmple_simple['bool'][0]}, + {exmple_simple['str'][2]: exmple_simple['date'][2]}, + {exmple_simple['str'][2]: exmple_simple['datetime'][2]} +] +# add lists to dict +example_dict_monotypes_all = list(example_dict_monotypes) +for example_list_monotype in example_list_monotypes: + example_dict_monotypes_all.append( + {exmple_simple['str'][0]: example_list_monotype} + ) +# add self to dict, nested +current_items = list(example_dict_monotypes_all) +for current_item in current_items: + example_dict_monotypes_all.append( + {exmple_simple['str'][0]: current_item} + ) + +# add dicts to list +example_list_monotypes_all = list(example_list_monotypes) +for example_dict_monotype in example_dict_monotypes: + example_list_monotypes_all.append( + [example_dict_monotype] + ) +# add self to list, nested +current_items = list(example_list_monotypes_all) +for current_item in current_items: + example_list_monotypes_all.append( + [current_item] + ) +EXAMPLES = { + 'int': exmple_simple['int'], + 'str': exmple_simple['str'], + 'float': exmple_simple['float'], + 'bool': exmple_simple['bool'], + 'None': exmple_simple['None'], + 'date': exmple_simple['date'], + 'datetime': exmple_simple['datetime'], + 'list': example_list_monotypes_all, + 'dict': example_dict_monotypes_all +} + +VAR_NAME_INVALID_TYPES = ['int', 'float', 'bool', 'None'] + + +def get_examples(types): + res = [] + for type in types: + res.extend(EXAMPLES[type]) + return res diff --git a/samples/client/petstore/python/test_python2.sh b/samples/client/petstore/python/test_python2.sh index fb0eaed6ffa0..7b6caaa311cc 100755 --- a/samples/client/petstore/python/test_python2.sh +++ b/samples/client/petstore/python/test_python2.sh @@ -9,9 +9,10 @@ DEACTIVE=false export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8 +PY_LOC=$(which python) ### set virtualenv if [ -z "$VIRTUAL_ENV" ]; then - virtualenv $VENV --no-site-packages --always-copy + virtualenv $VENV --python=$PY_LOC --no-site-packages --always-copy source $VENV/bin/activate DEACTIVE=true fi @@ -30,4 +31,3 @@ flake8 --show-source petstore_api/ #if [ $DEACTIVE == true ]; then # deactivate #fi - diff --git a/samples/client/petstore/python/tests/test_deserialization.py b/samples/client/petstore/python/tests/test_deserialization.py index 6c4e083d1cd7..395f5fe4ab12 100644 --- a/samples/client/petstore/python/tests/test_deserialization.py +++ b/samples/client/petstore/python/tests/test_deserialization.py @@ -11,15 +11,66 @@ from collections import namedtuple import json import os +import six import time import unittest -import datetime -import petstore_api +from dateutil.tz import tzoffset +import petstore_api +from petstore_api import ( + AdditionalPropertiesAnyType, + AdditionalPropertiesClass, + Category, + Dog, + EnumTest, + OuterEnum, + Pet, + Tag +) +from petstore_api.exceptions import ( + ApiTypeError, + ApiKeyError, + ApiValueError, +) +from petstore_api.model_utils import ( + date, + datetime, + file_type, + int, + model_to_dict, + none_type, + str +) +from petstore_api.rest import RESTResponse MockResponse = namedtuple('MockResponse', 'data') +ANYTYPE_PAIRS = [ + ("7", "7"), + ("what", "what"), + (5, 5), + (2147483647, 2147483647), # int32 max + (-2147483648, -2147483648), # int32 min + (9223372036854775807, 9223372036854775807), # int 64 max + (-9223372036854775808, -9223372036854775808), # int 64 min + (-3.1415, -3.1415), + (True, True), + (False, False), + ({}, {}), + ({'hi': 'there'}, {'hi': 'there'}), + ({'hi': None}, {'hi': None}), + ([], []), + ([None], [None]), + ([0, 1], [0, 1]), + (['a', 2.7], ['a', 2.7]), + ("1997-07-16", date(1997, 7, 16)), + ( + "1997-07-16T19:20:30.45+01:00", + datetime(1997, 7, 16, 19, 20, 30, 450000, + tzinfo=tzoffset(None, 3600)) + ), +] class DeserializationTests(unittest.TestCase): @@ -29,6 +80,10 @@ def setUp(self): def test_enum_test(self): """ deserialize dict(str, Enum_Test) """ + + # TODO: fix this test + # this test will not work until this issue is fixed: + # https://github.com/OpenAPITools/openapi-generator/issues/1991 data = { 'enum_test': { "enum_string": "UPPER", @@ -39,16 +94,23 @@ def test_enum_test(self): } } response = MockResponse(data=json.dumps(data)) + # ignore the first bracket and read tuples as 'of' + # [{str: (EnumTest,)}] -> {str: (EnumTest,)} dict of EnumTest instances + response_types_mixed = [{str: (EnumTest,)}] - deserialized = self.deserialize(response, 'dict(str, EnumTest)') + deserialized = self.deserialize(response, response_types_mixed) self.assertTrue(isinstance(deserialized, dict)) - self.assertTrue(isinstance(deserialized['enum_test'], petstore_api.EnumTest)) - self.assertEqual(deserialized['enum_test'], - petstore_api.EnumTest(enum_string="UPPER", - enum_string_required="lower", - enum_integer=1, - enum_number=1.1, - outer_enum=petstore_api.OuterEnum.PLACED)) + self.assertTrue(isinstance(deserialized['enum_test'], EnumTest)) + self.assertEqual( + deserialized['enum_test'], + EnumTest( + enum_string="UPPER", + enum_string_required="lower", + enum_integer=1, + enum_number=1.1, + outer_enum=OuterEnum.PLACED + ) + ) def test_deserialize_dict_str_pet(self): """ deserialize dict(str, Pet) """ @@ -73,26 +135,27 @@ def test_deserialize_dict_str_pet(self): } } response = MockResponse(data=json.dumps(data)) + response_types_mixed = [{str: (Pet,)}] - deserialized = self.deserialize(response, 'dict(str, Pet)') + deserialized = self.deserialize(response, response_types_mixed) self.assertTrue(isinstance(deserialized, dict)) - self.assertTrue(isinstance(deserialized['pet'], petstore_api.Pet)) + self.assertTrue(isinstance(deserialized['pet'], Pet)) def test_deserialize_dict_str_dog(self): """ deserialize dict(str, Dog), use discriminator""" data = { 'dog': { - "id": 0, "className": "Dog", "color": "white", - "bread": "Jack Russel Terrier" + "breed": "Jack Russel Terrier" } } response = MockResponse(data=json.dumps(data)) + response_types_mixed = [{str: (Dog,)}] - deserialized = self.deserialize(response, 'dict(str, Animal)') + deserialized = self.deserialize(response, response_types_mixed) self.assertTrue(isinstance(deserialized, dict)) - self.assertTrue(isinstance(deserialized['dog'], petstore_api.Dog)) + self.assertTrue(isinstance(deserialized['dog'], Dog)) def test_deserialize_dict_str_int(self): """ deserialize dict(str, int) """ @@ -100,34 +163,75 @@ def test_deserialize_dict_str_int(self): 'integer': 1 } response = MockResponse(data=json.dumps(data)) + response_types_mixed = [{str: (int,)}] - deserialized = self.deserialize(response, 'dict(str, int)') + deserialized = self.deserialize(response, response_types_mixed) self.assertTrue(isinstance(deserialized, dict)) self.assertTrue(isinstance(deserialized['integer'], int)) + self.assertEqual(deserialized, data) def test_deserialize_str(self): """ deserialize str """ data = "test str" response = MockResponse(data=json.dumps(data)) + response_types_mixed = [str] - deserialized = self.deserialize(response, "str") + deserialized = self.deserialize(response, response_types_mixed) self.assertTrue(isinstance(deserialized, str)) + self.assertEqual(deserialized, data) + + def test_deserialize_str_to_int(self): + """ deserialize str """ + + input_output_pairs = ( + ("2", 2), + ("2147483647", 2147483647), # int32 max + ("-2147483648", -2147483648), # int32 min + ("9223372036854775807", 9223372036854775807), # int 64 max + ("-9223372036854775808", -9223372036854775808), # int 64 min + ) + response_types_mixed = [int] + + for input, output in input_output_pairs: + response = MockResponse(data=json.dumps(input)) + deserialized = self.deserialize(response, response_types_mixed) + self.assertTrue(isinstance(deserialized, int)) + self.assertEqual(deserialized, output) + def test_deserialize_date(self): """ deserialize date """ data = "1997-07-16" response = MockResponse(data=json.dumps(data)) + response_types_mixed = [date] - deserialized = self.deserialize(response, "date") - self.assertTrue(isinstance(deserialized, datetime.date)) + deserialized = self.deserialize(response, response_types_mixed) + self.assertTrue(isinstance(deserialized, date)) + correct_date = date(1997, 7, 16) + self.assertEqual(deserialized, correct_date) def test_deserialize_datetime(self): """ deserialize datetime """ data = "1997-07-16T19:20:30.45+01:00" + response_types_mixed = [datetime] response = MockResponse(data=json.dumps(data)) - deserialized = self.deserialize(response, "datetime") - self.assertTrue(isinstance(deserialized, datetime.datetime)) + deserialized = self.deserialize(response, response_types_mixed) + self.assertTrue(isinstance(deserialized, datetime)) + correct_datetime = datetime(1997, 7, 16, 19, 20, 30, 450000, + tzinfo=tzoffset(None, 3600)) + self.assertEqual(deserialized, correct_datetime) + + def test_deserialize_datetime_to_date(self): + """ deserialize datetime to date """ + data = "1997-07-16T19:20:30.45+01:00" + response_types_mixed = [date] + response = MockResponse(data=json.dumps(data)) + + deserialized = self.deserialize(response, response_types_mixed) + self.assertTrue(isinstance(deserialized, date)) + correct_date = date(1997, 7, 16) + self.assertEqual(deserialized, correct_date) def test_deserialize_pet(self): """ deserialize pet """ @@ -150,15 +254,22 @@ def test_deserialize_pet(self): "status": "available" } response = MockResponse(data=json.dumps(data)) + response_types_mixed = [Pet] - deserialized = self.deserialize(response, "Pet") - self.assertTrue(isinstance(deserialized, petstore_api.Pet)) + deserialized = self.deserialize(response, response_types_mixed) + self.assertTrue(isinstance(deserialized, Pet)) self.assertEqual(deserialized.id, 0) self.assertEqual(deserialized.name, "doggie") - self.assertTrue(isinstance(deserialized.category, petstore_api.Category)) + self.assertTrue(isinstance(deserialized.category, Category)) self.assertEqual(deserialized.category.name, "string") + self.assertEqual(deserialized.category.id, 0) self.assertTrue(isinstance(deserialized.tags, list)) + self.assertTrue(isinstance(deserialized.tags[0], Tag)) self.assertEqual(deserialized.tags[0].name, "string") + self.assertEqual(deserialized.tags[0].id, 0) + self.assertEqual(deserialized.status, "available") + self.assertEqual(deserialized.status, "available") + self.assertEqual(data, model_to_dict(deserialized, serialize=True)) def test_deserialize_list_of_pet(self): """ deserialize list[Pet] """ @@ -200,15 +311,171 @@ def test_deserialize_list_of_pet(self): "status": "available" }] response = MockResponse(data=json.dumps(data)) + response_types_mixed = [[(Pet,)]] - deserialized = self.deserialize(response, "list[Pet]") + deserialized = self.deserialize(response, response_types_mixed) self.assertTrue(isinstance(deserialized, list)) - self.assertTrue(isinstance(deserialized[0], petstore_api.Pet)) + self.assertTrue(isinstance(deserialized[0], Pet)) self.assertEqual(deserialized[0].id, 0) self.assertEqual(deserialized[1].id, 1) self.assertEqual(deserialized[0].name, "doggie0") self.assertEqual(deserialized[1].name, "doggie1") + def test_deserialize_failure_keyerror(self): + """ deserialize list[Pet] """ + data = [ + { + "id": 0, + "category": { + "id": 0, + "name": "string" + }, + "name": "doggie0", + "photoUrls": [ + "string" + ], + "tags": [ + { + "id": 0, + "name": "string" + } + ], + "status": "available" + }, + { + "id": 1, + "category": { + "id": 0, + "name": "string" + }, + "namee": "doggie1", + "photoUrls": [ + "string" + ], + "tags": [ + { + "id": 0, + "name": "string" + } + ], + "status": "available" + }] + response = MockResponse(data=json.dumps(data)) + response_types_mixed = [[(Pet,)]] + + error_msg = () + with self.assertRaises(ApiKeyError) as exc: + deserialized = self.deserialize(response, response_types_mixed) + self.assertEqual(str(exc.exception), + "\"Pet has no key 'namee' at ['received_data'][1]['namee']\"") + + def test_deserialize_failure_typeerror(self): + """ deserialize list[Pet] """ + data = [ + { + "id": 0, + "category": { + "id": 0, + "name": "string" + }, + "name": "doggie0", + "photoUrls": [ + "string" + ], + "tags": [ + { + "id": 0, + "name": "string" + } + ], + "status": "available" + }, + { + "id": None, + "category": { + "id": 0, + "name": "string" + }, + "name": "doggie1", + "photoUrls": [ + "string" + ], + "tags": [ + { + "id": 0, + "name": "string" + } + ], + "status": "available" + }] + response = MockResponse(data=json.dumps(data)) + response_types_mixed = [[(Pet,)]] + + with self.assertRaises(ApiTypeError) as exc: + deserialized = self.deserialize(response, response_types_mixed) + exception_str = str(exc.exception) + py2_error = ( + "Invalid type for variable 'id'. Required value type is " + "one of [int, long, newint] and passed type was NoneType at " + "['received_data'][1]['id']" + ) + py3_error = ( + "Invalid type for variable 'id'. Required value type is int " + "and passed type was NoneType at ['received_data'][1]['id']" + ) + if six.PY2: + self.assertEqual(exception_str, py2_error) + else: + self.assertEqual(exception_str, py3_error) + + def test_deserialize_failure_valueerror(self): + """ deserialize list[Pet] """ + data = [ + { + "id": 0, + "category": { + "id": 0, + "name": "string" + }, + "name": "doggie0", + "photoUrls": [ + "string" + ], + "tags": [ + { + "id": 0, + "name": "string" + } + ], + "status": "available" + }, + { + "id": 'a1', + "category": { + "id": 0, + "name": "string" + }, + "name": "doggie1", + "photoUrls": [ + "string" + ], + "tags": [ + { + "id": 0, + "name": "string" + } + ], + "status": "available" + }] + response = MockResponse(data=json.dumps(data)) + response_types_mixed = [[(Pet,)]] + + # Failed to parse 'a1' as int at ['received_data'][1]['id'] + error_msg = (r"Failed to parse [u]?\'a1\' as int at " + r"\[\'received_data\'\]\[1\]\[\'id\'\]") + with self.assertRaisesRegexp(ApiValueError, error_msg) as exc: + deserialized = self.deserialize(response, response_types_mixed) + def test_deserialize_nested_dict(self): """ deserialize dict(str, dict(str, int)) """ data = { @@ -217,25 +484,211 @@ def test_deserialize_nested_dict(self): } } response = MockResponse(data=json.dumps(data)) + response_types_mixed = [{str: ({str: (int,)},)}] - deserialized = self.deserialize(response, "dict(str, dict(str, int))") + deserialized = self.deserialize(response, response_types_mixed) self.assertTrue(isinstance(deserialized, dict)) self.assertTrue(isinstance(deserialized["foo"], dict)) self.assertTrue(isinstance(deserialized["foo"]["bar"], int)) + self.assertEqual(deserialized, data) def test_deserialize_nested_list(self): """ deserialize list[list[str]] """ data = [["foo"]] response = MockResponse(data=json.dumps(data)) + response_types_mixed = [[([(str,)],)]] - deserialized = self.deserialize(response, "list[list[str]]") + deserialized = self.deserialize(response, response_types_mixed) self.assertTrue(isinstance(deserialized, list)) self.assertTrue(isinstance(deserialized[0], list)) self.assertTrue(isinstance(deserialized[0][0], str)) + self.assertEqual(deserialized, data) + + def test_deserialize_list_to_class_instance(self): + """ deserialize list to model """ + photo_urls = ['http://www.example.com/image.jpg'] + # this is the only required property, which is a positional argument + data = [photo_urls] + response = MockResponse(data=json.dumps(data)) + response_types_mixed = [Pet] - def test_deserialize_none(self): + deserialized = self.deserialize(response, response_types_mixed) + self.assertTrue(isinstance(deserialized, Pet)) + self.assertEqual(deserialized.photo_urls, photo_urls) + + def test_deserialize_str_to_int_failure(self): + """ try to deserialize bad string into int """ + data = {'hi': 'a23'} + response = MockResponse(data=json.dumps(data)) + response_types_mixed = [{str: (int,)}] + + # python2 casts the 'a23' as unicode and has a prefex u in its repr + # Failed to parse 'a23' as int at ['received_data']['hi'] + error_msg = (r"Failed to parse [u]?\'a23\' as int at " + r"\[\'received_data\'\]\[\'hi\'\]") + with self.assertRaisesRegexp(ApiValueError, error_msg) as exc: + deserialized = self.deserialize(response, response_types_mixed) + + def test_deserialize_str_to_date_failure(self): + """ try to deserialize bad string into int """ + string_inputs = [str('bogus'), u'bogus', 'bogus'] + response_types_mixed = [date] + + for string_input in string_inputs: + response = MockResponse(data=json.dumps(string_input)) + + # If you need your parameter to have a fallback string value, + # please set its type as `type: {}` in your spec. That allows the + # value to be any type. Failed to parse u'bogus' as date at + # ['received_data'] + error_msg = ( + r"If you need your parameter to have a fallback string value, " + r"please set its type as \`type: \{\}\` in your spec\. That " + r"allows the value to be any type\. Failed to parse " + r"[u]?\'bogus\' as date at \[\'received_data\'\]" + ) + with self.assertRaisesRegexp(ApiValueError, error_msg) as exc: + deserialized = self.deserialize(response, response_types_mixed) + + + def test_deserialize_none_failure(self): """ deserialize None """ - response = MockResponse(data=json.dumps(None)) + data = None + response = MockResponse(data=json.dumps(data)) + response_types_mixed = [datetime] - deserialized = self.deserialize(response, "datetime") - self.assertIsNone(deserialized) + error_msg = ( + "Invalid type for variable 'received_data'. Required value type is " + "datetime and passed type was NoneType at ['received_data']" + ) + with self.assertRaises(ApiTypeError) as exc: + deserialized = self.deserialize(response, response_types_mixed) + self.assertEqual(str(exc.exception), error_msg) + + def test_deserialize_nullable_success(self): + """ deserialize datatetime/None """ + response_types_mixed = [date, none_type] + + data = None + response = MockResponse(data=json.dumps(data)) + deserialized = self.deserialize(response, response_types_mixed) + self.assertTrue(isinstance(deserialized, none_type)) + self.assertEqual(deserialized, None) + + data = "1997-07-16" + response = MockResponse(data=json.dumps(data)) + deserialized = self.deserialize(response, response_types_mixed) + self.assertTrue(isinstance(deserialized, date)) + self.assertEqual(deserialized, date(1997, 7, 16)) + + def test_deserialize_anytype_primitive(self): + response_types_mixed = [ + bool, date, datetime, dict, float, int, list, str + ] + for input, output in ANYTYPE_PAIRS: + response = MockResponse(data=json.dumps(input)) + deserialized = self.deserialize(response, response_types_mixed) + self.assertEqual(deserialized, output) + + def test_deserialize_anytype_primitive_failure(self): + response_types_mixed = [ + bool, date, datetime, dict, float, int, list, str + ] + response = MockResponse(data=json.dumps(None)) + with self.assertRaises(ApiTypeError) as exc: + deserialized = self.deserialize(response, response_types_mixed) + exception_str = str(exc.exception) + py2_error = ( + "Invalid type for variable 'received_data'. Required value type is" + " one of [bool, date, datetime, dict, float, int, list, long, " + "newint, newstr, str, unicode] and passed type was NoneType at " + "['received_data']" + ) + py3_error = ( + "Invalid type for variable 'received_data'. Required value type " + "is one of [bool, date, datetime, dict, float, int, list, str] " + "and passed type was NoneType at ['received_data']" + ) + if six.PY2: + self.assertEqual(exception_str, py2_error) + else: + self.assertEqual(exception_str, py3_error) + + + def test_deserialize_anytype_list(self): + response_types_mixed = [ + [(bool, date, datetime, dict, float, int, list, str)] + ] + for input, output in ANYTYPE_PAIRS: + response = MockResponse(data=json.dumps([input])) + deserialized = self.deserialize(response, response_types_mixed) + self.assertEqual(deserialized, [output]) + + def test_deserialize_anytype_dict(self): + response_types_mixed = [ + { + str: (bool, date, datetime, dict, float, int, list, str) + } + ] + string_keys = [str('bogus'), u'bogus', 'bogus'] + for string_key in string_keys: + for input, output in ANYTYPE_PAIRS: + response = MockResponse(data=json.dumps({string_key: input})) + deserialized = self.deserialize(response, response_types_mixed) + self.assertEqual(deserialized, {string_key: output}) + + def test_deserialize_anytype_model_prop(self): + response_types_mixed = [AdditionalPropertiesClass] + for input, output in ANYTYPE_PAIRS: + response = MockResponse(data=json.dumps(dict(anytype_1=input))) + deserialized = self.deserialize(response, response_types_mixed) + self.assertTrue(isinstance(deserialized, AdditionalPropertiesClass)) + self.assertEqual(deserialized.anytype_1, output) + + def test_deserialize_anytype_additionalproperties_prop(self): + response_types_mixed = [AdditionalPropertiesAnyType] + for input, output in ANYTYPE_PAIRS: + response = MockResponse(data=json.dumps(dict(some_var=input))) + deserialized = self.deserialize(response, response_types_mixed) + self.assertTrue(isinstance(deserialized, AdditionalPropertiesAnyType)) + self.assertEqual(deserialized['some_var'], output) + + def test_deserialize_file(self): + """Ensures that file deserialization works""" + response_types_mixed = [file_type] + + # sample from http://www.jtricks.com/download-text + HTTPResponse = namedtuple( + 'urllib3_response_HTTPResponse', + ['status', 'reason', 'data', 'getheaders', 'getheader'] + ) + headers = {'Content-Disposition': 'attachment; filename=content.txt'} + def get_headers(): + return headers + def get_header(name, default=None): + return headers.get(name, default) + file_data = ( + "You are reading text file that was supposed to be downloaded\r\n" + "to your hard disk. If your browser offered to save you the file," + "\r\nthen it handled the Content-Disposition header correctly." + ) + http_response = HTTPResponse( + status=200, + reason='OK', + data=file_data, + getheaders=get_headers, + getheader=get_header + ) + # response which is deserialized to a file + mock_response = RESTResponse(http_response) + file_path = None + try: + file_path = self.deserialize(mock_response, response_types_mixed) + self.assertTrue(os.path.isfile(file_path)) + if six.PY3: + file_data = file_data.encode('utf-8') + with open(file_path, 'rb') as file_object: + self.assertEqual(file_object.read(), file_data) + finally: + if file_path: + os.unlink(file_path) diff --git a/samples/client/petstore/python/tests/test_enum_arrays.py b/samples/client/petstore/python/tests/test_enum_arrays.py index 2f7e347f9c35..120fa64446a5 100644 --- a/samples/client/petstore/python/tests/test_enum_arrays.py +++ b/samples/client/petstore/python/tests/test_enum_arrays.py @@ -34,7 +34,7 @@ def test_enumarrays_init(self): self.assertEqual(fish_or_crab.just_symbol, ">=") self.assertEqual(fish_or_crab.array_enum, ["fish"]) - fish_or_crab = petstore_api.EnumArrays("$", ["crab"]) + fish_or_crab = petstore_api.EnumArrays(just_symbol="$", array_enum=["crab"]) self.assertEqual(fish_or_crab.just_symbol, "$") self.assertEqual(fish_or_crab.array_enum, ["crab"]) @@ -82,13 +82,13 @@ def test_enumarrays_setter(self): fish_or_crab.array_enum = ["fish", "fish", "fish"] self.assertEqual(fish_or_crab.array_enum, ["fish", "fish", "fish"]) - + fish_or_crab.array_enum = ["crab"] self.assertEqual(fish_or_crab.array_enum, ["crab"]) - + fish_or_crab.array_enum = ["crab", "fish"] self.assertEqual(fish_or_crab.array_enum, ["crab", "fish"]) - + fish_or_crab.array_enum = ["crab", "fish", "crab", "fish"] self.assertEqual(fish_or_crab.array_enum, ["crab", "fish", "crab", "fish"]) @@ -100,12 +100,12 @@ def test_enumarrays_setter(self): fish_or_crab.just_symbol = "!=" except ValueError: self.assertEqual(fish_or_crab.just_symbol, None) - + try: fish_or_crab.just_symbol = ["fish"] except ValueError: self.assertEqual(fish_or_crab.just_symbol, None) - + try: fish_or_crab.array_enum = ["cat"] except ValueError: @@ -131,7 +131,7 @@ def test_todict(self): 'array_enum': ["fish", "crab"] } - dollar_fish_crab = petstore_api.EnumArrays("$", ["fish", "crab"]) + dollar_fish_crab = petstore_api.EnumArrays(just_symbol="$", array_enum=["fish", "crab"]) self.assertEqual(dollar_fish_crab_dict, dollar_fish_crab.to_dict()) @@ -143,7 +143,7 @@ def test_todict(self): 'array_enum': ["crab", "fish"] } - dollar_fish_crab = petstore_api.EnumArrays("$", ["fish", "crab"]) + dollar_fish_crab = petstore_api.EnumArrays(just_symbol="$", array_enum=["fish", "crab"]) self.assertNotEqual(dollar_crab_fish_dict, dollar_fish_crab.to_dict()) @@ -152,14 +152,14 @@ def test_equals(self): # # Check if object comparison works # - fish1 = petstore_api.EnumArrays("$", ["fish"]) - fish2 = petstore_api.EnumArrays("$", ["fish"]) + fish1 = petstore_api.EnumArrays(just_symbol="$", array_enum=["fish"]) + fish2 = petstore_api.EnumArrays(just_symbol="$", array_enum=["fish"]) self.assertEqual(fish1, fish2) - fish = petstore_api.EnumArrays("$", ["fish"]) - crab = petstore_api.EnumArrays("$", ["crab"]) - self.assertNotEqual(fish, crab) + fish = petstore_api.EnumArrays(just_symbol="$", array_enum=["fish"]) + crab = petstore_api.EnumArrays(just_symbol="$", array_enum=["crab"]) + self.assertNotEqual(fish, crab) - dollar = petstore_api.EnumArrays("$") - greater = petstore_api.EnumArrays(">=") - self.assertNotEqual(dollar, greater) \ No newline at end of file + dollar = petstore_api.EnumArrays(just_symbol="$") + greater = petstore_api.EnumArrays(just_symbol=">=") + self.assertNotEqual(dollar, greater) diff --git a/samples/client/petstore/python/tests/test_pet_model.py b/samples/client/petstore/python/tests/test_pet_model.py index 70ab1a007a06..c3352015b973 100644 --- a/samples/client/petstore/python/tests/test_pet_model.py +++ b/samples/client/petstore/python/tests/test_pet_model.py @@ -36,7 +36,7 @@ def test_to_str(self): " 'name': 'test name',\n" " 'photo_urls': ['string'],\n" " 'status': 'available',\n" - " 'tags': [{'id': 1, 'name': None}]}") + " 'tags': [{'id': 1}]}") self.assertEqual(data, self.pet.to_str()) def test_equal(self): diff --git a/samples/openapi3/client/petstore/python/README.md b/samples/openapi3/client/petstore/python/README.md index 63317545a0ee..e9a8e9c5987d 100644 --- a/samples/openapi3/client/petstore/python/README.md +++ b/samples/openapi3/client/petstore/python/README.md @@ -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) diff --git a/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesClass.md b/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesClass.md index 796a789d4c4b..beb2e2d4f1ed 100644 --- a/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesClass.md +++ b/samples/openapi3/client/petstore/python/docs/AdditionalPropertiesClass.md @@ -3,8 +3,8 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**map_property** | **dict(str, str)** | | [optional] -**map_of_map_property** | **dict(str, dict(str, str))** | | [optional] +**map_property** | **{str: (str,)}** | | [optional] +**map_of_map_property** | **{str: ({str: (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/docs/ArrayOfArrayOfNumberOnly.md b/samples/openapi3/client/petstore/python/docs/ArrayOfArrayOfNumberOnly.md index aa3988ab1679..323b6edc56b9 100644 --- a/samples/openapi3/client/petstore/python/docs/ArrayOfArrayOfNumberOnly.md +++ b/samples/openapi3/client/petstore/python/docs/ArrayOfArrayOfNumberOnly.md @@ -3,7 +3,7 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**array_array_number** | **list[list[float]]** | | [optional] +**array_array_number** | **[([(float,)],)]** | | [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/ArrayOfNumberOnly.md b/samples/openapi3/client/petstore/python/docs/ArrayOfNumberOnly.md index 2c3de967aec6..502d335fcfc3 100644 --- a/samples/openapi3/client/petstore/python/docs/ArrayOfNumberOnly.md +++ b/samples/openapi3/client/petstore/python/docs/ArrayOfNumberOnly.md @@ -3,7 +3,7 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**array_number** | **list[float]** | | [optional] +**array_number** | **[(float,)]** | | [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/ArrayTest.md b/samples/openapi3/client/petstore/python/docs/ArrayTest.md index 6ab0d1378065..d3a915da27c1 100644 --- a/samples/openapi3/client/petstore/python/docs/ArrayTest.md +++ b/samples/openapi3/client/petstore/python/docs/ArrayTest.md @@ -3,9 +3,9 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**array_of_string** | **list[str]** | | [optional] -**array_array_of_integer** | **list[list[int]]** | | [optional] -**array_array_of_model** | **list[list[ReadOnlyFirst]]** | | [optional] +**array_of_string** | **[(str,)]** | | [optional] +**array_array_of_integer** | **[([(int,)],)]** | | [optional] +**array_array_of_model** | **[([(ReadOnlyFirst,)],)]** | | [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/Cat.md b/samples/openapi3/client/petstore/python/docs/Cat.md index 8d30565d014e..d052c5615b84 100644 --- a/samples/openapi3/client/petstore/python/docs/Cat.md +++ b/samples/openapi3/client/petstore/python/docs/Cat.md @@ -3,6 +3,8 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**class_name** | **str** | | +**color** | **str** | | [optional] [default to 'red'] **declawed** | **bool** | | [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/Dog.md b/samples/openapi3/client/petstore/python/docs/Dog.md index f727487975c4..ac70f17e668a 100644 --- a/samples/openapi3/client/petstore/python/docs/Dog.md +++ b/samples/openapi3/client/petstore/python/docs/Dog.md @@ -3,6 +3,8 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**class_name** | **str** | | +**color** | **str** | | [optional] [default to 'red'] **breed** | **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/docs/EnumArrays.md b/samples/openapi3/client/petstore/python/docs/EnumArrays.md index e15a5f1fd049..4a87d6a62ea2 100644 --- a/samples/openapi3/client/petstore/python/docs/EnumArrays.md +++ b/samples/openapi3/client/petstore/python/docs/EnumArrays.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **just_symbol** | **str** | | [optional] -**array_enum** | **list[str]** | | [optional] +**array_enum** | **[(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/docs/FakeApi.md b/samples/openapi3/client/petstore/python/docs/FakeApi.md index 2a95b367e6e0..12435e4a3a5f 100644 --- a/samples/openapi3/client/petstore/python/docs/FakeApi.md +++ b/samples/openapi3/client/petstore/python/docs/FakeApi.md @@ -429,7 +429,7 @@ int32 = 56 # int | None (optional) int64 = 56 # int | None (optional) float = 3.4 # float | None (optional) string = 'string_example' # str | None (optional) -binary = '/path/to/file' # file | None (optional) +binary = '/path/to/file' # file_type | None (optional) date = '2013-10-20' # date | None (optional) date_time = '2013-10-20T19:20:30+01:00' # datetime | None (optional) password = 'password_example' # str | None (optional) @@ -455,7 +455,7 @@ Name | Type | Description | Notes **int64** | **int**| None | [optional] **float** | **float**| None | [optional] **string** | **str**| None | [optional] - **binary** | **file**| None | [optional] + **binary** | **file_type**| None | [optional] **date** | **date**| None | [optional] **date_time** | **datetime**| None | [optional] **password** | **str**| None | [optional] @@ -494,13 +494,13 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.FakeApi() -enum_header_string_array = ['enum_header_string_array_example'] # list[str] | Header parameter enum test (string array) (optional) +enum_header_string_array = ['enum_header_string_array_example'] # [(str,)] | Header parameter enum test (string array) (optional) enum_header_string = '-efg' # str | Header parameter enum test (string) (optional) (default to '-efg') -enum_query_string_array = ['enum_query_string_array_example'] # list[str] | Query parameter enum test (string array) (optional) +enum_query_string_array = ['enum_query_string_array_example'] # [(str,)] | Query parameter enum test (string array) (optional) enum_query_string = '-efg' # str | Query parameter enum test (string) (optional) (default to '-efg') enum_query_integer = 56 # int | Query parameter enum test (double) (optional) enum_query_double = 3.4 # float | Query parameter enum test (double) (optional) -enum_form_string_array = '$' # list[str] | Form parameter enum test (string array) (optional) (default to '$') +enum_form_string_array = '$' # [(str,)] | Form parameter enum test (string array) (optional) (default to '$') enum_form_string = '-efg' # str | Form parameter enum test (string) (optional) (default to '-efg') try: @@ -514,13 +514,13 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **enum_header_string_array** | [**list[str]**](str.md)| Header parameter enum test (string array) | [optional] + **enum_header_string_array** | [**[(str,)]**](str.md)| Header parameter enum test (string array) | [optional] **enum_header_string** | **str**| Header parameter enum test (string) | [optional] [default to '-efg'] - **enum_query_string_array** | [**list[str]**](str.md)| Query parameter enum test (string array) | [optional] + **enum_query_string_array** | [**[(str,)]**](str.md)| Query parameter enum test (string array) | [optional] **enum_query_string** | **str**| Query parameter enum test (string) | [optional] [default to '-efg'] **enum_query_integer** | **int**| Query parameter enum test (double) | [optional] **enum_query_double** | **float**| Query parameter enum test (double) | [optional] - **enum_form_string_array** | [**list[str]**](str.md)| Form parameter enum test (string array) | [optional] [default to '$'] + **enum_form_string_array** | [**[(str,)]**](str.md)| Form parameter enum test (string array) | [optional] [default to '$'] **enum_form_string** | **str**| Form parameter enum test (string) | [optional] [default to '-efg'] ### Return type @@ -616,7 +616,7 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.FakeApi() -request_body = {'key': 'request_body_example'} # dict(str, str) | request body +request_body = {'key': 'request_body_example'} # {str: (str,)} | request body try: # test inline additionalProperties @@ -629,7 +629,7 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **request_body** | [**dict(str, str)**](str.md)| request body | + **request_body** | [**{str: (str,)}**](str.md)| request body | ### Return type diff --git a/samples/openapi3/client/petstore/python/docs/FileSchemaTestClass.md b/samples/openapi3/client/petstore/python/docs/FileSchemaTestClass.md index dc3722289887..73009bdb1bfb 100644 --- a/samples/openapi3/client/petstore/python/docs/FileSchemaTestClass.md +++ b/samples/openapi3/client/petstore/python/docs/FileSchemaTestClass.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **file** | [**File**](File.md) | | [optional] -**files** | [**list[File]**](File.md) | | [optional] +**files** | [**[(File,)]**](File.md) | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/FormatTest.md b/samples/openapi3/client/petstore/python/docs/FormatTest.md index d503d24bfa40..5f15e9fa142c 100644 --- a/samples/openapi3/client/petstore/python/docs/FormatTest.md +++ b/samples/openapi3/client/petstore/python/docs/FormatTest.md @@ -11,7 +11,7 @@ Name | Type | Description | Notes **double** | **float** | | [optional] **string** | **str** | | [optional] **byte** | **str** | | -**binary** | **file** | | [optional] +**binary** | **file_type** | | [optional] **date** | **date** | | **date_time** | **datetime** | | [optional] **uuid** | **str** | | [optional] diff --git a/samples/openapi3/client/petstore/python/docs/HealthCheckResult.md b/samples/openapi3/client/petstore/python/docs/HealthCheckResult.md index 346889210a3d..5223654b8f08 100644 --- a/samples/openapi3/client/petstore/python/docs/HealthCheckResult.md +++ b/samples/openapi3/client/petstore/python/docs/HealthCheckResult.md @@ -3,7 +3,7 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**nullable_message** | **str** | | [optional] +**nullable_message** | **str, none_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/InlineObject1.md b/samples/openapi3/client/petstore/python/docs/InlineObject1.md index 42d38efa3013..4349ad73e3b7 100644 --- a/samples/openapi3/client/petstore/python/docs/InlineObject1.md +++ b/samples/openapi3/client/petstore/python/docs/InlineObject1.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **additional_metadata** | **str** | Additional data to pass to server | [optional] -**file** | **file** | file to upload | [optional] +**file** | **file_type** | file to upload | [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/InlineObject2.md b/samples/openapi3/client/petstore/python/docs/InlineObject2.md index 9bfba12f6f15..0a854ca812b4 100644 --- a/samples/openapi3/client/petstore/python/docs/InlineObject2.md +++ b/samples/openapi3/client/petstore/python/docs/InlineObject2.md @@ -3,7 +3,7 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**enum_form_string_array** | **list[str]** | Form parameter enum test (string array) | [optional] +**enum_form_string_array** | **[(str,)]** | Form parameter enum test (string array) | [optional] **enum_form_string** | **str** | Form parameter enum test (string) | [optional] [default to '-efg'] [[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/InlineObject3.md b/samples/openapi3/client/petstore/python/docs/InlineObject3.md index ef9845fcd9c6..ad3112c4c3a3 100644 --- a/samples/openapi3/client/petstore/python/docs/InlineObject3.md +++ b/samples/openapi3/client/petstore/python/docs/InlineObject3.md @@ -12,7 +12,7 @@ Name | Type | Description | Notes **string** | **str** | None | [optional] **pattern_without_delimiter** | **str** | None | **byte** | **str** | None | -**binary** | **file** | None | [optional] +**binary** | **file_type** | None | [optional] **date** | **date** | None | [optional] **date_time** | **datetime** | None | [optional] **password** | **str** | None | [optional] diff --git a/samples/openapi3/client/petstore/python/docs/InlineObject5.md b/samples/openapi3/client/petstore/python/docs/InlineObject5.md index c4502f70f9c8..d41488d67762 100644 --- a/samples/openapi3/client/petstore/python/docs/InlineObject5.md +++ b/samples/openapi3/client/petstore/python/docs/InlineObject5.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **additional_metadata** | **str** | Additional data to pass to server | [optional] -**required_file** | **file** | file to upload | +**required_file** | **file_type** | file to upload | [[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/MapTest.md b/samples/openapi3/client/petstore/python/docs/MapTest.md index a5601691f885..c88c578cf82e 100644 --- a/samples/openapi3/client/petstore/python/docs/MapTest.md +++ b/samples/openapi3/client/petstore/python/docs/MapTest.md @@ -3,10 +3,10 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**map_map_of_string** | **dict(str, dict(str, str))** | | [optional] -**map_of_enum_string** | **dict(str, str)** | | [optional] -**direct_map** | **dict(str, bool)** | | [optional] -**indirect_map** | **dict(str, bool)** | | [optional] +**map_map_of_string** | **{str: ({str: (str,)},)}** | | [optional] +**map_of_enum_string** | **{str: (str,)}** | | [optional] +**direct_map** | **{str: (bool,)}** | | [optional] +**indirect_map** | **{str: (bool,)}** | | [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/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/openapi3/client/petstore/python/docs/MixedPropertiesAndAdditionalPropertiesClass.md index b9808d5275e5..1484c0638d83 100644 --- a/samples/openapi3/client/petstore/python/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/openapi3/client/petstore/python/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -5,7 +5,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **uuid** | **str** | | [optional] **date_time** | **datetime** | | [optional] -**map** | [**dict(str, Animal)**](Animal.md) | | [optional] +**map** | [**{str: (Animal,)}**](Animal.md) | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/NullableClass.md b/samples/openapi3/client/petstore/python/docs/NullableClass.md new file mode 100644 index 000000000000..6653ff69607f --- /dev/null +++ b/samples/openapi3/client/petstore/python/docs/NullableClass.md @@ -0,0 +1,21 @@ +# NullableClass + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**integer_prop** | **int, none_type** | | [optional] +**number_prop** | **float, none_type** | | [optional] +**boolean_prop** | **bool, none_type** | | [optional] +**string_prop** | **str, none_type** | | [optional] +**date_prop** | **date, none_type** | | [optional] +**datetime_prop** | **datetime, none_type** | | [optional] +**array_nullable_prop** | **[(bool, date, datetime, dict, float, int, list, str)], none_type** | | [optional] +**array_and_items_nullable_prop** | **[(bool, date, datetime, dict, float, int, list, str, none_type)], none_type** | | [optional] +**array_items_nullable** | **[(bool, date, datetime, dict, float, int, list, str, none_type)]** | | [optional] +**object_nullable_prop** | **{str: (bool, date, datetime, dict, float, int, list, str)}, none_type** | | [optional] +**object_and_items_nullable_prop** | **{str: (bool, date, datetime, dict, float, int, list, str, none_type)}, none_type** | | [optional] +**object_items_nullable** | **{str: (bool, date, datetime, dict, float, int, list, str, none_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/Pet.md b/samples/openapi3/client/petstore/python/docs/Pet.md index 9e15090300f8..745d5da843e7 100644 --- a/samples/openapi3/client/petstore/python/docs/Pet.md +++ b/samples/openapi3/client/petstore/python/docs/Pet.md @@ -6,8 +6,8 @@ Name | Type | Description | Notes **id** | **int** | | [optional] **category** | [**Category**](Category.md) | | [optional] **name** | **str** | | -**photo_urls** | **list[str]** | | -**tags** | [**list[Tag]**](Tag.md) | | [optional] +**photo_urls** | **[(str,)]** | | +**tags** | [**[(Tag,)]**](Tag.md) | | [optional] **status** | **str** | pet status in the store | [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/PetApi.md b/samples/openapi3/client/petstore/python/docs/PetApi.md index a089aabc55b2..51410deea03d 100644 --- a/samples/openapi3/client/petstore/python/docs/PetApi.md +++ b/samples/openapi3/client/petstore/python/docs/PetApi.md @@ -118,7 +118,7 @@ void (empty response body) [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **find_pets_by_status** -> list[Pet] find_pets_by_status(status) +> [(Pet,)] find_pets_by_status(status) Finds Pets by status @@ -139,7 +139,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN' # create an instance of the API class api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration)) -status = ['status_example'] # list[str] | Status values that need to be considered for filter +status = ['status_example'] # [(str,)] | Status values that need to be considered for filter try: # Finds Pets by status @@ -153,11 +153,11 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **status** | [**list[str]**](str.md)| Status values that need to be considered for filter | + **status** | [**[(str,)]**](str.md)| Status values that need to be considered for filter | ### Return type -[**list[Pet]**](Pet.md) +[**[(Pet,)]**](Pet.md) ### Authorization @@ -171,7 +171,7 @@ Name | Type | Description | Notes [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **find_pets_by_tags** -> list[Pet] find_pets_by_tags(tags) +> [(Pet,)] find_pets_by_tags(tags) Finds Pets by tags @@ -192,7 +192,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN' # create an instance of the API class api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration)) -tags = ['tags_example'] # list[str] | Tags to filter by +tags = ['tags_example'] # [(str,)] | Tags to filter by try: # Finds Pets by tags @@ -206,11 +206,11 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **tags** | [**list[str]**](str.md)| Tags to filter by | + **tags** | [**[(str,)]**](str.md)| Tags to filter by | ### Return type -[**list[Pet]**](Pet.md) +[**[(Pet,)]**](Pet.md) ### Authorization @@ -404,7 +404,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN' api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration)) pet_id = 56 # int | ID of pet to update additional_metadata = 'additional_metadata_example' # str | Additional data to pass to server (optional) -file = '/path/to/file' # file | file to upload (optional) +file = '/path/to/file' # file_type | file to upload (optional) try: # uploads an image @@ -420,7 +420,7 @@ Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **pet_id** | **int**| ID of pet to update | **additional_metadata** | **str**| Additional data to pass to server | [optional] - **file** | **file**| file to upload | [optional] + **file** | **file_type**| file to upload | [optional] ### Return type @@ -458,7 +458,7 @@ configuration.access_token = 'YOUR_ACCESS_TOKEN' # create an instance of the API class api_instance = petstore_api.PetApi(petstore_api.ApiClient(configuration)) pet_id = 56 # int | ID of pet to update -required_file = '/path/to/file' # file | file to upload +required_file = '/path/to/file' # file_type | file to upload additional_metadata = 'additional_metadata_example' # str | Additional data to pass to server (optional) try: @@ -474,7 +474,7 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- **pet_id** | **int**| ID of pet to update | - **required_file** | **file**| file to upload | + **required_file** | **file_type**| file to upload | **additional_metadata** | **str**| Additional data to pass to server | [optional] ### Return type diff --git a/samples/openapi3/client/petstore/python/docs/StoreApi.md b/samples/openapi3/client/petstore/python/docs/StoreApi.md index f40a25a154ea..b5258f7299a0 100644 --- a/samples/openapi3/client/petstore/python/docs/StoreApi.md +++ b/samples/openapi3/client/petstore/python/docs/StoreApi.md @@ -59,7 +59,7 @@ No authorization required [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **get_inventory** -> dict(str, int) get_inventory() +> {str: (int,)} get_inventory() Returns pet inventories by status @@ -96,7 +96,7 @@ This endpoint does not need any parameter. ### Return type -**dict(str, int)** +**{str: (int,)}** ### Authorization diff --git a/samples/openapi3/client/petstore/python/docs/UserApi.md b/samples/openapi3/client/petstore/python/docs/UserApi.md index da87cd282d1e..4da6eb4a6fb5 100644 --- a/samples/openapi3/client/petstore/python/docs/UserApi.md +++ b/samples/openapi3/client/petstore/python/docs/UserApi.md @@ -78,7 +78,7 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.UserApi() -user = NULL # list[User] | List of user object +user = NULL # [(User,)] | List of user object try: # Creates list of users with given input array @@ -91,7 +91,7 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **user** | [**list[User]**](list.md)| List of user object | + **user** | [**[(User,)]**](list.md)| List of user object | ### Return type @@ -124,7 +124,7 @@ from pprint import pprint # create an instance of the API class api_instance = petstore_api.UserApi() -user = NULL # list[User] | List of user object +user = NULL # [(User,)] | List of user object try: # Creates list of users with given input array @@ -137,7 +137,7 @@ except ApiException as e: Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **user** | [**list[User]**](list.md)| List of user object | + **user** | [**[(User,)]**](list.md)| List of user object | ### Return type diff --git a/samples/openapi3/client/petstore/python/petstore_api/__init__.py b/samples/openapi3/client/petstore/python/petstore_api/__init__.py index 847b8393f0b1..84b0f896cf87 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/__init__.py @@ -63,6 +63,7 @@ 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 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/another_fake_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/another_fake_api.py index 782f7fd07b35..805fe5d10182 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api/another_fake_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/another_fake_api.py @@ -18,6 +18,20 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.client import Client class AnotherFakeApi(object): @@ -32,7 +46,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def call_123_test_special_tags(self, client, **kwargs): # noqa: E501 + def call_123_test_special_tags(self, client, _check_type=False, **kwargs): # noqa: E501 """To test special tags # noqa: E501 To test special tags and operation ID starting with number # noqa: E501 @@ -49,12 +63,12 @@ def call_123_test_special_tags(self, client, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.call_123_test_special_tags_with_http_info(client, **kwargs) # noqa: E501 + return self.call_123_test_special_tags_with_http_info(client, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.call_123_test_special_tags_with_http_info(client, **kwargs) # noqa: E501 + (data) = self.call_123_test_special_tags_with_http_info(client, _check_type=_check_type, **kwargs) # noqa: E501 return data - def call_123_test_special_tags_with_http_info(self, client, **kwargs): # noqa: E501 + def call_123_test_special_tags_with_http_info(self, client, _check_type=False, **kwargs): # noqa: E501 """To test special tags # noqa: E501 To test special tags and operation ID starting with number # noqa: E501 @@ -80,16 +94,26 @@ def call_123_test_special_tags_with_http_info(self, client, **kwargs): # noqa: for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method call_123_test_special_tags" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'client': [Client], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'client' is set if ('client' not in local_var_params or local_var_params['client'] is None): - raise ValueError("Missing the required parameter `client` when calling `call_123_test_special_tags`") # noqa: E501 + raise ApiValueError("Missing the required parameter `client` when calling `call_123_test_special_tags`") # noqa: E501 collection_formats = {} @@ -124,7 +148,7 @@ def call_123_test_special_tags_with_http_info(self, client, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types_mixed=[Client], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/default_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/default_api.py index 035f2697a667..d49c68fb21ea 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api/default_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/default_api.py @@ -18,6 +18,20 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.inline_response_default import InlineResponseDefault class DefaultApi(object): @@ -32,7 +46,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def foo_get(self, **kwargs): # noqa: E501 + def foo_get(self, _check_type=False, **kwargs): # noqa: E501 """foo_get # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -47,12 +61,12 @@ def foo_get(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.foo_get_with_http_info(**kwargs) # noqa: E501 + return self.foo_get_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.foo_get_with_http_info(**kwargs) # noqa: E501 + (data) = self.foo_get_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def foo_get_with_http_info(self, **kwargs): # noqa: E501 + def foo_get_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """foo_get # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -76,7 +90,7 @@ def foo_get_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method foo_get" % key ) @@ -110,7 +124,7 @@ def foo_get_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='InlineResponseDefault', # noqa: E501 + response_types_mixed=[InlineResponseDefault], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/fake_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/fake_api.py index cf6ff848c63d..6568c2be814a 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api/fake_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/fake_api.py @@ -18,6 +18,24 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.client import Client +from petstore_api.models.file_schema_test_class import FileSchemaTestClass +from petstore_api.models.health_check_result import HealthCheckResult +from petstore_api.models.outer_composite import OuterComposite +from petstore_api.models.user import User class FakeApi(object): @@ -32,7 +50,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def fake_health_get(self, **kwargs): # noqa: E501 + def fake_health_get(self, _check_type=False, **kwargs): # noqa: E501 """Health check endpoint # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -47,12 +65,12 @@ def fake_health_get(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.fake_health_get_with_http_info(**kwargs) # noqa: E501 + return self.fake_health_get_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.fake_health_get_with_http_info(**kwargs) # noqa: E501 + (data) = self.fake_health_get_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def fake_health_get_with_http_info(self, **kwargs): # noqa: E501 + def fake_health_get_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """Health check endpoint # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -76,7 +94,7 @@ def fake_health_get_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method fake_health_get" % key ) @@ -110,7 +128,7 @@ def fake_health_get_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='HealthCheckResult', # noqa: E501 + response_types_mixed=[HealthCheckResult], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -118,7 +136,7 @@ def fake_health_get_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def fake_outer_boolean_serialize(self, **kwargs): # noqa: E501 + def fake_outer_boolean_serialize(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_boolean_serialize # noqa: E501 Test serialization of outer boolean types # noqa: E501 @@ -135,12 +153,12 @@ def fake_outer_boolean_serialize(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.fake_outer_boolean_serialize_with_http_info(**kwargs) # noqa: E501 + return self.fake_outer_boolean_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.fake_outer_boolean_serialize_with_http_info(**kwargs) # noqa: E501 + (data) = self.fake_outer_boolean_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 + def fake_outer_boolean_serialize_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_boolean_serialize # noqa: E501 Test serialization of outer boolean types # noqa: E501 @@ -166,12 +184,22 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method fake_outer_boolean_serialize" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [bool], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) collection_formats = {} @@ -206,7 +234,7 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='bool', # noqa: E501 + response_types_mixed=[bool], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -214,7 +242,7 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def fake_outer_composite_serialize(self, **kwargs): # noqa: E501 + def fake_outer_composite_serialize(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_composite_serialize # noqa: E501 Test serialization of object with outer number type # noqa: E501 @@ -231,12 +259,12 @@ def fake_outer_composite_serialize(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.fake_outer_composite_serialize_with_http_info(**kwargs) # noqa: E501 + return self.fake_outer_composite_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.fake_outer_composite_serialize_with_http_info(**kwargs) # noqa: E501 + (data) = self.fake_outer_composite_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 + def fake_outer_composite_serialize_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_composite_serialize # noqa: E501 Test serialization of object with outer number type # noqa: E501 @@ -262,12 +290,22 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method fake_outer_composite_serialize" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'outer_composite': [OuterComposite], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) collection_formats = {} @@ -302,7 +340,7 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='OuterComposite', # noqa: E501 + response_types_mixed=[OuterComposite], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -310,7 +348,7 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def fake_outer_number_serialize(self, **kwargs): # noqa: E501 + def fake_outer_number_serialize(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_number_serialize # noqa: E501 Test serialization of outer number types # noqa: E501 @@ -327,12 +365,12 @@ def fake_outer_number_serialize(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.fake_outer_number_serialize_with_http_info(**kwargs) # noqa: E501 + return self.fake_outer_number_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.fake_outer_number_serialize_with_http_info(**kwargs) # noqa: E501 + (data) = self.fake_outer_number_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 + def fake_outer_number_serialize_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_number_serialize # noqa: E501 Test serialization of outer number types # noqa: E501 @@ -358,12 +396,22 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method fake_outer_number_serialize" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [float], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) collection_formats = {} @@ -398,7 +446,7 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='float', # noqa: E501 + response_types_mixed=[float], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -406,7 +454,7 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def fake_outer_string_serialize(self, **kwargs): # noqa: E501 + def fake_outer_string_serialize(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_string_serialize # noqa: E501 Test serialization of outer string types # noqa: E501 @@ -423,12 +471,12 @@ def fake_outer_string_serialize(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.fake_outer_string_serialize_with_http_info(**kwargs) # noqa: E501 + return self.fake_outer_string_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.fake_outer_string_serialize_with_http_info(**kwargs) # noqa: E501 + (data) = self.fake_outer_string_serialize_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 + def fake_outer_string_serialize_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """fake_outer_string_serialize # noqa: E501 Test serialization of outer string types # noqa: E501 @@ -454,12 +502,22 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method fake_outer_string_serialize" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'body': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) collection_formats = {} @@ -494,7 +552,7 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='str', # noqa: E501 + response_types_mixed=[str], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -502,7 +560,7 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_body_with_file_schema(self, file_schema_test_class, **kwargs): # noqa: E501 + def test_body_with_file_schema(self, file_schema_test_class, _check_type=False, **kwargs): # noqa: E501 """test_body_with_file_schema # noqa: E501 For this test, the body for this request much reference a schema named `File`. # noqa: E501 @@ -519,12 +577,12 @@ def test_body_with_file_schema(self, file_schema_test_class, **kwargs): # noqa: """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_body_with_file_schema_with_http_info(file_schema_test_class, **kwargs) # noqa: E501 + return self.test_body_with_file_schema_with_http_info(file_schema_test_class, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_body_with_file_schema_with_http_info(file_schema_test_class, **kwargs) # noqa: E501 + (data) = self.test_body_with_file_schema_with_http_info(file_schema_test_class, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_body_with_file_schema_with_http_info(self, file_schema_test_class, **kwargs): # noqa: E501 + def test_body_with_file_schema_with_http_info(self, file_schema_test_class, _check_type=False, **kwargs): # noqa: E501 """test_body_with_file_schema # noqa: E501 For this test, the body for this request much reference a schema named `File`. # noqa: E501 @@ -550,16 +608,26 @@ def test_body_with_file_schema_with_http_info(self, file_schema_test_class, **kw for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_body_with_file_schema" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'file_schema_test_class': [FileSchemaTestClass], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'file_schema_test_class' is set if ('file_schema_test_class' not in local_var_params or local_var_params['file_schema_test_class'] is None): - raise ValueError("Missing the required parameter `file_schema_test_class` when calling `test_body_with_file_schema`") # noqa: E501 + raise ApiValueError("Missing the required parameter `file_schema_test_class` when calling `test_body_with_file_schema`") # noqa: E501 collection_formats = {} @@ -590,7 +658,7 @@ def test_body_with_file_schema_with_http_info(self, file_schema_test_class, **kw body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -598,7 +666,7 @@ def test_body_with_file_schema_with_http_info(self, file_schema_test_class, **kw _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_body_with_query_params(self, query, user, **kwargs): # noqa: E501 + def test_body_with_query_params(self, query, user, _check_type=False, **kwargs): # noqa: E501 """test_body_with_query_params # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -615,12 +683,12 @@ def test_body_with_query_params(self, query, user, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_body_with_query_params_with_http_info(query, user, **kwargs) # noqa: E501 + return self.test_body_with_query_params_with_http_info(query, user, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_body_with_query_params_with_http_info(query, user, **kwargs) # noqa: E501 + (data) = self.test_body_with_query_params_with_http_info(query, user, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_body_with_query_params_with_http_info(self, query, user, **kwargs): # noqa: E501 + def test_body_with_query_params_with_http_info(self, query, user, _check_type=False, **kwargs): # noqa: E501 """test_body_with_query_params # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -646,20 +714,31 @@ def test_body_with_query_params_with_http_info(self, query, user, **kwargs): # for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_body_with_query_params" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'query': [str], + 'user': [User], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'query' is set if ('query' not in local_var_params or local_var_params['query'] is None): - raise ValueError("Missing the required parameter `query` when calling `test_body_with_query_params`") # noqa: E501 + raise ApiValueError("Missing the required parameter `query` when calling `test_body_with_query_params`") # noqa: E501 # verify the required parameter 'user' is set if ('user' not in local_var_params or local_var_params['user'] is None): - raise ValueError("Missing the required parameter `user` when calling `test_body_with_query_params`") # noqa: E501 + raise ApiValueError("Missing the required parameter `user` when calling `test_body_with_query_params`") # noqa: E501 collection_formats = {} @@ -692,7 +771,7 @@ def test_body_with_query_params_with_http_info(self, query, user, **kwargs): # body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -700,7 +779,7 @@ def test_body_with_query_params_with_http_info(self, query, user, **kwargs): # _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_client_model(self, client, **kwargs): # noqa: E501 + def test_client_model(self, client, _check_type=False, **kwargs): # noqa: E501 """To test \"client\" model # noqa: E501 To test \"client\" model # noqa: E501 @@ -717,12 +796,12 @@ def test_client_model(self, client, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_client_model_with_http_info(client, **kwargs) # noqa: E501 + return self.test_client_model_with_http_info(client, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_client_model_with_http_info(client, **kwargs) # noqa: E501 + (data) = self.test_client_model_with_http_info(client, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_client_model_with_http_info(self, client, **kwargs): # noqa: E501 + def test_client_model_with_http_info(self, client, _check_type=False, **kwargs): # noqa: E501 """To test \"client\" model # noqa: E501 To test \"client\" model # noqa: E501 @@ -748,16 +827,26 @@ def test_client_model_with_http_info(self, client, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_client_model" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'client': [Client], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'client' is set if ('client' not in local_var_params or local_var_params['client'] is None): - raise ValueError("Missing the required parameter `client` when calling `test_client_model`") # noqa: E501 + raise ApiValueError("Missing the required parameter `client` when calling `test_client_model`") # noqa: E501 collection_formats = {} @@ -792,7 +881,7 @@ def test_client_model_with_http_info(self, client, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types_mixed=[Client], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -800,7 +889,7 @@ def test_client_model_with_http_info(self, client, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_endpoint_parameters(self, number, double, pattern_without_delimiter, byte, **kwargs): # noqa: E501 + def test_endpoint_parameters(self, number, double, pattern_without_delimiter, byte, _check_type=False, **kwargs): # noqa: E501 """Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 @@ -819,7 +908,7 @@ def test_endpoint_parameters(self, number, double, pattern_without_delimiter, by :param int int64: None :param float float: None :param str string: None - :param file binary: None + :param file_type binary: None :param date date: None :param datetime date_time: None :param str password: None @@ -830,12 +919,12 @@ def test_endpoint_parameters(self, number, double, pattern_without_delimiter, by """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_endpoint_parameters_with_http_info(number, double, pattern_without_delimiter, byte, **kwargs) # noqa: E501 + return self.test_endpoint_parameters_with_http_info(number, double, pattern_without_delimiter, byte, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_endpoint_parameters_with_http_info(number, double, pattern_without_delimiter, byte, **kwargs) # noqa: E501 + (data) = self.test_endpoint_parameters_with_http_info(number, double, pattern_without_delimiter, byte, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_endpoint_parameters_with_http_info(self, number, double, pattern_without_delimiter, byte, **kwargs): # noqa: E501 + def test_endpoint_parameters_with_http_info(self, number, double, pattern_without_delimiter, byte, _check_type=False, **kwargs): # noqa: E501 """Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # noqa: E501 @@ -854,7 +943,7 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou :param int int64: None :param float float: None :param str string: None - :param file binary: None + :param file_type binary: None :param date date: None :param datetime date_time: None :param str password: None @@ -874,57 +963,80 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_endpoint_parameters" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'number': [float], + 'double': [float], + 'pattern_without_delimiter': [str], + 'byte': [str], + 'integer': [int], + 'int32': [int], + 'int64': [int], + 'float': [float], + 'string': [str], + 'binary': [file_type], + 'date': [date], + 'date_time': [datetime], + 'password': [str], + 'param_callback': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'number' is set if ('number' not in local_var_params or local_var_params['number'] is None): - raise ValueError("Missing the required parameter `number` when calling `test_endpoint_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `number` when calling `test_endpoint_parameters`") # noqa: E501 # verify the required parameter 'double' is set if ('double' not in local_var_params or local_var_params['double'] is None): - raise ValueError("Missing the required parameter `double` when calling `test_endpoint_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `double` when calling `test_endpoint_parameters`") # noqa: E501 # verify the required parameter 'pattern_without_delimiter' is set if ('pattern_without_delimiter' not in local_var_params or local_var_params['pattern_without_delimiter'] is None): - raise ValueError("Missing the required parameter `pattern_without_delimiter` when calling `test_endpoint_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pattern_without_delimiter` when calling `test_endpoint_parameters`") # noqa: E501 # verify the required parameter 'byte' is set if ('byte' not in local_var_params or local_var_params['byte'] is None): - raise ValueError("Missing the required parameter `byte` when calling `test_endpoint_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `byte` when calling `test_endpoint_parameters`") # noqa: E501 if 'number' in local_var_params and local_var_params['number'] > 543.2: # noqa: E501 - raise ValueError("Invalid value for parameter `number` when calling `test_endpoint_parameters`, must be a value less than or equal to `543.2`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `number` when calling `test_endpoint_parameters`, must be a value less than or equal to `543.2`") # noqa: E501 if 'number' in local_var_params and local_var_params['number'] < 32.1: # noqa: E501 - raise ValueError("Invalid value for parameter `number` when calling `test_endpoint_parameters`, must be a value greater than or equal to `32.1`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `number` when calling `test_endpoint_parameters`, must be a value greater than or equal to `32.1`") # noqa: E501 if 'double' in local_var_params and local_var_params['double'] > 123.4: # noqa: E501 - raise ValueError("Invalid value for parameter `double` when calling `test_endpoint_parameters`, must be a value less than or equal to `123.4`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `double` when calling `test_endpoint_parameters`, must be a value less than or equal to `123.4`") # noqa: E501 if 'double' in local_var_params and local_var_params['double'] < 67.8: # noqa: E501 - raise ValueError("Invalid value for parameter `double` when calling `test_endpoint_parameters`, must be a value greater than or equal to `67.8`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `double` when calling `test_endpoint_parameters`, must be a value greater than or equal to `67.8`") # noqa: E501 if 'pattern_without_delimiter' in local_var_params and not re.search(r'^[A-Z].*', local_var_params['pattern_without_delimiter']): # noqa: E501 - raise ValueError("Invalid value for parameter `pattern_without_delimiter` when calling `test_endpoint_parameters`, must conform to the pattern `/^[A-Z].*/`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `pattern_without_delimiter` when calling `test_endpoint_parameters`, must conform to the pattern `/^[A-Z].*/`") # noqa: E501 if 'integer' in local_var_params and local_var_params['integer'] > 100: # noqa: E501 - raise ValueError("Invalid value for parameter `integer` when calling `test_endpoint_parameters`, must be a value less than or equal to `100`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `integer` when calling `test_endpoint_parameters`, must be a value less than or equal to `100`") # noqa: E501 if 'integer' in local_var_params and local_var_params['integer'] < 10: # noqa: E501 - raise ValueError("Invalid value for parameter `integer` when calling `test_endpoint_parameters`, must be a value greater than or equal to `10`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `integer` when calling `test_endpoint_parameters`, must be a value greater than or equal to `10`") # noqa: E501 if 'int32' in local_var_params and local_var_params['int32'] > 200: # noqa: E501 - raise ValueError("Invalid value for parameter `int32` when calling `test_endpoint_parameters`, must be a value less than or equal to `200`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `int32` when calling `test_endpoint_parameters`, must be a value less than or equal to `200`") # noqa: E501 if 'int32' in local_var_params and local_var_params['int32'] < 20: # noqa: E501 - raise ValueError("Invalid value for parameter `int32` when calling `test_endpoint_parameters`, must be a value greater than or equal to `20`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `int32` when calling `test_endpoint_parameters`, must be a value greater than or equal to `20`") # noqa: E501 if 'float' in local_var_params and local_var_params['float'] > 987.6: # noqa: E501 - raise ValueError("Invalid value for parameter `float` when calling `test_endpoint_parameters`, must be a value less than or equal to `987.6`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `float` when calling `test_endpoint_parameters`, must be a value less than or equal to `987.6`") # noqa: E501 if 'string' in local_var_params and not re.search(r'[a-z]', local_var_params['string'], flags=re.IGNORECASE): # noqa: E501 - raise ValueError("Invalid value for parameter `string` when calling `test_endpoint_parameters`, must conform to the pattern `/[a-z]/i`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `string` when calling `test_endpoint_parameters`, must conform to the pattern `/[a-z]/i`") # noqa: E501 if ('password' in local_var_params and len(local_var_params['password']) > 64): - raise ValueError("Invalid value for parameter `password` when calling `test_endpoint_parameters`, length must be less than or equal to `64`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `password` when calling `test_endpoint_parameters`, length must be less than or equal to `64`") # noqa: E501 if ('password' in local_var_params and len(local_var_params['password']) < 10): - raise ValueError("Invalid value for parameter `password` when calling `test_endpoint_parameters`, length must be greater than or equal to `10`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `password` when calling `test_endpoint_parameters`, length must be greater than or equal to `10`") # noqa: E501 collection_formats = {} path_params = {} @@ -980,7 +1092,7 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -988,7 +1100,7 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_enum_parameters(self, **kwargs): # noqa: E501 + def test_enum_parameters(self, _check_type=False, **kwargs): # noqa: E501 """To test enum parameters # noqa: E501 To test enum parameters # noqa: E501 @@ -998,13 +1110,13 @@ def test_enum_parameters(self, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] enum_header_string_array: Header parameter enum test (string array) + :param [(str,)] enum_header_string_array: Header parameter enum test (string array) :param str enum_header_string: Header parameter enum test (string) - :param list[str] enum_query_string_array: Query parameter enum test (string array) + :param [(str,)] enum_query_string_array: Query parameter enum test (string array) :param str enum_query_string: Query parameter enum test (string) :param int enum_query_integer: Query parameter enum test (double) :param float enum_query_double: Query parameter enum test (double) - :param list[str] enum_form_string_array: Form parameter enum test (string array) + :param [(str,)] enum_form_string_array: Form parameter enum test (string array) :param str enum_form_string: Form parameter enum test (string) :return: None If the method is called asynchronously, @@ -1012,12 +1124,12 @@ def test_enum_parameters(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_enum_parameters_with_http_info(**kwargs) # noqa: E501 + return self.test_enum_parameters_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_enum_parameters_with_http_info(**kwargs) # noqa: E501 + (data) = self.test_enum_parameters_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 + def test_enum_parameters_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """To test enum parameters # noqa: E501 To test enum parameters # noqa: E501 @@ -1027,13 +1139,13 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] enum_header_string_array: Header parameter enum test (string array) + :param [(str,)] enum_header_string_array: Header parameter enum test (string array) :param str enum_header_string: Header parameter enum test (string) - :param list[str] enum_query_string_array: Query parameter enum test (string array) + :param [(str,)] enum_query_string_array: Query parameter enum test (string array) :param str enum_query_string: Query parameter enum test (string) :param int enum_query_integer: Query parameter enum test (double) :param float enum_query_double: Query parameter enum test (double) - :param list[str] enum_form_string_array: Form parameter enum test (string array) + :param [(str,)] enum_form_string_array: Form parameter enum test (string array) :param str enum_form_string: Form parameter enum test (string) :return: None If the method is called asynchronously, @@ -1050,12 +1162,29 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_enum_parameters" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'enum_header_string_array': [[(str,)]], + 'enum_header_string': [str], + 'enum_query_string_array': [[(str,)]], + 'enum_query_string': [str], + 'enum_query_integer': [int], + 'enum_query_double': [float], + 'enum_form_string_array': [[(str,)]], + 'enum_form_string': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) collection_formats = {} @@ -1103,7 +1232,7 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1111,7 +1240,7 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_group_parameters(self, required_string_group, required_boolean_group, required_int64_group, **kwargs): # noqa: E501 + def test_group_parameters(self, required_string_group, required_boolean_group, required_int64_group, _check_type=False, **kwargs): # noqa: E501 """Fake endpoint to test group parameters (optional) # noqa: E501 Fake endpoint to test group parameters (optional) # noqa: E501 @@ -1133,12 +1262,12 @@ def test_group_parameters(self, required_string_group, required_boolean_group, r """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_group_parameters_with_http_info(required_string_group, required_boolean_group, required_int64_group, **kwargs) # noqa: E501 + return self.test_group_parameters_with_http_info(required_string_group, required_boolean_group, required_int64_group, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_group_parameters_with_http_info(required_string_group, required_boolean_group, required_int64_group, **kwargs) # noqa: E501 + (data) = self.test_group_parameters_with_http_info(required_string_group, required_boolean_group, required_int64_group, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_group_parameters_with_http_info(self, required_string_group, required_boolean_group, required_int64_group, **kwargs): # noqa: E501 + def test_group_parameters_with_http_info(self, required_string_group, required_boolean_group, required_int64_group, _check_type=False, **kwargs): # noqa: E501 """Fake endpoint to test group parameters (optional) # noqa: E501 Fake endpoint to test group parameters (optional) # noqa: E501 @@ -1169,24 +1298,39 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_group_parameters" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'required_string_group': [int], + 'required_boolean_group': [bool], + 'required_int64_group': [int], + 'string_group': [int], + 'boolean_group': [bool], + 'int64_group': [int], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'required_string_group' is set if ('required_string_group' not in local_var_params or local_var_params['required_string_group'] is None): - raise ValueError("Missing the required parameter `required_string_group` when calling `test_group_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `required_string_group` when calling `test_group_parameters`") # noqa: E501 # verify the required parameter 'required_boolean_group' is set if ('required_boolean_group' not in local_var_params or local_var_params['required_boolean_group'] is None): - raise ValueError("Missing the required parameter `required_boolean_group` when calling `test_group_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `required_boolean_group` when calling `test_group_parameters`") # noqa: E501 # verify the required parameter 'required_int64_group' is set if ('required_int64_group' not in local_var_params or local_var_params['required_int64_group'] is None): - raise ValueError("Missing the required parameter `required_int64_group` when calling `test_group_parameters`") # noqa: E501 + raise ApiValueError("Missing the required parameter `required_int64_group` when calling `test_group_parameters`") # noqa: E501 collection_formats = {} @@ -1223,7 +1367,7 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1231,7 +1375,7 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_inline_additional_properties(self, request_body, **kwargs): # noqa: E501 + def test_inline_additional_properties(self, request_body, _check_type=False, **kwargs): # noqa: E501 """test inline additionalProperties # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -1240,19 +1384,19 @@ def test_inline_additional_properties(self, request_body, **kwargs): # noqa: E5 >>> result = thread.get() :param async_req bool - :param dict(str, str) request_body: request body (required) + :param {str: (str,)} request_body: request body (required) :return: None If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_inline_additional_properties_with_http_info(request_body, **kwargs) # noqa: E501 + return self.test_inline_additional_properties_with_http_info(request_body, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_inline_additional_properties_with_http_info(request_body, **kwargs) # noqa: E501 + (data) = self.test_inline_additional_properties_with_http_info(request_body, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_inline_additional_properties_with_http_info(self, request_body, **kwargs): # noqa: E501 + def test_inline_additional_properties_with_http_info(self, request_body, _check_type=False, **kwargs): # noqa: E501 """test inline additionalProperties # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -1261,7 +1405,7 @@ def test_inline_additional_properties_with_http_info(self, request_body, **kwarg >>> result = thread.get() :param async_req bool - :param dict(str, str) request_body: request body (required) + :param {str: (str,)} request_body: request body (required) :return: None If the method is called asynchronously, returns the request thread. @@ -1277,16 +1421,26 @@ def test_inline_additional_properties_with_http_info(self, request_body, **kwarg for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_inline_additional_properties" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'request_body': [{str: (str,)}], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'request_body' is set if ('request_body' not in local_var_params or local_var_params['request_body'] is None): - raise ValueError("Missing the required parameter `request_body` when calling `test_inline_additional_properties`") # noqa: E501 + raise ApiValueError("Missing the required parameter `request_body` when calling `test_inline_additional_properties`") # noqa: E501 collection_formats = {} @@ -1317,7 +1471,7 @@ def test_inline_additional_properties_with_http_info(self, request_body, **kwarg body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1325,7 +1479,7 @@ def test_inline_additional_properties_with_http_info(self, request_body, **kwarg _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def test_json_form_data(self, param, param2, **kwargs): # noqa: E501 + def test_json_form_data(self, param, param2, _check_type=False, **kwargs): # noqa: E501 """test json serialization of form data # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -1342,12 +1496,12 @@ def test_json_form_data(self, param, param2, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_json_form_data_with_http_info(param, param2, **kwargs) # noqa: E501 + return self.test_json_form_data_with_http_info(param, param2, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_json_form_data_with_http_info(param, param2, **kwargs) # noqa: E501 + (data) = self.test_json_form_data_with_http_info(param, param2, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa: E501 + def test_json_form_data_with_http_info(self, param, param2, _check_type=False, **kwargs): # noqa: E501 """test json serialization of form data # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -1373,20 +1527,31 @@ def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa: for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_json_form_data" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'param': [str], + 'param2': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'param' is set if ('param' not in local_var_params or local_var_params['param'] is None): - raise ValueError("Missing the required parameter `param` when calling `test_json_form_data`") # noqa: E501 + raise ApiValueError("Missing the required parameter `param` when calling `test_json_form_data`") # noqa: E501 # verify the required parameter 'param2' is set if ('param2' not in local_var_params or local_var_params['param2'] is None): - raise ValueError("Missing the required parameter `param2` when calling `test_json_form_data`") # noqa: E501 + raise ApiValueError("Missing the required parameter `param2` when calling `test_json_form_data`") # noqa: E501 collection_formats = {} @@ -1419,7 +1584,7 @@ def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/fake_classname_tags_123_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/fake_classname_tags_123_api.py index 80e03e6626ee..d29126b2035f 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api/fake_classname_tags_123_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/fake_classname_tags_123_api.py @@ -18,6 +18,20 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.client import Client class FakeClassnameTags123Api(object): @@ -32,7 +46,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def test_classname(self, client, **kwargs): # noqa: E501 + def test_classname(self, client, _check_type=False, **kwargs): # noqa: E501 """To test class name in snake case # noqa: E501 To test class name in snake case # noqa: E501 @@ -49,12 +63,12 @@ def test_classname(self, client, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.test_classname_with_http_info(client, **kwargs) # noqa: E501 + return self.test_classname_with_http_info(client, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.test_classname_with_http_info(client, **kwargs) # noqa: E501 + (data) = self.test_classname_with_http_info(client, _check_type=_check_type, **kwargs) # noqa: E501 return data - def test_classname_with_http_info(self, client, **kwargs): # noqa: E501 + def test_classname_with_http_info(self, client, _check_type=False, **kwargs): # noqa: E501 """To test class name in snake case # noqa: E501 To test class name in snake case # noqa: E501 @@ -80,16 +94,26 @@ def test_classname_with_http_info(self, client, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method test_classname" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'client': [Client], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'client' is set if ('client' not in local_var_params or local_var_params['client'] is None): - raise ValueError("Missing the required parameter `client` when calling `test_classname`") # noqa: E501 + raise ApiValueError("Missing the required parameter `client` when calling `test_classname`") # noqa: E501 collection_formats = {} @@ -124,7 +148,7 @@ def test_classname_with_http_info(self, client, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types_mixed=[Client], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/pet_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/pet_api.py index 401ebb237209..152527958630 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api/pet_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/pet_api.py @@ -18,6 +18,21 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.api_response import ApiResponse +from petstore_api.models.pet import Pet class PetApi(object): @@ -32,7 +47,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def add_pet(self, pet, **kwargs): # noqa: E501 + def add_pet(self, pet, _check_type=False, **kwargs): # noqa: E501 """Add a new pet to the store # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -48,12 +63,12 @@ def add_pet(self, pet, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.add_pet_with_http_info(pet, **kwargs) # noqa: E501 + return self.add_pet_with_http_info(pet, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.add_pet_with_http_info(pet, **kwargs) # noqa: E501 + (data) = self.add_pet_with_http_info(pet, _check_type=_check_type, **kwargs) # noqa: E501 return data - def add_pet_with_http_info(self, pet, **kwargs): # noqa: E501 + def add_pet_with_http_info(self, pet, _check_type=False, **kwargs): # noqa: E501 """Add a new pet to the store # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -68,13 +83,17 @@ def add_pet_with_http_info(self, pet, **kwargs): # noqa: E501 returns the request thread. """ + local_var_params = locals() local_var_hosts = ['http://petstore.swagger.io/v2', 'http://path-server-test.petstore.local/v2'] # noqa: E501 local_var_host = local_var_hosts[0] - if kwargs.get('_host_index'): - if int(kwags.get('_host_index')) < 0 or int(kawgs.get('_host_index')) >= len(local_var_hosts): - raise ValueError("Invalid host index. Must be 0 <= index < %s" % len(local_var_host)) - local_var_host = local_var_hosts[int(kwargs.get('_host_index'))] - local_var_params = locals() + _host_index = kwargs.get('_host_index') + if _host_index: + if (int(_host_index) < 0 or + int(_host_index) >= len(local_var_hosts)): + raise ApiValueError( + "Invalid host index. Must be 0 <= index < %s" % + len(local_var_host)) + local_var_host = local_var_hosts[int(_host_index)] all_params = ['pet'] # noqa: E501 all_params.append('async_req') @@ -84,16 +103,26 @@ def add_pet_with_http_info(self, pet, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params and key != "_host_index": - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method add_pet" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet': [Pet], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet' is set if ('pet' not in local_var_params or local_var_params['pet'] is None): - raise ValueError("Missing the required parameter `pet` when calling `add_pet`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet` when calling `add_pet`") # noqa: E501 collection_formats = {} @@ -124,7 +153,7 @@ def add_pet_with_http_info(self, pet, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -133,7 +162,7 @@ def add_pet_with_http_info(self, pet, **kwargs): # noqa: E501 _host=local_var_host, collection_formats=collection_formats) - def delete_pet(self, pet_id, **kwargs): # noqa: E501 + def delete_pet(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Deletes a pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -150,12 +179,12 @@ def delete_pet(self, pet_id, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.delete_pet_with_http_info(pet_id, **kwargs) # noqa: E501 + return self.delete_pet_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.delete_pet_with_http_info(pet_id, **kwargs) # noqa: E501 + (data) = self.delete_pet_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 + def delete_pet_with_http_info(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Deletes a pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -181,16 +210,27 @@ def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method delete_pet" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet_id': [int], + 'api_key': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet_id' is set if ('pet_id' not in local_var_params or local_var_params['pet_id'] is None): - raise ValueError("Missing the required parameter `pet_id` when calling `delete_pet`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet_id` when calling `delete_pet`") # noqa: E501 collection_formats = {} @@ -219,7 +259,7 @@ def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -227,7 +267,7 @@ def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def find_pets_by_status(self, status, **kwargs): # noqa: E501 + def find_pets_by_status(self, status, _check_type=False, **kwargs): # noqa: E501 """Finds Pets by status # noqa: E501 Multiple status values can be provided with comma separated strings # noqa: E501 @@ -237,19 +277,19 @@ def find_pets_by_status(self, status, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] status: Status values that need to be considered for filter (required) - :return: list[Pet] + :param [(str,)] status: Status values that need to be considered for filter (required) + :return: [(Pet,)] If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.find_pets_by_status_with_http_info(status, **kwargs) # noqa: E501 + return self.find_pets_by_status_with_http_info(status, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.find_pets_by_status_with_http_info(status, **kwargs) # noqa: E501 + (data) = self.find_pets_by_status_with_http_info(status, _check_type=_check_type, **kwargs) # noqa: E501 return data - def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 + def find_pets_by_status_with_http_info(self, status, _check_type=False, **kwargs): # noqa: E501 """Finds Pets by status # noqa: E501 Multiple status values can be provided with comma separated strings # noqa: E501 @@ -259,8 +299,8 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] status: Status values that need to be considered for filter (required) - :return: list[Pet] + :param [(str,)] status: Status values that need to be considered for filter (required) + :return: [(Pet,)] If the method is called asynchronously, returns the request thread. """ @@ -275,16 +315,26 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method find_pets_by_status" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'status': [[(str,)]], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'status' is set if ('status' not in local_var_params or local_var_params['status'] is None): - raise ValueError("Missing the required parameter `status` when calling `find_pets_by_status`") # noqa: E501 + raise ApiValueError("Missing the required parameter `status` when calling `find_pets_by_status`") # noqa: E501 collection_formats = {} @@ -316,7 +366,7 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='list[Pet]', # noqa: E501 + response_types_mixed=[[(Pet,)]], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -324,7 +374,7 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def find_pets_by_tags(self, tags, **kwargs): # noqa: E501 + def find_pets_by_tags(self, tags, _check_type=False, **kwargs): # noqa: E501 """Finds Pets by tags # noqa: E501 Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. # noqa: E501 @@ -334,19 +384,19 @@ def find_pets_by_tags(self, tags, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] tags: Tags to filter by (required) - :return: list[Pet] + :param [(str,)] tags: Tags to filter by (required) + :return: [(Pet,)] If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.find_pets_by_tags_with_http_info(tags, **kwargs) # noqa: E501 + return self.find_pets_by_tags_with_http_info(tags, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.find_pets_by_tags_with_http_info(tags, **kwargs) # noqa: E501 + (data) = self.find_pets_by_tags_with_http_info(tags, _check_type=_check_type, **kwargs) # noqa: E501 return data - def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 + def find_pets_by_tags_with_http_info(self, tags, _check_type=False, **kwargs): # noqa: E501 """Finds Pets by tags # noqa: E501 Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. # noqa: E501 @@ -356,8 +406,8 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[str] tags: Tags to filter by (required) - :return: list[Pet] + :param [(str,)] tags: Tags to filter by (required) + :return: [(Pet,)] If the method is called asynchronously, returns the request thread. """ @@ -372,16 +422,26 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method find_pets_by_tags" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'tags': [[(str,)]], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'tags' is set if ('tags' not in local_var_params or local_var_params['tags'] is None): - raise ValueError("Missing the required parameter `tags` when calling `find_pets_by_tags`") # noqa: E501 + raise ApiValueError("Missing the required parameter `tags` when calling `find_pets_by_tags`") # noqa: E501 collection_formats = {} @@ -413,7 +473,7 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='list[Pet]', # noqa: E501 + response_types_mixed=[[(Pet,)]], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -421,7 +481,7 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def get_pet_by_id(self, pet_id, **kwargs): # noqa: E501 + def get_pet_by_id(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Find pet by ID # noqa: E501 Returns a single pet # noqa: E501 @@ -438,12 +498,12 @@ def get_pet_by_id(self, pet_id, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.get_pet_by_id_with_http_info(pet_id, **kwargs) # noqa: E501 + return self.get_pet_by_id_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.get_pet_by_id_with_http_info(pet_id, **kwargs) # noqa: E501 + (data) = self.get_pet_by_id_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 + def get_pet_by_id_with_http_info(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Find pet by ID # noqa: E501 Returns a single pet # noqa: E501 @@ -469,16 +529,26 @@ def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method get_pet_by_id" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet_id': [int], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet_id' is set if ('pet_id' not in local_var_params or local_var_params['pet_id'] is None): - raise ValueError("Missing the required parameter `pet_id` when calling `get_pet_by_id`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet_id` when calling `get_pet_by_id`") # noqa: E501 collection_formats = {} @@ -509,7 +579,7 @@ def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Pet', # noqa: E501 + response_types_mixed=[Pet], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -517,7 +587,7 @@ def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def update_pet(self, pet, **kwargs): # noqa: E501 + def update_pet(self, pet, _check_type=False, **kwargs): # noqa: E501 """Update an existing pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -533,12 +603,12 @@ def update_pet(self, pet, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.update_pet_with_http_info(pet, **kwargs) # noqa: E501 + return self.update_pet_with_http_info(pet, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.update_pet_with_http_info(pet, **kwargs) # noqa: E501 + (data) = self.update_pet_with_http_info(pet, _check_type=_check_type, **kwargs) # noqa: E501 return data - def update_pet_with_http_info(self, pet, **kwargs): # noqa: E501 + def update_pet_with_http_info(self, pet, _check_type=False, **kwargs): # noqa: E501 """Update an existing pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -553,13 +623,17 @@ def update_pet_with_http_info(self, pet, **kwargs): # noqa: E501 returns the request thread. """ + local_var_params = locals() local_var_hosts = ['http://petstore.swagger.io/v2', 'http://path-server-test.petstore.local/v2'] # noqa: E501 local_var_host = local_var_hosts[0] - if kwargs.get('_host_index'): - if int(kwags.get('_host_index')) < 0 or int(kawgs.get('_host_index')) >= len(local_var_hosts): - raise ValueError("Invalid host index. Must be 0 <= index < %s" % len(local_var_host)) - local_var_host = local_var_hosts[int(kwargs.get('_host_index'))] - local_var_params = locals() + _host_index = kwargs.get('_host_index') + if _host_index: + if (int(_host_index) < 0 or + int(_host_index) >= len(local_var_hosts)): + raise ApiValueError( + "Invalid host index. Must be 0 <= index < %s" % + len(local_var_host)) + local_var_host = local_var_hosts[int(_host_index)] all_params = ['pet'] # noqa: E501 all_params.append('async_req') @@ -569,16 +643,26 @@ def update_pet_with_http_info(self, pet, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params and key != "_host_index": - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method update_pet" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet': [Pet], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet' is set if ('pet' not in local_var_params or local_var_params['pet'] is None): - raise ValueError("Missing the required parameter `pet` when calling `update_pet`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet` when calling `update_pet`") # noqa: E501 collection_formats = {} @@ -609,7 +693,7 @@ def update_pet_with_http_info(self, pet, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -618,7 +702,7 @@ def update_pet_with_http_info(self, pet, **kwargs): # noqa: E501 _host=local_var_host, collection_formats=collection_formats) - def update_pet_with_form(self, pet_id, **kwargs): # noqa: E501 + def update_pet_with_form(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Updates a pet in the store with form data # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -636,12 +720,12 @@ def update_pet_with_form(self, pet_id, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.update_pet_with_form_with_http_info(pet_id, **kwargs) # noqa: E501 + return self.update_pet_with_form_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.update_pet_with_form_with_http_info(pet_id, **kwargs) # noqa: E501 + (data) = self.update_pet_with_form_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 + def update_pet_with_form_with_http_info(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """Updates a pet in the store with form data # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -668,16 +752,28 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method update_pet_with_form" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet_id': [int], + 'name': [str], + 'status': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet_id' is set if ('pet_id' not in local_var_params or local_var_params['pet_id'] is None): - raise ValueError("Missing the required parameter `pet_id` when calling `update_pet_with_form`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet_id` when calling `update_pet_with_form`") # noqa: E501 collection_formats = {} @@ -712,7 +808,7 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -720,7 +816,7 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def upload_file(self, pet_id, **kwargs): # noqa: E501 + def upload_file(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """uploads an image # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -731,19 +827,19 @@ def upload_file(self, pet_id, **kwargs): # noqa: E501 :param async_req bool :param int pet_id: ID of pet to update (required) :param str additional_metadata: Additional data to pass to server - :param file file: file to upload + :param file_type file: file to upload :return: ApiResponse If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.upload_file_with_http_info(pet_id, **kwargs) # noqa: E501 + return self.upload_file_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.upload_file_with_http_info(pet_id, **kwargs) # noqa: E501 + (data) = self.upload_file_with_http_info(pet_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 + def upload_file_with_http_info(self, pet_id, _check_type=False, **kwargs): # noqa: E501 """uploads an image # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -754,7 +850,7 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 :param async_req bool :param int pet_id: ID of pet to update (required) :param str additional_metadata: Additional data to pass to server - :param file file: file to upload + :param file_type file: file to upload :return: ApiResponse If the method is called asynchronously, returns the request thread. @@ -770,16 +866,28 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method upload_file" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet_id': [int], + 'additional_metadata': [str], + 'file': [file_type], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet_id' is set if ('pet_id' not in local_var_params or local_var_params['pet_id'] is None): - raise ValueError("Missing the required parameter `pet_id` when calling `upload_file`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet_id` when calling `upload_file`") # noqa: E501 collection_formats = {} @@ -818,7 +926,7 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='ApiResponse', # noqa: E501 + response_types_mixed=[ApiResponse], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -826,7 +934,7 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def upload_file_with_required_file(self, pet_id, required_file, **kwargs): # noqa: E501 + def upload_file_with_required_file(self, pet_id, required_file, _check_type=False, **kwargs): # noqa: E501 """uploads an image (required) # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -836,7 +944,7 @@ def upload_file_with_required_file(self, pet_id, required_file, **kwargs): # no :param async_req bool :param int pet_id: ID of pet to update (required) - :param file required_file: file to upload (required) + :param file_type required_file: file to upload (required) :param str additional_metadata: Additional data to pass to server :return: ApiResponse If the method is called asynchronously, @@ -844,12 +952,12 @@ def upload_file_with_required_file(self, pet_id, required_file, **kwargs): # no """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.upload_file_with_required_file_with_http_info(pet_id, required_file, **kwargs) # noqa: E501 + return self.upload_file_with_required_file_with_http_info(pet_id, required_file, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.upload_file_with_required_file_with_http_info(pet_id, required_file, **kwargs) # noqa: E501 + (data) = self.upload_file_with_required_file_with_http_info(pet_id, required_file, _check_type=_check_type, **kwargs) # noqa: E501 return data - def upload_file_with_required_file_with_http_info(self, pet_id, required_file, **kwargs): # noqa: E501 + def upload_file_with_required_file_with_http_info(self, pet_id, required_file, _check_type=False, **kwargs): # noqa: E501 """uploads an image (required) # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -859,7 +967,7 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, * :param async_req bool :param int pet_id: ID of pet to update (required) - :param file required_file: file to upload (required) + :param file_type required_file: file to upload (required) :param str additional_metadata: Additional data to pass to server :return: ApiResponse If the method is called asynchronously, @@ -876,20 +984,32 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, * for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method upload_file_with_required_file" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'pet_id': [int], + 'required_file': [file_type], + 'additional_metadata': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'pet_id' is set if ('pet_id' not in local_var_params or local_var_params['pet_id'] is None): - raise ValueError("Missing the required parameter `pet_id` when calling `upload_file_with_required_file`") # noqa: E501 + raise ApiValueError("Missing the required parameter `pet_id` when calling `upload_file_with_required_file`") # noqa: E501 # verify the required parameter 'required_file' is set if ('required_file' not in local_var_params or local_var_params['required_file'] is None): - raise ValueError("Missing the required parameter `required_file` when calling `upload_file_with_required_file`") # noqa: E501 + raise ApiValueError("Missing the required parameter `required_file` when calling `upload_file_with_required_file`") # noqa: E501 collection_formats = {} @@ -928,7 +1048,7 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, * body=body_params, post_params=form_params, files=local_var_files, - response_type='ApiResponse', # noqa: E501 + response_types_mixed=[ApiResponse], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/store_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/store_api.py index 5ef48fac2a78..226121683d51 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api/store_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/store_api.py @@ -18,6 +18,20 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.order import Order class StoreApi(object): @@ -32,7 +46,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def delete_order(self, order_id, **kwargs): # noqa: E501 + def delete_order(self, order_id, _check_type=False, **kwargs): # noqa: E501 """Delete purchase order by ID # noqa: E501 For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors # noqa: E501 @@ -49,12 +63,12 @@ def delete_order(self, order_id, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.delete_order_with_http_info(order_id, **kwargs) # noqa: E501 + return self.delete_order_with_http_info(order_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.delete_order_with_http_info(order_id, **kwargs) # noqa: E501 + (data) = self.delete_order_with_http_info(order_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 + def delete_order_with_http_info(self, order_id, _check_type=False, **kwargs): # noqa: E501 """Delete purchase order by ID # noqa: E501 For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors # noqa: E501 @@ -80,16 +94,26 @@ def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method delete_order" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'order_id': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'order_id' is set if ('order_id' not in local_var_params or local_var_params['order_id'] is None): - raise ValueError("Missing the required parameter `order_id` when calling `delete_order`") # noqa: E501 + raise ApiValueError("Missing the required parameter `order_id` when calling `delete_order`") # noqa: E501 collection_formats = {} @@ -116,7 +140,7 @@ def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -124,7 +148,7 @@ def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def get_inventory(self, **kwargs): # noqa: E501 + def get_inventory(self, _check_type=False, **kwargs): # noqa: E501 """Returns pet inventories by status # noqa: E501 Returns a map of status codes to quantities # noqa: E501 @@ -134,18 +158,18 @@ def get_inventory(self, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :return: dict(str, int) + :return: {str: (int,)} If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.get_inventory_with_http_info(**kwargs) # noqa: E501 + return self.get_inventory_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.get_inventory_with_http_info(**kwargs) # noqa: E501 + (data) = self.get_inventory_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def get_inventory_with_http_info(self, **kwargs): # noqa: E501 + def get_inventory_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """Returns pet inventories by status # noqa: E501 Returns a map of status codes to quantities # noqa: E501 @@ -155,7 +179,7 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :return: dict(str, int) + :return: {str: (int,)} If the method is called asynchronously, returns the request thread. """ @@ -170,7 +194,7 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method get_inventory" % key ) @@ -204,7 +228,7 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='dict(str, int)', # noqa: E501 + response_types_mixed=[{str: (int,)}], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -212,7 +236,7 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def get_order_by_id(self, order_id, **kwargs): # noqa: E501 + def get_order_by_id(self, order_id, _check_type=False, **kwargs): # noqa: E501 """Find purchase order by ID # noqa: E501 For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions # noqa: E501 @@ -229,12 +253,12 @@ def get_order_by_id(self, order_id, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.get_order_by_id_with_http_info(order_id, **kwargs) # noqa: E501 + return self.get_order_by_id_with_http_info(order_id, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.get_order_by_id_with_http_info(order_id, **kwargs) # noqa: E501 + (data) = self.get_order_by_id_with_http_info(order_id, _check_type=_check_type, **kwargs) # noqa: E501 return data - def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 + def get_order_by_id_with_http_info(self, order_id, _check_type=False, **kwargs): # noqa: E501 """Find purchase order by ID # noqa: E501 For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions # noqa: E501 @@ -260,21 +284,31 @@ def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method get_order_by_id" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'order_id': [int], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'order_id' is set if ('order_id' not in local_var_params or local_var_params['order_id'] is None): - raise ValueError("Missing the required parameter `order_id` when calling `get_order_by_id`") # noqa: E501 + raise ApiValueError("Missing the required parameter `order_id` when calling `get_order_by_id`") # noqa: E501 if 'order_id' in local_var_params and local_var_params['order_id'] > 5: # noqa: E501 - raise ValueError("Invalid value for parameter `order_id` when calling `get_order_by_id`, must be a value less than or equal to `5`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `order_id` when calling `get_order_by_id`, must be a value less than or equal to `5`") # noqa: E501 if 'order_id' in local_var_params and local_var_params['order_id'] < 1: # noqa: E501 - raise ValueError("Invalid value for parameter `order_id` when calling `get_order_by_id`, must be a value greater than or equal to `1`") # noqa: E501 + raise ApiValueError("Invalid value for parameter `order_id` when calling `get_order_by_id`, must be a value greater than or equal to `1`") # noqa: E501 collection_formats = {} path_params = {} @@ -304,7 +338,7 @@ def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Order', # noqa: E501 + response_types_mixed=[Order], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -312,7 +346,7 @@ def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def place_order(self, order, **kwargs): # noqa: E501 + def place_order(self, order, _check_type=False, **kwargs): # noqa: E501 """Place an order for a pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -328,12 +362,12 @@ def place_order(self, order, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.place_order_with_http_info(order, **kwargs) # noqa: E501 + return self.place_order_with_http_info(order, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.place_order_with_http_info(order, **kwargs) # noqa: E501 + (data) = self.place_order_with_http_info(order, _check_type=_check_type, **kwargs) # noqa: E501 return data - def place_order_with_http_info(self, order, **kwargs): # noqa: E501 + def place_order_with_http_info(self, order, _check_type=False, **kwargs): # noqa: E501 """Place an order for a pet # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -358,16 +392,26 @@ def place_order_with_http_info(self, order, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method place_order" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'order': [Order], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'order' is set if ('order' not in local_var_params or local_var_params['order'] is None): - raise ValueError("Missing the required parameter `order` when calling `place_order`") # noqa: E501 + raise ApiValueError("Missing the required parameter `order` when calling `place_order`") # noqa: E501 collection_formats = {} @@ -402,7 +446,7 @@ def place_order_with_http_info(self, order, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Order', # noqa: E501 + response_types_mixed=[Order], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/user_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/user_api.py index bb02a2a472cb..851dfec08233 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api/user_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/user_api.py @@ -18,6 +18,20 @@ import six from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.models.user import User class UserApi(object): @@ -32,7 +46,7 @@ def __init__(self, api_client=None): api_client = ApiClient() self.api_client = api_client - def create_user(self, user, **kwargs): # noqa: E501 + def create_user(self, user, _check_type=False, **kwargs): # noqa: E501 """Create user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -49,12 +63,12 @@ def create_user(self, user, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.create_user_with_http_info(user, **kwargs) # noqa: E501 + return self.create_user_with_http_info(user, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.create_user_with_http_info(user, **kwargs) # noqa: E501 + (data) = self.create_user_with_http_info(user, _check_type=_check_type, **kwargs) # noqa: E501 return data - def create_user_with_http_info(self, user, **kwargs): # noqa: E501 + def create_user_with_http_info(self, user, _check_type=False, **kwargs): # noqa: E501 """Create user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -80,16 +94,26 @@ def create_user_with_http_info(self, user, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method create_user" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'user': [User], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'user' is set if ('user' not in local_var_params or local_var_params['user'] is None): - raise ValueError("Missing the required parameter `user` when calling `create_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `user` when calling `create_user`") # noqa: E501 collection_formats = {} @@ -120,7 +144,7 @@ def create_user_with_http_info(self, user, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -128,7 +152,7 @@ def create_user_with_http_info(self, user, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def create_users_with_array_input(self, user, **kwargs): # noqa: E501 + def create_users_with_array_input(self, user, _check_type=False, **kwargs): # noqa: E501 """Creates list of users with given input array # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -137,19 +161,19 @@ def create_users_with_array_input(self, user, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[User] user: List of user object (required) + :param [(User,)] user: List of user object (required) :return: None If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.create_users_with_array_input_with_http_info(user, **kwargs) # noqa: E501 + return self.create_users_with_array_input_with_http_info(user, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.create_users_with_array_input_with_http_info(user, **kwargs) # noqa: E501 + (data) = self.create_users_with_array_input_with_http_info(user, _check_type=_check_type, **kwargs) # noqa: E501 return data - def create_users_with_array_input_with_http_info(self, user, **kwargs): # noqa: E501 + def create_users_with_array_input_with_http_info(self, user, _check_type=False, **kwargs): # noqa: E501 """Creates list of users with given input array # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -158,7 +182,7 @@ def create_users_with_array_input_with_http_info(self, user, **kwargs): # noqa: >>> result = thread.get() :param async_req bool - :param list[User] user: List of user object (required) + :param [(User,)] user: List of user object (required) :return: None If the method is called asynchronously, returns the request thread. @@ -174,16 +198,26 @@ def create_users_with_array_input_with_http_info(self, user, **kwargs): # noqa: for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method create_users_with_array_input" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'user': [[(User,)]], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'user' is set if ('user' not in local_var_params or local_var_params['user'] is None): - raise ValueError("Missing the required parameter `user` when calling `create_users_with_array_input`") # noqa: E501 + raise ApiValueError("Missing the required parameter `user` when calling `create_users_with_array_input`") # noqa: E501 collection_formats = {} @@ -214,7 +248,7 @@ def create_users_with_array_input_with_http_info(self, user, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -222,7 +256,7 @@ def create_users_with_array_input_with_http_info(self, user, **kwargs): # noqa: _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def create_users_with_list_input(self, user, **kwargs): # noqa: E501 + def create_users_with_list_input(self, user, _check_type=False, **kwargs): # noqa: E501 """Creates list of users with given input array # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -231,19 +265,19 @@ def create_users_with_list_input(self, user, **kwargs): # noqa: E501 >>> result = thread.get() :param async_req bool - :param list[User] user: List of user object (required) + :param [(User,)] user: List of user object (required) :return: None If the method is called asynchronously, returns the request thread. """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.create_users_with_list_input_with_http_info(user, **kwargs) # noqa: E501 + return self.create_users_with_list_input_with_http_info(user, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.create_users_with_list_input_with_http_info(user, **kwargs) # noqa: E501 + (data) = self.create_users_with_list_input_with_http_info(user, _check_type=_check_type, **kwargs) # noqa: E501 return data - def create_users_with_list_input_with_http_info(self, user, **kwargs): # noqa: E501 + def create_users_with_list_input_with_http_info(self, user, _check_type=False, **kwargs): # noqa: E501 """Creates list of users with given input array # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -252,7 +286,7 @@ def create_users_with_list_input_with_http_info(self, user, **kwargs): # noqa: >>> result = thread.get() :param async_req bool - :param list[User] user: List of user object (required) + :param [(User,)] user: List of user object (required) :return: None If the method is called asynchronously, returns the request thread. @@ -268,16 +302,26 @@ def create_users_with_list_input_with_http_info(self, user, **kwargs): # noqa: for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method create_users_with_list_input" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'user': [[(User,)]], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'user' is set if ('user' not in local_var_params or local_var_params['user'] is None): - raise ValueError("Missing the required parameter `user` when calling `create_users_with_list_input`") # noqa: E501 + raise ApiValueError("Missing the required parameter `user` when calling `create_users_with_list_input`") # noqa: E501 collection_formats = {} @@ -308,7 +352,7 @@ def create_users_with_list_input_with_http_info(self, user, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -316,7 +360,7 @@ def create_users_with_list_input_with_http_info(self, user, **kwargs): # noqa: _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def delete_user(self, username, **kwargs): # noqa: E501 + def delete_user(self, username, _check_type=False, **kwargs): # noqa: E501 """Delete user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -333,12 +377,12 @@ def delete_user(self, username, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.delete_user_with_http_info(username, **kwargs) # noqa: E501 + return self.delete_user_with_http_info(username, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.delete_user_with_http_info(username, **kwargs) # noqa: E501 + (data) = self.delete_user_with_http_info(username, _check_type=_check_type, **kwargs) # noqa: E501 return data - def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 + def delete_user_with_http_info(self, username, _check_type=False, **kwargs): # noqa: E501 """Delete user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -364,16 +408,26 @@ def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method delete_user" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'username': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'username' is set if ('username' not in local_var_params or local_var_params['username'] is None): - raise ValueError("Missing the required parameter `username` when calling `delete_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `username` when calling `delete_user`") # noqa: E501 collection_formats = {} @@ -400,7 +454,7 @@ def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -408,7 +462,7 @@ def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def get_user_by_name(self, username, **kwargs): # noqa: E501 + def get_user_by_name(self, username, _check_type=False, **kwargs): # noqa: E501 """Get user by user name # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -424,12 +478,12 @@ def get_user_by_name(self, username, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.get_user_by_name_with_http_info(username, **kwargs) # noqa: E501 + return self.get_user_by_name_with_http_info(username, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.get_user_by_name_with_http_info(username, **kwargs) # noqa: E501 + (data) = self.get_user_by_name_with_http_info(username, _check_type=_check_type, **kwargs) # noqa: E501 return data - def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 + def get_user_by_name_with_http_info(self, username, _check_type=False, **kwargs): # noqa: E501 """Get user by user name # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -454,16 +508,26 @@ def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method get_user_by_name" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'username': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'username' is set if ('username' not in local_var_params or local_var_params['username'] is None): - raise ValueError("Missing the required parameter `username` when calling `get_user_by_name`") # noqa: E501 + raise ApiValueError("Missing the required parameter `username` when calling `get_user_by_name`") # noqa: E501 collection_formats = {} @@ -494,7 +558,7 @@ def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='User', # noqa: E501 + response_types_mixed=[User], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -502,7 +566,7 @@ def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def login_user(self, username, password, **kwargs): # noqa: E501 + def login_user(self, username, password, _check_type=False, **kwargs): # noqa: E501 """Logs user into the system # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -519,12 +583,12 @@ def login_user(self, username, password, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.login_user_with_http_info(username, password, **kwargs) # noqa: E501 + return self.login_user_with_http_info(username, password, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.login_user_with_http_info(username, password, **kwargs) # noqa: E501 + (data) = self.login_user_with_http_info(username, password, _check_type=_check_type, **kwargs) # noqa: E501 return data - def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 + def login_user_with_http_info(self, username, password, _check_type=False, **kwargs): # noqa: E501 """Logs user into the system # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -550,20 +614,31 @@ def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method login_user" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'username': [str], + 'password': [str], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'username' is set if ('username' not in local_var_params or local_var_params['username'] is None): - raise ValueError("Missing the required parameter `username` when calling `login_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `username` when calling `login_user`") # noqa: E501 # verify the required parameter 'password' is set if ('password' not in local_var_params or local_var_params['password'] is None): - raise ValueError("Missing the required parameter `password` when calling `login_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `password` when calling `login_user`") # noqa: E501 collection_formats = {} @@ -596,7 +671,7 @@ def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='str', # noqa: E501 + response_types_mixed=[str], # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -604,7 +679,7 @@ def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def logout_user(self, **kwargs): # noqa: E501 + def logout_user(self, _check_type=False, **kwargs): # noqa: E501 """Logs out current logged in user session # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -619,12 +694,12 @@ def logout_user(self, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.logout_user_with_http_info(**kwargs) # noqa: E501 + return self.logout_user_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.logout_user_with_http_info(**kwargs) # noqa: E501 + (data) = self.logout_user_with_http_info(_check_type=_check_type, **kwargs) # noqa: E501 return data - def logout_user_with_http_info(self, **kwargs): # noqa: E501 + def logout_user_with_http_info(self, _check_type=False, **kwargs): # noqa: E501 """Logs out current logged in user session # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -648,7 +723,7 @@ def logout_user_with_http_info(self, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method logout_user" % key ) @@ -678,7 +753,7 @@ def logout_user_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -686,7 +761,7 @@ def logout_user_with_http_info(self, **kwargs): # noqa: E501 _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats) - def update_user(self, username, user, **kwargs): # noqa: E501 + def update_user(self, username, user, _check_type=False, **kwargs): # noqa: E501 """Updated user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -704,12 +779,12 @@ def update_user(self, username, user, **kwargs): # noqa: E501 """ kwargs['_return_http_data_only'] = True if kwargs.get('async_req'): - return self.update_user_with_http_info(username, user, **kwargs) # noqa: E501 + return self.update_user_with_http_info(username, user, _check_type=_check_type, **kwargs) # noqa: E501 else: - (data) = self.update_user_with_http_info(username, user, **kwargs) # noqa: E501 + (data) = self.update_user_with_http_info(username, user, _check_type=_check_type, **kwargs) # noqa: E501 return data - def update_user_with_http_info(self, username, user, **kwargs): # noqa: E501 + def update_user_with_http_info(self, username, user, _check_type=False, **kwargs): # noqa: E501 """Updated user # noqa: E501 This can only be done by the logged in user. # noqa: E501 @@ -736,20 +811,31 @@ def update_user_with_http_info(self, username, user, **kwargs): # noqa: E501 for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: - raise TypeError( + raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method update_user" % key ) local_var_params[key] = val del local_var_params['kwargs'] + data_types_by_param = { + 'username': [str], + 'user': [User], + } + + if _check_type: + for param_name, param_value in six.iteritems(local_var_params): + required_types_mixed = data_types_by_param.get(param_name) + if required_type: + local_var_params[param_name] = validate_and_convert_types( + param_value, required_types_mixed, [param_name]) # verify the required parameter 'username' is set if ('username' not in local_var_params or local_var_params['username'] is None): - raise ValueError("Missing the required parameter `username` when calling `update_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `username` when calling `update_user`") # noqa: E501 # verify the required parameter 'user' is set if ('user' not in local_var_params or local_var_params['user'] is None): - raise ValueError("Missing the required parameter `user` when calling `update_user`") # noqa: E501 + raise ApiValueError("Missing the required parameter `user` when calling `update_user`") # noqa: E501 collection_formats = {} @@ -782,7 +868,7 @@ def update_user_with_http_info(self, username, user, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types_mixed=None, # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api_client.py b/samples/openapi3/client/petstore/python/petstore_api/api_client.py index a8f86aecf393..2be258b82b13 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api_client.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api_client.py @@ -10,7 +10,7 @@ from __future__ import absolute_import -import datetime +import copy import json import mimetypes from multiprocessing.pool import ThreadPool @@ -23,6 +23,22 @@ from six.moves.urllib.parse import quote from petstore_api.configuration import Configuration +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( + OpenApiModel, + date, + datetime, + deserialize_file, + file_type, + model_to_dict, + none_type, + str, + validate_and_convert_types +) import petstore_api.models from petstore_api import rest @@ -49,17 +65,11 @@ class ApiClient(object): to the API. More threads means more concurrent API requests. """ - PRIMITIVE_TYPES = (float, bool, bytes, six.text_type) + six.integer_types - NATIVE_TYPES_MAPPING = { - 'int': int, - 'long': int if six.PY3 else long, # noqa: F821 - 'float': float, - 'str': str, - 'bool': bool, - 'date': datetime.date, - 'datetime': datetime.datetime, - 'object': object, - } + # six.binary_type python2=str, python3=bytes + # six.text_type python2=unicode, python3=str + PRIMITIVE_TYPES = ( + (float, bool, six.binary_type, six.text_type) + six.integer_types + ) _pool = None def __init__(self, configuration=None, header_name=None, header_value=None, @@ -107,7 +117,7 @@ def set_default_header(self, header_name, header_value): def __call_api( self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, - files=None, response_type=None, auth_settings=None, + files=None, response_types_mixed=None, auth_settings=None, _return_http_data_only=None, collection_formats=None, _preload_content=True, _request_timeout=None, _host=None): @@ -174,8 +184,9 @@ def __call_api( return_data = response_data if _preload_content: # deserialize response data - if response_type: - return_data = self.deserialize(response_data, response_type) + if response_types_mixed: + return_data = self.deserialize(response_data, + response_types_mixed) else: return_data = None @@ -209,89 +220,59 @@ def sanitize_for_serialization(self, obj): elif isinstance(obj, tuple): return tuple(self.sanitize_for_serialization(sub_obj) for sub_obj in obj) - elif isinstance(obj, (datetime.datetime, datetime.date)): + elif isinstance(obj, (datetime, date)): return obj.isoformat() if isinstance(obj, dict): obj_dict = obj else: - # Convert model obj to dict except - # attributes `openapi_types`, `attribute_map` - # and attributes which value is not None. + # Convert model obj to dict # Convert attribute name to json key in # model definition for request. - obj_dict = {obj.attribute_map[attr]: getattr(obj, attr) - for attr, _ in six.iteritems(obj.openapi_types) - if getattr(obj, attr) is not None} + obj_dict = model_to_dict(obj, serialize=True) return {key: self.sanitize_for_serialization(val) for key, val in six.iteritems(obj_dict)} - def deserialize(self, response, response_type): + def deserialize(self, response, response_types_mixed): """Deserializes response into an object. :param response: RESTResponse object to be deserialized. - :param response_type: class literal for - deserialized object, or string of class name. + :param response_types_mixed: For the response, a list of + valid classes, or a list tuples of valid classes, or a dict where + the value is a tuple of value classes. :return: deserialized object. """ # handle file downloading # save response body into a tmp file and return the instance - if response_type == "file": - return self.__deserialize_file(response) + if response_types_mixed == [file_type]: + content_disposition = response.getheader("Content-Disposition") + return deserialize_file(response.data, self.configuration, + content_disposition=content_disposition) # fetch data from response object try: - data = json.loads(response.data) + received_data = json.loads(response.data) except ValueError: - data = response.data + # this path is used if we are deserializing string data + received_data = response.data - return self.__deserialize(data, response_type) + # store our data under the key of 'received_data' so users have some + # context if they are deserializing a string and the data type is wrong + deserialized_data = validate_and_convert_types( + received_data, + response_types_mixed, + ['received_data'], + configuration=self.configuration + ) + return deserialized_data - def __deserialize(self, data, klass): - """Deserializes dict, list, str into an object. - - :param data: dict, list or str. - :param klass: class literal, or string of class name. - - :return: object. - """ - if data is None: - return None - - if type(klass) == str: - if klass.startswith('list['): - sub_kls = re.match(r'list\[(.*)\]', klass).group(1) - return [self.__deserialize(sub_data, sub_kls) - for sub_data in data] - - if klass.startswith('dict('): - sub_kls = re.match(r'dict\(([^,]*), (.*)\)', klass).group(2) - return {k: self.__deserialize(v, sub_kls) - for k, v in six.iteritems(data)} - - # convert str to class - if klass in self.NATIVE_TYPES_MAPPING: - klass = self.NATIVE_TYPES_MAPPING[klass] - else: - klass = getattr(petstore_api.models, klass) - - if klass in self.PRIMITIVE_TYPES: - return self.__deserialize_primitive(data, klass) - elif klass == object: - return self.__deserialize_object(data) - elif klass == datetime.date: - return self.__deserialize_date(data) - elif klass == datetime.datetime: - return self.__deserialize_datatime(data) - else: - return self.__deserialize_model(data, klass) def call_api(self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, files=None, - response_type=None, auth_settings=None, async_req=None, + response_types_mixed=None, auth_settings=None, async_req=None, _return_http_data_only=None, collection_formats=None, _preload_content=True, _request_timeout=None, _host=None): """Makes the HTTP request (synchronous) and returns deserialized data. @@ -308,7 +289,15 @@ def call_api(self, resource_path, method, :param post_params dict: Request post form parameters, for `application/x-www-form-urlencoded`, `multipart/form-data`. :param auth_settings list: Auth Settings names for the request. - :param response: Response data type. + :param response_types_mixed: For the response, a list of + valid classes, or a list tuples of valid classes, or a dict where + the value is a tuple of value classes. + Example values: + [str] + [Pet] + [float, none_type], + [[(int, none_type)]], + [{str: (bool, str, int, float, date, datetime, str, none_type)}] :param files dict: key -> filename, value -> filepath, for `multipart/form-data`. :param async_req bool: execute request asynchronously @@ -334,7 +323,7 @@ def call_api(self, resource_path, method, return self.__call_api(resource_path, method, path_params, query_params, header_params, body, post_params, files, - response_type, auth_settings, + response_types_mixed, auth_settings, _return_http_data_only, collection_formats, _preload_content, _request_timeout, _host) else: @@ -342,7 +331,7 @@ def call_api(self, resource_path, method, method, path_params, query_params, header_params, body, post_params, files, - response_type, auth_settings, + response_types_mixed, auth_settings, _return_http_data_only, collection_formats, _preload_content, @@ -406,7 +395,7 @@ def request(self, method, url, query_params=None, headers=None, _request_timeout=_request_timeout, body=body) else: - raise ValueError( + raise ApiValueError( "http method must be `GET`, `HEAD`, `OPTIONS`," " `POST`, `PATCH`, `PUT` or `DELETE`." ) @@ -521,120 +510,6 @@ def update_params_for_auth(self, headers, querys, auth_settings): elif auth_setting['in'] == 'query': querys.append((auth_setting['key'], auth_setting['value'])) else: - raise ValueError( + raise ApiValueError( 'Authentication token must be in `query` or `header`' ) - - def __deserialize_file(self, response): - """Deserializes body to file - - Saves response body into a file in a temporary folder, - using the filename from the `Content-Disposition` header if provided. - - :param response: RESTResponse. - :return: file path. - """ - fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path) - os.close(fd) - os.remove(path) - - content_disposition = response.getheader("Content-Disposition") - if content_disposition: - filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?', - content_disposition).group(1) - path = os.path.join(os.path.dirname(path), filename) - - with open(path, "wb") as f: - f.write(response.data) - - return path - - def __deserialize_primitive(self, data, klass): - """Deserializes string to primitive type. - - :param data: str. - :param klass: class literal. - - :return: int, long, float, str, bool. - """ - try: - return klass(data) - except UnicodeEncodeError: - return six.text_type(data) - except TypeError: - return data - - def __deserialize_object(self, value): - """Return an original value. - - :return: object. - """ - return value - - def __deserialize_date(self, string): - """Deserializes string to date. - - :param string: str. - :return: date. - """ - try: - from dateutil.parser import parse - return parse(string).date() - except ImportError: - return string - except ValueError: - raise rest.ApiException( - status=0, - reason="Failed to parse `{0}` as date object".format(string) - ) - - def __deserialize_datatime(self, string): - """Deserializes string to datetime. - - The string should be in iso8601 datetime format. - - :param string: str. - :return: datetime. - """ - try: - from dateutil.parser import parse - return parse(string) - except ImportError: - return string - except ValueError: - raise rest.ApiException( - status=0, - reason=( - "Failed to parse `{0}` as datetime object" - .format(string) - ) - ) - - def __deserialize_model(self, data, klass): - """Deserializes list or dict to model. - - :param data: dict, list. - :param klass: class literal. - :return: model object. - """ - - if not klass.openapi_types and not hasattr(klass, - 'get_real_child_model'): - return data - - kwargs = {} - if klass.openapi_types is not None: - for attr, attr_type in six.iteritems(klass.openapi_types): - if (data is not None and - klass.attribute_map[attr] in data and - isinstance(data, (list, dict))): - value = data[klass.attribute_map[attr]] - kwargs[attr] = self.__deserialize(value, attr_type) - - instance = klass(**kwargs) - - if hasattr(instance, 'get_real_child_model'): - klass_name = instance.get_real_child_model(data) - if klass_name: - instance = self.__deserialize(data, klass_name) - return instance diff --git a/samples/openapi3/client/petstore/python/petstore_api/exceptions.py b/samples/openapi3/client/petstore/python/petstore_api/exceptions.py new file mode 100644 index 000000000000..6bf34b3f9fa7 --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/exceptions.py @@ -0,0 +1,121 @@ +# 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: + is_int = isinstance(pth, int) + if six.PY2 and isinstance(pth, long) and is_int == False: + is_int = True + if is_int: + result += "[{0}]".format(pth) + else: + result += "['{0}']".format(pth) + return result diff --git a/samples/openapi3/client/petstore/python/petstore_api/model_utils.py b/samples/openapi3/client/petstore/python/petstore_api/model_utils.py new file mode 100644 index 000000000000..148a9cf683ea --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/model_utils.py @@ -0,0 +1,605 @@ +# 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 copy +from datetime import date, datetime # noqa: F401 +import os +import re +import tempfile + +from dateutil.parser import parse +import six + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) + +none_type = type(None) +if six.PY3: + import io + file_type = io.IOBase + # these are needed for when other modules import str and int from here + str = str + int = int +else: + file_type = file # noqa: F821 + str_py2 = str + unicode_py2 = unicode + long_py2 = long + int_py2 = int + # this requires that the future library is installed + from builtins import int, str + + +class OpenApiModel(object): + """The base class for all OpenAPIModels""" + + +def get_simple_class(input_value): + """Returns an input_value's simple class that we will use for type checking + Python2: + float and int will return int, where int is the python3 int backport + str and unicode will return str, where str is the python3 str backport + Note: float and int ARE both instances of int backport + Note: str_py2 and unicode_py2 are NOT both instances of str backport + + Args: + input_value (class/class_instance): the item for which we will return + the simple class + """ + if isinstance(input_value, type): + # input_value is a class + return input_value + elif isinstance(input_value, list): + return list + elif isinstance(input_value, dict): + return dict + elif isinstance(input_value, none_type): + return none_type + elif isinstance(input_value, file_type): + return file_type + elif isinstance(input_value, bool): + # this must be higher than the int check because + # isinstance(True, int) == True + return bool + elif isinstance(input_value, int): + # for python2 input_value==long_instance -> return int + # where int is the python3 int backport + return int + elif isinstance(input_value, datetime): + # this must be higher than the date check because + # isinstance(datetime_instance, date) == True + return datetime + elif isinstance(input_value, date): + return datetime + elif (six.PY2 and isinstance(input_value, (str_py2, unicode_py2, str)) or + isinstance(input_value, str)): + return str + return type(input_value) + + +COERCION_INDEX_BY_TYPE = { + none_type: 0, + list: 1, + OpenApiModel: 2, + dict: 3, + float: 4, + int: 5, + bool: 6, + datetime: 7, + date: 8, + str: 9 +} + +# these are used to limit what type conversions we try to do +# when we have a valid type already and we want to try converting +# to another type +UPCONVERSION_TYPE_PAIRS = ( + (str, datetime), + (str, date), + (list, OpenApiModel), + (dict, OpenApiModel), +) + +COERCIBLE_TYPE_PAIRS = ( + (dict, OpenApiModel), + (list, OpenApiModel), + (str, int), + (str, float), + (str, datetime), + (str, date), + (int, str), + (float, str), + (str, file_type) +) + + +def order_response_types(required_types): + """Returns the required types sorted in coercion order + + Args: + required_types (list/tuple): collection of classes or instance of + list or dict with classs information inside it + + Returns: + (list): coercion order sorted collection of classes or instance + of list or dict with classs information inside it + """ + + def index_getter(class_or_instance): + if isinstance(class_or_instance, list): + return COERCION_INDEX_BY_TYPE[list] + elif isinstance(class_or_instance, dict): + return COERCION_INDEX_BY_TYPE[dict] + elif issubclass(class_or_instance, OpenApiModel): + return COERCION_INDEX_BY_TYPE[OpenApiModel] + return COERCION_INDEX_BY_TYPE[class_or_instance] + + sorted_types = sorted( + required_types, + key=lambda class_or_instance: index_getter(class_or_instance) + ) + return sorted_types + + +def remove_uncoercible(required_types_classes, current_item, must_convert=True): + """Only keeps the type conversions that are possible + + Args: + required_types_classes (tuple): tuple of classes that are required + these should be ordered by COERCION_INDEX_BY_TYPE + current_item (any): the current item to be converted + + Keyword Args: + must_convert (bool): if True the item to convert is of the wrong + type and we want a big list of coercibles + if False, we want a limited list of coercibles + + Returns: + (list): the remaining coercible required types, classes only + """ + current_type_simple = get_simple_class(current_item) + + results_classes = [] + for required_type_class in required_types_classes: + # convert our models to OpenApiModel + required_type_class_simplified = required_type_class + if isinstance(required_type_class_simplified, type): + if issubclass(required_type_class_simplified, OpenApiModel): + required_type_class_simplified = OpenApiModel + + if required_type_class_simplified == current_type_simple: + # don't consider converting to one's own class + continue + + class_pair = (current_type_simple, required_type_class_simplified) + if must_convert and class_pair in COERCIBLE_TYPE_PAIRS: + results_classes.append(required_type_class) + elif class_pair in UPCONVERSION_TYPE_PAIRS: + results_classes.append(required_type_class) + return results_classes + + +def get_required_type_classes(required_types_mixed): + """Converts the tuple required_types into a tuple and a dict described + below + + Args: + required_types_mixed (tuple/list): will contain either classes or + instance of list or dict + + Returns: + (valid_classes, dict_valid_class_to_child_types_mixed): + valid_classes (tuple): the valid classes that the current item + should be + dict_valid_class_to_child_types_mixed (doct): + valid_class (class): this is the key + child_types_mixed (list/dict/tuple): describes the valid child + types + """ + valid_classes = [] + child_req_types_by_current_type = {} + for required_type in required_types_mixed: + if isinstance(required_type, list): + valid_classes.append(list) + child_req_types_by_current_type[list] = required_type[0] + elif isinstance(required_type, dict): + valid_classes.append(dict) + child_req_types_by_current_type[dict] = required_type[str] + else: + valid_classes.append(required_type) + return tuple(valid_classes), child_req_types_by_current_type + + +def change_keys_js_to_python(input_dict, model_class): + """ + Converts from javascript_key keys in the input_dict to python_keys in + the output dict using the mapping in model_class + """ + + output_dict = {} + reversed_attr_map = {value: key for key, value in + six.iteritems(model_class.attribute_map)} + for javascript_key, value in six.iteritems(input_dict): + python_key = reversed_attr_map.get(javascript_key) + if python_key is None: + # if the key is unknown, it is in error or it is an + # additionalProperties variable + python_key = javascript_key + output_dict[python_key] = value + return output_dict + + +def get_type_error(var_value, path_to_item, valid_classes, key_type=False): + error_msg = type_error_message( + var_name=path_to_item[-1], + var_value=var_value, + valid_classes=valid_classes, + key_type=key_type + ) + return ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=valid_classes, + key_type=key_type + ) + + +def deserialize_primitive(data, klass, path_to_item): + """Deserializes string to primitive type. + + :param data: str/int/float + :param klass: str/class the class to convert to + + :return: int, float, str, bool, date, datetime + """ + additional_message = "" + try: + if klass in {datetime, date}: + additional_message = ( + "If you need your parameter to have a fallback " + "string value, please set its type as `type: {}` in your " + "spec. That allows the value to be any type. " + ) + if klass == datetime: + if len(data) < 8: + raise ValueError("This is not a datetime") + # The string should be in iso8601 datetime format. + parsed_datetime = parse(data) + date_only = (parsed_datetime.hour == 0 and + parsed_datetime.minute == 0 and + parsed_datetime.second == 0 and + parsed_datetime.tzinfo == None and + 8 <= len(data) <= 10) + if date_only: + raise ValueError("This is a date, not a datetime") + return parsed_datetime + elif klass == date: + if len(data) < 8: + raise ValueError("This is not a date") + return parse(data).date() + else: + converted_value = klass(data) + if isinstance(data, str) and klass == float: + if str(converted_value) != data: + # '7' -> 7.0 -> '7.0' != '7' + raise ValueError('This is not a float') + return converted_value + except (OverflowError, ValueError): + # parse can raise OverflowError + raise ApiValueError( + "{0}Failed to parse {1} as {2}".format( + additional_message, repr(data), get_py3_class_name(klass) + ), + path_to_item=path_to_item + ) + + +def deserialize_model(model_data, model_class, path_to_item, configuration): + """Deserializes model_data to model instance. + + Args: + model_data (list/dict): data to instantiate the model + model_class (OpenApiModel): the model class + path_to_item (list): path to the model in the received data + configuration (Configuration): the instance to use to convert files + + Returns: + model instance + + Raise: + ApiTypeError + ApiValueError + ApiKeyError + """ + fixed_model_data = copy.deepcopy(model_data) + + if isinstance(fixed_model_data, dict): + fixed_model_data = change_keys_js_to_python(fixed_model_data, + model_class) + + kw_args = dict(_check_type=True, + _path_to_item=path_to_item, + _configuration=configuration) + if isinstance(model_data, list): + instance = model_class(*model_data, **kw_args) + elif isinstance(model_data, dict): + kw_args.update(fixed_model_data) + instance = model_class(**kw_args) + + if hasattr(instance, 'get_real_child_model'): + discriminator_class = instance.get_real_child_model(model_data) + if discriminator_class: + if isinstance(model_data, list): + instance = discriminator_class(*model_data, **kw_args) + elif isinstance(model_data, dict): + instance = discriminator_class(**kw_args) + + return instance + + +def deserialize_file(response_data, configuration, content_disposition=None): + """Deserializes body to file + + Saves response body into a file in a temporary folder, + using the filename from the `Content-Disposition` header if provided. + + Args: + param response_data (str): the file data to write + configuration (Configuration): the instance to use to convert files + + Keyword Args: + content_disposition (str): the value of the Content-Disposition + header + + Returns: + (str): the deserialized file path + """ + fd, path = tempfile.mkstemp(dir=configuration.temp_folder_path) + os.close(fd) + os.remove(path) + + if content_disposition: + filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?', + content_disposition).group(1) + path = os.path.join(os.path.dirname(path), filename) + + with open(path, "wb") as f: + if six.PY3 and isisinstance(response_data, str): + # in python3 change str to bytes so we can write it + response_data = response_data.encode('utf-8') + f.write(response_data) + + return path + + +def attempt_convert_item(input_value, valid_classes, path_to_item, + configuration, key_type=False, must_convert=False): + """ + Args: + input_value (any): the data to convert + valid_classes (any): the classes that are valid + path_to_item (list): the path to the item to convert + configuration (Configuration): the instance to use to convert files + key_type (bool): if True we need to convert a key type (not supported) + must_convert (bool): if True we must convert + + Returns: + instance (any) the fixed item + + Raises: + ApiTypeError + ApiValueError + ApiKeyError + """ + valid_classes_ordered = order_response_types(valid_classes) + valid_classes_coercible = remove_uncoercible( + valid_classes_ordered, input_value) + if not valid_classes_coercible or key_type: + # we do not handle keytype errors, json will take care + # of this for us + raise get_type_error(input_value, path_to_item, valid_classes, + key_type=key_type) + deserialized_item = None + for valid_class in valid_classes_coercible: + try: + if issubclass(valid_class, OpenApiModel): + return deserialize_model(input_value, valid_class, + path_to_item, configuration) + elif valid_class == file_type: + return deserialize_file(input_value, configuration) + return deserialize_primitive(input_value, valid_class, + path_to_item) + except (ApiTypeError, ApiValueError, ApiKeyError) as conversion_exc: + if must_convert: + raise conversion_exc + # if we have conversion errors when must_convert == False + # we ignore the exception and move on to the next class + continue + # we were unable to convert, must_convert == False + return input_value + + +def validate_and_convert_types(input_value, required_types_mixed, path_to_item, + configuration=None): + """Raises a TypeError is there is a problem, otherwise returns value + + Args: + input_value (any): the data to validate/convert + required_types_mixed (list/dict/tuple): A list of + valid classes, or a list tuples of valid classes, or a dict where + the value is a tuple of value classes + path_to_item: (list) the path to the data being validated + this stores a list of keys or indices to get to the data being + validated + configuration: (Configuration): the configuration class to use + when converting file_type items. + If passed, conversion will be attempted when possible + If not passed, no conversions will be attempted and + exceptions will be raised + + Returns: + the correctly typed value + + Raises: + ApiTypeError + """ + results = get_required_type_classes(required_types_mixed) + valid_classes, child_req_types_by_current_type = results + + input_class_simple = get_simple_class(input_value) + valid_type = input_class_simple in set(valid_classes) + if not valid_type: + if configuration: + # if input_value is not valid_type try to convert it + converted_instance = attempt_convert_item(input_value, + valid_classes, path_to_item, configuration, key_type=False, + must_convert=True) + return converted_instance + else: + raise get_type_error(input_value, path_to_item, valid_classes, + key_type=False) + + # input_value's type is in valid_classes + if len(valid_classes) > 1 and configuration: + # there are valid classes which are not the current class + valid_classes_coercible = remove_uncoercible( + valid_classes, input_value, must_convert=False) + if valid_classes_coercible: + converted_instance = attempt_convert_item(input_value, + valid_classes_coercible, path_to_item, configuration, + key_type=False, must_convert=False) + return converted_instance + + if child_req_types_by_current_type == {}: + # all types are of the required types and there are no more inner + # variables left to look at + return input_value + inner_required_types = child_req_types_by_current_type.get( + type(input_value) + ) + if inner_required_types is None: + # for this type, there are not more inner variables left to look at + return input_value + if isinstance(input_value, list): + if input_value == []: + # allow an empty list + return input_value + for index, inner_value in enumerate(input_value): + inner_path = list(path_to_item) + inner_path.append(index) + input_value[index] = validate_and_convert_types(inner_value, + inner_required_types, inner_path, configuration=configuration) + elif isinstance(input_value, dict): + if input_value == {}: + # allow an empty dict + return input_value + for inner_key, inner_val in six.iteritems(input_value): + inner_path = list(path_to_item) + inner_path.append(inner_key) + if get_simple_class(inner_key) != str: + raise get_type_error(inner_key, inner_path, valid_classes, + key_type=True) + input_value[inner_key] = validate_and_convert_types(inner_val, + inner_required_types, inner_path, configuration=configuration) + return input_value + + +def model_to_dict(model_instance, serialize=True): + """Returns the model properties as a dict + + Args: + model_instance (one of your model instances): the model instance that + will be converted to a dict. + + Keyword Args: + serialize (bool): if True, the keys in the dict will be values from + attribute_map + """ + result = {} + + for attr, value in six.iteritems(model_instance._data_store): + if serialize: + attr = model_instance.attribute_map[attr] + if isinstance(value, list): + result[attr] = list(map( + lambda x: model_to_dict(x, serialize=serialize) + if hasattr(x, '_data_store') else x, value + )) + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], + model_to_dict(item[1], serialize=serialize)) + if hasattr(item[1], '_data_store') else item, + value.items() + )) + elif hasattr(value, '_data_store'): + result[attr] = model_to_dict(value, serialize=serialize) + else: + result[attr] = value + + return result + + +def type_error_message(var_value=None, var_name=None, valid_classes=None, + key_type=None): + """ + Keyword Args: + var_value (any): the variable which has the type_error + var_name (str): the name of the variable which has the typ error + valid_classes (tuple): the accepted classes for current_item's + value + 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 + """ + key_or_value = 'value' + if key_type: + key_or_value = 'key' + valid_classes_phrase = get_valid_classes_phrase(valid_classes) + msg = ( + "Invalid type for variable '{0}'. Required {1} type {2} and " + "passed type was {3}".format( + var_name, + key_or_value, + valid_classes_phrase, + type(var_value).__name__, + ) + ) + return msg + + +def get_valid_classes_phrase(input_classes): + """Returns a string phrase describing what types are allowed + Note: Adds the extra valid classes in python2 + """ + all_classes = list(input_classes) + if six.PY2 and str in input_classes: + all_classes.extend([str_py2, unicode_py2]) + if six.PY2 and int in input_classes: + all_classes.extend([int_py2, long_py2]) + all_classes = sorted(all_classes, key=lambda cls: cls.__name__) + all_class_names = [cls.__name__ for cls in all_classes] + if len(all_class_names) == 1: + return 'is {0}'.format(all_class_names[0]) + return "is one of [{0}]".format(", ".join(all_class_names)) + + +def get_py3_class_name(input_class): + if six.PY2: + if input_class == str: + return 'str' + elif input_class == int: + return 'int' + return input_class.__name__ diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py index e8586263cc2e..b20700c782cb 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/__init__.py @@ -48,6 +48,7 @@ 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 diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_class.py b/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_class.py index dc4648ae1c7f..9aae96b52c93 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_class.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/additional_properties_class.py @@ -15,8 +15,27 @@ import six - -class AdditionalPropertiesClass(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class AdditionalPropertiesClass(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +46,163 @@ class AdditionalPropertiesClass(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'map_property': 'dict(str, str)', - 'map_of_map_property': 'dict(str, dict(str, str))' + 'map_property': [{str: (str,)}], # noqa: E501 + 'map_of_map_property': [{str: ({str: (str,)},)}] # noqa: E501 } - attribute_map = { - 'map_property': 'map_property', - 'map_of_map_property': 'map_of_map_property' + 'map_property': 'map_property', # noqa: E501 + 'map_of_map_property': 'map_of_map_property' # noqa: E501 } - def __init__(self, map_property=None, map_of_map_property=None): # noqa: E501 - """AdditionalPropertiesClass - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """AdditionalPropertiesClass - 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 False + _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 + _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. + map_property ({str: (str,)}): [optional] # noqa: E501 + map_of_map_property ({str: ({str: (str,)},)}): [optional] # noqa: E501 + """ - self._map_property = None - self._map_of_map_property = None + self._data_store = {} self.discriminator = None - - if map_property is not None: - self.map_property = map_property - if map_of_map_property is not None: - self.map_of_map_property = map_of_map_property + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def map_property(self): """Gets the map_property of this AdditionalPropertiesClass. # noqa: E501 - :return: The map_property of this AdditionalPropertiesClass. # noqa: E501 - :rtype: dict(str, str) + Returns: + ({str: (str,)}): The map_property of this AdditionalPropertiesClass. # noqa: E501 """ - return self._map_property + return self._data_store.get('map_property') @map_property.setter - def map_property(self, map_property): + def map_property( + self, map_property): """Sets the map_property of this AdditionalPropertiesClass. - :param map_property: The map_property of this AdditionalPropertiesClass. # noqa: E501 - :type: dict(str, str) + Returns: + ({str: (str,)}): The map_property of this AdditionalPropertiesClass. # noqa: E501 """ - self._map_property = map_property + self.__setitem__( + 'map_property', + map_property + ) @property def map_of_map_property(self): """Gets the map_of_map_property of this AdditionalPropertiesClass. # noqa: E501 - :return: The map_of_map_property of this AdditionalPropertiesClass. # noqa: E501 - :rtype: dict(str, dict(str, str)) + Returns: + ({str: ({str: (str,)},)}): The map_of_map_property of this AdditionalPropertiesClass. # noqa: E501 """ - return self._map_of_map_property + return self._data_store.get('map_of_map_property') @map_of_map_property.setter - def map_of_map_property(self, map_of_map_property): + def map_of_map_property( + self, map_of_map_property): """Sets the map_of_map_property of this AdditionalPropertiesClass. - :param map_of_map_property: The map_of_map_property of this AdditionalPropertiesClass. # noqa: E501 - :type: dict(str, dict(str, str)) + Returns: + ({str: ({str: (str,)},)}): The map_of_map_property of this AdditionalPropertiesClass. # noqa: E501 """ - self._map_of_map_property = map_of_map_property + self.__setitem__( + 'map_of_map_property', + map_of_map_property + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/animal.py b/samples/openapi3/client/petstore/python/petstore_api/models/animal.py index abd6f705e5e8..ba09d8520ca1 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/animal.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/animal.py @@ -15,8 +15,29 @@ import six - -class Animal(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.cat import Cat +from petstore_api.models.dog import Dog + + +class Animal(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,78 +48,167 @@ class Animal(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'class_name': 'str', - 'color': 'str' + 'class_name': [str], # noqa: E501 + 'color': [str] # noqa: E501 } - attribute_map = { - 'class_name': 'className', - 'color': 'color' + 'class_name': 'className', # noqa: E501 + 'color': 'color' # noqa: E501 } - discriminator_value_class_map = { - 'Dog': 'Dog', - 'Cat': 'Cat' + 'Dog': Dog, + 'Cat': Cat } - def __init__(self, class_name=None, color='red'): # noqa: E501 - """Animal - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, class_name, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Animal - a model defined in OpenAPI + + Args: + class_name (str): + + 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 False + _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 + _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. + color (str): [optional] if omitted the server will use the default value of 'red' # noqa: E501 + """ - self._class_name = None - self._color = None + self._data_store = {} self.discriminator = 'class_name' + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + # assign using .var_name to check against nullable and enums self.class_name = class_name - if color is not None: - self.color = color + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def class_name(self): """Gets the class_name of this Animal. # noqa: E501 - :return: The class_name of this Animal. # noqa: E501 - :rtype: str + Returns: + (str): The class_name of this Animal. # noqa: E501 """ - return self._class_name + return self._data_store.get('class_name') @class_name.setter - def class_name(self, class_name): + def class_name( + self, class_name): """Sets the class_name of this Animal. - :param class_name: The class_name of this Animal. # noqa: E501 - :type: str + Returns: + (str): The class_name of this Animal. # noqa: E501 """ if class_name is None: - raise ValueError("Invalid value for `class_name`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `class_name`, must not be `None`") # noqa: E501 - self._class_name = class_name + self.__setitem__( + 'class_name', + class_name + ) @property def color(self): """Gets the color of this Animal. # noqa: E501 - :return: The color of this Animal. # noqa: E501 - :rtype: str + Returns: + (str): The color of this Animal. # noqa: E501 """ - return self._color + return self._data_store.get('color') @color.setter - def color(self, color): + def color( + self, color): """Sets the color of this Animal. - :param color: The color of this Animal. # noqa: E501 - :type: str + Returns: + (str): The color of this Animal. # noqa: E501 """ - self._color = color + self.__setitem__( + 'color', + color + ) def get_real_child_model(self, data): """Returns the real base class specified by the discriminator""" @@ -108,27 +218,7 @@ def get_real_child_model(self, data): 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/api_response.py b/samples/openapi3/client/petstore/python/petstore_api/models/api_response.py index e62983030491..50fcf50f5207 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/api_response.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/api_response.py @@ -15,8 +15,27 @@ import six - -class ApiResponse(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ApiResponse(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,122 +46,191 @@ class ApiResponse(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'code': 'int', - 'type': 'str', - 'message': 'str' + 'code': [int], # noqa: E501 + 'type': [str], # noqa: E501 + 'message': [str] # noqa: E501 } - attribute_map = { - 'code': 'code', - 'type': 'type', - 'message': 'message' + 'code': 'code', # noqa: E501 + 'type': 'type', # noqa: E501 + 'message': 'message' # noqa: E501 } - def __init__(self, code=None, type=None, message=None): # noqa: E501 - """ApiResponse - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ApiResponse - 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 False + _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 + _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. + code (int): [optional] # noqa: E501 + type (str): [optional] # noqa: E501 + message (str): [optional] # noqa: E501 + """ - self._code = None - self._type = None - self._message = None + self._data_store = {} self.discriminator = None - - if code is not None: - self.code = code - if type is not None: - self.type = type - if message is not None: - self.message = message + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def code(self): """Gets the code of this ApiResponse. # noqa: E501 - :return: The code of this ApiResponse. # noqa: E501 - :rtype: int + Returns: + (int): The code of this ApiResponse. # noqa: E501 """ - return self._code + return self._data_store.get('code') @code.setter - def code(self, code): + def code( + self, code): """Sets the code of this ApiResponse. - :param code: The code of this ApiResponse. # noqa: E501 - :type: int + Returns: + (int): The code of this ApiResponse. # noqa: E501 """ - self._code = code + self.__setitem__( + 'code', + code + ) @property def type(self): """Gets the type of this ApiResponse. # noqa: E501 - :return: The type of this ApiResponse. # noqa: E501 - :rtype: str + Returns: + (str): The type of this ApiResponse. # noqa: E501 """ - return self._type + return self._data_store.get('type') @type.setter - def type(self, type): + def type( + self, type): """Sets the type of this ApiResponse. - :param type: The type of this ApiResponse. # noqa: E501 - :type: str + Returns: + (str): The type of this ApiResponse. # noqa: E501 """ - self._type = type + self.__setitem__( + 'type', + type + ) @property def message(self): """Gets the message of this ApiResponse. # noqa: E501 - :return: The message of this ApiResponse. # noqa: E501 - :rtype: str + Returns: + (str): The message of this ApiResponse. # noqa: E501 """ - return self._message + return self._data_store.get('message') @message.setter - def message(self, message): + def message( + self, message): """Sets the message of this ApiResponse. - :param message: The message of this ApiResponse. # noqa: E501 - :type: str + Returns: + (str): The message of this ApiResponse. # noqa: E501 """ - self._message = message + self.__setitem__( + 'message', + message + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_number_only.py b/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_number_only.py index fde218a4661c..407b261c7f34 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_number_only.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/array_of_array_of_number_only.py @@ -15,8 +15,27 @@ import six - -class ArrayOfArrayOfNumberOnly(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ArrayOfArrayOfNumberOnly(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class ArrayOfArrayOfNumberOnly(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'array_array_number': 'list[list[float]]' + 'array_array_number': [[([(float,)],)]] # noqa: E501 } - attribute_map = { - 'array_array_number': 'ArrayArrayNumber' + 'array_array_number': 'ArrayArrayNumber' # noqa: E501 } - def __init__(self, array_array_number=None): # noqa: E501 - """ArrayOfArrayOfNumberOnly - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ArrayOfArrayOfNumberOnly - a model defined in OpenAPI - self._array_array_number = None - self.discriminator = None - if array_array_number is not None: - self.array_array_number = array_array_number + + 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 False + _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 + _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. + array_array_number ([([(float,)],)]): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def array_array_number(self): """Gets the array_array_number of this ArrayOfArrayOfNumberOnly. # noqa: E501 - :return: The array_array_number of this ArrayOfArrayOfNumberOnly. # noqa: E501 - :rtype: list[list[float]] + Returns: + ([([(float,)],)]): The array_array_number of this ArrayOfArrayOfNumberOnly. # noqa: E501 """ - return self._array_array_number + return self._data_store.get('array_array_number') @array_array_number.setter - def array_array_number(self, array_array_number): + def array_array_number( + self, array_array_number): """Sets the array_array_number of this ArrayOfArrayOfNumberOnly. - :param array_array_number: The array_array_number of this ArrayOfArrayOfNumberOnly. # noqa: E501 - :type: list[list[float]] + Returns: + ([([(float,)],)]): The array_array_number of this ArrayOfArrayOfNumberOnly. # noqa: E501 """ - self._array_array_number = array_array_number + self.__setitem__( + 'array_array_number', + array_array_number + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/array_of_number_only.py b/samples/openapi3/client/petstore/python/petstore_api/models/array_of_number_only.py index 8999e563c4a6..790a6761dc06 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/array_of_number_only.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/array_of_number_only.py @@ -15,8 +15,27 @@ import six - -class ArrayOfNumberOnly(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ArrayOfNumberOnly(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class ArrayOfNumberOnly(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'array_number': 'list[float]' + 'array_number': [[(float,)]] # noqa: E501 } - attribute_map = { - 'array_number': 'ArrayNumber' + 'array_number': 'ArrayNumber' # noqa: E501 } - def __init__(self, array_number=None): # noqa: E501 - """ArrayOfNumberOnly - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ArrayOfNumberOnly - a model defined in OpenAPI - self._array_number = None - self.discriminator = None - if array_number is not None: - self.array_number = array_number + + 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 False + _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 + _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. + array_number ([(float,)]): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def array_number(self): """Gets the array_number of this ArrayOfNumberOnly. # noqa: E501 - :return: The array_number of this ArrayOfNumberOnly. # noqa: E501 - :rtype: list[float] + Returns: + ([(float,)]): The array_number of this ArrayOfNumberOnly. # noqa: E501 """ - return self._array_number + return self._data_store.get('array_number') @array_number.setter - def array_number(self, array_number): + def array_number( + self, array_number): """Sets the array_number of this ArrayOfNumberOnly. - :param array_number: The array_number of this ArrayOfNumberOnly. # noqa: E501 - :type: list[float] + Returns: + ([(float,)]): The array_number of this ArrayOfNumberOnly. # noqa: E501 """ - self._array_number = array_number + self.__setitem__( + 'array_number', + array_number + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/array_test.py b/samples/openapi3/client/petstore/python/petstore_api/models/array_test.py index 05cc108139a5..63e94762f367 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/array_test.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/array_test.py @@ -15,8 +15,28 @@ import six - -class ArrayTest(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.read_only_first import ReadOnlyFirst + + +class ArrayTest(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,122 +47,191 @@ class ArrayTest(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'array_of_string': 'list[str]', - 'array_array_of_integer': 'list[list[int]]', - 'array_array_of_model': 'list[list[ReadOnlyFirst]]' + 'array_of_string': [[(str,)]], # noqa: E501 + 'array_array_of_integer': [[([(int,)],)]], # noqa: E501 + 'array_array_of_model': [[([(ReadOnlyFirst,)],)]] # noqa: E501 } - attribute_map = { - 'array_of_string': 'array_of_string', - 'array_array_of_integer': 'array_array_of_integer', - 'array_array_of_model': 'array_array_of_model' + 'array_of_string': 'array_of_string', # noqa: E501 + 'array_array_of_integer': 'array_array_of_integer', # noqa: E501 + 'array_array_of_model': 'array_array_of_model' # noqa: E501 } - def __init__(self, array_of_string=None, array_array_of_integer=None, array_array_of_model=None): # noqa: E501 - """ArrayTest - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ArrayTest - 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 False + _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 + _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. + array_of_string ([(str,)]): [optional] # noqa: E501 + array_array_of_integer ([([(int,)],)]): [optional] # noqa: E501 + array_array_of_model ([([(ReadOnlyFirst,)],)]): [optional] # noqa: E501 + """ - self._array_of_string = None - self._array_array_of_integer = None - self._array_array_of_model = None + self._data_store = {} self.discriminator = None - - if array_of_string is not None: - self.array_of_string = array_of_string - if array_array_of_integer is not None: - self.array_array_of_integer = array_array_of_integer - if array_array_of_model is not None: - self.array_array_of_model = array_array_of_model + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def array_of_string(self): """Gets the array_of_string of this ArrayTest. # noqa: E501 - :return: The array_of_string of this ArrayTest. # noqa: E501 - :rtype: list[str] + Returns: + ([(str,)]): The array_of_string of this ArrayTest. # noqa: E501 """ - return self._array_of_string + return self._data_store.get('array_of_string') @array_of_string.setter - def array_of_string(self, array_of_string): + def array_of_string( + self, array_of_string): """Sets the array_of_string of this ArrayTest. - :param array_of_string: The array_of_string of this ArrayTest. # noqa: E501 - :type: list[str] + Returns: + ([(str,)]): The array_of_string of this ArrayTest. # noqa: E501 """ - self._array_of_string = array_of_string + self.__setitem__( + 'array_of_string', + array_of_string + ) @property def array_array_of_integer(self): """Gets the array_array_of_integer of this ArrayTest. # noqa: E501 - :return: The array_array_of_integer of this ArrayTest. # noqa: E501 - :rtype: list[list[int]] + Returns: + ([([(int,)],)]): The array_array_of_integer of this ArrayTest. # noqa: E501 """ - return self._array_array_of_integer + return self._data_store.get('array_array_of_integer') @array_array_of_integer.setter - def array_array_of_integer(self, array_array_of_integer): + def array_array_of_integer( + self, array_array_of_integer): """Sets the array_array_of_integer of this ArrayTest. - :param array_array_of_integer: The array_array_of_integer of this ArrayTest. # noqa: E501 - :type: list[list[int]] + Returns: + ([([(int,)],)]): The array_array_of_integer of this ArrayTest. # noqa: E501 """ - self._array_array_of_integer = array_array_of_integer + self.__setitem__( + 'array_array_of_integer', + array_array_of_integer + ) @property def array_array_of_model(self): """Gets the array_array_of_model of this ArrayTest. # noqa: E501 - :return: The array_array_of_model of this ArrayTest. # noqa: E501 - :rtype: list[list[ReadOnlyFirst]] + Returns: + ([([(ReadOnlyFirst,)],)]): The array_array_of_model of this ArrayTest. # noqa: E501 """ - return self._array_array_of_model + return self._data_store.get('array_array_of_model') @array_array_of_model.setter - def array_array_of_model(self, array_array_of_model): + def array_array_of_model( + self, array_array_of_model): """Sets the array_array_of_model of this ArrayTest. - :param array_array_of_model: The array_array_of_model of this ArrayTest. # noqa: E501 - :type: list[list[ReadOnlyFirst]] + Returns: + ([([(ReadOnlyFirst,)],)]): The array_array_of_model of this ArrayTest. # noqa: E501 """ - self._array_array_of_model = array_array_of_model + self.__setitem__( + 'array_array_of_model', + array_array_of_model + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/capitalization.py b/samples/openapi3/client/petstore/python/petstore_api/models/capitalization.py index 923f5c4aae86..97f1c86c1cbf 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/capitalization.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/capitalization.py @@ -15,8 +15,27 @@ import six - -class Capitalization(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Capitalization(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,155 +46,246 @@ class Capitalization(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'small_camel': 'str', - 'capital_camel': 'str', - 'small_snake': 'str', - 'capital_snake': 'str', - 'sca_eth_flow_points': 'str', - 'att_name': 'str' + 'small_camel': [str], # noqa: E501 + 'capital_camel': [str], # noqa: E501 + 'small_snake': [str], # noqa: E501 + 'capital_snake': [str], # noqa: E501 + 'sca_eth_flow_points': [str], # noqa: E501 + 'att_name': [str] # noqa: E501 } - attribute_map = { - 'small_camel': 'smallCamel', - 'capital_camel': 'CapitalCamel', - 'small_snake': 'small_Snake', - 'capital_snake': 'Capital_Snake', - 'sca_eth_flow_points': 'SCA_ETH_Flow_Points', - 'att_name': 'ATT_NAME' + 'small_camel': 'smallCamel', # noqa: E501 + 'capital_camel': 'CapitalCamel', # noqa: E501 + 'small_snake': 'small_Snake', # noqa: E501 + 'capital_snake': 'Capital_Snake', # noqa: E501 + 'sca_eth_flow_points': 'SCA_ETH_Flow_Points', # noqa: E501 + 'att_name': 'ATT_NAME' # noqa: E501 } - def __init__(self, small_camel=None, capital_camel=None, small_snake=None, capital_snake=None, sca_eth_flow_points=None, att_name=None): # noqa: E501 - """Capitalization - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Capitalization - 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 False + _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 + _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. + small_camel (str): [optional] # noqa: E501 + capital_camel (str): [optional] # noqa: E501 + small_snake (str): [optional] # noqa: E501 + capital_snake (str): [optional] # noqa: E501 + sca_eth_flow_points (str): [optional] # noqa: E501 + att_name (str): Name of the pet . [optional] # noqa: E501 + """ - self._small_camel = None - self._capital_camel = None - self._small_snake = None - self._capital_snake = None - self._sca_eth_flow_points = None - self._att_name = None + self._data_store = {} self.discriminator = None - - if small_camel is not None: - self.small_camel = small_camel - if capital_camel is not None: - self.capital_camel = capital_camel - if small_snake is not None: - self.small_snake = small_snake - if capital_snake is not None: - self.capital_snake = capital_snake - if sca_eth_flow_points is not None: - self.sca_eth_flow_points = sca_eth_flow_points - if att_name is not None: - self.att_name = att_name + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def small_camel(self): """Gets the small_camel of this Capitalization. # noqa: E501 - :return: The small_camel of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The small_camel of this Capitalization. # noqa: E501 """ - return self._small_camel + return self._data_store.get('small_camel') @small_camel.setter - def small_camel(self, small_camel): + def small_camel( + self, small_camel): """Sets the small_camel of this Capitalization. - :param small_camel: The small_camel of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The small_camel of this Capitalization. # noqa: E501 """ - self._small_camel = small_camel + self.__setitem__( + 'small_camel', + small_camel + ) @property def capital_camel(self): """Gets the capital_camel of this Capitalization. # noqa: E501 - :return: The capital_camel of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The capital_camel of this Capitalization. # noqa: E501 """ - return self._capital_camel + return self._data_store.get('capital_camel') @capital_camel.setter - def capital_camel(self, capital_camel): + def capital_camel( + self, capital_camel): """Sets the capital_camel of this Capitalization. - :param capital_camel: The capital_camel of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The capital_camel of this Capitalization. # noqa: E501 """ - self._capital_camel = capital_camel + self.__setitem__( + 'capital_camel', + capital_camel + ) @property def small_snake(self): """Gets the small_snake of this Capitalization. # noqa: E501 - :return: The small_snake of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The small_snake of this Capitalization. # noqa: E501 """ - return self._small_snake + return self._data_store.get('small_snake') @small_snake.setter - def small_snake(self, small_snake): + def small_snake( + self, small_snake): """Sets the small_snake of this Capitalization. - :param small_snake: The small_snake of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The small_snake of this Capitalization. # noqa: E501 """ - self._small_snake = small_snake + self.__setitem__( + 'small_snake', + small_snake + ) @property def capital_snake(self): """Gets the capital_snake of this Capitalization. # noqa: E501 - :return: The capital_snake of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The capital_snake of this Capitalization. # noqa: E501 """ - return self._capital_snake + return self._data_store.get('capital_snake') @capital_snake.setter - def capital_snake(self, capital_snake): + def capital_snake( + self, capital_snake): """Sets the capital_snake of this Capitalization. - :param capital_snake: The capital_snake of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The capital_snake of this Capitalization. # noqa: E501 """ - self._capital_snake = capital_snake + self.__setitem__( + 'capital_snake', + capital_snake + ) @property def sca_eth_flow_points(self): """Gets the sca_eth_flow_points of this Capitalization. # noqa: E501 - :return: The sca_eth_flow_points of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The sca_eth_flow_points of this Capitalization. # noqa: E501 """ - return self._sca_eth_flow_points + return self._data_store.get('sca_eth_flow_points') @sca_eth_flow_points.setter - def sca_eth_flow_points(self, sca_eth_flow_points): + def sca_eth_flow_points( + self, sca_eth_flow_points): """Sets the sca_eth_flow_points of this Capitalization. - :param sca_eth_flow_points: The sca_eth_flow_points of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The sca_eth_flow_points of this Capitalization. # noqa: E501 """ - self._sca_eth_flow_points = sca_eth_flow_points + self.__setitem__( + 'sca_eth_flow_points', + sca_eth_flow_points + ) @property def att_name(self): @@ -183,46 +293,30 @@ def att_name(self): Name of the pet # noqa: E501 - :return: The att_name of this Capitalization. # noqa: E501 - :rtype: str + Returns: + (str): The att_name of this Capitalization. # noqa: E501 """ - return self._att_name + return self._data_store.get('att_name') @att_name.setter - def att_name(self, att_name): + def att_name( + self, att_name): """Sets the att_name of this Capitalization. Name of the pet # noqa: E501 - :param att_name: The att_name of this Capitalization. # noqa: E501 - :type: str + Returns: + (str): The att_name of this Capitalization. # noqa: E501 """ - self._att_name = att_name + self.__setitem__( + 'att_name', + att_name + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/cat.py b/samples/openapi3/client/petstore/python/petstore_api/models/cat.py index c5c87a6b1118..49bec13ed39e 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/cat.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/cat.py @@ -15,8 +15,27 @@ import six +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) -class Cat(object): + +class Cat(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,195 @@ class Cat(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'declawed': 'bool' + 'class_name': [str], # noqa: E501 + 'color': [str], # noqa: E501 + 'declawed': [bool] # noqa: E501 } - attribute_map = { - 'declawed': 'declawed' + 'class_name': 'className', # noqa: E501 + 'color': 'color', # noqa: E501 + 'declawed': 'declawed' # noqa: E501 } - def __init__(self, declawed=None): # noqa: E501 - """Cat - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, class_name, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Cat - a model defined in OpenAPI + + Args: + class_name (str): + + 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 False + _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 + _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. + declawed (bool): [optional] # noqa: E501 + color (str): [optional] if omitted the server will use the default value of 'red' # noqa: E501 + """ - self._declawed = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + # assign using .var_name to check against nullable and enums + self.class_name = class_name + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def class_name(self): + """Gets the class_name of this Cat. # noqa: E501 + + + Returns: + (str): The class_name of this Cat. # noqa: E501 + """ + return self._data_store.get('class_name') + + @class_name.setter + def class_name( + self, class_name): + """Sets the class_name of this Cat. + + + Returns: + (str): The class_name of this Cat. # noqa: E501 + """ + if class_name is None: + raise ApiValueError("Invalid value for `class_name`, must not be `None`") # noqa: E501 - if declawed is not None: - self.declawed = declawed + self.__setitem__( + 'class_name', + class_name + ) + + @property + def color(self): + """Gets the color of this Cat. # noqa: E501 + + + Returns: + (str): The color of this Cat. # noqa: E501 + """ + return self._data_store.get('color') + + @color.setter + def color( + self, color): + """Sets the color of this Cat. + + + Returns: + (str): The color of this Cat. # noqa: E501 + """ + + self.__setitem__( + 'color', + color + ) @property def declawed(self): """Gets the declawed of this Cat. # noqa: E501 - :return: The declawed of this Cat. # noqa: E501 - :rtype: bool + Returns: + (bool): The declawed of this Cat. # noqa: E501 """ - return self._declawed + return self._data_store.get('declawed') @declawed.setter - def declawed(self, declawed): + def declawed( + self, declawed): """Sets the declawed of this Cat. - :param declawed: The declawed of this Cat. # noqa: E501 - :type: bool + Returns: + (bool): The declawed of this Cat. # noqa: E501 """ - self._declawed = declawed + self.__setitem__( + 'declawed', + declawed + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/category.py b/samples/openapi3/client/petstore/python/petstore_api/models/category.py index 5b2f79eaec8d..28b9f6ada0fa 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/category.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/category.py @@ -15,8 +15,27 @@ import six - -class Category(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Category(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,97 +46,167 @@ class Category(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'id': 'int', - 'name': 'str' + 'id': [int], # noqa: E501 + 'name': [str] # noqa: E501 } - attribute_map = { - 'id': 'id', - 'name': 'name' + 'id': 'id', # noqa: E501 + 'name': 'name' # noqa: E501 } - def __init__(self, id=None, name='default-name'): # noqa: E501 - """Category - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, name='default-name', _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Category - a model defined in OpenAPI + + Args: + name (str): defaults to 'default-name', must be one of ['default-name'] # noqa: E501 + + 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 False + _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 + _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. + id (int): [optional] # noqa: E501 + """ - self._id = None - self._name = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration - if id is not None: - self.id = id + # assign using .var_name to check against nullable and enums self.name = name + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def id(self): """Gets the id of this Category. # noqa: E501 - :return: The id of this Category. # noqa: E501 - :rtype: int + Returns: + (int): The id of this Category. # noqa: E501 """ - return self._id + return self._data_store.get('id') @id.setter - def id(self, id): + def id( + self, id): """Sets the id of this Category. - :param id: The id of this Category. # noqa: E501 - :type: int + Returns: + (int): The id of this Category. # noqa: E501 """ - self._id = id + self.__setitem__( + 'id', + id + ) @property def name(self): """Gets the name of this Category. # noqa: E501 - :return: The name of this Category. # noqa: E501 - :rtype: str + Returns: + (str): The name of this Category. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this Category. - :param name: The name of this Category. # noqa: E501 - :type: str + Returns: + (str): The name of this Category. # noqa: E501 """ if name is None: - raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `name`, must not be `None`") # noqa: E501 - self._name = name + self.__setitem__( + 'name', + name + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/class_model.py b/samples/openapi3/client/petstore/python/petstore_api/models/class_model.py index e207ba41ec92..d665edf7efd5 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/class_model.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/class_model.py @@ -15,8 +15,27 @@ import six - -class ClassModel(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ClassModel(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class ClassModel(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - '_class': 'str' + '_class': [str] # noqa: E501 } - attribute_map = { - '_class': '_class' + '_class': '_class' # noqa: E501 } - def __init__(self, _class=None): # noqa: E501 - """ClassModel - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ClassModel - a model defined in OpenAPI - self.__class = None - self.discriminator = None - if _class is not None: - self._class = _class + + 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 False + _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 + _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. + _class (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def _class(self): """Gets the _class of this ClassModel. # noqa: E501 - :return: The _class of this ClassModel. # noqa: E501 - :rtype: str + Returns: + (str): The _class of this ClassModel. # noqa: E501 """ - return self.__class + return self._data_store.get('_class') @_class.setter - def _class(self, _class): + def _class( + self, _class): """Sets the _class of this ClassModel. - :param _class: The _class of this ClassModel. # noqa: E501 - :type: str + Returns: + (str): The _class of this ClassModel. # noqa: E501 """ - self.__class = _class + self.__setitem__( + '_class', + _class + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/client.py b/samples/openapi3/client/petstore/python/petstore_api/models/client.py index e742468e7763..ea315bc1cadd 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/client.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/client.py @@ -15,8 +15,27 @@ import six - -class Client(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Client(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class Client(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'client': 'str' + 'client': [str] # noqa: E501 } - attribute_map = { - 'client': 'client' + 'client': 'client' # noqa: E501 } - def __init__(self, client=None): # noqa: E501 - """Client - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Client - a model defined in OpenAPI - self._client = None - self.discriminator = None - if client is not None: - self.client = client + + 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 False + _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 + _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. + client (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def client(self): """Gets the client of this Client. # noqa: E501 - :return: The client of this Client. # noqa: E501 - :rtype: str + Returns: + (str): The client of this Client. # noqa: E501 """ - return self._client + return self._data_store.get('client') @client.setter - def client(self, client): + def client( + self, client): """Sets the client of this Client. - :param client: The client of this Client. # noqa: E501 - :type: str + Returns: + (str): The client of this Client. # noqa: E501 """ - self._client = client + self.__setitem__( + 'client', + client + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/dog.py b/samples/openapi3/client/petstore/python/petstore_api/models/dog.py index c2bc8f745d15..0febcbab94ec 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/dog.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/dog.py @@ -15,8 +15,27 @@ import six +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) -class Dog(object): + +class Dog(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,195 @@ class Dog(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'breed': 'str' + 'class_name': [str], # noqa: E501 + 'color': [str], # noqa: E501 + 'breed': [str] # noqa: E501 } - attribute_map = { - 'breed': 'breed' + 'class_name': 'className', # noqa: E501 + 'color': 'color', # noqa: E501 + 'breed': 'breed' # noqa: E501 } - def __init__(self, breed=None): # noqa: E501 - """Dog - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, class_name, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Dog - a model defined in OpenAPI + + Args: + class_name (str): + + 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 False + _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 + _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. + breed (str): [optional] # noqa: E501 + color (str): [optional] if omitted the server will use the default value of 'red' # noqa: E501 + """ - self._breed = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + # assign using .var_name to check against nullable and enums + self.class_name = class_name + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def class_name(self): + """Gets the class_name of this Dog. # noqa: E501 + + + Returns: + (str): The class_name of this Dog. # noqa: E501 + """ + return self._data_store.get('class_name') + + @class_name.setter + def class_name( + self, class_name): + """Sets the class_name of this Dog. + + + Returns: + (str): The class_name of this Dog. # noqa: E501 + """ + if class_name is None: + raise ApiValueError("Invalid value for `class_name`, must not be `None`") # noqa: E501 - if breed is not None: - self.breed = breed + self.__setitem__( + 'class_name', + class_name + ) + + @property + def color(self): + """Gets the color of this Dog. # noqa: E501 + + + Returns: + (str): The color of this Dog. # noqa: E501 + """ + return self._data_store.get('color') + + @color.setter + def color( + self, color): + """Sets the color of this Dog. + + + Returns: + (str): The color of this Dog. # noqa: E501 + """ + + self.__setitem__( + 'color', + color + ) @property def breed(self): """Gets the breed of this Dog. # noqa: E501 - :return: The breed of this Dog. # noqa: E501 - :rtype: str + Returns: + (str): The breed of this Dog. # noqa: E501 """ - return self._breed + return self._data_store.get('breed') @breed.setter - def breed(self, breed): + def breed( + self, breed): """Sets the breed of this Dog. - :param breed: The breed of this Dog. # noqa: E501 - :type: str + Returns: + (str): The breed of this Dog. # noqa: E501 """ - self._breed = breed + self.__setitem__( + 'breed', + breed + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/enum_arrays.py b/samples/openapi3/client/petstore/python/petstore_api/models/enum_arrays.py index df4363c356c3..88e4f0a20751 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/enum_arrays.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/enum_arrays.py @@ -15,8 +15,27 @@ import six - -class EnumArrays(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class EnumArrays(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,109 +46,176 @@ class EnumArrays(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'just_symbol': 'str', - 'array_enum': 'list[str]' + 'just_symbol': [str], # noqa: E501 + 'array_enum': [[(str,)]] # noqa: E501 } - attribute_map = { - 'just_symbol': 'just_symbol', - 'array_enum': 'array_enum' + 'just_symbol': 'just_symbol', # noqa: E501 + 'array_enum': 'array_enum' # noqa: E501 } - def __init__(self, just_symbol=None, array_enum=None): # noqa: E501 - """EnumArrays - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """EnumArrays - 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 False + _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 + _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. + just_symbol (str): [optional] # noqa: E501 + array_enum ([(str,)]): [optional] # noqa: E501 + """ - self._just_symbol = None - self._array_enum = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) - if just_symbol is not None: - self.just_symbol = just_symbol - if array_enum is not None: - self.array_enum = array_enum + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def just_symbol(self): """Gets the just_symbol of this EnumArrays. # noqa: E501 - :return: The just_symbol of this EnumArrays. # noqa: E501 - :rtype: str + Returns: + (str): The just_symbol of this EnumArrays. # noqa: E501 """ - return self._just_symbol + return self._data_store.get('just_symbol') @just_symbol.setter - def just_symbol(self, just_symbol): + def just_symbol( + self, just_symbol): """Sets the just_symbol of this EnumArrays. - :param just_symbol: The just_symbol of this EnumArrays. # noqa: E501 - :type: str + Returns: + (str): The just_symbol of this EnumArrays. # noqa: E501 """ allowed_values = [">=", "$"] # noqa: E501 if just_symbol not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `just_symbol` ({0}), must be one of {1}" # noqa: E501 .format(just_symbol, allowed_values) ) - self._just_symbol = just_symbol + self.__setitem__( + 'just_symbol', + just_symbol + ) @property def array_enum(self): """Gets the array_enum of this EnumArrays. # noqa: E501 - :return: The array_enum of this EnumArrays. # noqa: E501 - :rtype: list[str] + Returns: + ([(str,)]): The array_enum of this EnumArrays. # noqa: E501 """ - return self._array_enum + return self._data_store.get('array_enum') @array_enum.setter - def array_enum(self, array_enum): + def array_enum( + self, array_enum): """Sets the array_enum of this EnumArrays. - :param array_enum: The array_enum of this EnumArrays. # noqa: E501 - :type: list[str] + Returns: + ([(str,)]): The array_enum of this EnumArrays. # noqa: E501 """ allowed_values = ["fish", "crab"] # noqa: E501 if not set(array_enum).issubset(set(allowed_values)): - raise ValueError( + raise ApiValueError( "Invalid values for `array_enum` [{0}], must be a subset of [{1}]" # noqa: E501 .format(", ".join(map(str, set(array_enum) - set(allowed_values))), # noqa: E501 ", ".join(map(str, allowed_values))) ) - self._array_enum = array_enum + self.__setitem__( + 'array_enum', + array_enum + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/enum_class.py b/samples/openapi3/client/petstore/python/petstore_api/models/enum_class.py index 182197d8aa6e..67731827fc1c 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/enum_class.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/enum_class.py @@ -15,8 +15,27 @@ import six - -class EnumClass(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class EnumClass(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -34,42 +53,107 @@ class EnumClass(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { } - attribute_map = { } - def __init__(self): # noqa: E501 - """EnumClass - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """EnumClass - 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 False + _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 + _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. + """ + + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py b/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py index 82c7e3ee002f..dcdf1c64919b 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/enum_test.py @@ -15,8 +15,31 @@ import six - -class EnumTest(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.outer_enum import OuterEnum +from petstore_api.models.outer_enum_default_value import OuterEnumDefaultValue +from petstore_api.models.outer_enum_integer import OuterEnumInteger +from petstore_api.models.outer_enum_integer_default_value import OuterEnumIntegerDefaultValue + + +class EnumTest(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,277 +50,359 @@ class EnumTest(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'enum_string': 'str', - 'enum_string_required': 'str', - 'enum_integer': 'int', - 'enum_number': 'float', - 'outer_enum': 'OuterEnum', - 'outer_enum_integer': 'OuterEnumInteger', - 'outer_enum_default_value': 'OuterEnumDefaultValue', - 'outer_enum_integer_default_value': 'OuterEnumIntegerDefaultValue' + 'enum_string': [str], # noqa: E501 + 'enum_string_required': [str], # noqa: E501 + 'enum_integer': [int], # noqa: E501 + 'enum_number': [float], # noqa: E501 + 'outer_enum': [OuterEnum], # noqa: E501 + 'outer_enum_integer': [OuterEnumInteger], # noqa: E501 + 'outer_enum_default_value': [OuterEnumDefaultValue], # noqa: E501 + 'outer_enum_integer_default_value': [OuterEnumIntegerDefaultValue] # noqa: E501 } - attribute_map = { - 'enum_string': 'enum_string', - 'enum_string_required': 'enum_string_required', - 'enum_integer': 'enum_integer', - 'enum_number': 'enum_number', - 'outer_enum': 'outerEnum', - 'outer_enum_integer': 'outerEnumInteger', - 'outer_enum_default_value': 'outerEnumDefaultValue', - 'outer_enum_integer_default_value': 'outerEnumIntegerDefaultValue' + 'enum_string': 'enum_string', # noqa: E501 + 'enum_string_required': 'enum_string_required', # noqa: E501 + 'enum_integer': 'enum_integer', # noqa: E501 + 'enum_number': 'enum_number', # noqa: E501 + 'outer_enum': 'outerEnum', # noqa: E501 + 'outer_enum_integer': 'outerEnumInteger', # noqa: E501 + 'outer_enum_default_value': 'outerEnumDefaultValue', # noqa: E501 + 'outer_enum_integer_default_value': 'outerEnumIntegerDefaultValue' # noqa: E501 } - def __init__(self, enum_string=None, enum_string_required=None, enum_integer=None, enum_number=None, outer_enum=None, outer_enum_integer=None, outer_enum_default_value=None, outer_enum_integer_default_value=None): # noqa: E501 - """EnumTest - a model defined in OpenAPI""" # noqa: E501 - - self._enum_string = None - self._enum_string_required = None - self._enum_integer = None - self._enum_number = None - self._outer_enum = None - self._outer_enum_integer = None - self._outer_enum_default_value = None - self._outer_enum_integer_default_value = None + def __init__(self, enum_string_required, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """EnumTest - a model defined in OpenAPI + + Args: + enum_string_required (str): + + 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 False + _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 + _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. + enum_string (str): [optional] # noqa: E501 + enum_integer (int): [optional] # noqa: E501 + enum_number (float): [optional] # noqa: E501 + outer_enum (OuterEnum): [optional] # noqa: E501 + outer_enum_integer (OuterEnumInteger): [optional] # noqa: E501 + outer_enum_default_value (OuterEnumDefaultValue): [optional] # noqa: E501 + outer_enum_integer_default_value (OuterEnumIntegerDefaultValue): [optional] # noqa: E501 + """ + + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration - if enum_string is not None: - self.enum_string = enum_string + # assign using .var_name to check against nullable and enums self.enum_string_required = enum_string_required - if enum_integer is not None: - self.enum_integer = enum_integer - if enum_number is not None: - self.enum_number = enum_number - if outer_enum is not None: - self.outer_enum = outer_enum - if outer_enum_integer is not None: - self.outer_enum_integer = outer_enum_integer - if outer_enum_default_value is not None: - self.outer_enum_default_value = outer_enum_default_value - if outer_enum_integer_default_value is not None: - self.outer_enum_integer_default_value = outer_enum_integer_default_value + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def enum_string(self): """Gets the enum_string of this EnumTest. # noqa: E501 - :return: The enum_string of this EnumTest. # noqa: E501 - :rtype: str + Returns: + (str): The enum_string of this EnumTest. # noqa: E501 """ - return self._enum_string + return self._data_store.get('enum_string') @enum_string.setter - def enum_string(self, enum_string): + def enum_string( + self, enum_string): """Sets the enum_string of this EnumTest. - :param enum_string: The enum_string of this EnumTest. # noqa: E501 - :type: str + Returns: + (str): The enum_string of this EnumTest. # noqa: E501 """ allowed_values = ["UPPER", "lower", ""] # noqa: E501 if enum_string not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `enum_string` ({0}), must be one of {1}" # noqa: E501 .format(enum_string, allowed_values) ) - self._enum_string = enum_string + self.__setitem__( + 'enum_string', + enum_string + ) @property def enum_string_required(self): """Gets the enum_string_required of this EnumTest. # noqa: E501 - :return: The enum_string_required of this EnumTest. # noqa: E501 - :rtype: str + Returns: + (str): The enum_string_required of this EnumTest. # noqa: E501 """ - return self._enum_string_required + return self._data_store.get('enum_string_required') @enum_string_required.setter - def enum_string_required(self, enum_string_required): + def enum_string_required( + self, enum_string_required): """Sets the enum_string_required of this EnumTest. - :param enum_string_required: The enum_string_required of this EnumTest. # noqa: E501 - :type: str + Returns: + (str): The enum_string_required of this EnumTest. # noqa: E501 """ if enum_string_required is None: - raise ValueError("Invalid value for `enum_string_required`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `enum_string_required`, must not be `None`") # noqa: E501 allowed_values = ["UPPER", "lower", ""] # noqa: E501 if enum_string_required not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `enum_string_required` ({0}), must be one of {1}" # noqa: E501 .format(enum_string_required, allowed_values) ) - self._enum_string_required = enum_string_required + self.__setitem__( + 'enum_string_required', + enum_string_required + ) @property def enum_integer(self): """Gets the enum_integer of this EnumTest. # noqa: E501 - :return: The enum_integer of this EnumTest. # noqa: E501 - :rtype: int + Returns: + (int): The enum_integer of this EnumTest. # noqa: E501 """ - return self._enum_integer + return self._data_store.get('enum_integer') @enum_integer.setter - def enum_integer(self, enum_integer): + def enum_integer( + self, enum_integer): """Sets the enum_integer of this EnumTest. - :param enum_integer: The enum_integer of this EnumTest. # noqa: E501 - :type: int + Returns: + (int): The enum_integer of this EnumTest. # noqa: E501 """ allowed_values = [1, -1] # noqa: E501 if enum_integer not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `enum_integer` ({0}), must be one of {1}" # noqa: E501 .format(enum_integer, allowed_values) ) - self._enum_integer = enum_integer + self.__setitem__( + 'enum_integer', + enum_integer + ) @property def enum_number(self): """Gets the enum_number of this EnumTest. # noqa: E501 - :return: The enum_number of this EnumTest. # noqa: E501 - :rtype: float + Returns: + (float): The enum_number of this EnumTest. # noqa: E501 """ - return self._enum_number + return self._data_store.get('enum_number') @enum_number.setter - def enum_number(self, enum_number): + def enum_number( + self, enum_number): """Sets the enum_number of this EnumTest. - :param enum_number: The enum_number of this EnumTest. # noqa: E501 - :type: float + Returns: + (float): The enum_number of this EnumTest. # noqa: E501 """ allowed_values = [1.1, -1.2] # noqa: E501 if enum_number not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `enum_number` ({0}), must be one of {1}" # noqa: E501 .format(enum_number, allowed_values) ) - self._enum_number = enum_number + self.__setitem__( + 'enum_number', + enum_number + ) @property def outer_enum(self): """Gets the outer_enum of this EnumTest. # noqa: E501 - :return: The outer_enum of this EnumTest. # noqa: E501 - :rtype: OuterEnum + Returns: + (OuterEnum): The outer_enum of this EnumTest. # noqa: E501 """ - return self._outer_enum + return self._data_store.get('outer_enum') @outer_enum.setter - def outer_enum(self, outer_enum): + def outer_enum( + self, outer_enum): """Sets the outer_enum of this EnumTest. - :param outer_enum: The outer_enum of this EnumTest. # noqa: E501 - :type: OuterEnum + Returns: + (OuterEnum): The outer_enum of this EnumTest. # noqa: E501 """ - self._outer_enum = outer_enum + self.__setitem__( + 'outer_enum', + outer_enum + ) @property def outer_enum_integer(self): """Gets the outer_enum_integer of this EnumTest. # noqa: E501 - :return: The outer_enum_integer of this EnumTest. # noqa: E501 - :rtype: OuterEnumInteger + Returns: + (OuterEnumInteger): The outer_enum_integer of this EnumTest. # noqa: E501 """ - return self._outer_enum_integer + return self._data_store.get('outer_enum_integer') @outer_enum_integer.setter - def outer_enum_integer(self, outer_enum_integer): + def outer_enum_integer( + self, outer_enum_integer): """Sets the outer_enum_integer of this EnumTest. - :param outer_enum_integer: The outer_enum_integer of this EnumTest. # noqa: E501 - :type: OuterEnumInteger + Returns: + (OuterEnumInteger): The outer_enum_integer of this EnumTest. # noqa: E501 """ - self._outer_enum_integer = outer_enum_integer + self.__setitem__( + 'outer_enum_integer', + outer_enum_integer + ) @property def outer_enum_default_value(self): """Gets the outer_enum_default_value of this EnumTest. # noqa: E501 - :return: The outer_enum_default_value of this EnumTest. # noqa: E501 - :rtype: OuterEnumDefaultValue + Returns: + (OuterEnumDefaultValue): The outer_enum_default_value of this EnumTest. # noqa: E501 """ - return self._outer_enum_default_value + return self._data_store.get('outer_enum_default_value') @outer_enum_default_value.setter - def outer_enum_default_value(self, outer_enum_default_value): + def outer_enum_default_value( + self, outer_enum_default_value): """Sets the outer_enum_default_value of this EnumTest. - :param outer_enum_default_value: The outer_enum_default_value of this EnumTest. # noqa: E501 - :type: OuterEnumDefaultValue + Returns: + (OuterEnumDefaultValue): The outer_enum_default_value of this EnumTest. # noqa: E501 """ - self._outer_enum_default_value = outer_enum_default_value + self.__setitem__( + 'outer_enum_default_value', + outer_enum_default_value + ) @property def outer_enum_integer_default_value(self): """Gets the outer_enum_integer_default_value of this EnumTest. # noqa: E501 - :return: The outer_enum_integer_default_value of this EnumTest. # noqa: E501 - :rtype: OuterEnumIntegerDefaultValue + Returns: + (OuterEnumIntegerDefaultValue): The outer_enum_integer_default_value of this EnumTest. # noqa: E501 """ - return self._outer_enum_integer_default_value + return self._data_store.get('outer_enum_integer_default_value') @outer_enum_integer_default_value.setter - def outer_enum_integer_default_value(self, outer_enum_integer_default_value): + def outer_enum_integer_default_value( + self, outer_enum_integer_default_value): """Sets the outer_enum_integer_default_value of this EnumTest. - :param outer_enum_integer_default_value: The outer_enum_integer_default_value of this EnumTest. # noqa: E501 - :type: OuterEnumIntegerDefaultValue + Returns: + (OuterEnumIntegerDefaultValue): The outer_enum_integer_default_value of this EnumTest. # noqa: E501 """ - self._outer_enum_integer_default_value = outer_enum_integer_default_value + self.__setitem__( + 'outer_enum_integer_default_value', + outer_enum_integer_default_value + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/file.py b/samples/openapi3/client/petstore/python/petstore_api/models/file.py index 34d77c3b4cf8..3fdc580d4198 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/file.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/file.py @@ -15,8 +15,27 @@ import six - -class File(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class File(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,25 +46,106 @@ class File(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'source_uri': 'str' + 'source_uri': [str] # noqa: E501 } - attribute_map = { - 'source_uri': 'sourceURI' + 'source_uri': 'sourceURI' # noqa: E501 } - def __init__(self, source_uri=None): # noqa: E501 - """File - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """File - a model defined in OpenAPI - self._source_uri = None - self.discriminator = None - if source_uri is not None: - self.source_uri = source_uri + + 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 False + _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 + _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. + source_uri (str): Test capitalization. [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def source_uri(self): @@ -53,46 +153,30 @@ def source_uri(self): Test capitalization # noqa: E501 - :return: The source_uri of this File. # noqa: E501 - :rtype: str + Returns: + (str): The source_uri of this File. # noqa: E501 """ - return self._source_uri + return self._data_store.get('source_uri') @source_uri.setter - def source_uri(self, source_uri): + def source_uri( + self, source_uri): """Sets the source_uri of this File. Test capitalization # noqa: E501 - :param source_uri: The source_uri of this File. # noqa: E501 - :type: str + Returns: + (str): The source_uri of this File. # noqa: E501 """ - self._source_uri = source_uri + self.__setitem__( + 'source_uri', + source_uri + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/file_schema_test_class.py b/samples/openapi3/client/petstore/python/petstore_api/models/file_schema_test_class.py index 026822dee749..ed77661a5bfe 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/file_schema_test_class.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/file_schema_test_class.py @@ -15,8 +15,28 @@ import six - -class FileSchemaTestClass(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.file import File + + +class FileSchemaTestClass(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +47,163 @@ class FileSchemaTestClass(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'file': 'File', - 'files': 'list[File]' + 'file': [File], # noqa: E501 + 'files': [[(File,)]] # noqa: E501 } - attribute_map = { - 'file': 'file', - 'files': 'files' + 'file': 'file', # noqa: E501 + 'files': 'files' # noqa: E501 } - def __init__(self, file=None, files=None): # noqa: E501 - """FileSchemaTestClass - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """FileSchemaTestClass - 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 False + _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 + _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. + file (File): [optional] # noqa: E501 + files ([(File,)]): [optional] # noqa: E501 + """ - self._file = None - self._files = None + self._data_store = {} self.discriminator = None - - if file is not None: - self.file = file - if files is not None: - self.files = files + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def file(self): """Gets the file of this FileSchemaTestClass. # noqa: E501 - :return: The file of this FileSchemaTestClass. # noqa: E501 - :rtype: File + Returns: + (File): The file of this FileSchemaTestClass. # noqa: E501 """ - return self._file + return self._data_store.get('file') @file.setter - def file(self, file): + def file( + self, file): """Sets the file of this FileSchemaTestClass. - :param file: The file of this FileSchemaTestClass. # noqa: E501 - :type: File + Returns: + (File): The file of this FileSchemaTestClass. # noqa: E501 """ - self._file = file + self.__setitem__( + 'file', + file + ) @property def files(self): """Gets the files of this FileSchemaTestClass. # noqa: E501 - :return: The files of this FileSchemaTestClass. # noqa: E501 - :rtype: list[File] + Returns: + ([(File,)]): The files of this FileSchemaTestClass. # noqa: E501 """ - return self._files + return self._data_store.get('files') @files.setter - def files(self, files): + def files( + self, files): """Sets the files of this FileSchemaTestClass. - :param files: The files of this FileSchemaTestClass. # noqa: E501 - :type: list[File] + Returns: + ([(File,)]): The files of this FileSchemaTestClass. # noqa: E501 """ - self._files = files + self.__setitem__( + 'files', + files + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/foo.py b/samples/openapi3/client/petstore/python/petstore_api/models/foo.py index a34065b6cc2a..cd51f7673cfb 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/foo.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/foo.py @@ -15,8 +15,27 @@ import six - -class Foo(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Foo(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class Foo(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'bar': 'str' + 'bar': [str] # noqa: E501 } - attribute_map = { - 'bar': 'bar' + 'bar': 'bar' # noqa: E501 } - def __init__(self, bar='bar'): # noqa: E501 - """Foo - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Foo - a model defined in OpenAPI - self._bar = None - self.discriminator = None - if bar is not None: - self.bar = bar + + 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 False + _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 + _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. + bar (str): [optional] if omitted the server will use the default value of 'bar' # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def bar(self): """Gets the bar of this Foo. # noqa: E501 - :return: The bar of this Foo. # noqa: E501 - :rtype: str + Returns: + (str): The bar of this Foo. # noqa: E501 """ - return self._bar + return self._data_store.get('bar') @bar.setter - def bar(self, bar): + def bar( + self, bar): """Sets the bar of this Foo. - :param bar: The bar of this Foo. # noqa: E501 - :type: str + Returns: + (str): The bar of this Foo. # noqa: E501 """ - self._bar = bar + self.__setitem__( + 'bar', + bar + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/format_test.py b/samples/openapi3/client/petstore/python/petstore_api/models/format_test.py index 5e3eb721f124..87d4dd9aa736 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/format_test.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/format_test.py @@ -15,8 +15,27 @@ import six - -class FormatTest(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class FormatTest(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,398 +46,512 @@ class FormatTest(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'integer': 'int', - 'int32': 'int', - 'int64': 'int', - 'number': 'float', - 'float': 'float', - 'double': 'float', - 'string': 'str', - 'byte': 'str', - 'binary': 'file', - 'date': 'date', - 'date_time': 'datetime', - 'uuid': 'str', - 'password': 'str', - 'pattern_with_digits': 'str', - 'pattern_with_digits_and_delimiter': 'str' + 'integer': [int], # noqa: E501 + 'int32': [int], # noqa: E501 + 'int64': [int], # noqa: E501 + 'number': [float], # noqa: E501 + 'float': [float], # noqa: E501 + 'double': [float], # noqa: E501 + 'string': [str], # noqa: E501 + 'byte': [str], # noqa: E501 + 'binary': [file_type], # noqa: E501 + 'date': [date], # noqa: E501 + 'date_time': [datetime], # noqa: E501 + 'uuid': [str], # noqa: E501 + 'password': [str], # noqa: E501 + 'pattern_with_digits': [str], # noqa: E501 + 'pattern_with_digits_and_delimiter': [str] # noqa: E501 } - attribute_map = { - 'integer': 'integer', - 'int32': 'int32', - 'int64': 'int64', - 'number': 'number', - 'float': 'float', - 'double': 'double', - 'string': 'string', - 'byte': 'byte', - 'binary': 'binary', - 'date': 'date', - 'date_time': 'dateTime', - 'uuid': 'uuid', - 'password': 'password', - 'pattern_with_digits': 'pattern_with_digits', - 'pattern_with_digits_and_delimiter': 'pattern_with_digits_and_delimiter' + 'integer': 'integer', # noqa: E501 + 'int32': 'int32', # noqa: E501 + 'int64': 'int64', # noqa: E501 + 'number': 'number', # noqa: E501 + 'float': 'float', # noqa: E501 + 'double': 'double', # noqa: E501 + 'string': 'string', # noqa: E501 + 'byte': 'byte', # noqa: E501 + 'binary': 'binary', # noqa: E501 + 'date': 'date', # noqa: E501 + 'date_time': 'dateTime', # noqa: E501 + 'uuid': 'uuid', # noqa: E501 + 'password': 'password', # noqa: E501 + 'pattern_with_digits': 'pattern_with_digits', # noqa: E501 + 'pattern_with_digits_and_delimiter': 'pattern_with_digits_and_delimiter' # noqa: E501 } - def __init__(self, integer=None, int32=None, int64=None, number=None, float=None, double=None, string=None, byte=None, binary=None, date=None, date_time=None, uuid=None, password=None, pattern_with_digits=None, pattern_with_digits_and_delimiter=None): # noqa: E501 - """FormatTest - a model defined in OpenAPI""" # noqa: E501 - - self._integer = None - self._int32 = None - self._int64 = None - self._number = None - self._float = None - self._double = None - self._string = None - self._byte = None - self._binary = None - self._date = None - self._date_time = None - self._uuid = None - self._password = None - self._pattern_with_digits = None - self._pattern_with_digits_and_delimiter = None + def __init__(self, number, byte, date, password, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """FormatTest - a model defined in OpenAPI + + Args: + number (float): + byte (str): + date (date): + password (str): + + 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 False + _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 + _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. + integer (int): [optional] # noqa: E501 + int32 (int): [optional] # noqa: E501 + int64 (int): [optional] # noqa: E501 + float (float): [optional] # noqa: E501 + double (float): [optional] # noqa: E501 + string (str): [optional] # noqa: E501 + binary (file_type): [optional] # noqa: E501 + date_time (datetime): [optional] # noqa: E501 + uuid (str): [optional] # noqa: E501 + pattern_with_digits (str): A string that is a 10 digit number. Can have leading zeros.. [optional] # noqa: E501 + pattern_with_digits_and_delimiter (str): A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01.. [optional] # noqa: E501 + """ + + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration - if integer is not None: - self.integer = integer - if int32 is not None: - self.int32 = int32 - if int64 is not None: - self.int64 = int64 + # assign using .var_name to check against nullable and enums self.number = number - if float is not None: - self.float = float - if double is not None: - self.double = double - if string is not None: - self.string = string self.byte = byte - if binary is not None: - self.binary = binary self.date = date - if date_time is not None: - self.date_time = date_time - if uuid is not None: - self.uuid = uuid self.password = password - if pattern_with_digits is not None: - self.pattern_with_digits = pattern_with_digits - if pattern_with_digits_and_delimiter is not None: - self.pattern_with_digits_and_delimiter = pattern_with_digits_and_delimiter + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def integer(self): """Gets the integer of this FormatTest. # noqa: E501 - :return: The integer of this FormatTest. # noqa: E501 - :rtype: int + Returns: + (int): The integer of this FormatTest. # noqa: E501 """ - return self._integer + return self._data_store.get('integer') @integer.setter - def integer(self, integer): + def integer( + self, integer): """Sets the integer of this FormatTest. - :param integer: The integer of this FormatTest. # noqa: E501 - :type: int + Returns: + (int): The integer of this FormatTest. # noqa: E501 """ if integer is not None and integer > 100: # noqa: E501 - raise ValueError("Invalid value for `integer`, must be a value less than or equal to `100`") # noqa: E501 + raise ApiValueError("Invalid value for `integer`, must be a value less than or equal to `100`") # noqa: E501 if integer is not None and integer < 10: # noqa: E501 - raise ValueError("Invalid value for `integer`, must be a value greater than or equal to `10`") # noqa: E501 + raise ApiValueError("Invalid value for `integer`, must be a value greater than or equal to `10`") # noqa: E501 - self._integer = integer + self.__setitem__( + 'integer', + integer + ) @property def int32(self): """Gets the int32 of this FormatTest. # noqa: E501 - :return: The int32 of this FormatTest. # noqa: E501 - :rtype: int + Returns: + (int): The int32 of this FormatTest. # noqa: E501 """ - return self._int32 + return self._data_store.get('int32') @int32.setter - def int32(self, int32): + def int32( + self, int32): """Sets the int32 of this FormatTest. - :param int32: The int32 of this FormatTest. # noqa: E501 - :type: int + Returns: + (int): The int32 of this FormatTest. # noqa: E501 """ if int32 is not None and int32 > 200: # noqa: E501 - raise ValueError("Invalid value for `int32`, must be a value less than or equal to `200`") # noqa: E501 + raise ApiValueError("Invalid value for `int32`, must be a value less than or equal to `200`") # noqa: E501 if int32 is not None and int32 < 20: # noqa: E501 - raise ValueError("Invalid value for `int32`, must be a value greater than or equal to `20`") # noqa: E501 + raise ApiValueError("Invalid value for `int32`, must be a value greater than or equal to `20`") # noqa: E501 - self._int32 = int32 + self.__setitem__( + 'int32', + int32 + ) @property def int64(self): """Gets the int64 of this FormatTest. # noqa: E501 - :return: The int64 of this FormatTest. # noqa: E501 - :rtype: int + Returns: + (int): The int64 of this FormatTest. # noqa: E501 """ - return self._int64 + return self._data_store.get('int64') @int64.setter - def int64(self, int64): + def int64( + self, int64): """Sets the int64 of this FormatTest. - :param int64: The int64 of this FormatTest. # noqa: E501 - :type: int + Returns: + (int): The int64 of this FormatTest. # noqa: E501 """ - self._int64 = int64 + self.__setitem__( + 'int64', + int64 + ) @property def number(self): """Gets the number of this FormatTest. # noqa: E501 - :return: The number of this FormatTest. # noqa: E501 - :rtype: float + Returns: + (float): The number of this FormatTest. # noqa: E501 """ - return self._number + return self._data_store.get('number') @number.setter - def number(self, number): + def number( + self, number): """Sets the number of this FormatTest. - :param number: The number of this FormatTest. # noqa: E501 - :type: float + Returns: + (float): The number of this FormatTest. # noqa: E501 """ if number is None: - raise ValueError("Invalid value for `number`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `number`, must not be `None`") # noqa: E501 if number is not None and number > 543.2: # noqa: E501 - raise ValueError("Invalid value for `number`, must be a value less than or equal to `543.2`") # noqa: E501 + raise ApiValueError("Invalid value for `number`, must be a value less than or equal to `543.2`") # noqa: E501 if number is not None and number < 32.1: # noqa: E501 - raise ValueError("Invalid value for `number`, must be a value greater than or equal to `32.1`") # noqa: E501 + raise ApiValueError("Invalid value for `number`, must be a value greater than or equal to `32.1`") # noqa: E501 - self._number = number + self.__setitem__( + 'number', + number + ) @property def float(self): """Gets the float of this FormatTest. # noqa: E501 - :return: The float of this FormatTest. # noqa: E501 - :rtype: float + Returns: + (float): The float of this FormatTest. # noqa: E501 """ - return self._float + return self._data_store.get('float') @float.setter - def float(self, float): + def float( + self, float): """Sets the float of this FormatTest. - :param float: The float of this FormatTest. # noqa: E501 - :type: float + Returns: + (float): The float of this FormatTest. # noqa: E501 """ if float is not None and float > 987.6: # noqa: E501 - raise ValueError("Invalid value for `float`, must be a value less than or equal to `987.6`") # noqa: E501 + raise ApiValueError("Invalid value for `float`, must be a value less than or equal to `987.6`") # noqa: E501 if float is not None and float < 54.3: # noqa: E501 - raise ValueError("Invalid value for `float`, must be a value greater than or equal to `54.3`") # noqa: E501 + raise ApiValueError("Invalid value for `float`, must be a value greater than or equal to `54.3`") # noqa: E501 - self._float = float + self.__setitem__( + 'float', + float + ) @property def double(self): """Gets the double of this FormatTest. # noqa: E501 - :return: The double of this FormatTest. # noqa: E501 - :rtype: float + Returns: + (float): The double of this FormatTest. # noqa: E501 """ - return self._double + return self._data_store.get('double') @double.setter - def double(self, double): + def double( + self, double): """Sets the double of this FormatTest. - :param double: The double of this FormatTest. # noqa: E501 - :type: float + Returns: + (float): The double of this FormatTest. # noqa: E501 """ if double is not None and double > 123.4: # noqa: E501 - raise ValueError("Invalid value for `double`, must be a value less than or equal to `123.4`") # noqa: E501 + raise ApiValueError("Invalid value for `double`, must be a value less than or equal to `123.4`") # noqa: E501 if double is not None and double < 67.8: # noqa: E501 - raise ValueError("Invalid value for `double`, must be a value greater than or equal to `67.8`") # noqa: E501 + raise ApiValueError("Invalid value for `double`, must be a value greater than or equal to `67.8`") # noqa: E501 - self._double = double + self.__setitem__( + 'double', + double + ) @property def string(self): """Gets the string of this FormatTest. # noqa: E501 - :return: The string of this FormatTest. # noqa: E501 - :rtype: str + Returns: + (str): The string of this FormatTest. # noqa: E501 """ - return self._string + return self._data_store.get('string') @string.setter - def string(self, string): + def string( + self, string): """Sets the string of this FormatTest. - :param string: The string of this FormatTest. # noqa: E501 - :type: str + Returns: + (str): The string of this FormatTest. # noqa: E501 """ - if string is not None and not re.search(r'[a-z]', string, flags=re.IGNORECASE): # noqa: E501 - raise ValueError(r"Invalid value for `string`, must be a follow pattern or equal to `/[a-z]/i`") # noqa: E501 + if string is not None and not re.search(r'', string): # noqa: E501 + raise ApiValueError(r"Invalid value for `string`, must be a follow pattern or equal to `/[a-z]/i`") # noqa: E501 - self._string = string + self.__setitem__( + 'string', + string + ) @property def byte(self): """Gets the byte of this FormatTest. # noqa: E501 - :return: The byte of this FormatTest. # noqa: E501 - :rtype: str + Returns: + (str): The byte of this FormatTest. # noqa: E501 """ - return self._byte + return self._data_store.get('byte') @byte.setter - def byte(self, byte): + def byte( + self, byte): """Sets the byte of this FormatTest. - :param byte: The byte of this FormatTest. # noqa: E501 - :type: str + Returns: + (str): The byte of this FormatTest. # noqa: E501 """ if byte is None: - raise ValueError("Invalid value for `byte`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `byte`, must not be `None`") # noqa: E501 - self._byte = byte + self.__setitem__( + 'byte', + byte + ) @property def binary(self): """Gets the binary of this FormatTest. # noqa: E501 - :return: The binary of this FormatTest. # noqa: E501 - :rtype: file + Returns: + (file_type): The binary of this FormatTest. # noqa: E501 """ - return self._binary + return self._data_store.get('binary') @binary.setter - def binary(self, binary): + def binary( + self, binary): """Sets the binary of this FormatTest. - :param binary: The binary of this FormatTest. # noqa: E501 - :type: file + Returns: + (file_type): The binary of this FormatTest. # noqa: E501 """ - self._binary = binary + self.__setitem__( + 'binary', + binary + ) @property def date(self): """Gets the date of this FormatTest. # noqa: E501 - :return: The date of this FormatTest. # noqa: E501 - :rtype: date + Returns: + (date): The date of this FormatTest. # noqa: E501 """ - return self._date + return self._data_store.get('date') @date.setter - def date(self, date): + def date( + self, date): """Sets the date of this FormatTest. - :param date: The date of this FormatTest. # noqa: E501 - :type: date + Returns: + (date): The date of this FormatTest. # noqa: E501 """ if date is None: - raise ValueError("Invalid value for `date`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `date`, must not be `None`") # noqa: E501 - self._date = date + self.__setitem__( + 'date', + date + ) @property def date_time(self): """Gets the date_time of this FormatTest. # noqa: E501 - :return: The date_time of this FormatTest. # noqa: E501 - :rtype: datetime + Returns: + (datetime): The date_time of this FormatTest. # noqa: E501 """ - return self._date_time + return self._data_store.get('date_time') @date_time.setter - def date_time(self, date_time): + def date_time( + self, date_time): """Sets the date_time of this FormatTest. - :param date_time: The date_time of this FormatTest. # noqa: E501 - :type: datetime + Returns: + (datetime): The date_time of this FormatTest. # noqa: E501 """ - self._date_time = date_time + self.__setitem__( + 'date_time', + date_time + ) @property def uuid(self): """Gets the uuid of this FormatTest. # noqa: E501 - :return: The uuid of this FormatTest. # noqa: E501 - :rtype: str + Returns: + (str): The uuid of this FormatTest. # noqa: E501 """ - return self._uuid + return self._data_store.get('uuid') @uuid.setter - def uuid(self, uuid): + def uuid( + self, uuid): """Sets the uuid of this FormatTest. - :param uuid: The uuid of this FormatTest. # noqa: E501 - :type: str + Returns: + (str): The uuid of this FormatTest. # noqa: E501 """ - self._uuid = uuid + self.__setitem__( + 'uuid', + uuid + ) @property def password(self): """Gets the password of this FormatTest. # noqa: E501 - :return: The password of this FormatTest. # noqa: E501 - :rtype: str + Returns: + (str): The password of this FormatTest. # noqa: E501 """ - return self._password + return self._data_store.get('password') @password.setter - def password(self, password): + def password( + self, password): """Sets the password of this FormatTest. - :param password: The password of this FormatTest. # noqa: E501 - :type: str + Returns: + (str): The password of this FormatTest. # noqa: E501 """ if password is None: - raise ValueError("Invalid value for `password`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `password`, must not be `None`") # noqa: E501 if password is not None and len(password) > 64: - raise ValueError("Invalid value for `password`, length must be less than or equal to `64`") # noqa: E501 + raise ApiValueError("Invalid value for `password`, length must be less than or equal to `64`") # noqa: E501 if password is not None and len(password) < 10: - raise ValueError("Invalid value for `password`, length must be greater than or equal to `10`") # noqa: E501 + raise ApiValueError("Invalid value for `password`, length must be greater than or equal to `10`") # noqa: E501 - self._password = password + self.__setitem__( + 'password', + password + ) @property def pattern_with_digits(self): @@ -426,24 +559,28 @@ def pattern_with_digits(self): A string that is a 10 digit number. Can have leading zeros. # noqa: E501 - :return: The pattern_with_digits of this FormatTest. # noqa: E501 - :rtype: str + Returns: + (str): The pattern_with_digits of this FormatTest. # noqa: E501 """ - return self._pattern_with_digits + return self._data_store.get('pattern_with_digits') @pattern_with_digits.setter - def pattern_with_digits(self, pattern_with_digits): + def pattern_with_digits( + self, pattern_with_digits): """Sets the pattern_with_digits of this FormatTest. A string that is a 10 digit number. Can have leading zeros. # noqa: E501 - :param pattern_with_digits: The pattern_with_digits of this FormatTest. # noqa: E501 - :type: str + Returns: + (str): The pattern_with_digits of this FormatTest. # noqa: E501 """ - if pattern_with_digits is not None and not re.search(r'^\d{10}$', pattern_with_digits): # noqa: E501 - raise ValueError(r"Invalid value for `pattern_with_digits`, must be a follow pattern or equal to `/^\d{10}$/`") # noqa: E501 + if pattern_with_digits is not None and not re.search(r'', pattern_with_digits): # noqa: E501 + raise ApiValueError(r"Invalid value for `pattern_with_digits`, must be a follow pattern or equal to `/^\d{10}$/`") # noqa: E501 - self._pattern_with_digits = pattern_with_digits + self.__setitem__( + 'pattern_with_digits', + pattern_with_digits + ) @property def pattern_with_digits_and_delimiter(self): @@ -451,48 +588,32 @@ def pattern_with_digits_and_delimiter(self): A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01. # noqa: E501 - :return: The pattern_with_digits_and_delimiter of this FormatTest. # noqa: E501 - :rtype: str + Returns: + (str): The pattern_with_digits_and_delimiter of this FormatTest. # noqa: E501 """ - return self._pattern_with_digits_and_delimiter + return self._data_store.get('pattern_with_digits_and_delimiter') @pattern_with_digits_and_delimiter.setter - def pattern_with_digits_and_delimiter(self, pattern_with_digits_and_delimiter): + def pattern_with_digits_and_delimiter( + self, pattern_with_digits_and_delimiter): """Sets the pattern_with_digits_and_delimiter of this FormatTest. A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01. # noqa: E501 - :param pattern_with_digits_and_delimiter: The pattern_with_digits_and_delimiter of this FormatTest. # noqa: E501 - :type: str + Returns: + (str): The pattern_with_digits_and_delimiter of this FormatTest. # noqa: E501 """ - if pattern_with_digits_and_delimiter is not None and not re.search(r'^image_\d{1,3}$', pattern_with_digits_and_delimiter, flags=re.IGNORECASE): # noqa: E501 - raise ValueError(r"Invalid value for `pattern_with_digits_and_delimiter`, must be a follow pattern or equal to `/^image_\d{1,3}$/i`") # noqa: E501 + if pattern_with_digits_and_delimiter is not None and not re.search(r'', pattern_with_digits_and_delimiter): # noqa: E501 + raise ApiValueError(r"Invalid value for `pattern_with_digits_and_delimiter`, must be a follow pattern or equal to `/^image_\d{1,3}$/i`") # noqa: E501 - self._pattern_with_digits_and_delimiter = pattern_with_digits_and_delimiter + self.__setitem__( + 'pattern_with_digits_and_delimiter', + pattern_with_digits_and_delimiter + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/has_only_read_only.py b/samples/openapi3/client/petstore/python/petstore_api/models/has_only_read_only.py index 41db3ff71958..eeff7da1fbaf 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/has_only_read_only.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/has_only_read_only.py @@ -15,8 +15,27 @@ import six - -class HasOnlyReadOnly(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class HasOnlyReadOnly(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +46,163 @@ class HasOnlyReadOnly(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'bar': 'str', - 'foo': 'str' + 'bar': [str], # noqa: E501 + 'foo': [str] # noqa: E501 } - attribute_map = { - 'bar': 'bar', - 'foo': 'foo' + 'bar': 'bar', # noqa: E501 + 'foo': 'foo' # noqa: E501 } - def __init__(self, bar=None, foo=None): # noqa: E501 - """HasOnlyReadOnly - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """HasOnlyReadOnly - 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 False + _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 + _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. + bar (str): [optional] # noqa: E501 + foo (str): [optional] # noqa: E501 + """ - self._bar = None - self._foo = None + self._data_store = {} self.discriminator = None - - if bar is not None: - self.bar = bar - if foo is not None: - self.foo = foo + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def bar(self): """Gets the bar of this HasOnlyReadOnly. # noqa: E501 - :return: The bar of this HasOnlyReadOnly. # noqa: E501 - :rtype: str + Returns: + (str): The bar of this HasOnlyReadOnly. # noqa: E501 """ - return self._bar + return self._data_store.get('bar') @bar.setter - def bar(self, bar): + def bar( + self, bar): """Sets the bar of this HasOnlyReadOnly. - :param bar: The bar of this HasOnlyReadOnly. # noqa: E501 - :type: str + Returns: + (str): The bar of this HasOnlyReadOnly. # noqa: E501 """ - self._bar = bar + self.__setitem__( + 'bar', + bar + ) @property def foo(self): """Gets the foo of this HasOnlyReadOnly. # noqa: E501 - :return: The foo of this HasOnlyReadOnly. # noqa: E501 - :rtype: str + Returns: + (str): The foo of this HasOnlyReadOnly. # noqa: E501 """ - return self._foo + return self._data_store.get('foo') @foo.setter - def foo(self, foo): + def foo( + self, foo): """Sets the foo of this HasOnlyReadOnly. - :param foo: The foo of this HasOnlyReadOnly. # noqa: E501 - :type: str + Returns: + (str): The foo of this HasOnlyReadOnly. # noqa: E501 """ - self._foo = foo + self.__setitem__( + 'foo', + foo + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/health_check_result.py b/samples/openapi3/client/petstore/python/petstore_api/models/health_check_result.py index cf091b3db7bc..03b02f530da3 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/health_check_result.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/health_check_result.py @@ -15,8 +15,27 @@ import six - -class HealthCheckResult(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class HealthCheckResult(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,69 +46,135 @@ class HealthCheckResult(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'nullable_message': 'str' + 'nullable_message': [str, none_type] # noqa: E501 } - attribute_map = { - 'nullable_message': 'NullableMessage' + 'nullable_message': 'NullableMessage' # noqa: E501 } - def __init__(self, nullable_message=None): # noqa: E501 - """HealthCheckResult - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """HealthCheckResult - a model defined in OpenAPI - self._nullable_message = None - self.discriminator = None - self.nullable_message = nullable_message + + 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 False + _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 + _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. + nullable_message (str, none_type): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def nullable_message(self): """Gets the nullable_message of this HealthCheckResult. # noqa: E501 - :return: The nullable_message of this HealthCheckResult. # noqa: E501 - :rtype: str + Returns: + (str, none_type): The nullable_message of this HealthCheckResult. # noqa: E501 """ - return self._nullable_message + return self._data_store.get('nullable_message') @nullable_message.setter - def nullable_message(self, nullable_message): + def nullable_message( + self, nullable_message): """Sets the nullable_message of this HealthCheckResult. - :param nullable_message: The nullable_message of this HealthCheckResult. # noqa: E501 - :type: str + Returns: + (str, none_type): The nullable_message of this HealthCheckResult. # noqa: E501 """ - self._nullable_message = nullable_message + self.__setitem__( + 'nullable_message', + nullable_message + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/inline_object.py b/samples/openapi3/client/petstore/python/petstore_api/models/inline_object.py index 290c0f211d5b..7a22b109dee6 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/inline_object.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/inline_object.py @@ -15,8 +15,27 @@ import six - -class InlineObject(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class InlineObject(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,30 +46,109 @@ class InlineObject(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'name': 'str', - 'status': 'str' + 'name': [str], # noqa: E501 + 'status': [str] # noqa: E501 } - attribute_map = { - 'name': 'name', - 'status': 'status' + 'name': 'name', # noqa: E501 + 'status': 'status' # noqa: E501 } - def __init__(self, name=None, status=None): # noqa: E501 - """InlineObject - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """InlineObject - 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 False + _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 + _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. + name (str): Updated name of the pet. [optional] # noqa: E501 + status (str): Updated status of the pet. [optional] # noqa: E501 + """ - self._name = None - self._status = None + self._data_store = {} self.discriminator = None - - if name is not None: - self.name = name - if status is not None: - self.status = status + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def name(self): @@ -58,22 +156,26 @@ def name(self): Updated name of the pet # noqa: E501 - :return: The name of this InlineObject. # noqa: E501 - :rtype: str + Returns: + (str): The name of this InlineObject. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this InlineObject. Updated name of the pet # noqa: E501 - :param name: The name of this InlineObject. # noqa: E501 - :type: str + Returns: + (str): The name of this InlineObject. # noqa: E501 """ - self._name = name + self.__setitem__( + 'name', + name + ) @property def status(self): @@ -81,46 +183,30 @@ def status(self): Updated status of the pet # noqa: E501 - :return: The status of this InlineObject. # noqa: E501 - :rtype: str + Returns: + (str): The status of this InlineObject. # noqa: E501 """ - return self._status + return self._data_store.get('status') @status.setter - def status(self, status): + def status( + self, status): """Sets the status of this InlineObject. Updated status of the pet # noqa: E501 - :param status: The status of this InlineObject. # noqa: E501 - :type: str + Returns: + (str): The status of this InlineObject. # noqa: E501 """ - self._status = status + self.__setitem__( + 'status', + status + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/inline_object1.py b/samples/openapi3/client/petstore/python/petstore_api/models/inline_object1.py index d24a6947f1c6..7f5d94e5f396 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/inline_object1.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/inline_object1.py @@ -15,8 +15,27 @@ import six - -class InlineObject1(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class InlineObject1(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,30 +46,109 @@ class InlineObject1(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'additional_metadata': 'str', - 'file': 'file' + 'additional_metadata': [str], # noqa: E501 + 'file': [file_type] # noqa: E501 } - attribute_map = { - 'additional_metadata': 'additionalMetadata', - 'file': 'file' + 'additional_metadata': 'additionalMetadata', # noqa: E501 + 'file': 'file' # noqa: E501 } - def __init__(self, additional_metadata=None, file=None): # noqa: E501 - """InlineObject1 - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """InlineObject1 - 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 False + _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 + _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. + additional_metadata (str): Additional data to pass to server. [optional] # noqa: E501 + file (file_type): file to upload. [optional] # noqa: E501 + """ - self._additional_metadata = None - self._file = None + self._data_store = {} self.discriminator = None - - if additional_metadata is not None: - self.additional_metadata = additional_metadata - if file is not None: - self.file = file + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def additional_metadata(self): @@ -58,22 +156,26 @@ def additional_metadata(self): Additional data to pass to server # noqa: E501 - :return: The additional_metadata of this InlineObject1. # noqa: E501 - :rtype: str + Returns: + (str): The additional_metadata of this InlineObject1. # noqa: E501 """ - return self._additional_metadata + return self._data_store.get('additional_metadata') @additional_metadata.setter - def additional_metadata(self, additional_metadata): + def additional_metadata( + self, additional_metadata): """Sets the additional_metadata of this InlineObject1. Additional data to pass to server # noqa: E501 - :param additional_metadata: The additional_metadata of this InlineObject1. # noqa: E501 - :type: str + Returns: + (str): The additional_metadata of this InlineObject1. # noqa: E501 """ - self._additional_metadata = additional_metadata + self.__setitem__( + 'additional_metadata', + additional_metadata + ) @property def file(self): @@ -81,46 +183,30 @@ def file(self): file to upload # noqa: E501 - :return: The file of this InlineObject1. # noqa: E501 - :rtype: file + Returns: + (file_type): The file of this InlineObject1. # noqa: E501 """ - return self._file + return self._data_store.get('file') @file.setter - def file(self, file): + def file( + self, file): """Sets the file of this InlineObject1. file to upload # noqa: E501 - :param file: The file of this InlineObject1. # noqa: E501 - :type: file + Returns: + (file_type): The file of this InlineObject1. # noqa: E501 """ - self._file = file + self.__setitem__( + 'file', + file + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/inline_object2.py b/samples/openapi3/client/petstore/python/petstore_api/models/inline_object2.py index b6dffad6091d..f134f35c4f7e 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/inline_object2.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/inline_object2.py @@ -15,8 +15,27 @@ import six - -class InlineObject2(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class InlineObject2(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,30 +46,109 @@ class InlineObject2(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'enum_form_string_array': 'list[str]', - 'enum_form_string': 'str' + 'enum_form_string_array': [[(str,)]], # noqa: E501 + 'enum_form_string': [str] # noqa: E501 } - attribute_map = { - 'enum_form_string_array': 'enum_form_string_array', - 'enum_form_string': 'enum_form_string' + 'enum_form_string_array': 'enum_form_string_array', # noqa: E501 + 'enum_form_string': 'enum_form_string' # noqa: E501 } - def __init__(self, enum_form_string_array=None, enum_form_string='-efg'): # noqa: E501 - """InlineObject2 - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """InlineObject2 - 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 False + _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 + _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. + enum_form_string_array ([(str,)]): Form parameter enum test (string array). [optional] # noqa: E501 + enum_form_string (str): Form parameter enum test (string). [optional] if omitted the server will use the default value of '-efg' # noqa: E501 + """ - self._enum_form_string_array = None - self._enum_form_string = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) - if enum_form_string_array is not None: - self.enum_form_string_array = enum_form_string_array - if enum_form_string is not None: - self.enum_form_string = enum_form_string + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def enum_form_string_array(self): @@ -58,29 +156,33 @@ def enum_form_string_array(self): Form parameter enum test (string array) # noqa: E501 - :return: The enum_form_string_array of this InlineObject2. # noqa: E501 - :rtype: list[str] + Returns: + ([(str,)]): The enum_form_string_array of this InlineObject2. # noqa: E501 """ - return self._enum_form_string_array + return self._data_store.get('enum_form_string_array') @enum_form_string_array.setter - def enum_form_string_array(self, enum_form_string_array): + def enum_form_string_array( + self, enum_form_string_array): """Sets the enum_form_string_array of this InlineObject2. Form parameter enum test (string array) # noqa: E501 - :param enum_form_string_array: The enum_form_string_array of this InlineObject2. # noqa: E501 - :type: list[str] + Returns: + ([(str,)]): The enum_form_string_array of this InlineObject2. # noqa: E501 """ allowed_values = [">", "$"] # noqa: E501 if not set(enum_form_string_array).issubset(set(allowed_values)): - raise ValueError( + raise ApiValueError( "Invalid values for `enum_form_string_array` [{0}], must be a subset of [{1}]" # noqa: E501 .format(", ".join(map(str, set(enum_form_string_array) - set(allowed_values))), # noqa: E501 ", ".join(map(str, allowed_values))) ) - self._enum_form_string_array = enum_form_string_array + self.__setitem__( + 'enum_form_string_array', + enum_form_string_array + ) @property def enum_form_string(self): @@ -88,52 +190,36 @@ def enum_form_string(self): Form parameter enum test (string) # noqa: E501 - :return: The enum_form_string of this InlineObject2. # noqa: E501 - :rtype: str + Returns: + (str): The enum_form_string of this InlineObject2. # noqa: E501 """ - return self._enum_form_string + return self._data_store.get('enum_form_string') @enum_form_string.setter - def enum_form_string(self, enum_form_string): + def enum_form_string( + self, enum_form_string): """Sets the enum_form_string of this InlineObject2. Form parameter enum test (string) # noqa: E501 - :param enum_form_string: The enum_form_string of this InlineObject2. # noqa: E501 - :type: str + Returns: + (str): The enum_form_string of this InlineObject2. # noqa: E501 """ allowed_values = ["_abc", "-efg", "(xyz)"] # noqa: E501 if enum_form_string not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `enum_form_string` ({0}), must be one of {1}" # noqa: E501 .format(enum_form_string, allowed_values) ) - self._enum_form_string = enum_form_string + self.__setitem__( + 'enum_form_string', + enum_form_string + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/inline_object3.py b/samples/openapi3/client/petstore/python/petstore_api/models/inline_object3.py index 100f32c628aa..17d83c40feb8 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/inline_object3.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/inline_object3.py @@ -15,8 +15,27 @@ import six - -class InlineObject3(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class InlineObject3(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,86 +46,150 @@ class InlineObject3(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'integer': 'int', - 'int32': 'int', - 'int64': 'int', - 'number': 'float', - 'float': 'float', - 'double': 'float', - 'string': 'str', - 'pattern_without_delimiter': 'str', - 'byte': 'str', - 'binary': 'file', - 'date': 'date', - 'date_time': 'datetime', - 'password': 'str', - 'callback': 'str' + 'integer': [int], # noqa: E501 + 'int32': [int], # noqa: E501 + 'int64': [int], # noqa: E501 + 'number': [float], # noqa: E501 + 'float': [float], # noqa: E501 + 'double': [float], # noqa: E501 + 'string': [str], # noqa: E501 + 'pattern_without_delimiter': [str], # noqa: E501 + 'byte': [str], # noqa: E501 + 'binary': [file_type], # noqa: E501 + 'date': [date], # noqa: E501 + 'date_time': [datetime], # noqa: E501 + 'password': [str], # noqa: E501 + 'callback': [str] # noqa: E501 } - attribute_map = { - 'integer': 'integer', - 'int32': 'int32', - 'int64': 'int64', - 'number': 'number', - 'float': 'float', - 'double': 'double', - 'string': 'string', - 'pattern_without_delimiter': 'pattern_without_delimiter', - 'byte': 'byte', - 'binary': 'binary', - 'date': 'date', - 'date_time': 'dateTime', - 'password': 'password', - 'callback': 'callback' + 'integer': 'integer', # noqa: E501 + 'int32': 'int32', # noqa: E501 + 'int64': 'int64', # noqa: E501 + 'number': 'number', # noqa: E501 + 'float': 'float', # noqa: E501 + 'double': 'double', # noqa: E501 + 'string': 'string', # noqa: E501 + 'pattern_without_delimiter': 'pattern_without_delimiter', # noqa: E501 + 'byte': 'byte', # noqa: E501 + 'binary': 'binary', # noqa: E501 + 'date': 'date', # noqa: E501 + 'date_time': 'dateTime', # noqa: E501 + 'password': 'password', # noqa: E501 + 'callback': 'callback' # noqa: E501 } - def __init__(self, integer=None, int32=None, int64=None, number=None, float=None, double=None, string=None, pattern_without_delimiter=None, byte=None, binary=None, date=None, date_time=None, password=None, callback=None): # noqa: E501 - """InlineObject3 - a model defined in OpenAPI""" # noqa: E501 - - self._integer = None - self._int32 = None - self._int64 = None - self._number = None - self._float = None - self._double = None - self._string = None - self._pattern_without_delimiter = None - self._byte = None - self._binary = None - self._date = None - self._date_time = None - self._password = None - self._callback = None + def __init__(self, number, double, pattern_without_delimiter, byte, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """InlineObject3 - a model defined in OpenAPI + + Args: + number (float): None + double (float): None + pattern_without_delimiter (str): None + byte (str): None + + 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 False + _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 + _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. + integer (int): None. [optional] # noqa: E501 + int32 (int): None. [optional] # noqa: E501 + int64 (int): None. [optional] # noqa: E501 + float (float): None. [optional] # noqa: E501 + string (str): None. [optional] # noqa: E501 + binary (file_type): None. [optional] # noqa: E501 + date (date): None. [optional] # noqa: E501 + date_time (datetime): None. [optional] # noqa: E501 + password (str): None. [optional] # noqa: E501 + callback (str): None. [optional] # noqa: E501 + """ + + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration - if integer is not None: - self.integer = integer - if int32 is not None: - self.int32 = int32 - if int64 is not None: - self.int64 = int64 + # assign using .var_name to check against nullable and enums self.number = number - if float is not None: - self.float = float self.double = double - if string is not None: - self.string = string self.pattern_without_delimiter = pattern_without_delimiter self.byte = byte - if binary is not None: - self.binary = binary - if date is not None: - self.date = date - if date_time is not None: - self.date_time = date_time - if password is not None: - self.password = password - if callback is not None: - self.callback = callback + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def integer(self): @@ -114,26 +197,30 @@ def integer(self): None # noqa: E501 - :return: The integer of this InlineObject3. # noqa: E501 - :rtype: int + Returns: + (int): The integer of this InlineObject3. # noqa: E501 """ - return self._integer + return self._data_store.get('integer') @integer.setter - def integer(self, integer): + def integer( + self, integer): """Sets the integer of this InlineObject3. None # noqa: E501 - :param integer: The integer of this InlineObject3. # noqa: E501 - :type: int + Returns: + (int): The integer of this InlineObject3. # noqa: E501 """ if integer is not None and integer > 100: # noqa: E501 - raise ValueError("Invalid value for `integer`, must be a value less than or equal to `100`") # noqa: E501 + raise ApiValueError("Invalid value for `integer`, must be a value less than or equal to `100`") # noqa: E501 if integer is not None and integer < 10: # noqa: E501 - raise ValueError("Invalid value for `integer`, must be a value greater than or equal to `10`") # noqa: E501 + raise ApiValueError("Invalid value for `integer`, must be a value greater than or equal to `10`") # noqa: E501 - self._integer = integer + self.__setitem__( + 'integer', + integer + ) @property def int32(self): @@ -141,26 +228,30 @@ def int32(self): None # noqa: E501 - :return: The int32 of this InlineObject3. # noqa: E501 - :rtype: int + Returns: + (int): The int32 of this InlineObject3. # noqa: E501 """ - return self._int32 + return self._data_store.get('int32') @int32.setter - def int32(self, int32): + def int32( + self, int32): """Sets the int32 of this InlineObject3. None # noqa: E501 - :param int32: The int32 of this InlineObject3. # noqa: E501 - :type: int + Returns: + (int): The int32 of this InlineObject3. # noqa: E501 """ if int32 is not None and int32 > 200: # noqa: E501 - raise ValueError("Invalid value for `int32`, must be a value less than or equal to `200`") # noqa: E501 + raise ApiValueError("Invalid value for `int32`, must be a value less than or equal to `200`") # noqa: E501 if int32 is not None and int32 < 20: # noqa: E501 - raise ValueError("Invalid value for `int32`, must be a value greater than or equal to `20`") # noqa: E501 + raise ApiValueError("Invalid value for `int32`, must be a value greater than or equal to `20`") # noqa: E501 - self._int32 = int32 + self.__setitem__( + 'int32', + int32 + ) @property def int64(self): @@ -168,22 +259,26 @@ def int64(self): None # noqa: E501 - :return: The int64 of this InlineObject3. # noqa: E501 - :rtype: int + Returns: + (int): The int64 of this InlineObject3. # noqa: E501 """ - return self._int64 + return self._data_store.get('int64') @int64.setter - def int64(self, int64): + def int64( + self, int64): """Sets the int64 of this InlineObject3. None # noqa: E501 - :param int64: The int64 of this InlineObject3. # noqa: E501 - :type: int + Returns: + (int): The int64 of this InlineObject3. # noqa: E501 """ - self._int64 = int64 + self.__setitem__( + 'int64', + int64 + ) @property def number(self): @@ -191,28 +286,32 @@ def number(self): None # noqa: E501 - :return: The number of this InlineObject3. # noqa: E501 - :rtype: float + Returns: + (float): The number of this InlineObject3. # noqa: E501 """ - return self._number + return self._data_store.get('number') @number.setter - def number(self, number): + def number( + self, number): """Sets the number of this InlineObject3. None # noqa: E501 - :param number: The number of this InlineObject3. # noqa: E501 - :type: float + Returns: + (float): The number of this InlineObject3. # noqa: E501 """ if number is None: - raise ValueError("Invalid value for `number`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `number`, must not be `None`") # noqa: E501 if number is not None and number > 543.2: # noqa: E501 - raise ValueError("Invalid value for `number`, must be a value less than or equal to `543.2`") # noqa: E501 + raise ApiValueError("Invalid value for `number`, must be a value less than or equal to `543.2`") # noqa: E501 if number is not None and number < 32.1: # noqa: E501 - raise ValueError("Invalid value for `number`, must be a value greater than or equal to `32.1`") # noqa: E501 + raise ApiValueError("Invalid value for `number`, must be a value greater than or equal to `32.1`") # noqa: E501 - self._number = number + self.__setitem__( + 'number', + number + ) @property def float(self): @@ -220,24 +319,28 @@ def float(self): None # noqa: E501 - :return: The float of this InlineObject3. # noqa: E501 - :rtype: float + Returns: + (float): The float of this InlineObject3. # noqa: E501 """ - return self._float + return self._data_store.get('float') @float.setter - def float(self, float): + def float( + self, float): """Sets the float of this InlineObject3. None # noqa: E501 - :param float: The float of this InlineObject3. # noqa: E501 - :type: float + Returns: + (float): The float of this InlineObject3. # noqa: E501 """ if float is not None and float > 987.6: # noqa: E501 - raise ValueError("Invalid value for `float`, must be a value less than or equal to `987.6`") # noqa: E501 + raise ApiValueError("Invalid value for `float`, must be a value less than or equal to `987.6`") # noqa: E501 - self._float = float + self.__setitem__( + 'float', + float + ) @property def double(self): @@ -245,28 +348,32 @@ def double(self): None # noqa: E501 - :return: The double of this InlineObject3. # noqa: E501 - :rtype: float + Returns: + (float): The double of this InlineObject3. # noqa: E501 """ - return self._double + return self._data_store.get('double') @double.setter - def double(self, double): + def double( + self, double): """Sets the double of this InlineObject3. None # noqa: E501 - :param double: The double of this InlineObject3. # noqa: E501 - :type: float + Returns: + (float): The double of this InlineObject3. # noqa: E501 """ if double is None: - raise ValueError("Invalid value for `double`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `double`, must not be `None`") # noqa: E501 if double is not None and double > 123.4: # noqa: E501 - raise ValueError("Invalid value for `double`, must be a value less than or equal to `123.4`") # noqa: E501 + raise ApiValueError("Invalid value for `double`, must be a value less than or equal to `123.4`") # noqa: E501 if double is not None and double < 67.8: # noqa: E501 - raise ValueError("Invalid value for `double`, must be a value greater than or equal to `67.8`") # noqa: E501 + raise ApiValueError("Invalid value for `double`, must be a value greater than or equal to `67.8`") # noqa: E501 - self._double = double + self.__setitem__( + 'double', + double + ) @property def string(self): @@ -274,24 +381,28 @@ def string(self): None # noqa: E501 - :return: The string of this InlineObject3. # noqa: E501 - :rtype: str + Returns: + (str): The string of this InlineObject3. # noqa: E501 """ - return self._string + return self._data_store.get('string') @string.setter - def string(self, string): + def string( + self, string): """Sets the string of this InlineObject3. None # noqa: E501 - :param string: The string of this InlineObject3. # noqa: E501 - :type: str + Returns: + (str): The string of this InlineObject3. # noqa: E501 """ - if string is not None and not re.search(r'[a-z]', string, flags=re.IGNORECASE): # noqa: E501 - raise ValueError(r"Invalid value for `string`, must be a follow pattern or equal to `/[a-z]/i`") # noqa: E501 + if string is not None and not re.search(r'', string): # noqa: E501 + raise ApiValueError(r"Invalid value for `string`, must be a follow pattern or equal to `/[a-z]/i`") # noqa: E501 - self._string = string + self.__setitem__( + 'string', + string + ) @property def pattern_without_delimiter(self): @@ -299,26 +410,30 @@ def pattern_without_delimiter(self): None # noqa: E501 - :return: The pattern_without_delimiter of this InlineObject3. # noqa: E501 - :rtype: str + Returns: + (str): The pattern_without_delimiter of this InlineObject3. # noqa: E501 """ - return self._pattern_without_delimiter + return self._data_store.get('pattern_without_delimiter') @pattern_without_delimiter.setter - def pattern_without_delimiter(self, pattern_without_delimiter): + def pattern_without_delimiter( + self, pattern_without_delimiter): """Sets the pattern_without_delimiter of this InlineObject3. None # noqa: E501 - :param pattern_without_delimiter: The pattern_without_delimiter of this InlineObject3. # noqa: E501 - :type: str + Returns: + (str): The pattern_without_delimiter of this InlineObject3. # noqa: E501 """ if pattern_without_delimiter is None: - raise ValueError("Invalid value for `pattern_without_delimiter`, must not be `None`") # noqa: E501 - if pattern_without_delimiter is not None and not re.search(r'^[A-Z].*', pattern_without_delimiter): # noqa: E501 - raise ValueError(r"Invalid value for `pattern_without_delimiter`, must be a follow pattern or equal to `/^[A-Z].*/`") # noqa: E501 + raise ApiValueError("Invalid value for `pattern_without_delimiter`, must not be `None`") # noqa: E501 + if pattern_without_delimiter is not None and not re.search(r'', pattern_without_delimiter): # noqa: E501 + raise ApiValueError(r"Invalid value for `pattern_without_delimiter`, must be a follow pattern or equal to `/^[A-Z].*/`") # noqa: E501 - self._pattern_without_delimiter = pattern_without_delimiter + self.__setitem__( + 'pattern_without_delimiter', + pattern_without_delimiter + ) @property def byte(self): @@ -326,24 +441,28 @@ def byte(self): None # noqa: E501 - :return: The byte of this InlineObject3. # noqa: E501 - :rtype: str + Returns: + (str): The byte of this InlineObject3. # noqa: E501 """ - return self._byte + return self._data_store.get('byte') @byte.setter - def byte(self, byte): + def byte( + self, byte): """Sets the byte of this InlineObject3. None # noqa: E501 - :param byte: The byte of this InlineObject3. # noqa: E501 - :type: str + Returns: + (str): The byte of this InlineObject3. # noqa: E501 """ if byte is None: - raise ValueError("Invalid value for `byte`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `byte`, must not be `None`") # noqa: E501 - self._byte = byte + self.__setitem__( + 'byte', + byte + ) @property def binary(self): @@ -351,22 +470,26 @@ def binary(self): None # noqa: E501 - :return: The binary of this InlineObject3. # noqa: E501 - :rtype: file + Returns: + (file_type): The binary of this InlineObject3. # noqa: E501 """ - return self._binary + return self._data_store.get('binary') @binary.setter - def binary(self, binary): + def binary( + self, binary): """Sets the binary of this InlineObject3. None # noqa: E501 - :param binary: The binary of this InlineObject3. # noqa: E501 - :type: file + Returns: + (file_type): The binary of this InlineObject3. # noqa: E501 """ - self._binary = binary + self.__setitem__( + 'binary', + binary + ) @property def date(self): @@ -374,22 +497,26 @@ def date(self): None # noqa: E501 - :return: The date of this InlineObject3. # noqa: E501 - :rtype: date + Returns: + (date): The date of this InlineObject3. # noqa: E501 """ - return self._date + return self._data_store.get('date') @date.setter - def date(self, date): + def date( + self, date): """Sets the date of this InlineObject3. None # noqa: E501 - :param date: The date of this InlineObject3. # noqa: E501 - :type: date + Returns: + (date): The date of this InlineObject3. # noqa: E501 """ - self._date = date + self.__setitem__( + 'date', + date + ) @property def date_time(self): @@ -397,22 +524,26 @@ def date_time(self): None # noqa: E501 - :return: The date_time of this InlineObject3. # noqa: E501 - :rtype: datetime + Returns: + (datetime): The date_time of this InlineObject3. # noqa: E501 """ - return self._date_time + return self._data_store.get('date_time') @date_time.setter - def date_time(self, date_time): + def date_time( + self, date_time): """Sets the date_time of this InlineObject3. None # noqa: E501 - :param date_time: The date_time of this InlineObject3. # noqa: E501 - :type: datetime + Returns: + (datetime): The date_time of this InlineObject3. # noqa: E501 """ - self._date_time = date_time + self.__setitem__( + 'date_time', + date_time + ) @property def password(self): @@ -420,26 +551,30 @@ def password(self): None # noqa: E501 - :return: The password of this InlineObject3. # noqa: E501 - :rtype: str + Returns: + (str): The password of this InlineObject3. # noqa: E501 """ - return self._password + return self._data_store.get('password') @password.setter - def password(self, password): + def password( + self, password): """Sets the password of this InlineObject3. None # noqa: E501 - :param password: The password of this InlineObject3. # noqa: E501 - :type: str + Returns: + (str): The password of this InlineObject3. # noqa: E501 """ if password is not None and len(password) > 64: - raise ValueError("Invalid value for `password`, length must be less than or equal to `64`") # noqa: E501 + raise ApiValueError("Invalid value for `password`, length must be less than or equal to `64`") # noqa: E501 if password is not None and len(password) < 10: - raise ValueError("Invalid value for `password`, length must be greater than or equal to `10`") # noqa: E501 + raise ApiValueError("Invalid value for `password`, length must be greater than or equal to `10`") # noqa: E501 - self._password = password + self.__setitem__( + 'password', + password + ) @property def callback(self): @@ -447,46 +582,30 @@ def callback(self): None # noqa: E501 - :return: The callback of this InlineObject3. # noqa: E501 - :rtype: str + Returns: + (str): The callback of this InlineObject3. # noqa: E501 """ - return self._callback + return self._data_store.get('callback') @callback.setter - def callback(self, callback): + def callback( + self, callback): """Sets the callback of this InlineObject3. None # noqa: E501 - :param callback: The callback of this InlineObject3. # noqa: E501 - :type: str + Returns: + (str): The callback of this InlineObject3. # noqa: E501 """ - self._callback = callback + self.__setitem__( + 'callback', + callback + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/inline_object4.py b/samples/openapi3/client/petstore/python/petstore_api/models/inline_object4.py index f0e6032cfa3c..591bb6061abb 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/inline_object4.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/inline_object4.py @@ -15,8 +15,27 @@ import six - -class InlineObject4(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class InlineObject4(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,28 +46,112 @@ class InlineObject4(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'param': 'str', - 'param2': 'str' + 'param': [str], # noqa: E501 + 'param2': [str] # noqa: E501 } - attribute_map = { - 'param': 'param', - 'param2': 'param2' + 'param': 'param', # noqa: E501 + 'param2': 'param2' # noqa: E501 } - def __init__(self, param=None, param2=None): # noqa: E501 - """InlineObject4 - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, param, param2, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """InlineObject4 - a model defined in OpenAPI + + Args: + param (str): field1 + param2 (str): field2 + + 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 False + _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 + _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. + """ - self._param = None - self._param2 = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + # assign using .var_name to check against nullable and enums self.param = param self.param2 = param2 + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def param(self): @@ -56,24 +159,28 @@ def param(self): field1 # noqa: E501 - :return: The param of this InlineObject4. # noqa: E501 - :rtype: str + Returns: + (str): The param of this InlineObject4. # noqa: E501 """ - return self._param + return self._data_store.get('param') @param.setter - def param(self, param): + def param( + self, param): """Sets the param of this InlineObject4. field1 # noqa: E501 - :param param: The param of this InlineObject4. # noqa: E501 - :type: str + Returns: + (str): The param of this InlineObject4. # noqa: E501 """ if param is None: - raise ValueError("Invalid value for `param`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `param`, must not be `None`") # noqa: E501 - self._param = param + self.__setitem__( + 'param', + param + ) @property def param2(self): @@ -81,48 +188,32 @@ def param2(self): field2 # noqa: E501 - :return: The param2 of this InlineObject4. # noqa: E501 - :rtype: str + Returns: + (str): The param2 of this InlineObject4. # noqa: E501 """ - return self._param2 + return self._data_store.get('param2') @param2.setter - def param2(self, param2): + def param2( + self, param2): """Sets the param2 of this InlineObject4. field2 # noqa: E501 - :param param2: The param2 of this InlineObject4. # noqa: E501 - :type: str + Returns: + (str): The param2 of this InlineObject4. # noqa: E501 """ if param2 is None: - raise ValueError("Invalid value for `param2`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `param2`, must not be `None`") # noqa: E501 - self._param2 = param2 + self.__setitem__( + 'param2', + param2 + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/inline_object5.py b/samples/openapi3/client/petstore/python/petstore_api/models/inline_object5.py index 8a51ff7ef951..691a29dfd4f7 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/inline_object5.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/inline_object5.py @@ -15,8 +15,27 @@ import six - -class InlineObject5(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class InlineObject5(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,29 +46,111 @@ class InlineObject5(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'additional_metadata': 'str', - 'required_file': 'file' + 'additional_metadata': [str], # noqa: E501 + 'required_file': [file_type] # noqa: E501 } - attribute_map = { - 'additional_metadata': 'additionalMetadata', - 'required_file': 'requiredFile' + 'additional_metadata': 'additionalMetadata', # noqa: E501 + 'required_file': 'requiredFile' # noqa: E501 } - def __init__(self, additional_metadata=None, required_file=None): # noqa: E501 - """InlineObject5 - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, required_file, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """InlineObject5 - a model defined in OpenAPI + + Args: + required_file (file_type): file to upload + + 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 False + _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 + _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. + additional_metadata (str): Additional data to pass to server. [optional] # noqa: E501 + """ - self._additional_metadata = None - self._required_file = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration - if additional_metadata is not None: - self.additional_metadata = additional_metadata + # assign using .var_name to check against nullable and enums self.required_file = required_file + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def additional_metadata(self): @@ -57,22 +158,26 @@ def additional_metadata(self): Additional data to pass to server # noqa: E501 - :return: The additional_metadata of this InlineObject5. # noqa: E501 - :rtype: str + Returns: + (str): The additional_metadata of this InlineObject5. # noqa: E501 """ - return self._additional_metadata + return self._data_store.get('additional_metadata') @additional_metadata.setter - def additional_metadata(self, additional_metadata): + def additional_metadata( + self, additional_metadata): """Sets the additional_metadata of this InlineObject5. Additional data to pass to server # noqa: E501 - :param additional_metadata: The additional_metadata of this InlineObject5. # noqa: E501 - :type: str + Returns: + (str): The additional_metadata of this InlineObject5. # noqa: E501 """ - self._additional_metadata = additional_metadata + self.__setitem__( + 'additional_metadata', + additional_metadata + ) @property def required_file(self): @@ -80,48 +185,32 @@ def required_file(self): file to upload # noqa: E501 - :return: The required_file of this InlineObject5. # noqa: E501 - :rtype: file + Returns: + (file_type): The required_file of this InlineObject5. # noqa: E501 """ - return self._required_file + return self._data_store.get('required_file') @required_file.setter - def required_file(self, required_file): + def required_file( + self, required_file): """Sets the required_file of this InlineObject5. file to upload # noqa: E501 - :param required_file: The required_file of this InlineObject5. # noqa: E501 - :type: file + Returns: + (file_type): The required_file of this InlineObject5. # noqa: E501 """ if required_file is None: - raise ValueError("Invalid value for `required_file`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `required_file`, must not be `None`") # noqa: E501 - self._required_file = required_file + self.__setitem__( + 'required_file', + required_file + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/inline_response_default.py b/samples/openapi3/client/petstore/python/petstore_api/models/inline_response_default.py index 68980531ed43..2e07c18f5718 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/inline_response_default.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/inline_response_default.py @@ -15,8 +15,28 @@ import six - -class InlineResponseDefault(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.foo import Foo + + +class InlineResponseDefault(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +47,135 @@ class InlineResponseDefault(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'string': 'Foo' + 'string': [Foo] # noqa: E501 } - attribute_map = { - 'string': 'string' + 'string': 'string' # noqa: E501 } - def __init__(self, string=None): # noqa: E501 - """InlineResponseDefault - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """InlineResponseDefault - a model defined in OpenAPI - self._string = None - self.discriminator = None - if string is not None: - self.string = string + + 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 False + _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 + _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. + string (Foo): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def string(self): """Gets the string of this InlineResponseDefault. # noqa: E501 - :return: The string of this InlineResponseDefault. # noqa: E501 - :rtype: Foo + Returns: + (Foo): The string of this InlineResponseDefault. # noqa: E501 """ - return self._string + return self._data_store.get('string') @string.setter - def string(self, string): + def string( + self, string): """Sets the string of this InlineResponseDefault. - :param string: The string of this InlineResponseDefault. # noqa: E501 - :type: Foo + Returns: + (Foo): The string of this InlineResponseDefault. # noqa: E501 """ - self._string = string + self.__setitem__( + 'string', + string + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/list.py b/samples/openapi3/client/petstore/python/petstore_api/models/list.py index 08e12ad53104..71b3c3ea4033 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/list.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/list.py @@ -15,8 +15,27 @@ import six - -class List(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class List(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class List(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - '_123_list': 'str' + '_123_list': [str] # noqa: E501 } - attribute_map = { - '_123_list': '123-list' + '_123_list': '123-list' # noqa: E501 } - def __init__(self, _123_list=None): # noqa: E501 - """List - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """List - a model defined in OpenAPI - self.__123_list = None - self.discriminator = None - if _123_list is not None: - self._123_list = _123_list + + 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 False + _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 + _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. + _123_list (str): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def _123_list(self): """Gets the _123_list of this List. # noqa: E501 - :return: The _123_list of this List. # noqa: E501 - :rtype: str + Returns: + (str): The _123_list of this List. # noqa: E501 """ - return self.__123_list + return self._data_store.get('_123_list') @_123_list.setter - def _123_list(self, _123_list): + def _123_list( + self, _123_list): """Sets the _123_list of this List. - :param _123_list: The _123_list of this List. # noqa: E501 - :type: str + Returns: + (str): The _123_list of this List. # noqa: E501 """ - self.__123_list = _123_list + self.__setitem__( + '_123_list', + _123_list + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/map_test.py b/samples/openapi3/client/petstore/python/petstore_api/models/map_test.py index f04bd2cc1421..c846484fb60f 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/map_test.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/map_test.py @@ -15,8 +15,27 @@ import six - -class MapTest(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class MapTest(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,155 +46,226 @@ class MapTest(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'map_map_of_string': 'dict(str, dict(str, str))', - 'map_of_enum_string': 'dict(str, str)', - 'direct_map': 'dict(str, bool)', - 'indirect_map': 'dict(str, bool)' + 'map_map_of_string': [{str: ({str: (str,)},)}], # noqa: E501 + 'map_of_enum_string': [{str: (str,)}], # noqa: E501 + 'direct_map': [{str: (bool,)}], # noqa: E501 + 'indirect_map': [{str: (bool,)}] # noqa: E501 } - attribute_map = { - 'map_map_of_string': 'map_map_of_string', - 'map_of_enum_string': 'map_of_enum_string', - 'direct_map': 'direct_map', - 'indirect_map': 'indirect_map' + 'map_map_of_string': 'map_map_of_string', # noqa: E501 + 'map_of_enum_string': 'map_of_enum_string', # noqa: E501 + 'direct_map': 'direct_map', # noqa: E501 + 'indirect_map': 'indirect_map' # noqa: E501 } - def __init__(self, map_map_of_string=None, map_of_enum_string=None, direct_map=None, indirect_map=None): # noqa: E501 - """MapTest - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """MapTest - 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 False + _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 + _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. + map_map_of_string ({str: ({str: (str,)},)}): [optional] # noqa: E501 + map_of_enum_string ({str: (str,)}): [optional] # noqa: E501 + direct_map ({str: (bool,)}): [optional] # noqa: E501 + indirect_map ({str: (bool,)}): [optional] # noqa: E501 + """ - self._map_map_of_string = None - self._map_of_enum_string = None - self._direct_map = None - self._indirect_map = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) - if map_map_of_string is not None: - self.map_map_of_string = map_map_of_string - if map_of_enum_string is not None: - self.map_of_enum_string = map_of_enum_string - if direct_map is not None: - self.direct_map = direct_map - if indirect_map is not None: - self.indirect_map = indirect_map + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def map_map_of_string(self): """Gets the map_map_of_string of this MapTest. # noqa: E501 - :return: The map_map_of_string of this MapTest. # noqa: E501 - :rtype: dict(str, dict(str, str)) + Returns: + ({str: ({str: (str,)},)}): The map_map_of_string of this MapTest. # noqa: E501 """ - return self._map_map_of_string + return self._data_store.get('map_map_of_string') @map_map_of_string.setter - def map_map_of_string(self, map_map_of_string): + def map_map_of_string( + self, map_map_of_string): """Sets the map_map_of_string of this MapTest. - :param map_map_of_string: The map_map_of_string of this MapTest. # noqa: E501 - :type: dict(str, dict(str, str)) + Returns: + ({str: ({str: (str,)},)}): The map_map_of_string of this MapTest. # noqa: E501 """ - self._map_map_of_string = map_map_of_string + self.__setitem__( + 'map_map_of_string', + map_map_of_string + ) @property def map_of_enum_string(self): """Gets the map_of_enum_string of this MapTest. # noqa: E501 - :return: The map_of_enum_string of this MapTest. # noqa: E501 - :rtype: dict(str, str) + Returns: + ({str: (str,)}): The map_of_enum_string of this MapTest. # noqa: E501 """ - return self._map_of_enum_string + return self._data_store.get('map_of_enum_string') @map_of_enum_string.setter - def map_of_enum_string(self, map_of_enum_string): + def map_of_enum_string( + self, map_of_enum_string): """Sets the map_of_enum_string of this MapTest. - :param map_of_enum_string: The map_of_enum_string of this MapTest. # noqa: E501 - :type: dict(str, str) + Returns: + ({str: (str,)}): The map_of_enum_string of this MapTest. # noqa: E501 """ allowed_values = ["UPPER", "lower"] # noqa: E501 if not set(map_of_enum_string.keys()).issubset(set(allowed_values)): - raise ValueError( + raise ApiValueError( "Invalid keys in `map_of_enum_string` [{0}], must be a subset of [{1}]" # noqa: E501 .format(", ".join(map(str, set(map_of_enum_string.keys()) - set(allowed_values))), # noqa: E501 ", ".join(map(str, allowed_values))) ) - self._map_of_enum_string = map_of_enum_string + self.__setitem__( + 'map_of_enum_string', + map_of_enum_string + ) @property def direct_map(self): """Gets the direct_map of this MapTest. # noqa: E501 - :return: The direct_map of this MapTest. # noqa: E501 - :rtype: dict(str, bool) + Returns: + ({str: (bool,)}): The direct_map of this MapTest. # noqa: E501 """ - return self._direct_map + return self._data_store.get('direct_map') @direct_map.setter - def direct_map(self, direct_map): + def direct_map( + self, direct_map): """Sets the direct_map of this MapTest. - :param direct_map: The direct_map of this MapTest. # noqa: E501 - :type: dict(str, bool) + Returns: + ({str: (bool,)}): The direct_map of this MapTest. # noqa: E501 """ - self._direct_map = direct_map + self.__setitem__( + 'direct_map', + direct_map + ) @property def indirect_map(self): """Gets the indirect_map of this MapTest. # noqa: E501 - :return: The indirect_map of this MapTest. # noqa: E501 - :rtype: dict(str, bool) + Returns: + ({str: (bool,)}): The indirect_map of this MapTest. # noqa: E501 """ - return self._indirect_map + return self._data_store.get('indirect_map') @indirect_map.setter - def indirect_map(self, indirect_map): + def indirect_map( + self, indirect_map): """Sets the indirect_map of this MapTest. - :param indirect_map: The indirect_map of this MapTest. # noqa: E501 - :type: dict(str, bool) + Returns: + ({str: (bool,)}): The indirect_map of this MapTest. # noqa: E501 """ - self._indirect_map = indirect_map + self.__setitem__( + 'indirect_map', + indirect_map + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/mixed_properties_and_additional_properties_class.py b/samples/openapi3/client/petstore/python/petstore_api/models/mixed_properties_and_additional_properties_class.py index ecf67acc5e95..1d61e2c659ff 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/mixed_properties_and_additional_properties_class.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/mixed_properties_and_additional_properties_class.py @@ -15,8 +15,28 @@ import six - -class MixedPropertiesAndAdditionalPropertiesClass(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.animal import Animal + + +class MixedPropertiesAndAdditionalPropertiesClass(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,122 +47,191 @@ class MixedPropertiesAndAdditionalPropertiesClass(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'uuid': 'str', - 'date_time': 'datetime', - 'map': 'dict(str, Animal)' + 'uuid': [str], # noqa: E501 + 'date_time': [datetime], # noqa: E501 + 'map': [{str: (Animal,)}] # noqa: E501 } - attribute_map = { - 'uuid': 'uuid', - 'date_time': 'dateTime', - 'map': 'map' + 'uuid': 'uuid', # noqa: E501 + 'date_time': 'dateTime', # noqa: E501 + 'map': 'map' # noqa: E501 } - def __init__(self, uuid=None, date_time=None, map=None): # noqa: E501 - """MixedPropertiesAndAdditionalPropertiesClass - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """MixedPropertiesAndAdditionalPropertiesClass - 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 False + _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 + _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. + uuid (str): [optional] # noqa: E501 + date_time (datetime): [optional] # noqa: E501 + map ({str: (Animal,)}): [optional] # noqa: E501 + """ - self._uuid = None - self._date_time = None - self._map = None + self._data_store = {} self.discriminator = None - - if uuid is not None: - self.uuid = uuid - if date_time is not None: - self.date_time = date_time - if map is not None: - self.map = map + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def uuid(self): """Gets the uuid of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :return: The uuid of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :rtype: str + Returns: + (str): The uuid of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - return self._uuid + return self._data_store.get('uuid') @uuid.setter - def uuid(self, uuid): + def uuid( + self, uuid): """Sets the uuid of this MixedPropertiesAndAdditionalPropertiesClass. - :param uuid: The uuid of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :type: str + Returns: + (str): The uuid of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - self._uuid = uuid + self.__setitem__( + 'uuid', + uuid + ) @property def date_time(self): """Gets the date_time of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :return: The date_time of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :rtype: datetime + Returns: + (datetime): The date_time of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - return self._date_time + return self._data_store.get('date_time') @date_time.setter - def date_time(self, date_time): + def date_time( + self, date_time): """Sets the date_time of this MixedPropertiesAndAdditionalPropertiesClass. - :param date_time: The date_time of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :type: datetime + Returns: + (datetime): The date_time of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - self._date_time = date_time + self.__setitem__( + 'date_time', + date_time + ) @property def map(self): """Gets the map of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :return: The map of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :rtype: dict(str, Animal) + Returns: + ({str: (Animal,)}): The map of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - return self._map + return self._data_store.get('map') @map.setter - def map(self, map): + def map( + self, map): """Sets the map of this MixedPropertiesAndAdditionalPropertiesClass. - :param map: The map of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 - :type: dict(str, Animal) + Returns: + ({str: (Animal,)}): The map of this MixedPropertiesAndAdditionalPropertiesClass. # noqa: E501 """ - self._map = map + self.__setitem__( + 'map', + map + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/model200_response.py b/samples/openapi3/client/petstore/python/petstore_api/models/model200_response.py index ec778cdcb74b..e44d7f28022e 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/model200_response.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/model200_response.py @@ -15,8 +15,27 @@ import six - -class Model200Response(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Model200Response(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +46,163 @@ class Model200Response(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'name': 'int', - '_class': 'str' + 'name': [int], # noqa: E501 + '_class': [str] # noqa: E501 } - attribute_map = { - 'name': 'name', - '_class': 'class' + 'name': 'name', # noqa: E501 + '_class': 'class' # noqa: E501 } - def __init__(self, name=None, _class=None): # noqa: E501 - """Model200Response - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Model200Response - 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 False + _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 + _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. + name (int): [optional] # noqa: E501 + _class (str): [optional] # noqa: E501 + """ - self._name = None - self.__class = None + self._data_store = {} self.discriminator = None - - if name is not None: - self.name = name - if _class is not None: - self._class = _class + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def name(self): """Gets the name of this Model200Response. # noqa: E501 - :return: The name of this Model200Response. # noqa: E501 - :rtype: int + Returns: + (int): The name of this Model200Response. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this Model200Response. - :param name: The name of this Model200Response. # noqa: E501 - :type: int + Returns: + (int): The name of this Model200Response. # noqa: E501 """ - self._name = name + self.__setitem__( + 'name', + name + ) @property def _class(self): """Gets the _class of this Model200Response. # noqa: E501 - :return: The _class of this Model200Response. # noqa: E501 - :rtype: str + Returns: + (str): The _class of this Model200Response. # noqa: E501 """ - return self.__class + return self._data_store.get('_class') @_class.setter - def _class(self, _class): + def _class( + self, _class): """Sets the _class of this Model200Response. - :param _class: The _class of this Model200Response. # noqa: E501 - :type: str + Returns: + (str): The _class of this Model200Response. # noqa: E501 """ - self.__class = _class + self.__setitem__( + '_class', + _class + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/model_return.py b/samples/openapi3/client/petstore/python/petstore_api/models/model_return.py index 3862245ef71d..7f3e64a12ab5 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/model_return.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/model_return.py @@ -15,8 +15,27 @@ import six - -class ModelReturn(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ModelReturn(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class ModelReturn(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - '_return': 'int' + '_return': [int] # noqa: E501 } - attribute_map = { - '_return': 'return' + '_return': 'return' # noqa: E501 } - def __init__(self, _return=None): # noqa: E501 - """ModelReturn - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ModelReturn - a model defined in OpenAPI - self.__return = None - self.discriminator = None - if _return is not None: - self._return = _return + + 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 False + _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 + _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. + _return (int): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def _return(self): """Gets the _return of this ModelReturn. # noqa: E501 - :return: The _return of this ModelReturn. # noqa: E501 - :rtype: int + Returns: + (int): The _return of this ModelReturn. # noqa: E501 """ - return self.__return + return self._data_store.get('_return') @_return.setter - def _return(self, _return): + def _return( + self, _return): """Sets the _return of this ModelReturn. - :param _return: The _return of this ModelReturn. # noqa: E501 - :type: int + Returns: + (int): The _return of this ModelReturn. # noqa: E501 """ - self.__return = _return + self.__setitem__( + '_return', + _return + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/name.py b/samples/openapi3/client/petstore/python/petstore_api/models/name.py index b2e97e596a4d..1b06fe765b43 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/name.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/name.py @@ -15,8 +15,27 @@ import six - -class Name(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Name(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,149 +46,223 @@ class Name(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'name': 'int', - 'snake_case': 'int', - '_property': 'str', - '_123_number': 'int' + 'name': [int], # noqa: E501 + 'snake_case': [int], # noqa: E501 + '_property': [str], # noqa: E501 + '_123_number': [int] # noqa: E501 } - attribute_map = { - 'name': 'name', - 'snake_case': 'snake_case', - '_property': 'property', - '_123_number': '123Number' + 'name': 'name', # noqa: E501 + 'snake_case': 'snake_case', # noqa: E501 + '_property': 'property', # noqa: E501 + '_123_number': '123Number' # noqa: E501 } - def __init__(self, name=None, snake_case=None, _property=None, _123_number=None): # noqa: E501 - """Name - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, name, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Name - a model defined in OpenAPI + + Args: + name (int): + + 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 False + _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 + _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. + snake_case (int): [optional] # noqa: E501 + _property (str): [optional] # noqa: E501 + _123_number (int): [optional] # noqa: E501 + """ - self._name = None - self._snake_case = None - self.__property = None - self.__123_number = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + # assign using .var_name to check against nullable and enums self.name = name - if snake_case is not None: - self.snake_case = snake_case - if _property is not None: - self._property = _property - if _123_number is not None: - self._123_number = _123_number + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def name(self): """Gets the name of this Name. # noqa: E501 - :return: The name of this Name. # noqa: E501 - :rtype: int + Returns: + (int): The name of this Name. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this Name. - :param name: The name of this Name. # noqa: E501 - :type: int + Returns: + (int): The name of this Name. # noqa: E501 """ if name is None: - raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `name`, must not be `None`") # noqa: E501 - self._name = name + self.__setitem__( + 'name', + name + ) @property def snake_case(self): """Gets the snake_case of this Name. # noqa: E501 - :return: The snake_case of this Name. # noqa: E501 - :rtype: int + Returns: + (int): The snake_case of this Name. # noqa: E501 """ - return self._snake_case + return self._data_store.get('snake_case') @snake_case.setter - def snake_case(self, snake_case): + def snake_case( + self, snake_case): """Sets the snake_case of this Name. - :param snake_case: The snake_case of this Name. # noqa: E501 - :type: int + Returns: + (int): The snake_case of this Name. # noqa: E501 """ - self._snake_case = snake_case + self.__setitem__( + 'snake_case', + snake_case + ) @property def _property(self): """Gets the _property of this Name. # noqa: E501 - :return: The _property of this Name. # noqa: E501 - :rtype: str + Returns: + (str): The _property of this Name. # noqa: E501 """ - return self.__property + return self._data_store.get('_property') @_property.setter - def _property(self, _property): + def _property( + self, _property): """Sets the _property of this Name. - :param _property: The _property of this Name. # noqa: E501 - :type: str + Returns: + (str): The _property of this Name. # noqa: E501 """ - self.__property = _property + self.__setitem__( + '_property', + _property + ) @property def _123_number(self): """Gets the _123_number of this Name. # noqa: E501 - :return: The _123_number of this Name. # noqa: E501 - :rtype: int + Returns: + (int): The _123_number of this Name. # noqa: E501 """ - return self.__123_number + return self._data_store.get('_123_number') @_123_number.setter - def _123_number(self, _123_number): + def _123_number( + self, _123_number): """Sets the _123_number of this Name. - :param _123_number: The _123_number of this Name. # noqa: E501 - :type: int + Returns: + (int): The _123_number of this Name. # noqa: E501 """ - self.__123_number = _123_number + self.__setitem__( + '_123_number', + _123_number + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/nullable_class.py b/samples/openapi3/client/petstore/python/petstore_api/models/nullable_class.py new file mode 100644 index 000000000000..5beabf446fa8 --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/models/nullable_class.py @@ -0,0 +1,506 @@ +# 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 + +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class NullableClass(OpenApiModel): + """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. + Optional and required variables only. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + Optional, required variables, and + additional properties. + additional_properties_type (str): The attribute type for + additional_properties variables only. + """ + openapi_types = { + 'integer_prop': [int, none_type], # noqa: E501 + 'number_prop': [float, none_type], # noqa: E501 + 'boolean_prop': [bool, none_type], # noqa: E501 + 'string_prop': [str, none_type], # noqa: E501 + 'date_prop': [date, none_type], # noqa: E501 + 'datetime_prop': [datetime, none_type], # noqa: E501 + 'array_nullable_prop': [[(bool, date, datetime, dict, float, int, list, str)], none_type], # noqa: E501 + 'array_and_items_nullable_prop': [[(bool, date, datetime, dict, float, int, list, str, none_type)], none_type], # noqa: E501 + 'array_items_nullable': [[(bool, date, datetime, dict, float, int, list, str, none_type)]], # noqa: E501 + 'object_nullable_prop': [{str: (bool, date, datetime, dict, float, int, list, str)}, none_type], # noqa: E501 + 'object_and_items_nullable_prop': [{str: (bool, date, datetime, dict, float, int, list, str, none_type)}, none_type], # noqa: E501 + 'object_items_nullable': [{str: (bool, date, datetime, dict, float, int, list, str, none_type)}] # noqa: E501 + } + attribute_map = { + 'integer_prop': 'integer_prop', # noqa: E501 + 'number_prop': 'number_prop', # noqa: E501 + 'boolean_prop': 'boolean_prop', # noqa: E501 + 'string_prop': 'string_prop', # noqa: E501 + 'date_prop': 'date_prop', # noqa: E501 + 'datetime_prop': 'datetime_prop', # noqa: E501 + 'array_nullable_prop': 'array_nullable_prop', # noqa: E501 + 'array_and_items_nullable_prop': 'array_and_items_nullable_prop', # noqa: E501 + 'array_items_nullable': 'array_items_nullable', # noqa: E501 + 'object_nullable_prop': 'object_nullable_prop', # noqa: E501 + 'object_and_items_nullable_prop': 'object_and_items_nullable_prop', # noqa: E501 + 'object_items_nullable': 'object_items_nullable' # noqa: E501 + } + additional_properties_type = [bool, date, datetime, dict, float, int, list, str, none_type] # noqa: E501 + + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """NullableClass - 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 False + _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 + _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. + integer_prop (int, none_type): [optional] # noqa: E501 + number_prop (float, none_type): [optional] # noqa: E501 + boolean_prop (bool, none_type): [optional] # noqa: E501 + string_prop (str, none_type): [optional] # noqa: E501 + date_prop (date, none_type): [optional] # noqa: E501 + datetime_prop (datetime, none_type): [optional] # noqa: E501 + array_nullable_prop ([(bool, date, datetime, dict, float, int, list, str)], none_type): [optional] # noqa: E501 + array_and_items_nullable_prop ([(bool, date, datetime, dict, float, int, list, str, none_type)], none_type): [optional] # noqa: E501 + array_items_nullable ([(bool, date, datetime, dict, float, int, list, str, none_type)]): [optional] # noqa: E501 + object_nullable_prop ({str: (bool, date, datetime, dict, float, int, list, str)}, none_type): [optional] # noqa: E501 + object_and_items_nullable_prop ({str: (bool, date, datetime, dict, float, int, list, str, none_type)}, none_type): [optional] # noqa: E501 + object_items_nullable ({str: (bool, date, datetime, dict, float, int, list, str, none_type)}): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + check_type = True + required_types_mixed = self.additional_properties_type + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + # set a variable name value for json serialization + if (name not in self.openapi_types and + name not in self.attribute_map): + self.attribute_map[name] = name + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) + + @property + def integer_prop(self): + """Gets the integer_prop of this NullableClass. # noqa: E501 + + + Returns: + (int, none_type): The integer_prop of this NullableClass. # noqa: E501 + """ + return self._data_store.get('integer_prop') + + @integer_prop.setter + def integer_prop( + self, integer_prop): + """Sets the integer_prop of this NullableClass. + + + Returns: + (int, none_type): The integer_prop of this NullableClass. # noqa: E501 + """ + + self.__setitem__( + 'integer_prop', + integer_prop + ) + + @property + def number_prop(self): + """Gets the number_prop of this NullableClass. # noqa: E501 + + + Returns: + (float, none_type): The number_prop of this NullableClass. # noqa: E501 + """ + return self._data_store.get('number_prop') + + @number_prop.setter + def number_prop( + self, number_prop): + """Sets the number_prop of this NullableClass. + + + Returns: + (float, none_type): The number_prop of this NullableClass. # noqa: E501 + """ + + self.__setitem__( + 'number_prop', + number_prop + ) + + @property + def boolean_prop(self): + """Gets the boolean_prop of this NullableClass. # noqa: E501 + + + Returns: + (bool, none_type): The boolean_prop of this NullableClass. # noqa: E501 + """ + return self._data_store.get('boolean_prop') + + @boolean_prop.setter + def boolean_prop( + self, boolean_prop): + """Sets the boolean_prop of this NullableClass. + + + Returns: + (bool, none_type): The boolean_prop of this NullableClass. # noqa: E501 + """ + + self.__setitem__( + 'boolean_prop', + boolean_prop + ) + + @property + def string_prop(self): + """Gets the string_prop of this NullableClass. # noqa: E501 + + + Returns: + (str, none_type): The string_prop of this NullableClass. # noqa: E501 + """ + return self._data_store.get('string_prop') + + @string_prop.setter + def string_prop( + self, string_prop): + """Sets the string_prop of this NullableClass. + + + Returns: + (str, none_type): The string_prop of this NullableClass. # noqa: E501 + """ + + self.__setitem__( + 'string_prop', + string_prop + ) + + @property + def date_prop(self): + """Gets the date_prop of this NullableClass. # noqa: E501 + + + Returns: + (date, none_type): The date_prop of this NullableClass. # noqa: E501 + """ + return self._data_store.get('date_prop') + + @date_prop.setter + def date_prop( + self, date_prop): + """Sets the date_prop of this NullableClass. + + + Returns: + (date, none_type): The date_prop of this NullableClass. # noqa: E501 + """ + + self.__setitem__( + 'date_prop', + date_prop + ) + + @property + def datetime_prop(self): + """Gets the datetime_prop of this NullableClass. # noqa: E501 + + + Returns: + (datetime, none_type): The datetime_prop of this NullableClass. # noqa: E501 + """ + return self._data_store.get('datetime_prop') + + @datetime_prop.setter + def datetime_prop( + self, datetime_prop): + """Sets the datetime_prop of this NullableClass. + + + Returns: + (datetime, none_type): The datetime_prop of this NullableClass. # noqa: E501 + """ + + self.__setitem__( + 'datetime_prop', + datetime_prop + ) + + @property + def array_nullable_prop(self): + """Gets the array_nullable_prop of this NullableClass. # noqa: E501 + + + Returns: + ([(bool, date, datetime, dict, float, int, list, str)], none_type): The array_nullable_prop of this NullableClass. # noqa: E501 + """ + return self._data_store.get('array_nullable_prop') + + @array_nullable_prop.setter + def array_nullable_prop( + self, array_nullable_prop): + """Sets the array_nullable_prop of this NullableClass. + + + Returns: + ([(bool, date, datetime, dict, float, int, list, str)], none_type): The array_nullable_prop of this NullableClass. # noqa: E501 + """ + + self.__setitem__( + '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 + + + Returns: + ([(bool, date, datetime, dict, float, int, list, str, none_type)], none_type): The array_and_items_nullable_prop of this NullableClass. # noqa: E501 + """ + return self._data_store.get('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. + + + Returns: + ([(bool, date, datetime, dict, float, int, list, str, none_type)], none_type): The array_and_items_nullable_prop of this NullableClass. # noqa: E501 + """ + + self.__setitem__( + '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 + + + Returns: + ([(bool, date, datetime, dict, float, int, list, str, none_type)]): The array_items_nullable of this NullableClass. # noqa: E501 + """ + return self._data_store.get('array_items_nullable') + + @array_items_nullable.setter + def array_items_nullable( + self, array_items_nullable): + """Sets the array_items_nullable of this NullableClass. + + + Returns: + ([(bool, date, datetime, dict, float, int, list, str, none_type)]): The array_items_nullable of this NullableClass. # noqa: E501 + """ + + self.__setitem__( + 'array_items_nullable', + array_items_nullable + ) + + @property + def object_nullable_prop(self): + """Gets the object_nullable_prop of this NullableClass. # noqa: E501 + + + Returns: + ({str: (bool, date, datetime, dict, float, int, list, str)}, none_type): The object_nullable_prop of this NullableClass. # noqa: E501 + """ + return self._data_store.get('object_nullable_prop') + + @object_nullable_prop.setter + def object_nullable_prop( + self, object_nullable_prop): + """Sets the object_nullable_prop of this NullableClass. + + + Returns: + ({str: (bool, date, datetime, dict, float, int, list, str)}, none_type): The object_nullable_prop of this NullableClass. # noqa: E501 + """ + + self.__setitem__( + '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 + + + Returns: + ({str: (bool, date, datetime, dict, float, int, list, str, none_type)}, none_type): The object_and_items_nullable_prop of this NullableClass. # noqa: E501 + """ + return self._data_store.get('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. + + + Returns: + ({str: (bool, date, datetime, dict, float, int, list, str, none_type)}, none_type): The object_and_items_nullable_prop of this NullableClass. # noqa: E501 + """ + + self.__setitem__( + '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 + + + Returns: + ({str: (bool, date, datetime, dict, float, int, list, str, none_type)}): The object_items_nullable of this NullableClass. # noqa: E501 + """ + return self._data_store.get('object_items_nullable') + + @object_items_nullable.setter + def object_items_nullable( + self, object_items_nullable): + """Sets the object_items_nullable of this NullableClass. + + + Returns: + ({str: (bool, date, datetime, dict, float, int, list, str, none_type)}): The object_items_nullable of this NullableClass. # noqa: E501 + """ + + self.__setitem__( + 'object_items_nullable', + object_items_nullable + ) + + def to_dict(self): + """Returns the model properties as a dict""" + return model_to_dict(self, serialize=False) + + 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 diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/number_only.py b/samples/openapi3/client/petstore/python/petstore_api/models/number_only.py index ab39ee8195d4..8cbc7054da0b 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/number_only.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/number_only.py @@ -15,8 +15,27 @@ import six - -class NumberOnly(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class NumberOnly(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class NumberOnly(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'just_number': 'float' + 'just_number': [float] # noqa: E501 } - attribute_map = { - 'just_number': 'JustNumber' + 'just_number': 'JustNumber' # noqa: E501 } - def __init__(self, just_number=None): # noqa: E501 - """NumberOnly - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """NumberOnly - a model defined in OpenAPI - self._just_number = None - self.discriminator = None - if just_number is not None: - self.just_number = just_number + + 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 False + _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 + _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. + just_number (float): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def just_number(self): """Gets the just_number of this NumberOnly. # noqa: E501 - :return: The just_number of this NumberOnly. # noqa: E501 - :rtype: float + Returns: + (float): The just_number of this NumberOnly. # noqa: E501 """ - return self._just_number + return self._data_store.get('just_number') @just_number.setter - def just_number(self, just_number): + def just_number( + self, just_number): """Sets the just_number of this NumberOnly. - :param just_number: The just_number of this NumberOnly. # noqa: E501 - :type: float + Returns: + (float): The just_number of this NumberOnly. # noqa: E501 """ - self._just_number = just_number + self.__setitem__( + 'just_number', + just_number + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/order.py b/samples/openapi3/client/petstore/python/petstore_api/models/order.py index 697d84447cdc..8f5e45a33be8 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/order.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/order.py @@ -15,8 +15,27 @@ import six - -class Order(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Order(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,134 +46,221 @@ class Order(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'id': 'int', - 'pet_id': 'int', - 'quantity': 'int', - 'ship_date': 'datetime', - 'status': 'str', - 'complete': 'bool' + 'id': [int], # noqa: E501 + 'pet_id': [int], # noqa: E501 + 'quantity': [int], # noqa: E501 + 'ship_date': [datetime], # noqa: E501 + 'status': [str], # noqa: E501 + 'complete': [bool] # noqa: E501 } - attribute_map = { - 'id': 'id', - 'pet_id': 'petId', - 'quantity': 'quantity', - 'ship_date': 'shipDate', - 'status': 'status', - 'complete': 'complete' + 'id': 'id', # noqa: E501 + 'pet_id': 'petId', # noqa: E501 + 'quantity': 'quantity', # noqa: E501 + 'ship_date': 'shipDate', # noqa: E501 + 'status': 'status', # noqa: E501 + 'complete': 'complete' # noqa: E501 } - def __init__(self, id=None, pet_id=None, quantity=None, ship_date=None, status=None, complete=False): # noqa: E501 - """Order - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Order - 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 False + _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 + _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. + id (int): [optional] # noqa: E501 + pet_id (int): [optional] # noqa: E501 + quantity (int): [optional] # noqa: E501 + ship_date (datetime): [optional] # noqa: E501 + status (str): Order Status. [optional] # noqa: E501 + complete (bool): [optional] if omitted the server will use the default value of False # noqa: E501 + """ - self._id = None - self._pet_id = None - self._quantity = None - self._ship_date = None - self._status = None - self._complete = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) - if id is not None: - self.id = id - if pet_id is not None: - self.pet_id = pet_id - if quantity is not None: - self.quantity = quantity - if ship_date is not None: - self.ship_date = ship_date - if status is not None: - self.status = status - if complete is not None: - self.complete = complete + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def id(self): """Gets the id of this Order. # noqa: E501 - :return: The id of this Order. # noqa: E501 - :rtype: int + Returns: + (int): The id of this Order. # noqa: E501 """ - return self._id + return self._data_store.get('id') @id.setter - def id(self, id): + def id( + self, id): """Sets the id of this Order. - :param id: The id of this Order. # noqa: E501 - :type: int + Returns: + (int): The id of this Order. # noqa: E501 """ - self._id = id + self.__setitem__( + 'id', + id + ) @property def pet_id(self): """Gets the pet_id of this Order. # noqa: E501 - :return: The pet_id of this Order. # noqa: E501 - :rtype: int + Returns: + (int): The pet_id of this Order. # noqa: E501 """ - return self._pet_id + return self._data_store.get('pet_id') @pet_id.setter - def pet_id(self, pet_id): + def pet_id( + self, pet_id): """Sets the pet_id of this Order. - :param pet_id: The pet_id of this Order. # noqa: E501 - :type: int + Returns: + (int): The pet_id of this Order. # noqa: E501 """ - self._pet_id = pet_id + self.__setitem__( + 'pet_id', + pet_id + ) @property def quantity(self): """Gets the quantity of this Order. # noqa: E501 - :return: The quantity of this Order. # noqa: E501 - :rtype: int + Returns: + (int): The quantity of this Order. # noqa: E501 """ - return self._quantity + return self._data_store.get('quantity') @quantity.setter - def quantity(self, quantity): + def quantity( + self, quantity): """Sets the quantity of this Order. - :param quantity: The quantity of this Order. # noqa: E501 - :type: int + Returns: + (int): The quantity of this Order. # noqa: E501 """ - self._quantity = quantity + self.__setitem__( + 'quantity', + quantity + ) @property def ship_date(self): """Gets the ship_date of this Order. # noqa: E501 - :return: The ship_date of this Order. # noqa: E501 - :rtype: datetime + Returns: + (datetime): The ship_date of this Order. # noqa: E501 """ - return self._ship_date + return self._data_store.get('ship_date') @ship_date.setter - def ship_date(self, ship_date): + def ship_date( + self, ship_date): """Sets the ship_date of this Order. - :param ship_date: The ship_date of this Order. # noqa: E501 - :type: datetime + Returns: + (datetime): The ship_date of this Order. # noqa: E501 """ - self._ship_date = ship_date + self.__setitem__( + 'ship_date', + ship_date + ) @property def status(self): @@ -162,73 +268,61 @@ def status(self): Order Status # noqa: E501 - :return: The status of this Order. # noqa: E501 - :rtype: str + Returns: + (str): The status of this Order. # noqa: E501 """ - return self._status + return self._data_store.get('status') @status.setter - def status(self, status): + def status( + self, status): """Sets the status of this Order. Order Status # noqa: E501 - :param status: The status of this Order. # noqa: E501 - :type: str + Returns: + (str): The status of this Order. # noqa: E501 """ allowed_values = ["placed", "approved", "delivered"] # noqa: E501 if status not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `status` ({0}), must be one of {1}" # noqa: E501 .format(status, allowed_values) ) - self._status = status + self.__setitem__( + 'status', + status + ) @property def complete(self): """Gets the complete of this Order. # noqa: E501 - :return: The complete of this Order. # noqa: E501 - :rtype: bool + Returns: + (bool): The complete of this Order. # noqa: E501 """ - return self._complete + return self._data_store.get('complete') @complete.setter - def complete(self, complete): + def complete( + self, complete): """Sets the complete of this Order. - :param complete: The complete of this Order. # noqa: E501 - :type: bool + Returns: + (bool): The complete of this Order. # noqa: E501 """ - self._complete = complete + self.__setitem__( + 'complete', + complete + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/outer_composite.py b/samples/openapi3/client/petstore/python/petstore_api/models/outer_composite.py index b22b16c6fdcd..3da4dfb6426d 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/outer_composite.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/outer_composite.py @@ -15,8 +15,27 @@ import six - -class OuterComposite(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class OuterComposite(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,122 +46,191 @@ class OuterComposite(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'my_number': 'float', - 'my_string': 'str', - 'my_boolean': 'bool' + 'my_number': [float], # noqa: E501 + 'my_string': [str], # noqa: E501 + 'my_boolean': [bool] # noqa: E501 } - attribute_map = { - 'my_number': 'my_number', - 'my_string': 'my_string', - 'my_boolean': 'my_boolean' + 'my_number': 'my_number', # noqa: E501 + 'my_string': 'my_string', # noqa: E501 + 'my_boolean': 'my_boolean' # noqa: E501 } - def __init__(self, my_number=None, my_string=None, my_boolean=None): # noqa: E501 - """OuterComposite - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """OuterComposite - 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 False + _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 + _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. + my_number (float): [optional] # noqa: E501 + my_string (str): [optional] # noqa: E501 + my_boolean (bool): [optional] # noqa: E501 + """ - self._my_number = None - self._my_string = None - self._my_boolean = None + self._data_store = {} self.discriminator = None - - if my_number is not None: - self.my_number = my_number - if my_string is not None: - self.my_string = my_string - if my_boolean is not None: - self.my_boolean = my_boolean + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def my_number(self): """Gets the my_number of this OuterComposite. # noqa: E501 - :return: The my_number of this OuterComposite. # noqa: E501 - :rtype: float + Returns: + (float): The my_number of this OuterComposite. # noqa: E501 """ - return self._my_number + return self._data_store.get('my_number') @my_number.setter - def my_number(self, my_number): + def my_number( + self, my_number): """Sets the my_number of this OuterComposite. - :param my_number: The my_number of this OuterComposite. # noqa: E501 - :type: float + Returns: + (float): The my_number of this OuterComposite. # noqa: E501 """ - self._my_number = my_number + self.__setitem__( + 'my_number', + my_number + ) @property def my_string(self): """Gets the my_string of this OuterComposite. # noqa: E501 - :return: The my_string of this OuterComposite. # noqa: E501 - :rtype: str + Returns: + (str): The my_string of this OuterComposite. # noqa: E501 """ - return self._my_string + return self._data_store.get('my_string') @my_string.setter - def my_string(self, my_string): + def my_string( + self, my_string): """Sets the my_string of this OuterComposite. - :param my_string: The my_string of this OuterComposite. # noqa: E501 - :type: str + Returns: + (str): The my_string of this OuterComposite. # noqa: E501 """ - self._my_string = my_string + self.__setitem__( + 'my_string', + my_string + ) @property def my_boolean(self): """Gets the my_boolean of this OuterComposite. # noqa: E501 - :return: The my_boolean of this OuterComposite. # noqa: E501 - :rtype: bool + Returns: + (bool): The my_boolean of this OuterComposite. # noqa: E501 """ - return self._my_boolean + return self._data_store.get('my_boolean') @my_boolean.setter - def my_boolean(self, my_boolean): + def my_boolean( + self, my_boolean): """Sets the my_boolean of this OuterComposite. - :param my_boolean: The my_boolean of this OuterComposite. # noqa: E501 - :type: bool + Returns: + (bool): The my_boolean of this OuterComposite. # noqa: E501 """ - self._my_boolean = my_boolean + self.__setitem__( + 'my_boolean', + my_boolean + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum.py b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum.py index 10d6be19a4c9..9d4398b5188d 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum.py @@ -15,8 +15,27 @@ import six - -class OuterEnum(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class OuterEnum(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -34,42 +53,107 @@ class OuterEnum(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { } - attribute_map = { } - def __init__(self): # noqa: E501 - """OuterEnum - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """OuterEnum - 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 False + _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 + _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. + """ + + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_default_value.py b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_default_value.py index 5bc51296116f..7eaccbb5e837 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_default_value.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_default_value.py @@ -15,8 +15,27 @@ import six - -class OuterEnumDefaultValue(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class OuterEnumDefaultValue(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -34,42 +53,107 @@ class OuterEnumDefaultValue(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { } - attribute_map = { } - def __init__(self): # noqa: E501 - """OuterEnumDefaultValue - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """OuterEnumDefaultValue - 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 False + _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 + _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. + """ + + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer.py b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer.py index 150335ae701d..4c3c383c63ff 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer.py @@ -15,8 +15,27 @@ import six - -class OuterEnumInteger(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class OuterEnumInteger(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -34,42 +53,107 @@ class OuterEnumInteger(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { } - attribute_map = { } - def __init__(self): # noqa: E501 - """OuterEnumInteger - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """OuterEnumInteger - 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 False + _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 + _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. + """ + + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer_default_value.py b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer_default_value.py index 90fbf60dc2eb..ffe4bb1a785f 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer_default_value.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer_default_value.py @@ -15,8 +15,27 @@ import six - -class OuterEnumIntegerDefaultValue(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class OuterEnumIntegerDefaultValue(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -34,42 +53,107 @@ class OuterEnumIntegerDefaultValue(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { } - attribute_map = { } - def __init__(self): # noqa: E501 - """OuterEnumIntegerDefaultValue - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """OuterEnumIntegerDefaultValue - 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 False + _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 + _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. + """ + + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/pet.py b/samples/openapi3/client/petstore/python/petstore_api/models/pet.py index d3c412f4a82b..1b30f1186d6f 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/pet.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/pet.py @@ -15,8 +15,29 @@ import six - -class Pet(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) +from petstore_api.models.category import Category +from petstore_api.models.tag import Tag + + +class Pet(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,157 +48,253 @@ class Pet(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'id': 'int', - 'category': 'Category', - 'name': 'str', - 'photo_urls': 'list[str]', - 'tags': 'list[Tag]', - 'status': 'str' + 'id': [int], # noqa: E501 + 'category': [Category], # noqa: E501 + 'name': [str], # noqa: E501 + 'photo_urls': [[(str,)]], # noqa: E501 + 'tags': [[(Tag,)]], # noqa: E501 + 'status': [str] # noqa: E501 } - attribute_map = { - 'id': 'id', - 'category': 'category', - 'name': 'name', - 'photo_urls': 'photoUrls', - 'tags': 'tags', - 'status': 'status' + 'id': 'id', # noqa: E501 + 'category': 'category', # noqa: E501 + 'name': 'name', # noqa: E501 + 'photo_urls': 'photoUrls', # noqa: E501 + 'tags': 'tags', # noqa: E501 + 'status': 'status' # noqa: E501 } - def __init__(self, id=None, category=None, name=None, photo_urls=None, tags=None, status=None): # noqa: E501 - """Pet - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, name, photo_urls, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Pet - a model defined in OpenAPI + + Args: + name (str): + photo_urls ([(str,)]): + + 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 False + _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 + _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. + id (int): [optional] # noqa: E501 + category (Category): [optional] # noqa: E501 + tags ([(Tag,)]): [optional] # noqa: E501 + status (str): pet status in the store. [optional] # noqa: E501 + """ - self._id = None - self._category = None - self._name = None - self._photo_urls = None - self._tags = None - self._status = None + self._data_store = {} self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration - if id is not None: - self.id = id - if category is not None: - self.category = category + # assign using .var_name to check against nullable and enums self.name = name self.photo_urls = photo_urls - if tags is not None: - self.tags = tags - if status is not None: - self.status = status + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def id(self): """Gets the id of this Pet. # noqa: E501 - :return: The id of this Pet. # noqa: E501 - :rtype: int + Returns: + (int): The id of this Pet. # noqa: E501 """ - return self._id + return self._data_store.get('id') @id.setter - def id(self, id): + def id( + self, id): """Sets the id of this Pet. - :param id: The id of this Pet. # noqa: E501 - :type: int + Returns: + (int): The id of this Pet. # noqa: E501 """ - self._id = id + self.__setitem__( + 'id', + id + ) @property def category(self): """Gets the category of this Pet. # noqa: E501 - :return: The category of this Pet. # noqa: E501 - :rtype: Category + Returns: + (Category): The category of this Pet. # noqa: E501 """ - return self._category + return self._data_store.get('category') @category.setter - def category(self, category): + def category( + self, category): """Sets the category of this Pet. - :param category: The category of this Pet. # noqa: E501 - :type: Category + Returns: + (Category): The category of this Pet. # noqa: E501 """ - self._category = category + self.__setitem__( + 'category', + category + ) @property def name(self): """Gets the name of this Pet. # noqa: E501 - :return: The name of this Pet. # noqa: E501 - :rtype: str + Returns: + (str): The name of this Pet. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this Pet. - :param name: The name of this Pet. # noqa: E501 - :type: str + Returns: + (str): The name of this Pet. # noqa: E501 """ if name is None: - raise ValueError("Invalid value for `name`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `name`, must not be `None`") # noqa: E501 - self._name = name + self.__setitem__( + 'name', + name + ) @property def photo_urls(self): """Gets the photo_urls of this Pet. # noqa: E501 - :return: The photo_urls of this Pet. # noqa: E501 - :rtype: list[str] + Returns: + ([(str,)]): The photo_urls of this Pet. # noqa: E501 """ - return self._photo_urls + return self._data_store.get('photo_urls') @photo_urls.setter - def photo_urls(self, photo_urls): + def photo_urls( + self, photo_urls): """Sets the photo_urls of this Pet. - :param photo_urls: The photo_urls of this Pet. # noqa: E501 - :type: list[str] + Returns: + ([(str,)]): The photo_urls of this Pet. # noqa: E501 """ if photo_urls is None: - raise ValueError("Invalid value for `photo_urls`, must not be `None`") # noqa: E501 + raise ApiValueError("Invalid value for `photo_urls`, must not be `None`") # noqa: E501 - self._photo_urls = photo_urls + self.__setitem__( + 'photo_urls', + photo_urls + ) @property def tags(self): """Gets the tags of this Pet. # noqa: E501 - :return: The tags of this Pet. # noqa: E501 - :rtype: list[Tag] + Returns: + ([(Tag,)]): The tags of this Pet. # noqa: E501 """ - return self._tags + return self._data_store.get('tags') @tags.setter - def tags(self, tags): + def tags( + self, tags): """Sets the tags of this Pet. - :param tags: The tags of this Pet. # noqa: E501 - :type: list[Tag] + Returns: + ([(Tag,)]): The tags of this Pet. # noqa: E501 """ - self._tags = tags + self.__setitem__( + 'tags', + tags + ) @property def status(self): @@ -185,52 +302,36 @@ def status(self): pet status in the store # noqa: E501 - :return: The status of this Pet. # noqa: E501 - :rtype: str + Returns: + (str): The status of this Pet. # noqa: E501 """ - return self._status + return self._data_store.get('status') @status.setter - def status(self, status): + def status( + self, status): """Sets the status of this Pet. pet status in the store # noqa: E501 - :param status: The status of this Pet. # noqa: E501 - :type: str + Returns: + (str): The status of this Pet. # noqa: E501 """ allowed_values = ["available", "pending", "sold"] # noqa: E501 if status not in allowed_values: - raise ValueError( + raise ApiValueError( "Invalid value for `status` ({0}), must be one of {1}" # noqa: E501 .format(status, allowed_values) ) - self._status = status + self.__setitem__( + 'status', + status + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/read_only_first.py b/samples/openapi3/client/petstore/python/petstore_api/models/read_only_first.py index 2b257be18de4..0309488b3f37 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/read_only_first.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/read_only_first.py @@ -15,8 +15,27 @@ import six - -class ReadOnlyFirst(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class ReadOnlyFirst(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +46,163 @@ class ReadOnlyFirst(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'bar': 'str', - 'baz': 'str' + 'bar': [str], # noqa: E501 + 'baz': [str] # noqa: E501 } - attribute_map = { - 'bar': 'bar', - 'baz': 'baz' + 'bar': 'bar', # noqa: E501 + 'baz': 'baz' # noqa: E501 } - def __init__(self, bar=None, baz=None): # noqa: E501 - """ReadOnlyFirst - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """ReadOnlyFirst - 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 False + _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 + _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. + bar (str): [optional] # noqa: E501 + baz (str): [optional] # noqa: E501 + """ - self._bar = None - self._baz = None + self._data_store = {} self.discriminator = None - - if bar is not None: - self.bar = bar - if baz is not None: - self.baz = baz + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def bar(self): """Gets the bar of this ReadOnlyFirst. # noqa: E501 - :return: The bar of this ReadOnlyFirst. # noqa: E501 - :rtype: str + Returns: + (str): The bar of this ReadOnlyFirst. # noqa: E501 """ - return self._bar + return self._data_store.get('bar') @bar.setter - def bar(self, bar): + def bar( + self, bar): """Sets the bar of this ReadOnlyFirst. - :param bar: The bar of this ReadOnlyFirst. # noqa: E501 - :type: str + Returns: + (str): The bar of this ReadOnlyFirst. # noqa: E501 """ - self._bar = bar + self.__setitem__( + 'bar', + bar + ) @property def baz(self): """Gets the baz of this ReadOnlyFirst. # noqa: E501 - :return: The baz of this ReadOnlyFirst. # noqa: E501 - :rtype: str + Returns: + (str): The baz of this ReadOnlyFirst. # noqa: E501 """ - return self._baz + return self._data_store.get('baz') @baz.setter - def baz(self, baz): + def baz( + self, baz): """Sets the baz of this ReadOnlyFirst. - :param baz: The baz of this ReadOnlyFirst. # noqa: E501 - :type: str + Returns: + (str): The baz of this ReadOnlyFirst. # noqa: E501 """ - self._baz = baz + self.__setitem__( + 'baz', + baz + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/special_model_name.py b/samples/openapi3/client/petstore/python/petstore_api/models/special_model_name.py index fa59b887471b..9431157f2c3e 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/special_model_name.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/special_model_name.py @@ -15,8 +15,27 @@ import six - -class SpecialModelName(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class SpecialModelName(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,70 +46,135 @@ class SpecialModelName(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'special_property_name': 'int' + 'special_property_name': [int] # noqa: E501 } - attribute_map = { - 'special_property_name': '$special[property.name]' + 'special_property_name': '$special[property.name]' # noqa: E501 } - def __init__(self, special_property_name=None): # noqa: E501 - """SpecialModelName - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """SpecialModelName - a model defined in OpenAPI - self._special_property_name = None - self.discriminator = None - if special_property_name is not None: - self.special_property_name = special_property_name + + 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 False + _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 + _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. + special_property_name (int): [optional] # noqa: E501 + """ + + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def special_property_name(self): """Gets the special_property_name of this SpecialModelName. # noqa: E501 - :return: The special_property_name of this SpecialModelName. # noqa: E501 - :rtype: int + Returns: + (int): The special_property_name of this SpecialModelName. # noqa: E501 """ - return self._special_property_name + return self._data_store.get('special_property_name') @special_property_name.setter - def special_property_name(self, special_property_name): + def special_property_name( + self, special_property_name): """Sets the special_property_name of this SpecialModelName. - :param special_property_name: The special_property_name of this SpecialModelName. # noqa: E501 - :type: int + Returns: + (int): The special_property_name of this SpecialModelName. # noqa: E501 """ - self._special_property_name = special_property_name + self.__setitem__( + 'special_property_name', + special_property_name + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/tag.py b/samples/openapi3/client/petstore/python/petstore_api/models/tag.py index 8fcc8a848660..0c781dc5be7c 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/tag.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/tag.py @@ -15,8 +15,27 @@ import six - -class Tag(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class Tag(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,96 +46,163 @@ class Tag(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'id': 'int', - 'name': 'str' + 'id': [int], # noqa: E501 + 'name': [str] # noqa: E501 } - attribute_map = { - 'id': 'id', - 'name': 'name' + 'id': 'id', # noqa: E501 + 'name': 'name' # noqa: E501 } - def __init__(self, id=None, name=None): # noqa: E501 - """Tag - a model defined in OpenAPI""" # noqa: E501 + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """Tag - 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 False + _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 + _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. + id (int): [optional] # noqa: E501 + name (str): [optional] # noqa: E501 + """ - self._id = None - self._name = None + self._data_store = {} self.discriminator = None - - if id is not None: - self.id = id - if name is not None: - self.name = name + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def id(self): """Gets the id of this Tag. # noqa: E501 - :return: The id of this Tag. # noqa: E501 - :rtype: int + Returns: + (int): The id of this Tag. # noqa: E501 """ - return self._id + return self._data_store.get('id') @id.setter - def id(self, id): + def id( + self, id): """Sets the id of this Tag. - :param id: The id of this Tag. # noqa: E501 - :type: int + Returns: + (int): The id of this Tag. # noqa: E501 """ - self._id = id + self.__setitem__( + 'id', + id + ) @property def name(self): """Gets the name of this Tag. # noqa: E501 - :return: The name of this Tag. # noqa: E501 - :rtype: str + Returns: + (str): The name of this Tag. # noqa: E501 """ - return self._name + return self._data_store.get('name') @name.setter - def name(self, name): + def name( + self, name): """Sets the name of this Tag. - :param name: The name of this Tag. # noqa: E501 - :type: str + Returns: + (str): The name of this Tag. # noqa: E501 """ - self._name = name + self.__setitem__( + 'name', + name + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/user.py b/samples/openapi3/client/petstore/python/petstore_api/models/user.py index 9736c47c1f87..33b99bfdb45c 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/user.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/user.py @@ -15,8 +15,27 @@ import six - -class User(object): +from petstore_api.exceptions import ( + ApiKeyError, + ApiTypeError, + ApiValueError, +) +from petstore_api.model_utils import ( # noqa: F401 + OpenApiModel, + date, + datetime, + file_type, + get_simple_class, + int, + model_to_dict, + none_type, + str, + type_error_message, + validate_and_convert_types +) + + +class User(OpenApiModel): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -27,207 +46,302 @@ class User(object): Attributes: openapi_types (dict): The key is attribute name and the value is attribute type. + Optional and required variables only. attribute_map (dict): The key is attribute name and the value is json key in definition. + Optional, required variables, and + additional properties. """ openapi_types = { - 'id': 'int', - 'username': 'str', - 'first_name': 'str', - 'last_name': 'str', - 'email': 'str', - 'password': 'str', - 'phone': 'str', - 'user_status': 'int' + 'id': [int], # noqa: E501 + 'username': [str], # noqa: E501 + 'first_name': [str], # noqa: E501 + 'last_name': [str], # noqa: E501 + 'email': [str], # noqa: E501 + 'password': [str], # noqa: E501 + 'phone': [str], # noqa: E501 + 'user_status': [int] # noqa: E501 } - attribute_map = { - 'id': 'id', - 'username': 'username', - 'first_name': 'firstName', - 'last_name': 'lastName', - 'email': 'email', - 'password': 'password', - 'phone': 'phone', - 'user_status': 'userStatus' + 'id': 'id', # noqa: E501 + 'username': 'username', # noqa: E501 + 'first_name': 'firstName', # noqa: E501 + 'last_name': 'lastName', # noqa: E501 + 'email': 'email', # noqa: E501 + 'password': 'password', # noqa: E501 + 'phone': 'phone', # noqa: E501 + 'user_status': 'userStatus' # noqa: E501 } - def __init__(self, id=None, username=None, first_name=None, last_name=None, email=None, password=None, phone=None, user_status=None): # noqa: E501 - """User - a model defined in OpenAPI""" # noqa: E501 - - self._id = None - self._username = None - self._first_name = None - self._last_name = None - self._email = None - self._password = None - self._phone = None - self._user_status = None - self.discriminator = None + def __init__(self, _check_type=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """User - 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 False + _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 + _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. + id (int): [optional] # noqa: E501 + username (str): [optional] # noqa: E501 + first_name (str): [optional] # noqa: E501 + last_name (str): [optional] # noqa: E501 + email (str): [optional] # noqa: E501 + password (str): [optional] # noqa: E501 + phone (str): [optional] # noqa: E501 + user_status (int): User Status. [optional] # noqa: E501 + """ - if id is not None: - self.id = id - if username is not None: - self.username = username - if first_name is not None: - self.first_name = first_name - if last_name is not None: - self.last_name = last_name - if email is not None: - self.email = email - if password is not None: - self.password = password - if phone is not None: - self.phone = phone - if user_status is not None: - self.user_status = user_status + self._data_store = {} + self.discriminator = None + self._check_type = _check_type + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name in self.openapi_types: + # assign using .var_name to check against nullable and enums + setattr(self, var_name, var_value) + else: + self.__setitem__(var_name, var_value) + + def __setitem__(self, name, value): + if name in self.openapi_types: + check_type = self._check_type + required_types_mixed = self.openapi_types[name] + else: + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + path_to_item + ) + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + + if get_simple_class(name) != str: + error_msg = type_error_message( + var_name=name, + var_value=name, + valid_classes=(str,), + key_type=True + ) + raise ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=(str,), + key_type=True + ) + + if check_type: + self._data_store[name] = validate_and_convert_types( + value, required_types_mixed, path_to_item, + configuration=self._configuration) + else: + self._data_store[name] = value + + def __getitem__(self, name): + if name in self.openapi_types: + return self._data_store.get(name) + if name in self._data_store: + return self._data_store[name] + + path_to_item = [] + if self._path_to_item: + path_to_item.extend(self._path_to_item) + path_to_item.append(name) + raise ApiKeyError( + "{0} has no key '{1}'".format(type(self).__name__, name), + [name] + ) @property def id(self): """Gets the id of this User. # noqa: E501 - :return: The id of this User. # noqa: E501 - :rtype: int + Returns: + (int): The id of this User. # noqa: E501 """ - return self._id + return self._data_store.get('id') @id.setter - def id(self, id): + def id( + self, id): """Sets the id of this User. - :param id: The id of this User. # noqa: E501 - :type: int + Returns: + (int): The id of this User. # noqa: E501 """ - self._id = id + self.__setitem__( + 'id', + id + ) @property def username(self): """Gets the username of this User. # noqa: E501 - :return: The username of this User. # noqa: E501 - :rtype: str + Returns: + (str): The username of this User. # noqa: E501 """ - return self._username + return self._data_store.get('username') @username.setter - def username(self, username): + def username( + self, username): """Sets the username of this User. - :param username: The username of this User. # noqa: E501 - :type: str + Returns: + (str): The username of this User. # noqa: E501 """ - self._username = username + self.__setitem__( + 'username', + username + ) @property def first_name(self): """Gets the first_name of this User. # noqa: E501 - :return: The first_name of this User. # noqa: E501 - :rtype: str + Returns: + (str): The first_name of this User. # noqa: E501 """ - return self._first_name + return self._data_store.get('first_name') @first_name.setter - def first_name(self, first_name): + def first_name( + self, first_name): """Sets the first_name of this User. - :param first_name: The first_name of this User. # noqa: E501 - :type: str + Returns: + (str): The first_name of this User. # noqa: E501 """ - self._first_name = first_name + self.__setitem__( + 'first_name', + first_name + ) @property def last_name(self): """Gets the last_name of this User. # noqa: E501 - :return: The last_name of this User. # noqa: E501 - :rtype: str + Returns: + (str): The last_name of this User. # noqa: E501 """ - return self._last_name + return self._data_store.get('last_name') @last_name.setter - def last_name(self, last_name): + def last_name( + self, last_name): """Sets the last_name of this User. - :param last_name: The last_name of this User. # noqa: E501 - :type: str + Returns: + (str): The last_name of this User. # noqa: E501 """ - self._last_name = last_name + self.__setitem__( + 'last_name', + last_name + ) @property def email(self): """Gets the email of this User. # noqa: E501 - :return: The email of this User. # noqa: E501 - :rtype: str + Returns: + (str): The email of this User. # noqa: E501 """ - return self._email + return self._data_store.get('email') @email.setter - def email(self, email): + def email( + self, email): """Sets the email of this User. - :param email: The email of this User. # noqa: E501 - :type: str + Returns: + (str): The email of this User. # noqa: E501 """ - self._email = email + self.__setitem__( + 'email', + email + ) @property def password(self): """Gets the password of this User. # noqa: E501 - :return: The password of this User. # noqa: E501 - :rtype: str + Returns: + (str): The password of this User. # noqa: E501 """ - return self._password + return self._data_store.get('password') @password.setter - def password(self, password): + def password( + self, password): """Sets the password of this User. - :param password: The password of this User. # noqa: E501 - :type: str + Returns: + (str): The password of this User. # noqa: E501 """ - self._password = password + self.__setitem__( + 'password', + password + ) @property def phone(self): """Gets the phone of this User. # noqa: E501 - :return: The phone of this User. # noqa: E501 - :rtype: str + Returns: + (str): The phone of this User. # noqa: E501 """ - return self._phone + return self._data_store.get('phone') @phone.setter - def phone(self, phone): + def phone( + self, phone): """Sets the phone of this User. - :param phone: The phone of this User. # noqa: E501 - :type: str + Returns: + (str): The phone of this User. # noqa: E501 """ - self._phone = phone + self.__setitem__( + 'phone', + phone + ) @property def user_status(self): @@ -235,46 +349,30 @@ def user_status(self): User Status # noqa: E501 - :return: The user_status of this User. # noqa: E501 - :rtype: int + Returns: + (int): The user_status of this User. # noqa: E501 """ - return self._user_status + return self._data_store.get('user_status') @user_status.setter - def user_status(self, user_status): + def user_status( + self, user_status): """Sets the user_status of this User. User Status # noqa: E501 - :param user_status: The user_status of this User. # noqa: E501 - :type: int + Returns: + (int): The user_status of this User. # noqa: E501 """ - self._user_status = user_status + self.__setitem__( + 'user_status', + user_status + ) 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 + return model_to_dict(self, serialize=False) def to_str(self): """Returns the string representation of the model""" diff --git a/samples/openapi3/client/petstore/python/petstore_api/rest.py b/samples/openapi3/client/petstore/python/petstore_api/rest.py index 30ba5fb8d3f5..7f44af7113fd 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/rest.py +++ b/samples/openapi3/client/petstore/python/petstore_api/rest.py @@ -22,12 +22,9 @@ # python 2 and python 3 compatibility library import six from six.moves.urllib.parse import urlencode +import urllib3 -try: - import urllib3 -except ImportError: - raise ImportError('OpenAPI Python client requires urllib3.') - +from petstore_api.exceptions import ApiException, ApiValueError logger = logging.getLogger(__name__) @@ -130,7 +127,7 @@ def request(self, method, url, query_params=None, headers=None, 'PATCH', 'OPTIONS'] if post_params and body: - raise ValueError( + raise ApiValueError( "body parameter cannot be used with post_params parameter." ) @@ -292,31 +289,3 @@ def PATCH(self, url, headers=None, query_params=None, post_params=None, _preload_content=_preload_content, _request_timeout=_request_timeout, body=body) - - -class ApiException(Exception): - - 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 diff --git a/samples/openapi3/client/petstore/python/petstore_api/utils.py b/samples/openapi3/client/petstore/python/petstore_api/utils.py new file mode 100644 index 000000000000..0bad6742a836 --- /dev/null +++ b/samples/openapi3/client/petstore/python/petstore_api/utils.py @@ -0,0 +1,216 @@ +# 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 datetime import date, datetime # noqa: F401 + +import six + +none_type = type(None) +if six.PY3: + import io + file_type = io.IOBase +else: + file_type = file # noqa: F821 + + +class OpenApiModel(object): + """The base class for all OpenAPIModels""" + + +class OpenApiException(Exception): + """The base exception class for all OpenAPIExceptions""" + + +class ApiTypeError(OpenApiException, TypeError): + def __init__(self, required_types, current_item, path_to_item, + key_type=False): + """ Raises an exception for TypeErrors + + Args: + required_types (tuple): the primitive classes that current item + should be an instance of + current_item (any): the value which is the incorrect type + path_to_item (list): a list of keys an indices to get to the + current_item + 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 + """ + key_or_value = 'value' + if key_type: + key_or_value = 'key' + msg = ( + "Invalid type for variable {0}. Required {1} type is {2} and " + "passed type was {3} at location={4}".format( + path_to_item[0], + key_or_value, + required_types, + type(current_item), + path_to_item + ) + ) + super(ApiTypeError, self).__init__(msg) + self.key_type = key_type + self.path_to_item = path_to_item + self.current_item = current_item + self.required_types = required_types + + +class ApiValueError(OpenApiException, ValueError): + def __init__(self, msg): + super(ApiTypeError, self).__init__(msg) + + +class ApiKeyError(OpenApiException, KeyError): + def __init__(self, msg): + super(ApiKeyError, self).__init__(msg) + + +def get_required_type_classes(required_types): + """Converts the tuple required_types into a tuple of: + tuple(child_classes), dict(class: required_type) + where required_type is a class or list instance or dict instance + + Args: + required_types (tuple/list): will contain either classes or instance + of list or dict + """ + results = [] + child_req_types_by_current_type = {} + for required_type in required_types: + if isinstance(required_type, list): + results.append(list) + child_req_types_by_current_type[list] = required_type[0] + elif isinstance(required_type, dict): + results.append(dict) + child_req_types_by_current_type[dict] = required_type[str] + else: + results.append(required_type) + return tuple(results), child_req_types_by_current_type + + +def get_parent_key_or_index(input_data, variable_path): + """Returns a tuple of parent, key_or_index + + Args: + input_data (dict/list): the root data object that had an + ApiTypeException + variable_path (list): the path to the exception, values are keys or + indices + + Returns: + [parent, key_or_index]: + parent (dict/list): the parent of the item that has an + ApiTypeException + key_or_index (str/int): the key that points to the item that has an + ApiTypeException + """ + current_item = input_data + for index, path_value in variable_path[:-1]: + current_item = current_item[path_value] + parent = current_item + key_or_index = variable_path[-1] + return parent, key_or_index + + +def validate_type(input_value, required_types, variable_path): + """Raises a TypeError is ther is a problem, otherwise continue""" + results = get_required_type_classes(required_types) + valid_classes, child_req_types_by_current_type = results + + valid_type = False + for required_class in valid_classes: + if ((type(input_value) == bool and required_class == int) or + (type(input_value) == datetime and required_class == date)): + # we can't use isinstance because + # isinstance(True, int) == True == isinstance(datetime_val, date) + valid_type = False + continue + valid_type = isinstance(input_value, required_class) + if valid_type: + break + if not valid_type: + raise ApiTypeError( + valid_classes, + input_value, + variable_path + ) + # input_value's type is in valid_classes + if child_req_types_by_current_type == {}: + # all types are of the required types and there are no more inner + # variables left to look at + return + inner_required_types = child_req_types_by_current_type.get( + type(input_value) + ) + if inner_required_types is None: + # for this type, there are not more inner variables left to look at + return + if isinstance(input_value, list): + if input_value == []: + # allow an empty list + return + for index, inner_value in enumerate(input_value): + inner_path = list(variable_path) + inner_path.append(index) + validate_type(inner_value, inner_required_types, inner_path) + elif isinstance(input_value, dict): + if input_value == {}: + # allow an empty dict + return + for inner_key, inner_val in six.iteritems(input_value): + inner_path = list(variable_path) + inner_path.append(inner_key) + if not isinstance(inner_key, str): + raise ApiTypeError( + (str,), + inner_key, + inner_path, + key_type=True + ) + validate_type(inner_val, inner_required_types, inner_path) + + +def model_to_dict(model_instance, serialize=True): + """Returns the model properties as a dict + + Args: + model_instance (one of your model instances): the model instance that + will be converted to a dict. + + Keyword Args: + serialize (bool): if True, the keys in the dict will be values from + attribute_map + """ + result = {} + + for attr, value in six.iteritems(model_instance._data_store): + if serialize: + attr = model_instance.attribute_map[attr] + if isinstance(value, list): + result[attr] = list(map( + lambda x: model_to_dict(x, serialize=serialize) + if hasattr(x, '_data_store') else x, value + )) + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], + model_to_dict(item[1], serialize=serialize)) + if hasattr(item[1], '_data_store') else item, + value.items() + )) + elif hasattr(value, '_data_store'): + result[attr] = model_to_dict(value, serialize=serialize) + else: + result[attr] = value + + return result diff --git a/samples/openapi3/client/petstore/python/requirements.txt b/samples/openapi3/client/petstore/python/requirements.txt index bafdc07532f5..2e252c8a0833 100644 --- a/samples/openapi3/client/petstore/python/requirements.txt +++ b/samples/openapi3/client/petstore/python/requirements.txt @@ -1,5 +1,6 @@ certifi >= 14.05.14 -six >= 1.10 +future; python_version<="2.7" python_dateutil >= 2.5.3 setuptools >= 21.0.0 +six >= 1.10 urllib3 >= 1.15.1 diff --git a/samples/openapi3/client/petstore/python/setup.py b/samples/openapi3/client/petstore/python/setup.py index 3cfa069e2047..7655bd0faa12 100644 --- a/samples/openapi3/client/petstore/python/setup.py +++ b/samples/openapi3/client/petstore/python/setup.py @@ -31,6 +31,11 @@ url="", keywords=["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"], install_requires=REQUIRES, + extras_require={ + ':python_version <= "2.7"': [ + 'future', + ], + }, packages=find_packages(), include_package_data=True, long_description="""\ diff --git a/samples/openapi3/client/petstore/python/test/test_nullable_class.py b/samples/openapi3/client/petstore/python/test/test_nullable_class.py new file mode 100644 index 000000000000..7089bee5280c --- /dev/null +++ b/samples/openapi3/client/petstore/python/test/test_nullable_class.py @@ -0,0 +1,349 @@ +# 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.utils import ApiTypeError +from test.utils import EXAMPLES, VAR_NAME_INVALID_TYPES, get_examples + + +VALID_TYPES_BY_VAR = { + 'integer_prop': ['int', 'None'], + 'number_prop': ['float', 'None'], + 'boolean_prop': ['bool', 'None'], + 'string_prop': ['str', 'None'], + 'date_prop': ['date', 'None'], + 'datetime_prop': ['datetime', 'None'], + 'array_nullable_prop': ['list', 'None'], + 'object_nullable_prop': ['dict', 'None'] +} + +class TestNullableClass(unittest.TestCase): + """NullableClass unit test stubs""" + + def test_integer_prop_valid_values(self): + var_name = 'integer_prop' + for var_value in get_examples(VALID_TYPES_BY_VAR[var_name]): + keyword_args = {var_name: var_value} + a = NullableClass(_check_type=True, **keyword_args) + assert a[var_name] == var_value + assert a.to_dict() == keyword_args + b = NullableClass(_check_type=True) + b[var_name] = var_value + assert b[var_name] == var_value + assert b.to_dict() == keyword_args + + def test_integer_prop_invalid_values(self): + var_name = 'integer_prop' + valid_types = VALID_TYPES_BY_VAR[var_name] + invalid_types = [ + val for val in EXAMPLES.keys() if val not in valid_types + ] + for var_value in get_examples(invalid_types): + keyword_args = {var_name: var_value} + with self.assertRaises(ApiTypeError) as exc: + a = NullableClass(_check_type=True, **keyword_args) + with self.assertRaises(ApiTypeError): + a = NullableClass(_check_type=True) + a[var_name] = var_value + + def test_number_prop_valid_values(self): + var_name = 'number_prop' + for var_value in get_examples(VALID_TYPES_BY_VAR[var_name]): + keyword_args = {var_name: var_value} + a = NullableClass(_check_type=True, **keyword_args) + assert a[var_name] == var_value + assert a.to_dict() == keyword_args + b = NullableClass(_check_type=True) + b[var_name] = var_value + assert b[var_name] == var_value + assert b.to_dict() == keyword_args + + def test_number_prop_invalid_values(self): + var_name = 'number_prop' + valid_types = VALID_TYPES_BY_VAR[var_name] + invalid_types = [ + val for val in EXAMPLES.keys() if val not in valid_types + ] + for var_value in get_examples(invalid_types): + keyword_args = {var_name: var_value} + with self.assertRaises(ApiTypeError): + NullableClass(_check_type=True, **keyword_args) + with self.assertRaises(ApiTypeError): + a = NullableClass(_check_type=True) + a[var_name] = var_value + + def test_boolean_prop_valid_values(self): + var_name = 'boolean_prop' + for var_value in get_examples(VALID_TYPES_BY_VAR[var_name]): + keyword_args = {var_name: var_value} + a = NullableClass(_check_type=True, **keyword_args) + assert a[var_name] == var_value + assert a.to_dict() == keyword_args + b = NullableClass(_check_type=True) + b[var_name] = var_value + assert b[var_name] == var_value + assert b.to_dict() == keyword_args + + def test_boolean_prop_invalid_values(self): + var_name = 'boolean_prop' + valid_types = VALID_TYPES_BY_VAR[var_name] + invalid_types = [ + val for val in EXAMPLES.keys() if val not in valid_types + ] + for var_value in get_examples(invalid_types): + keyword_args = {var_name: var_value} + with self.assertRaises(ApiTypeError): + NullableClass(_check_type=True, **keyword_args) + with self.assertRaises(ApiTypeError): + a = NullableClass(_check_type=True) + a[var_name] = var_value + + def test_string_prop_valid_values(self): + var_name = 'string_prop' + for var_value in get_examples(VALID_TYPES_BY_VAR[var_name]): + keyword_args = {var_name: var_value} + a = NullableClass(_check_type=True, **keyword_args) + assert a[var_name] == var_value + assert a.to_dict() == keyword_args + b = NullableClass(_check_type=True) + b[var_name] = var_value + assert b[var_name] == var_value + assert b.to_dict() == keyword_args + + def test_string_prop_invalid_values(self): + var_name = 'string_prop' + valid_types = VALID_TYPES_BY_VAR[var_name] + invalid_types = [ + val for val in EXAMPLES.keys() if val not in valid_types + ] + for var_value in get_examples(invalid_types): + keyword_args = {var_name: var_value} + with self.assertRaises(ApiTypeError): + NullableClass(_check_type=True, **keyword_args) + with self.assertRaises(ApiTypeError): + a = NullableClass(_check_type=True) + a[var_name] = var_value + + def test_date_prop_valid_values(self): + var_name = 'date_prop' + for var_value in get_examples(VALID_TYPES_BY_VAR[var_name]): + keyword_args = {var_name: var_value} + a = NullableClass(_check_type=True, **keyword_args) + assert a[var_name] == var_value + assert a.to_dict() == keyword_args + b = NullableClass(_check_type=True) + b[var_name] = var_value + assert b[var_name] == var_value + assert b.to_dict() == keyword_args + + def test_date_prop_invalid_values(self): + var_name = 'date_prop' + valid_types = VALID_TYPES_BY_VAR[var_name] + invalid_types = [ + val for val in EXAMPLES.keys() if val not in valid_types + ] + for var_value in get_examples(invalid_types): + keyword_args = {var_name: var_value} + with self.assertRaises(ApiTypeError): + NullableClass(_check_type=True, **keyword_args) + print(keyword_args) + a = 5 + with self.assertRaises(ApiTypeError): + a = NullableClass(_check_type=True) + a[var_name] = var_value + + def test_datetime_prop_valid_values(self): + var_name = 'datetime_prop' + for var_value in get_examples(VALID_TYPES_BY_VAR[var_name]): + keyword_args = {var_name: var_value} + a = NullableClass(_check_type=True, **keyword_args) + assert a[var_name] == var_value + assert a.to_dict() == keyword_args + b = NullableClass(_check_type=True) + b[var_name] = var_value + assert b[var_name] == var_value + assert b.to_dict() == keyword_args + + def test_datetime_prop_invalid_values(self): + var_name = 'datetime_prop' + valid_types = VALID_TYPES_BY_VAR[var_name] + invalid_types = [ + val for val in EXAMPLES.keys() if val not in valid_types + ] + for var_value in get_examples(invalid_types): + keyword_args = {var_name: var_value} + with self.assertRaises(ApiTypeError): + NullableClass(_check_type=True, **keyword_args) + with self.assertRaises(ApiTypeError): + a = NullableClass(_check_type=True) + a[var_name] = var_value + + def test_array_nullable_prop_valid_values(self): + var_name = 'array_nullable_prop' + for var_value in get_examples(VALID_TYPES_BY_VAR[var_name]): + keyword_args = {var_name: var_value} + a = NullableClass(_check_type=True, **keyword_args) + assert a[var_name] == var_value + assert a.to_dict() == keyword_args + b = NullableClass(_check_type=True) + b[var_name] = var_value + assert b[var_name] == var_value + assert b.to_dict() == keyword_args + + def test_array_nullable_prop_invalid_values(self): + var_name = 'array_nullable_prop' + valid_types = VALID_TYPES_BY_VAR[var_name] + invalid_types = [ + val for val in EXAMPLES.keys() if val not in valid_types + ] + for var_value in get_examples(invalid_types): + keyword_args = {var_name: var_value} + with self.assertRaises(ApiTypeError): + NullableClass(_check_type=True, **keyword_args) + with self.assertRaises(ApiTypeError): + a = NullableClass(_check_type=True) + a[var_name] = var_value + + def test_array_and_items_nullable_prop_valid_values(self): + var_name = 'array_and_items_nullable_prop' + var_values = get_examples(['list', 'None']) + var_values.append([None]) + for var_value in var_values: + keyword_args = {var_name: var_value} + a = NullableClass(_check_type=True, **keyword_args) + assert a[var_name] == var_value + assert a.to_dict() == keyword_args + b = NullableClass(_check_type=True) + b[var_name] = var_value + assert b[var_name] == var_value + assert b.to_dict() == keyword_args + + def test_array_and_items_nullable_prop_invalid_values(self): + var_name = 'array_and_items_nullable_prop' + var_values = [object, [object]] + for var_value in var_values: + keyword_args = {var_name: var_value} + with self.assertRaises(ApiTypeError): + NullableClass(_check_type=True, **keyword_args) + with self.assertRaises(ApiTypeError): + a = NullableClass(_check_type=True) + a[var_name] = var_value + + def test_array_items_nullable_valid_values(self): + var_name = 'array_items_nullable' + var_values = get_examples(['list']) + var_values.append([None]) + for var_value in var_values: + keyword_args = {var_name: var_value} + a = NullableClass(_check_type=True, **keyword_args) + assert a[var_name] == var_value + assert a.to_dict() == keyword_args + b = NullableClass(_check_type=True) + b[var_name] = var_value + assert b[var_name] == var_value + assert b.to_dict() == keyword_args + + def test_array_items_nullable_invalid_values(self): + var_name = 'array_items_nullable' + var_values = [None, object, [object]] + for var_value in var_values: + keyword_args = {var_name: var_value} + with self.assertRaises(ApiTypeError): + NullableClass(_check_type=True, **keyword_args) + with self.assertRaises(ApiTypeError): + a = NullableClass(_check_type=True) + a[var_name] = var_value + + def test_object_nullable_prop_valid_values(self): + var_name = 'object_nullable_prop' + for var_value in get_examples(VALID_TYPES_BY_VAR[var_name]): + keyword_args = {var_name: var_value} + a = NullableClass(_check_type=True, **keyword_args) + assert a[var_name] == var_value + assert a.to_dict() == keyword_args + b = NullableClass(_check_type=True) + b[var_name] = var_value + assert b[var_name] == var_value + assert b.to_dict() == keyword_args + + def test_object_nullable_prop_invalid_values(self): + var_name = 'object_nullable_prop' + valid_types = VALID_TYPES_BY_VAR[var_name] + invalid_types = [ + val for val in EXAMPLES.keys() if val not in valid_types + ] + for var_value in get_examples(invalid_types): + keyword_args = {var_name: var_value} + with self.assertRaises(ApiTypeError): + NullableClass(_check_type=True, **keyword_args) + with self.assertRaises(ApiTypeError): + a = NullableClass(_check_type=True) + a[var_name] = var_value + + def test_object_and_items_nullable_prop_valid_values(self): + var_name = 'object_and_items_nullable_prop' + var_values = get_examples(['dict', 'None']) + var_values.append({'hi': None}) + for var_value in var_values: + keyword_args = {var_name: var_value} + a = NullableClass(_check_type=True, **keyword_args) + assert a[var_name] == var_value + assert a.to_dict() == keyword_args + b = NullableClass(_check_type=True) + b[var_name] = var_value + assert b[var_name] == var_value + assert b.to_dict() == keyword_args + + def test_object_and_items_nullable_prop_invalid_values(self): + var_name = 'object_and_items_nullable_prop' + var_values = [object, {'hi': object}] + for var_value in var_values: + keyword_args = {var_name: var_value} + with self.assertRaises(ApiTypeError): + NullableClass(_check_type=True, **keyword_args) + with self.assertRaises(ApiTypeError): + a = NullableClass(_check_type=True) + a[var_name] = var_value + + def test_object_items_nullable_valid_values(self): + var_name = 'object_items_nullable' + var_values = get_examples(['dict']) + var_values.append({'hi': None}) + for var_value in var_values: + keyword_args = {var_name: var_value} + a = NullableClass(_check_type=True, **keyword_args) + assert a[var_name] == var_value + assert a.to_dict() == keyword_args + b = NullableClass(_check_type=True) + b[var_name] = var_value + assert b[var_name] == var_value + assert b.to_dict() == keyword_args + + def test_object_items_nullable_invalid_values(self): + var_name = 'object_items_nullable' + var_values = [None, object, {'hi': object}] + for var_value in var_values: + keyword_args = {var_name: var_value} + with self.assertRaises(ApiTypeError): + NullableClass(_check_type=True, **keyword_args) + with self.assertRaises(ApiTypeError): + a = NullableClass(_check_type=True) + a[var_name] = var_value + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python/test/utils.py b/samples/openapi3/client/petstore/python/test/utils.py new file mode 100644 index 000000000000..d571a4c69e97 --- /dev/null +++ b/samples/openapi3/client/petstore/python/test/utils.py @@ -0,0 +1,103 @@ +# coding: utf-8 + +from datetime import date, datetime, timedelta, tzinfo + + +class TimeZone(tzinfo): + def __init__(self, hours_offset): + self.time_delta = timedelta(hours=hours_offset) + def utcoffset(self, dt): + return self.time_delta + +exmple_simple = { + 'int': [2, -5, 0], + 'str': ['مرحبا كيف حالك', 'fancy\nstring', 'hey there'], + 'float': [3.14159, -12.4, 0.0], + 'bool': [True, False], + 'None': [None], + 'date': [date(1000, 7, 31), date(1970, 1, 1), date(2396, 2, 29)], + 'datetime': [datetime(1000, 7, 31, 13, 32, 57, tzinfo=None), datetime(1970, 1, 1, 2, 12, 41, tzinfo=TimeZone(0)), datetime(2396, 2, 29, 23, 57, 6, tzinfo=TimeZone(-6))] +} + +example_list_monotypes = [ + [], + [exmple_simple['int'][0]], + exmple_simple['int'], + [exmple_simple['str'][0]], + exmple_simple['str'], + [exmple_simple['float'][0]], + exmple_simple['float'], + [exmple_simple['bool'][0]], + exmple_simple['bool'], + [exmple_simple['date'][0]], + exmple_simple['date'], + [exmple_simple['datetime'][0]], + exmple_simple['datetime'] +] + +example_dict_monotypes = [ + {}, + {exmple_simple['str'][0]: exmple_simple['str'][0]}, + {exmple_simple['str'][0]: exmple_simple['int'][0]}, + {exmple_simple['str'][0]: exmple_simple['float'][0]}, + {exmple_simple['str'][0]: exmple_simple['bool'][0]}, + {exmple_simple['str'][0]: exmple_simple['date'][0]}, + {exmple_simple['str'][0]: exmple_simple['datetime'][0]}, + {exmple_simple['str'][1]: exmple_simple['str'][1]}, + {exmple_simple['str'][1]: exmple_simple['int'][1]}, + {exmple_simple['str'][1]: exmple_simple['float'][1]}, + {exmple_simple['str'][1]: exmple_simple['bool'][1]}, + {exmple_simple['str'][1]: exmple_simple['date'][1]}, + {exmple_simple['str'][1]: exmple_simple['datetime'][1]}, + {exmple_simple['str'][2]: exmple_simple['str'][2]}, + {exmple_simple['str'][2]: exmple_simple['int'][2]}, + {exmple_simple['str'][2]: exmple_simple['float'][2]}, + {exmple_simple['str'][2]: exmple_simple['bool'][0]}, + {exmple_simple['str'][2]: exmple_simple['date'][2]}, + {exmple_simple['str'][2]: exmple_simple['datetime'][2]} +] +# add lists to dict +example_dict_monotypes_all = list(example_dict_monotypes) +for example_list_monotype in example_list_monotypes: + example_dict_monotypes_all.append( + {exmple_simple['str'][0]: example_list_monotype} + ) +# add self to dict, nested +current_items = list(example_dict_monotypes_all) +for current_item in current_items: + example_dict_monotypes_all.append( + {exmple_simple['str'][0]: current_item} + ) + +# add dicts to list +example_list_monotypes_all = list(example_list_monotypes) +for example_dict_monotype in example_dict_monotypes: + example_list_monotypes_all.append( + [example_dict_monotype] + ) +# add self to list, nested +current_items = list(example_list_monotypes_all) +for current_item in current_items: + example_list_monotypes_all.append( + [current_item] + ) +EXAMPLES = { + 'int': exmple_simple['int'], + 'str': exmple_simple['str'], + 'float': exmple_simple['float'], + 'bool': exmple_simple['bool'], + 'None': exmple_simple['None'], + 'date': exmple_simple['date'], + 'datetime': exmple_simple['datetime'], + 'list': example_list_monotypes_all, + 'dict': example_dict_monotypes_all +} + +VAR_NAME_INVALID_TYPES = ['int', 'float', 'bool', 'None'] + + +def get_examples(types): + res = [] + for type in types: + res.extend(EXAMPLES[type]) + return res diff --git a/samples/server/petstore/jaxrs-cxf/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java b/samples/server/petstore/jaxrs-cxf/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java index 70d0b3fb041c..b5e047a7a2de 100644 --- a/samples/server/petstore/jaxrs-cxf/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java +++ b/samples/server/petstore/jaxrs-cxf/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java @@ -16,7 +16,7 @@ import javax.xml.bind.annotation.XmlEnumValue; import com.fasterxml.jackson.annotation.JsonProperty; -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @ApiModelProperty(value = "") private Map mapProperty = null; @@ -75,7 +75,7 @@ public AdditionalPropertiesClass putMapOfMapPropertyItem(String key, Map implements Serializable { @JsonProperty("map_property") private Map mapProperty = null; @@ -103,12 +103,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -116,7 +117,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); - + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/server/petstore/jaxrs-spec-interface/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java b/samples/server/petstore/jaxrs-spec-interface/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java index 58abe9915cb2..93ac99b02914 100644 --- a/samples/server/petstore/jaxrs-spec-interface/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java +++ b/samples/server/petstore/jaxrs-spec-interface/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java @@ -17,7 +17,7 @@ -public class AdditionalPropertiesClass implements Serializable { +public class AdditionalPropertiesClass extends HashMap implements Serializable { private @Valid Map mapProperty = new HashMap(); private @Valid Map> mapOfMapProperty = new HashMap>(); @@ -79,7 +79,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); - + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/server/petstore/jaxrs-spec-interface/src/main/openapi/openapi.yaml b/samples/server/petstore/jaxrs-spec-interface/src/main/openapi/openapi.yaml index e19bfe47ee0f..a52af95dfa5c 100644 --- a/samples/server/petstore/jaxrs-spec-interface/src/main/openapi/openapi.yaml +++ b/samples/server/petstore/jaxrs-spec-interface/src/main/openapi/openapi.yaml @@ -1547,6 +1547,8 @@ components: - enum_string_required type: object AdditionalPropertiesClass: + additionalProperties: + type: string properties: map_property: additionalProperties: diff --git a/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java b/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java index 58abe9915cb2..93ac99b02914 100644 --- a/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java +++ b/samples/server/petstore/jaxrs-spec/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java @@ -17,7 +17,7 @@ -public class AdditionalPropertiesClass implements Serializable { +public class AdditionalPropertiesClass extends HashMap implements Serializable { private @Valid Map mapProperty = new HashMap(); private @Valid Map> mapOfMapProperty = new HashMap>(); @@ -79,7 +79,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); - + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/server/petstore/jaxrs-spec/src/main/openapi/openapi.yaml b/samples/server/petstore/jaxrs-spec/src/main/openapi/openapi.yaml index e19bfe47ee0f..a52af95dfa5c 100644 --- a/samples/server/petstore/jaxrs-spec/src/main/openapi/openapi.yaml +++ b/samples/server/petstore/jaxrs-spec/src/main/openapi/openapi.yaml @@ -1547,6 +1547,8 @@ components: - enum_string_required type: object AdditionalPropertiesClass: + additionalProperties: + type: string properties: map_property: additionalProperties: diff --git a/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java b/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java index a23b475596c9..7ab5e59a8928 100644 --- a/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java +++ b/samples/server/petstore/jaxrs/jersey1-useTags/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java @@ -28,7 +28,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") private Map mapProperty = null; @@ -102,12 +102,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -115,7 +116,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); - + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/server/petstore/jaxrs/jersey1/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java b/samples/server/petstore/jaxrs/jersey1/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java index a23b475596c9..7ab5e59a8928 100644 --- a/samples/server/petstore/jaxrs/jersey1/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java +++ b/samples/server/petstore/jaxrs/jersey1/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java @@ -28,7 +28,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") private Map mapProperty = null; @@ -102,12 +102,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -115,7 +116,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); - + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java b/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java index a23b475596c9..7ab5e59a8928 100644 --- a/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java +++ b/samples/server/petstore/jaxrs/jersey2-useTags/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java @@ -28,7 +28,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") private Map mapProperty = null; @@ -102,12 +102,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -115,7 +116,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); - + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/server/petstore/jaxrs/jersey2/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java b/samples/server/petstore/jaxrs/jersey2/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java index a23b475596c9..7ab5e59a8928 100644 --- a/samples/server/petstore/jaxrs/jersey2/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java +++ b/samples/server/petstore/jaxrs/jersey2/src/gen/java/org/openapitools/model/AdditionalPropertiesClass.java @@ -28,7 +28,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") private Map mapProperty = null; @@ -102,12 +102,13 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @@ -115,7 +116,7 @@ public int hashCode() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); - + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/server/petstore/spring-mvc-j8-async/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java b/samples/server/petstore/spring-mvc-j8-async/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java index 4845592fef18..c4edb32981d7 100644 --- a/samples/server/petstore/spring-mvc-j8-async/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java +++ b/samples/server/petstore/spring-mvc-j8-async/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java @@ -16,7 +16,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") @Valid private Map mapProperty = null; @@ -93,19 +93,20 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); - + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/server/petstore/spring-mvc-j8-localdatetime/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java b/samples/server/petstore/spring-mvc-j8-localdatetime/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java index 4845592fef18..c4edb32981d7 100644 --- a/samples/server/petstore/spring-mvc-j8-localdatetime/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java +++ b/samples/server/petstore/spring-mvc-j8-localdatetime/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java @@ -16,7 +16,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") @Valid private Map mapProperty = null; @@ -93,19 +93,20 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); - + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java b/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java index 88a003703b22..4f28fe07808f 100644 --- a/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java +++ b/samples/server/petstore/spring-mvc/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java @@ -16,7 +16,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") @Valid private Map mapProperty = null; @@ -93,19 +93,20 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); - + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java index 88a003703b22..4f28fe07808f 100644 --- a/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java +++ b/samples/server/petstore/springboot-beanvalidation/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java @@ -16,7 +16,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") @Valid private Map mapProperty = null; @@ -93,19 +93,20 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); - + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java index 4845592fef18..c4edb32981d7 100644 --- a/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java +++ b/samples/server/petstore/springboot-delegate-j8/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java @@ -16,7 +16,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") @Valid private Map mapProperty = null; @@ -93,19 +93,20 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); - + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java index 88a003703b22..4f28fe07808f 100644 --- a/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java +++ b/samples/server/petstore/springboot-delegate/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java @@ -16,7 +16,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") @Valid private Map mapProperty = null; @@ -93,19 +93,20 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); - + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java b/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java index 4845592fef18..c4edb32981d7 100644 --- a/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java +++ b/samples/server/petstore/springboot-implicitHeaders/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java @@ -16,7 +16,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") @Valid private Map mapProperty = null; @@ -93,19 +93,20 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); - + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java index 4845592fef18..c4edb32981d7 100644 --- a/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java +++ b/samples/server/petstore/springboot-reactive/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java @@ -16,7 +16,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") @Valid private Map mapProperty = null; @@ -93,19 +93,20 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); - + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/server/petstore/springboot-reactive/src/main/resources/openapi.yaml b/samples/server/petstore/springboot-reactive/src/main/resources/openapi.yaml index a4da8e432b8c..a724092f0582 100644 --- a/samples/server/petstore/springboot-reactive/src/main/resources/openapi.yaml +++ b/samples/server/petstore/springboot-reactive/src/main/resources/openapi.yaml @@ -1607,6 +1607,8 @@ components: - enum_string_required type: object AdditionalPropertiesClass: + additionalProperties: + type: string properties: map_property: additionalProperties: diff --git a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java b/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java index 4845592fef18..c4edb32981d7 100644 --- a/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java +++ b/samples/server/petstore/springboot-useoptional/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java @@ -16,7 +16,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") @Valid private Map mapProperty = null; @@ -93,19 +93,20 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); - + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/model/AdditionalPropertiesClass.java b/samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/model/AdditionalPropertiesClass.java index cb66f641276d..abff65ba8736 100644 --- a/samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/model/AdditionalPropertiesClass.java +++ b/samples/server/petstore/springboot-virtualan/src/main/java/org/openapitools/virtualan/model/AdditionalPropertiesClass.java @@ -16,7 +16,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") @Valid private Map mapProperty = null; @@ -93,19 +93,20 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); - + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}"); diff --git a/samples/server/petstore/springboot/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java b/samples/server/petstore/springboot/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java index 4845592fef18..c4edb32981d7 100644 --- a/samples/server/petstore/springboot/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java +++ b/samples/server/petstore/springboot/src/main/java/org/openapitools/model/AdditionalPropertiesClass.java @@ -16,7 +16,7 @@ * AdditionalPropertiesClass */ -public class AdditionalPropertiesClass { +public class AdditionalPropertiesClass extends HashMap { @JsonProperty("map_property") @Valid private Map mapProperty = null; @@ -93,19 +93,20 @@ public boolean equals(java.lang.Object o) { } AdditionalPropertiesClass additionalPropertiesClass = (AdditionalPropertiesClass) o; return Objects.equals(this.mapProperty, additionalPropertiesClass.mapProperty) && - Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty); + Objects.equals(this.mapOfMapProperty, additionalPropertiesClass.mapOfMapProperty) && + super.equals(o); } @Override public int hashCode() { - return Objects.hash(mapProperty, mapOfMapProperty); + return Objects.hash(mapProperty, mapOfMapProperty, super.hashCode()); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class AdditionalPropertiesClass {\n"); - + sb.append(" ").append(toIndentedString(super.toString())).append("\n"); sb.append(" mapProperty: ").append(toIndentedString(mapProperty)).append("\n"); sb.append(" mapOfMapProperty: ").append(toIndentedString(mapOfMapProperty)).append("\n"); sb.append("}");