From 49cf292064353627a634484f66c693e5ab681b54 Mon Sep 17 00:00:00 2001 From: Guillaume Smaha Date: Mon, 13 May 2019 16:09:28 -0400 Subject: [PATCH 1/4] Support python 3.7 for all server-generators Signed-off-by: Guillaume Smaha --- .../PythonAbstractConnexionServerCodegen.java | 1 + .../PythonBluePlanetServerCodegen.java | 2 ++ .../python-aiohttp/typing_patch.mustache | 32 +++++++++++++++++++ .../resources/python-aiohttp/util.mustache | 7 ++-- .../app/{{packageName}}/typing_patch.mustache | 32 +++++++++++++++++++ .../app/{{packageName}}/util.mustache | 7 ++-- .../python-flask/typing_patch.mustache | 32 +++++++++++++++++++ .../main/resources/python-flask/util.mustache | 7 ++-- .../.openapi-generator/VERSION | 2 +- .../openapi_server/openapi/openapi.yaml | 17 ++++++---- .../openapi_server/typing_patch.py | 32 +++++++++++++++++++ .../openapi_server/util.py | 7 ++-- .../python-flask/.openapi-generator/VERSION | 2 +- .../openapi_server/openapi/openapi.yaml | 17 ++++++---- .../openapi_server/typing_patch.py | 32 +++++++++++++++++++ .../python-flask/openapi_server/util.py | 7 ++-- .../python-aiohttp/.openapi-generator/VERSION | 2 +- .../openapi_server/openapi/openapi.yaml | 12 ++++--- .../openapi_server/typing_patch.py | 32 +++++++++++++++++++ .../python-aiohttp/openapi_server/util.py | 7 ++-- .../.openapi-generator/VERSION | 2 +- .../app/openapi_server/typing_patch.py | 32 +++++++++++++++++++ .../app/openapi_server/util.py | 7 ++-- .../.openapi-generator/VERSION | 2 +- .../openapi_server/openapi/openapi.yaml | 12 ++++--- .../openapi_server/typing_patch.py | 32 +++++++++++++++++++ .../openapi_server/util.py | 7 ++-- .../python-flask/.openapi-generator/VERSION | 2 +- .../openapi_server/openapi/openapi.yaml | 12 ++++--- .../openapi_server/typing_patch.py | 32 +++++++++++++++++++ .../python-flask/openapi_server/util.py | 7 ++-- 31 files changed, 377 insertions(+), 59 deletions(-) create mode 100644 modules/openapi-generator/src/main/resources/python-aiohttp/typing_patch.mustache create mode 100644 modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/typing_patch.mustache create mode 100644 modules/openapi-generator/src/main/resources/python-flask/typing_patch.mustache create mode 100644 samples/server/openapi3/petstore/python-flask-python2/openapi_server/typing_patch.py create mode 100644 samples/server/openapi3/petstore/python-flask/openapi_server/typing_patch.py create mode 100644 samples/server/petstore/python-aiohttp/openapi_server/typing_patch.py create mode 100644 samples/server/petstore/python-blueplanet/app/openapi_server/typing_patch.py create mode 100644 samples/server/petstore/python-flask-python2/openapi_server/typing_patch.py create mode 100644 samples/server/petstore/python-flask/openapi_server/typing_patch.py diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonAbstractConnexionServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonAbstractConnexionServerCodegen.java index e3e9d4ebf655..2ec3c1c8240d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonAbstractConnexionServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonAbstractConnexionServerCodegen.java @@ -201,6 +201,7 @@ public void processOpts() { } supportingFiles.add(new SupportingFile("__main__.mustache", packagePath(), "__main__.py")); supportingFiles.add(new SupportingFile("util.mustache", packagePath(), "util.py")); + supportingFiles.add(new SupportingFile("typing_patch.mustache", packagePath(), "typing_patch.py")); supportingFiles.add(new SupportingFile("__init__.mustache", packagePath() + File.separatorChar + packageToPath(controllerPackage), "__init__.py")); supportingFiles.add(new SupportingFile("security_controller_.mustache", packagePath() + File.separatorChar + packageToPath(controllerPackage), "security_controller_.py")); supportingFiles.add(new SupportingFile("__init__model.mustache", packagePath() + File.separatorChar + packageToPath(modelPackage), "__init__.py")); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonBluePlanetServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonBluePlanetServerCodegen.java index 7a1599a4c32d..259e7a046980 100755 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonBluePlanetServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonBluePlanetServerCodegen.java @@ -118,6 +118,7 @@ public void processOpts() { supportingFiles.add(new SupportingFile("app/{{packageName}}/__main__.mustache", APP_PACKAGE_PATH, "__main__.py")); supportingFiles.add(new SupportingFile("app/{{packageName}}/encoder.mustache", APP_PACKAGE_PATH, "encoder.py")); supportingFiles.add(new SupportingFile("app/{{packageName}}/util.mustache", APP_PACKAGE_PATH, "util.py")); + supportingFiles.add(new SupportingFile("app/{{packageName}}/typing_patch.mustache", APP_PACKAGE_PATH, "typing_patch.py")); supportingFiles.add(new SupportingFile("app/{{packageName}}/controllers/__init__.mustache", CONTROLLER_PATH, "__init__.py")); @@ -192,6 +193,7 @@ protected void addSupportingFiles() { supportingFiles.add(new SupportingFile("app/{{packageName}}/__main__.mustache", APP_PACKAGE_PATH, "__main__.py")); supportingFiles.add(new SupportingFile("app/{{packageName}}/encoder.mustache", APP_PACKAGE_PATH, "encoder.py")); supportingFiles.add(new SupportingFile("app/{{packageName}}/util.mustache", APP_PACKAGE_PATH, "util.py")); + supportingFiles.add(new SupportingFile("app/{{packageName}}/typing_patch.mustache", APP_PACKAGE_PATH, "typing_patch.py")); supportingFiles.add(new SupportingFile("app/{{packageName}}/controllers/__init__.mustache", CONTROLLER_PATH, "__init__.py")); diff --git a/modules/openapi-generator/src/main/resources/python-aiohttp/typing_patch.mustache b/modules/openapi-generator/src/main/resources/python-aiohttp/typing_patch.mustache new file mode 100644 index 000000000000..a56029f6b5bb --- /dev/null +++ b/modules/openapi-generator/src/main/resources/python-aiohttp/typing_patch.mustache @@ -0,0 +1,32 @@ +# coding: utf-8 + +import sys + +if sys.version_info < (3, 7): + import typing + + def is_generic(klass): + """ Determine whether klass is a generic class """ + return type(klass) == typing.GenericMeta + + def is_dict(klass): + """ Determine whether klass is a Dict """ + return klass.__extra__ == dict + + def is_list(klass): + """ Determine whether klass is a List """ + return klass.__extra__ == list + +else: + + def is_generic(klass): + """ Determine whether klass is a generic class """ + return hasattr(klass, '__origin__') + + def is_dict(klass): + """ Determine whether klass is a Dict """ + return klass.__origin__ == list + + def is_list(klass): + """ Determine whether klass is a List """ + return klass.__origin__ == list diff --git a/modules/openapi-generator/src/main/resources/python-aiohttp/util.mustache b/modules/openapi-generator/src/main/resources/python-aiohttp/util.mustache index 9263acb016ea..dbe64d400d62 100644 --- a/modules/openapi-generator/src/main/resources/python-aiohttp/util.mustache +++ b/modules/openapi-generator/src/main/resources/python-aiohttp/util.mustache @@ -2,6 +2,7 @@ import datetime import typing from typing import Union +from {{packageName}} import typing_patch T = typing.TypeVar('T') Class = typing.Type[T] @@ -26,10 +27,10 @@ def _deserialize(data: Union[dict, list, str], klass: Union[Class, str]) -> Unio return deserialize_date(data) elif klass == datetime.datetime: return deserialize_datetime(data) - elif type(klass) == typing.GenericMeta: - if klass.__extra__ == list: + elif typing_patch.is_generic(klass): + if typing_patch.is_list(klass): return _deserialize_list(data, klass.__args__[0]) - if klass.__extra__ == dict: + if typing_patch.is_dict(klass): return _deserialize_dict(data, klass.__args__[1]) else: return deserialize_model(data, klass) diff --git a/modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/typing_patch.mustache b/modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/typing_patch.mustache new file mode 100644 index 000000000000..a56029f6b5bb --- /dev/null +++ b/modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/typing_patch.mustache @@ -0,0 +1,32 @@ +# coding: utf-8 + +import sys + +if sys.version_info < (3, 7): + import typing + + def is_generic(klass): + """ Determine whether klass is a generic class """ + return type(klass) == typing.GenericMeta + + def is_dict(klass): + """ Determine whether klass is a Dict """ + return klass.__extra__ == dict + + def is_list(klass): + """ Determine whether klass is a List """ + return klass.__extra__ == list + +else: + + def is_generic(klass): + """ Determine whether klass is a generic class """ + return hasattr(klass, '__origin__') + + def is_dict(klass): + """ Determine whether klass is a Dict """ + return klass.__origin__ == list + + def is_list(klass): + """ Determine whether klass is a List """ + return klass.__origin__ == list diff --git a/modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/util.mustache b/modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/util.mustache index 527d1424c3d5..a15169e1b0b3 100644 --- a/modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/util.mustache +++ b/modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/util.mustache @@ -2,6 +2,7 @@ import datetime import six import typing +from {{packageName}} import typing_patch def _deserialize(data, klass): @@ -23,10 +24,10 @@ def _deserialize(data, klass): return deserialize_date(data) elif klass == datetime.datetime: return deserialize_datetime(data) - elif type(klass) == typing.GenericMeta: - if klass.__extra__ == list: + elif typing_patch.is_generic(klass): + if typing_patch.is_list(klass): return _deserialize_list(data, klass.__args__[0]) - if klass.__extra__ == dict: + if typing_patch.is_dict(klass): return _deserialize_dict(data, klass.__args__[1]) else: return deserialize_model(data, klass) diff --git a/modules/openapi-generator/src/main/resources/python-flask/typing_patch.mustache b/modules/openapi-generator/src/main/resources/python-flask/typing_patch.mustache new file mode 100644 index 000000000000..a56029f6b5bb --- /dev/null +++ b/modules/openapi-generator/src/main/resources/python-flask/typing_patch.mustache @@ -0,0 +1,32 @@ +# coding: utf-8 + +import sys + +if sys.version_info < (3, 7): + import typing + + def is_generic(klass): + """ Determine whether klass is a generic class """ + return type(klass) == typing.GenericMeta + + def is_dict(klass): + """ Determine whether klass is a Dict """ + return klass.__extra__ == dict + + def is_list(klass): + """ Determine whether klass is a List """ + return klass.__extra__ == list + +else: + + def is_generic(klass): + """ Determine whether klass is a generic class """ + return hasattr(klass, '__origin__') + + def is_dict(klass): + """ Determine whether klass is a Dict """ + return klass.__origin__ == list + + def is_list(klass): + """ Determine whether klass is a List """ + return klass.__origin__ == list diff --git a/modules/openapi-generator/src/main/resources/python-flask/util.mustache b/modules/openapi-generator/src/main/resources/python-flask/util.mustache index c7340cd00059..17e7af17aec4 100644 --- a/modules/openapi-generator/src/main/resources/python-flask/util.mustache +++ b/modules/openapi-generator/src/main/resources/python-flask/util.mustache @@ -2,6 +2,7 @@ import datetime import six import typing +from {{packageName}} import typing_patch def _deserialize(data, klass): @@ -23,10 +24,10 @@ def _deserialize(data, klass): return deserialize_date(data) elif klass == datetime.datetime: return deserialize_datetime(data) - elif type(klass) == typing.GenericMeta: - if klass.__extra__ == list: + elif typing_patch.is_generic(klass): + if typing_patch.is_list(klass): return _deserialize_list(data, klass.__args__[0]) - if klass.__extra__ == dict: + if typing_patch.is_dict(klass): return _deserialize_dict(data, klass.__args__[1]) else: return deserialize_model(data, klass) diff --git a/samples/server/openapi3/petstore/python-flask-python2/.openapi-generator/VERSION b/samples/server/openapi3/petstore/python-flask-python2/.openapi-generator/VERSION index afa636560641..0c89fc927e32 100644 --- a/samples/server/openapi3/petstore/python-flask-python2/.openapi-generator/VERSION +++ b/samples/server/openapi3/petstore/python-flask-python2/.openapi-generator/VERSION @@ -1 +1 @@ -4.0.0-SNAPSHOT \ No newline at end of file +4.0.0 \ No newline at end of file diff --git a/samples/server/openapi3/petstore/python-flask-python2/openapi_server/openapi/openapi.yaml b/samples/server/openapi3/petstore/python-flask-python2/openapi_server/openapi/openapi.yaml index f11d309f8d50..851fb5fb8167 100644 --- a/samples/server/openapi3/petstore/python-flask-python2/openapi_server/openapi/openapi.yaml +++ b/samples/server/openapi3/petstore/python-flask-python2/openapi_server/openapi/openapi.yaml @@ -1,6 +1,7 @@ openapi: 3.0.0 info: - description: This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + description: This is a sample server Petstore server. For this sample, you can use + the api key `special-key` to test the authorization filters. license: name: Apache-2.0 url: http://www.apache.org/licenses/LICENSE-2.0.html @@ -92,7 +93,6 @@ paths: description: Invalid status value security: - petstore_auth: - - write:pets - read:pets summary: Finds Pets by status tags: @@ -101,7 +101,8 @@ paths: /pet/findByTags: get: deprecated: true - description: Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + description: Multiple tags can be provided with comma separated strings. Use + tag1, tag2, tag3 for testing. operationId: find_pets_by_tags parameters: - description: Tags to filter by @@ -141,7 +142,6 @@ paths: description: Invalid tag value security: - petstore_auth: - - write:pets - read:pets summary: Finds Pets by tags tags: @@ -337,7 +337,8 @@ paths: x-openapi-router-controller: openapi_server.controllers.store_controller /store/order/{orderId}: delete: - description: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + description: For valid response try integer IDs with value < 1000. Anything + above 1000 or nonintegers will generate API errors operationId: delete_order parameters: - description: ID of the order that needs to be deleted @@ -358,7 +359,8 @@ paths: - store x-openapi-router-controller: openapi_server.controllers.store_controller get: - description: For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + description: For valid response try integer IDs with value <= 5 or > 10. Other + values will generated exceptions operationId: get_order_by_id parameters: - description: ID of pet that needs to be fetched @@ -471,7 +473,8 @@ paths: description: successful operation headers: Set-Cookie: - description: Cookie authentication key for use with the `auth_cookie` apiKey authentication. + description: Cookie authentication key for use with the `auth_cookie` + apiKey authentication. explode: false schema: example: AUTH_KEY=abcde12345; Path=/; HttpOnly diff --git a/samples/server/openapi3/petstore/python-flask-python2/openapi_server/typing_patch.py b/samples/server/openapi3/petstore/python-flask-python2/openapi_server/typing_patch.py new file mode 100644 index 000000000000..a56029f6b5bb --- /dev/null +++ b/samples/server/openapi3/petstore/python-flask-python2/openapi_server/typing_patch.py @@ -0,0 +1,32 @@ +# coding: utf-8 + +import sys + +if sys.version_info < (3, 7): + import typing + + def is_generic(klass): + """ Determine whether klass is a generic class """ + return type(klass) == typing.GenericMeta + + def is_dict(klass): + """ Determine whether klass is a Dict """ + return klass.__extra__ == dict + + def is_list(klass): + """ Determine whether klass is a List """ + return klass.__extra__ == list + +else: + + def is_generic(klass): + """ Determine whether klass is a generic class """ + return hasattr(klass, '__origin__') + + def is_dict(klass): + """ Determine whether klass is a Dict """ + return klass.__origin__ == list + + def is_list(klass): + """ Determine whether klass is a List """ + return klass.__origin__ == list diff --git a/samples/server/openapi3/petstore/python-flask-python2/openapi_server/util.py b/samples/server/openapi3/petstore/python-flask-python2/openapi_server/util.py index c7340cd00059..d753b2a08088 100644 --- a/samples/server/openapi3/petstore/python-flask-python2/openapi_server/util.py +++ b/samples/server/openapi3/petstore/python-flask-python2/openapi_server/util.py @@ -2,6 +2,7 @@ import six import typing +from openapi_server import typing_patch def _deserialize(data, klass): @@ -23,10 +24,10 @@ def _deserialize(data, klass): return deserialize_date(data) elif klass == datetime.datetime: return deserialize_datetime(data) - elif type(klass) == typing.GenericMeta: - if klass.__extra__ == list: + elif typing_patch.is_generic(klass): + if typing_patch.is_list(klass): return _deserialize_list(data, klass.__args__[0]) - if klass.__extra__ == dict: + if typing_patch.is_dict(klass): return _deserialize_dict(data, klass.__args__[1]) else: return deserialize_model(data, klass) diff --git a/samples/server/openapi3/petstore/python-flask/.openapi-generator/VERSION b/samples/server/openapi3/petstore/python-flask/.openapi-generator/VERSION index afa636560641..0c89fc927e32 100644 --- a/samples/server/openapi3/petstore/python-flask/.openapi-generator/VERSION +++ b/samples/server/openapi3/petstore/python-flask/.openapi-generator/VERSION @@ -1 +1 @@ -4.0.0-SNAPSHOT \ No newline at end of file +4.0.0 \ No newline at end of file diff --git a/samples/server/openapi3/petstore/python-flask/openapi_server/openapi/openapi.yaml b/samples/server/openapi3/petstore/python-flask/openapi_server/openapi/openapi.yaml index f11d309f8d50..851fb5fb8167 100644 --- a/samples/server/openapi3/petstore/python-flask/openapi_server/openapi/openapi.yaml +++ b/samples/server/openapi3/petstore/python-flask/openapi_server/openapi/openapi.yaml @@ -1,6 +1,7 @@ openapi: 3.0.0 info: - description: This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + description: This is a sample server Petstore server. For this sample, you can use + the api key `special-key` to test the authorization filters. license: name: Apache-2.0 url: http://www.apache.org/licenses/LICENSE-2.0.html @@ -92,7 +93,6 @@ paths: description: Invalid status value security: - petstore_auth: - - write:pets - read:pets summary: Finds Pets by status tags: @@ -101,7 +101,8 @@ paths: /pet/findByTags: get: deprecated: true - description: Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + description: Multiple tags can be provided with comma separated strings. Use + tag1, tag2, tag3 for testing. operationId: find_pets_by_tags parameters: - description: Tags to filter by @@ -141,7 +142,6 @@ paths: description: Invalid tag value security: - petstore_auth: - - write:pets - read:pets summary: Finds Pets by tags tags: @@ -337,7 +337,8 @@ paths: x-openapi-router-controller: openapi_server.controllers.store_controller /store/order/{orderId}: delete: - description: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + description: For valid response try integer IDs with value < 1000. Anything + above 1000 or nonintegers will generate API errors operationId: delete_order parameters: - description: ID of the order that needs to be deleted @@ -358,7 +359,8 @@ paths: - store x-openapi-router-controller: openapi_server.controllers.store_controller get: - description: For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + description: For valid response try integer IDs with value <= 5 or > 10. Other + values will generated exceptions operationId: get_order_by_id parameters: - description: ID of pet that needs to be fetched @@ -471,7 +473,8 @@ paths: description: successful operation headers: Set-Cookie: - description: Cookie authentication key for use with the `auth_cookie` apiKey authentication. + description: Cookie authentication key for use with the `auth_cookie` + apiKey authentication. explode: false schema: example: AUTH_KEY=abcde12345; Path=/; HttpOnly diff --git a/samples/server/openapi3/petstore/python-flask/openapi_server/typing_patch.py b/samples/server/openapi3/petstore/python-flask/openapi_server/typing_patch.py new file mode 100644 index 000000000000..a56029f6b5bb --- /dev/null +++ b/samples/server/openapi3/petstore/python-flask/openapi_server/typing_patch.py @@ -0,0 +1,32 @@ +# coding: utf-8 + +import sys + +if sys.version_info < (3, 7): + import typing + + def is_generic(klass): + """ Determine whether klass is a generic class """ + return type(klass) == typing.GenericMeta + + def is_dict(klass): + """ Determine whether klass is a Dict """ + return klass.__extra__ == dict + + def is_list(klass): + """ Determine whether klass is a List """ + return klass.__extra__ == list + +else: + + def is_generic(klass): + """ Determine whether klass is a generic class """ + return hasattr(klass, '__origin__') + + def is_dict(klass): + """ Determine whether klass is a Dict """ + return klass.__origin__ == list + + def is_list(klass): + """ Determine whether klass is a List """ + return klass.__origin__ == list diff --git a/samples/server/openapi3/petstore/python-flask/openapi_server/util.py b/samples/server/openapi3/petstore/python-flask/openapi_server/util.py index c7340cd00059..d753b2a08088 100644 --- a/samples/server/openapi3/petstore/python-flask/openapi_server/util.py +++ b/samples/server/openapi3/petstore/python-flask/openapi_server/util.py @@ -2,6 +2,7 @@ import six import typing +from openapi_server import typing_patch def _deserialize(data, klass): @@ -23,10 +24,10 @@ def _deserialize(data, klass): return deserialize_date(data) elif klass == datetime.datetime: return deserialize_datetime(data) - elif type(klass) == typing.GenericMeta: - if klass.__extra__ == list: + elif typing_patch.is_generic(klass): + if typing_patch.is_list(klass): return _deserialize_list(data, klass.__args__[0]) - if klass.__extra__ == dict: + if typing_patch.is_dict(klass): return _deserialize_dict(data, klass.__args__[1]) else: return deserialize_model(data, klass) diff --git a/samples/server/petstore/python-aiohttp/.openapi-generator/VERSION b/samples/server/petstore/python-aiohttp/.openapi-generator/VERSION index afa636560641..0c89fc927e32 100644 --- a/samples/server/petstore/python-aiohttp/.openapi-generator/VERSION +++ b/samples/server/petstore/python-aiohttp/.openapi-generator/VERSION @@ -1 +1 @@ -4.0.0-SNAPSHOT \ No newline at end of file +4.0.0 \ No newline at end of file diff --git a/samples/server/petstore/python-aiohttp/openapi_server/openapi/openapi.yaml b/samples/server/petstore/python-aiohttp/openapi_server/openapi/openapi.yaml index 1979eb6b1c2d..3571653f41c9 100644 --- a/samples/server/petstore/python-aiohttp/openapi_server/openapi/openapi.yaml +++ b/samples/server/petstore/python-aiohttp/openapi_server/openapi/openapi.yaml @@ -1,6 +1,7 @@ openapi: 3.0.1 info: - description: This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + description: This is a sample server Petstore server. For this sample, you can use + the api key `special-key` to test the authorization filters. license: name: Apache-2.0 url: http://www.apache.org/licenses/LICENSE-2.0.html @@ -123,7 +124,8 @@ paths: /pet/findByTags: get: deprecated: true - description: Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + description: Multiple tags can be provided with comma separated strings. Use + tag1, tag2, tag3 for testing. operationId: find_pets_by_tags parameters: - description: Tags to filter by @@ -347,7 +349,8 @@ paths: x-openapi-router-controller: openapi_server.controllers.store_controller /store/order/{orderId}: delete: - description: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + description: For valid response try integer IDs with value < 1000. Anything + above 1000 or nonintegers will generate API errors operationId: delete_order parameters: - description: ID of the order that needs to be deleted @@ -368,7 +371,8 @@ paths: - store x-openapi-router-controller: openapi_server.controllers.store_controller get: - description: For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + description: For valid response try integer IDs with value <= 5 or > 10. Other + values will generated exceptions operationId: get_order_by_id parameters: - description: ID of pet that needs to be fetched diff --git a/samples/server/petstore/python-aiohttp/openapi_server/typing_patch.py b/samples/server/petstore/python-aiohttp/openapi_server/typing_patch.py new file mode 100644 index 000000000000..a56029f6b5bb --- /dev/null +++ b/samples/server/petstore/python-aiohttp/openapi_server/typing_patch.py @@ -0,0 +1,32 @@ +# coding: utf-8 + +import sys + +if sys.version_info < (3, 7): + import typing + + def is_generic(klass): + """ Determine whether klass is a generic class """ + return type(klass) == typing.GenericMeta + + def is_dict(klass): + """ Determine whether klass is a Dict """ + return klass.__extra__ == dict + + def is_list(klass): + """ Determine whether klass is a List """ + return klass.__extra__ == list + +else: + + def is_generic(klass): + """ Determine whether klass is a generic class """ + return hasattr(klass, '__origin__') + + def is_dict(klass): + """ Determine whether klass is a Dict """ + return klass.__origin__ == list + + def is_list(klass): + """ Determine whether klass is a List """ + return klass.__origin__ == list diff --git a/samples/server/petstore/python-aiohttp/openapi_server/util.py b/samples/server/petstore/python-aiohttp/openapi_server/util.py index 9263acb016ea..a290ec377a71 100644 --- a/samples/server/petstore/python-aiohttp/openapi_server/util.py +++ b/samples/server/petstore/python-aiohttp/openapi_server/util.py @@ -2,6 +2,7 @@ import typing from typing import Union +from openapi_server import typing_patch T = typing.TypeVar('T') Class = typing.Type[T] @@ -26,10 +27,10 @@ def _deserialize(data: Union[dict, list, str], klass: Union[Class, str]) -> Unio return deserialize_date(data) elif klass == datetime.datetime: return deserialize_datetime(data) - elif type(klass) == typing.GenericMeta: - if klass.__extra__ == list: + elif typing_patch.is_generic(klass): + if typing_patch.is_list(klass): return _deserialize_list(data, klass.__args__[0]) - if klass.__extra__ == dict: + if typing_patch.is_dict(klass): return _deserialize_dict(data, klass.__args__[1]) else: return deserialize_model(data, klass) diff --git a/samples/server/petstore/python-blueplanet/.openapi-generator/VERSION b/samples/server/petstore/python-blueplanet/.openapi-generator/VERSION index afa636560641..0c89fc927e32 100644 --- a/samples/server/petstore/python-blueplanet/.openapi-generator/VERSION +++ b/samples/server/petstore/python-blueplanet/.openapi-generator/VERSION @@ -1 +1 @@ -4.0.0-SNAPSHOT \ No newline at end of file +4.0.0 \ No newline at end of file diff --git a/samples/server/petstore/python-blueplanet/app/openapi_server/typing_patch.py b/samples/server/petstore/python-blueplanet/app/openapi_server/typing_patch.py new file mode 100644 index 000000000000..a56029f6b5bb --- /dev/null +++ b/samples/server/petstore/python-blueplanet/app/openapi_server/typing_patch.py @@ -0,0 +1,32 @@ +# coding: utf-8 + +import sys + +if sys.version_info < (3, 7): + import typing + + def is_generic(klass): + """ Determine whether klass is a generic class """ + return type(klass) == typing.GenericMeta + + def is_dict(klass): + """ Determine whether klass is a Dict """ + return klass.__extra__ == dict + + def is_list(klass): + """ Determine whether klass is a List """ + return klass.__extra__ == list + +else: + + def is_generic(klass): + """ Determine whether klass is a generic class """ + return hasattr(klass, '__origin__') + + def is_dict(klass): + """ Determine whether klass is a Dict """ + return klass.__origin__ == list + + def is_list(klass): + """ Determine whether klass is a List """ + return klass.__origin__ == list diff --git a/samples/server/petstore/python-blueplanet/app/openapi_server/util.py b/samples/server/petstore/python-blueplanet/app/openapi_server/util.py index 527d1424c3d5..72499ff45050 100644 --- a/samples/server/petstore/python-blueplanet/app/openapi_server/util.py +++ b/samples/server/petstore/python-blueplanet/app/openapi_server/util.py @@ -2,6 +2,7 @@ import six import typing +from openapi_server import typing_patch def _deserialize(data, klass): @@ -23,10 +24,10 @@ def _deserialize(data, klass): return deserialize_date(data) elif klass == datetime.datetime: return deserialize_datetime(data) - elif type(klass) == typing.GenericMeta: - if klass.__extra__ == list: + elif typing_patch.is_generic(klass): + if typing_patch.is_list(klass): return _deserialize_list(data, klass.__args__[0]) - if klass.__extra__ == dict: + if typing_patch.is_dict(klass): return _deserialize_dict(data, klass.__args__[1]) else: return deserialize_model(data, klass) diff --git a/samples/server/petstore/python-flask-python2/.openapi-generator/VERSION b/samples/server/petstore/python-flask-python2/.openapi-generator/VERSION index afa636560641..0c89fc927e32 100644 --- a/samples/server/petstore/python-flask-python2/.openapi-generator/VERSION +++ b/samples/server/petstore/python-flask-python2/.openapi-generator/VERSION @@ -1 +1 @@ -4.0.0-SNAPSHOT \ No newline at end of file +4.0.0 \ No newline at end of file diff --git a/samples/server/petstore/python-flask-python2/openapi_server/openapi/openapi.yaml b/samples/server/petstore/python-flask-python2/openapi_server/openapi/openapi.yaml index ca14f8b7cf33..122782a9b938 100644 --- a/samples/server/petstore/python-flask-python2/openapi_server/openapi/openapi.yaml +++ b/samples/server/petstore/python-flask-python2/openapi_server/openapi/openapi.yaml @@ -1,6 +1,7 @@ openapi: 3.0.1 info: - description: This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + description: This is a sample server Petstore server. For this sample, you can use + the api key `special-key` to test the authorization filters. license: name: Apache-2.0 url: http://www.apache.org/licenses/LICENSE-2.0.html @@ -121,7 +122,8 @@ paths: /pet/findByTags: get: deprecated: true - description: Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + description: Multiple tags can be provided with comma separated strings. Use + tag1, tag2, tag3 for testing. operationId: find_pets_by_tags parameters: - description: Tags to filter by @@ -340,7 +342,8 @@ paths: x-openapi-router-controller: openapi_server.controllers.store_controller /store/order/{orderId}: delete: - description: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + description: For valid response try integer IDs with value < 1000. Anything + above 1000 or nonintegers will generate API errors operationId: delete_order parameters: - description: ID of the order that needs to be deleted @@ -361,7 +364,8 @@ paths: - store x-openapi-router-controller: openapi_server.controllers.store_controller get: - description: For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + description: For valid response try integer IDs with value <= 5 or > 10. Other + values will generated exceptions operationId: get_order_by_id parameters: - description: ID of pet that needs to be fetched diff --git a/samples/server/petstore/python-flask-python2/openapi_server/typing_patch.py b/samples/server/petstore/python-flask-python2/openapi_server/typing_patch.py new file mode 100644 index 000000000000..a56029f6b5bb --- /dev/null +++ b/samples/server/petstore/python-flask-python2/openapi_server/typing_patch.py @@ -0,0 +1,32 @@ +# coding: utf-8 + +import sys + +if sys.version_info < (3, 7): + import typing + + def is_generic(klass): + """ Determine whether klass is a generic class """ + return type(klass) == typing.GenericMeta + + def is_dict(klass): + """ Determine whether klass is a Dict """ + return klass.__extra__ == dict + + def is_list(klass): + """ Determine whether klass is a List """ + return klass.__extra__ == list + +else: + + def is_generic(klass): + """ Determine whether klass is a generic class """ + return hasattr(klass, '__origin__') + + def is_dict(klass): + """ Determine whether klass is a Dict """ + return klass.__origin__ == list + + def is_list(klass): + """ Determine whether klass is a List """ + return klass.__origin__ == list diff --git a/samples/server/petstore/python-flask-python2/openapi_server/util.py b/samples/server/petstore/python-flask-python2/openapi_server/util.py index c7340cd00059..d753b2a08088 100644 --- a/samples/server/petstore/python-flask-python2/openapi_server/util.py +++ b/samples/server/petstore/python-flask-python2/openapi_server/util.py @@ -2,6 +2,7 @@ import six import typing +from openapi_server import typing_patch def _deserialize(data, klass): @@ -23,10 +24,10 @@ def _deserialize(data, klass): return deserialize_date(data) elif klass == datetime.datetime: return deserialize_datetime(data) - elif type(klass) == typing.GenericMeta: - if klass.__extra__ == list: + elif typing_patch.is_generic(klass): + if typing_patch.is_list(klass): return _deserialize_list(data, klass.__args__[0]) - if klass.__extra__ == dict: + if typing_patch.is_dict(klass): return _deserialize_dict(data, klass.__args__[1]) else: return deserialize_model(data, klass) diff --git a/samples/server/petstore/python-flask/.openapi-generator/VERSION b/samples/server/petstore/python-flask/.openapi-generator/VERSION index afa636560641..0c89fc927e32 100644 --- a/samples/server/petstore/python-flask/.openapi-generator/VERSION +++ b/samples/server/petstore/python-flask/.openapi-generator/VERSION @@ -1 +1 @@ -4.0.0-SNAPSHOT \ No newline at end of file +4.0.0 \ No newline at end of file diff --git a/samples/server/petstore/python-flask/openapi_server/openapi/openapi.yaml b/samples/server/petstore/python-flask/openapi_server/openapi/openapi.yaml index ca14f8b7cf33..122782a9b938 100644 --- a/samples/server/petstore/python-flask/openapi_server/openapi/openapi.yaml +++ b/samples/server/petstore/python-flask/openapi_server/openapi/openapi.yaml @@ -1,6 +1,7 @@ openapi: 3.0.1 info: - description: This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + description: This is a sample server Petstore server. For this sample, you can use + the api key `special-key` to test the authorization filters. license: name: Apache-2.0 url: http://www.apache.org/licenses/LICENSE-2.0.html @@ -121,7 +122,8 @@ paths: /pet/findByTags: get: deprecated: true - description: Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + description: Multiple tags can be provided with comma separated strings. Use + tag1, tag2, tag3 for testing. operationId: find_pets_by_tags parameters: - description: Tags to filter by @@ -340,7 +342,8 @@ paths: x-openapi-router-controller: openapi_server.controllers.store_controller /store/order/{orderId}: delete: - description: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + description: For valid response try integer IDs with value < 1000. Anything + above 1000 or nonintegers will generate API errors operationId: delete_order parameters: - description: ID of the order that needs to be deleted @@ -361,7 +364,8 @@ paths: - store x-openapi-router-controller: openapi_server.controllers.store_controller get: - description: For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + description: For valid response try integer IDs with value <= 5 or > 10. Other + values will generated exceptions operationId: get_order_by_id parameters: - description: ID of pet that needs to be fetched diff --git a/samples/server/petstore/python-flask/openapi_server/typing_patch.py b/samples/server/petstore/python-flask/openapi_server/typing_patch.py new file mode 100644 index 000000000000..a56029f6b5bb --- /dev/null +++ b/samples/server/petstore/python-flask/openapi_server/typing_patch.py @@ -0,0 +1,32 @@ +# coding: utf-8 + +import sys + +if sys.version_info < (3, 7): + import typing + + def is_generic(klass): + """ Determine whether klass is a generic class """ + return type(klass) == typing.GenericMeta + + def is_dict(klass): + """ Determine whether klass is a Dict """ + return klass.__extra__ == dict + + def is_list(klass): + """ Determine whether klass is a List """ + return klass.__extra__ == list + +else: + + def is_generic(klass): + """ Determine whether klass is a generic class """ + return hasattr(klass, '__origin__') + + def is_dict(klass): + """ Determine whether klass is a Dict """ + return klass.__origin__ == list + + def is_list(klass): + """ Determine whether klass is a List """ + return klass.__origin__ == list diff --git a/samples/server/petstore/python-flask/openapi_server/util.py b/samples/server/petstore/python-flask/openapi_server/util.py index c7340cd00059..d753b2a08088 100644 --- a/samples/server/petstore/python-flask/openapi_server/util.py +++ b/samples/server/petstore/python-flask/openapi_server/util.py @@ -2,6 +2,7 @@ import six import typing +from openapi_server import typing_patch def _deserialize(data, klass): @@ -23,10 +24,10 @@ def _deserialize(data, klass): return deserialize_date(data) elif klass == datetime.datetime: return deserialize_datetime(data) - elif type(klass) == typing.GenericMeta: - if klass.__extra__ == list: + elif typing_patch.is_generic(klass): + if typing_patch.is_list(klass): return _deserialize_list(data, klass.__args__[0]) - if klass.__extra__ == dict: + if typing_patch.is_dict(klass): return _deserialize_dict(data, klass.__args__[1]) else: return deserialize_model(data, klass) From cbc405869b2d142b8e7cc52e7858b02720c10315 Mon Sep 17 00:00:00 2001 From: Guillaume Smaha Date: Mon, 20 May 2019 09:12:20 -0400 Subject: [PATCH 2/4] Rename typing_patch.py to typing_utils.py --- .../languages/PythonAbstractConnexionServerCodegen.java | 2 +- .../codegen/languages/PythonBluePlanetServerCodegen.java | 4 ++-- .../src/main/resources/python-aiohttp/util.mustache | 8 ++++---- .../python-blueplanet/app/{{packageName}}/util.mustache | 8 ++++---- .../src/main/resources/python-flask/util.mustache | 8 ++++---- .../openapi_server/{typing_patch.py => typing_utils.py} | 0 .../petstore/python-flask-python2/openapi_server/util.py | 8 ++++---- .../openapi_server/{typing_patch.py => typing_utils.py} | 0 .../openapi3/petstore/python-flask/openapi_server/util.py | 8 ++++---- .../openapi_server/{typing_patch.py => typing_utils.py} | 0 .../server/petstore/python-aiohttp/openapi_server/util.py | 8 ++++---- .../openapi_server/{typing_patch.py => typing_utils.py} | 0 .../petstore/python-blueplanet/app/openapi_server/util.py | 8 ++++---- .../openapi_server/{typing_patch.py => typing_utils.py} | 0 .../petstore/python-flask-python2/openapi_server/util.py | 8 ++++---- .../openapi_server/{typing_patch.py => typing_utils.py} | 0 .../server/petstore/python-flask/openapi_server/util.py | 8 ++++---- 17 files changed, 39 insertions(+), 39 deletions(-) rename samples/server/openapi3/petstore/python-flask-python2/openapi_server/{typing_patch.py => typing_utils.py} (100%) rename samples/server/openapi3/petstore/python-flask/openapi_server/{typing_patch.py => typing_utils.py} (100%) rename samples/server/petstore/python-aiohttp/openapi_server/{typing_patch.py => typing_utils.py} (100%) rename samples/server/petstore/python-blueplanet/app/openapi_server/{typing_patch.py => typing_utils.py} (100%) rename samples/server/petstore/python-flask-python2/openapi_server/{typing_patch.py => typing_utils.py} (100%) rename samples/server/petstore/python-flask/openapi_server/{typing_patch.py => typing_utils.py} (100%) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonAbstractConnexionServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonAbstractConnexionServerCodegen.java index 2ec3c1c8240d..dae89d0ae873 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonAbstractConnexionServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonAbstractConnexionServerCodegen.java @@ -201,7 +201,7 @@ public void processOpts() { } supportingFiles.add(new SupportingFile("__main__.mustache", packagePath(), "__main__.py")); supportingFiles.add(new SupportingFile("util.mustache", packagePath(), "util.py")); - supportingFiles.add(new SupportingFile("typing_patch.mustache", packagePath(), "typing_patch.py")); + supportingFiles.add(new SupportingFile("typing_utils.mustache", packagePath(), "typing_utils.py")); supportingFiles.add(new SupportingFile("__init__.mustache", packagePath() + File.separatorChar + packageToPath(controllerPackage), "__init__.py")); supportingFiles.add(new SupportingFile("security_controller_.mustache", packagePath() + File.separatorChar + packageToPath(controllerPackage), "security_controller_.py")); supportingFiles.add(new SupportingFile("__init__model.mustache", packagePath() + File.separatorChar + packageToPath(modelPackage), "__init__.py")); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonBluePlanetServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonBluePlanetServerCodegen.java index 259e7a046980..f45a2f6510d4 100755 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonBluePlanetServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonBluePlanetServerCodegen.java @@ -118,7 +118,7 @@ public void processOpts() { supportingFiles.add(new SupportingFile("app/{{packageName}}/__main__.mustache", APP_PACKAGE_PATH, "__main__.py")); supportingFiles.add(new SupportingFile("app/{{packageName}}/encoder.mustache", APP_PACKAGE_PATH, "encoder.py")); supportingFiles.add(new SupportingFile("app/{{packageName}}/util.mustache", APP_PACKAGE_PATH, "util.py")); - supportingFiles.add(new SupportingFile("app/{{packageName}}/typing_patch.mustache", APP_PACKAGE_PATH, "typing_patch.py")); + supportingFiles.add(new SupportingFile("app/{{packageName}}/typing_utils.mustache", APP_PACKAGE_PATH, "typing_utils.py")); supportingFiles.add(new SupportingFile("app/{{packageName}}/controllers/__init__.mustache", CONTROLLER_PATH, "__init__.py")); @@ -193,7 +193,7 @@ protected void addSupportingFiles() { supportingFiles.add(new SupportingFile("app/{{packageName}}/__main__.mustache", APP_PACKAGE_PATH, "__main__.py")); supportingFiles.add(new SupportingFile("app/{{packageName}}/encoder.mustache", APP_PACKAGE_PATH, "encoder.py")); supportingFiles.add(new SupportingFile("app/{{packageName}}/util.mustache", APP_PACKAGE_PATH, "util.py")); - supportingFiles.add(new SupportingFile("app/{{packageName}}/typing_patch.mustache", APP_PACKAGE_PATH, "typing_patch.py")); + supportingFiles.add(new SupportingFile("app/{{packageName}}/typing_utils.mustache", APP_PACKAGE_PATH, "typing_utils.py")); supportingFiles.add(new SupportingFile("app/{{packageName}}/controllers/__init__.mustache", CONTROLLER_PATH, "__init__.py")); diff --git a/modules/openapi-generator/src/main/resources/python-aiohttp/util.mustache b/modules/openapi-generator/src/main/resources/python-aiohttp/util.mustache index dbe64d400d62..1b1eadc7ee2a 100644 --- a/modules/openapi-generator/src/main/resources/python-aiohttp/util.mustache +++ b/modules/openapi-generator/src/main/resources/python-aiohttp/util.mustache @@ -2,7 +2,7 @@ import datetime import typing from typing import Union -from {{packageName}} import typing_patch +from {{packageName}} import typing_utils T = typing.TypeVar('T') Class = typing.Type[T] @@ -27,10 +27,10 @@ def _deserialize(data: Union[dict, list, str], klass: Union[Class, str]) -> Unio return deserialize_date(data) elif klass == datetime.datetime: return deserialize_datetime(data) - elif typing_patch.is_generic(klass): - if typing_patch.is_list(klass): + elif typing_utils.is_generic(klass): + if typing_utils.is_list(klass): return _deserialize_list(data, klass.__args__[0]) - if typing_patch.is_dict(klass): + if typing_utils.is_dict(klass): return _deserialize_dict(data, klass.__args__[1]) else: return deserialize_model(data, klass) diff --git a/modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/util.mustache b/modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/util.mustache index a15169e1b0b3..9763c8fc8500 100644 --- a/modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/util.mustache +++ b/modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/util.mustache @@ -2,7 +2,7 @@ import datetime import six import typing -from {{packageName}} import typing_patch +from {{packageName}} import typing_utils def _deserialize(data, klass): @@ -24,10 +24,10 @@ def _deserialize(data, klass): return deserialize_date(data) elif klass == datetime.datetime: return deserialize_datetime(data) - elif typing_patch.is_generic(klass): - if typing_patch.is_list(klass): + elif typing_utils.is_generic(klass): + if typing_utils.is_list(klass): return _deserialize_list(data, klass.__args__[0]) - if typing_patch.is_dict(klass): + if typing_utils.is_dict(klass): return _deserialize_dict(data, klass.__args__[1]) else: return deserialize_model(data, klass) diff --git a/modules/openapi-generator/src/main/resources/python-flask/util.mustache b/modules/openapi-generator/src/main/resources/python-flask/util.mustache index 17e7af17aec4..30ba3247eee8 100644 --- a/modules/openapi-generator/src/main/resources/python-flask/util.mustache +++ b/modules/openapi-generator/src/main/resources/python-flask/util.mustache @@ -2,7 +2,7 @@ import datetime import six import typing -from {{packageName}} import typing_patch +from {{packageName}} import typing_utils def _deserialize(data, klass): @@ -24,10 +24,10 @@ def _deserialize(data, klass): return deserialize_date(data) elif klass == datetime.datetime: return deserialize_datetime(data) - elif typing_patch.is_generic(klass): - if typing_patch.is_list(klass): + elif typing_utils.is_generic(klass): + if typing_utils.is_list(klass): return _deserialize_list(data, klass.__args__[0]) - if typing_patch.is_dict(klass): + if typing_utils.is_dict(klass): return _deserialize_dict(data, klass.__args__[1]) else: return deserialize_model(data, klass) diff --git a/samples/server/openapi3/petstore/python-flask-python2/openapi_server/typing_patch.py b/samples/server/openapi3/petstore/python-flask-python2/openapi_server/typing_utils.py similarity index 100% rename from samples/server/openapi3/petstore/python-flask-python2/openapi_server/typing_patch.py rename to samples/server/openapi3/petstore/python-flask-python2/openapi_server/typing_utils.py diff --git a/samples/server/openapi3/petstore/python-flask-python2/openapi_server/util.py b/samples/server/openapi3/petstore/python-flask-python2/openapi_server/util.py index d753b2a08088..4b0188652ba7 100644 --- a/samples/server/openapi3/petstore/python-flask-python2/openapi_server/util.py +++ b/samples/server/openapi3/petstore/python-flask-python2/openapi_server/util.py @@ -2,7 +2,7 @@ import six import typing -from openapi_server import typing_patch +from openapi_server import typing_utils def _deserialize(data, klass): @@ -24,10 +24,10 @@ def _deserialize(data, klass): return deserialize_date(data) elif klass == datetime.datetime: return deserialize_datetime(data) - elif typing_patch.is_generic(klass): - if typing_patch.is_list(klass): + elif typing_utils.is_generic(klass): + if typing_utils.is_list(klass): return _deserialize_list(data, klass.__args__[0]) - if typing_patch.is_dict(klass): + if typing_utils.is_dict(klass): return _deserialize_dict(data, klass.__args__[1]) else: return deserialize_model(data, klass) diff --git a/samples/server/openapi3/petstore/python-flask/openapi_server/typing_patch.py b/samples/server/openapi3/petstore/python-flask/openapi_server/typing_utils.py similarity index 100% rename from samples/server/openapi3/petstore/python-flask/openapi_server/typing_patch.py rename to samples/server/openapi3/petstore/python-flask/openapi_server/typing_utils.py diff --git a/samples/server/openapi3/petstore/python-flask/openapi_server/util.py b/samples/server/openapi3/petstore/python-flask/openapi_server/util.py index d753b2a08088..4b0188652ba7 100644 --- a/samples/server/openapi3/petstore/python-flask/openapi_server/util.py +++ b/samples/server/openapi3/petstore/python-flask/openapi_server/util.py @@ -2,7 +2,7 @@ import six import typing -from openapi_server import typing_patch +from openapi_server import typing_utils def _deserialize(data, klass): @@ -24,10 +24,10 @@ def _deserialize(data, klass): return deserialize_date(data) elif klass == datetime.datetime: return deserialize_datetime(data) - elif typing_patch.is_generic(klass): - if typing_patch.is_list(klass): + elif typing_utils.is_generic(klass): + if typing_utils.is_list(klass): return _deserialize_list(data, klass.__args__[0]) - if typing_patch.is_dict(klass): + if typing_utils.is_dict(klass): return _deserialize_dict(data, klass.__args__[1]) else: return deserialize_model(data, klass) diff --git a/samples/server/petstore/python-aiohttp/openapi_server/typing_patch.py b/samples/server/petstore/python-aiohttp/openapi_server/typing_utils.py similarity index 100% rename from samples/server/petstore/python-aiohttp/openapi_server/typing_patch.py rename to samples/server/petstore/python-aiohttp/openapi_server/typing_utils.py diff --git a/samples/server/petstore/python-aiohttp/openapi_server/util.py b/samples/server/petstore/python-aiohttp/openapi_server/util.py index a290ec377a71..c446943677ea 100644 --- a/samples/server/petstore/python-aiohttp/openapi_server/util.py +++ b/samples/server/petstore/python-aiohttp/openapi_server/util.py @@ -2,7 +2,7 @@ import typing from typing import Union -from openapi_server import typing_patch +from openapi_server import typing_utils T = typing.TypeVar('T') Class = typing.Type[T] @@ -27,10 +27,10 @@ def _deserialize(data: Union[dict, list, str], klass: Union[Class, str]) -> Unio return deserialize_date(data) elif klass == datetime.datetime: return deserialize_datetime(data) - elif typing_patch.is_generic(klass): - if typing_patch.is_list(klass): + elif typing_utils.is_generic(klass): + if typing_utils.is_list(klass): return _deserialize_list(data, klass.__args__[0]) - if typing_patch.is_dict(klass): + if typing_utils.is_dict(klass): return _deserialize_dict(data, klass.__args__[1]) else: return deserialize_model(data, klass) diff --git a/samples/server/petstore/python-blueplanet/app/openapi_server/typing_patch.py b/samples/server/petstore/python-blueplanet/app/openapi_server/typing_utils.py similarity index 100% rename from samples/server/petstore/python-blueplanet/app/openapi_server/typing_patch.py rename to samples/server/petstore/python-blueplanet/app/openapi_server/typing_utils.py diff --git a/samples/server/petstore/python-blueplanet/app/openapi_server/util.py b/samples/server/petstore/python-blueplanet/app/openapi_server/util.py index 72499ff45050..fc9f8b16f0b3 100644 --- a/samples/server/petstore/python-blueplanet/app/openapi_server/util.py +++ b/samples/server/petstore/python-blueplanet/app/openapi_server/util.py @@ -2,7 +2,7 @@ import six import typing -from openapi_server import typing_patch +from openapi_server import typing_utils def _deserialize(data, klass): @@ -24,10 +24,10 @@ def _deserialize(data, klass): return deserialize_date(data) elif klass == datetime.datetime: return deserialize_datetime(data) - elif typing_patch.is_generic(klass): - if typing_patch.is_list(klass): + elif typing_utils.is_generic(klass): + if typing_utils.is_list(klass): return _deserialize_list(data, klass.__args__[0]) - if typing_patch.is_dict(klass): + if typing_utils.is_dict(klass): return _deserialize_dict(data, klass.__args__[1]) else: return deserialize_model(data, klass) diff --git a/samples/server/petstore/python-flask-python2/openapi_server/typing_patch.py b/samples/server/petstore/python-flask-python2/openapi_server/typing_utils.py similarity index 100% rename from samples/server/petstore/python-flask-python2/openapi_server/typing_patch.py rename to samples/server/petstore/python-flask-python2/openapi_server/typing_utils.py diff --git a/samples/server/petstore/python-flask-python2/openapi_server/util.py b/samples/server/petstore/python-flask-python2/openapi_server/util.py index d753b2a08088..4b0188652ba7 100644 --- a/samples/server/petstore/python-flask-python2/openapi_server/util.py +++ b/samples/server/petstore/python-flask-python2/openapi_server/util.py @@ -2,7 +2,7 @@ import six import typing -from openapi_server import typing_patch +from openapi_server import typing_utils def _deserialize(data, klass): @@ -24,10 +24,10 @@ def _deserialize(data, klass): return deserialize_date(data) elif klass == datetime.datetime: return deserialize_datetime(data) - elif typing_patch.is_generic(klass): - if typing_patch.is_list(klass): + elif typing_utils.is_generic(klass): + if typing_utils.is_list(klass): return _deserialize_list(data, klass.__args__[0]) - if typing_patch.is_dict(klass): + if typing_utils.is_dict(klass): return _deserialize_dict(data, klass.__args__[1]) else: return deserialize_model(data, klass) diff --git a/samples/server/petstore/python-flask/openapi_server/typing_patch.py b/samples/server/petstore/python-flask/openapi_server/typing_utils.py similarity index 100% rename from samples/server/petstore/python-flask/openapi_server/typing_patch.py rename to samples/server/petstore/python-flask/openapi_server/typing_utils.py diff --git a/samples/server/petstore/python-flask/openapi_server/util.py b/samples/server/petstore/python-flask/openapi_server/util.py index d753b2a08088..4b0188652ba7 100644 --- a/samples/server/petstore/python-flask/openapi_server/util.py +++ b/samples/server/petstore/python-flask/openapi_server/util.py @@ -2,7 +2,7 @@ import six import typing -from openapi_server import typing_patch +from openapi_server import typing_utils def _deserialize(data, klass): @@ -24,10 +24,10 @@ def _deserialize(data, klass): return deserialize_date(data) elif klass == datetime.datetime: return deserialize_datetime(data) - elif typing_patch.is_generic(klass): - if typing_patch.is_list(klass): + elif typing_utils.is_generic(klass): + if typing_utils.is_list(klass): return _deserialize_list(data, klass.__args__[0]) - if typing_patch.is_dict(klass): + if typing_utils.is_dict(klass): return _deserialize_dict(data, klass.__args__[1]) else: return deserialize_model(data, klass) From 82dcb4ef215e2d4a4ff4cb755e4191881af71e44 Mon Sep 17 00:00:00 2001 From: Guillaume Smaha Date: Mon, 20 May 2019 11:24:45 -0400 Subject: [PATCH 3/4] Renaming typing_patch.mustache to typing_utils.mustache --- .../{typing_patch.mustache => typing_utils.mustache} | 0 .../{typing_patch.mustache => typing_utils.mustache} | 0 .../python-flask/{typing_patch.mustache => typing_utils.mustache} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename modules/openapi-generator/src/main/resources/python-aiohttp/{typing_patch.mustache => typing_utils.mustache} (100%) rename modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/{typing_patch.mustache => typing_utils.mustache} (100%) rename modules/openapi-generator/src/main/resources/python-flask/{typing_patch.mustache => typing_utils.mustache} (100%) diff --git a/modules/openapi-generator/src/main/resources/python-aiohttp/typing_patch.mustache b/modules/openapi-generator/src/main/resources/python-aiohttp/typing_utils.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/python-aiohttp/typing_patch.mustache rename to modules/openapi-generator/src/main/resources/python-aiohttp/typing_utils.mustache diff --git a/modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/typing_patch.mustache b/modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/typing_utils.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/typing_patch.mustache rename to modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/typing_utils.mustache diff --git a/modules/openapi-generator/src/main/resources/python-flask/typing_patch.mustache b/modules/openapi-generator/src/main/resources/python-flask/typing_utils.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/python-flask/typing_patch.mustache rename to modules/openapi-generator/src/main/resources/python-flask/typing_utils.mustache From b232d613ed8cd3cc307884f5c754586965f35dcd Mon Sep 17 00:00:00 2001 From: Guillaume Smaha Date: Tue, 21 May 2019 10:47:49 -0400 Subject: [PATCH 4/4] Fix comparaison in typing_utils.is_dict for python3.7 --- .../src/main/resources/python-aiohttp/typing_utils.mustache | 2 +- .../python-blueplanet/app/{{packageName}}/typing_utils.mustache | 2 +- .../src/main/resources/python-flask/typing_utils.mustache | 2 +- .../python-flask-python2/openapi_server/typing_utils.py | 2 +- .../petstore/python-flask/openapi_server/typing_utils.py | 2 +- .../petstore/python-aiohttp/openapi_server/typing_utils.py | 2 +- .../python-blueplanet/app/openapi_server/typing_utils.py | 2 +- .../python-flask-python2/openapi_server/typing_utils.py | 2 +- .../server/petstore/python-flask/openapi_server/typing_utils.py | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python-aiohttp/typing_utils.mustache b/modules/openapi-generator/src/main/resources/python-aiohttp/typing_utils.mustache index a56029f6b5bb..0563f81fd534 100644 --- a/modules/openapi-generator/src/main/resources/python-aiohttp/typing_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python-aiohttp/typing_utils.mustache @@ -25,7 +25,7 @@ else: def is_dict(klass): """ Determine whether klass is a Dict """ - return klass.__origin__ == list + return klass.__origin__ == dict def is_list(klass): """ Determine whether klass is a List """ diff --git a/modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/typing_utils.mustache b/modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/typing_utils.mustache index a56029f6b5bb..0563f81fd534 100644 --- a/modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/typing_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python-blueplanet/app/{{packageName}}/typing_utils.mustache @@ -25,7 +25,7 @@ else: def is_dict(klass): """ Determine whether klass is a Dict """ - return klass.__origin__ == list + return klass.__origin__ == dict def is_list(klass): """ Determine whether klass is a List """ diff --git a/modules/openapi-generator/src/main/resources/python-flask/typing_utils.mustache b/modules/openapi-generator/src/main/resources/python-flask/typing_utils.mustache index a56029f6b5bb..0563f81fd534 100644 --- a/modules/openapi-generator/src/main/resources/python-flask/typing_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python-flask/typing_utils.mustache @@ -25,7 +25,7 @@ else: def is_dict(klass): """ Determine whether klass is a Dict """ - return klass.__origin__ == list + return klass.__origin__ == dict def is_list(klass): """ Determine whether klass is a List """ diff --git a/samples/server/openapi3/petstore/python-flask-python2/openapi_server/typing_utils.py b/samples/server/openapi3/petstore/python-flask-python2/openapi_server/typing_utils.py index a56029f6b5bb..0563f81fd534 100644 --- a/samples/server/openapi3/petstore/python-flask-python2/openapi_server/typing_utils.py +++ b/samples/server/openapi3/petstore/python-flask-python2/openapi_server/typing_utils.py @@ -25,7 +25,7 @@ def is_generic(klass): def is_dict(klass): """ Determine whether klass is a Dict """ - return klass.__origin__ == list + return klass.__origin__ == dict def is_list(klass): """ Determine whether klass is a List """ diff --git a/samples/server/openapi3/petstore/python-flask/openapi_server/typing_utils.py b/samples/server/openapi3/petstore/python-flask/openapi_server/typing_utils.py index a56029f6b5bb..0563f81fd534 100644 --- a/samples/server/openapi3/petstore/python-flask/openapi_server/typing_utils.py +++ b/samples/server/openapi3/petstore/python-flask/openapi_server/typing_utils.py @@ -25,7 +25,7 @@ def is_generic(klass): def is_dict(klass): """ Determine whether klass is a Dict """ - return klass.__origin__ == list + return klass.__origin__ == dict def is_list(klass): """ Determine whether klass is a List """ diff --git a/samples/server/petstore/python-aiohttp/openapi_server/typing_utils.py b/samples/server/petstore/python-aiohttp/openapi_server/typing_utils.py index a56029f6b5bb..0563f81fd534 100644 --- a/samples/server/petstore/python-aiohttp/openapi_server/typing_utils.py +++ b/samples/server/petstore/python-aiohttp/openapi_server/typing_utils.py @@ -25,7 +25,7 @@ def is_generic(klass): def is_dict(klass): """ Determine whether klass is a Dict """ - return klass.__origin__ == list + return klass.__origin__ == dict def is_list(klass): """ Determine whether klass is a List """ diff --git a/samples/server/petstore/python-blueplanet/app/openapi_server/typing_utils.py b/samples/server/petstore/python-blueplanet/app/openapi_server/typing_utils.py index a56029f6b5bb..0563f81fd534 100644 --- a/samples/server/petstore/python-blueplanet/app/openapi_server/typing_utils.py +++ b/samples/server/petstore/python-blueplanet/app/openapi_server/typing_utils.py @@ -25,7 +25,7 @@ def is_generic(klass): def is_dict(klass): """ Determine whether klass is a Dict """ - return klass.__origin__ == list + return klass.__origin__ == dict def is_list(klass): """ Determine whether klass is a List """ diff --git a/samples/server/petstore/python-flask-python2/openapi_server/typing_utils.py b/samples/server/petstore/python-flask-python2/openapi_server/typing_utils.py index a56029f6b5bb..0563f81fd534 100644 --- a/samples/server/petstore/python-flask-python2/openapi_server/typing_utils.py +++ b/samples/server/petstore/python-flask-python2/openapi_server/typing_utils.py @@ -25,7 +25,7 @@ def is_generic(klass): def is_dict(klass): """ Determine whether klass is a Dict """ - return klass.__origin__ == list + return klass.__origin__ == dict def is_list(klass): """ Determine whether klass is a List """ diff --git a/samples/server/petstore/python-flask/openapi_server/typing_utils.py b/samples/server/petstore/python-flask/openapi_server/typing_utils.py index a56029f6b5bb..0563f81fd534 100644 --- a/samples/server/petstore/python-flask/openapi_server/typing_utils.py +++ b/samples/server/petstore/python-flask/openapi_server/typing_utils.py @@ -25,7 +25,7 @@ def is_generic(klass): def is_dict(klass): """ Determine whether klass is a Dict """ - return klass.__origin__ == list + return klass.__origin__ == dict def is_list(klass): """ Determine whether klass is a List """