From c43c1708891aa2e46721de6f31bc230a6716c3b6 Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Fri, 29 May 2020 18:32:22 +0200 Subject: [PATCH 01/18] [python] Support named arrays --- ...odels-for-testing-with-http-signature.yaml | 19 +++- .../petstore/python-experimental/README.md | 1 + .../python-experimental/docs/FakeApi.md | 57 ++++++++++ .../petstore_api/api/fake_api.py | 104 ++++++++++++++++++ 4 files changed, 180 insertions(+), 1 deletion(-) 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 6fb6d09416e0..9b863d75a53a 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 @@ -1097,6 +1097,19 @@ paths: application/json: schema: $ref: '#/components/schemas/HealthCheckResult' + /fake/array-of-enums: + get: + tags: + - fake + summary: Array of Enums + operationId: getArrayOfEnums + responses: + 200: + description: Got named array of enums + content: + application/json: + schema: + $ref: '#/components/schemas/ArrayOfEnums' servers: - url: 'http://{server}.swagger.io:{port}/v2' description: petstore server @@ -1443,7 +1456,7 @@ components: maximum: 543.2 minimum: 32.1 type: number - multipleOf: 32.5 + multipleOf: 32.5 float: type: number format: float @@ -1703,6 +1716,10 @@ components: - placed - approved - delivered + ArrayOfEnums: + type: array + items: + $ref: '#/components/schemas/OuterEnum' OuterEnumInteger: type: integer enum: diff --git a/samples/openapi3/client/petstore/python-experimental/README.md b/samples/openapi3/client/petstore/python-experimental/README.md index 9827e98d2a13..4fb05b933539 100644 --- a/samples/openapi3/client/petstore/python-experimental/README.md +++ b/samples/openapi3/client/petstore/python-experimental/README.md @@ -87,6 +87,7 @@ Class | Method | HTTP request | Description *FakeApi* | [**fake_outer_composite_serialize**](docs/FakeApi.md#fake_outer_composite_serialize) | **POST** /fake/outer/composite | *FakeApi* | [**fake_outer_number_serialize**](docs/FakeApi.md#fake_outer_number_serialize) | **POST** /fake/outer/number | *FakeApi* | [**fake_outer_string_serialize**](docs/FakeApi.md#fake_outer_string_serialize) | **POST** /fake/outer/string | +*FakeApi* | [**get_array_of_enums**](docs/FakeApi.md#get_array_of_enums) | **GET** /fake/array-of-enums | Array of Enums *FakeApi* | [**test_body_with_file_schema**](docs/FakeApi.md#test_body_with_file_schema) | **PUT** /fake/body-with-file-schema | *FakeApi* | [**test_body_with_query_params**](docs/FakeApi.md#test_body_with_query_params) | **PUT** /fake/body-with-query-params | *FakeApi* | [**test_client_model**](docs/FakeApi.md#test_client_model) | **PATCH** /fake | To test \"client\" model diff --git a/samples/openapi3/client/petstore/python-experimental/docs/FakeApi.md b/samples/openapi3/client/petstore/python-experimental/docs/FakeApi.md index a31649db9aaf..6ae3d3fd7229 100644 --- a/samples/openapi3/client/petstore/python-experimental/docs/FakeApi.md +++ b/samples/openapi3/client/petstore/python-experimental/docs/FakeApi.md @@ -9,6 +9,7 @@ Method | HTTP request | Description [**fake_outer_composite_serialize**](FakeApi.md#fake_outer_composite_serialize) | **POST** /fake/outer/composite | [**fake_outer_number_serialize**](FakeApi.md#fake_outer_number_serialize) | **POST** /fake/outer/number | [**fake_outer_string_serialize**](FakeApi.md#fake_outer_string_serialize) | **POST** /fake/outer/string | +[**get_array_of_enums**](FakeApi.md#get_array_of_enums) | **GET** /fake/array-of-enums | Array of Enums [**test_body_with_file_schema**](FakeApi.md#test_body_with_file_schema) | **PUT** /fake/body-with-file-schema | [**test_body_with_query_params**](FakeApi.md#test_body_with_query_params) | **PUT** /fake/body-with-query-params | [**test_client_model**](FakeApi.md#test_client_model) | **PATCH** /fake | To test \"client\" model @@ -324,6 +325,62 @@ No authorization required [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) +# **get_array_of_enums** +> array_of_enums.ArrayOfEnums get_array_of_enums() + +Array of Enums + +### Example + +```python +from __future__ import print_function +import time +import petstore_api +from pprint import pprint +# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2 +# See configuration.py for a list of all supported configuration parameters. +configuration = petstore_api.Configuration( + host = "http://petstore.swagger.io:80/v2" +) + + +# Enter a context with an instance of the API client +with petstore_api.ApiClient() as api_client: + # Create an instance of the API class + api_instance = petstore_api.FakeApi(api_client) + + # example, this endpoint has no required or optional parameters + try: + # Array of Enums + api_response = api_instance.get_array_of_enums() + pprint(api_response) + except petstore_api.ApiException as e: + print("Exception when calling FakeApi->get_array_of_enums: %s\n" % e) +``` + +### Parameters +This endpoint does not need any parameter. + +### Return type + +[**array_of_enums.ArrayOfEnums**](ArrayOfEnums.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +**200** | Got named array of enums | - | + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + # **test_body_with_file_schema** > test_body_with_file_schema(file_schema_test_class_file_schema_test_class) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api.py index fd5096ba6de1..b688356ada64 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api.py @@ -36,6 +36,7 @@ ) from petstore_api.models import health_check_result from petstore_api.models import outer_composite +from petstore_api.models import array_of_enums from petstore_api.models import file_schema_test_class from petstore_api.models import user from petstore_api.models import client @@ -600,6 +601,109 @@ def __fake_outer_string_serialize( callable=__fake_outer_string_serialize ) + def __get_array_of_enums( + self, + **kwargs + ): + """Array of Enums # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.get_array_of_enums(async_req=True) + >>> result = thread.get() + + + Keyword Args: + _return_http_data_only (bool): response data without head status + code and headers. Default is True. + _preload_content (bool): if False, the urllib3.HTTPResponse object + will be returned without reading/decoding response data. + Default is True. + _request_timeout (float/tuple): timeout setting for this request. If one + number provided, it will be total request timeout. It can also + be a pair (tuple) of (connection, read) timeouts. + Default is None. + _check_input_type (bool): specifies if type checking + should be done one the data sent to the server. + Default is True. + _check_return_type (bool): specifies if type checking + should be done one the data received from the server. + Default is True. + _host_index (int): specifies the index of the server + that we want to use. + Default is 0. + async_req (bool): execute request asynchronously + + Returns: + array_of_enums.ArrayOfEnums + If the method is called asynchronously, returns the request + thread. + """ + kwargs['async_req'] = kwargs.get( + 'async_req', False + ) + kwargs['_return_http_data_only'] = kwargs.get( + '_return_http_data_only', True + ) + kwargs['_preload_content'] = kwargs.get( + '_preload_content', True + ) + kwargs['_request_timeout'] = kwargs.get( + '_request_timeout', None + ) + kwargs['_check_input_type'] = kwargs.get( + '_check_input_type', True + ) + kwargs['_check_return_type'] = kwargs.get( + '_check_return_type', True + ) + kwargs['_host_index'] = kwargs.get('_host_index', 0) + return self.call_with_http_info(**kwargs) + + self.get_array_of_enums = Endpoint( + settings={ + 'response_type': (array_of_enums.ArrayOfEnums,), + 'auth': [], + 'endpoint_path': '/fake/array-of-enums', + 'operation_id': 'get_array_of_enums', + 'http_method': 'GET', + 'servers': [], + }, + params_map={ + 'all': [ + ], + 'required': [], + 'nullable': [ + ], + 'enum': [ + ], + 'validation': [ + ] + }, + root_map={ + 'validations': { + }, + 'allowed_values': { + }, + 'openapi_types': { + }, + 'attribute_map': { + }, + 'location_map': { + }, + 'collection_format_map': { + } + }, + headers_map={ + 'accept': [ + 'application/json' + ], + 'content_type': [], + }, + api_client=api_client, + callable=__get_array_of_enums + ) + def __test_body_with_file_schema( self, file_schema_test_class_file_schema_test_class, From b8a1a37570afc48c1b172db77e3f1a7955c4fc8e Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Mon, 1 Jun 2020 20:04:18 +0200 Subject: [PATCH 02/18] Fix named array type --- .../PythonClientExperimentalCodegen.java | 13 +- ...odels-for-testing-with-http-signature.yaml | 16 +- .../.openapi-generator/FILES | 6 + .../petstore/python-experimental/README.md | 3 +- .../python-experimental/docs/AnimalFarm.md | 9 + .../python-experimental/docs/FakeApi.md | 59 --- .../python-experimental/docs/FarmApi.md | 67 ++++ .../petstore_api/api/__init__.py | 1 + .../petstore_api/api/fake_api.py | 104 ----- .../petstore_api/api/farm_api.py | 373 ++++++++++++++++++ .../petstore_api/apis/__init__.py | 1 + .../petstore_api/model/animal_farm.py | 175 ++++++++ .../petstore_api/models/__init__.py | 1 + .../test/test_animal_farm.py | 43 ++ .../python-experimental/test/test_drawing.py | 133 +------ .../python-experimental/test/test_farm_api.py | 39 ++ .../python-experimental/test/test_fruit.py | 180 +-------- .../test/test_fruit_req.py | 138 +------ .../python-experimental/test/test_gm_fruit.py | 189 +-------- .../python-experimental/test/test_mammal.py | 13 +- .../test/test_outer_enum.py | 13 +- .../test/test_parent_pet.py | 9 +- .../test/test_quadrilateral.py | 7 +- .../python-experimental/test/test_shape.py | 67 +--- .../python-experimental/test/test_tag.py | 2 +- .../python-experimental/test/test_triangle.py | 9 +- 26 files changed, 772 insertions(+), 898 deletions(-) create mode 100644 samples/openapi3/client/petstore/python-experimental/docs/AnimalFarm.md create mode 100644 samples/openapi3/client/petstore/python-experimental/docs/FarmApi.md create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/api/farm_api.py create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/animal_farm.py create mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_animal_farm.py create mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_farm_api.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 384960012385..b034d16a2e12 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 @@ -377,7 +377,7 @@ private void fixModelImports(Set imports) { /** * Override with special post-processing for all models. - */ + */ @SuppressWarnings({"static-method", "unchecked"}) public Map postProcessAllModels(Map objs) { // loop through all models and delete ones where type!=object and the model has no validations and enums @@ -417,14 +417,13 @@ public Map postProcessAllModels(Map objs) { Schema modelSchema = ModelUtils.getSchema(this.openAPI, cm.name); CodegenProperty modelProperty = fromProperty("value", modelSchema); + + LOGGER.warn("schema: {}\ncm.isEnum = {}\ncm.isAlias = {}\ncm.isArrayModel = {} && modelProperty.isEnum = {} && modelProperty.hasValidation = {}\n{}", cm.name, cm.isEnum, cm.isAlias, cm.isArrayModel, modelProperty.isEnum, modelProperty.hasValidation, cm.arrayModelType); if (cm.isEnum || cm.isAlias) { if (!modelProperty.isEnum && !modelProperty.hasValidation) { // remove these models because they are aliases and do not have any enums or validations modelSchemasToRemove.put(cm.name, modelSchema); } - } else if (cm.isArrayModel && !modelProperty.isEnum && !modelProperty.hasValidation) { - // remove any ArrayModels which lack validation and enums - modelSchemasToRemove.put(cm.name, modelSchema); } } } @@ -905,7 +904,7 @@ public String getSimpleTypeDeclaration(Schema schema) { * Primitive types in the OAS specification are implemented in Python using the corresponding * Python primitive types. * Composed types (e.g. allAll, oneOf, anyOf) are represented in Python using list of types. - * + * * The caller should set the prefix and suffix arguments to empty string, except when * getTypeString invokes itself recursively. A non-empty prefix/suffix may be specified * to wrap the return value in a python dict, list or tuple. @@ -913,7 +912,7 @@ public String getSimpleTypeDeclaration(Schema schema) { * Examples: * - "bool, date, float" The data must be a bool, date or float. * - "[bool, date]" The data must be an array, and the array items must be a bool or date. - * + * * @param p The OAS schema. * @param prefix prepended to the returned value. * @param suffix appended to the returned value. @@ -968,7 +967,7 @@ private String getTypeString(Schema p, String prefix, String suffix, List array_of_enums.ArrayOfEnums get_array_of_enums() - -Array of Enums - -### Example - -```python -from __future__ import print_function -import time -import petstore_api -from petstore_api.api import fake_api -from petstore_api.model import array_of_enums -from pprint import pprint -# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2 -# See configuration.py for a list of all supported configuration parameters. -configuration = petstore_api.Configuration( - host = "http://petstore.swagger.io:80/v2" -) - - -# Enter a context with an instance of the API client -with petstore_api.ApiClient() as api_client: - # Create an instance of the API class - api_instance = fake_api.FakeApi(api_client) - - # example, this endpoint has no required or optional parameters - try: - # Array of Enums - api_response = api_instance.get_array_of_enums() - pprint(api_response) - except petstore_api.ApiException as e: - print("Exception when calling FakeApi->get_array_of_enums: %s\n" % e) -``` - -### Parameters -This endpoint does not need any parameter. - -### Return type - -[**array_of_enums.ArrayOfEnums**](ArrayOfEnums.md) - -### Authorization - -No authorization required - -### HTTP request headers - - - **Content-Type**: Not defined - - **Accept**: application/json - -### HTTP response details -| Status code | Description | Response headers | -|-------------|-------------|------------------| -**200** | Got named array of enums | - | - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) - # **test_body_with_file_schema** > test_body_with_file_schema(file_schema_test_class_file_schema_test_class) diff --git a/samples/openapi3/client/petstore/python-experimental/docs/FarmApi.md b/samples/openapi3/client/petstore/python-experimental/docs/FarmApi.md new file mode 100644 index 000000000000..1367cf06f7a1 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/docs/FarmApi.md @@ -0,0 +1,67 @@ +# petstore_api.FarmApi + +All URIs are relative to *http://petstore.swagger.io:80/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**farm**](FarmApi.md#farm) | **GET** /farm/animals | Animal Farm + + +# **farm** +> animal_farm.AnimalFarm farm() + +Animal Farm + +### Example + +```python +from __future__ import print_function +import time +import petstore_api +from petstore_api.api import farm_api +from petstore_api.model import animal_farm +from pprint import pprint +# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2 +# See configuration.py for a list of all supported configuration parameters. +configuration = petstore_api.Configuration( + host = "http://petstore.swagger.io:80/v2" +) + + +# Enter a context with an instance of the API client +with petstore_api.ApiClient() as api_client: + # Create an instance of the API class + api_instance = farm_api.FarmApi(api_client) + + # example, this endpoint has no required or optional parameters + try: + # Animal Farm + api_response = api_instance.farm() + pprint(api_response) + except petstore_api.ApiException as e: + print("Exception when calling FarmApi->farm: %s\n" % e) +``` + +### Parameters +This endpoint does not need any parameter. + +### Return type + +[**animal_farm.AnimalFarm**](AnimalFarm.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +**200** | Got named array of enums | - | + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/__init__.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/__init__.py index fa4e54a80091..1d2f2d52b4fd 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/__init__.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/__init__.py @@ -7,6 +7,7 @@ from petstore_api.api.default_api import DefaultApi from petstore_api.api.fake_api import FakeApi from petstore_api.api.fake_classname_tags_123_api import FakeClassnameTags123Api +from petstore_api.api.farm_api import FarmApi from petstore_api.api.pet_api import PetApi from petstore_api.api.store_api import StoreApi from petstore_api.api.user_api import UserApi diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api.py index 3c5de6178be2..69531b0525fa 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api.py @@ -36,7 +36,6 @@ ) from petstore_api.model import health_check_result from petstore_api.model import outer_composite -from petstore_api.model import array_of_enums from petstore_api.model import file_schema_test_class from petstore_api.model import user from petstore_api.model import client @@ -601,109 +600,6 @@ def __fake_outer_string_serialize( callable=__fake_outer_string_serialize ) - def __get_array_of_enums( - self, - **kwargs - ): - """Array of Enums # noqa: E501 - - This method makes a synchronous HTTP request by default. To make an - asynchronous HTTP request, please pass async_req=True - >>> thread = api.get_array_of_enums(async_req=True) - >>> result = thread.get() - - - Keyword Args: - _return_http_data_only (bool): response data without head status - code and headers. Default is True. - _preload_content (bool): if False, the urllib3.HTTPResponse object - will be returned without reading/decoding response data. - Default is True. - _request_timeout (float/tuple): timeout setting for this request. If one - number provided, it will be total request timeout. It can also - be a pair (tuple) of (connection, read) timeouts. - Default is None. - _check_input_type (bool): specifies if type checking - should be done one the data sent to the server. - Default is True. - _check_return_type (bool): specifies if type checking - should be done one the data received from the server. - Default is True. - _host_index (int): specifies the index of the server - that we want to use. - Default is 0. - async_req (bool): execute request asynchronously - - Returns: - array_of_enums.ArrayOfEnums - If the method is called asynchronously, returns the request - thread. - """ - kwargs['async_req'] = kwargs.get( - 'async_req', False - ) - kwargs['_return_http_data_only'] = kwargs.get( - '_return_http_data_only', True - ) - kwargs['_preload_content'] = kwargs.get( - '_preload_content', True - ) - kwargs['_request_timeout'] = kwargs.get( - '_request_timeout', None - ) - kwargs['_check_input_type'] = kwargs.get( - '_check_input_type', True - ) - kwargs['_check_return_type'] = kwargs.get( - '_check_return_type', True - ) - kwargs['_host_index'] = kwargs.get('_host_index', 0) - return self.call_with_http_info(**kwargs) - - self.get_array_of_enums = Endpoint( - settings={ - 'response_type': (array_of_enums.ArrayOfEnums,), - 'auth': [], - 'endpoint_path': '/fake/array-of-enums', - 'operation_id': 'get_array_of_enums', - 'http_method': 'GET', - 'servers': [], - }, - params_map={ - 'all': [ - ], - 'required': [], - 'nullable': [ - ], - 'enum': [ - ], - 'validation': [ - ] - }, - root_map={ - 'validations': { - }, - 'allowed_values': { - }, - 'openapi_types': { - }, - 'attribute_map': { - }, - 'location_map': { - }, - 'collection_format_map': { - } - }, - headers_map={ - 'accept': [ - 'application/json' - ], - 'content_type': [], - }, - api_client=api_client, - callable=__get_array_of_enums - ) - def __test_body_with_file_schema( self, file_schema_test_class_file_schema_test_class, diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/farm_api.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/farm_api.py new file mode 100644 index 000000000000..0cae63fe3230 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/farm_api.py @@ -0,0 +1,373 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import re # noqa: F401 +import sys # noqa: F401 + +# python 2 and python 3 compatibility library +import six + +from petstore_api.api_client import ApiClient +from petstore_api.exceptions import ( + ApiTypeError, + ApiValueError +) +from petstore_api.model_utils import ( # noqa: F401 + check_allowed_values, + check_validations, + date, + datetime, + file_type, + int, + none_type, + str, + validate_and_convert_types +) +from petstore_api.model import animal_farm + + +class FarmApi(object): + """NOTE: This class is auto generated by OpenAPI Generator + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + def __init__(self, api_client=None): + if api_client is None: + api_client = ApiClient() + self.api_client = api_client + + def __farm( + self, + **kwargs + ): + """Animal Farm # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.farm(async_req=True) + >>> result = thread.get() + + + Keyword Args: + _return_http_data_only (bool): response data without head status + code and headers. Default is True. + _preload_content (bool): if False, the urllib3.HTTPResponse object + will be returned without reading/decoding response data. + Default is True. + _request_timeout (float/tuple): timeout setting for this request. If one + number provided, it will be total request timeout. It can also + be a pair (tuple) of (connection, read) timeouts. + Default is None. + _check_input_type (bool): specifies if type checking + should be done one the data sent to the server. + Default is True. + _check_return_type (bool): specifies if type checking + should be done one the data received from the server. + Default is True. + _host_index (int): specifies the index of the server + that we want to use. + Default is 0. + async_req (bool): execute request asynchronously + + Returns: + animal_farm.AnimalFarm + If the method is called asynchronously, returns the request + thread. + """ + kwargs['async_req'] = kwargs.get( + 'async_req', False + ) + kwargs['_return_http_data_only'] = kwargs.get( + '_return_http_data_only', True + ) + kwargs['_preload_content'] = kwargs.get( + '_preload_content', True + ) + kwargs['_request_timeout'] = kwargs.get( + '_request_timeout', None + ) + kwargs['_check_input_type'] = kwargs.get( + '_check_input_type', True + ) + kwargs['_check_return_type'] = kwargs.get( + '_check_return_type', True + ) + kwargs['_host_index'] = kwargs.get('_host_index', 0) + return self.call_with_http_info(**kwargs) + + self.farm = Endpoint( + settings={ + 'response_type': (animal_farm.AnimalFarm,), + 'auth': [], + 'endpoint_path': '/farm/animals', + 'operation_id': 'farm', + 'http_method': 'GET', + 'servers': [], + }, + params_map={ + 'all': [ + ], + 'required': [], + 'nullable': [ + ], + 'enum': [ + ], + 'validation': [ + ] + }, + root_map={ + 'validations': { + }, + 'allowed_values': { + }, + 'openapi_types': { + }, + 'attribute_map': { + }, + 'location_map': { + }, + 'collection_format_map': { + } + }, + headers_map={ + 'accept': [ + 'application/json' + ], + 'content_type': [], + }, + api_client=api_client, + callable=__farm + ) + + +class Endpoint(object): + def __init__(self, settings=None, params_map=None, root_map=None, + headers_map=None, api_client=None, callable=None): + """Creates an endpoint + + Args: + settings (dict): see below key value pairs + 'response_type' (tuple/None): response type + 'auth' (list): a list of auth type keys + 'endpoint_path' (str): the endpoint path + 'operation_id' (str): endpoint string identifier + 'http_method' (str): POST/PUT/PATCH/GET etc + 'servers' (list): list of str servers that this endpoint is at + params_map (dict): see below key value pairs + 'all' (list): list of str endpoint parameter names + 'required' (list): list of required parameter names + 'nullable' (list): list of nullable parameter names + 'enum' (list): list of parameters with enum values + 'validation' (list): list of parameters with validations + root_map + 'validations' (dict): the dict mapping endpoint parameter tuple + paths to their validation dictionaries + 'allowed_values' (dict): the dict mapping endpoint parameter + tuple paths to their allowed_values (enum) dictionaries + 'openapi_types' (dict): param_name to openapi type + 'attribute_map' (dict): param_name to camelCase name + 'location_map' (dict): param_name to 'body', 'file', 'form', + 'header', 'path', 'query' + collection_format_map (dict): param_name to `csv` etc. + headers_map (dict): see below key value pairs + 'accept' (list): list of Accept header strings + 'content_type' (list): list of Content-Type header strings + api_client (ApiClient) api client instance + callable (function): the function which is invoked when the + Endpoint is called + """ + self.settings = settings + self.params_map = params_map + self.params_map['all'].extend([ + 'async_req', + '_host_index', + '_preload_content', + '_request_timeout', + '_return_http_data_only', + '_check_input_type', + '_check_return_type' + ]) + self.params_map['nullable'].extend(['_request_timeout']) + self.validations = root_map['validations'] + self.allowed_values = root_map['allowed_values'] + self.openapi_types = root_map['openapi_types'] + extra_types = { + 'async_req': (bool,), + '_host_index': (int,), + '_preload_content': (bool,), + '_request_timeout': (none_type, int, (int,), [int]), + '_return_http_data_only': (bool,), + '_check_input_type': (bool,), + '_check_return_type': (bool,) + } + self.openapi_types.update(extra_types) + self.attribute_map = root_map['attribute_map'] + self.location_map = root_map['location_map'] + self.collection_format_map = root_map['collection_format_map'] + self.headers_map = headers_map + self.api_client = api_client + self.callable = callable + + def __validate_inputs(self, kwargs): + for param in self.params_map['enum']: + if param in kwargs: + check_allowed_values( + self.allowed_values, + (param,), + kwargs[param] + ) + + for param in self.params_map['validation']: + if param in kwargs: + check_validations( + self.validations, + (param,), + kwargs[param], + configuration=self.api_client.configuration + ) + + if kwargs['_check_input_type'] is False: + return + + for key, value in six.iteritems(kwargs): + fixed_val = validate_and_convert_types( + value, + self.openapi_types[key], + [key], + False, + kwargs['_check_input_type'], + configuration=self.api_client.configuration + ) + kwargs[key] = fixed_val + + def __gather_params(self, kwargs): + params = { + 'body': None, + 'collection_format': {}, + 'file': {}, + 'form': [], + 'header': {}, + 'path': {}, + 'query': [] + } + + for param_name, param_value in six.iteritems(kwargs): + param_location = self.location_map.get(param_name) + if param_location is None: + continue + if param_location: + if param_location == 'body': + params['body'] = param_value + continue + base_name = self.attribute_map[param_name] + if (param_location == 'form' and + self.openapi_types[param_name] == (file_type,)): + params['file'][param_name] = [param_value] + elif (param_location == 'form' and + self.openapi_types[param_name] == ([file_type],)): + # param_value is already a list + params['file'][param_name] = param_value + elif param_location in {'form', 'query'}: + param_value_full = (base_name, param_value) + params[param_location].append(param_value_full) + if param_location not in {'form', 'query'}: + params[param_location][base_name] = param_value + collection_format = self.collection_format_map.get(param_name) + if collection_format: + params['collection_format'][base_name] = collection_format + + return params + + def __call__(self, *args, **kwargs): + """ This method is invoked when endpoints are called + Example: + pet_api = PetApi() + pet_api.add_pet # this is an instance of the class Endpoint + pet_api.add_pet() # this invokes pet_api.add_pet.__call__() + which then invokes the callable functions stored in that endpoint at + pet_api.add_pet.callable or self.callable in this class + """ + return self.callable(self, *args, **kwargs) + + def call_with_http_info(self, **kwargs): + + try: + _host = self.settings['servers'][kwargs['_host_index']] + except IndexError: + if self.settings['servers']: + raise ApiValueError( + "Invalid host index. Must be 0 <= index < %s" % + len(self.settings['servers']) + ) + _host = None + + for key, value in six.iteritems(kwargs): + if key not in self.params_map['all']: + raise ApiTypeError( + "Got an unexpected parameter '%s'" + " to method `%s`" % + (key, self.settings['operation_id']) + ) + # only throw this nullable ApiValueError if _check_input_type + # is False, if _check_input_type==True we catch this case + # in self.__validate_inputs + if (key not in self.params_map['nullable'] and value is None + and kwargs['_check_input_type'] is False): + raise ApiValueError( + "Value may not be None for non-nullable parameter `%s`" + " when calling `%s`" % + (key, self.settings['operation_id']) + ) + + for key in self.params_map['required']: + if key not in kwargs.keys(): + raise ApiValueError( + "Missing the required parameter `%s` when calling " + "`%s`" % (key, self.settings['operation_id']) + ) + + self.__validate_inputs(kwargs) + + params = self.__gather_params(kwargs) + + accept_headers_list = self.headers_map['accept'] + if accept_headers_list: + params['header']['Accept'] = self.api_client.select_header_accept( + accept_headers_list) + + content_type_headers_list = self.headers_map['content_type'] + if content_type_headers_list: + header_list = self.api_client.select_header_content_type( + content_type_headers_list) + params['header']['Content-Type'] = header_list + + return self.api_client.call_api( + self.settings['endpoint_path'], self.settings['http_method'], + params['path'], + params['query'], + params['header'], + body=params['body'], + post_params=params['form'], + files=params['file'], + response_type=self.settings['response_type'], + auth_settings=self.settings['auth'], + async_req=kwargs['async_req'], + _check_type=kwargs['_check_return_type'], + _return_http_data_only=kwargs['_return_http_data_only'], + _preload_content=kwargs['_preload_content'], + _request_timeout=kwargs['_request_timeout'], + _host=_host, + collection_formats=params['collection_format']) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/__init__.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/__init__.py index 41cbd0aa055e..19871fa18210 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/__init__.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/__init__.py @@ -16,6 +16,7 @@ from petstore_api.api.default_api import DefaultApi from petstore_api.api.fake_api import FakeApi from petstore_api.api.fake_classname_tags_123_api import FakeClassnameTags123Api +from petstore_api.api.farm_api import FarmApi from petstore_api.api.pet_api import PetApi from petstore_api.api.store_api import StoreApi from petstore_api.api.user_api import UserApi diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/animal_farm.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/animal_farm.py new file mode 100644 index 000000000000..0017e93ab62d --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/animal_farm.py @@ -0,0 +1,175 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import +import re # noqa: F401 +import sys # noqa: F401 + +import six # 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, + int, + none_type, + str, + validate_get_composed_info, +) +try: + from petstore_api.model import animal +except ImportError: + animal = sys.modules[ + 'petstore_api.model.animal'] + + +class AnimalFarm(ModelNormal): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + discriminator_value_class_map (dict): A dict to go from the discriminator + variable value to the discriminator class name. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = { + } + + validations = { + } + + additional_properties_type = None + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a class method so a model may have properties that are + of type self, this ensures that we don't create a cyclic import + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + return { + } + + @cached_property + def discriminator(): + return None + + attribute_map = { + } + + _composed_schemas = {} + + required_properties = set([ + '_data_store', + '_check_type', + '_spec_property_naming', + '_path_to_item', + '_configuration', + '_visited_composed_classes', + ]) + + @convert_js_args_to_python_args + def __init__(self, *args, **kwargs): # noqa: E501 + """animal_farm.AnimalFarm - a model defined in OpenAPI + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + """ + + _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__,) + + for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue + setattr(self, var_name, var_value) 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 7c58ced9f86a..018302a720ba 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 @@ -14,6 +14,7 @@ from petstore_api.model.additional_properties_class import AdditionalPropertiesClass from petstore_api.model.address import Address from petstore_api.model.animal import Animal +from petstore_api.model.animal_farm import AnimalFarm from petstore_api.model.api_response import ApiResponse from petstore_api.model.apple import Apple from petstore_api.model.apple_req import AppleReq diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_animal_farm.py b/samples/openapi3/client/petstore/python-experimental/test/test_animal_farm.py new file mode 100644 index 000000000000..7117d42b430e --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/test/test_animal_farm.py @@ -0,0 +1,43 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import +import sys +import unittest + +import petstore_api +try: + from petstore_api.model import animal +except ImportError: + animal = sys.modules[ + 'petstore_api.model.animal'] +from petstore_api.model.animal_farm import AnimalFarm + + +class TestAnimalFarm(unittest.TestCase): + """AnimalFarm unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testAnimalFarm(self): + """Test AnimalFarm""" + # FIXME: construct object with mandatory attributes with example values + # model = AnimalFarm() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_drawing.py b/samples/openapi3/client/petstore/python-experimental/test/test_drawing.py index dbfba3ea700f..e4997e48f9ff 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_drawing.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_drawing.py @@ -15,6 +15,11 @@ import unittest import petstore_api +try: + from petstore_api.model import fruit +except ImportError: + fruit = sys.modules[ + 'petstore_api.model.fruit'] try: from petstore_api.model import nullable_shape except ImportError: @@ -42,130 +47,12 @@ def setUp(self): def tearDown(self): pass - def test_create_instances(self): - """ - Validate instance can be created using pythonic name or OAS names. - """ - - # Validate object can be created using pythonic names. - inst = shape.Shape( - shape_type="Triangle", - triangle_type="IsoscelesTriangle" - ) - from petstore_api.model.isosceles_triangle import IsoscelesTriangle - assert isinstance(inst, IsoscelesTriangle) - - # Validate object can be created using OAS names. - # For example, this can be used to construct objects on the client - # when the input data is available as JSON documents. - data = { - 'shapeType': "Triangle", - 'triangleType': "IsoscelesTriangle" - } - inst = shape.Shape(_spec_property_naming=True, **data) - assert isinstance(inst, IsoscelesTriangle) - - def test_deserialize_oneof_reference(self): - """ - Validate the scenario when the type of a OAS property is 'oneOf', and the 'oneOf' - schema is specified as a reference ($ref), not an inline 'oneOf' schema. - """ - isosceles_triangle = shape.Shape( - shape_type="Triangle", - triangle_type="IsoscelesTriangle" - ) - from petstore_api.model.isosceles_triangle import IsoscelesTriangle - from petstore_api.model.triangle import Triangle - from petstore_api.model.equilateral_triangle import EquilateralTriangle - - assert isinstance(isosceles_triangle, IsoscelesTriangle) - inst = Drawing( - # 'main_shape' has type 'Shape', which is a oneOf [triangle, quadrilateral] - # composed schema. So we should be able to assign a petstore_api.Triangle - # to a 'main_shape'. - main_shape=isosceles_triangle, - shapes=[ - shape.Shape( - shape_type="Triangle", - triangle_type="EquilateralTriangle" - ), - Triangle( - shape_type="Triangle", - triangle_type="IsoscelesTriangle" - ), - EquilateralTriangle( - shape_type="Triangle", - triangle_type="EquilateralTriangle" - ), - shape.Shape( - shape_type="Quadrilateral", - quadrilateral_type="ComplexQuadrilateral" - ), - ], - ) - from petstore_api.model.complex_quadrilateral import ComplexQuadrilateral - assert isinstance(inst, Drawing) - assert isinstance(inst.main_shape, IsoscelesTriangle) - self.assertEqual(len(inst.shapes), 4) - assert isinstance(inst.shapes[0], EquilateralTriangle) - assert isinstance(inst.shapes[1], IsoscelesTriangle) - assert isinstance(inst.shapes[2], EquilateralTriangle) - assert isinstance(inst.shapes[3], ComplexQuadrilateral) - - # Validate we cannot assign the None value to main_shape because the 'null' type - # is not one of the allowed types in the 'Shape' schema. - err_msg = ("Invalid type for variable '{}'. " - "Required value type is {} and passed type was {} at {}") - with self.assertRaisesRegexp( - petstore_api.ApiTypeError, - err_msg.format("main_shape", "Shape", "NoneType", "\['main_shape'\]") - ): - inst = Drawing( - # 'main_shape' has type 'Shape', which is a oneOf [triangle, quadrilateral] - # So the None value should not be allowed and an exception should be raised. - main_shape=None, - ) - - - def test_deserialize_oneof_reference_with_null_type(self): - """ - Validate the scenario when the type of a OAS property is 'oneOf', and the 'oneOf' - schema is specified as a reference ($ref), not an inline 'oneOf' schema. - Further, the 'oneOf' schema has a 'null' type child schema (as introduced in - OpenAPI 3.1). - """ - - # Validate we can assign the None value to shape_or_null, because the 'null' type - # is one of the allowed types in the 'ShapeOrNull' schema. - inst = Drawing( - # 'shape_or_null' has type 'ShapeOrNull', which is a oneOf [null, triangle, quadrilateral] - shape_or_null=None, - ) - assert isinstance(inst, Drawing) - self.assertFalse(hasattr(inst, 'main_shape')) - self.assertTrue(hasattr(inst, 'shape_or_null')) - self.assertIsNone(inst.shape_or_null) - - - def test_deserialize_oneof_reference_with_nullable_type(self): - """ - Validate the scenario when the type of a OAS property is 'oneOf', and the 'oneOf' - schema is specified as a reference ($ref), not an inline 'oneOf' schema. - Further, the 'oneOf' schema has the 'nullable' attribute (as introduced in - OpenAPI 3.0 and deprecated in 3.1). - """ + def testDrawing(self): + """Test Drawing""" + # FIXME: construct object with mandatory attributes with example values + # model = Drawing() # noqa: E501 + pass - # Validate we can assign the None value to nullable_shape, because the NullableShape - # has the 'nullable: true' attribute. - inst = Drawing( - # 'nullable_shape' has type 'NullableShape', which is a oneOf [triangle, quadrilateral] - # and the 'nullable: true' attribute. - nullable_shape=None, - ) - assert isinstance(inst, Drawing) - self.assertFalse(hasattr(inst, 'main_shape')) - self.assertTrue(hasattr(inst, 'nullable_shape')) - self.assertIsNone(inst.nullable_shape) if __name__ == '__main__': unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_farm_api.py b/samples/openapi3/client/petstore/python-experimental/test/test_farm_api.py new file mode 100644 index 000000000000..b39e76ae7833 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/test/test_farm_api.py @@ -0,0 +1,39 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import unittest + +import petstore_api +from petstore_api.api.farm_api import FarmApi # noqa: E501 + + +class TestFarmApi(unittest.TestCase): + """FarmApi unit test stubs""" + + def setUp(self): + self.api = FarmApi() # noqa: E501 + + def tearDown(self): + pass + + def test_farm(self): + """Test case for farm + + Animal Farm # noqa: E501 + """ + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_fruit.py b/samples/openapi3/client/petstore/python-experimental/test/test_fruit.py index 1eb9d09d5061..e02319bb6ff6 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_fruit.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_fruit.py @@ -39,184 +39,10 @@ def tearDown(self): def testFruit(self): """Test Fruit""" + # FIXME: construct object with mandatory attributes with example values + # model = Fruit() # noqa: E501 + pass - # make an instance of Fruit, a composed schema oneOf model - # banana test - length_cm = 20.3 - color = 'yellow' - fruit = Fruit(length_cm=length_cm, color=color) - # check its properties - self.assertEqual(fruit.length_cm, length_cm) - self.assertEqual(fruit['length_cm'], length_cm) - self.assertEqual(getattr(fruit, 'length_cm'), length_cm) - self.assertEqual(fruit.color, color) - self.assertEqual(fruit['color'], color) - self.assertEqual(getattr(fruit, 'color'), color) - # check the dict representation - self.assertEqual( - fruit.to_dict(), - { - 'length_cm': length_cm, - 'color': color - } - ) - # setting a value that doesn't exist raises an exception - # with a key - with self.assertRaises(AttributeError): - fruit['invalid_variable'] = 'some value' - - # Assert that we can call the builtin hasattr() function. - # hasattr should return False for non-existent attribute. - # Internally hasattr catches the AttributeError exception. - self.assertFalse(hasattr(fruit, 'invalid_variable')) - - # Assert that we can call the builtin hasattr() function. - # hasattr should return True for existent attribute. - self.assertTrue(hasattr(fruit, 'color')) - - # with setattr - with self.assertRaises(AttributeError): - setattr(fruit, 'invalid_variable', 'some value') - - # getting a value that doesn't exist raises an exception - # with a key - with self.assertRaises(AttributeError): - invalid_variable = fruit['cultivar'] - # with getattr - # Per Python doc, if the named attribute does not exist, - # default is returned if provided. - self.assertEqual(getattr(fruit, 'cultivar', 'some value'), 'some value') - - # Per Python doc, if the named attribute does not exist, - # default is returned if provided, otherwise AttributeError is raised. - with self.assertRaises(AttributeError): - getattr(fruit, 'cultivar') - - # make sure that the ModelComposed class properties are correct - # model._composed_schemas stores the anyOf/allOf/oneOf info - self.assertEqual( - fruit._composed_schemas, - { - 'anyOf': [], - 'allOf': [], - 'oneOf': [ - apple.Apple, - banana.Banana, - ], - } - ) - # model._composed_instances is a list of the instances that were - # made from the anyOf/allOf/OneOf classes in model._composed_schemas - for composed_instance in fruit._composed_instances: - if composed_instance.__class__ == banana.Banana: - banana_instance = composed_instance - self.assertEqual( - fruit._composed_instances, - [banana_instance] - ) - # model._var_name_to_model_instances maps the variable name to the - # model instances which store that variable - self.assertEqual( - fruit._var_name_to_model_instances, - { - 'color': [fruit], - 'length_cm': [fruit, banana_instance], - 'cultivar': [fruit], - 'origin': [fruit], - } - ) - # model._additional_properties_model_instances stores a list of - # models which have the property additional_properties_type != None - self.assertEqual( - fruit._additional_properties_model_instances, [] - ) - - # if we modify one of the properties owned by multiple - # model_instances we get an exception when we try to access that - # property because the retrieved values are not all the same - banana_instance.length_cm = 4.56 - with self.assertRaises(petstore_api.ApiValueError): - some_length_cm = fruit.length_cm - - # including extra parameters raises an exception - with self.assertRaises(petstore_api.ApiValueError): - fruit = Fruit( - color=color, - length_cm=length_cm, - unknown_property='some value' - ) - - # including input parameters for two oneOf instances raise an exception - with self.assertRaises(petstore_api.ApiValueError): - fruit = Fruit( - length_cm=length_cm, - cultivar='granny smith' - ) - - # make an instance of Fruit, a composed schema oneOf model - # apple test - color = 'red' - cultivar = 'golden delicious' - fruit = Fruit(color=color, cultivar=cultivar) - # check its properties - self.assertEqual(fruit.color, color) - self.assertEqual(fruit['color'], color) - self.assertEqual(getattr(fruit, 'color'), color) - self.assertEqual(fruit.cultivar, cultivar) - self.assertEqual(fruit['cultivar'], cultivar) - self.assertEqual(getattr(fruit, 'cultivar'), cultivar) - # check the dict representation - self.assertEqual( - fruit.to_dict(), - { - 'color': color, - 'cultivar': cultivar - } - ) - - # model._composed_instances is a list of the instances that were - # made from the anyOf/allOf/OneOf classes in model._composed_schemas - for composed_instance in fruit._composed_instances: - if composed_instance.__class__ == apple.Apple: - apple_instance = composed_instance - self.assertEqual( - fruit._composed_instances, - [apple_instance] - ) - # model._var_name_to_model_instances maps the variable name to the - # model instances which store that variable - self.assertEqual( - fruit._var_name_to_model_instances, - { - 'color': [fruit], - 'length_cm': [fruit], - 'cultivar': [fruit, apple_instance], - 'origin': [fruit, apple_instance], - } - ) - # model._additional_properties_model_instances stores a list of - # models which have the property additional_properties_type != None - self.assertEqual( - fruit._additional_properties_model_instances, [] - ) - - def testFruitNullValue(self): - # Since 'apple' is nullable, validate we can create an apple with the 'null' value. - fruit = apple.Apple(None) - self.assertIsNone(fruit) - - # 'banana' is not nullable. - with self.assertRaises(petstore_api.ApiTypeError): - banana.Banana(None) - - # Since 'fruit' has oneOf 'apple', 'banana' and 'apple' is nullable, - # validate we can create a fruit with the 'null' value. - fruit = Fruit(None) - self.assertIsNone(fruit) - - # Redo the same thing, this time passing a null Apple to the Fruit constructor. - fruit = Fruit(apple.Apple(None)) - self.assertIsNone(fruit) if __name__ == '__main__': unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_fruit_req.py b/samples/openapi3/client/petstore/python-experimental/test/test_fruit_req.py index 3a1aa8fc283b..79f23dea6313 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_fruit_req.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_fruit_req.py @@ -39,142 +39,10 @@ def tearDown(self): def testFruitReq(self): """Test FruitReq""" + # FIXME: construct object with mandatory attributes with example values + # model = FruitReq() # noqa: E501 + pass - # make an instance of Fruit, a composed schema oneOf model - # banana test - length_cm = 20.3 - fruit = FruitReq(length_cm=length_cm) - # check its properties - self.assertEqual(fruit.length_cm, length_cm) - self.assertEqual(fruit['length_cm'], length_cm) - self.assertEqual(getattr(fruit, 'length_cm'), length_cm) - # check the dict representation - self.assertEqual( - fruit.to_dict(), - { - 'length_cm': length_cm, - } - ) - # setting a value that doesn't exist raises an exception - # with a key - with self.assertRaises(AttributeError): - fruit['invalid_variable'] = 'some value' - # with setattr - with self.assertRaises(AttributeError): - setattr(fruit, 'invalid_variable', 'some value') - - # getting a value that doesn't exist raises an exception - # with a key - with self.assertRaises(AttributeError): - invalid_variable = fruit['cultivar'] - # with getattr - self.assertEqual(getattr(fruit, 'cultivar', 'some value'), 'some value') - - with self.assertRaises(AttributeError): - getattr(fruit, 'cultivar') - - # make sure that the ModelComposed class properties are correct - # model._composed_schemas stores the anyOf/allOf/oneOf info - self.assertEqual( - fruit._composed_schemas, - { - 'anyOf': [], - 'allOf': [], - 'oneOf': [ - apple_req.AppleReq, - banana_req.BananaReq, - type(None), - ], - } - ) - # model._composed_instances is a list of the instances that were - # made from the anyOf/allOf/OneOf classes in model._composed_schemas - for composed_instance in fruit._composed_instances: - if composed_instance.__class__ == banana_req.BananaReq: - banana_instance = composed_instance - self.assertEqual( - fruit._composed_instances, - [banana_instance] - ) - # model._var_name_to_model_instances maps the variable name to the - # model instances which store that variable - self.assertEqual( - fruit._var_name_to_model_instances, - { - 'length_cm': [fruit, banana_instance], - 'cultivar': [fruit], - 'mealy': [fruit], - 'sweet': [fruit, banana_instance], - } - ) - # model._additional_properties_model_instances stores a list of - # models which have the property additional_properties_type != None - self.assertEqual( - fruit._additional_properties_model_instances, [] - ) - - # if we modify one of the properties owned by multiple - # model_instances we get an exception when we try to access that - # property because the retrieved values are not all the same - banana_instance.length_cm = 4.56 - with self.assertRaises(petstore_api.ApiValueError): - some_length_cm = fruit.length_cm - - # including extra parameters raises an exception - with self.assertRaises(petstore_api.ApiValueError): - fruit = FruitReq( - length_cm=length_cm, - unknown_property='some value' - ) - - # including input parameters for two oneOf instances raise an exception - with self.assertRaises(petstore_api.ApiValueError): - fruit = FruitReq( - length_cm=length_cm, - cultivar='granny smith' - ) - - # make an instance of Fruit, a composed schema oneOf model - # apple test - cultivar = 'golden delicious' - fruit = FruitReq(cultivar=cultivar) - # check its properties - self.assertEqual(fruit.cultivar, cultivar) - self.assertEqual(fruit['cultivar'], cultivar) - self.assertEqual(getattr(fruit, 'cultivar'), cultivar) - # check the dict representation - self.assertEqual( - fruit.to_dict(), - { - 'cultivar': cultivar - } - ) - - # model._composed_instances is a list of the instances that were - # made from the anyOf/allOf/OneOf classes in model._composed_schemas - for composed_instance in fruit._composed_instances: - if composed_instance.__class__ == apple_req.AppleReq: - apple_instance = composed_instance - self.assertEqual( - fruit._composed_instances, - [apple_instance] - ) - # model._var_name_to_model_instances maps the variable name to the - # model instances which store that variable - self.assertEqual( - fruit._var_name_to_model_instances, - { - 'length_cm': [fruit], - 'cultivar': [fruit, apple_instance], - 'mealy': [fruit, apple_instance], - 'sweet': [fruit], - } - ) - # model._additional_properties_model_instances stores a list of - # models which have the property additional_properties_type != None - self.assertEqual( - fruit._additional_properties_model_instances, [] - ) if __name__ == '__main__': unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_gm_fruit.py b/samples/openapi3/client/petstore/python-experimental/test/test_gm_fruit.py index 9d13e90659d0..eddeea0b8f28 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_gm_fruit.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_gm_fruit.py @@ -39,193 +39,10 @@ def tearDown(self): def testGmFruit(self): """Test GmFruit""" + # FIXME: construct object with mandatory attributes with example values + # model = GmFruit() # noqa: E501 + pass - # make an instance of GmFruit, a composed schema anyOf model - # banana test - length_cm = 20.3 - color = 'yellow' - fruit = GmFruit(length_cm=length_cm, color=color) - # check its properties - self.assertEqual(fruit.length_cm, length_cm) - self.assertEqual(fruit['length_cm'], length_cm) - self.assertEqual(getattr(fruit, 'length_cm'), length_cm) - self.assertEqual(fruit.color, color) - self.assertEqual(fruit['color'], color) - self.assertEqual(getattr(fruit, 'color'), color) - # check the dict representation - self.assertEqual( - fruit.to_dict(), - { - 'length_cm': length_cm, - 'color': color - } - ) - # setting a value that doesn't exist raises an exception - # with a key - with self.assertRaises(AttributeError): - fruit['invalid_variable'] = 'some value' - # with setattr - with self.assertRaises(AttributeError): - setattr(fruit, 'invalid_variable', 'some value') - - # getting a value that doesn't exist raises an exception - # with a key - with self.assertRaises(AttributeError): - invalid_variable = fruit['cultivar'] - # with getattr - self.assertTrue(getattr(fruit, 'cultivar', 'some value'), 'some value') - - with self.assertRaises(AttributeError): - invalid_variable = getattr(fruit, 'cultivar') - - # make sure that the ModelComposed class properties are correct - # model._composed_schemas stores the anyOf/allOf/oneOf info - self.assertEqual( - fruit._composed_schemas, - { - 'anyOf': [ - apple.Apple, - banana.Banana, - ], - 'allOf': [], - 'oneOf': [], - } - ) - # model._composed_instances is a list of the instances that were - # made from the anyOf/allOf/OneOf classes in model._composed_schemas - for composed_instance in fruit._composed_instances: - if composed_instance.__class__ == banana.Banana: - banana_instance = composed_instance - self.assertEqual( - fruit._composed_instances, - [banana_instance] - ) - # model._var_name_to_model_instances maps the variable name to the - # model instances which store that variable - self.assertEqual( - fruit._var_name_to_model_instances, - { - 'color': [fruit], - 'length_cm': [fruit, banana_instance], - 'cultivar': [fruit], - 'origin': [fruit], - } - ) - # model._additional_properties_model_instances stores a list of - # models which have the property additional_properties_type != None - self.assertEqual( - fruit._additional_properties_model_instances, [] - ) - - # if we modify one of the properties owned by multiple - # model_instances we get an exception when we try to access that - # property because the retrieved values are not all the same - banana_instance.length_cm = 4.56 - with self.assertRaises(petstore_api.ApiValueError): - some_length_cm = fruit.length_cm - - # including extra parameters raises an exception - with self.assertRaises(petstore_api.ApiValueError): - fruit = GmFruit( - color=color, - length_cm=length_cm, - unknown_property='some value' - ) - - # including input parameters for both anyOf instances works - cultivar = 'banaple' - color = 'orange' - fruit = GmFruit( - color=color, - cultivar=cultivar, - length_cm=length_cm - ) - self.assertEqual(fruit.color, color) - self.assertEqual(fruit['color'], color) - self.assertEqual(getattr(fruit, 'color'), color) - self.assertEqual(fruit.cultivar, cultivar) - self.assertEqual(fruit['cultivar'], cultivar) - self.assertEqual(getattr(fruit, 'cultivar'), cultivar) - self.assertEqual(fruit.length_cm, length_cm) - self.assertEqual(fruit['length_cm'], length_cm) - self.assertEqual(getattr(fruit, 'length_cm'), length_cm) - - # model._composed_instances is a list of the instances that were - # made from the anyOf/allOf/OneOf classes in model._composed_schemas - for composed_instance in fruit._composed_instances: - if composed_instance.__class__ == apple.Apple: - apple_instance = composed_instance - elif composed_instance.__class__ == banana.Banana: - banana_instance = composed_instance - self.assertEqual( - fruit._composed_instances, - [apple_instance, banana_instance] - ) - # model._var_name_to_model_instances maps the variable name to the - # model instances which store that variable - self.assertEqual( - fruit._var_name_to_model_instances, - { - 'color': [fruit], - 'length_cm': [fruit, banana_instance], - 'cultivar': [fruit, apple_instance], - 'origin': [fruit, apple_instance], - } - ) - - # make an instance of GmFruit, a composed schema anyOf model - # apple test - color = 'red' - cultivar = 'golden delicious' - origin = 'California' - fruit = GmFruit(color=color, cultivar=cultivar, origin=origin) - # check its properties - self.assertEqual(fruit.color, color) - self.assertEqual(fruit['color'], color) - self.assertEqual(getattr(fruit, 'color'), color) - self.assertEqual(fruit.cultivar, cultivar) - self.assertEqual(fruit['cultivar'], cultivar) - self.assertEqual(getattr(fruit, 'cultivar'), cultivar) - - self.assertEqual(fruit.origin, origin) - self.assertEqual(fruit['origin'], origin) - self.assertEqual(getattr(fruit, 'origin'), origin) - - # check the dict representation - self.assertEqual( - fruit.to_dict(), - { - 'color': color, - 'cultivar': cultivar, - 'origin': origin, - } - ) - - # model._composed_instances is a list of the instances that were - # made from the anyOf/allOf/OneOf classes in model._composed_schemas - for composed_instance in fruit._composed_instances: - if composed_instance.__class__ == apple.Apple: - apple_instance = composed_instance - self.assertEqual( - fruit._composed_instances, - [apple_instance] - ) - # model._var_name_to_model_instances maps the variable name to the - # model instances which store that variable - self.assertEqual( - fruit._var_name_to_model_instances, - { - 'color': [fruit], - 'length_cm': [fruit], - 'cultivar': [fruit, apple_instance], - 'origin': [fruit, apple_instance], - } - ) - # model._additional_properties_model_instances stores a list of - # models which have the property additional_properties_type != None - self.assertEqual( - fruit._additional_properties_model_instances, [] - ) if __name__ == '__main__': unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_mammal.py b/samples/openapi3/client/petstore/python-experimental/test/test_mammal.py index 2a8893d02fb3..2d482aef29d2 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_mammal.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_mammal.py @@ -15,6 +15,11 @@ import unittest import petstore_api +try: + from petstore_api.model import pig +except ImportError: + pig = sys.modules[ + 'petstore_api.model.pig'] try: from petstore_api.model import whale except ImportError: @@ -39,11 +44,9 @@ def tearDown(self): def testMammal(self): """Test Mammal""" - - # tests that we can make a BasquePig by traveling through descendant discriminator in Pig - model = Mammal(class_name="BasquePig") - from petstore_api.model import basque_pig - assert isinstance(model, basque_pig.BasquePig) + # FIXME: construct object with mandatory attributes with example values + # model = Mammal() # noqa: E501 + pass if __name__ == '__main__': diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_outer_enum.py b/samples/openapi3/client/petstore/python-experimental/test/test_outer_enum.py index ab9dac9d612b..b9423fb81e58 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_outer_enum.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_outer_enum.py @@ -29,16 +29,9 @@ def tearDown(self): def testOuterEnum(self): """Test OuterEnum""" - # Since 'OuterEnum' is nullable, validate the null value can be assigned - # to OuterEnum. - inst = OuterEnum(None) - self.assertIsNone(inst) - - inst = OuterEnum('approved') - assert isinstance(inst, OuterEnum) - - with self.assertRaises(petstore_api.ApiValueError): - OuterEnum('garbage') + # FIXME: construct object with mandatory attributes with example values + # model = OuterEnum() # noqa: E501 + pass if __name__ == '__main__': diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_parent_pet.py b/samples/openapi3/client/petstore/python-experimental/test/test_parent_pet.py index 15262872e195..5268a00d9a87 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_parent_pet.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_parent_pet.py @@ -39,12 +39,9 @@ def tearDown(self): def testParentPet(self): """Test ParentPet""" - - # test that we can make a ParentPet from a ParentPet - # which requires that we travel back through ParentPet's allOf descendant - # GrandparentAnimal, and we use the descendant's discriminator to make ParentPet - model = ParentPet(pet_type="ParentPet") - assert isinstance(model, ParentPet) + # FIXME: construct object with mandatory attributes with example values + # model = ParentPet() # noqa: E501 + pass if __name__ == '__main__': diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_quadrilateral.py b/samples/openapi3/client/petstore/python-experimental/test/test_quadrilateral.py index 149b9a0070b6..64871ac5203c 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_quadrilateral.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_quadrilateral.py @@ -39,10 +39,9 @@ def tearDown(self): def testQuadrilateral(self): """Test Quadrilateral""" - instance = Quadrilateral(shape_type="Quadrilateral", quadrilateral_type="ComplexQuadrilateral") - assert isinstance(instance, complex_quadrilateral.ComplexQuadrilateral) - instance = Quadrilateral(shape_type="Quadrilateral", quadrilateral_type="SimpleQuadrilateral") - assert isinstance(instance, simple_quadrilateral.SimpleQuadrilateral) + # FIXME: construct object with mandatory attributes with example values + # model = Quadrilateral() # noqa: E501 + pass if __name__ == '__main__': diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_shape.py b/samples/openapi3/client/petstore/python-experimental/test/test_shape.py index 4424679aeccb..100eaab7cc07 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_shape.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_shape.py @@ -39,71 +39,10 @@ def tearDown(self): def testShape(self): """Test Shape""" - from petstore_api.model import complex_quadrilateral - from petstore_api.model import simple_quadrilateral - from petstore_api.model import equilateral_triangle - from petstore_api.model import isosceles_triangle - from petstore_api.model import scalene_triangle - tri = triangle.Triangle( - shape_type="Triangle", - triangle_type="EquilateralTriangle" - ) - assert isinstance(tri, equilateral_triangle.EquilateralTriangle) - - tri = triangle.Triangle( - shape_type="Triangle", - triangle_type="IsoscelesTriangle" - ) - assert isinstance(tri, isosceles_triangle.IsoscelesTriangle) - - tri = triangle.Triangle( - shape_type="Triangle", - triangle_type="ScaleneTriangle" - ) - assert isinstance(tri, scalene_triangle.ScaleneTriangle) - - quad = Shape( - shape_type="Quadrilateral", - quadrilateral_type="ComplexQuadrilateral" - ) - assert isinstance(quad, complex_quadrilateral.ComplexQuadrilateral) - - quad = Shape( - shape_type="Quadrilateral", - quadrilateral_type="SimpleQuadrilateral" - ) - assert isinstance(quad, simple_quadrilateral.SimpleQuadrilateral) - - # No discriminator provided. - err_msg = ("Cannot deserialize input data due to missing discriminator. " - "The discriminator property '{}' is missing at path: ()" - ) - with self.assertRaisesRegexp( - petstore_api.ApiValueError, - err_msg.format("shapeType") - ): - Shape() - - # invalid shape_type (first discriminator). 'Circle' does not exist in the model. - err_msg = ("Cannot deserialize input data due to invalid discriminator " - "value. The OpenAPI document has no mapping for discriminator " - "property '{}'='{}' at path: ()" - ) - with self.assertRaisesRegexp( - petstore_api.ApiValueError, - err_msg.format("shapeType", "Circle") - ): - Shape(shape_type="Circle") + # FIXME: construct object with mandatory attributes with example values + # model = Shape() # noqa: E501 + pass - # invalid quadrilateral_type (second discriminator) - with self.assertRaisesRegexp( - petstore_api.ApiValueError, - err_msg.format("quadrilateralType", "Triangle") - ): - Shape( - shape_type="Quadrilateral", - quadrilateral_type="Triangle" - ) if __name__ == '__main__': unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_tag.py b/samples/openapi3/client/petstore/python-experimental/test/test_tag.py index b0a09d94a785..68a3b9046bf4 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_tag.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_tag.py @@ -11,7 +11,7 @@ from __future__ import absolute_import - +import sys import unittest import petstore_api diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_triangle.py b/samples/openapi3/client/petstore/python-experimental/test/test_triangle.py index 65ae20743e14..84cbfe0c7051 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_triangle.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_triangle.py @@ -44,12 +44,9 @@ def tearDown(self): def testTriangle(self): """Test Triangle""" - tri = Triangle(shape_type="Triangle", triangle_type="EquilateralTriangle") - assert isinstance(tri, equilateral_triangle.EquilateralTriangle) - tri = Triangle(shape_type="Triangle", triangle_type="IsoscelesTriangle") - assert isinstance(tri, isosceles_triangle.IsoscelesTriangle) - tri = Triangle(shape_type="Triangle", triangle_type="ScaleneTriangle") - assert isinstance(tri, scalene_triangle.ScaleneTriangle) + # FIXME: construct object with mandatory attributes with example values + # model = Triangle() # noqa: E501 + pass if __name__ == '__main__': From 31407d4d579e5a67a06f0991c07593ef42f82dd2 Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Mon, 1 Jun 2020 20:18:57 +0200 Subject: [PATCH 03/18] Use ModelSimple --- .../languages/PythonClientExperimentalCodegen.java | 1 - .../python/python-experimental/model.mustache | 5 +++++ .../python-experimental/.openapi-generator/FILES | 2 -- .../petstore_api/model/animal_farm.py | 11 ++--------- 4 files changed, 7 insertions(+), 12 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 b034d16a2e12..0c696c6dc247 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 @@ -418,7 +418,6 @@ public Map postProcessAllModels(Map objs) { Schema modelSchema = ModelUtils.getSchema(this.openAPI, cm.name); CodegenProperty modelProperty = fromProperty("value", modelSchema); - LOGGER.warn("schema: {}\ncm.isEnum = {}\ncm.isAlias = {}\ncm.isArrayModel = {} && modelProperty.isEnum = {} && modelProperty.hasValidation = {}\n{}", cm.name, cm.isEnum, cm.isAlias, cm.isArrayModel, modelProperty.isEnum, modelProperty.hasValidation, cm.arrayModelType); if (cm.isEnum || cm.isAlias) { if (!modelProperty.isEnum && !modelProperty.hasValidation) { // remove these models because they are aliases and do not have any enums or validations diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model.mustache index 0790c6143578..490629c5a386 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model.mustache @@ -37,7 +37,12 @@ from {{packageName}}.model_utils import ( # noqa: F401 {{> python-experimental/model_templates/model_simple }} {{/isAlias}} {{^isAlias}} +{{#isArrayModel}} +{{> python-experimental/model_templates/model_simple }} +{{/isArrayModel}} +{{^isArrayModel}} {{> python-experimental/model_templates/model_normal }} +{{/isArrayModel}} {{/isAlias}} {{/interfaces}} {{#interfaces}} diff --git a/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES index 6229b4f43997..6069bc6566db 100644 --- a/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES @@ -201,6 +201,4 @@ setup.cfg setup.py test-requirements.txt test/__init__.py -test/test_animal_farm.py -test/test_farm_api.py tox.ini diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/animal_farm.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/animal_farm.py index 0017e93ab62d..1bf28922fd7b 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/animal_farm.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/animal_farm.py @@ -40,7 +40,7 @@ 'petstore_api.model.animal'] -class AnimalFarm(ModelNormal): +class AnimalFarm(ModelSimple): """NOTE: This class is auto generated by OpenAPI Generator. Ref: https://openapi-generator.tech @@ -51,10 +51,6 @@ class AnimalFarm(ModelNormal): and the for var_name this is (var_name,). The value is a dict with a capitalized key describing the allowed value and an allowed value. These dicts store the allowed enum values. - attribute_map (dict): The key is attribute name - and the value is json key in definition. - discriminator_value_class_map (dict): A dict to go from the discriminator - variable value to the discriminator class name. validations (dict): The key is the tuple path to the attribute and the for var_name this is (var_name,). The value is a dict that stores validations for max_length, min_length, max_items, @@ -91,10 +87,7 @@ def openapi_types(): def discriminator(): return None - attribute_map = { - } - - _composed_schemas = {} + _composed_schemas = None required_properties = set([ '_data_store', From ed9f53bd2a7a831c44b63d6dc2437b1d2ee9e389 Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Tue, 2 Jun 2020 16:05:05 +0200 Subject: [PATCH 04/18] Reset samples --- .../.openapi-generator/FILES | 4 - .../petstore/python-experimental/README.md | 2 - .../petstore_api/api/__init__.py | 1 - .../petstore_api/apis/__init__.py | 1 - .../petstore_api/models/__init__.py | 1 - .../python-experimental/test/test_drawing.py | 133 +++++++++++- .../python-experimental/test/test_fruit.py | 180 ++++++++++++++++- .../test/test_fruit_req.py | 138 ++++++++++++- .../python-experimental/test/test_gm_fruit.py | 189 +++++++++++++++++- .../python-experimental/test/test_mammal.py | 13 +- .../test/test_outer_enum.py | 13 +- .../test/test_parent_pet.py | 9 +- .../test/test_quadrilateral.py | 7 +- .../python-experimental/test/test_shape.py | 67 ++++++- .../python-experimental/test/test_tag.py | 2 +- .../python-experimental/test/test_triangle.py | 9 +- 16 files changed, 717 insertions(+), 52 deletions(-) diff --git a/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES index 6069bc6566db..ffc326a12f08 100644 --- a/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES @@ -5,7 +5,6 @@ README.md docs/AdditionalPropertiesClass.md docs/Address.md docs/Animal.md -docs/AnimalFarm.md docs/AnotherFakeApi.md docs/ApiResponse.md docs/Apple.md @@ -36,7 +35,6 @@ docs/EnumTest.md docs/EquilateralTriangle.md docs/FakeApi.md docs/FakeClassnameTags123Api.md -docs/FarmApi.md docs/File.md docs/FileSchemaTestClass.md docs/Foo.md @@ -100,7 +98,6 @@ petstore_api/api/another_fake_api.py petstore_api/api/default_api.py petstore_api/api/fake_api.py petstore_api/api/fake_classname_tags_123_api.py -petstore_api/api/farm_api.py petstore_api/api/pet_api.py petstore_api/api/store_api.py petstore_api/api/user_api.py @@ -112,7 +109,6 @@ petstore_api/model/__init__.py petstore_api/model/additional_properties_class.py petstore_api/model/address.py petstore_api/model/animal.py -petstore_api/model/animal_farm.py petstore_api/model/api_response.py petstore_api/model/apple.py petstore_api/model/apple_req.py diff --git a/samples/openapi3/client/petstore/python-experimental/README.md b/samples/openapi3/client/petstore/python-experimental/README.md index 622ac9805d8b..a542d727b93d 100644 --- a/samples/openapi3/client/petstore/python-experimental/README.md +++ b/samples/openapi3/client/petstore/python-experimental/README.md @@ -97,7 +97,6 @@ Class | Method | HTTP request | Description *FakeApi* | [**test_json_form_data**](docs/FakeApi.md#test_json_form_data) | **GET** /fake/jsonFormData | test json serialization of form data *FakeApi* | [**test_query_parameter_collection_format**](docs/FakeApi.md#test_query_parameter_collection_format) | **PUT** /fake/test-query-paramters | *FakeClassnameTags123Api* | [**test_classname**](docs/FakeClassnameTags123Api.md#test_classname) | **PATCH** /fake_classname_test | To test class name in snake case -*FarmApi* | [**farm**](docs/FarmApi.md#farm) | **GET** /farm/animals | Animal Farm *PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **POST** /pet | Add a new pet to the store *PetApi* | [**delete_pet**](docs/PetApi.md#delete_pet) | **DELETE** /pet/{petId} | Deletes a pet *PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status) | **GET** /pet/findByStatus | Finds Pets by status @@ -126,7 +125,6 @@ Class | Method | HTTP request | Description - [additional_properties_class.AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md) - [address.Address](docs/Address.md) - [animal.Animal](docs/Animal.md) - - [animal_farm.AnimalFarm](docs/AnimalFarm.md) - [api_response.ApiResponse](docs/ApiResponse.md) - [apple.Apple](docs/Apple.md) - [apple_req.AppleReq](docs/AppleReq.md) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/__init__.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/__init__.py index 1d2f2d52b4fd..fa4e54a80091 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/__init__.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/__init__.py @@ -7,7 +7,6 @@ from petstore_api.api.default_api import DefaultApi from petstore_api.api.fake_api import FakeApi from petstore_api.api.fake_classname_tags_123_api import FakeClassnameTags123Api -from petstore_api.api.farm_api import FarmApi from petstore_api.api.pet_api import PetApi from petstore_api.api.store_api import StoreApi from petstore_api.api.user_api import UserApi diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/__init__.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/__init__.py index 19871fa18210..41cbd0aa055e 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/__init__.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/__init__.py @@ -16,7 +16,6 @@ from petstore_api.api.default_api import DefaultApi from petstore_api.api.fake_api import FakeApi from petstore_api.api.fake_classname_tags_123_api import FakeClassnameTags123Api -from petstore_api.api.farm_api import FarmApi from petstore_api.api.pet_api import PetApi from petstore_api.api.store_api import StoreApi from petstore_api.api.user_api import UserApi 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 018302a720ba..7c58ced9f86a 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 @@ -14,7 +14,6 @@ from petstore_api.model.additional_properties_class import AdditionalPropertiesClass from petstore_api.model.address import Address from petstore_api.model.animal import Animal -from petstore_api.model.animal_farm import AnimalFarm from petstore_api.model.api_response import ApiResponse from petstore_api.model.apple import Apple from petstore_api.model.apple_req import AppleReq diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_drawing.py b/samples/openapi3/client/petstore/python-experimental/test/test_drawing.py index e4997e48f9ff..dbfba3ea700f 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_drawing.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_drawing.py @@ -15,11 +15,6 @@ import unittest import petstore_api -try: - from petstore_api.model import fruit -except ImportError: - fruit = sys.modules[ - 'petstore_api.model.fruit'] try: from petstore_api.model import nullable_shape except ImportError: @@ -47,12 +42,130 @@ def setUp(self): def tearDown(self): pass - def testDrawing(self): - """Test Drawing""" - # FIXME: construct object with mandatory attributes with example values - # model = Drawing() # noqa: E501 - pass + def test_create_instances(self): + """ + Validate instance can be created using pythonic name or OAS names. + """ + + # Validate object can be created using pythonic names. + inst = shape.Shape( + shape_type="Triangle", + triangle_type="IsoscelesTriangle" + ) + from petstore_api.model.isosceles_triangle import IsoscelesTriangle + assert isinstance(inst, IsoscelesTriangle) + + # Validate object can be created using OAS names. + # For example, this can be used to construct objects on the client + # when the input data is available as JSON documents. + data = { + 'shapeType': "Triangle", + 'triangleType': "IsoscelesTriangle" + } + inst = shape.Shape(_spec_property_naming=True, **data) + assert isinstance(inst, IsoscelesTriangle) + + def test_deserialize_oneof_reference(self): + """ + Validate the scenario when the type of a OAS property is 'oneOf', and the 'oneOf' + schema is specified as a reference ($ref), not an inline 'oneOf' schema. + """ + isosceles_triangle = shape.Shape( + shape_type="Triangle", + triangle_type="IsoscelesTriangle" + ) + from petstore_api.model.isosceles_triangle import IsoscelesTriangle + from petstore_api.model.triangle import Triangle + from petstore_api.model.equilateral_triangle import EquilateralTriangle + + assert isinstance(isosceles_triangle, IsoscelesTriangle) + inst = Drawing( + # 'main_shape' has type 'Shape', which is a oneOf [triangle, quadrilateral] + # composed schema. So we should be able to assign a petstore_api.Triangle + # to a 'main_shape'. + main_shape=isosceles_triangle, + shapes=[ + shape.Shape( + shape_type="Triangle", + triangle_type="EquilateralTriangle" + ), + Triangle( + shape_type="Triangle", + triangle_type="IsoscelesTriangle" + ), + EquilateralTriangle( + shape_type="Triangle", + triangle_type="EquilateralTriangle" + ), + shape.Shape( + shape_type="Quadrilateral", + quadrilateral_type="ComplexQuadrilateral" + ), + ], + ) + from petstore_api.model.complex_quadrilateral import ComplexQuadrilateral + assert isinstance(inst, Drawing) + assert isinstance(inst.main_shape, IsoscelesTriangle) + self.assertEqual(len(inst.shapes), 4) + assert isinstance(inst.shapes[0], EquilateralTriangle) + assert isinstance(inst.shapes[1], IsoscelesTriangle) + assert isinstance(inst.shapes[2], EquilateralTriangle) + assert isinstance(inst.shapes[3], ComplexQuadrilateral) + + # Validate we cannot assign the None value to main_shape because the 'null' type + # is not one of the allowed types in the 'Shape' schema. + err_msg = ("Invalid type for variable '{}'. " + "Required value type is {} and passed type was {} at {}") + with self.assertRaisesRegexp( + petstore_api.ApiTypeError, + err_msg.format("main_shape", "Shape", "NoneType", "\['main_shape'\]") + ): + inst = Drawing( + # 'main_shape' has type 'Shape', which is a oneOf [triangle, quadrilateral] + # So the None value should not be allowed and an exception should be raised. + main_shape=None, + ) + + + def test_deserialize_oneof_reference_with_null_type(self): + """ + Validate the scenario when the type of a OAS property is 'oneOf', and the 'oneOf' + schema is specified as a reference ($ref), not an inline 'oneOf' schema. + Further, the 'oneOf' schema has a 'null' type child schema (as introduced in + OpenAPI 3.1). + """ + + # Validate we can assign the None value to shape_or_null, because the 'null' type + # is one of the allowed types in the 'ShapeOrNull' schema. + inst = Drawing( + # 'shape_or_null' has type 'ShapeOrNull', which is a oneOf [null, triangle, quadrilateral] + shape_or_null=None, + ) + assert isinstance(inst, Drawing) + self.assertFalse(hasattr(inst, 'main_shape')) + self.assertTrue(hasattr(inst, 'shape_or_null')) + self.assertIsNone(inst.shape_or_null) + + + def test_deserialize_oneof_reference_with_nullable_type(self): + """ + Validate the scenario when the type of a OAS property is 'oneOf', and the 'oneOf' + schema is specified as a reference ($ref), not an inline 'oneOf' schema. + Further, the 'oneOf' schema has the 'nullable' attribute (as introduced in + OpenAPI 3.0 and deprecated in 3.1). + """ + # Validate we can assign the None value to nullable_shape, because the NullableShape + # has the 'nullable: true' attribute. + inst = Drawing( + # 'nullable_shape' has type 'NullableShape', which is a oneOf [triangle, quadrilateral] + # and the 'nullable: true' attribute. + nullable_shape=None, + ) + assert isinstance(inst, Drawing) + self.assertFalse(hasattr(inst, 'main_shape')) + self.assertTrue(hasattr(inst, 'nullable_shape')) + self.assertIsNone(inst.nullable_shape) if __name__ == '__main__': unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_fruit.py b/samples/openapi3/client/petstore/python-experimental/test/test_fruit.py index e02319bb6ff6..1eb9d09d5061 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_fruit.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_fruit.py @@ -39,10 +39,184 @@ def tearDown(self): def testFruit(self): """Test Fruit""" - # FIXME: construct object with mandatory attributes with example values - # model = Fruit() # noqa: E501 - pass + # make an instance of Fruit, a composed schema oneOf model + # banana test + length_cm = 20.3 + color = 'yellow' + fruit = Fruit(length_cm=length_cm, color=color) + # check its properties + self.assertEqual(fruit.length_cm, length_cm) + self.assertEqual(fruit['length_cm'], length_cm) + self.assertEqual(getattr(fruit, 'length_cm'), length_cm) + self.assertEqual(fruit.color, color) + self.assertEqual(fruit['color'], color) + self.assertEqual(getattr(fruit, 'color'), color) + # check the dict representation + self.assertEqual( + fruit.to_dict(), + { + 'length_cm': length_cm, + 'color': color + } + ) + # setting a value that doesn't exist raises an exception + # with a key + with self.assertRaises(AttributeError): + fruit['invalid_variable'] = 'some value' + + # Assert that we can call the builtin hasattr() function. + # hasattr should return False for non-existent attribute. + # Internally hasattr catches the AttributeError exception. + self.assertFalse(hasattr(fruit, 'invalid_variable')) + + # Assert that we can call the builtin hasattr() function. + # hasattr should return True for existent attribute. + self.assertTrue(hasattr(fruit, 'color')) + + # with setattr + with self.assertRaises(AttributeError): + setattr(fruit, 'invalid_variable', 'some value') + + # getting a value that doesn't exist raises an exception + # with a key + with self.assertRaises(AttributeError): + invalid_variable = fruit['cultivar'] + # with getattr + # Per Python doc, if the named attribute does not exist, + # default is returned if provided. + self.assertEqual(getattr(fruit, 'cultivar', 'some value'), 'some value') + + # Per Python doc, if the named attribute does not exist, + # default is returned if provided, otherwise AttributeError is raised. + with self.assertRaises(AttributeError): + getattr(fruit, 'cultivar') + + # make sure that the ModelComposed class properties are correct + # model._composed_schemas stores the anyOf/allOf/oneOf info + self.assertEqual( + fruit._composed_schemas, + { + 'anyOf': [], + 'allOf': [], + 'oneOf': [ + apple.Apple, + banana.Banana, + ], + } + ) + # model._composed_instances is a list of the instances that were + # made from the anyOf/allOf/OneOf classes in model._composed_schemas + for composed_instance in fruit._composed_instances: + if composed_instance.__class__ == banana.Banana: + banana_instance = composed_instance + self.assertEqual( + fruit._composed_instances, + [banana_instance] + ) + # model._var_name_to_model_instances maps the variable name to the + # model instances which store that variable + self.assertEqual( + fruit._var_name_to_model_instances, + { + 'color': [fruit], + 'length_cm': [fruit, banana_instance], + 'cultivar': [fruit], + 'origin': [fruit], + } + ) + # model._additional_properties_model_instances stores a list of + # models which have the property additional_properties_type != None + self.assertEqual( + fruit._additional_properties_model_instances, [] + ) + + # if we modify one of the properties owned by multiple + # model_instances we get an exception when we try to access that + # property because the retrieved values are not all the same + banana_instance.length_cm = 4.56 + with self.assertRaises(petstore_api.ApiValueError): + some_length_cm = fruit.length_cm + + # including extra parameters raises an exception + with self.assertRaises(petstore_api.ApiValueError): + fruit = Fruit( + color=color, + length_cm=length_cm, + unknown_property='some value' + ) + + # including input parameters for two oneOf instances raise an exception + with self.assertRaises(petstore_api.ApiValueError): + fruit = Fruit( + length_cm=length_cm, + cultivar='granny smith' + ) + + # make an instance of Fruit, a composed schema oneOf model + # apple test + color = 'red' + cultivar = 'golden delicious' + fruit = Fruit(color=color, cultivar=cultivar) + # check its properties + self.assertEqual(fruit.color, color) + self.assertEqual(fruit['color'], color) + self.assertEqual(getattr(fruit, 'color'), color) + self.assertEqual(fruit.cultivar, cultivar) + self.assertEqual(fruit['cultivar'], cultivar) + self.assertEqual(getattr(fruit, 'cultivar'), cultivar) + # check the dict representation + self.assertEqual( + fruit.to_dict(), + { + 'color': color, + 'cultivar': cultivar + } + ) + + # model._composed_instances is a list of the instances that were + # made from the anyOf/allOf/OneOf classes in model._composed_schemas + for composed_instance in fruit._composed_instances: + if composed_instance.__class__ == apple.Apple: + apple_instance = composed_instance + self.assertEqual( + fruit._composed_instances, + [apple_instance] + ) + # model._var_name_to_model_instances maps the variable name to the + # model instances which store that variable + self.assertEqual( + fruit._var_name_to_model_instances, + { + 'color': [fruit], + 'length_cm': [fruit], + 'cultivar': [fruit, apple_instance], + 'origin': [fruit, apple_instance], + } + ) + # model._additional_properties_model_instances stores a list of + # models which have the property additional_properties_type != None + self.assertEqual( + fruit._additional_properties_model_instances, [] + ) + + def testFruitNullValue(self): + # Since 'apple' is nullable, validate we can create an apple with the 'null' value. + fruit = apple.Apple(None) + self.assertIsNone(fruit) + + # 'banana' is not nullable. + with self.assertRaises(petstore_api.ApiTypeError): + banana.Banana(None) + + # Since 'fruit' has oneOf 'apple', 'banana' and 'apple' is nullable, + # validate we can create a fruit with the 'null' value. + fruit = Fruit(None) + self.assertIsNone(fruit) + + # Redo the same thing, this time passing a null Apple to the Fruit constructor. + fruit = Fruit(apple.Apple(None)) + self.assertIsNone(fruit) if __name__ == '__main__': unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_fruit_req.py b/samples/openapi3/client/petstore/python-experimental/test/test_fruit_req.py index 79f23dea6313..3a1aa8fc283b 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_fruit_req.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_fruit_req.py @@ -39,10 +39,142 @@ def tearDown(self): def testFruitReq(self): """Test FruitReq""" - # FIXME: construct object with mandatory attributes with example values - # model = FruitReq() # noqa: E501 - pass + # make an instance of Fruit, a composed schema oneOf model + # banana test + length_cm = 20.3 + fruit = FruitReq(length_cm=length_cm) + # check its properties + self.assertEqual(fruit.length_cm, length_cm) + self.assertEqual(fruit['length_cm'], length_cm) + self.assertEqual(getattr(fruit, 'length_cm'), length_cm) + # check the dict representation + self.assertEqual( + fruit.to_dict(), + { + 'length_cm': length_cm, + } + ) + # setting a value that doesn't exist raises an exception + # with a key + with self.assertRaises(AttributeError): + fruit['invalid_variable'] = 'some value' + # with setattr + with self.assertRaises(AttributeError): + setattr(fruit, 'invalid_variable', 'some value') + + # getting a value that doesn't exist raises an exception + # with a key + with self.assertRaises(AttributeError): + invalid_variable = fruit['cultivar'] + # with getattr + self.assertEqual(getattr(fruit, 'cultivar', 'some value'), 'some value') + + with self.assertRaises(AttributeError): + getattr(fruit, 'cultivar') + + # make sure that the ModelComposed class properties are correct + # model._composed_schemas stores the anyOf/allOf/oneOf info + self.assertEqual( + fruit._composed_schemas, + { + 'anyOf': [], + 'allOf': [], + 'oneOf': [ + apple_req.AppleReq, + banana_req.BananaReq, + type(None), + ], + } + ) + # model._composed_instances is a list of the instances that were + # made from the anyOf/allOf/OneOf classes in model._composed_schemas + for composed_instance in fruit._composed_instances: + if composed_instance.__class__ == banana_req.BananaReq: + banana_instance = composed_instance + self.assertEqual( + fruit._composed_instances, + [banana_instance] + ) + # model._var_name_to_model_instances maps the variable name to the + # model instances which store that variable + self.assertEqual( + fruit._var_name_to_model_instances, + { + 'length_cm': [fruit, banana_instance], + 'cultivar': [fruit], + 'mealy': [fruit], + 'sweet': [fruit, banana_instance], + } + ) + # model._additional_properties_model_instances stores a list of + # models which have the property additional_properties_type != None + self.assertEqual( + fruit._additional_properties_model_instances, [] + ) + + # if we modify one of the properties owned by multiple + # model_instances we get an exception when we try to access that + # property because the retrieved values are not all the same + banana_instance.length_cm = 4.56 + with self.assertRaises(petstore_api.ApiValueError): + some_length_cm = fruit.length_cm + + # including extra parameters raises an exception + with self.assertRaises(petstore_api.ApiValueError): + fruit = FruitReq( + length_cm=length_cm, + unknown_property='some value' + ) + + # including input parameters for two oneOf instances raise an exception + with self.assertRaises(petstore_api.ApiValueError): + fruit = FruitReq( + length_cm=length_cm, + cultivar='granny smith' + ) + + # make an instance of Fruit, a composed schema oneOf model + # apple test + cultivar = 'golden delicious' + fruit = FruitReq(cultivar=cultivar) + # check its properties + self.assertEqual(fruit.cultivar, cultivar) + self.assertEqual(fruit['cultivar'], cultivar) + self.assertEqual(getattr(fruit, 'cultivar'), cultivar) + # check the dict representation + self.assertEqual( + fruit.to_dict(), + { + 'cultivar': cultivar + } + ) + + # model._composed_instances is a list of the instances that were + # made from the anyOf/allOf/OneOf classes in model._composed_schemas + for composed_instance in fruit._composed_instances: + if composed_instance.__class__ == apple_req.AppleReq: + apple_instance = composed_instance + self.assertEqual( + fruit._composed_instances, + [apple_instance] + ) + # model._var_name_to_model_instances maps the variable name to the + # model instances which store that variable + self.assertEqual( + fruit._var_name_to_model_instances, + { + 'length_cm': [fruit], + 'cultivar': [fruit, apple_instance], + 'mealy': [fruit, apple_instance], + 'sweet': [fruit], + } + ) + # model._additional_properties_model_instances stores a list of + # models which have the property additional_properties_type != None + self.assertEqual( + fruit._additional_properties_model_instances, [] + ) if __name__ == '__main__': unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_gm_fruit.py b/samples/openapi3/client/petstore/python-experimental/test/test_gm_fruit.py index eddeea0b8f28..9d13e90659d0 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_gm_fruit.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_gm_fruit.py @@ -39,10 +39,193 @@ def tearDown(self): def testGmFruit(self): """Test GmFruit""" - # FIXME: construct object with mandatory attributes with example values - # model = GmFruit() # noqa: E501 - pass + # make an instance of GmFruit, a composed schema anyOf model + # banana test + length_cm = 20.3 + color = 'yellow' + fruit = GmFruit(length_cm=length_cm, color=color) + # check its properties + self.assertEqual(fruit.length_cm, length_cm) + self.assertEqual(fruit['length_cm'], length_cm) + self.assertEqual(getattr(fruit, 'length_cm'), length_cm) + self.assertEqual(fruit.color, color) + self.assertEqual(fruit['color'], color) + self.assertEqual(getattr(fruit, 'color'), color) + # check the dict representation + self.assertEqual( + fruit.to_dict(), + { + 'length_cm': length_cm, + 'color': color + } + ) + # setting a value that doesn't exist raises an exception + # with a key + with self.assertRaises(AttributeError): + fruit['invalid_variable'] = 'some value' + # with setattr + with self.assertRaises(AttributeError): + setattr(fruit, 'invalid_variable', 'some value') + + # getting a value that doesn't exist raises an exception + # with a key + with self.assertRaises(AttributeError): + invalid_variable = fruit['cultivar'] + # with getattr + self.assertTrue(getattr(fruit, 'cultivar', 'some value'), 'some value') + + with self.assertRaises(AttributeError): + invalid_variable = getattr(fruit, 'cultivar') + + # make sure that the ModelComposed class properties are correct + # model._composed_schemas stores the anyOf/allOf/oneOf info + self.assertEqual( + fruit._composed_schemas, + { + 'anyOf': [ + apple.Apple, + banana.Banana, + ], + 'allOf': [], + 'oneOf': [], + } + ) + # model._composed_instances is a list of the instances that were + # made from the anyOf/allOf/OneOf classes in model._composed_schemas + for composed_instance in fruit._composed_instances: + if composed_instance.__class__ == banana.Banana: + banana_instance = composed_instance + self.assertEqual( + fruit._composed_instances, + [banana_instance] + ) + # model._var_name_to_model_instances maps the variable name to the + # model instances which store that variable + self.assertEqual( + fruit._var_name_to_model_instances, + { + 'color': [fruit], + 'length_cm': [fruit, banana_instance], + 'cultivar': [fruit], + 'origin': [fruit], + } + ) + # model._additional_properties_model_instances stores a list of + # models which have the property additional_properties_type != None + self.assertEqual( + fruit._additional_properties_model_instances, [] + ) + + # if we modify one of the properties owned by multiple + # model_instances we get an exception when we try to access that + # property because the retrieved values are not all the same + banana_instance.length_cm = 4.56 + with self.assertRaises(petstore_api.ApiValueError): + some_length_cm = fruit.length_cm + + # including extra parameters raises an exception + with self.assertRaises(petstore_api.ApiValueError): + fruit = GmFruit( + color=color, + length_cm=length_cm, + unknown_property='some value' + ) + + # including input parameters for both anyOf instances works + cultivar = 'banaple' + color = 'orange' + fruit = GmFruit( + color=color, + cultivar=cultivar, + length_cm=length_cm + ) + self.assertEqual(fruit.color, color) + self.assertEqual(fruit['color'], color) + self.assertEqual(getattr(fruit, 'color'), color) + self.assertEqual(fruit.cultivar, cultivar) + self.assertEqual(fruit['cultivar'], cultivar) + self.assertEqual(getattr(fruit, 'cultivar'), cultivar) + self.assertEqual(fruit.length_cm, length_cm) + self.assertEqual(fruit['length_cm'], length_cm) + self.assertEqual(getattr(fruit, 'length_cm'), length_cm) + + # model._composed_instances is a list of the instances that were + # made from the anyOf/allOf/OneOf classes in model._composed_schemas + for composed_instance in fruit._composed_instances: + if composed_instance.__class__ == apple.Apple: + apple_instance = composed_instance + elif composed_instance.__class__ == banana.Banana: + banana_instance = composed_instance + self.assertEqual( + fruit._composed_instances, + [apple_instance, banana_instance] + ) + # model._var_name_to_model_instances maps the variable name to the + # model instances which store that variable + self.assertEqual( + fruit._var_name_to_model_instances, + { + 'color': [fruit], + 'length_cm': [fruit, banana_instance], + 'cultivar': [fruit, apple_instance], + 'origin': [fruit, apple_instance], + } + ) + + # make an instance of GmFruit, a composed schema anyOf model + # apple test + color = 'red' + cultivar = 'golden delicious' + origin = 'California' + fruit = GmFruit(color=color, cultivar=cultivar, origin=origin) + # check its properties + self.assertEqual(fruit.color, color) + self.assertEqual(fruit['color'], color) + self.assertEqual(getattr(fruit, 'color'), color) + self.assertEqual(fruit.cultivar, cultivar) + self.assertEqual(fruit['cultivar'], cultivar) + self.assertEqual(getattr(fruit, 'cultivar'), cultivar) + + self.assertEqual(fruit.origin, origin) + self.assertEqual(fruit['origin'], origin) + self.assertEqual(getattr(fruit, 'origin'), origin) + + # check the dict representation + self.assertEqual( + fruit.to_dict(), + { + 'color': color, + 'cultivar': cultivar, + 'origin': origin, + } + ) + + # model._composed_instances is a list of the instances that were + # made from the anyOf/allOf/OneOf classes in model._composed_schemas + for composed_instance in fruit._composed_instances: + if composed_instance.__class__ == apple.Apple: + apple_instance = composed_instance + self.assertEqual( + fruit._composed_instances, + [apple_instance] + ) + # model._var_name_to_model_instances maps the variable name to the + # model instances which store that variable + self.assertEqual( + fruit._var_name_to_model_instances, + { + 'color': [fruit], + 'length_cm': [fruit], + 'cultivar': [fruit, apple_instance], + 'origin': [fruit, apple_instance], + } + ) + # model._additional_properties_model_instances stores a list of + # models which have the property additional_properties_type != None + self.assertEqual( + fruit._additional_properties_model_instances, [] + ) if __name__ == '__main__': unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_mammal.py b/samples/openapi3/client/petstore/python-experimental/test/test_mammal.py index 2d482aef29d2..2a8893d02fb3 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_mammal.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_mammal.py @@ -15,11 +15,6 @@ import unittest import petstore_api -try: - from petstore_api.model import pig -except ImportError: - pig = sys.modules[ - 'petstore_api.model.pig'] try: from petstore_api.model import whale except ImportError: @@ -44,9 +39,11 @@ def tearDown(self): def testMammal(self): """Test Mammal""" - # FIXME: construct object with mandatory attributes with example values - # model = Mammal() # noqa: E501 - pass + + # tests that we can make a BasquePig by traveling through descendant discriminator in Pig + model = Mammal(class_name="BasquePig") + from petstore_api.model import basque_pig + assert isinstance(model, basque_pig.BasquePig) if __name__ == '__main__': diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_outer_enum.py b/samples/openapi3/client/petstore/python-experimental/test/test_outer_enum.py index b9423fb81e58..ab9dac9d612b 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_outer_enum.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_outer_enum.py @@ -29,9 +29,16 @@ def tearDown(self): def testOuterEnum(self): """Test OuterEnum""" - # FIXME: construct object with mandatory attributes with example values - # model = OuterEnum() # noqa: E501 - pass + # Since 'OuterEnum' is nullable, validate the null value can be assigned + # to OuterEnum. + inst = OuterEnum(None) + self.assertIsNone(inst) + + inst = OuterEnum('approved') + assert isinstance(inst, OuterEnum) + + with self.assertRaises(petstore_api.ApiValueError): + OuterEnum('garbage') if __name__ == '__main__': diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_parent_pet.py b/samples/openapi3/client/petstore/python-experimental/test/test_parent_pet.py index 5268a00d9a87..15262872e195 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_parent_pet.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_parent_pet.py @@ -39,9 +39,12 @@ def tearDown(self): def testParentPet(self): """Test ParentPet""" - # FIXME: construct object with mandatory attributes with example values - # model = ParentPet() # noqa: E501 - pass + + # test that we can make a ParentPet from a ParentPet + # which requires that we travel back through ParentPet's allOf descendant + # GrandparentAnimal, and we use the descendant's discriminator to make ParentPet + model = ParentPet(pet_type="ParentPet") + assert isinstance(model, ParentPet) if __name__ == '__main__': diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_quadrilateral.py b/samples/openapi3/client/petstore/python-experimental/test/test_quadrilateral.py index 64871ac5203c..149b9a0070b6 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_quadrilateral.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_quadrilateral.py @@ -39,9 +39,10 @@ def tearDown(self): def testQuadrilateral(self): """Test Quadrilateral""" - # FIXME: construct object with mandatory attributes with example values - # model = Quadrilateral() # noqa: E501 - pass + instance = Quadrilateral(shape_type="Quadrilateral", quadrilateral_type="ComplexQuadrilateral") + assert isinstance(instance, complex_quadrilateral.ComplexQuadrilateral) + instance = Quadrilateral(shape_type="Quadrilateral", quadrilateral_type="SimpleQuadrilateral") + assert isinstance(instance, simple_quadrilateral.SimpleQuadrilateral) if __name__ == '__main__': diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_shape.py b/samples/openapi3/client/petstore/python-experimental/test/test_shape.py index 100eaab7cc07..4424679aeccb 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_shape.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_shape.py @@ -39,10 +39,71 @@ def tearDown(self): def testShape(self): """Test Shape""" - # FIXME: construct object with mandatory attributes with example values - # model = Shape() # noqa: E501 - pass + from petstore_api.model import complex_quadrilateral + from petstore_api.model import simple_quadrilateral + from petstore_api.model import equilateral_triangle + from petstore_api.model import isosceles_triangle + from petstore_api.model import scalene_triangle + tri = triangle.Triangle( + shape_type="Triangle", + triangle_type="EquilateralTriangle" + ) + assert isinstance(tri, equilateral_triangle.EquilateralTriangle) + + tri = triangle.Triangle( + shape_type="Triangle", + triangle_type="IsoscelesTriangle" + ) + assert isinstance(tri, isosceles_triangle.IsoscelesTriangle) + + tri = triangle.Triangle( + shape_type="Triangle", + triangle_type="ScaleneTriangle" + ) + assert isinstance(tri, scalene_triangle.ScaleneTriangle) + + quad = Shape( + shape_type="Quadrilateral", + quadrilateral_type="ComplexQuadrilateral" + ) + assert isinstance(quad, complex_quadrilateral.ComplexQuadrilateral) + + quad = Shape( + shape_type="Quadrilateral", + quadrilateral_type="SimpleQuadrilateral" + ) + assert isinstance(quad, simple_quadrilateral.SimpleQuadrilateral) + + # No discriminator provided. + err_msg = ("Cannot deserialize input data due to missing discriminator. " + "The discriminator property '{}' is missing at path: ()" + ) + with self.assertRaisesRegexp( + petstore_api.ApiValueError, + err_msg.format("shapeType") + ): + Shape() + + # invalid shape_type (first discriminator). 'Circle' does not exist in the model. + err_msg = ("Cannot deserialize input data due to invalid discriminator " + "value. The OpenAPI document has no mapping for discriminator " + "property '{}'='{}' at path: ()" + ) + with self.assertRaisesRegexp( + petstore_api.ApiValueError, + err_msg.format("shapeType", "Circle") + ): + Shape(shape_type="Circle") + # invalid quadrilateral_type (second discriminator) + with self.assertRaisesRegexp( + petstore_api.ApiValueError, + err_msg.format("quadrilateralType", "Triangle") + ): + Shape( + shape_type="Quadrilateral", + quadrilateral_type="Triangle" + ) if __name__ == '__main__': unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_tag.py b/samples/openapi3/client/petstore/python-experimental/test/test_tag.py index 68a3b9046bf4..b0a09d94a785 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_tag.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_tag.py @@ -11,7 +11,7 @@ from __future__ import absolute_import -import sys + import unittest import petstore_api diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_triangle.py b/samples/openapi3/client/petstore/python-experimental/test/test_triangle.py index 84cbfe0c7051..65ae20743e14 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_triangle.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_triangle.py @@ -44,9 +44,12 @@ def tearDown(self): def testTriangle(self): """Test Triangle""" - # FIXME: construct object with mandatory attributes with example values - # model = Triangle() # noqa: E501 - pass + tri = Triangle(shape_type="Triangle", triangle_type="EquilateralTriangle") + assert isinstance(tri, equilateral_triangle.EquilateralTriangle) + tri = Triangle(shape_type="Triangle", triangle_type="IsoscelesTriangle") + assert isinstance(tri, isosceles_triangle.IsoscelesTriangle) + tri = Triangle(shape_type="Triangle", triangle_type="ScaleneTriangle") + assert isinstance(tri, scalene_triangle.ScaleneTriangle) if __name__ == '__main__': From 9b393c690b1295a380a9bf283e0407e0e61dbf50 Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Tue, 2 Jun 2020 16:08:48 +0200 Subject: [PATCH 05/18] Regenerated --- .../petstore/python-experimental/.openapi-generator/FILES | 4 ++++ .../openapi3/client/petstore/python-experimental/README.md | 2 ++ .../petstore/python-experimental/petstore_api/api/__init__.py | 1 + .../python-experimental/petstore_api/apis/__init__.py | 1 + .../python-experimental/petstore_api/models/__init__.py | 1 + 5 files changed, 9 insertions(+) diff --git a/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES index ffc326a12f08..6069bc6566db 100644 --- a/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES @@ -5,6 +5,7 @@ README.md docs/AdditionalPropertiesClass.md docs/Address.md docs/Animal.md +docs/AnimalFarm.md docs/AnotherFakeApi.md docs/ApiResponse.md docs/Apple.md @@ -35,6 +36,7 @@ docs/EnumTest.md docs/EquilateralTriangle.md docs/FakeApi.md docs/FakeClassnameTags123Api.md +docs/FarmApi.md docs/File.md docs/FileSchemaTestClass.md docs/Foo.md @@ -98,6 +100,7 @@ petstore_api/api/another_fake_api.py petstore_api/api/default_api.py petstore_api/api/fake_api.py petstore_api/api/fake_classname_tags_123_api.py +petstore_api/api/farm_api.py petstore_api/api/pet_api.py petstore_api/api/store_api.py petstore_api/api/user_api.py @@ -109,6 +112,7 @@ petstore_api/model/__init__.py petstore_api/model/additional_properties_class.py petstore_api/model/address.py petstore_api/model/animal.py +petstore_api/model/animal_farm.py petstore_api/model/api_response.py petstore_api/model/apple.py petstore_api/model/apple_req.py diff --git a/samples/openapi3/client/petstore/python-experimental/README.md b/samples/openapi3/client/petstore/python-experimental/README.md index a542d727b93d..622ac9805d8b 100644 --- a/samples/openapi3/client/petstore/python-experimental/README.md +++ b/samples/openapi3/client/petstore/python-experimental/README.md @@ -97,6 +97,7 @@ Class | Method | HTTP request | Description *FakeApi* | [**test_json_form_data**](docs/FakeApi.md#test_json_form_data) | **GET** /fake/jsonFormData | test json serialization of form data *FakeApi* | [**test_query_parameter_collection_format**](docs/FakeApi.md#test_query_parameter_collection_format) | **PUT** /fake/test-query-paramters | *FakeClassnameTags123Api* | [**test_classname**](docs/FakeClassnameTags123Api.md#test_classname) | **PATCH** /fake_classname_test | To test class name in snake case +*FarmApi* | [**farm**](docs/FarmApi.md#farm) | **GET** /farm/animals | Animal Farm *PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **POST** /pet | Add a new pet to the store *PetApi* | [**delete_pet**](docs/PetApi.md#delete_pet) | **DELETE** /pet/{petId} | Deletes a pet *PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status) | **GET** /pet/findByStatus | Finds Pets by status @@ -125,6 +126,7 @@ Class | Method | HTTP request | Description - [additional_properties_class.AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md) - [address.Address](docs/Address.md) - [animal.Animal](docs/Animal.md) + - [animal_farm.AnimalFarm](docs/AnimalFarm.md) - [api_response.ApiResponse](docs/ApiResponse.md) - [apple.Apple](docs/Apple.md) - [apple_req.AppleReq](docs/AppleReq.md) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/__init__.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/__init__.py index fa4e54a80091..1d2f2d52b4fd 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/__init__.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/__init__.py @@ -7,6 +7,7 @@ from petstore_api.api.default_api import DefaultApi from petstore_api.api.fake_api import FakeApi from petstore_api.api.fake_classname_tags_123_api import FakeClassnameTags123Api +from petstore_api.api.farm_api import FarmApi from petstore_api.api.pet_api import PetApi from petstore_api.api.store_api import StoreApi from petstore_api.api.user_api import UserApi diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/__init__.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/__init__.py index 41cbd0aa055e..19871fa18210 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/__init__.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/__init__.py @@ -16,6 +16,7 @@ from petstore_api.api.default_api import DefaultApi from petstore_api.api.fake_api import FakeApi from petstore_api.api.fake_classname_tags_123_api import FakeClassnameTags123Api +from petstore_api.api.farm_api import FarmApi from petstore_api.api.pet_api import PetApi from petstore_api.api.store_api import StoreApi from petstore_api.api.user_api import UserApi 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 7c58ced9f86a..018302a720ba 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 @@ -14,6 +14,7 @@ from petstore_api.model.additional_properties_class import AdditionalPropertiesClass from petstore_api.model.address import Address from petstore_api.model.animal import Animal +from petstore_api.model.animal_farm import AnimalFarm from petstore_api.model.api_response import ApiResponse from petstore_api.model.apple import Apple from petstore_api.model.apple_req import AppleReq From c1ee2a5d9250f23df687126ca76be3877cb6ca44 Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Tue, 2 Jun 2020 16:20:04 +0200 Subject: [PATCH 06/18] Animal farm test --- .../petstore/python-experimental/test/test_animal_farm.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_animal_farm.py b/samples/openapi3/client/petstore/python-experimental/test/test_animal_farm.py index 7117d42b430e..d0df47fdcd1f 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_animal_farm.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_animal_farm.py @@ -34,9 +34,9 @@ def tearDown(self): def testAnimalFarm(self): """Test AnimalFarm""" - # FIXME: construct object with mandatory attributes with example values - # model = AnimalFarm() # noqa: E501 - pass + animals = [animal.Animal(className="dog"), animal.Animal(className="cat")] + model = AnimalFarm(animals) + assert False if __name__ == '__main__': From 0b00e42da28343979167040abac520a3e8663f9d Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Tue, 2 Jun 2020 16:56:46 +0200 Subject: [PATCH 07/18] Array of enums --- ...odels-for-testing-with-http-signature.yaml | 14 +- .../.openapi-generator/FILES | 5 +- .../petstore/python-experimental/README.md | 3 +- .../python-experimental/docs/ArrayOfEnums.md | 9 + .../python-experimental/docs/FakeApi.md | 59 ++++++ .../petstore_api/api/__init__.py | 1 - .../petstore_api/api/fake_api.py | 104 +++++++++++ .../petstore_api/apis/__init__.py | 1 - .../petstore_api/model/array_of_enums.py | 168 ++++++++++++++++++ .../petstore_api/models/__init__.py | 1 + .../test/test_array_of_enums.py | 43 +++++ .../tests/test_api_validation.py | 7 + 12 files changed, 405 insertions(+), 10 deletions(-) create mode 100644 samples/openapi3/client/petstore/python-experimental/docs/ArrayOfEnums.md create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_of_enums.py create mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_array_of_enums.py 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 38c0c9249b50..effef037e0e4 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 @@ -1097,19 +1097,19 @@ paths: application/json: schema: $ref: '#/components/schemas/HealthCheckResult' - /farm/animals: + /fake/array-of-enums: get: tags: - - farm - summary: Animal Farm - operationId: farm + - fake + summary: Array of Enums + operationId: getArrayOfEnums responses: 200: description: Got named array of enums content: application/json: schema: - $ref: '#/components/schemas/AnimalFarm' + $ref: '#/components/schemas/ArrayOfEnums' servers: - url: 'http://{server}.swagger.io:{port}/v2' description: petstore server @@ -2082,3 +2082,7 @@ components: properties: name: type: string + ArrayOfEnums: + type: array + items: + $ref: '#/components/schemas/OuterEnum' diff --git a/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES index 6069bc6566db..3f05d37a37bf 100644 --- a/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES @@ -11,6 +11,7 @@ docs/ApiResponse.md docs/Apple.md docs/AppleReq.md docs/ArrayOfArrayOfNumberOnly.md +docs/ArrayOfEnums.md docs/ArrayOfNumberOnly.md docs/ArrayTest.md docs/Banana.md @@ -36,7 +37,6 @@ docs/EnumTest.md docs/EquilateralTriangle.md docs/FakeApi.md docs/FakeClassnameTags123Api.md -docs/FarmApi.md docs/File.md docs/FileSchemaTestClass.md docs/Foo.md @@ -100,7 +100,6 @@ petstore_api/api/another_fake_api.py petstore_api/api/default_api.py petstore_api/api/fake_api.py petstore_api/api/fake_classname_tags_123_api.py -petstore_api/api/farm_api.py petstore_api/api/pet_api.py petstore_api/api/store_api.py petstore_api/api/user_api.py @@ -117,6 +116,7 @@ petstore_api/model/api_response.py petstore_api/model/apple.py petstore_api/model/apple_req.py petstore_api/model/array_of_array_of_number_only.py +petstore_api/model/array_of_enums.py petstore_api/model/array_of_number_only.py petstore_api/model/array_test.py petstore_api/model/banana.py @@ -201,4 +201,5 @@ setup.cfg setup.py test-requirements.txt test/__init__.py +test/test_fake_api.py tox.ini diff --git a/samples/openapi3/client/petstore/python-experimental/README.md b/samples/openapi3/client/petstore/python-experimental/README.md index 622ac9805d8b..3c16a26ddc63 100644 --- a/samples/openapi3/client/petstore/python-experimental/README.md +++ b/samples/openapi3/client/petstore/python-experimental/README.md @@ -87,6 +87,7 @@ Class | Method | HTTP request | Description *FakeApi* | [**fake_outer_composite_serialize**](docs/FakeApi.md#fake_outer_composite_serialize) | **POST** /fake/outer/composite | *FakeApi* | [**fake_outer_number_serialize**](docs/FakeApi.md#fake_outer_number_serialize) | **POST** /fake/outer/number | *FakeApi* | [**fake_outer_string_serialize**](docs/FakeApi.md#fake_outer_string_serialize) | **POST** /fake/outer/string | +*FakeApi* | [**get_array_of_enums**](docs/FakeApi.md#get_array_of_enums) | **GET** /fake/array-of-enums | Array of Enums *FakeApi* | [**test_body_with_file_schema**](docs/FakeApi.md#test_body_with_file_schema) | **PUT** /fake/body-with-file-schema | *FakeApi* | [**test_body_with_query_params**](docs/FakeApi.md#test_body_with_query_params) | **PUT** /fake/body-with-query-params | *FakeApi* | [**test_client_model**](docs/FakeApi.md#test_client_model) | **PATCH** /fake | To test \"client\" model @@ -97,7 +98,6 @@ Class | Method | HTTP request | Description *FakeApi* | [**test_json_form_data**](docs/FakeApi.md#test_json_form_data) | **GET** /fake/jsonFormData | test json serialization of form data *FakeApi* | [**test_query_parameter_collection_format**](docs/FakeApi.md#test_query_parameter_collection_format) | **PUT** /fake/test-query-paramters | *FakeClassnameTags123Api* | [**test_classname**](docs/FakeClassnameTags123Api.md#test_classname) | **PATCH** /fake_classname_test | To test class name in snake case -*FarmApi* | [**farm**](docs/FarmApi.md#farm) | **GET** /farm/animals | Animal Farm *PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **POST** /pet | Add a new pet to the store *PetApi* | [**delete_pet**](docs/PetApi.md#delete_pet) | **DELETE** /pet/{petId} | Deletes a pet *PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status) | **GET** /pet/findByStatus | Finds Pets by status @@ -131,6 +131,7 @@ Class | Method | HTTP request | Description - [apple.Apple](docs/Apple.md) - [apple_req.AppleReq](docs/AppleReq.md) - [array_of_array_of_number_only.ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md) + - [array_of_enums.ArrayOfEnums](docs/ArrayOfEnums.md) - [array_of_number_only.ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md) - [array_test.ArrayTest](docs/ArrayTest.md) - [banana.Banana](docs/Banana.md) diff --git a/samples/openapi3/client/petstore/python-experimental/docs/ArrayOfEnums.md b/samples/openapi3/client/petstore/python-experimental/docs/ArrayOfEnums.md new file mode 100644 index 000000000000..504c0821c3be --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/docs/ArrayOfEnums.md @@ -0,0 +1,9 @@ +# array_of_enums.ArrayOfEnums + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- + +[[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/FakeApi.md b/samples/openapi3/client/petstore/python-experimental/docs/FakeApi.md index 6bd8936f1b5b..6a79ea1c772b 100644 --- a/samples/openapi3/client/petstore/python-experimental/docs/FakeApi.md +++ b/samples/openapi3/client/petstore/python-experimental/docs/FakeApi.md @@ -9,6 +9,7 @@ Method | HTTP request | Description [**fake_outer_composite_serialize**](FakeApi.md#fake_outer_composite_serialize) | **POST** /fake/outer/composite | [**fake_outer_number_serialize**](FakeApi.md#fake_outer_number_serialize) | **POST** /fake/outer/number | [**fake_outer_string_serialize**](FakeApi.md#fake_outer_string_serialize) | **POST** /fake/outer/string | +[**get_array_of_enums**](FakeApi.md#get_array_of_enums) | **GET** /fake/array-of-enums | Array of Enums [**test_body_with_file_schema**](FakeApi.md#test_body_with_file_schema) | **PUT** /fake/body-with-file-schema | [**test_body_with_query_params**](FakeApi.md#test_body_with_query_params) | **PUT** /fake/body-with-query-params | [**test_client_model**](FakeApi.md#test_client_model) | **PATCH** /fake | To test \"client\" model @@ -331,6 +332,64 @@ No authorization required [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) +# **get_array_of_enums** +> array_of_enums.ArrayOfEnums get_array_of_enums() + +Array of Enums + +### Example + +```python +from __future__ import print_function +import time +import petstore_api +from petstore_api.api import fake_api +from petstore_api.model import array_of_enums +from pprint import pprint +# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2 +# See configuration.py for a list of all supported configuration parameters. +configuration = petstore_api.Configuration( + host = "http://petstore.swagger.io:80/v2" +) + + +# Enter a context with an instance of the API client +with petstore_api.ApiClient() as api_client: + # Create an instance of the API class + api_instance = fake_api.FakeApi(api_client) + + # example, this endpoint has no required or optional parameters + try: + # Array of Enums + api_response = api_instance.get_array_of_enums() + pprint(api_response) + except petstore_api.ApiException as e: + print("Exception when calling FakeApi->get_array_of_enums: %s\n" % e) +``` + +### Parameters +This endpoint does not need any parameter. + +### Return type + +[**array_of_enums.ArrayOfEnums**](ArrayOfEnums.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +**200** | Got named array of enums | - | + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + # **test_body_with_file_schema** > test_body_with_file_schema(file_schema_test_class_file_schema_test_class) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/__init__.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/__init__.py index 1d2f2d52b4fd..fa4e54a80091 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/__init__.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/__init__.py @@ -7,7 +7,6 @@ from petstore_api.api.default_api import DefaultApi from petstore_api.api.fake_api import FakeApi from petstore_api.api.fake_classname_tags_123_api import FakeClassnameTags123Api -from petstore_api.api.farm_api import FarmApi from petstore_api.api.pet_api import PetApi from petstore_api.api.store_api import StoreApi from petstore_api.api.user_api import UserApi diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api.py index 69531b0525fa..3c5de6178be2 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api.py @@ -36,6 +36,7 @@ ) from petstore_api.model import health_check_result from petstore_api.model import outer_composite +from petstore_api.model import array_of_enums from petstore_api.model import file_schema_test_class from petstore_api.model import user from petstore_api.model import client @@ -600,6 +601,109 @@ def __fake_outer_string_serialize( callable=__fake_outer_string_serialize ) + def __get_array_of_enums( + self, + **kwargs + ): + """Array of Enums # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.get_array_of_enums(async_req=True) + >>> result = thread.get() + + + Keyword Args: + _return_http_data_only (bool): response data without head status + code and headers. Default is True. + _preload_content (bool): if False, the urllib3.HTTPResponse object + will be returned without reading/decoding response data. + Default is True. + _request_timeout (float/tuple): timeout setting for this request. If one + number provided, it will be total request timeout. It can also + be a pair (tuple) of (connection, read) timeouts. + Default is None. + _check_input_type (bool): specifies if type checking + should be done one the data sent to the server. + Default is True. + _check_return_type (bool): specifies if type checking + should be done one the data received from the server. + Default is True. + _host_index (int): specifies the index of the server + that we want to use. + Default is 0. + async_req (bool): execute request asynchronously + + Returns: + array_of_enums.ArrayOfEnums + If the method is called asynchronously, returns the request + thread. + """ + kwargs['async_req'] = kwargs.get( + 'async_req', False + ) + kwargs['_return_http_data_only'] = kwargs.get( + '_return_http_data_only', True + ) + kwargs['_preload_content'] = kwargs.get( + '_preload_content', True + ) + kwargs['_request_timeout'] = kwargs.get( + '_request_timeout', None + ) + kwargs['_check_input_type'] = kwargs.get( + '_check_input_type', True + ) + kwargs['_check_return_type'] = kwargs.get( + '_check_return_type', True + ) + kwargs['_host_index'] = kwargs.get('_host_index', 0) + return self.call_with_http_info(**kwargs) + + self.get_array_of_enums = Endpoint( + settings={ + 'response_type': (array_of_enums.ArrayOfEnums,), + 'auth': [], + 'endpoint_path': '/fake/array-of-enums', + 'operation_id': 'get_array_of_enums', + 'http_method': 'GET', + 'servers': [], + }, + params_map={ + 'all': [ + ], + 'required': [], + 'nullable': [ + ], + 'enum': [ + ], + 'validation': [ + ] + }, + root_map={ + 'validations': { + }, + 'allowed_values': { + }, + 'openapi_types': { + }, + 'attribute_map': { + }, + 'location_map': { + }, + 'collection_format_map': { + } + }, + headers_map={ + 'accept': [ + 'application/json' + ], + 'content_type': [], + }, + api_client=api_client, + callable=__get_array_of_enums + ) + def __test_body_with_file_schema( self, file_schema_test_class_file_schema_test_class, diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/__init__.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/__init__.py index 19871fa18210..41cbd0aa055e 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/__init__.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/apis/__init__.py @@ -16,7 +16,6 @@ from petstore_api.api.default_api import DefaultApi from petstore_api.api.fake_api import FakeApi from petstore_api.api.fake_classname_tags_123_api import FakeClassnameTags123Api -from petstore_api.api.farm_api import FarmApi from petstore_api.api.pet_api import PetApi from petstore_api.api.store_api import StoreApi from petstore_api.api.user_api import UserApi diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_of_enums.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_of_enums.py new file mode 100644 index 000000000000..d04290d75438 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_of_enums.py @@ -0,0 +1,168 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import +import re # noqa: F401 +import sys # noqa: F401 + +import six # 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, + int, + none_type, + str, + validate_get_composed_info, +) +try: + from petstore_api.model import outer_enum +except ImportError: + outer_enum = sys.modules[ + 'petstore_api.model.outer_enum'] + + +class ArrayOfEnums(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 = { + } + + additional_properties_type = None + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a class method so a model may have properties that are + of type self, this ensures that we don't create a cyclic import + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + return { + } + + @cached_property + def discriminator(): + return None + + _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): # noqa: E501 + """array_of_enums.ArrayOfEnums - a model defined in OpenAPI + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _spec_property_naming (bool): True if the variable names in the input data + are serialized names, as specified in the OpenAPI document. + False if the variable names in the input data + are pythonic names, e.g. snake case (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + _visited_composed_classes (tuple): This stores a tuple of + classes that we have traveled through so that + if we see that class again we will not use its + discriminator again. + When traveling through a discriminator, the + composed schema that is + is traveled through is added to this set. + For example if Animal has a discriminator + petType and we pass in "Dog", and the class Dog + allOf includes Animal, we move through Animal + once using the discriminator, and pick Dog. + Then in Dog, we will make an instance of the + Animal class but this time we won't travel + through its discriminator because we passed in + _visited_composed_classes = (Animal,) + """ + + _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__,) + + for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue + setattr(self, var_name, var_value) 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 018302a720ba..7f3b8ea8ed9a 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 @@ -19,6 +19,7 @@ from petstore_api.model.apple import Apple from petstore_api.model.apple_req import AppleReq from petstore_api.model.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly +from petstore_api.model.array_of_enums import ArrayOfEnums from petstore_api.model.array_of_number_only import ArrayOfNumberOnly from petstore_api.model.array_test import ArrayTest from petstore_api.model.banana import Banana diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_array_of_enums.py b/samples/openapi3/client/petstore/python-experimental/test/test_array_of_enums.py new file mode 100644 index 000000000000..2b9007e564f0 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/test/test_array_of_enums.py @@ -0,0 +1,43 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import +import sys +import unittest + +import petstore_api +try: + from petstore_api.model import outer_enum +except ImportError: + outer_enum = sys.modules[ + 'petstore_api.model.outer_enum'] +from petstore_api.model.array_of_enums import ArrayOfEnums + + +class TestArrayOfEnums(unittest.TestCase): + """ArrayOfEnums unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testArrayOfEnums(self): + """Test ArrayOfEnums""" + # FIXME: construct object with mandatory attributes with example values + # model = ArrayOfEnums() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/tests/test_api_validation.py b/samples/openapi3/client/petstore/python-experimental/tests/test_api_validation.py index edf48ad0160b..cf0c379c580d 100644 --- a/samples/openapi3/client/petstore/python-experimental/tests/test_api_validation.py +++ b/samples/openapi3/client/petstore/python-experimental/tests/test_api_validation.py @@ -21,6 +21,7 @@ from collections import namedtuple import petstore_api +from petstore_api.model import array_of_enums from petstore_api.model import format_test import petstore_api.configuration @@ -42,6 +43,12 @@ def test_configuration(self): config.disabled_client_side_validations = 'foo' config.disabled_client_side_validations = "" + def test_array_of_enums(self): + data = [ + "placed", None + ] + response = MockResponse(data=json.dumps(data)) + deserialized = self.api_client.deserialize(response, (array_of_enums.ArrayOfEnums, ), True) def checkRaiseRegex(self, expected_exception, expected_regex): if sys.version_info < (3, 0): From 4a8ad25fe6b6418f6093b5e9409f8af75597cc97 Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Tue, 2 Jun 2020 17:12:58 +0200 Subject: [PATCH 08/18] Clean-up --- .../.openapi-generator/FILES | 1 - .../python-experimental/docs/FarmApi.md | 67 ------------------- 2 files changed, 68 deletions(-) delete mode 100644 samples/openapi3/client/petstore/python-experimental/docs/FarmApi.md diff --git a/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES b/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES index 3f05d37a37bf..0d022fe2bdef 100644 --- a/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/python-experimental/.openapi-generator/FILES @@ -201,5 +201,4 @@ setup.cfg setup.py test-requirements.txt test/__init__.py -test/test_fake_api.py tox.ini diff --git a/samples/openapi3/client/petstore/python-experimental/docs/FarmApi.md b/samples/openapi3/client/petstore/python-experimental/docs/FarmApi.md deleted file mode 100644 index 1367cf06f7a1..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/docs/FarmApi.md +++ /dev/null @@ -1,67 +0,0 @@ -# petstore_api.FarmApi - -All URIs are relative to *http://petstore.swagger.io:80/v2* - -Method | HTTP request | Description -------------- | ------------- | ------------- -[**farm**](FarmApi.md#farm) | **GET** /farm/animals | Animal Farm - - -# **farm** -> animal_farm.AnimalFarm farm() - -Animal Farm - -### Example - -```python -from __future__ import print_function -import time -import petstore_api -from petstore_api.api import farm_api -from petstore_api.model import animal_farm -from pprint import pprint -# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2 -# See configuration.py for a list of all supported configuration parameters. -configuration = petstore_api.Configuration( - host = "http://petstore.swagger.io:80/v2" -) - - -# Enter a context with an instance of the API client -with petstore_api.ApiClient() as api_client: - # Create an instance of the API class - api_instance = farm_api.FarmApi(api_client) - - # example, this endpoint has no required or optional parameters - try: - # Animal Farm - api_response = api_instance.farm() - pprint(api_response) - except petstore_api.ApiException as e: - print("Exception when calling FarmApi->farm: %s\n" % e) -``` - -### Parameters -This endpoint does not need any parameter. - -### Return type - -[**animal_farm.AnimalFarm**](AnimalFarm.md) - -### Authorization - -No authorization required - -### HTTP request headers - - - **Content-Type**: Not defined - - **Accept**: application/json - -### HTTP response details -| Status code | Description | Response headers | -|-------------|-------------|------------------| -**200** | Got named array of enums | - | - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) - From a58959900538b103c426eb37dc1604bd9253d61e Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Tue, 2 Jun 2020 17:15:11 +0200 Subject: [PATCH 09/18] Clean-up --- .../petstore_api/api/farm_api.py | 373 ------------------ 1 file changed, 373 deletions(-) delete mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/api/farm_api.py diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/farm_api.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/farm_api.py deleted file mode 100644 index 0cae63fe3230..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/farm_api.py +++ /dev/null @@ -1,373 +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 -""" - - -from __future__ import absolute_import - -import re # noqa: F401 -import sys # noqa: F401 - -# python 2 and python 3 compatibility library -import six - -from petstore_api.api_client import ApiClient -from petstore_api.exceptions import ( - ApiTypeError, - ApiValueError -) -from petstore_api.model_utils import ( # noqa: F401 - check_allowed_values, - check_validations, - date, - datetime, - file_type, - int, - none_type, - str, - validate_and_convert_types -) -from petstore_api.model import animal_farm - - -class FarmApi(object): - """NOTE: This class is auto generated by OpenAPI Generator - Ref: https://openapi-generator.tech - - Do not edit the class manually. - """ - - def __init__(self, api_client=None): - if api_client is None: - api_client = ApiClient() - self.api_client = api_client - - def __farm( - self, - **kwargs - ): - """Animal Farm # noqa: E501 - - This method makes a synchronous HTTP request by default. To make an - asynchronous HTTP request, please pass async_req=True - >>> thread = api.farm(async_req=True) - >>> result = thread.get() - - - Keyword Args: - _return_http_data_only (bool): response data without head status - code and headers. Default is True. - _preload_content (bool): if False, the urllib3.HTTPResponse object - will be returned without reading/decoding response data. - Default is True. - _request_timeout (float/tuple): timeout setting for this request. If one - number provided, it will be total request timeout. It can also - be a pair (tuple) of (connection, read) timeouts. - Default is None. - _check_input_type (bool): specifies if type checking - should be done one the data sent to the server. - Default is True. - _check_return_type (bool): specifies if type checking - should be done one the data received from the server. - Default is True. - _host_index (int): specifies the index of the server - that we want to use. - Default is 0. - async_req (bool): execute request asynchronously - - Returns: - animal_farm.AnimalFarm - If the method is called asynchronously, returns the request - thread. - """ - kwargs['async_req'] = kwargs.get( - 'async_req', False - ) - kwargs['_return_http_data_only'] = kwargs.get( - '_return_http_data_only', True - ) - kwargs['_preload_content'] = kwargs.get( - '_preload_content', True - ) - kwargs['_request_timeout'] = kwargs.get( - '_request_timeout', None - ) - kwargs['_check_input_type'] = kwargs.get( - '_check_input_type', True - ) - kwargs['_check_return_type'] = kwargs.get( - '_check_return_type', True - ) - kwargs['_host_index'] = kwargs.get('_host_index', 0) - return self.call_with_http_info(**kwargs) - - self.farm = Endpoint( - settings={ - 'response_type': (animal_farm.AnimalFarm,), - 'auth': [], - 'endpoint_path': '/farm/animals', - 'operation_id': 'farm', - 'http_method': 'GET', - 'servers': [], - }, - params_map={ - 'all': [ - ], - 'required': [], - 'nullable': [ - ], - 'enum': [ - ], - 'validation': [ - ] - }, - root_map={ - 'validations': { - }, - 'allowed_values': { - }, - 'openapi_types': { - }, - 'attribute_map': { - }, - 'location_map': { - }, - 'collection_format_map': { - } - }, - headers_map={ - 'accept': [ - 'application/json' - ], - 'content_type': [], - }, - api_client=api_client, - callable=__farm - ) - - -class Endpoint(object): - def __init__(self, settings=None, params_map=None, root_map=None, - headers_map=None, api_client=None, callable=None): - """Creates an endpoint - - Args: - settings (dict): see below key value pairs - 'response_type' (tuple/None): response type - 'auth' (list): a list of auth type keys - 'endpoint_path' (str): the endpoint path - 'operation_id' (str): endpoint string identifier - 'http_method' (str): POST/PUT/PATCH/GET etc - 'servers' (list): list of str servers that this endpoint is at - params_map (dict): see below key value pairs - 'all' (list): list of str endpoint parameter names - 'required' (list): list of required parameter names - 'nullable' (list): list of nullable parameter names - 'enum' (list): list of parameters with enum values - 'validation' (list): list of parameters with validations - root_map - 'validations' (dict): the dict mapping endpoint parameter tuple - paths to their validation dictionaries - 'allowed_values' (dict): the dict mapping endpoint parameter - tuple paths to their allowed_values (enum) dictionaries - 'openapi_types' (dict): param_name to openapi type - 'attribute_map' (dict): param_name to camelCase name - 'location_map' (dict): param_name to 'body', 'file', 'form', - 'header', 'path', 'query' - collection_format_map (dict): param_name to `csv` etc. - headers_map (dict): see below key value pairs - 'accept' (list): list of Accept header strings - 'content_type' (list): list of Content-Type header strings - api_client (ApiClient) api client instance - callable (function): the function which is invoked when the - Endpoint is called - """ - self.settings = settings - self.params_map = params_map - self.params_map['all'].extend([ - 'async_req', - '_host_index', - '_preload_content', - '_request_timeout', - '_return_http_data_only', - '_check_input_type', - '_check_return_type' - ]) - self.params_map['nullable'].extend(['_request_timeout']) - self.validations = root_map['validations'] - self.allowed_values = root_map['allowed_values'] - self.openapi_types = root_map['openapi_types'] - extra_types = { - 'async_req': (bool,), - '_host_index': (int,), - '_preload_content': (bool,), - '_request_timeout': (none_type, int, (int,), [int]), - '_return_http_data_only': (bool,), - '_check_input_type': (bool,), - '_check_return_type': (bool,) - } - self.openapi_types.update(extra_types) - self.attribute_map = root_map['attribute_map'] - self.location_map = root_map['location_map'] - self.collection_format_map = root_map['collection_format_map'] - self.headers_map = headers_map - self.api_client = api_client - self.callable = callable - - def __validate_inputs(self, kwargs): - for param in self.params_map['enum']: - if param in kwargs: - check_allowed_values( - self.allowed_values, - (param,), - kwargs[param] - ) - - for param in self.params_map['validation']: - if param in kwargs: - check_validations( - self.validations, - (param,), - kwargs[param], - configuration=self.api_client.configuration - ) - - if kwargs['_check_input_type'] is False: - return - - for key, value in six.iteritems(kwargs): - fixed_val = validate_and_convert_types( - value, - self.openapi_types[key], - [key], - False, - kwargs['_check_input_type'], - configuration=self.api_client.configuration - ) - kwargs[key] = fixed_val - - def __gather_params(self, kwargs): - params = { - 'body': None, - 'collection_format': {}, - 'file': {}, - 'form': [], - 'header': {}, - 'path': {}, - 'query': [] - } - - for param_name, param_value in six.iteritems(kwargs): - param_location = self.location_map.get(param_name) - if param_location is None: - continue - if param_location: - if param_location == 'body': - params['body'] = param_value - continue - base_name = self.attribute_map[param_name] - if (param_location == 'form' and - self.openapi_types[param_name] == (file_type,)): - params['file'][param_name] = [param_value] - elif (param_location == 'form' and - self.openapi_types[param_name] == ([file_type],)): - # param_value is already a list - params['file'][param_name] = param_value - elif param_location in {'form', 'query'}: - param_value_full = (base_name, param_value) - params[param_location].append(param_value_full) - if param_location not in {'form', 'query'}: - params[param_location][base_name] = param_value - collection_format = self.collection_format_map.get(param_name) - if collection_format: - params['collection_format'][base_name] = collection_format - - return params - - def __call__(self, *args, **kwargs): - """ This method is invoked when endpoints are called - Example: - pet_api = PetApi() - pet_api.add_pet # this is an instance of the class Endpoint - pet_api.add_pet() # this invokes pet_api.add_pet.__call__() - which then invokes the callable functions stored in that endpoint at - pet_api.add_pet.callable or self.callable in this class - """ - return self.callable(self, *args, **kwargs) - - def call_with_http_info(self, **kwargs): - - try: - _host = self.settings['servers'][kwargs['_host_index']] - except IndexError: - if self.settings['servers']: - raise ApiValueError( - "Invalid host index. Must be 0 <= index < %s" % - len(self.settings['servers']) - ) - _host = None - - for key, value in six.iteritems(kwargs): - if key not in self.params_map['all']: - raise ApiTypeError( - "Got an unexpected parameter '%s'" - " to method `%s`" % - (key, self.settings['operation_id']) - ) - # only throw this nullable ApiValueError if _check_input_type - # is False, if _check_input_type==True we catch this case - # in self.__validate_inputs - if (key not in self.params_map['nullable'] and value is None - and kwargs['_check_input_type'] is False): - raise ApiValueError( - "Value may not be None for non-nullable parameter `%s`" - " when calling `%s`" % - (key, self.settings['operation_id']) - ) - - for key in self.params_map['required']: - if key not in kwargs.keys(): - raise ApiValueError( - "Missing the required parameter `%s` when calling " - "`%s`" % (key, self.settings['operation_id']) - ) - - self.__validate_inputs(kwargs) - - params = self.__gather_params(kwargs) - - accept_headers_list = self.headers_map['accept'] - if accept_headers_list: - params['header']['Accept'] = self.api_client.select_header_accept( - accept_headers_list) - - content_type_headers_list = self.headers_map['content_type'] - if content_type_headers_list: - header_list = self.api_client.select_header_content_type( - content_type_headers_list) - params['header']['Content-Type'] = header_list - - return self.api_client.call_api( - self.settings['endpoint_path'], self.settings['http_method'], - params['path'], - params['query'], - params['header'], - body=params['body'], - post_params=params['form'], - files=params['file'], - response_type=self.settings['response_type'], - auth_settings=self.settings['auth'], - async_req=kwargs['async_req'], - _check_type=kwargs['_check_return_type'], - _return_http_data_only=kwargs['_return_http_data_only'], - _preload_content=kwargs['_preload_content'], - _request_timeout=kwargs['_request_timeout'], - _host=_host, - collection_formats=params['collection_format']) From e29055e7ae872de75f0a313e2f8ba93ef8602fab Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Tue, 2 Jun 2020 17:21:11 +0200 Subject: [PATCH 10/18] Clean-up --- .../test/test_animal_farm.py | 43 ------------------- .../python-experimental/test/test_farm_api.py | 39 ----------------- 2 files changed, 82 deletions(-) delete mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_animal_farm.py delete mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_farm_api.py diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_animal_farm.py b/samples/openapi3/client/petstore/python-experimental/test/test_animal_farm.py deleted file mode 100644 index d0df47fdcd1f..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/test/test_animal_farm.py +++ /dev/null @@ -1,43 +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 -""" - - -from __future__ import absolute_import -import sys -import unittest - -import petstore_api -try: - from petstore_api.model import animal -except ImportError: - animal = sys.modules[ - 'petstore_api.model.animal'] -from petstore_api.model.animal_farm import AnimalFarm - - -class TestAnimalFarm(unittest.TestCase): - """AnimalFarm unit test stubs""" - - def setUp(self): - pass - - def tearDown(self): - pass - - def testAnimalFarm(self): - """Test AnimalFarm""" - animals = [animal.Animal(className="dog"), animal.Animal(className="cat")] - model = AnimalFarm(animals) - assert False - - -if __name__ == '__main__': - unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_farm_api.py b/samples/openapi3/client/petstore/python-experimental/test/test_farm_api.py deleted file mode 100644 index b39e76ae7833..000000000000 --- a/samples/openapi3/client/petstore/python-experimental/test/test_farm_api.py +++ /dev/null @@ -1,39 +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 -""" - - -from __future__ import absolute_import - -import unittest - -import petstore_api -from petstore_api.api.farm_api import FarmApi # noqa: E501 - - -class TestFarmApi(unittest.TestCase): - """FarmApi unit test stubs""" - - def setUp(self): - self.api = FarmApi() # noqa: E501 - - def tearDown(self): - pass - - def test_farm(self): - """Test case for farm - - Animal Farm # noqa: E501 - """ - pass - - -if __name__ == '__main__': - unittest.main() From 49eb08f1f9370500c8e924f34de6400cd3ed1839 Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Tue, 2 Jun 2020 18:55:09 +0200 Subject: [PATCH 11/18] Fix array type generation --- .../PythonClientExperimentalCodegen.java | 15 ++++++- .../python-experimental/docs/AnimalFarm.md | 1 + .../python-experimental/docs/ArrayOfEnums.md | 1 + .../petstore_api/model/animal_farm.py | 7 ++- .../petstore_api/model/array_of_enums.py | 7 ++- .../test/test_animal_farm.py | 43 +++++++++++++++++++ .../tests/test_api_validation.py | 3 ++ 7 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_animal_farm.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 0c696c6dc247..9dbc7b017ee8 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 @@ -823,7 +823,7 @@ public CodegenModel fromModel(String name, Schema schema) { result.unescapedDescription = simpleModelName(name); // make non-object type models have one property so we can use it to store enums and validations - if (result.isAlias || result.isEnum) { + if (result.isAlias || result.isEnum || result.isArrayModel) { Schema modelSchema = ModelUtils.getSchema(this.openAPI, result.name); CodegenProperty modelProperty = fromProperty("value", modelSchema); if (modelProperty.isEnum == true || modelProperty.hasValidation == true) { @@ -841,7 +841,20 @@ public CodegenModel fromModel(String name, Schema schema) { postProcessModelProperty(result, prop); } } + } else if (result.isArrayModel) { + LOGGER.warn("\n\n{}\n\n", modelSchema); + LOGGER.warn("\n\n{}\n\n", modelProperty); + List theProperties = Arrays.asList(modelProperty); + result.setAllVars(theProperties); + result.setVars(theProperties); + result.setRequiredVars(theProperties); + // post process model properties + if (result.vars != null) { + for (CodegenProperty prop : result.vars) { + postProcessModelProperty(result, prop); + } + } } } diff --git a/samples/openapi3/client/petstore/python-experimental/docs/AnimalFarm.md b/samples/openapi3/client/petstore/python-experimental/docs/AnimalFarm.md index bac5e6627d15..c9976c7ddab9 100644 --- a/samples/openapi3/client/petstore/python-experimental/docs/AnimalFarm.md +++ b/samples/openapi3/client/petstore/python-experimental/docs/AnimalFarm.md @@ -3,6 +3,7 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**value** | [**[animal.Animal]**](Animal.md) | | [[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/ArrayOfEnums.md b/samples/openapi3/client/petstore/python-experimental/docs/ArrayOfEnums.md index 504c0821c3be..ad9394655bcb 100644 --- a/samples/openapi3/client/petstore/python-experimental/docs/ArrayOfEnums.md +++ b/samples/openapi3/client/petstore/python-experimental/docs/ArrayOfEnums.md @@ -3,6 +3,7 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- +**value** | [**[outer_enum.OuterEnum, none_type]**](OuterEnum.md) | | [[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/animal_farm.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/animal_farm.py index 1bf28922fd7b..3e6d723ff2b2 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/animal_farm.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/animal_farm.py @@ -81,6 +81,7 @@ def openapi_types(): and the value is attribute type. """ return { + 'value': ([animal.Animal],), # noqa: E501 } @cached_property @@ -99,9 +100,12 @@ def discriminator(): ]) @convert_js_args_to_python_args - def __init__(self, *args, **kwargs): # noqa: E501 + def __init__(self, value, *args, **kwargs): # noqa: E501 """animal_farm.AnimalFarm - a model defined in OpenAPI + Args: + value ([animal.Animal]): + Keyword Args: _check_type (bool): if True, values for parameters in openapi_types will be type checked and a TypeError will be @@ -158,6 +162,7 @@ def __init__(self, *args, **kwargs): # noqa: E501 self._configuration = _configuration self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + self.value = value for var_name, var_value in six.iteritems(kwargs): if var_name not in self.attribute_map and \ self._configuration is not None and \ diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_of_enums.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_of_enums.py index d04290d75438..0bea865e36ca 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_of_enums.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_of_enums.py @@ -81,6 +81,7 @@ def openapi_types(): and the value is attribute type. """ return { + 'value': ([outer_enum.OuterEnum, none_type],), # noqa: E501 } @cached_property @@ -99,9 +100,12 @@ def discriminator(): ]) @convert_js_args_to_python_args - def __init__(self, *args, **kwargs): # noqa: E501 + def __init__(self, value, *args, **kwargs): # noqa: E501 """array_of_enums.ArrayOfEnums - a model defined in OpenAPI + Args: + value ([outer_enum.OuterEnum, none_type]): + Keyword Args: _check_type (bool): if True, values for parameters in openapi_types will be type checked and a TypeError will be @@ -158,6 +162,7 @@ def __init__(self, *args, **kwargs): # noqa: E501 self._configuration = _configuration self._visited_composed_classes = _visited_composed_classes + (self.__class__,) + self.value = value for var_name, var_value in six.iteritems(kwargs): if var_name not in self.attribute_map and \ self._configuration is not None and \ diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_animal_farm.py b/samples/openapi3/client/petstore/python-experimental/test/test_animal_farm.py new file mode 100644 index 000000000000..7117d42b430e --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/test/test_animal_farm.py @@ -0,0 +1,43 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import +import sys +import unittest + +import petstore_api +try: + from petstore_api.model import animal +except ImportError: + animal = sys.modules[ + 'petstore_api.model.animal'] +from petstore_api.model.animal_farm import AnimalFarm + + +class TestAnimalFarm(unittest.TestCase): + """AnimalFarm unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testAnimalFarm(self): + """Test AnimalFarm""" + # FIXME: construct object with mandatory attributes with example values + # model = AnimalFarm() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/tests/test_api_validation.py b/samples/openapi3/client/petstore/python-experimental/tests/test_api_validation.py index cf0c379c580d..e9eb0a70f786 100644 --- a/samples/openapi3/client/petstore/python-experimental/tests/test_api_validation.py +++ b/samples/openapi3/client/petstore/python-experimental/tests/test_api_validation.py @@ -23,6 +23,7 @@ import petstore_api from petstore_api.model import array_of_enums from petstore_api.model import format_test +from petstore_api.model import outer_enum import petstore_api.configuration HOST = 'http://petstore.swagger.io/v2' @@ -49,6 +50,8 @@ def test_array_of_enums(self): ] response = MockResponse(data=json.dumps(data)) deserialized = self.api_client.deserialize(response, (array_of_enums.ArrayOfEnums, ), True) + assert isinstance(deserialized, array_of_enums.ArrayOfEnums) + assert array_of_enums.ArrayOfEnums([outer_enum.OuterEnum(v) for v in data]) == deserialized def checkRaiseRegex(self, expected_exception, expected_regex): if sys.version_info < (3, 0): From fcbd31aa068b37e61509f8bd6cfc980b82806cb0 Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Wed, 3 Jun 2020 13:10:14 +0200 Subject: [PATCH 12/18] simplify --- .../PythonClientExperimentalCodegen.java | 16 +--------------- 1 file changed, 1 insertion(+), 15 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 9dbc7b017ee8..c08b46c66171 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 @@ -826,25 +826,11 @@ public CodegenModel fromModel(String name, Schema schema) { if (result.isAlias || result.isEnum || result.isArrayModel) { Schema modelSchema = ModelUtils.getSchema(this.openAPI, result.name); CodegenProperty modelProperty = fromProperty("value", modelSchema); - if (modelProperty.isEnum == true || modelProperty.hasValidation == true) { + if (modelProperty.isEnum == true || modelProperty.hasValidation == true || result.isArrayModel) { // these models are non-object models with enums and/or validations // add a single property to the model so we can have a way to access validations result.isAlias = true; modelProperty.required = true; - List theProperties = Arrays.asList(modelProperty); - result.setAllVars(theProperties); - result.setVars(theProperties); - result.setRequiredVars(theProperties); - // post process model properties - if (result.vars != null) { - for (CodegenProperty prop : result.vars) { - postProcessModelProperty(result, prop); - } - } - } else if (result.isArrayModel) { - LOGGER.warn("\n\n{}\n\n", modelSchema); - LOGGER.warn("\n\n{}\n\n", modelProperty); - List theProperties = Arrays.asList(modelProperty); result.setAllVars(theProperties); result.setVars(theProperties); From 1f890db2af2da9ff2d3d40718ed0fa62ab66e431 Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Wed, 3 Jun 2020 13:13:08 +0200 Subject: [PATCH 13/18] array model is not alias --- .../codegen/languages/PythonClientExperimentalCodegen.java | 2 +- 1 file changed, 1 insertion(+), 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 c08b46c66171..59ab5ce04223 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 @@ -829,7 +829,7 @@ public CodegenModel fromModel(String name, Schema schema) { if (modelProperty.isEnum == true || modelProperty.hasValidation == true || result.isArrayModel) { // these models are non-object models with enums and/or validations // add a single property to the model so we can have a way to access validations - result.isAlias = true; + result.isAlias = !result.isArrayModel; modelProperty.required = true; List theProperties = Arrays.asList(modelProperty); result.setAllVars(theProperties); From 7a2366a46879402088d35d14f963ea19abff64ac Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Wed, 3 Jun 2020 13:25:27 +0200 Subject: [PATCH 14/18] Array model has one value field --- .../codegen/python/PythonClientExperimentalTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c7988952b7f5..b48bc1e16525 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 @@ -268,7 +268,7 @@ public void arrayModelTest() { Assert.assertEquals(cm.classname, "sample.Sample"); Assert.assertEquals(cm.classVarName, "sample"); Assert.assertEquals(cm.description, "an array model"); - Assert.assertEquals(cm.vars.size(), 0); + Assert.assertEquals(cm.vars.size(), 1); // there is one value for Childer definition Assert.assertEquals(cm.parent, "list"); Assert.assertEquals(cm.imports.size(), 1); Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("children.Children")).size(), 1); From a5d37004d487bf68b58f0f2583bf67e1c4694fb0 Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Wed, 3 Jun 2020 15:39:11 +0200 Subject: [PATCH 15/18] ensure up-to-date --- .../.openapi-generator/FILES | 3 + .../petstore/python-experimental/README.md | 1 + .../docs/AdditionalPropertiesAnyType.md | 2 +- .../docs/AdditionalPropertiesArray.md | 2 +- .../docs/AdditionalPropertiesClass.md | 10 +- .../docs/AdditionalPropertiesObject.md | 2 +- .../python-experimental/docs/AnimalFarm.md | 10 + .../petstore/python-experimental/docs/Cat.md | 1 + .../python-experimental/docs/Child.md | 1 + .../python-experimental/docs/ChildCat.md | 1 + .../python-experimental/docs/ChildDog.md | 1 + .../python-experimental/docs/ChildLizard.md | 1 + .../petstore/python-experimental/docs/Dog.md | 1 + .../python-experimental/docs/Parent.md | 1 + .../python-experimental/docs/ParentPet.md | 1 + .../model/additional_properties_any_type.py | 2 +- .../model/additional_properties_array.py | 2 +- .../model/additional_properties_class.py | 20 +- .../model/additional_properties_object.py | 2 +- .../petstore_api/model/animal_farm.py | 173 ++++++++++++++++++ .../petstore_api/model/cat.py | 2 +- .../petstore_api/model/child.py | 2 +- .../petstore_api/model/child_cat.py | 2 +- .../petstore_api/model/child_dog.py | 2 +- .../petstore_api/model/child_lizard.py | 2 +- .../petstore_api/model/dog.py | 2 +- .../petstore_api/model/parent.py | 2 +- .../petstore_api/model/parent_pet.py | 2 +- .../petstore_api/models/__init__.py | 1 + .../test/test_animal_farm.py | 43 +++++ 30 files changed, 268 insertions(+), 29 deletions(-) create mode 100644 samples/client/petstore/python-experimental/docs/AnimalFarm.md create mode 100644 samples/client/petstore/python-experimental/petstore_api/model/animal_farm.py create mode 100644 samples/client/petstore/python-experimental/test/test_animal_farm.py diff --git a/samples/client/petstore/python-experimental/.openapi-generator/FILES b/samples/client/petstore/python-experimental/.openapi-generator/FILES index d282130ffbc0..5be8e024e836 100644 --- a/samples/client/petstore/python-experimental/.openapi-generator/FILES +++ b/samples/client/petstore/python-experimental/.openapi-generator/FILES @@ -11,6 +11,7 @@ docs/AdditionalPropertiesNumber.md docs/AdditionalPropertiesObject.md docs/AdditionalPropertiesString.md docs/Animal.md +docs/AnimalFarm.md docs/AnotherFakeApi.md docs/ApiResponse.md docs/ArrayOfArrayOfNumberOnly.md @@ -93,6 +94,7 @@ petstore_api/model/additional_properties_number.py petstore_api/model/additional_properties_object.py petstore_api/model/additional_properties_string.py petstore_api/model/animal.py +petstore_api/model/animal_farm.py petstore_api/model/api_response.py petstore_api/model/array_of_array_of_number_only.py petstore_api/model/array_of_number_only.py @@ -154,4 +156,5 @@ setup.cfg setup.py test-requirements.txt test/__init__.py +test/test_animal_farm.py tox.ini diff --git a/samples/client/petstore/python-experimental/README.md b/samples/client/petstore/python-experimental/README.md index d6b85d02a55a..9826cfaf9872 100644 --- a/samples/client/petstore/python-experimental/README.md +++ b/samples/client/petstore/python-experimental/README.md @@ -131,6 +131,7 @@ Class | Method | HTTP request | Description - [additional_properties_object.AdditionalPropertiesObject](docs/AdditionalPropertiesObject.md) - [additional_properties_string.AdditionalPropertiesString](docs/AdditionalPropertiesString.md) - [animal.Animal](docs/Animal.md) + - [animal_farm.AnimalFarm](docs/AnimalFarm.md) - [api_response.ApiResponse](docs/ApiResponse.md) - [array_of_array_of_number_only.ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md) - [array_of_number_only.ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md) diff --git a/samples/client/petstore/python-experimental/docs/AdditionalPropertiesAnyType.md b/samples/client/petstore/python-experimental/docs/AdditionalPropertiesAnyType.md index d27928ab7527..62eee911ea26 100644 --- a/samples/client/petstore/python-experimental/docs/AdditionalPropertiesAnyType.md +++ b/samples/client/petstore/python-experimental/docs/AdditionalPropertiesAnyType.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **name** | **str** | | [optional] -**any string name** | **bool, date, datetime, dict, float, int, list, str** | any string name can be used but the value must be the correct type | [optional] +**any string name** | **{str: (bool, date, datetime, dict, float, int, list, str, none_type)}** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/AdditionalPropertiesArray.md b/samples/client/petstore/python-experimental/docs/AdditionalPropertiesArray.md index 6eac3ace2eca..46be89a5b23e 100644 --- a/samples/client/petstore/python-experimental/docs/AdditionalPropertiesArray.md +++ b/samples/client/petstore/python-experimental/docs/AdditionalPropertiesArray.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **name** | **str** | | [optional] -**any string name** | **[bool, date, datetime, dict, float, int, list, str]** | any string name can be used but the value must be the correct type | [optional] +**any string name** | **[{str: (bool, date, datetime, dict, float, int, list, str, none_type)}]** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/AdditionalPropertiesClass.md b/samples/client/petstore/python-experimental/docs/AdditionalPropertiesClass.md index 4b232aa174af..cf00d9d4c816 100644 --- a/samples/client/petstore/python-experimental/docs/AdditionalPropertiesClass.md +++ b/samples/client/petstore/python-experimental/docs/AdditionalPropertiesClass.md @@ -8,12 +8,12 @@ Name | Type | Description | Notes **map_integer** | **{str: (int,)}** | | [optional] **map_boolean** | **{str: (bool,)}** | | [optional] **map_array_integer** | **{str: ([int],)}** | | [optional] -**map_array_anytype** | **{str: ([bool, date, datetime, dict, float, int, list, str],)}** | | [optional] +**map_array_anytype** | **{str: ([{str: (bool, date, datetime, dict, float, int, list, str, none_type)}],)}** | | [optional] **map_map_string** | **{str: ({str: (str,)},)}** | | [optional] -**map_map_anytype** | **{str: ({str: (bool, date, datetime, dict, float, int, list, str,)},)}** | | [optional] -**anytype_1** | **bool, date, datetime, dict, float, int, list, str** | | [optional] -**anytype_2** | **bool, date, datetime, dict, float, int, list, str** | | [optional] -**anytype_3** | **bool, date, datetime, dict, float, int, list, str** | | [optional] +**map_map_anytype** | **{str: ({str: ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},)},)}** | | [optional] +**anytype_1** | **{str: (bool, date, datetime, dict, float, int, list, str, none_type)}** | | [optional] +**anytype_2** | **{str: (bool, date, datetime, dict, float, int, list, str, none_type)}** | | [optional] +**anytype_3** | **{str: (bool, date, datetime, dict, float, int, list, str, none_type)}** | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/AdditionalPropertiesObject.md b/samples/client/petstore/python-experimental/docs/AdditionalPropertiesObject.md index 36026fe72f82..15763836ddb1 100644 --- a/samples/client/petstore/python-experimental/docs/AdditionalPropertiesObject.md +++ b/samples/client/petstore/python-experimental/docs/AdditionalPropertiesObject.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **name** | **str** | | [optional] -**any string name** | **{str: (bool, date, datetime, dict, float, int, list, str,)}** | any string name can be used but the value must be the correct type | [optional] +**any string name** | **{str: ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},)}** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/AnimalFarm.md b/samples/client/petstore/python-experimental/docs/AnimalFarm.md new file mode 100644 index 000000000000..c9976c7ddab9 --- /dev/null +++ b/samples/client/petstore/python-experimental/docs/AnimalFarm.md @@ -0,0 +1,10 @@ +# animal_farm.AnimalFarm + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**value** | [**[animal.Animal]**](Animal.md) | | + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/samples/client/petstore/python-experimental/docs/Cat.md b/samples/client/petstore/python-experimental/docs/Cat.md index 1d7b5b26d715..846a97c82a84 100644 --- a/samples/client/petstore/python-experimental/docs/Cat.md +++ b/samples/client/petstore/python-experimental/docs/Cat.md @@ -6,6 +6,7 @@ Name | Type | Description | Notes **class_name** | **str** | | **declawed** | **bool** | | [optional] **color** | **str** | | [optional] if omitted the server will use the default value of 'red' +**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/Child.md b/samples/client/petstore/python-experimental/docs/Child.md index bc3c7f3922d3..4e43e94825b7 100644 --- a/samples/client/petstore/python-experimental/docs/Child.md +++ b/samples/client/petstore/python-experimental/docs/Child.md @@ -6,6 +6,7 @@ Name | Type | Description | Notes **radio_waves** | **bool** | | [optional] **tele_vision** | **bool** | | [optional] **inter_net** | **bool** | | [optional] +**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/ChildCat.md b/samples/client/petstore/python-experimental/docs/ChildCat.md index 8f5ea4b2ced0..bee23082474c 100644 --- a/samples/client/petstore/python-experimental/docs/ChildCat.md +++ b/samples/client/petstore/python-experimental/docs/ChildCat.md @@ -5,6 +5,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **pet_type** | **str** | | **name** | **str** | | [optional] +**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/ChildDog.md b/samples/client/petstore/python-experimental/docs/ChildDog.md index 2680d987a452..631b0362886c 100644 --- a/samples/client/petstore/python-experimental/docs/ChildDog.md +++ b/samples/client/petstore/python-experimental/docs/ChildDog.md @@ -5,6 +5,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **pet_type** | **str** | | **bark** | **str** | | [optional] +**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/ChildLizard.md b/samples/client/petstore/python-experimental/docs/ChildLizard.md index 97b8891a27e2..2e315eb2f21b 100644 --- a/samples/client/petstore/python-experimental/docs/ChildLizard.md +++ b/samples/client/petstore/python-experimental/docs/ChildLizard.md @@ -5,6 +5,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **pet_type** | **str** | | **loves_rocks** | **bool** | | [optional] +**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/Dog.md b/samples/client/petstore/python-experimental/docs/Dog.md index ec98b99dcec5..4c0497d67698 100644 --- a/samples/client/petstore/python-experimental/docs/Dog.md +++ b/samples/client/petstore/python-experimental/docs/Dog.md @@ -6,6 +6,7 @@ Name | Type | Description | Notes **class_name** | **str** | | **breed** | **str** | | [optional] **color** | **str** | | [optional] if omitted the server will use the default value of 'red' +**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/Parent.md b/samples/client/petstore/python-experimental/docs/Parent.md index 2437d3c81ac9..74beb2c531ce 100644 --- a/samples/client/petstore/python-experimental/docs/Parent.md +++ b/samples/client/petstore/python-experimental/docs/Parent.md @@ -5,6 +5,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **radio_waves** | **bool** | | [optional] **tele_vision** | **bool** | | [optional] +**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/ParentPet.md b/samples/client/petstore/python-experimental/docs/ParentPet.md index 12bfa5c7fe5c..78693cf8f0e6 100644 --- a/samples/client/petstore/python-experimental/docs/ParentPet.md +++ b/samples/client/petstore/python-experimental/docs/ParentPet.md @@ -4,6 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **pet_type** | **str** | | +**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_any_type.py b/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_any_type.py index 7ea7b1f807bd..65b9c2cc7ec2 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_any_type.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_any_type.py @@ -65,7 +65,7 @@ class AdditionalPropertiesAnyType(ModelNormal): validations = { } - additional_properties_type = (bool, date, datetime, dict, float, int, list, str,) # noqa: E501 + additional_properties_type = ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},) # noqa: E501 _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_array.py b/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_array.py index 5dc25499eaf9..0d76c73813f5 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_array.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_array.py @@ -65,7 +65,7 @@ class AdditionalPropertiesArray(ModelNormal): validations = { } - additional_properties_type = ([bool, date, datetime, dict, float, int, list, str],) # noqa: E501 + additional_properties_type = ([{str: (bool, date, datetime, dict, float, int, list, str, none_type)}],) # noqa: E501 _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_class.py b/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_class.py index 1b98c5f06e5d..eb4d08acb5ce 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_class.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_class.py @@ -85,12 +85,12 @@ def openapi_types(): 'map_integer': ({str: (int,)},), # noqa: E501 'map_boolean': ({str: (bool,)},), # noqa: E501 'map_array_integer': ({str: ([int],)},), # noqa: E501 - 'map_array_anytype': ({str: ([bool, date, datetime, dict, float, int, list, str],)},), # noqa: E501 + 'map_array_anytype': ({str: ([{str: (bool, date, datetime, dict, float, int, list, str, none_type)}],)},), # noqa: E501 'map_map_string': ({str: ({str: (str,)},)},), # noqa: E501 - 'map_map_anytype': ({str: ({str: (bool, date, datetime, dict, float, int, list, str,)},)},), # noqa: E501 - 'anytype_1': (bool, date, datetime, dict, float, int, list, str,), # noqa: E501 - 'anytype_2': (bool, date, datetime, dict, float, int, list, str,), # noqa: E501 - 'anytype_3': (bool, date, datetime, dict, float, int, list, str,), # noqa: E501 + 'map_map_anytype': ({str: ({str: ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},)},)},), # noqa: E501 + 'anytype_1': ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},), # noqa: E501 + 'anytype_2': ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},), # noqa: E501 + 'anytype_3': ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},), # noqa: E501 } @cached_property @@ -162,12 +162,12 @@ def __init__(self, *args, **kwargs): # noqa: E501 map_integer ({str: (int,)}): [optional] # noqa: E501 map_boolean ({str: (bool,)}): [optional] # noqa: E501 map_array_integer ({str: ([int],)}): [optional] # noqa: E501 - map_array_anytype ({str: ([bool, date, datetime, dict, float, int, list, str],)}): [optional] # noqa: E501 + map_array_anytype ({str: ([{str: (bool, date, datetime, dict, float, int, list, str, none_type)}],)}): [optional] # noqa: E501 map_map_string ({str: ({str: (str,)},)}): [optional] # noqa: E501 - map_map_anytype ({str: ({str: (bool, date, datetime, dict, float, int, list, str,)},)}): [optional] # noqa: E501 - anytype_1 (bool, date, datetime, dict, float, int, list, str): [optional] # noqa: E501 - anytype_2 (bool, date, datetime, dict, float, int, list, str): [optional] # noqa: E501 - anytype_3 (bool, date, datetime, dict, float, int, list, str): [optional] # noqa: E501 + map_map_anytype ({str: ({str: ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},)},)}): [optional] # noqa: E501 + anytype_1 ({str: (bool, date, datetime, dict, float, int, list, str, none_type)}): [optional] # noqa: E501 + anytype_2 ({str: (bool, date, datetime, dict, float, int, list, str, none_type)}): [optional] # noqa: E501 + anytype_3 ({str: (bool, date, datetime, dict, float, int, list, str, none_type)}): [optional] # noqa: E501 """ _check_type = kwargs.pop('_check_type', True) diff --git a/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_object.py b/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_object.py index 03ca022e6f82..c68db9ca6589 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_object.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_object.py @@ -65,7 +65,7 @@ class AdditionalPropertiesObject(ModelNormal): validations = { } - additional_properties_type = ({str: (bool, date, datetime, dict, float, int, list, str,)},) # noqa: E501 + additional_properties_type = ({str: ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},)},) # noqa: E501 _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/model/animal_farm.py b/samples/client/petstore/python-experimental/petstore_api/model/animal_farm.py new file mode 100644 index 000000000000..3e6d723ff2b2 --- /dev/null +++ b/samples/client/petstore/python-experimental/petstore_api/model/animal_farm.py @@ -0,0 +1,173 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import +import re # noqa: F401 +import sys # noqa: F401 + +import six # 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, + int, + none_type, + str, + validate_get_composed_info, +) +try: + from petstore_api.model import animal +except ImportError: + animal = sys.modules[ + 'petstore_api.model.animal'] + + +class AnimalFarm(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 = { + } + + additional_properties_type = None + + _nullable = False + + @cached_property + def openapi_types(): + """ + This must be a class method so a model may have properties that are + of type self, this ensures that we don't create a cyclic import + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + return { + 'value': ([animal.Animal],), # noqa: E501 + } + + @cached_property + def discriminator(): + return None + + _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): # noqa: E501 + """animal_farm.AnimalFarm - a model defined in OpenAPI + + Args: + value ([animal.Animal]): + + 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 + for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue + setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/model/cat.py b/samples/client/petstore/python-experimental/petstore_api/model/cat.py index b40a97dbab9a..011e8739b52c 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/cat.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/cat.py @@ -75,7 +75,7 @@ class Cat(ModelComposed): validations = { } - additional_properties_type = None + additional_properties_type = (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501 _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/model/child.py b/samples/client/petstore/python-experimental/petstore_api/model/child.py index 37c138d6a488..c2b62b72bdf8 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/child.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/child.py @@ -75,7 +75,7 @@ class Child(ModelComposed): validations = { } - additional_properties_type = None + additional_properties_type = (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501 _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/model/child_cat.py b/samples/client/petstore/python-experimental/petstore_api/model/child_cat.py index 6d42f11a18ff..996f3e0098e2 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/child_cat.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/child_cat.py @@ -75,7 +75,7 @@ class ChildCat(ModelComposed): validations = { } - additional_properties_type = None + additional_properties_type = (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501 _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/model/child_dog.py b/samples/client/petstore/python-experimental/petstore_api/model/child_dog.py index b7a93571a6a0..f60b977ef118 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/child_dog.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/child_dog.py @@ -75,7 +75,7 @@ class ChildDog(ModelComposed): validations = { } - additional_properties_type = None + additional_properties_type = (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501 _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/model/child_lizard.py b/samples/client/petstore/python-experimental/petstore_api/model/child_lizard.py index 978fea14a183..548db149f502 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/child_lizard.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/child_lizard.py @@ -75,7 +75,7 @@ class ChildLizard(ModelComposed): validations = { } - additional_properties_type = None + additional_properties_type = (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501 _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/model/dog.py b/samples/client/petstore/python-experimental/petstore_api/model/dog.py index 547eba90c2b1..a100eb3c70ef 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/dog.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/dog.py @@ -75,7 +75,7 @@ class Dog(ModelComposed): validations = { } - additional_properties_type = None + additional_properties_type = (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501 _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/model/parent.py b/samples/client/petstore/python-experimental/petstore_api/model/parent.py index a855a3ffd014..a9ccc697d1d5 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/parent.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/parent.py @@ -75,7 +75,7 @@ class Parent(ModelComposed): validations = { } - additional_properties_type = None + additional_properties_type = (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501 _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/model/parent_pet.py b/samples/client/petstore/python-experimental/petstore_api/model/parent_pet.py index 0b0b30c656f5..8687982cf8f1 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/parent_pet.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/parent_pet.py @@ -85,7 +85,7 @@ class ParentPet(ModelComposed): validations = { } - additional_properties_type = None + additional_properties_type = (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501 _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/models/__init__.py b/samples/client/petstore/python-experimental/petstore_api/models/__init__.py index 51bdb1a85a57..e70777afd690 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/__init__.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/__init__.py @@ -20,6 +20,7 @@ from petstore_api.model.additional_properties_object import AdditionalPropertiesObject from petstore_api.model.additional_properties_string import AdditionalPropertiesString from petstore_api.model.animal import Animal +from petstore_api.model.animal_farm import AnimalFarm from petstore_api.model.api_response import ApiResponse from petstore_api.model.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly from petstore_api.model.array_of_number_only import ArrayOfNumberOnly diff --git a/samples/client/petstore/python-experimental/test/test_animal_farm.py b/samples/client/petstore/python-experimental/test/test_animal_farm.py new file mode 100644 index 000000000000..7117d42b430e --- /dev/null +++ b/samples/client/petstore/python-experimental/test/test_animal_farm.py @@ -0,0 +1,43 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import +import sys +import unittest + +import petstore_api +try: + from petstore_api.model import animal +except ImportError: + animal = sys.modules[ + 'petstore_api.model.animal'] +from petstore_api.model.animal_farm import AnimalFarm + + +class TestAnimalFarm(unittest.TestCase): + """AnimalFarm unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testAnimalFarm(self): + """Test AnimalFarm""" + # FIXME: construct object with mandatory attributes with example values + # model = AnimalFarm() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() From a7dbe80e26612007baf574f4ff888b6f1b27bb0a Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Thu, 4 Jun 2020 11:36:08 +0200 Subject: [PATCH 16/18] ./bin/utils/ensure-up-to-date --batch --- .../client/petstore/python-experimental/.openapi-generator/FILES | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/client/petstore/python-experimental/.openapi-generator/FILES b/samples/client/petstore/python-experimental/.openapi-generator/FILES index 5be8e024e836..6e7ed3cb31ab 100644 --- a/samples/client/petstore/python-experimental/.openapi-generator/FILES +++ b/samples/client/petstore/python-experimental/.openapi-generator/FILES @@ -156,5 +156,4 @@ setup.cfg setup.py test-requirements.txt test/__init__.py -test/test_animal_farm.py tox.ini From b2ca2f78e295ce1d94b42f6ebc55d9d5a64f1918 Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Thu, 4 Jun 2020 11:47:35 +0200 Subject: [PATCH 17/18] Solve issue with missing import for array model --- .../codegen/languages/PythonClientExperimentalCodegen.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 9490af435c17..e5adf04afdf9 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 @@ -423,7 +423,7 @@ public Map postProcessAllModels(Map objs) { CodegenProperty modelProperty = fromProperty("value", modelSchema); if (cm.isEnum || cm.isAlias) { - if (!modelProperty.isEnum && !modelProperty.hasValidation) { + 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); } @@ -833,7 +833,7 @@ public CodegenModel fromModel(String name, Schema schema) { if (modelProperty.isEnum == true || modelProperty.hasValidation == true || result.isArrayModel) { // these models are non-object models with enums and/or validations // add a single property to the model so we can have a way to access validations - result.isAlias = !result.isArrayModel; + result.isAlias = true; modelProperty.required = true; List theProperties = Arrays.asList(modelProperty); result.setAllVars(theProperties); From 3132aca2052d497ed9e1f3fbfeb90e46523c5562 Mon Sep 17 00:00:00 2001 From: Jiri Kuncar Date: Thu, 4 Jun 2020 11:59:26 +0200 Subject: [PATCH 18/18] regenerate --- .../docs/AdditionalPropertiesAnyType.md | 2 +- .../docs/AdditionalPropertiesArray.md | 2 +- .../docs/AdditionalPropertiesClass.md | 10 +++++----- .../docs/AdditionalPropertiesObject.md | 2 +- .../petstore/python-experimental/docs/Cat.md | 1 - .../python-experimental/docs/Child.md | 1 - .../python-experimental/docs/ChildCat.md | 1 - .../python-experimental/docs/ChildDog.md | 1 - .../python-experimental/docs/ChildLizard.md | 1 - .../petstore/python-experimental/docs/Dog.md | 1 - .../python-experimental/docs/Parent.md | 1 - .../python-experimental/docs/ParentPet.md | 1 - .../model/additional_properties_any_type.py | 2 +- .../model/additional_properties_array.py | 2 +- .../model/additional_properties_class.py | 20 +++++++++---------- .../model/additional_properties_object.py | 2 +- .../petstore_api/model/cat.py | 2 +- .../petstore_api/model/child.py | 2 +- .../petstore_api/model/child_cat.py | 2 +- .../petstore_api/model/child_dog.py | 2 +- .../petstore_api/model/child_lizard.py | 2 +- .../petstore_api/model/dog.py | 2 +- .../petstore_api/model/parent.py | 2 +- .../petstore_api/model/parent_pet.py | 2 +- 24 files changed, 29 insertions(+), 37 deletions(-) diff --git a/samples/client/petstore/python-experimental/docs/AdditionalPropertiesAnyType.md b/samples/client/petstore/python-experimental/docs/AdditionalPropertiesAnyType.md index 62eee911ea26..d27928ab7527 100644 --- a/samples/client/petstore/python-experimental/docs/AdditionalPropertiesAnyType.md +++ b/samples/client/petstore/python-experimental/docs/AdditionalPropertiesAnyType.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **name** | **str** | | [optional] -**any string name** | **{str: (bool, date, datetime, dict, float, int, list, str, none_type)}** | any string name can be used but the value must be the correct type | [optional] +**any string name** | **bool, date, datetime, dict, float, int, list, str** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/AdditionalPropertiesArray.md b/samples/client/petstore/python-experimental/docs/AdditionalPropertiesArray.md index 46be89a5b23e..6eac3ace2eca 100644 --- a/samples/client/petstore/python-experimental/docs/AdditionalPropertiesArray.md +++ b/samples/client/petstore/python-experimental/docs/AdditionalPropertiesArray.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **name** | **str** | | [optional] -**any string name** | **[{str: (bool, date, datetime, dict, float, int, list, str, none_type)}]** | any string name can be used but the value must be the correct type | [optional] +**any string name** | **[bool, date, datetime, dict, float, int, list, str]** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/AdditionalPropertiesClass.md b/samples/client/petstore/python-experimental/docs/AdditionalPropertiesClass.md index cf00d9d4c816..4b232aa174af 100644 --- a/samples/client/petstore/python-experimental/docs/AdditionalPropertiesClass.md +++ b/samples/client/petstore/python-experimental/docs/AdditionalPropertiesClass.md @@ -8,12 +8,12 @@ Name | Type | Description | Notes **map_integer** | **{str: (int,)}** | | [optional] **map_boolean** | **{str: (bool,)}** | | [optional] **map_array_integer** | **{str: ([int],)}** | | [optional] -**map_array_anytype** | **{str: ([{str: (bool, date, datetime, dict, float, int, list, str, none_type)}],)}** | | [optional] +**map_array_anytype** | **{str: ([bool, date, datetime, dict, float, int, list, str],)}** | | [optional] **map_map_string** | **{str: ({str: (str,)},)}** | | [optional] -**map_map_anytype** | **{str: ({str: ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},)},)}** | | [optional] -**anytype_1** | **{str: (bool, date, datetime, dict, float, int, list, str, none_type)}** | | [optional] -**anytype_2** | **{str: (bool, date, datetime, dict, float, int, list, str, none_type)}** | | [optional] -**anytype_3** | **{str: (bool, date, datetime, dict, float, int, list, str, none_type)}** | | [optional] +**map_map_anytype** | **{str: ({str: (bool, date, datetime, dict, float, int, list, str,)},)}** | | [optional] +**anytype_1** | **bool, date, datetime, dict, float, int, list, str** | | [optional] +**anytype_2** | **bool, date, datetime, dict, float, int, list, str** | | [optional] +**anytype_3** | **bool, date, datetime, dict, float, int, list, str** | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/AdditionalPropertiesObject.md b/samples/client/petstore/python-experimental/docs/AdditionalPropertiesObject.md index 15763836ddb1..36026fe72f82 100644 --- a/samples/client/petstore/python-experimental/docs/AdditionalPropertiesObject.md +++ b/samples/client/petstore/python-experimental/docs/AdditionalPropertiesObject.md @@ -4,7 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **name** | **str** | | [optional] -**any string name** | **{str: ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},)}** | any string name can be used but the value must be the correct type | [optional] +**any string name** | **{str: (bool, date, datetime, dict, float, int, list, str,)}** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/Cat.md b/samples/client/petstore/python-experimental/docs/Cat.md index 846a97c82a84..1d7b5b26d715 100644 --- a/samples/client/petstore/python-experimental/docs/Cat.md +++ b/samples/client/petstore/python-experimental/docs/Cat.md @@ -6,7 +6,6 @@ Name | Type | Description | Notes **class_name** | **str** | | **declawed** | **bool** | | [optional] **color** | **str** | | [optional] if omitted the server will use the default value of 'red' -**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/Child.md b/samples/client/petstore/python-experimental/docs/Child.md index 4e43e94825b7..bc3c7f3922d3 100644 --- a/samples/client/petstore/python-experimental/docs/Child.md +++ b/samples/client/petstore/python-experimental/docs/Child.md @@ -6,7 +6,6 @@ Name | Type | Description | Notes **radio_waves** | **bool** | | [optional] **tele_vision** | **bool** | | [optional] **inter_net** | **bool** | | [optional] -**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/ChildCat.md b/samples/client/petstore/python-experimental/docs/ChildCat.md index bee23082474c..8f5ea4b2ced0 100644 --- a/samples/client/petstore/python-experimental/docs/ChildCat.md +++ b/samples/client/petstore/python-experimental/docs/ChildCat.md @@ -5,7 +5,6 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **pet_type** | **str** | | **name** | **str** | | [optional] -**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/ChildDog.md b/samples/client/petstore/python-experimental/docs/ChildDog.md index 631b0362886c..2680d987a452 100644 --- a/samples/client/petstore/python-experimental/docs/ChildDog.md +++ b/samples/client/petstore/python-experimental/docs/ChildDog.md @@ -5,7 +5,6 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **pet_type** | **str** | | **bark** | **str** | | [optional] -**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/ChildLizard.md b/samples/client/petstore/python-experimental/docs/ChildLizard.md index 2e315eb2f21b..97b8891a27e2 100644 --- a/samples/client/petstore/python-experimental/docs/ChildLizard.md +++ b/samples/client/petstore/python-experimental/docs/ChildLizard.md @@ -5,7 +5,6 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **pet_type** | **str** | | **loves_rocks** | **bool** | | [optional] -**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/Dog.md b/samples/client/petstore/python-experimental/docs/Dog.md index 4c0497d67698..ec98b99dcec5 100644 --- a/samples/client/petstore/python-experimental/docs/Dog.md +++ b/samples/client/petstore/python-experimental/docs/Dog.md @@ -6,7 +6,6 @@ Name | Type | Description | Notes **class_name** | **str** | | **breed** | **str** | | [optional] **color** | **str** | | [optional] if omitted the server will use the default value of 'red' -**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/Parent.md b/samples/client/petstore/python-experimental/docs/Parent.md index 74beb2c531ce..2437d3c81ac9 100644 --- a/samples/client/petstore/python-experimental/docs/Parent.md +++ b/samples/client/petstore/python-experimental/docs/Parent.md @@ -5,7 +5,6 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **radio_waves** | **bool** | | [optional] **tele_vision** | **bool** | | [optional] -**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/ParentPet.md b/samples/client/petstore/python-experimental/docs/ParentPet.md index 78693cf8f0e6..12bfa5c7fe5c 100644 --- a/samples/client/petstore/python-experimental/docs/ParentPet.md +++ b/samples/client/petstore/python-experimental/docs/ParentPet.md @@ -4,7 +4,6 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **pet_type** | **str** | | -**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_any_type.py b/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_any_type.py index 65b9c2cc7ec2..7ea7b1f807bd 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_any_type.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_any_type.py @@ -65,7 +65,7 @@ class AdditionalPropertiesAnyType(ModelNormal): validations = { } - additional_properties_type = ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},) # noqa: E501 + additional_properties_type = (bool, date, datetime, dict, float, int, list, str,) # noqa: E501 _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_array.py b/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_array.py index 0d76c73813f5..5dc25499eaf9 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_array.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_array.py @@ -65,7 +65,7 @@ class AdditionalPropertiesArray(ModelNormal): validations = { } - additional_properties_type = ([{str: (bool, date, datetime, dict, float, int, list, str, none_type)}],) # noqa: E501 + additional_properties_type = ([bool, date, datetime, dict, float, int, list, str],) # noqa: E501 _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_class.py b/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_class.py index eb4d08acb5ce..1b98c5f06e5d 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_class.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_class.py @@ -85,12 +85,12 @@ def openapi_types(): 'map_integer': ({str: (int,)},), # noqa: E501 'map_boolean': ({str: (bool,)},), # noqa: E501 'map_array_integer': ({str: ([int],)},), # noqa: E501 - 'map_array_anytype': ({str: ([{str: (bool, date, datetime, dict, float, int, list, str, none_type)}],)},), # noqa: E501 + 'map_array_anytype': ({str: ([bool, date, datetime, dict, float, int, list, str],)},), # noqa: E501 'map_map_string': ({str: ({str: (str,)},)},), # noqa: E501 - 'map_map_anytype': ({str: ({str: ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},)},)},), # noqa: E501 - 'anytype_1': ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},), # noqa: E501 - 'anytype_2': ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},), # noqa: E501 - 'anytype_3': ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},), # noqa: E501 + 'map_map_anytype': ({str: ({str: (bool, date, datetime, dict, float, int, list, str,)},)},), # noqa: E501 + 'anytype_1': (bool, date, datetime, dict, float, int, list, str,), # noqa: E501 + 'anytype_2': (bool, date, datetime, dict, float, int, list, str,), # noqa: E501 + 'anytype_3': (bool, date, datetime, dict, float, int, list, str,), # noqa: E501 } @cached_property @@ -162,12 +162,12 @@ def __init__(self, *args, **kwargs): # noqa: E501 map_integer ({str: (int,)}): [optional] # noqa: E501 map_boolean ({str: (bool,)}): [optional] # noqa: E501 map_array_integer ({str: ([int],)}): [optional] # noqa: E501 - map_array_anytype ({str: ([{str: (bool, date, datetime, dict, float, int, list, str, none_type)}],)}): [optional] # noqa: E501 + map_array_anytype ({str: ([bool, date, datetime, dict, float, int, list, str],)}): [optional] # noqa: E501 map_map_string ({str: ({str: (str,)},)}): [optional] # noqa: E501 - map_map_anytype ({str: ({str: ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},)},)}): [optional] # noqa: E501 - anytype_1 ({str: (bool, date, datetime, dict, float, int, list, str, none_type)}): [optional] # noqa: E501 - anytype_2 ({str: (bool, date, datetime, dict, float, int, list, str, none_type)}): [optional] # noqa: E501 - anytype_3 ({str: (bool, date, datetime, dict, float, int, list, str, none_type)}): [optional] # noqa: E501 + map_map_anytype ({str: ({str: (bool, date, datetime, dict, float, int, list, str,)},)}): [optional] # noqa: E501 + anytype_1 (bool, date, datetime, dict, float, int, list, str): [optional] # noqa: E501 + anytype_2 (bool, date, datetime, dict, float, int, list, str): [optional] # noqa: E501 + anytype_3 (bool, date, datetime, dict, float, int, list, str): [optional] # noqa: E501 """ _check_type = kwargs.pop('_check_type', True) diff --git a/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_object.py b/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_object.py index c68db9ca6589..03ca022e6f82 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_object.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/additional_properties_object.py @@ -65,7 +65,7 @@ class AdditionalPropertiesObject(ModelNormal): validations = { } - additional_properties_type = ({str: ({str: (bool, date, datetime, dict, float, int, list, str, none_type)},)},) # noqa: E501 + additional_properties_type = ({str: (bool, date, datetime, dict, float, int, list, str,)},) # noqa: E501 _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/model/cat.py b/samples/client/petstore/python-experimental/petstore_api/model/cat.py index 011e8739b52c..b40a97dbab9a 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/cat.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/cat.py @@ -75,7 +75,7 @@ class Cat(ModelComposed): validations = { } - additional_properties_type = (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501 + additional_properties_type = None _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/model/child.py b/samples/client/petstore/python-experimental/petstore_api/model/child.py index c2b62b72bdf8..37c138d6a488 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/child.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/child.py @@ -75,7 +75,7 @@ class Child(ModelComposed): validations = { } - additional_properties_type = (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501 + additional_properties_type = None _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/model/child_cat.py b/samples/client/petstore/python-experimental/petstore_api/model/child_cat.py index 996f3e0098e2..6d42f11a18ff 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/child_cat.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/child_cat.py @@ -75,7 +75,7 @@ class ChildCat(ModelComposed): validations = { } - additional_properties_type = (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501 + additional_properties_type = None _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/model/child_dog.py b/samples/client/petstore/python-experimental/petstore_api/model/child_dog.py index f60b977ef118..b7a93571a6a0 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/child_dog.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/child_dog.py @@ -75,7 +75,7 @@ class ChildDog(ModelComposed): validations = { } - additional_properties_type = (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501 + additional_properties_type = None _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/model/child_lizard.py b/samples/client/petstore/python-experimental/petstore_api/model/child_lizard.py index 548db149f502..978fea14a183 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/child_lizard.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/child_lizard.py @@ -75,7 +75,7 @@ class ChildLizard(ModelComposed): validations = { } - additional_properties_type = (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501 + additional_properties_type = None _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/model/dog.py b/samples/client/petstore/python-experimental/petstore_api/model/dog.py index a100eb3c70ef..547eba90c2b1 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/dog.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/dog.py @@ -75,7 +75,7 @@ class Dog(ModelComposed): validations = { } - additional_properties_type = (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501 + additional_properties_type = None _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/model/parent.py b/samples/client/petstore/python-experimental/petstore_api/model/parent.py index a9ccc697d1d5..a855a3ffd014 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/parent.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/parent.py @@ -75,7 +75,7 @@ class Parent(ModelComposed): validations = { } - additional_properties_type = (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501 + additional_properties_type = None _nullable = False diff --git a/samples/client/petstore/python-experimental/petstore_api/model/parent_pet.py b/samples/client/petstore/python-experimental/petstore_api/model/parent_pet.py index 8687982cf8f1..0b0b30c656f5 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model/parent_pet.py +++ b/samples/client/petstore/python-experimental/petstore_api/model/parent_pet.py @@ -85,7 +85,7 @@ class ParentPet(ModelComposed): validations = { } - additional_properties_type = (bool, date, datetime, dict, float, int, list, str, none_type,) # noqa: E501 + additional_properties_type = None _nullable = False