From fe1257f216be6c9ce3297c68fcfbdb3f4b69529d Mon Sep 17 00:00:00 2001 From: Justin Black Date: Fri, 21 Aug 2020 08:37:13 -0700 Subject: [PATCH 01/16] Adds generator specific unaliasSchema method --- .../openapitools/codegen/DefaultCodegen.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) 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 d9e54a5a9134..55317d61e4f8 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 @@ -1971,6 +1971,10 @@ public String toOneOfName(List names, ComposedSchema composedSchema) { return "oneOf<" + String.join(",", names) + ">"; } + protected Schema unaliasSchema(Schema schema, Map usedImportMappings) { + return ModelUtils.unaliasSchema(this.openAPI, schema, usedImportMappings); + } + /** * Return a string representation of the schema type, resolving aliasing and references if necessary. * @@ -1978,7 +1982,7 @@ public String toOneOfName(List names, ComposedSchema composedSchema) { * @return the string representation of the schema type. */ protected String getSingleSchemaType(Schema schema) { - Schema unaliasSchema = ModelUtils.unaliasSchema(this.openAPI, schema, importMapping); + Schema unaliasSchema = unaliasSchema(schema, importMapping); if (StringUtils.isNotBlank(unaliasSchema.get$ref())) { // reference to another definition/schema // get the schema/model name from $ref @@ -2214,7 +2218,7 @@ public CodegenModel fromModel(String name, Schema schema) { } // unalias schema - schema = ModelUtils.unaliasSchema(this.openAPI, schema, importMapping); + schema = unaliasSchema(schema, importMapping); if (schema == null) { LOGGER.warn("Schema {} not found", name); return null; @@ -2328,7 +2332,7 @@ public CodegenModel fromModel(String name, Schema schema) { m.interfaces = new ArrayList(); for (Schema interfaceSchema : interfaces) { - interfaceSchema = ModelUtils.unaliasSchema(this.openAPI, interfaceSchema, importMapping); + interfaceSchema = unaliasSchema(interfaceSchema, importMapping); if (StringUtils.isBlank(interfaceSchema.get$ref())) { // primitive type @@ -2989,7 +2993,7 @@ public CodegenProperty fromProperty(String name, Schema p) { LOGGER.debug("debugging fromProperty for " + name + " : " + p); // unalias schema - p = ModelUtils.unaliasSchema(this.openAPI, p, importMapping); + p = unaliasSchema(p, importMapping); CodegenProperty property = CodegenModelFactory.newInstance(CodegenModelType.PROPERTY); @@ -3166,10 +3170,9 @@ public CodegenProperty fromProperty(String name, Schema p) { } else if (ModelUtils.isArraySchema(p)) { // default to string if inner item is undefined ArraySchema arraySchema = (ArraySchema) p; - Schema innerSchema = ModelUtils.unaliasSchema(this.openAPI, getSchemaItems(arraySchema), importMapping); + Schema innerSchema = unaliasSchema(getSchemaItems(arraySchema), importMapping); } else if (ModelUtils.isMapSchema(p)) { - Schema innerSchema = ModelUtils.unaliasSchema(this.openAPI, getAdditionalProperties(p), - importMapping); + Schema innerSchema = unaliasSchema(getAdditionalProperties(p), importMapping); if (innerSchema == null) { LOGGER.error("Undefined map inner type for `{}`. Default to String.", p.getName()); innerSchema = new StringSchema().description("//TODO automatically added by openapi-generator due to undefined type"); @@ -3249,7 +3252,7 @@ public CodegenProperty fromProperty(String name, Schema p) { itemName = property.name; } ArraySchema arraySchema = (ArraySchema) p; - Schema innerSchema = ModelUtils.unaliasSchema(this.openAPI, getSchemaItems(arraySchema), importMapping); + Schema innerSchema = unaliasSchema(getSchemaItems(arraySchema), importMapping); CodegenProperty cp = fromProperty(itemName, innerSchema); updatePropertyForArray(property, cp); } else if (ModelUtils.isMapSchema(p)) { @@ -3261,8 +3264,7 @@ public CodegenProperty fromProperty(String name, Schema p) { property.maxItems = p.getMaxProperties(); // handle inner property - Schema innerSchema = ModelUtils.unaliasSchema(this.openAPI, getAdditionalProperties(p), - importMapping); + Schema innerSchema = unaliasSchema(getAdditionalProperties(p), importMapping); if (innerSchema == null) { LOGGER.error("Undefined map inner type for `{}`. Default to String.", p.getName()); innerSchema = new StringSchema().description("//TODO automatically added by openapi-generator due to undefined type"); @@ -3502,7 +3504,7 @@ protected void handleMethodResponse(Operation operation, CodegenOperation op, ApiResponse methodResponse, Map importMappings) { - Schema responseSchema = ModelUtils.unaliasSchema(this.openAPI, ModelUtils.getSchemaFromResponse(methodResponse), importMappings); + Schema responseSchema = unaliasSchema(ModelUtils.getSchemaFromResponse(methodResponse), importMapping); if (responseSchema != null) { CodegenProperty cm = fromProperty("response", responseSchema); @@ -3906,8 +3908,7 @@ public CodegenResponse fromResponse(String responseCode, ApiResponse response) { } Schema responseSchema; if (this.openAPI != null && this.openAPI.getComponents() != null) { - responseSchema = ModelUtils.unaliasSchema(this.openAPI, ModelUtils.getSchemaFromResponse(response), - importMapping); + responseSchema = unaliasSchema(ModelUtils.getSchemaFromResponse(response), importMapping); } else { // no model/alias defined responseSchema = ModelUtils.getSchemaFromResponse(response); } @@ -4148,7 +4149,7 @@ public CodegenParameter fromParameter(Parameter parameter, Set imports) } if (parameterSchema != null) { - parameterSchema = ModelUtils.unaliasSchema(this.openAPI, parameterSchema); + parameterSchema = unaliasSchema(parameterSchema, Collections.emptyMap()); if (parameterSchema == null) { LOGGER.warn("warning! Schema not found for parameter \"" + parameter.getName() + "\", using String"); parameterSchema = new StringSchema().description("//TODO automatically added by openapi-generator due to missing type definition."); @@ -4688,7 +4689,7 @@ protected void addImport(CodegenModel m, String type) { private Map unaliasPropertySchema(Map properties) { if (properties != null) { for (String key : properties.keySet()) { - properties.put(key, ModelUtils.unaliasSchema(this.openAPI, properties.get(key), importMapping())); + properties.put(key, unaliasSchema(properties.get(key), importMapping())); } } From 27056353343feac20d6b7bdc6dbae1c303a565bf Mon Sep 17 00:00:00 2001 From: Justin Black Date: Fri, 21 Aug 2020 08:57:04 -0700 Subject: [PATCH 02/16] Adds unaliasSchema and hasValidation methods in python-experimental generator --- .../PythonClientExperimentalCodegen.java | 95 ++++++++-- .../.openapi-generator/VERSION | 2 +- .../petstore/python-experimental/docs/Bar.md | 10 + .../python-experimental/docs/Boolean.md | 10 + .../python-experimental/docs/DateTimeTest.md | 10 + .../python-experimental/docs/Number.md | 10 + .../python-experimental/docs/String.md | 10 + .../petstore_api/model/bar.py | 174 ++++++++++++++++++ .../petstore_api/model/boolean.py | 174 ++++++++++++++++++ .../petstore_api/model/date_time_test.py | 174 ++++++++++++++++++ .../petstore_api/model/number.py | 174 ++++++++++++++++++ .../petstore_api/model/string.py | 174 ++++++++++++++++++ .../python-experimental/test/test_bar.py | 37 ++++ .../python-experimental/test/test_boolean.py | 37 ++++ .../test/test_date_time_test.py | 37 ++++ .../python-experimental/test/test_number.py | 37 ++++ .../python-experimental/test/test_string.py | 37 ++++ 17 files changed, 1187 insertions(+), 15 deletions(-) create mode 100644 samples/openapi3/client/petstore/python-experimental/docs/Bar.md create mode 100644 samples/openapi3/client/petstore/python-experimental/docs/Boolean.md create mode 100644 samples/openapi3/client/petstore/python-experimental/docs/DateTimeTest.md create mode 100644 samples/openapi3/client/petstore/python-experimental/docs/Number.md create mode 100644 samples/openapi3/client/petstore/python-experimental/docs/String.md create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/bar.py create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean.py create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/date_time_test.py create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/number.py create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/string.py create mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_bar.py create mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_boolean.py create mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_date_time_test.py create mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_number.py create mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_string.py diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java index 941c5d11d87b..4f9337b9854f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java @@ -225,6 +225,70 @@ public String getName() { return "python-experimental"; } + @Override + protected Schema unaliasSchema(Schema schema, Map usedImportMappings) { + Map allSchemas = ModelUtils.getSchemas(openAPI); + if (allSchemas == null || allSchemas.isEmpty()) { + // skip the warning as the spec can have no model defined + //LOGGER.warn("allSchemas cannot be null/empty in unaliasSchema. Returned 'schema'"); + return schema; + } + + if (schema != null && StringUtils.isNotEmpty(schema.get$ref())) { + String simpleRef = ModelUtils.getSimpleRef(schema.get$ref()); + if (usedImportMappings.containsKey(simpleRef)) { + LOGGER.debug("Schema unaliasing of {} omitted because aliased class is to be mapped to {}", simpleRef, usedImportMappings.get(simpleRef)); + return schema; + } + Schema ref = allSchemas.get(simpleRef); + if (ref == null) { + once(LOGGER).warn("{} is not defined", schema.get$ref()); + return schema; + } else if (ref.getEnum() != null && !ref.getEnum().isEmpty()) { + // top-level enum class + return schema; + } else if (ModelUtils.isArraySchema(ref)) { + if (ModelUtils.isGenerateAliasAsModel(ref)) { + return schema; // generate a model extending array + } else { + return unaliasSchema(allSchemas.get(ModelUtils.getSimpleRef(schema.get$ref())), + usedImportMappings); + } + } else if (ModelUtils.isComposedSchema(ref)) { + return schema; + } else if (ModelUtils.isMapSchema(ref)) { + if (ref.getProperties() != null && !ref.getProperties().isEmpty()) // has at least one property + return schema; // treat it as model + else { + if (ModelUtils.isGenerateAliasAsModel(ref)) { + return schema; // generate a model extending map + } else { + // treat it as a typical map + return unaliasSchema(allSchemas.get(ModelUtils.getSimpleRef(schema.get$ref())), + usedImportMappings); + } + } + } else if (ModelUtils.isObjectSchema(ref)) { // model + if (ref.getProperties() != null && !ref.getProperties().isEmpty()) { // has at least one property + return schema; + } else { // free form object (type: object) + return unaliasSchema(allSchemas.get(ModelUtils.getSimpleRef(schema.get$ref())), + usedImportMappings); + } + } else if (HasValidation(ref)) { + // non object non array non map schemas that have validations + // are returned so we can generate those schemas as models + // we do this to: + // - preserve the validations in that model class in python + // - use those validations when we use this schema in composed oneOf schemas + return schema; + } else { + return unaliasSchema(allSchemas.get(ModelUtils.getSimpleRef(schema.get$ref())), usedImportMappings); + } + } + return schema; + } + public String pythonDate(Object dateValue) { String strValue = null; if (dateValue instanceof OffsetDateTime) { @@ -954,6 +1018,22 @@ public String getSimpleTypeDeclaration(Schema schema) { return oasType; } + public Boolean HasValidation(Schema s) { + return ( + s.getMaxItems() != null || + s.getMinLength() != null || + s.getMinItems() != null || + s.getMultipleOf() != null || + s.getPattern() != null || + s.getMaxLength() != null || + s.getMinimum() != null || + s.getMaximum() != null || + s.getExclusiveMaximum() != null || + s.getExclusiveMinimum() != null || + s.getUniqueItems() != null + ); + } + public Boolean modelWillBeMade(Schema s) { // only invoke this on $refed schemas if (ModelUtils.isComposedSchema(s) || ModelUtils.isObjectSchema(s) || ModelUtils.isArraySchema(s) || ModelUtils.isMapSchema(s)) { @@ -963,20 +1043,7 @@ public Boolean modelWillBeMade(Schema s) { if (enums != null && !enums.isEmpty()) { return true; } - Boolean hasValidation = ( - s.getMaxItems() != null || - s.getMinLength() != null || - s.getMinItems() != null || - s.getMultipleOf() != null || - s.getPattern() != null || - s.getMaxLength() != null || - s.getMinimum() != null || - s.getMaximum() != null || - s.getExclusiveMaximum() != null || - s.getExclusiveMinimum() != null || - s.getUniqueItems() != null - ); - if (hasValidation) { + if (HasValidation(s)) { return true; } return false; diff --git a/samples/openapi3/client/petstore/python-experimental/.openapi-generator/VERSION b/samples/openapi3/client/petstore/python-experimental/.openapi-generator/VERSION index d99e7162d01f..717311e32e3c 100644 --- a/samples/openapi3/client/petstore/python-experimental/.openapi-generator/VERSION +++ b/samples/openapi3/client/petstore/python-experimental/.openapi-generator/VERSION @@ -1 +1 @@ -5.0.0-SNAPSHOT \ No newline at end of file +unset \ No newline at end of file diff --git a/samples/openapi3/client/petstore/python-experimental/docs/Bar.md b/samples/openapi3/client/petstore/python-experimental/docs/Bar.md new file mode 100644 index 000000000000..1f2342420226 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/docs/Bar.md @@ -0,0 +1,10 @@ +# Bar + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**value** | **str** | | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python-experimental/docs/Boolean.md b/samples/openapi3/client/petstore/python-experimental/docs/Boolean.md new file mode 100644 index 000000000000..88876e8fcd0b --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/docs/Boolean.md @@ -0,0 +1,10 @@ +# Boolean + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**value** | **bool** | | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python-experimental/docs/DateTimeTest.md b/samples/openapi3/client/petstore/python-experimental/docs/DateTimeTest.md new file mode 100644 index 000000000000..56fba16d842a --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/docs/DateTimeTest.md @@ -0,0 +1,10 @@ +# DateTimeTest + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**value** | **datetime** | | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python-experimental/docs/Number.md b/samples/openapi3/client/petstore/python-experimental/docs/Number.md new file mode 100644 index 000000000000..05ad930bbd6e --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/docs/Number.md @@ -0,0 +1,10 @@ +# Number + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**value** | **float** | | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python-experimental/docs/String.md b/samples/openapi3/client/petstore/python-experimental/docs/String.md new file mode 100644 index 000000000000..e5a0ae57c4e4 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/docs/String.md @@ -0,0 +1,10 @@ +# String + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**value** | **str** | | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/bar.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/bar.py new file mode 100644 index 000000000000..ba1d082bf20d --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/bar.py @@ -0,0 +1,174 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import re # noqa: F401 +import sys # noqa: F401 + +import nulltype # noqa: F401 + +from petstore_api.model_utils import ( # noqa: F401 + ApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) + + +class Bar(ModelSimple): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = { + } + + validations = { + ('value',): { + }, + } + + additional_properties_type = None + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + return { + 'value': (str,), + } + + @cached_property + def discriminator(): + return None + + + attribute_map = {} + + _composed_schemas = None + + required_properties = set([ + '_data_store', + '_check_type', + '_spec_property_naming', + '_path_to_item', + '_configuration', + '_visited_composed_classes', + ]) + + @convert_js_args_to_python_args + def __init__(self, *args, **kwargs): + """Bar - a model defined in OpenAPI + + Keyword Args: + value (str): # noqa: E501 + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + """ + + if 'value' in kwargs: + value = kwargs.pop('value') + elif args: + args = list(args) + value = args.pop(0) + else: + value = + _check_type = kwargs.pop('_check_type', True) + _spec_property_naming = kwargs.pop('_spec_property_naming', False) + _path_to_item = kwargs.pop('_path_to_item', ()) + _configuration = kwargs.pop('_configuration', None) + _visited_composed_classes = kwargs.pop('_visited_composed_classes', ()) + + if args: + raise ApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % ( + args, + self.__class__.__name__, + ), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + self.value = value + if kwargs: + raise ApiTypeError( + "Invalid named arguments=%s passed to %s. Remove those invalid named arguments." % ( + kwargs, + self.__class__.__name__, + ), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean.py new file mode 100644 index 000000000000..2fc9bf976a3c --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean.py @@ -0,0 +1,174 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import re # noqa: F401 +import sys # noqa: F401 + +import nulltype # noqa: F401 + +from petstore_api.model_utils import ( # noqa: F401 + ApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) + + +class Boolean(ModelSimple): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = { + } + + validations = { + ('value',): { + }, + } + + additional_properties_type = None + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + return { + 'value': (bool,), + } + + @cached_property + def discriminator(): + return None + + + attribute_map = {} + + _composed_schemas = None + + required_properties = set([ + '_data_store', + '_check_type', + '_spec_property_naming', + '_path_to_item', + '_configuration', + '_visited_composed_classes', + ]) + + @convert_js_args_to_python_args + def __init__(self, *args, **kwargs): + """Boolean - a model defined in OpenAPI + + Keyword Args: + value (bool): # noqa: E501 + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + """ + + if 'value' in kwargs: + value = kwargs.pop('value') + elif args: + args = list(args) + value = args.pop(0) + else: + value = + _check_type = kwargs.pop('_check_type', True) + _spec_property_naming = kwargs.pop('_spec_property_naming', False) + _path_to_item = kwargs.pop('_path_to_item', ()) + _configuration = kwargs.pop('_configuration', None) + _visited_composed_classes = kwargs.pop('_visited_composed_classes', ()) + + if args: + raise ApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % ( + args, + self.__class__.__name__, + ), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + self.value = value + if kwargs: + raise ApiTypeError( + "Invalid named arguments=%s passed to %s. Remove those invalid named arguments." % ( + kwargs, + self.__class__.__name__, + ), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/date_time_test.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/date_time_test.py new file mode 100644 index 000000000000..a79471f25944 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/date_time_test.py @@ -0,0 +1,174 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import re # noqa: F401 +import sys # noqa: F401 + +import nulltype # noqa: F401 + +from petstore_api.model_utils import ( # noqa: F401 + ApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) + + +class DateTimeTest(ModelSimple): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = { + } + + validations = { + ('value',): { + }, + } + + additional_properties_type = None + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + return { + 'value': (datetime,), + } + + @cached_property + def discriminator(): + return None + + + attribute_map = {} + + _composed_schemas = None + + required_properties = set([ + '_data_store', + '_check_type', + '_spec_property_naming', + '_path_to_item', + '_configuration', + '_visited_composed_classes', + ]) + + @convert_js_args_to_python_args + def __init__(self, *args, **kwargs): + """DateTimeTest - a model defined in OpenAPI + + Keyword Args: + value (datetime): # noqa: E501 + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + """ + + if 'value' in kwargs: + value = kwargs.pop('value') + elif args: + args = list(args) + value = args.pop(0) + else: + value = + _check_type = kwargs.pop('_check_type', True) + _spec_property_naming = kwargs.pop('_spec_property_naming', False) + _path_to_item = kwargs.pop('_path_to_item', ()) + _configuration = kwargs.pop('_configuration', None) + _visited_composed_classes = kwargs.pop('_visited_composed_classes', ()) + + if args: + raise ApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % ( + args, + self.__class__.__name__, + ), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + self.value = value + if kwargs: + raise ApiTypeError( + "Invalid named arguments=%s passed to %s. Remove those invalid named arguments." % ( + kwargs, + self.__class__.__name__, + ), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number.py new file mode 100644 index 000000000000..aa7e2e62e607 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number.py @@ -0,0 +1,174 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import re # noqa: F401 +import sys # noqa: F401 + +import nulltype # noqa: F401 + +from petstore_api.model_utils import ( # noqa: F401 + ApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) + + +class Number(ModelSimple): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = { + } + + validations = { + ('value',): { + }, + } + + additional_properties_type = None + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + return { + 'value': (float,), + } + + @cached_property + def discriminator(): + return None + + + attribute_map = {} + + _composed_schemas = None + + required_properties = set([ + '_data_store', + '_check_type', + '_spec_property_naming', + '_path_to_item', + '_configuration', + '_visited_composed_classes', + ]) + + @convert_js_args_to_python_args + def __init__(self, *args, **kwargs): + """Number - a model defined in OpenAPI + + Keyword Args: + value (float): # noqa: E501 + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + """ + + if 'value' in kwargs: + value = kwargs.pop('value') + elif args: + args = list(args) + value = args.pop(0) + else: + value = + _check_type = kwargs.pop('_check_type', True) + _spec_property_naming = kwargs.pop('_spec_property_naming', False) + _path_to_item = kwargs.pop('_path_to_item', ()) + _configuration = kwargs.pop('_configuration', None) + _visited_composed_classes = kwargs.pop('_visited_composed_classes', ()) + + if args: + raise ApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % ( + args, + self.__class__.__name__, + ), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + self.value = value + if kwargs: + raise ApiTypeError( + "Invalid named arguments=%s passed to %s. Remove those invalid named arguments." % ( + kwargs, + self.__class__.__name__, + ), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string.py new file mode 100644 index 000000000000..4ec673447cf5 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string.py @@ -0,0 +1,174 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import re # noqa: F401 +import sys # noqa: F401 + +import nulltype # noqa: F401 + +from petstore_api.model_utils import ( # noqa: F401 + ApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) + + +class String(ModelSimple): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = { + } + + validations = { + ('value',): { + }, + } + + additional_properties_type = None + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + return { + 'value': (str,), + } + + @cached_property + def discriminator(): + return None + + + attribute_map = {} + + _composed_schemas = None + + required_properties = set([ + '_data_store', + '_check_type', + '_spec_property_naming', + '_path_to_item', + '_configuration', + '_visited_composed_classes', + ]) + + @convert_js_args_to_python_args + def __init__(self, *args, **kwargs): + """String - a model defined in OpenAPI + + Keyword Args: + value (str): # noqa: E501 + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + """ + + if 'value' in kwargs: + value = kwargs.pop('value') + elif args: + args = list(args) + value = args.pop(0) + else: + value = + _check_type = kwargs.pop('_check_type', True) + _spec_property_naming = kwargs.pop('_spec_property_naming', False) + _path_to_item = kwargs.pop('_path_to_item', ()) + _configuration = kwargs.pop('_configuration', None) + _visited_composed_classes = kwargs.pop('_visited_composed_classes', ()) + + if args: + raise ApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % ( + args, + self.__class__.__name__, + ), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + self.value = value + if kwargs: + raise ApiTypeError( + "Invalid named arguments=%s passed to %s. Remove those invalid named arguments." % ( + kwargs, + self.__class__.__name__, + ), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_bar.py b/samples/openapi3/client/petstore/python-experimental/test/test_bar.py new file mode 100644 index 000000000000..a63f1e74f8be --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/test/test_bar.py @@ -0,0 +1,37 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest + +import petstore_api +from petstore_api.model.bar import Bar + + +class TestBar(unittest.TestCase): + """Bar unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testBar(self): + """Test Bar""" + # FIXME: construct object with mandatory attributes with example values + # model = Bar() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_boolean.py b/samples/openapi3/client/petstore/python-experimental/test/test_boolean.py new file mode 100644 index 000000000000..703c3b8e6e98 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/test/test_boolean.py @@ -0,0 +1,37 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest + +import petstore_api +from petstore_api.model.boolean import Boolean + + +class TestBoolean(unittest.TestCase): + """Boolean unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testBoolean(self): + """Test Boolean""" + # FIXME: construct object with mandatory attributes with example values + # model = Boolean() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_date_time_test.py b/samples/openapi3/client/petstore/python-experimental/test/test_date_time_test.py new file mode 100644 index 000000000000..cd9db5764946 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/test/test_date_time_test.py @@ -0,0 +1,37 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest + +import petstore_api +from petstore_api.model.date_time_test import DateTimeTest + + +class TestDateTimeTest(unittest.TestCase): + """DateTimeTest unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testDateTimeTest(self): + """Test DateTimeTest""" + # FIXME: construct object with mandatory attributes with example values + # model = DateTimeTest() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_number.py b/samples/openapi3/client/petstore/python-experimental/test/test_number.py new file mode 100644 index 000000000000..8656313f4fca --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/test/test_number.py @@ -0,0 +1,37 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest + +import petstore_api +from petstore_api.model.number import Number + + +class TestNumber(unittest.TestCase): + """Number unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testNumber(self): + """Test Number""" + # FIXME: construct object with mandatory attributes with example values + # model = Number() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_string.py b/samples/openapi3/client/petstore/python-experimental/test/test_string.py new file mode 100644 index 000000000000..5034f26cdec0 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/test/test_string.py @@ -0,0 +1,37 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest + +import petstore_api +from petstore_api.model.string import String + + +class TestString(unittest.TestCase): + """String unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testString(self): + """Test String""" + # FIXME: construct object with mandatory attributes with example values + # model = String() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() From d3791acfe23b66de25d0dfc051b5bd6b89bcb491 Mon Sep 17 00:00:00 2001 From: Justin Black Date: Fri, 21 Aug 2020 08:59:10 -0700 Subject: [PATCH 03/16] Removes primitive models with no validations, docs, tests, and models --- .../petstore/python-experimental/docs/Bar.md | 10 - .../python-experimental/docs/Boolean.md | 10 - .../python-experimental/docs/DateTimeTest.md | 10 - .../python-experimental/docs/Number.md | 10 - .../python-experimental/docs/String.md | 10 - .../petstore_api/model/bar.py | 174 ------------------ .../petstore_api/model/boolean.py | 174 ------------------ .../petstore_api/model/date_time_test.py | 174 ------------------ .../petstore_api/model/number.py | 174 ------------------ .../petstore_api/model/string.py | 174 ------------------ .../python-experimental/test/test_bar.py | 37 ---- .../python-experimental/test/test_boolean.py | 37 ---- .../test/test_date_time_test.py | 37 ---- .../python-experimental/test/test_number.py | 37 ---- .../python-experimental/test/test_string.py | 37 ---- 15 files changed, 1105 deletions(-) delete mode 100644 samples/openapi3/client/petstore/python-experimental/docs/Bar.md delete mode 100644 samples/openapi3/client/petstore/python-experimental/docs/Boolean.md delete mode 100644 samples/openapi3/client/petstore/python-experimental/docs/DateTimeTest.md delete mode 100644 samples/openapi3/client/petstore/python-experimental/docs/Number.md delete mode 100644 samples/openapi3/client/petstore/python-experimental/docs/String.md delete mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/bar.py delete mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean.py delete mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/date_time_test.py delete mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/number.py delete mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/string.py delete mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_bar.py delete mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_boolean.py delete mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_date_time_test.py delete mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_number.py delete mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_string.py diff --git a/samples/openapi3/client/petstore/python-experimental/docs/Bar.md b/samples/openapi3/client/petstore/python-experimental/docs/Bar.md deleted file mode 100644 index 1f2342420226..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/docs/Bar.md +++ /dev/null @@ -1,10 +0,0 @@ -# Bar - -## Properties -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**value** | **str** | | - -[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) - - diff --git a/samples/openapi3/client/petstore/python-experimental/docs/Boolean.md b/samples/openapi3/client/petstore/python-experimental/docs/Boolean.md deleted file mode 100644 index 88876e8fcd0b..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/docs/Boolean.md +++ /dev/null @@ -1,10 +0,0 @@ -# Boolean - -## Properties -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**value** | **bool** | | - -[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) - - diff --git a/samples/openapi3/client/petstore/python-experimental/docs/DateTimeTest.md b/samples/openapi3/client/petstore/python-experimental/docs/DateTimeTest.md deleted file mode 100644 index 56fba16d842a..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/docs/DateTimeTest.md +++ /dev/null @@ -1,10 +0,0 @@ -# DateTimeTest - -## Properties -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**value** | **datetime** | | - -[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) - - diff --git a/samples/openapi3/client/petstore/python-experimental/docs/Number.md b/samples/openapi3/client/petstore/python-experimental/docs/Number.md deleted file mode 100644 index 05ad930bbd6e..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/docs/Number.md +++ /dev/null @@ -1,10 +0,0 @@ -# Number - -## Properties -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**value** | **float** | | - -[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) - - diff --git a/samples/openapi3/client/petstore/python-experimental/docs/String.md b/samples/openapi3/client/petstore/python-experimental/docs/String.md deleted file mode 100644 index e5a0ae57c4e4..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/docs/String.md +++ /dev/null @@ -1,10 +0,0 @@ -# String - -## Properties -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**value** | **str** | | - -[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) - - diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/bar.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/bar.py deleted file mode 100644 index ba1d082bf20d..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/bar.py +++ /dev/null @@ -1,174 +0,0 @@ -# coding: utf-8 - -""" - OpenAPI Petstore - - This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 - - The version of the OpenAPI document: 1.0.0 - Generated by: https://openapi-generator.tech -""" - - -import re # noqa: F401 -import sys # noqa: F401 - -import nulltype # noqa: F401 - -from petstore_api.model_utils import ( # noqa: F401 - ApiTypeError, - ModelComposed, - ModelNormal, - ModelSimple, - cached_property, - change_keys_js_to_python, - convert_js_args_to_python_args, - date, - datetime, - file_type, - none_type, - validate_get_composed_info, -) - - -class Bar(ModelSimple): - """NOTE: This class is auto generated by OpenAPI Generator. - Ref: https://openapi-generator.tech - - Do not edit the class manually. - - Attributes: - allowed_values (dict): The key is the tuple path to the attribute - and the for var_name this is (var_name,). The value is a dict - with a capitalized key describing the allowed value and an allowed - value. These dicts store the allowed enum values. - validations (dict): The key is the tuple path to the attribute - and the for var_name this is (var_name,). The value is a dict - that stores validations for max_length, min_length, max_items, - min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, - inclusive_minimum, and regex. - additional_properties_type (tuple): A tuple of classes accepted - as additional properties values. - """ - - allowed_values = { - } - - validations = { - ('value',): { - }, - } - - additional_properties_type = None - - _nullable = False - - @cached_property - def openapi_types(): - """ - This must be a method because a model may have properties that are - of type self, this must run after the class is loaded - - Returns - openapi_types (dict): The key is attribute name - and the value is attribute type. - """ - return { - 'value': (str,), - } - - @cached_property - def discriminator(): - return None - - - attribute_map = {} - - _composed_schemas = None - - required_properties = set([ - '_data_store', - '_check_type', - '_spec_property_naming', - '_path_to_item', - '_configuration', - '_visited_composed_classes', - ]) - - @convert_js_args_to_python_args - def __init__(self, *args, **kwargs): - """Bar - a model defined in OpenAPI - - Keyword Args: - value (str): # noqa: E501 - _check_type (bool): if True, values for parameters in openapi_types - will be type checked and a TypeError will be - raised if the wrong type is input. - Defaults to True - _path_to_item (tuple/list): This is a list of keys or values to - drill down to the model in received_data - when deserializing a response - _spec_property_naming (bool): True if the variable names in the input data - are serialized names, as specified in the OpenAPI document. - False if the variable names in the input data - are pythonic names, e.g. snake case (default) - _configuration (Configuration): the instance to use when - deserializing a file_type parameter. - If passed, type conversion is attempted - If omitted no type conversion is done. - _visited_composed_classes (tuple): This stores a tuple of - classes that we have traveled through so that - if we see that class again we will not use its - discriminator again. - When traveling through a discriminator, the - composed schema that is - is traveled through is added to this set. - For example if Animal has a discriminator - petType and we pass in "Dog", and the class Dog - allOf includes Animal, we move through Animal - once using the discriminator, and pick Dog. - Then in Dog, we will make an instance of the - Animal class but this time we won't travel - through its discriminator because we passed in - _visited_composed_classes = (Animal,) - """ - - if 'value' in kwargs: - value = kwargs.pop('value') - elif args: - args = list(args) - value = args.pop(0) - else: - value = - _check_type = kwargs.pop('_check_type', True) - _spec_property_naming = kwargs.pop('_spec_property_naming', False) - _path_to_item = kwargs.pop('_path_to_item', ()) - _configuration = kwargs.pop('_configuration', None) - _visited_composed_classes = kwargs.pop('_visited_composed_classes', ()) - - if args: - raise ApiTypeError( - "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % ( - args, - self.__class__.__name__, - ), - path_to_item=_path_to_item, - valid_classes=(self.__class__,), - ) - - self._data_store = {} - self._check_type = _check_type - self._spec_property_naming = _spec_property_naming - self._path_to_item = _path_to_item - self._configuration = _configuration - self._visited_composed_classes = _visited_composed_classes + (self.__class__,) - self.value = value - if kwargs: - raise ApiTypeError( - "Invalid named arguments=%s passed to %s. Remove those invalid named arguments." % ( - kwargs, - self.__class__.__name__, - ), - path_to_item=_path_to_item, - valid_classes=(self.__class__,), - ) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean.py deleted file mode 100644 index 2fc9bf976a3c..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean.py +++ /dev/null @@ -1,174 +0,0 @@ -# coding: utf-8 - -""" - OpenAPI Petstore - - This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 - - The version of the OpenAPI document: 1.0.0 - Generated by: https://openapi-generator.tech -""" - - -import re # noqa: F401 -import sys # noqa: F401 - -import nulltype # noqa: F401 - -from petstore_api.model_utils import ( # noqa: F401 - ApiTypeError, - ModelComposed, - ModelNormal, - ModelSimple, - cached_property, - change_keys_js_to_python, - convert_js_args_to_python_args, - date, - datetime, - file_type, - none_type, - validate_get_composed_info, -) - - -class Boolean(ModelSimple): - """NOTE: This class is auto generated by OpenAPI Generator. - Ref: https://openapi-generator.tech - - Do not edit the class manually. - - Attributes: - allowed_values (dict): The key is the tuple path to the attribute - and the for var_name this is (var_name,). The value is a dict - with a capitalized key describing the allowed value and an allowed - value. These dicts store the allowed enum values. - validations (dict): The key is the tuple path to the attribute - and the for var_name this is (var_name,). The value is a dict - that stores validations for max_length, min_length, max_items, - min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, - inclusive_minimum, and regex. - additional_properties_type (tuple): A tuple of classes accepted - as additional properties values. - """ - - allowed_values = { - } - - validations = { - ('value',): { - }, - } - - additional_properties_type = None - - _nullable = False - - @cached_property - def openapi_types(): - """ - This must be a method because a model may have properties that are - of type self, this must run after the class is loaded - - Returns - openapi_types (dict): The key is attribute name - and the value is attribute type. - """ - return { - 'value': (bool,), - } - - @cached_property - def discriminator(): - return None - - - attribute_map = {} - - _composed_schemas = None - - required_properties = set([ - '_data_store', - '_check_type', - '_spec_property_naming', - '_path_to_item', - '_configuration', - '_visited_composed_classes', - ]) - - @convert_js_args_to_python_args - def __init__(self, *args, **kwargs): - """Boolean - a model defined in OpenAPI - - Keyword Args: - value (bool): # noqa: E501 - _check_type (bool): if True, values for parameters in openapi_types - will be type checked and a TypeError will be - raised if the wrong type is input. - Defaults to True - _path_to_item (tuple/list): This is a list of keys or values to - drill down to the model in received_data - when deserializing a response - _spec_property_naming (bool): True if the variable names in the input data - are serialized names, as specified in the OpenAPI document. - False if the variable names in the input data - are pythonic names, e.g. snake case (default) - _configuration (Configuration): the instance to use when - deserializing a file_type parameter. - If passed, type conversion is attempted - If omitted no type conversion is done. - _visited_composed_classes (tuple): This stores a tuple of - classes that we have traveled through so that - if we see that class again we will not use its - discriminator again. - When traveling through a discriminator, the - composed schema that is - is traveled through is added to this set. - For example if Animal has a discriminator - petType and we pass in "Dog", and the class Dog - allOf includes Animal, we move through Animal - once using the discriminator, and pick Dog. - Then in Dog, we will make an instance of the - Animal class but this time we won't travel - through its discriminator because we passed in - _visited_composed_classes = (Animal,) - """ - - if 'value' in kwargs: - value = kwargs.pop('value') - elif args: - args = list(args) - value = args.pop(0) - else: - value = - _check_type = kwargs.pop('_check_type', True) - _spec_property_naming = kwargs.pop('_spec_property_naming', False) - _path_to_item = kwargs.pop('_path_to_item', ()) - _configuration = kwargs.pop('_configuration', None) - _visited_composed_classes = kwargs.pop('_visited_composed_classes', ()) - - if args: - raise ApiTypeError( - "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % ( - args, - self.__class__.__name__, - ), - path_to_item=_path_to_item, - valid_classes=(self.__class__,), - ) - - self._data_store = {} - self._check_type = _check_type - self._spec_property_naming = _spec_property_naming - self._path_to_item = _path_to_item - self._configuration = _configuration - self._visited_composed_classes = _visited_composed_classes + (self.__class__,) - self.value = value - if kwargs: - raise ApiTypeError( - "Invalid named arguments=%s passed to %s. Remove those invalid named arguments." % ( - kwargs, - self.__class__.__name__, - ), - path_to_item=_path_to_item, - valid_classes=(self.__class__,), - ) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/date_time_test.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/date_time_test.py deleted file mode 100644 index a79471f25944..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/date_time_test.py +++ /dev/null @@ -1,174 +0,0 @@ -# coding: utf-8 - -""" - OpenAPI Petstore - - This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 - - The version of the OpenAPI document: 1.0.0 - Generated by: https://openapi-generator.tech -""" - - -import re # noqa: F401 -import sys # noqa: F401 - -import nulltype # noqa: F401 - -from petstore_api.model_utils import ( # noqa: F401 - ApiTypeError, - ModelComposed, - ModelNormal, - ModelSimple, - cached_property, - change_keys_js_to_python, - convert_js_args_to_python_args, - date, - datetime, - file_type, - none_type, - validate_get_composed_info, -) - - -class DateTimeTest(ModelSimple): - """NOTE: This class is auto generated by OpenAPI Generator. - Ref: https://openapi-generator.tech - - Do not edit the class manually. - - Attributes: - allowed_values (dict): The key is the tuple path to the attribute - and the for var_name this is (var_name,). The value is a dict - with a capitalized key describing the allowed value and an allowed - value. These dicts store the allowed enum values. - validations (dict): The key is the tuple path to the attribute - and the for var_name this is (var_name,). The value is a dict - that stores validations for max_length, min_length, max_items, - min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, - inclusive_minimum, and regex. - additional_properties_type (tuple): A tuple of classes accepted - as additional properties values. - """ - - allowed_values = { - } - - validations = { - ('value',): { - }, - } - - additional_properties_type = None - - _nullable = False - - @cached_property - def openapi_types(): - """ - This must be a method because a model may have properties that are - of type self, this must run after the class is loaded - - Returns - openapi_types (dict): The key is attribute name - and the value is attribute type. - """ - return { - 'value': (datetime,), - } - - @cached_property - def discriminator(): - return None - - - attribute_map = {} - - _composed_schemas = None - - required_properties = set([ - '_data_store', - '_check_type', - '_spec_property_naming', - '_path_to_item', - '_configuration', - '_visited_composed_classes', - ]) - - @convert_js_args_to_python_args - def __init__(self, *args, **kwargs): - """DateTimeTest - a model defined in OpenAPI - - Keyword Args: - value (datetime): # noqa: E501 - _check_type (bool): if True, values for parameters in openapi_types - will be type checked and a TypeError will be - raised if the wrong type is input. - Defaults to True - _path_to_item (tuple/list): This is a list of keys or values to - drill down to the model in received_data - when deserializing a response - _spec_property_naming (bool): True if the variable names in the input data - are serialized names, as specified in the OpenAPI document. - False if the variable names in the input data - are pythonic names, e.g. snake case (default) - _configuration (Configuration): the instance to use when - deserializing a file_type parameter. - If passed, type conversion is attempted - If omitted no type conversion is done. - _visited_composed_classes (tuple): This stores a tuple of - classes that we have traveled through so that - if we see that class again we will not use its - discriminator again. - When traveling through a discriminator, the - composed schema that is - is traveled through is added to this set. - For example if Animal has a discriminator - petType and we pass in "Dog", and the class Dog - allOf includes Animal, we move through Animal - once using the discriminator, and pick Dog. - Then in Dog, we will make an instance of the - Animal class but this time we won't travel - through its discriminator because we passed in - _visited_composed_classes = (Animal,) - """ - - if 'value' in kwargs: - value = kwargs.pop('value') - elif args: - args = list(args) - value = args.pop(0) - else: - value = - _check_type = kwargs.pop('_check_type', True) - _spec_property_naming = kwargs.pop('_spec_property_naming', False) - _path_to_item = kwargs.pop('_path_to_item', ()) - _configuration = kwargs.pop('_configuration', None) - _visited_composed_classes = kwargs.pop('_visited_composed_classes', ()) - - if args: - raise ApiTypeError( - "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % ( - args, - self.__class__.__name__, - ), - path_to_item=_path_to_item, - valid_classes=(self.__class__,), - ) - - self._data_store = {} - self._check_type = _check_type - self._spec_property_naming = _spec_property_naming - self._path_to_item = _path_to_item - self._configuration = _configuration - self._visited_composed_classes = _visited_composed_classes + (self.__class__,) - self.value = value - if kwargs: - raise ApiTypeError( - "Invalid named arguments=%s passed to %s. Remove those invalid named arguments." % ( - kwargs, - self.__class__.__name__, - ), - path_to_item=_path_to_item, - valid_classes=(self.__class__,), - ) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number.py deleted file mode 100644 index aa7e2e62e607..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number.py +++ /dev/null @@ -1,174 +0,0 @@ -# coding: utf-8 - -""" - OpenAPI Petstore - - This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 - - The version of the OpenAPI document: 1.0.0 - Generated by: https://openapi-generator.tech -""" - - -import re # noqa: F401 -import sys # noqa: F401 - -import nulltype # noqa: F401 - -from petstore_api.model_utils import ( # noqa: F401 - ApiTypeError, - ModelComposed, - ModelNormal, - ModelSimple, - cached_property, - change_keys_js_to_python, - convert_js_args_to_python_args, - date, - datetime, - file_type, - none_type, - validate_get_composed_info, -) - - -class Number(ModelSimple): - """NOTE: This class is auto generated by OpenAPI Generator. - Ref: https://openapi-generator.tech - - Do not edit the class manually. - - Attributes: - allowed_values (dict): The key is the tuple path to the attribute - and the for var_name this is (var_name,). The value is a dict - with a capitalized key describing the allowed value and an allowed - value. These dicts store the allowed enum values. - validations (dict): The key is the tuple path to the attribute - and the for var_name this is (var_name,). The value is a dict - that stores validations for max_length, min_length, max_items, - min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, - inclusive_minimum, and regex. - additional_properties_type (tuple): A tuple of classes accepted - as additional properties values. - """ - - allowed_values = { - } - - validations = { - ('value',): { - }, - } - - additional_properties_type = None - - _nullable = False - - @cached_property - def openapi_types(): - """ - This must be a method because a model may have properties that are - of type self, this must run after the class is loaded - - Returns - openapi_types (dict): The key is attribute name - and the value is attribute type. - """ - return { - 'value': (float,), - } - - @cached_property - def discriminator(): - return None - - - attribute_map = {} - - _composed_schemas = None - - required_properties = set([ - '_data_store', - '_check_type', - '_spec_property_naming', - '_path_to_item', - '_configuration', - '_visited_composed_classes', - ]) - - @convert_js_args_to_python_args - def __init__(self, *args, **kwargs): - """Number - a model defined in OpenAPI - - Keyword Args: - value (float): # noqa: E501 - _check_type (bool): if True, values for parameters in openapi_types - will be type checked and a TypeError will be - raised if the wrong type is input. - Defaults to True - _path_to_item (tuple/list): This is a list of keys or values to - drill down to the model in received_data - when deserializing a response - _spec_property_naming (bool): True if the variable names in the input data - are serialized names, as specified in the OpenAPI document. - False if the variable names in the input data - are pythonic names, e.g. snake case (default) - _configuration (Configuration): the instance to use when - deserializing a file_type parameter. - If passed, type conversion is attempted - If omitted no type conversion is done. - _visited_composed_classes (tuple): This stores a tuple of - classes that we have traveled through so that - if we see that class again we will not use its - discriminator again. - When traveling through a discriminator, the - composed schema that is - is traveled through is added to this set. - For example if Animal has a discriminator - petType and we pass in "Dog", and the class Dog - allOf includes Animal, we move through Animal - once using the discriminator, and pick Dog. - Then in Dog, we will make an instance of the - Animal class but this time we won't travel - through its discriminator because we passed in - _visited_composed_classes = (Animal,) - """ - - if 'value' in kwargs: - value = kwargs.pop('value') - elif args: - args = list(args) - value = args.pop(0) - else: - value = - _check_type = kwargs.pop('_check_type', True) - _spec_property_naming = kwargs.pop('_spec_property_naming', False) - _path_to_item = kwargs.pop('_path_to_item', ()) - _configuration = kwargs.pop('_configuration', None) - _visited_composed_classes = kwargs.pop('_visited_composed_classes', ()) - - if args: - raise ApiTypeError( - "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % ( - args, - self.__class__.__name__, - ), - path_to_item=_path_to_item, - valid_classes=(self.__class__,), - ) - - self._data_store = {} - self._check_type = _check_type - self._spec_property_naming = _spec_property_naming - self._path_to_item = _path_to_item - self._configuration = _configuration - self._visited_composed_classes = _visited_composed_classes + (self.__class__,) - self.value = value - if kwargs: - raise ApiTypeError( - "Invalid named arguments=%s passed to %s. Remove those invalid named arguments." % ( - kwargs, - self.__class__.__name__, - ), - path_to_item=_path_to_item, - valid_classes=(self.__class__,), - ) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string.py deleted file mode 100644 index 4ec673447cf5..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string.py +++ /dev/null @@ -1,174 +0,0 @@ -# coding: utf-8 - -""" - OpenAPI Petstore - - This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 - - The version of the OpenAPI document: 1.0.0 - Generated by: https://openapi-generator.tech -""" - - -import re # noqa: F401 -import sys # noqa: F401 - -import nulltype # noqa: F401 - -from petstore_api.model_utils import ( # noqa: F401 - ApiTypeError, - ModelComposed, - ModelNormal, - ModelSimple, - cached_property, - change_keys_js_to_python, - convert_js_args_to_python_args, - date, - datetime, - file_type, - none_type, - validate_get_composed_info, -) - - -class String(ModelSimple): - """NOTE: This class is auto generated by OpenAPI Generator. - Ref: https://openapi-generator.tech - - Do not edit the class manually. - - Attributes: - allowed_values (dict): The key is the tuple path to the attribute - and the for var_name this is (var_name,). The value is a dict - with a capitalized key describing the allowed value and an allowed - value. These dicts store the allowed enum values. - validations (dict): The key is the tuple path to the attribute - and the for var_name this is (var_name,). The value is a dict - that stores validations for max_length, min_length, max_items, - min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, - inclusive_minimum, and regex. - additional_properties_type (tuple): A tuple of classes accepted - as additional properties values. - """ - - allowed_values = { - } - - validations = { - ('value',): { - }, - } - - additional_properties_type = None - - _nullable = False - - @cached_property - def openapi_types(): - """ - This must be a method because a model may have properties that are - of type self, this must run after the class is loaded - - Returns - openapi_types (dict): The key is attribute name - and the value is attribute type. - """ - return { - 'value': (str,), - } - - @cached_property - def discriminator(): - return None - - - attribute_map = {} - - _composed_schemas = None - - required_properties = set([ - '_data_store', - '_check_type', - '_spec_property_naming', - '_path_to_item', - '_configuration', - '_visited_composed_classes', - ]) - - @convert_js_args_to_python_args - def __init__(self, *args, **kwargs): - """String - a model defined in OpenAPI - - Keyword Args: - value (str): # noqa: E501 - _check_type (bool): if True, values for parameters in openapi_types - will be type checked and a TypeError will be - raised if the wrong type is input. - Defaults to True - _path_to_item (tuple/list): This is a list of keys or values to - drill down to the model in received_data - when deserializing a response - _spec_property_naming (bool): True if the variable names in the input data - are serialized names, as specified in the OpenAPI document. - False if the variable names in the input data - are pythonic names, e.g. snake case (default) - _configuration (Configuration): the instance to use when - deserializing a file_type parameter. - If passed, type conversion is attempted - If omitted no type conversion is done. - _visited_composed_classes (tuple): This stores a tuple of - classes that we have traveled through so that - if we see that class again we will not use its - discriminator again. - When traveling through a discriminator, the - composed schema that is - is traveled through is added to this set. - For example if Animal has a discriminator - petType and we pass in "Dog", and the class Dog - allOf includes Animal, we move through Animal - once using the discriminator, and pick Dog. - Then in Dog, we will make an instance of the - Animal class but this time we won't travel - through its discriminator because we passed in - _visited_composed_classes = (Animal,) - """ - - if 'value' in kwargs: - value = kwargs.pop('value') - elif args: - args = list(args) - value = args.pop(0) - else: - value = - _check_type = kwargs.pop('_check_type', True) - _spec_property_naming = kwargs.pop('_spec_property_naming', False) - _path_to_item = kwargs.pop('_path_to_item', ()) - _configuration = kwargs.pop('_configuration', None) - _visited_composed_classes = kwargs.pop('_visited_composed_classes', ()) - - if args: - raise ApiTypeError( - "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % ( - args, - self.__class__.__name__, - ), - path_to_item=_path_to_item, - valid_classes=(self.__class__,), - ) - - self._data_store = {} - self._check_type = _check_type - self._spec_property_naming = _spec_property_naming - self._path_to_item = _path_to_item - self._configuration = _configuration - self._visited_composed_classes = _visited_composed_classes + (self.__class__,) - self.value = value - if kwargs: - raise ApiTypeError( - "Invalid named arguments=%s passed to %s. Remove those invalid named arguments." % ( - kwargs, - self.__class__.__name__, - ), - path_to_item=_path_to_item, - valid_classes=(self.__class__,), - ) diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_bar.py b/samples/openapi3/client/petstore/python-experimental/test/test_bar.py deleted file mode 100644 index a63f1e74f8be..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/test/test_bar.py +++ /dev/null @@ -1,37 +0,0 @@ -# coding: utf-8 - -""" - OpenAPI Petstore - - This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 - - The version of the OpenAPI document: 1.0.0 - Generated by: https://openapi-generator.tech -""" - - -import sys -import unittest - -import petstore_api -from petstore_api.model.bar import Bar - - -class TestBar(unittest.TestCase): - """Bar unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def testBar(self): - """Test Bar""" - # FIXME: construct object with mandatory attributes with example values - # model = Bar() # noqa: E501 - pass - - -if __name__ == '__main__': - unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_boolean.py b/samples/openapi3/client/petstore/python-experimental/test/test_boolean.py deleted file mode 100644 index 703c3b8e6e98..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/test/test_boolean.py +++ /dev/null @@ -1,37 +0,0 @@ -# coding: utf-8 - -""" - OpenAPI Petstore - - This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 - - The version of the OpenAPI document: 1.0.0 - Generated by: https://openapi-generator.tech -""" - - -import sys -import unittest - -import petstore_api -from petstore_api.model.boolean import Boolean - - -class TestBoolean(unittest.TestCase): - """Boolean unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def testBoolean(self): - """Test Boolean""" - # FIXME: construct object with mandatory attributes with example values - # model = Boolean() # noqa: E501 - pass - - -if __name__ == '__main__': - unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_date_time_test.py b/samples/openapi3/client/petstore/python-experimental/test/test_date_time_test.py deleted file mode 100644 index cd9db5764946..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/test/test_date_time_test.py +++ /dev/null @@ -1,37 +0,0 @@ -# coding: utf-8 - -""" - OpenAPI Petstore - - This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 - - The version of the OpenAPI document: 1.0.0 - Generated by: https://openapi-generator.tech -""" - - -import sys -import unittest - -import petstore_api -from petstore_api.model.date_time_test import DateTimeTest - - -class TestDateTimeTest(unittest.TestCase): - """DateTimeTest unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def testDateTimeTest(self): - """Test DateTimeTest""" - # FIXME: construct object with mandatory attributes with example values - # model = DateTimeTest() # noqa: E501 - pass - - -if __name__ == '__main__': - unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_number.py b/samples/openapi3/client/petstore/python-experimental/test/test_number.py deleted file mode 100644 index 8656313f4fca..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/test/test_number.py +++ /dev/null @@ -1,37 +0,0 @@ -# coding: utf-8 - -""" - OpenAPI Petstore - - This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 - - The version of the OpenAPI document: 1.0.0 - Generated by: https://openapi-generator.tech -""" - - -import sys -import unittest - -import petstore_api -from petstore_api.model.number import Number - - -class TestNumber(unittest.TestCase): - """Number unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def testNumber(self): - """Test Number""" - # FIXME: construct object with mandatory attributes with example values - # model = Number() # noqa: E501 - pass - - -if __name__ == '__main__': - unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_string.py b/samples/openapi3/client/petstore/python-experimental/test/test_string.py deleted file mode 100644 index 5034f26cdec0..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/test/test_string.py +++ /dev/null @@ -1,37 +0,0 @@ -# coding: utf-8 - -""" - OpenAPI Petstore - - This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 - - The version of the OpenAPI document: 1.0.0 - Generated by: https://openapi-generator.tech -""" - - -import sys -import unittest - -import petstore_api -from petstore_api.model.string import String - - -class TestString(unittest.TestCase): - """String unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def testString(self): - """Test String""" - # FIXME: construct object with mandatory attributes with example values - # model = String() # noqa: E501 - pass - - -if __name__ == '__main__': - unittest.main() From c41c6a10ddc68e6c94aa1bb3ebbb602660465fef Mon Sep 17 00:00:00 2001 From: Justin Black Date: Fri, 21 Aug 2020 09:31:21 -0700 Subject: [PATCH 04/16] Uses unaliasSchema in getSchemaType and adds todos --- .../codegen/languages/PythonClientExperimentalCodegen.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java index 4f9337b9854f..77b1f48983b0 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java @@ -951,7 +951,7 @@ public CodegenModel fromModel(String name, Schema schema) { @Override public String getSchemaType(Schema schema) { if (schema instanceof ComposedSchema) { // composed schema - Schema unaliasSchema = ModelUtils.unaliasSchema(this.openAPI, schema, importMapping); + Schema unaliasSchema = unaliasSchema(schema, importMapping); String ref = unaliasSchema.get$ref(); if (ref != null) { String schemaName = ModelUtils.getSimpleRef(unaliasSchema.get$ref()); @@ -960,6 +960,7 @@ public String getSchemaType(Schema schema) { } return getAlias(schemaName); } else { + // TODO remove this once I remove all the variable setting that uses it // we may have be processing the component schema rather than a schema with a $ref // to a component schema // so loop through component schemas and use the found one's name if we match @@ -980,6 +981,7 @@ public String getSchemaType(Schema schema) { return "object"; } } + // TODO update this to use only getSingleSchemaType String openAPIType = getSingleSchemaType(schema); if (typeMapping.containsKey(openAPIType)) { String type = typeMapping.get(openAPIType); From 6b990631fa3049d021ff85414e809d7dfc29fe31 Mon Sep 17 00:00:00 2001 From: Justin Black Date: Fri, 21 Aug 2020 10:01:56 -0700 Subject: [PATCH 05/16] Deletes handleMethodResponse and fromResponse --- .../PythonClientExperimentalCodegen.java | 123 ++---------------- 1 file changed, 9 insertions(+), 114 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java index 77b1f48983b0..153d8b95fd8f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java @@ -452,11 +452,16 @@ public Map postProcessAllModels(Map objs) { @Override public CodegenProperty fromProperty(String name, Schema p) { // we have a custom version of this function to always set allowableValues.enumVars on all enum variables - CodegenProperty result = super.fromProperty(name, p); - if (result.isEnum) { - updateCodegenPropertyEnum(result); + CodegenProperty cp = super.fromProperty(name, p); + if (cp.isEnum) { + updateCodegenPropertyEnum(cp); } - return result; + // together with unaliasSchema this sets primitive types with validations as models + // this is used by fromResponse + if (cp.isPrimitiveType && p.get$ref() != null) { + cp.complexType = cp.dataType; + } + return cp; } /** @@ -530,58 +535,6 @@ public CodegenParameter fromRequestBody(RequestBody body, Set imports, S return result; } - /** - * Convert OAS Response object to Codegen Response object - * - * @param responseCode HTTP response code - * @param response OAS Response object - * @return Codegen Response object - */ - @Override - public CodegenResponse fromResponse(String responseCode, ApiResponse response) { - // if a response points at a model whose type != object and it has validations and/or enums, then we will - // generate the model, and response.baseType must be the name - // of the model. Point responses at models if the model is python class type ModelSimple - // When we serialize/deserialize ModelSimple models, validations and enums will be checked. - Schema responseSchema; - if (this.openAPI != null && this.openAPI.getComponents() != null) { - responseSchema = ModelUtils.unaliasSchema(this.openAPI, ModelUtils.getSchemaFromResponse(response), importMapping); - } else { // no model/alias defined - responseSchema = ModelUtils.getSchemaFromResponse(response); - } - - String newBaseType = null; - if (responseSchema != null) { - CodegenProperty cp = fromProperty("response", responseSchema); - if (cp.complexType != null) { - String modelName = cp.complexType; - Schema modelSchema = ModelUtils.getSchema(this.openAPI, modelName); - if (modelSchema != null && !"object".equals(modelSchema.getType())) { - CodegenProperty modelProp = fromProperty("response", modelSchema); - if (modelProp.isEnum == true || modelProp.hasValidation == true) { - // this model has validations and/or enums so we will generate it - newBaseType = modelName; - } - } - } else { - if (cp.isEnum == true || cp.hasValidation == true) { - // this model has validations and/or enums so we will generate it - Schema sc = ModelUtils.getSchemaFromResponse(response); - newBaseType = toModelName(ModelUtils.getSimpleRef(sc.get$ref())); - } - } - } - - CodegenResponse result = super.fromResponse(responseCode, response); - if (newBaseType != null) { - result.dataType = newBaseType; - // baseType is used to set the link to the model .md documentation - result.baseType = newBaseType; - } - - return result; - } - /** * Set op's returnBaseType, returnType, examples etc. * @@ -598,64 +551,6 @@ public void handleMethodResponse(Operation operation, handleMethodResponse(operation, schemas, op, methodResponse, Collections.emptyMap()); } - /** - * Set op's returnBaseType, returnType, examples etc. - * - * @param operation endpoint Operation - * @param schemas a map of the schemas in the openapi spec - * @param op endpoint CodegenOperation - * @param methodResponse the default ApiResponse for the endpoint - * @param importMappings mappings of external types to be omitted by unaliasing - */ - @Override - protected void handleMethodResponse(Operation operation, - Map schemas, - CodegenOperation op, - ApiResponse methodResponse, - Map importMappings) { - // we have a custom version of this method to handle endpoints that return models where - // type != object the model has validations and/or enums - // we do this by invoking our custom fromResponse method to create defaultResponse - // which we then use to set op.returnType and op.returnBaseType - CodegenResponse defaultResponse = fromResponse("defaultResponse", methodResponse); - Schema responseSchema = ModelUtils.unaliasSchema(this.openAPI, ModelUtils.getSchemaFromResponse(methodResponse), importMappings); - - if (responseSchema != null) { - op.returnBaseType = defaultResponse.baseType; - - // generate examples - String exampleStatusCode = "200"; - for (String key : operation.getResponses().keySet()) { - if (operation.getResponses().get(key) == methodResponse && !key.equals("default")) { - exampleStatusCode = key; - } - } - op.examples = new ExampleGenerator(schemas, this.openAPI).generateFromResponseSchema(exampleStatusCode, responseSchema, getProducesInfo(this.openAPI, operation)); - op.defaultResponse = toDefaultValue(responseSchema); - op.returnType = defaultResponse.dataType; - op.hasReference = schemas.containsKey(op.returnBaseType); - - // lookup discriminator - Schema schema = schemas.get(op.returnBaseType); - if (schema != null) { - CodegenModel cmod = fromModel(op.returnBaseType, schema); - op.discriminator = cmod.discriminator; - } - - if (defaultResponse.isListContainer) { - op.isListContainer = true; - } else if (defaultResponse.isMapContainer) { - op.isMapContainer = true; - } else { - op.returnSimpleType = true; - } - if (languageSpecificPrimitives().contains(op.returnBaseType) || op.returnBaseType == null) { - op.returnTypeIsPrimitive = true; - } - } - addHeaders(methodResponse, op.responseHeaders); - } - /** * Return the sanitized variable name for enum From df4452052287de8e9d40391d2b72f7cd0404e1e7 Mon Sep 17 00:00:00 2001 From: Justin Black Date: Sat, 22 Aug 2020 10:58:11 -0700 Subject: [PATCH 06/16] Simplifies fromRequestBody --- .../PythonClientExperimentalCodegen.java | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java index 153d8b95fd8f..6dda9095ca83 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java @@ -275,7 +275,7 @@ protected Schema unaliasSchema(Schema schema, Map usedImportMapp return unaliasSchema(allSchemas.get(ModelUtils.getSimpleRef(schema.get$ref())), usedImportMappings); } - } else if (HasValidation(ref)) { + } else if (hasValidation(ref)) { // non object non array non map schemas that have validations // are returned so we can generate those schemas as models // we do this to: @@ -455,6 +455,9 @@ public CodegenProperty fromProperty(String name, Schema p) { CodegenProperty cp = super.fromProperty(name, p); if (cp.isEnum) { updateCodegenPropertyEnum(cp); + if (p.get$ref() != null) { + String a = "a"; + } } // together with unaliasSchema this sets primitive types with validations as models // this is used by fromResponse @@ -508,31 +511,31 @@ public void updateCodegenPropertyEnum(CodegenProperty var) { // overwriting defaultValue omitted from here } + /*** + * We have a custom version of this method to produce links to models when they are + * primitive type (not map, not array, not object) and include validations or are enums + * + * @param body requesst body + * @param imports import collection + * @param bodyParameterName body parameter name + * @return the resultant CodegenParameter + */ @Override public CodegenParameter fromRequestBody(RequestBody body, Set imports, String bodyParameterName) { - CodegenParameter result = super.fromRequestBody(body, imports, bodyParameterName); - // if we generated a model with a non-object type because it has validations or enums, - // make sure that the datatype of that body parameter refers to our model class - Content content = body.getContent(); - Set keySet = content.keySet(); - Object[] keyArray = (Object[]) keySet.toArray(); - MediaType mediaType = content.get(keyArray[0]); - Schema schema = mediaType.getSchema(); - String ref = schema.get$ref(); - if (ref == null) { - return result; - } - String modelName = ModelUtils.getSimpleRef(ref); - // the result lacks validation info so we need to make a CodegenProperty from the schema to check - // if we have validation and enum info exists - Schema realSchema = ModelUtils.getSchema(this.openAPI, modelName); - CodegenProperty modelProp = fromProperty("body", realSchema); - if (modelProp.isPrimitiveType && (modelProp.hasValidation || modelProp.isEnum)) { - String simpleDataType = result.dataType; - result.dataType = toModelName(modelName); - result.baseType = result.dataType; + CodegenParameter cp = super.fromRequestBody(body, imports, bodyParameterName); + Schema schema = ModelUtils.getSchemaFromRequestBody(body); + if (schema.get$ref() == null) { + return cp; + } + Schema unaliasedSchema = unaliasSchema(schema, importMapping); + CodegenProperty unaliasedProp = fromProperty("body", unaliasedSchema); + Boolean dataTypeMismatch = !cp.dataType.equals(unaliasedProp.dataType); + Boolean baseTypeMismatch = !cp.baseType.equals(unaliasedProp.complexType) && unaliasedProp.complexType != null; + if (dataTypeMismatch || baseTypeMismatch) { + cp.dataType = unaliasedProp.dataType; + cp.baseType = unaliasedProp.complexType; } - return result; + return cp; } /** @@ -915,7 +918,7 @@ public String getSimpleTypeDeclaration(Schema schema) { return oasType; } - public Boolean HasValidation(Schema s) { + public Boolean hasValidation(Schema s) { return ( s.getMaxItems() != null || s.getMinLength() != null || @@ -940,7 +943,7 @@ public Boolean modelWillBeMade(Schema s) { if (enums != null && !enums.isEmpty()) { return true; } - if (HasValidation(s)) { + if (hasValidation(s)) { return true; } return false; From be6a8fc08e84d58905b1a510c4bd39b9aa29abf7 Mon Sep 17 00:00:00 2001 From: Justin Black Date: Sat, 22 Aug 2020 11:01:59 -0700 Subject: [PATCH 07/16] Removes unneeded handleMethodResponse --- .../PythonClientExperimentalCodegen.java | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java index 6dda9095ca83..2a1dd92d87cb 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java @@ -538,23 +538,6 @@ public CodegenParameter fromRequestBody(RequestBody body, Set imports, S return cp; } - /** - * Set op's returnBaseType, returnType, examples etc. - * - * @param operation endpoint Operation - * @param schemas a map of the schemas in the openapi spec - * @param op endpoint CodegenOperation - * @param methodResponse the default ApiResponse for the endpoint - */ - @Override - public void handleMethodResponse(Operation operation, - Map schemas, - CodegenOperation op, - ApiResponse methodResponse) { - handleMethodResponse(operation, schemas, op, methodResponse, Collections.emptyMap()); - } - - /** * Return the sanitized variable name for enum * From 2c1fdce2b6863aa3348de6cb4cc2cb5cd0a6eadd Mon Sep 17 00:00:00 2001 From: Justin Black Date: Sat, 22 Aug 2020 11:50:58 -0700 Subject: [PATCH 08/16] Updates javadoc --- .../languages/PythonClientExperimentalCodegen.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java index 2a1dd92d87cb..832e2f7295c3 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java @@ -444,6 +444,9 @@ public Map postProcessAllModels(Map objs) { /** * Convert OAS Property object to Codegen Property object + * We have a custom version of this method to always set allowableValues.enumVars on all enum variables + * Together with unaliasSchema this sets primitive types with validations as models + * This method is used by fromResponse * * @param name name of the property * @param p OAS property object @@ -451,16 +454,10 @@ public Map postProcessAllModels(Map objs) { */ @Override public CodegenProperty fromProperty(String name, Schema p) { - // we have a custom version of this function to always set allowableValues.enumVars on all enum variables CodegenProperty cp = super.fromProperty(name, p); if (cp.isEnum) { updateCodegenPropertyEnum(cp); - if (p.get$ref() != null) { - String a = "a"; - } } - // together with unaliasSchema this sets primitive types with validations as models - // this is used by fromResponse if (cp.isPrimitiveType && p.get$ref() != null) { cp.complexType = cp.dataType; } From d45b757a2edd46f93a859fbe39b9419b71d6c6ad Mon Sep 17 00:00:00 2001 From: Justin Black Date: Sat, 22 Aug 2020 21:27:04 -0700 Subject: [PATCH 09/16] Updates fromModel --- .../PythonClientExperimentalCodegen.java | 198 ++++-------------- ...odels-for-testing-with-http-signature.yaml | 5 + .../.openapi-generator/FILES | 2 + .../petstore/python-experimental/README.md | 1 + .../docs/NumberWithValidationsAndDefault.md | 10 + .../number_with_validations_and_default.py | 171 +++++++++++++++ .../petstore_api/models/__init__.py | 1 + ...est_number_with_validations_and_default.py | 37 ++++ 8 files changed, 271 insertions(+), 154 deletions(-) create mode 100644 samples/openapi3/client/petstore/python-experimental/docs/NumberWithValidationsAndDefault.md create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/number_with_validations_and_default.py create mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_number_with_validations_and_default.py diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java index 832e2f7295c3..af3c9fcf265e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java @@ -17,19 +17,16 @@ package org.openapitools.codegen.languages; import io.swagger.v3.core.util.Json; -import io.swagger.v3.oas.models.Operation; import io.swagger.v3.oas.models.media.*; import io.swagger.v3.oas.models.media.ArraySchema; import io.swagger.v3.oas.models.media.MediaType; import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.parameters.Parameter; import io.swagger.v3.oas.models.parameters.RequestBody; -import io.swagger.v3.oas.models.responses.ApiResponse; import io.swagger.v3.oas.models.security.SecurityScheme; import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.*; import org.openapitools.codegen.CodegenDiscriminator.MappedModel; -import org.openapitools.codegen.examples.ExampleGenerator; import org.openapitools.codegen.meta.features.*; import org.openapitools.codegen.utils.ModelUtils; import org.openapitools.codegen.utils.ProcessUtils; @@ -461,6 +458,9 @@ public CodegenProperty fromProperty(String name, Schema p) { if (cp.isPrimitiveType && p.get$ref() != null) { cp.complexType = cp.dataType; } + if (cp.isListContainer && cp.complexType == null && cp.mostInnerItems.complexType != null) { + cp.complexType = cp.mostInnerItems.complexType; + } return cp; } @@ -652,168 +652,58 @@ protected void addParentContainer(CodegenModel model, String name, Schema schema /** * Convert OAS Model object to Codegen Model object + * We have a custom version of this method so we can: + * - set the correct regex values for requiredVars + optionalVars + * - set model.defaultValue and model.hasRequired per the three use cases defined in this method * * @param name the name of the model - * @param schema OAS Model object + * @param sc OAS Model object * @return Codegen Model object */ @Override - public CodegenModel fromModel(String name, Schema schema) { - // we have a custom version of this function so we can produce - // models for components whose type != object and which have validations and enums - // this ensures that: - // - endpoint (operation) responses with validations and type!=(object or array) - // - oneOf $ref components with validations and type!=(object or array) - // when endpoints receive payloads of these models - // that they will be converted into instances of these models - Map propertyToModelName = new HashMap(); - Map propertiesMap = schema.getProperties(); - if (propertiesMap != null) { - for (Map.Entry entry : propertiesMap.entrySet()) { - String schemaPropertyName = entry.getKey(); - String pythonPropertyName = toVarName(schemaPropertyName); - Schema propertySchema = entry.getValue(); - String ref = propertySchema.get$ref(); - if (ref == null) { - continue; - } - Schema refSchema = ModelUtils.getReferencedSchema(this.openAPI, propertySchema); - String refType = refSchema.getType(); - if (refType == null || refType.equals("object")) { - continue; - } - CodegenProperty modelProperty = fromProperty("_fake_name", refSchema); - if (modelProperty.isEnum == true || modelProperty.hasValidation == false) { - continue; - } - String modelName = ModelUtils.getSimpleRef(ref); - propertyToModelName.put(pythonPropertyName, toModelName(modelName)); - } - } - CodegenModel result = super.fromModel(name, schema); - - // have oneOf point to the correct model - if (ModelUtils.isComposedSchema(schema)) { - ComposedSchema cs = (ComposedSchema) schema; - Map importCounts = new HashMap(); - List oneOfSchemas = cs.getOneOf(); - if (oneOfSchemas != null) { - for (int i = 0; i < oneOfSchemas.size(); i++) { - Schema oneOfSchema = oneOfSchemas.get(i); - String languageType = getTypeDeclaration(oneOfSchema); - String ref = oneOfSchema.get$ref(); - if (ref == null) { - Integer currVal = importCounts.getOrDefault(languageType, 0); - importCounts.put(languageType, currVal+1); - continue; - } - Schema refSchema = ModelUtils.getReferencedSchema(this.openAPI, oneOfSchema); - String refType = refSchema.getType(); - if (refType == null || refType.equals("object")) { - Integer currVal = importCounts.getOrDefault(languageType, 0); - importCounts.put(languageType, currVal+1); - continue; - } - - CodegenProperty modelProperty = fromProperty("_oneOfSchema", refSchema); - if (modelProperty.isEnum == true) { - Integer currVal = importCounts.getOrDefault(languageType, 0); - importCounts.put(languageType, currVal+1); - continue; - } - - languageType = getTypeDeclaration(refSchema); - if (modelProperty.hasValidation == false) { - Integer currVal = importCounts.getOrDefault(languageType, 0); - importCounts.put(languageType, currVal+1); - continue; - } - Integer currVal = importCounts.getOrDefault(languageType, 0); - importCounts.put(languageType, currVal); - String modelName = toModelName(ModelUtils.getSimpleRef(ref)); - result.imports.add(modelName); - result.oneOf.add(modelName); - currVal = importCounts.getOrDefault(modelName, 0); - importCounts.put(modelName, currVal+1); - } - } - for (Map.Entry entry : importCounts.entrySet()) { - String importName = entry.getKey(); - Integer importCount = entry.getValue(); - if (importCount == 0) { - result.oneOf.remove(importName); - } - } + public CodegenModel fromModel(String name, Schema sc) { + CodegenModel cm = super.fromModel(name, sc); + if (cm.requiredVars.size() > 0 && (cm.oneOf.size() > 0 || cm.anyOf.size() > 0)) { + addNullDefaultToOneOfAnyOfReqProps(sc, cm); } - - // this block handles models which have the python base class ModelSimple - // which are responsible for storing validations, enums, and an unnamed value - Schema modelSchema = ModelUtils.getSchema(this.openAPI, result.name); - CodegenProperty modelProperty = fromProperty("_value", modelSchema); - - Boolean isPythonModelSimpleModel = (result.isEnum || result.isArrayModel || result.isAlias && modelProperty.hasValidation); - if (isPythonModelSimpleModel) { - // In python, classes which inherit from our ModelSimple class store one value, - // like a str, int, list and extra data about that value like validations and enums - - if (result.isEnum) { - // if there is only one allowed value then we know that it should be set, so value is optional - // -> hasRequired = false - // if there are more than one allowed value then value is positional and required so - // -> hasRequired = true - ArrayList values = (ArrayList) result.allowableValues.get("values"); - if (values != null && values.size() > 1) { - result.hasRequired = true; - } - - if (modelProperty.defaultValue != null && result.defaultValue == null) { - result.defaultValue = modelProperty.defaultValue; - } - } else { - if (result.defaultValue == null) { - result.hasRequired = true; - } - } - } - // fix all property references to ModelSimple models, make those properties non-primitive and - // set their dataType and complexType to the model name, so documentation will refer to the correct model - // set regex values, before it was only done on model.vars - // NOTE: this is done for models of type != object which are not enums and have validations ArrayList> listOfLists = new ArrayList>(); - listOfLists.add(result.vars); - listOfLists.add(result.allVars); - listOfLists.add(result.requiredVars); - listOfLists.add(result.optionalVars); - listOfLists.add(result.readOnlyVars); - listOfLists.add(result.readWriteVars); + listOfLists.add(cm.requiredVars); + listOfLists.add(cm.optionalVars); for (List cpList : listOfLists) { for (CodegenProperty cp : cpList) { - // set regex values, before it was only done on model.vars - postProcessModelProperty(result, cp); - // fix references to non-object models - if (!propertyToModelName.containsKey(cp.name)) { - continue; - } - cp.isPrimitiveType = false; - String modelName = propertyToModelName.get(cp.name); - cp.complexType = modelName; - cp.dataType = modelName; - cp.isEnum = false; - cp.hasValidation = false; - result.imports.add(modelName); + // sets regex values + postProcessModelProperty(cm, cp); } } - - // if a class has a property of type self, remove the self import from imports - if (result.imports.contains(result.classname)) { - result.imports.remove(result.classname); - } - - if (result.requiredVars.size() > 0 && (result.oneOf.size() > 0 || result.anyOf.size() > 0)) { - addNullDefaultToOneOfAnyOfReqProps(schema, result); - } - - return result; + Boolean isNotPythonModelSimpleModel = (ModelUtils.isComposedSchema(sc) || ModelUtils.isObjectSchema(sc) || ModelUtils.isMapSchema(sc)); + if (isNotPythonModelSimpleModel) { + return cm; + } + // Use cases for default values / enums of length one + // 1. no default exists + // schema does not contain default + // cm.defaultValue unset, cm.hasRequired = true + // 2. server has a default + // schema contains default + // cm.defaultValue set, cm.hasRequired = true + // different value here to differentiate between use case 3 below + // This defaultValue is used in the client docs only and is not sent to the server + // 3. only one value is allowed in an enum + // schema does not contain default + // cm.defaultValue set, cm.hasRequired = false + // because we know what value needs to be set so the user doesn't need to input it + // This defaultValue is used in the client and is sent to the server + String defaultValue = toDefaultValue(sc); + if (sc.getDefault() == null && defaultValue == null) { + cm.hasRequired = true; + } else if (sc.getDefault() != null) { + cm.defaultValue = defaultValue; + cm.hasRequired = true; + } else if (defaultValue != null && cm.defaultValue == null) { + cm.defaultValue = defaultValue; + cm.hasRequired = false; + } + return cm; } /** diff --git a/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index 5e224d07adbe..7ce85797b9d7 100644 --- a/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -1886,6 +1886,11 @@ components: type: number minimum: 10 maximum: 20 + NumberWithValidationsAndDefault: + type: number + default: 15.0 + minimum: 10 + maximum: 20 ComposedOneOfNumberWithValidations: description: this is a model that allows payloads of type object or number oneOf: diff --git a/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES index 88b58048a791..4015ca27c2e8 100644 --- a/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES @@ -71,6 +71,7 @@ docs/NullableClass.md docs/NullableShape.md docs/NumberOnly.md docs/NumberWithValidations.md +docs/NumberWithValidationsAndDefault.md docs/ObjectModelWithRefProps.md docs/Order.md docs/ParentPet.md @@ -177,6 +178,7 @@ petstore_api/model/nullable_class.py petstore_api/model/nullable_shape.py petstore_api/model/number_only.py petstore_api/model/number_with_validations.py +petstore_api/model/number_with_validations_and_default.py petstore_api/model/object_model_with_ref_props.py petstore_api/model/order.py petstore_api/model/parent_pet.py diff --git a/samples/openapi3/client/petstore/python-experimental/README.md b/samples/openapi3/client/petstore/python-experimental/README.md index ec221684f4ed..e9332d542a23 100644 --- a/samples/openapi3/client/petstore/python-experimental/README.md +++ b/samples/openapi3/client/petstore/python-experimental/README.md @@ -194,6 +194,7 @@ Class | Method | HTTP request | Description - [NullableShape](docs/NullableShape.md) - [NumberOnly](docs/NumberOnly.md) - [NumberWithValidations](docs/NumberWithValidations.md) + - [NumberWithValidationsAndDefault](docs/NumberWithValidationsAndDefault.md) - [ObjectModelWithRefProps](docs/ObjectModelWithRefProps.md) - [Order](docs/Order.md) - [ParentPet](docs/ParentPet.md) diff --git a/samples/openapi3/client/petstore/python-experimental/docs/NumberWithValidationsAndDefault.md b/samples/openapi3/client/petstore/python-experimental/docs/NumberWithValidationsAndDefault.md new file mode 100644 index 000000000000..38fd8f22d62c --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/docs/NumberWithValidationsAndDefault.md @@ -0,0 +1,10 @@ +# NumberWithValidationsAndDefault + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**value** | **float** | | if omitted the server will use the default value of 15.0 + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number_with_validations_and_default.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number_with_validations_and_default.py new file mode 100644 index 000000000000..c129db2ab235 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number_with_validations_and_default.py @@ -0,0 +1,171 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import re # noqa: F401 +import sys # noqa: F401 + +import nulltype # noqa: F401 + +from petstore_api.model_utils import ( # noqa: F401 + ApiTypeError, + ModelComposed, + ModelNormal, + ModelSimple, + cached_property, + change_keys_js_to_python, + convert_js_args_to_python_args, + date, + datetime, + file_type, + none_type, + validate_get_composed_info, +) + + +class NumberWithValidationsAndDefault(ModelSimple): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = { + } + + validations = { + ('value',): { + 'inclusive_maximum': 20, + 'inclusive_minimum': 10, + }, + } + + additional_properties_type = None + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a method because a model may have properties that are + of type self, this must run after the class is loaded + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + return { + 'value': (float,), + } + + @cached_property + def discriminator(): + return None + + + attribute_map = {} + + _composed_schemas = None + + required_properties = set([ + '_data_store', + '_check_type', + '_spec_property_naming', + '_path_to_item', + '_configuration', + '_visited_composed_classes', + ]) + + @convert_js_args_to_python_args + def __init__(self, value, *args, **kwargs): + """NumberWithValidationsAndDefault - a model defined in OpenAPI + + Args: + value (float): if omitted the server will use the default value of 15.0 # 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 True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + """ + + _check_type = kwargs.pop('_check_type', True) + _spec_property_naming = kwargs.pop('_spec_property_naming', False) + _path_to_item = kwargs.pop('_path_to_item', ()) + _configuration = kwargs.pop('_configuration', None) + _visited_composed_classes = kwargs.pop('_visited_composed_classes', ()) + + if args: + raise ApiTypeError( + "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % ( + args, + self.__class__.__name__, + ), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) + + self._data_store = {} + self._check_type = _check_type + self._spec_property_naming = _spec_property_naming + self._path_to_item = _path_to_item + self._configuration = _configuration + self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + self.value = value + if kwargs: + raise ApiTypeError( + "Invalid named arguments=%s passed to %s. Remove those invalid named arguments." % ( + kwargs, + self.__class__.__name__, + ), + path_to_item=_path_to_item, + valid_classes=(self.__class__,), + ) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/__init__.py index 5f23a67ada11..59a6e07d9f90 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/__init__.py @@ -76,6 +76,7 @@ from petstore_api.model.nullable_shape import NullableShape from petstore_api.model.number_only import NumberOnly from petstore_api.model.number_with_validations import NumberWithValidations +from petstore_api.model.number_with_validations_and_default import NumberWithValidationsAndDefault from petstore_api.model.object_model_with_ref_props import ObjectModelWithRefProps from petstore_api.model.order import Order from petstore_api.model.parent_pet import ParentPet diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_number_with_validations_and_default.py b/samples/openapi3/client/petstore/python-experimental/test/test_number_with_validations_and_default.py new file mode 100644 index 000000000000..e643747406ae --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/test/test_number_with_validations_and_default.py @@ -0,0 +1,37 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest + +import petstore_api +from petstore_api.model.number_with_validations_and_default import NumberWithValidationsAndDefault + + +class TestNumberWithValidationsAndDefault(unittest.TestCase): + """NumberWithValidationsAndDefault unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testNumberWithValidationsAndDefault(self): + """Test NumberWithValidationsAndDefault""" + # FIXME: construct object with mandatory attributes with example values + # model = NumberWithValidationsAndDefault() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() From 8e9b4127f24f2d9c3ccbcdea2180b916b64db993 Mon Sep 17 00:00:00 2001 From: Justin Black Date: Sun, 23 Aug 2020 11:14:46 -0700 Subject: [PATCH 10/16] Adds python-exp java test defaultSettingInPrimitiveModelWithValidations, removes model NumberWithValidationsAndDefault form v3 sample spec --- .../python/PythonClientExperimentalTest.java | 36 +++- ...odels-for-testing-with-http-signature.yaml | 5 - .../.openapi-generator/FILES | 2 - .../petstore/python-experimental/README.md | 1 - .../docs/NumberWithValidationsAndDefault.md | 10 - .../number_with_validations_and_default.py | 171 ------------------ .../petstore_api/models/__init__.py | 1 - 7 files changed, 35 insertions(+), 191 deletions(-) delete mode 100644 samples/openapi3/client/petstore/python-experimental/docs/NumberWithValidationsAndDefault.md delete mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/number_with_validations_and_default.py diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientExperimentalTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientExperimentalTest.java index 258320fbc4ca..5412564359fc 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientExperimentalTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientExperimentalTest.java @@ -21,7 +21,8 @@ import io.swagger.v3.oas.models.Operation; import io.swagger.v3.oas.models.media.*; import io.swagger.v3.parser.util.SchemaTypeUtil; -import java.time.OffsetDateTime; +import java.math.BigDecimal; +import java.util.Arrays; import org.openapitools.codegen.*; import org.openapitools.codegen.languages.PythonClientExperimentalCodegen; import org.openapitools.codegen.utils.ModelUtils; @@ -341,4 +342,37 @@ public void importSpecialModelNameTest() { Assert.assertEquals(importValue, "from models.special_model_name import SpecialModelName"); } + @Test(description = "format imports of models containing special characters") + public void defaultSettingInPrimitiveModelWithValidations() { + final PythonClientExperimentalCodegen codegen = new PythonClientExperimentalCodegen(); + + OpenAPI openAPI = TestUtils.createOpenAPI(); + final Schema noDefault = new ArraySchema() + .type("number") + .minimum(new BigDecimal("10")); + final Schema hasDefault = new Schema() + .type("number") + .minimum(new BigDecimal("10")); + hasDefault.setDefault("15.0"); + final Schema noDefaultEumLengthOne = new Schema() + .type("number") + .minimum(new BigDecimal("10")); + noDefaultEumLengthOne.setEnum(Arrays.asList("15.0")); + openAPI.getComponents().addSchemas("noDefaultModel", noDefault); + openAPI.getComponents().addSchemas("hasDefaultModel", hasDefault); + openAPI.getComponents().addSchemas("noDefaultEumLengthOneModel", noDefaultEumLengthOne); + codegen.setOpenAPI(openAPI); + + final CodegenModel noDefaultModel = codegen.fromModel("noDefaultModel", noDefault); + Assert.assertEquals(noDefaultModel.defaultValue, null); + Assert.assertEquals(noDefaultModel.hasRequired, true); + + final CodegenModel hasDefaultModel = codegen.fromModel("hasDefaultModel", hasDefault); + Assert.assertEquals(hasDefaultModel.defaultValue, "15.0"); + Assert.assertEquals(hasDefaultModel.hasRequired, true); + + final CodegenModel noDefaultEumLengthOneModel = codegen.fromModel("noDefaultEumLengthOneModel", noDefaultEumLengthOne); + Assert.assertEquals(noDefaultEumLengthOneModel.defaultValue, "15.0"); + Assert.assertEquals(noDefaultEumLengthOneModel.hasRequired, false); + } } diff --git a/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index 7ce85797b9d7..5e224d07adbe 100644 --- a/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -1886,11 +1886,6 @@ components: type: number minimum: 10 maximum: 20 - NumberWithValidationsAndDefault: - type: number - default: 15.0 - minimum: 10 - maximum: 20 ComposedOneOfNumberWithValidations: description: this is a model that allows payloads of type object or number oneOf: diff --git a/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES index 4015ca27c2e8..88b58048a791 100644 --- a/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES @@ -71,7 +71,6 @@ docs/NullableClass.md docs/NullableShape.md docs/NumberOnly.md docs/NumberWithValidations.md -docs/NumberWithValidationsAndDefault.md docs/ObjectModelWithRefProps.md docs/Order.md docs/ParentPet.md @@ -178,7 +177,6 @@ petstore_api/model/nullable_class.py petstore_api/model/nullable_shape.py petstore_api/model/number_only.py petstore_api/model/number_with_validations.py -petstore_api/model/number_with_validations_and_default.py petstore_api/model/object_model_with_ref_props.py petstore_api/model/order.py petstore_api/model/parent_pet.py diff --git a/samples/openapi3/client/petstore/python-experimental/README.md b/samples/openapi3/client/petstore/python-experimental/README.md index e9332d542a23..ec221684f4ed 100644 --- a/samples/openapi3/client/petstore/python-experimental/README.md +++ b/samples/openapi3/client/petstore/python-experimental/README.md @@ -194,7 +194,6 @@ Class | Method | HTTP request | Description - [NullableShape](docs/NullableShape.md) - [NumberOnly](docs/NumberOnly.md) - [NumberWithValidations](docs/NumberWithValidations.md) - - [NumberWithValidationsAndDefault](docs/NumberWithValidationsAndDefault.md) - [ObjectModelWithRefProps](docs/ObjectModelWithRefProps.md) - [Order](docs/Order.md) - [ParentPet](docs/ParentPet.md) diff --git a/samples/openapi3/client/petstore/python-experimental/docs/NumberWithValidationsAndDefault.md b/samples/openapi3/client/petstore/python-experimental/docs/NumberWithValidationsAndDefault.md deleted file mode 100644 index 38fd8f22d62c..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/docs/NumberWithValidationsAndDefault.md +++ /dev/null @@ -1,10 +0,0 @@ -# NumberWithValidationsAndDefault - -## Properties -Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- -**value** | **float** | | if omitted the server will use the default value of 15.0 - -[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) - - diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number_with_validations_and_default.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number_with_validations_and_default.py deleted file mode 100644 index c129db2ab235..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number_with_validations_and_default.py +++ /dev/null @@ -1,171 +0,0 @@ -# coding: utf-8 - -""" - OpenAPI Petstore - - This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 - - The version of the OpenAPI document: 1.0.0 - Generated by: https://openapi-generator.tech -""" - - -import re # noqa: F401 -import sys # noqa: F401 - -import nulltype # noqa: F401 - -from petstore_api.model_utils import ( # noqa: F401 - ApiTypeError, - ModelComposed, - ModelNormal, - ModelSimple, - cached_property, - change_keys_js_to_python, - convert_js_args_to_python_args, - date, - datetime, - file_type, - none_type, - validate_get_composed_info, -) - - -class NumberWithValidationsAndDefault(ModelSimple): - """NOTE: This class is auto generated by OpenAPI Generator. - Ref: https://openapi-generator.tech - - Do not edit the class manually. - - Attributes: - allowed_values (dict): The key is the tuple path to the attribute - and the for var_name this is (var_name,). The value is a dict - with a capitalized key describing the allowed value and an allowed - value. These dicts store the allowed enum values. - validations (dict): The key is the tuple path to the attribute - and the for var_name this is (var_name,). The value is a dict - that stores validations for max_length, min_length, max_items, - min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, - inclusive_minimum, and regex. - additional_properties_type (tuple): A tuple of classes accepted - as additional properties values. - """ - - allowed_values = { - } - - validations = { - ('value',): { - 'inclusive_maximum': 20, - 'inclusive_minimum': 10, - }, - } - - additional_properties_type = None - - _nullable = False - - @cached_property - def openapi_types(): - """ - This must be a method because a model may have properties that are - of type self, this must run after the class is loaded - - Returns - openapi_types (dict): The key is attribute name - and the value is attribute type. - """ - return { - 'value': (float,), - } - - @cached_property - def discriminator(): - return None - - - attribute_map = {} - - _composed_schemas = None - - required_properties = set([ - '_data_store', - '_check_type', - '_spec_property_naming', - '_path_to_item', - '_configuration', - '_visited_composed_classes', - ]) - - @convert_js_args_to_python_args - def __init__(self, value, *args, **kwargs): - """NumberWithValidationsAndDefault - a model defined in OpenAPI - - Args: - value (float): if omitted the server will use the default value of 15.0 # 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 True - _path_to_item (tuple/list): This is a list of keys or values to - drill down to the model in received_data - when deserializing a response - _spec_property_naming (bool): True if the variable names in the input data - are serialized names, as specified in the OpenAPI document. - False if the variable names in the input data - are pythonic names, e.g. snake case (default) - _configuration (Configuration): the instance to use when - deserializing a file_type parameter. - If passed, type conversion is attempted - If omitted no type conversion is done. - _visited_composed_classes (tuple): This stores a tuple of - classes that we have traveled through so that - if we see that class again we will not use its - discriminator again. - When traveling through a discriminator, the - composed schema that is - is traveled through is added to this set. - For example if Animal has a discriminator - petType and we pass in "Dog", and the class Dog - allOf includes Animal, we move through Animal - once using the discriminator, and pick Dog. - Then in Dog, we will make an instance of the - Animal class but this time we won't travel - through its discriminator because we passed in - _visited_composed_classes = (Animal,) - """ - - _check_type = kwargs.pop('_check_type', True) - _spec_property_naming = kwargs.pop('_spec_property_naming', False) - _path_to_item = kwargs.pop('_path_to_item', ()) - _configuration = kwargs.pop('_configuration', None) - _visited_composed_classes = kwargs.pop('_visited_composed_classes', ()) - - if args: - raise ApiTypeError( - "Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % ( - args, - self.__class__.__name__, - ), - path_to_item=_path_to_item, - valid_classes=(self.__class__,), - ) - - self._data_store = {} - self._check_type = _check_type - self._spec_property_naming = _spec_property_naming - self._path_to_item = _path_to_item - self._configuration = _configuration - self._visited_composed_classes = _visited_composed_classes + (self.__class__,) - self.value = value - if kwargs: - raise ApiTypeError( - "Invalid named arguments=%s passed to %s. Remove those invalid named arguments." % ( - kwargs, - self.__class__.__name__, - ), - path_to_item=_path_to_item, - valid_classes=(self.__class__,), - ) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/__init__.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/__init__.py index 59a6e07d9f90..5f23a67ada11 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/__init__.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/__init__.py @@ -76,7 +76,6 @@ from petstore_api.model.nullable_shape import NullableShape from petstore_api.model.number_only import NumberOnly from petstore_api.model.number_with_validations import NumberWithValidations -from petstore_api.model.number_with_validations_and_default import NumberWithValidationsAndDefault from petstore_api.model.object_model_with_ref_props import ObjectModelWithRefProps from petstore_api.model.order import Order from petstore_api.model.parent_pet import ParentPet From 4ae976ffb00e9c041b5f9a1a6ac3abc581407771 Mon Sep 17 00:00:00 2001 From: Justin Black Date: Sun, 23 Aug 2020 13:18:21 -0700 Subject: [PATCH 11/16] Deletes getSimpleTypeDeclaration --- .../openapitools/codegen/DefaultCodegen.java | 2 +- .../PythonClientExperimentalCodegen.java | 100 +++++++----------- 2 files changed, 39 insertions(+), 63 deletions(-) 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 55317d61e4f8..1e3a8b53e83a 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 @@ -5814,7 +5814,7 @@ public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set return codegenParameter; } - private void addBodyModelSchema(CodegenParameter codegenParameter, String name, Schema schema, Set imports, String bodyParameterName, boolean forceSimpleRef) { + protected void addBodyModelSchema(CodegenParameter codegenParameter, String name, Schema schema, Set imports, String bodyParameterName, boolean forceSimpleRef) { CodegenModel codegenModel = null; if (StringUtils.isNotBlank(name)) { schema.setName(name); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java index af3c9fcf265e..5d5239f13a14 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java @@ -535,13 +535,42 @@ public CodegenParameter fromRequestBody(RequestBody body, Set imports, S return cp; } - /** - * Return the sanitized variable name for enum + /*** + * Adds the body model schema to the body parameter + * We have a custom version of this method so we can flip forceSimpleRef + * to True based upon the results of unaliasSchema + * With this customization, we ensure that when schemas are passed to getSchemaType + * - if they have ref in them they are a model + * - if they do not have ref in them they are not a model * - * @param value enum variable name - * @param datatype data type - * @return the sanitized variable name for enum + * @param codegenParameter the body parameter + * @param name model schema ref key in components + * @param schema the model schema (not refed) + * @param imports collection of imports + * @param bodyParameterName body parameter name + * @param forceSimpleRef if true use a model reference */ + @Override + protected void addBodyModelSchema(CodegenParameter codegenParameter, String name, Schema schema, Set imports, String bodyParameterName, boolean forceSimpleRef) { + if (name != null) { + Schema bodySchema = new Schema().$ref("#/components/schemas/" + name); + Schema unaliased = unaliasSchema(bodySchema, importMapping); + if (unaliased.get$ref() != null) { + forceSimpleRef = true; + } + } + super.addBodyModelSchema(codegenParameter, name, schema, imports, bodyParameterName, forceSimpleRef); + + } + + + /** + * Return the sanitized variable name for enum + * + * @param value enum variable name + * @param datatype data type + * @return the sanitized variable name for enum + */ public String toEnumVarName(String value, String datatype) { // our enum var names are keys in a python dict, so change spaces to underscores if (value.length() == 0) { @@ -707,10 +736,7 @@ public CodegenModel fromModel(String name, Schema sc) { } /** - * returns the OpenAPI type for the property. Use getAlias to handle $ref of primitive type - * We have a custom version of this function because for composed schemas we also want to return the model name - * In DefaultCodegen.java it returns a name built off of individual allOf/anyOf/oneOf which is not what - * python-experimental needs. Python-experimental needs the name of the composed schema + * Returns the python type for the property. * * @param schema property schema * @return string presentation of the type @@ -718,48 +744,12 @@ public CodegenModel fromModel(String name, Schema sc) { @SuppressWarnings("static-method") @Override public String getSchemaType(Schema schema) { - if (schema instanceof ComposedSchema) { // composed schema - Schema unaliasSchema = unaliasSchema(schema, importMapping); - String ref = unaliasSchema.get$ref(); - if (ref != null) { - String schemaName = ModelUtils.getSimpleRef(unaliasSchema.get$ref()); - if (StringUtils.isNotEmpty(schemaName) && importMapping.containsKey(schemaName)) { - return schemaName; - } - return getAlias(schemaName); - } else { - // TODO remove this once I remove all the variable setting that uses it - // we may have be processing the component schema rather than a schema with a $ref - // to a component schema - // so loop through component schemas and use the found one's name if we match - Map schemas = ModelUtils.getSchemas(openAPI); - for (String thisSchemaName : schemas.keySet()) { - Schema thisSchema = schemas.get(thisSchemaName); - if (!ModelUtils.isComposedSchema(thisSchema)) { - continue; - } - if (thisSchema == unaliasSchema) { - if (importMapping.containsKey(thisSchemaName)) { - return thisSchemaName; - } - return getAlias(thisSchemaName); - } - } - LOGGER.warn("Error obtaining the datatype from ref:" + unaliasSchema.get$ref() + ". Default to 'object'"); - return "object"; - } - } - // TODO update this to use only getSingleSchemaType String openAPIType = getSingleSchemaType(schema); if (typeMapping.containsKey(openAPIType)) { String type = typeMapping.get(openAPIType); - if (languageSpecificPrimitives.contains(type)) { - return type; - } - } else { - return toModelName(openAPIType); + return type; } - return openAPIType; + return toModelName(openAPIType); } public String getModelName(Schema sc) { @@ -774,20 +764,6 @@ public String getModelName(Schema sc) { return null; } - /** - * 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 Boolean hasValidation(Schema s) { return ( s.getMaxItems() != null || @@ -890,7 +866,7 @@ private String getTypeString(Schema p, String prefix, String suffix, List Date: Sun, 23 Aug 2020 13:19:57 -0700 Subject: [PATCH 12/16] Removes straggler file --- ...est_number_with_validations_and_default.py | 37 ------------------- 1 file changed, 37 deletions(-) delete mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_number_with_validations_and_default.py diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_number_with_validations_and_default.py b/samples/openapi3/client/petstore/python-experimental/test/test_number_with_validations_and_default.py deleted file mode 100644 index e643747406ae..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/test/test_number_with_validations_and_default.py +++ /dev/null @@ -1,37 +0,0 @@ -# coding: utf-8 - -""" - OpenAPI Petstore - - This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 - - The version of the OpenAPI document: 1.0.0 - Generated by: https://openapi-generator.tech -""" - - -import sys -import unittest - -import petstore_api -from petstore_api.model.number_with_validations_and_default import NumberWithValidationsAndDefault - - -class TestNumberWithValidationsAndDefault(unittest.TestCase): - """NumberWithValidationsAndDefault unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def testNumberWithValidationsAndDefault(self): - """Test NumberWithValidationsAndDefault""" - # FIXME: construct object with mandatory attributes with example values - # model = NumberWithValidationsAndDefault() # noqa: E501 - pass - - -if __name__ == '__main__': - unittest.main() From d9cba14d139b0b0043dd4f348be917a939cb0443 Mon Sep 17 00:00:00 2001 From: Justin Black Date: Sun, 23 Aug 2020 14:13:00 -0700 Subject: [PATCH 13/16] Deletes hasValidation and modelWillBeMade --- .../PythonClientExperimentalCodegen.java | 79 +++++++------------ 1 file changed, 27 insertions(+), 52 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java index 5d5239f13a14..4a70ffd4b54a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java @@ -238,6 +238,19 @@ protected Schema unaliasSchema(Schema schema, Map usedImportMapp return schema; } Schema ref = allSchemas.get(simpleRef); + Boolean hasValidation = ( + ref.getMaxItems() != null || + ref.getMinLength() != null || + ref.getMinItems() != null || + ref.getMultipleOf() != null || + ref.getPattern() != null || + ref.getMaxLength() != null || + ref.getMinimum() != null || + ref.getMaximum() != null || + ref.getExclusiveMaximum() != null || + ref.getExclusiveMinimum() != null || + ref.getUniqueItems() != null + ); if (ref == null) { once(LOGGER).warn("{} is not defined", schema.get$ref()); return schema; @@ -272,7 +285,7 @@ protected Schema unaliasSchema(Schema schema, Map usedImportMapp return unaliasSchema(allSchemas.get(ModelUtils.getSimpleRef(schema.get$ref())), usedImportMappings); } - } else if (hasValidation(ref)) { + } else if (hasValidation) { // non object non array non map schemas that have validations // are returned so we can generate those schemas as models // we do this to: @@ -753,48 +766,15 @@ public String getSchemaType(Schema schema) { } public String getModelName(Schema sc) { - Boolean thisModelWillBeMade = modelWillBeMade(sc); - Map schemas = ModelUtils.getSchemas(openAPI); - for (String thisSchemaName : schemas.keySet()) { - Schema thisSchema = schemas.get(thisSchemaName); - if (thisSchema == sc && thisModelWillBeMade) { - return toModelName(thisSchemaName); + if (sc.get$ref() != null) { + Schema unaliasedSchema = unaliasSchema(sc, importMapping); + if (unaliasedSchema.get$ref() != null) { + return toModelName(ModelUtils.getSimpleRef(sc.get$ref())); } } return null; } - public Boolean hasValidation(Schema s) { - return ( - s.getMaxItems() != null || - s.getMinLength() != null || - s.getMinItems() != null || - s.getMultipleOf() != null || - s.getPattern() != null || - s.getMaxLength() != null || - s.getMinimum() != null || - s.getMaximum() != null || - s.getExclusiveMaximum() != null || - s.getExclusiveMinimum() != null || - s.getUniqueItems() != null - ); - } - - public Boolean modelWillBeMade(Schema s) { - // only invoke this on $refed schemas - if (ModelUtils.isComposedSchema(s) || ModelUtils.isObjectSchema(s) || ModelUtils.isArraySchema(s) || ModelUtils.isMapSchema(s)) { - return true; - } - List enums = s.getEnum(); - if (enums != null && !enums.isEmpty()) { - return true; - } - if (hasValidation(s)) { - return true; - } - return false; - } - /** * Return a string representation of the Python types for the specified OAS schema. * Primitive types in the OAS specification are implemented in Python using the corresponding @@ -824,8 +804,8 @@ private String getTypeString(Schema p, String prefix, String suffix, List allDefinitions = ModelUtils.getSchemas(this.openAPI); String ref = ModelUtils.getSimpleRef(schema.get$ref()); - if (allDefinitions != null) { - Schema refSchema = allDefinitions.get(ref); - if (null == refSchema) { - return fullPrefix + "None" + closeChars; - } else { - String refModelName = getModelName(refSchema); - return toExampleValueRecursive(refModelName, refSchema, objExample, indentationLevel, prefix, exampleLine); - } - } else { - LOGGER.warn("allDefinitions not defined in toExampleValue!\n"); + Schema refSchema = allDefinitions.get(ref); + if (null == refSchema) { + LOGGER.warn("Unable to find referenced schema "+schema.get$ref()+"\n"); + return fullPrefix + "None" + closeChars; } + String refModelName = getModelName(schema); + return toExampleValueRecursive(refModelName, refSchema, objExample, indentationLevel, prefix, exampleLine); } else if (ModelUtils.isNullType(schema) || isAnyTypeSchema(schema)) { // The 'null' type is allowed in OAS 3.1 and above. It is not supported by OAS 3.0.x, // though this tooling supports it. From 8b0d4ab3d9cd4115413bfaf5603dbcb1a07849fb Mon Sep 17 00:00:00 2001 From: Justin Black Date: Sun, 23 Aug 2020 14:28:08 -0700 Subject: [PATCH 14/16] Uses super in fromFormProperty --- .../PythonClientExperimentalCodegen.java | 88 +------------------ 1 file changed, 4 insertions(+), 84 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java index 4a70ffd4b54a..3e952db62c67 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java @@ -1325,92 +1325,12 @@ public void setParameterExampleValue(CodegenParameter codegenParameter, RequestB */ @Override public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set imports) { - CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER); - - LOGGER.debug("Debugging fromFormProperty {}: {}", name, propertySchema); - CodegenProperty codegenProperty = fromProperty(name, propertySchema); - - ModelUtils.syncValidationProperties(propertySchema, codegenProperty); - - codegenParameter.isFormParam = Boolean.TRUE; - codegenParameter.baseName = codegenProperty.baseName; - codegenParameter.paramName = toParamName((codegenParameter.baseName)); - codegenParameter.baseType = codegenProperty.baseType; - codegenParameter.dataType = codegenProperty.dataType; - codegenParameter.dataFormat = codegenProperty.dataFormat; - codegenParameter.description = escapeText(codegenProperty.description); - codegenParameter.unescapedDescription = codegenProperty.getDescription(); - codegenParameter.jsonSchema = Json.pretty(propertySchema); - codegenParameter.defaultValue = codegenProperty.getDefaultValue(); - - if (codegenProperty.getVendorExtensions() != null && !codegenProperty.getVendorExtensions().isEmpty()) { - codegenParameter.vendorExtensions = codegenProperty.getVendorExtensions(); - } - if (propertySchema.getRequired() != null && !propertySchema.getRequired().isEmpty() && propertySchema.getRequired().contains(codegenProperty.baseName)) { - codegenParameter.required = Boolean.TRUE; - } - - // non-array/map - updateCodegenPropertyEnum(codegenProperty); - codegenParameter.isEnum = codegenProperty.isEnum; - codegenParameter._enum = codegenProperty._enum; - codegenParameter.allowableValues = codegenProperty.allowableValues; - - if (codegenProperty.isEnum) { - codegenParameter.datatypeWithEnum = codegenProperty.datatypeWithEnum; - codegenParameter.enumName = codegenProperty.enumName; - } - - if (codegenProperty.items != null && codegenProperty.items.isEnum) { - codegenParameter.items = codegenProperty.items; - codegenParameter.mostInnerItems = codegenProperty.mostInnerItems; - } - - // import - if (codegenProperty.complexType != null) { - imports.add(codegenProperty.complexType); - } - - // validation - // handle maximum, minimum properly for int/long by removing the trailing ".0" - if (ModelUtils.isIntegerSchema(propertySchema)) { - codegenParameter.maximum = propertySchema.getMaximum() == null ? null : String.valueOf(propertySchema.getMaximum().longValue()); - codegenParameter.minimum = propertySchema.getMinimum() == null ? null : String.valueOf(propertySchema.getMinimum().longValue()); - } else { - codegenParameter.maximum = propertySchema.getMaximum() == null ? null : String.valueOf(propertySchema.getMaximum()); - codegenParameter.minimum = propertySchema.getMinimum() == null ? null : String.valueOf(propertySchema.getMinimum()); - } - - codegenParameter.exclusiveMaximum = propertySchema.getExclusiveMaximum() == null ? false : propertySchema.getExclusiveMaximum(); - codegenParameter.exclusiveMinimum = propertySchema.getExclusiveMinimum() == null ? false : propertySchema.getExclusiveMinimum(); - codegenParameter.maxLength = propertySchema.getMaxLength(); - codegenParameter.minLength = propertySchema.getMinLength(); - codegenParameter.pattern = toRegularExpression(propertySchema.getPattern()); - codegenParameter.maxItems = propertySchema.getMaxItems(); - codegenParameter.minItems = propertySchema.getMinItems(); - codegenParameter.uniqueItems = propertySchema.getUniqueItems() == null ? false : propertySchema.getUniqueItems(); - codegenParameter.multipleOf = propertySchema.getMultipleOf(); - - // exclusive* are noop without corresponding min/max - if (codegenParameter.maximum != null || codegenParameter.minimum != null || - codegenParameter.maxLength != null || codegenParameter.minLength != null || - codegenParameter.maxItems != null || codegenParameter.minItems != null || - codegenParameter.pattern != null || codegenParameter.multipleOf != null) { - codegenParameter.hasValidation = true; - } - - setParameterBooleanFlagWithCodegenProperty(codegenParameter, codegenProperty); + CodegenParameter cp = super.fromFormProperty(name, propertySchema, imports); Parameter p = new Parameter(); p.setSchema(propertySchema); - p.setName(codegenParameter.paramName); - setParameterExampleValue(codegenParameter, p); - // setParameterExampleValue(codegenParameter); - // set nullable - setParameterNullable(codegenParameter, codegenProperty); - - //TODO collectionFormat for form parameter not yet supported - //codegenParameter.collectionFormat = getCollectionFormat(propertySchema); - return codegenParameter; + p.setName(cp.paramName); + setParameterExampleValue(cp, p); + return cp; } /** From a3831d8ccc865bca7972ecd02104ec0c82f60a6a Mon Sep 17 00:00:00 2001 From: Justin Black Date: Sun, 23 Aug 2020 14:37:18 -0700 Subject: [PATCH 15/16] Regenerates samples for python-experimental --- .../petstore/python-experimental/.openapi-generator/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/openapi3/client/petstore/python-experimental/.openapi-generator/VERSION b/samples/openapi3/client/petstore/python-experimental/.openapi-generator/VERSION index 717311e32e3c..d99e7162d01f 100644 --- a/samples/openapi3/client/petstore/python-experimental/.openapi-generator/VERSION +++ b/samples/openapi3/client/petstore/python-experimental/.openapi-generator/VERSION @@ -1 +1 @@ -unset \ No newline at end of file +5.0.0-SNAPSHOT \ No newline at end of file From b17f1c2a0fbf2afc9294e9ae09662bff71087d61 Mon Sep 17 00:00:00 2001 From: Justin Black Date: Sun, 23 Aug 2020 15:27:27 -0700 Subject: [PATCH 16/16] Updates postProcessAllModels --- .../PythonClientExperimentalCodegen.java | 66 +++++++++---------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java index 3e952db62c67..f156a44e6e99 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java @@ -403,52 +403,50 @@ public Map postProcessOperationsWithModels(Map o return objs; } - /** + /*** * Override with special post-processing for all models. + * we have a custom version of this method to: + * - remove any primitive models that do not contain validations + * these models are unaliased as inline definitions wherever the spec has them as refs + * this means that the generated client does not use these models + * because they are not used we do not write them + * - fix the model imports, go from model name to the full import string with toModelImport + globalImportFixer + * + * @param objs a map going from the model name to a object hoding the model info + * @return the updated objs */ - @SuppressWarnings({"static-method", "unchecked"}) + @Override public Map postProcessAllModels(Map objs) { super.postProcessAllModels(objs); - // loop through all models and delete ones where type!=object and the model has no validations and enums - // we will remove them because they are not needed - Map modelSchemasToRemove = new HashMap(); - - for (Object objModel: objs.values()) { - HashMap hmModel = (HashMap) objModel; - List> models = (List>) hmModel.get("models"); - for (Map model : models) { - CodegenModel cm = (CodegenModel) model.get("model"); - - // remove model if it is a primitive with no validations - if (cm.isEnum || cm.isAlias) { - Schema modelSchema = ModelUtils.getSchema(this.openAPI, cm.name); - CodegenProperty modelProperty = fromProperty("_value", modelSchema); - if (!modelProperty.isEnum && !modelProperty.hasValidation && !cm.isArrayModel) { - // remove these models because they are aliases and do not have any enums or validations - modelSchemasToRemove.put(cm.name, modelSchema); - continue; + List modelsToRemove = new ArrayList<>(); + Map allDefinitions = ModelUtils.getSchemas(this.openAPI); + for (String schemaName: allDefinitions.keySet()) { + Schema refSchema = new Schema().$ref("#/components/schemas/"+schemaName); + Schema unaliasedSchema = unaliasSchema(refSchema, importMapping); + String modelName = toModelName(schemaName); + if (unaliasedSchema.get$ref() == null) { + modelsToRemove.add(modelName); + } else { + HashMap objModel = (HashMap) objs.get(modelName); + List> models = (List>) objModel.get("models"); + for (Map model : models) { + CodegenModel cm = (CodegenModel) model.get("model"); + String[] importModelNames = cm.imports.toArray(new String[0]); + cm.imports.clear(); + for (String importModelName : importModelNames) { + cm.imports.add(toModelImport(importModelName)); + String globalImportFixer = "globals()['" + importModelName + "'] = " + importModelName; + cm.imports.add(globalImportFixer); } } - - // fix model imports - if (cm.imports.size() == 0) { - continue; - } - String[] modelNames = cm.imports.toArray(new String[0]); - cm.imports.clear(); - for (String modelName : modelNames) { - cm.imports.add(toModelImport(modelName)); - String globalImportFixer = "globals()['" + modelName + "'] = " + modelName; - cm.imports.add(globalImportFixer); - } } } - // Remove modelSchemasToRemove models from objs - for (String modelName : modelSchemasToRemove.keySet()) { + for (String modelName : modelsToRemove) { objs.remove(modelName); } + return objs; }