From 6c350a7d2d097d6c98558e60149d8763b8823868 Mon Sep 17 00:00:00 2001 From: Maneesh Sahu-SSI Date: Wed, 15 Jun 2016 13:43:36 -0700 Subject: [PATCH 1/2] Added long to primitive data types supported in Python codegen --- .../src/main/resources/python/api_client.mustache | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/python/api_client.mustache b/modules/swagger-codegen/src/main/resources/python/api_client.mustache index 2a4732f5af..81f670dee1 100644 --- a/modules/swagger-codegen/src/main/resources/python/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/python/api_client.mustache @@ -180,7 +180,7 @@ class ApiClient(object): Builds a JSON POST object. If obj is None, return None. - If obj is str, int, float, bool, return directly. + If obj is str, int, long, float, bool, return directly. If obj is datetime.datetime, datetime.date convert to string in iso8601 format. If obj is list, sanitize each element in the list. @@ -190,7 +190,7 @@ class ApiClient(object): :param obj: The data to serialize. :return: The serialized form of data. """ - types = (str, int, float, bool, tuple) + types = (str, int, long, float, bool, tuple) if sys.version_info < (3, 0): types = types + (unicode,) if isinstance(obj, type(None)): @@ -266,14 +266,14 @@ class ApiClient(object): # convert str to class # for native types - if klass in ['int', 'float', 'str', 'bool', + if klass in ['int', 'long', 'float', 'str', 'bool', "date", 'datetime', "object"]: klass = eval(klass) # for model types else: klass = eval('models.' + klass) - if klass in [int, float, str, bool]: + if klass in [int, long, float, str, bool]: return self.__deserialize_primitive(data, klass) elif klass == object: return self.__deserialize_object(data) @@ -501,7 +501,7 @@ class ApiClient(object): :param data: str. :param klass: class literal. - :return: int, float, str, bool. + :return: int, long, float, str, bool. """ try: value = klass(data) From 89befeb45b86905937e91a20880b1c36537db26e Mon Sep 17 00:00:00 2001 From: wing328 Date: Thu, 7 Jul 2016 22:17:27 +0800 Subject: [PATCH 2/2] fix long issue in python3 --- .../main/resources/python/api_client.mustache | 8 ++++++++ samples/client/petstore/python/README.md | 2 +- .../petstore/python/petstore_api/api_client.py | 18 +++++++++++++----- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/python/api_client.mustache b/modules/swagger-codegen/src/main/resources/python/api_client.mustache index a43766d603..e75c6be52e 100644 --- a/modules/swagger-codegen/src/main/resources/python/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/python/api_client.mustache @@ -46,6 +46,14 @@ except ImportError: # for python2 from urllib import quote +# special handling of `long` (python2 only) +try: + # Python 2 + long +except NameError: + # Python 3 + long = int + from .configuration import Configuration diff --git a/samples/client/petstore/python/README.md b/samples/client/petstore/python/README.md index 6c34951d30..a8bcf2f5f8 100644 --- a/samples/client/petstore/python/README.md +++ b/samples/client/petstore/python/README.md @@ -5,7 +5,7 @@ This Python package is automatically generated by the [Swagger Codegen](https:// - API version: 1.0.0 - Package version: 1.0.0 -- Build date: 2016-07-06T16:27:27.842+08:00 +- Build date: 2016-07-07T22:03:52.761+08:00 - Build package: class io.swagger.codegen.languages.PythonClientCodegen ## Requirements. diff --git a/samples/client/petstore/python/petstore_api/api_client.py b/samples/client/petstore/python/petstore_api/api_client.py index 2521ba15fd..ddfaf2ca74 100644 --- a/samples/client/petstore/python/petstore_api/api_client.py +++ b/samples/client/petstore/python/petstore_api/api_client.py @@ -46,6 +46,14 @@ except ImportError: # for python2 from urllib import quote +# special handling of `long` (python2 only) +try: + # Python 2 + long +except NameError: + # Python 3 + long = int + from .configuration import Configuration @@ -183,7 +191,7 @@ class ApiClient(object): Builds a JSON POST object. If obj is None, return None. - If obj is str, int, float, bool, return directly. + If obj is str, int, long, float, bool, return directly. If obj is datetime.datetime, datetime.date convert to string in iso8601 format. If obj is list, sanitize each element in the list. @@ -193,7 +201,7 @@ class ApiClient(object): :param obj: The data to serialize. :return: The serialized form of data. """ - types = (str, int, float, bool, tuple) + types = (str, int, long, float, bool, tuple) if sys.version_info < (3, 0): types = types + (unicode,) if isinstance(obj, type(None)): @@ -269,14 +277,14 @@ class ApiClient(object): # convert str to class # for native types - if klass in ['int', 'float', 'str', 'bool', + if klass in ['int', 'long', 'float', 'str', 'bool', "date", 'datetime', "object"]: klass = eval(klass) # for model types else: klass = eval('models.' + klass) - if klass in [int, float, str, bool]: + if klass in [int, long, float, str, bool]: return self.__deserialize_primitive(data, klass) elif klass == object: return self.__deserialize_object(data) @@ -505,7 +513,7 @@ class ApiClient(object): :param data: str. :param klass: class literal. - :return: int, float, str, bool. + :return: int, long, float, str, bool. """ try: value = klass(data)