mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-11 12:42:44 +00:00
[python-server] Support python 3.7 for all server-generators (#2884)
* Support python 3.7 for all server-generators Signed-off-by: Guillaume Smaha <guillaume.smaha@gmail.com> * Rename typing_patch.py to typing_utils.py * Renaming typing_patch.mustache to typing_utils.mustache * Fix comparaison in typing_utils.is_dict for python3.7
This commit is contained in:
committed by
William Cheng
parent
14118807ba
commit
20b8eff6e3
@@ -202,6 +202,7 @@ public class PythonAbstractConnexionServerCodegen extends DefaultCodegen impleme
|
||||
}
|
||||
supportingFiles.add(new SupportingFile("__main__.mustache", packagePath(), "__main__.py"));
|
||||
supportingFiles.add(new SupportingFile("util.mustache", packagePath(), "util.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"));
|
||||
|
||||
@@ -118,6 +118,7 @@ public class PythonBluePlanetServerCodegen extends PythonAbstractConnexionServer
|
||||
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_utils.mustache", APP_PACKAGE_PATH, "typing_utils.py"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("app/{{packageName}}/controllers/__init__.mustache", CONTROLLER_PATH, "__init__.py"));
|
||||
|
||||
@@ -192,6 +193,7 @@ public class PythonBluePlanetServerCodegen extends PythonAbstractConnexionServer
|
||||
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_utils.mustache", APP_PACKAGE_PATH, "typing_utils.py"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("app/{{packageName}}/controllers/__init__.mustache", CONTROLLER_PATH, "__init__.py"));
|
||||
|
||||
|
||||
32
modules/openapi-generator/src/main/resources/python-aiohttp/typing_utils.mustache
vendored
Normal file
32
modules/openapi-generator/src/main/resources/python-aiohttp/typing_utils.mustache
vendored
Normal file
@@ -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__ == dict
|
||||
|
||||
def is_list(klass):
|
||||
""" Determine whether klass is a List """
|
||||
return klass.__origin__ == list
|
||||
@@ -2,6 +2,7 @@ import datetime
|
||||
|
||||
import typing
|
||||
from typing import Union
|
||||
from {{packageName}} import typing_utils
|
||||
|
||||
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_utils.is_generic(klass):
|
||||
if typing_utils.is_list(klass):
|
||||
return _deserialize_list(data, klass.__args__[0])
|
||||
if klass.__extra__ == dict:
|
||||
if typing_utils.is_dict(klass):
|
||||
return _deserialize_dict(data, klass.__args__[1])
|
||||
else:
|
||||
return deserialize_model(data, klass)
|
||||
|
||||
@@ -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__ == dict
|
||||
|
||||
def is_list(klass):
|
||||
""" Determine whether klass is a List """
|
||||
return klass.__origin__ == list
|
||||
@@ -2,6 +2,7 @@ import datetime
|
||||
|
||||
import six
|
||||
import typing
|
||||
from {{packageName}} import typing_utils
|
||||
|
||||
|
||||
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_utils.is_generic(klass):
|
||||
if typing_utils.is_list(klass):
|
||||
return _deserialize_list(data, klass.__args__[0])
|
||||
if klass.__extra__ == dict:
|
||||
if typing_utils.is_dict(klass):
|
||||
return _deserialize_dict(data, klass.__args__[1])
|
||||
else:
|
||||
return deserialize_model(data, klass)
|
||||
|
||||
32
modules/openapi-generator/src/main/resources/python-flask/typing_utils.mustache
vendored
Normal file
32
modules/openapi-generator/src/main/resources/python-flask/typing_utils.mustache
vendored
Normal file
@@ -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__ == dict
|
||||
|
||||
def is_list(klass):
|
||||
""" Determine whether klass is a List """
|
||||
return klass.__origin__ == list
|
||||
@@ -2,6 +2,7 @@ import datetime
|
||||
|
||||
import six
|
||||
import typing
|
||||
from {{packageName}} import typing_utils
|
||||
|
||||
|
||||
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_utils.is_generic(klass):
|
||||
if typing_utils.is_list(klass):
|
||||
return _deserialize_list(data, klass.__args__[0])
|
||||
if klass.__extra__ == dict:
|
||||
if typing_utils.is_dict(klass):
|
||||
return _deserialize_dict(data, klass.__args__[1])
|
||||
else:
|
||||
return deserialize_model(data, klass)
|
||||
|
||||
Reference in New Issue
Block a user