From bd63c1d9d96a7cc99ea75a167bb297aa5d1f0488 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Tue, 15 Sep 2015 16:40:23 +0800 Subject: [PATCH] Support OPTIONS http verb in python client. --- .../main/resources/python/api_client.mustache | 4 +++ .../src/main/resources/python/rest.mustache | 28 +++++-------------- .../python/swagger_client/__init__.py | 2 +- .../python/swagger_client/api_client.py | 12 +++++--- .../python/swagger_client/apis/__init__.py | 2 +- .../python/swagger_client/apis/pet_api.py | 2 +- .../petstore/python/swagger_client/rest.py | 28 +++++-------------- 7 files changed, 29 insertions(+), 49 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 84a1dca45f..5ec6ddbccc 100644 --- a/modules/swagger-codegen/src/main/resources/python/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/python/api_client.mustache @@ -338,6 +338,10 @@ class ApiClient(object): return self.rest_client.HEAD(url, query_params=query_params, headers=headers) + elif method == "OPTIONS": + return self.rest_client.OPTIONS(url, + query_params=query_params, + headers=headers) elif method == "POST": return self.rest_client.POST(url, query_params=query_params, diff --git a/modules/swagger-codegen/src/main/resources/python/rest.mustache b/modules/swagger-codegen/src/main/resources/python/rest.mustache index 1481cbff3d..6279daedec 100644 --- a/modules/swagger-codegen/src/main/resources/python/rest.mustache +++ b/modules/swagger-codegen/src/main/resources/python/rest.mustache @@ -103,7 +103,7 @@ class RESTClientObject(object): and `multipart/form-data` """ method = method.upper() - assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH'] + assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH', 'OPTIONS'] if post_params and body: raise ValueError( @@ -138,7 +138,7 @@ class RESTClientObject(object): fields=post_params, encode_multipart=True, headers=headers) - # For `GET`, `HEAD`, `DELETE` + # For `GET`, `HEAD`, `DELETE`, `OPTIONS` else: r = self.pool_manager.request(method, url, fields=query_params, @@ -172,6 +172,11 @@ class RESTClientObject(object): headers=headers, query_params=query_params) + def OPTIONS(self, url, headers=None, query_params=None): + return self.request("OPTIONS", url, + headers=headers, + query_params=query_params) + def DELETE(self, url, headers=None, query_params=None): return self.request("DELETE", url, headers=headers, @@ -226,22 +231,3 @@ class ApiException(Exception): error_message += "HTTP response body: {0}\n".format(self.body) return error_message - - - - - - - - - - - - - - - - - - - diff --git a/samples/client/petstore/python/swagger_client/__init__.py b/samples/client/petstore/python/swagger_client/__init__.py index f61c5d5526..6e7b59f36f 100644 --- a/samples/client/petstore/python/swagger_client/__init__.py +++ b/samples/client/petstore/python/swagger_client/__init__.py @@ -9,8 +9,8 @@ from .models.order import Order # import apis into sdk package from .apis.user_api import UserApi -from .apis.pet_api import PetApi from .apis.store_api import StoreApi +from .apis.pet_api import PetApi # import ApiClient from .api_client import ApiClient diff --git a/samples/client/petstore/python/swagger_client/api_client.py b/samples/client/petstore/python/swagger_client/api_client.py index 1030bf9a83..a9d32c956e 100644 --- a/samples/client/petstore/python/swagger_client/api_client.py +++ b/samples/client/petstore/python/swagger_client/api_client.py @@ -270,7 +270,7 @@ class ApiClient(object): if klass in [int, float, str, bool]: return self.__deserialize_primitive(data, klass) elif klass == object: - return self.__deserialize_object() + return self.__deserialize_object(data) elif klass == date: return self.__deserialize_date(data) elif klass == datetime: @@ -338,6 +338,10 @@ class ApiClient(object): return self.rest_client.HEAD(url, query_params=query_params, headers=headers) + elif method == "OPTIONS": + return self.rest_client.OPTIONS(url, + query_params=query_params, + headers=headers) elif method == "POST": return self.rest_client.POST(url, query_params=query_params, @@ -495,13 +499,13 @@ class ApiClient(object): value = data return value - def __deserialize_object(self): + def __deserialize_object(self, value): """ - Deserializes empty object. + Return a original value. :return: object. """ - return object() + return value def __deserialize_date(self, string): """ diff --git a/samples/client/petstore/python/swagger_client/apis/__init__.py b/samples/client/petstore/python/swagger_client/apis/__init__.py index 592a56e282..c0e09458f9 100644 --- a/samples/client/petstore/python/swagger_client/apis/__init__.py +++ b/samples/client/petstore/python/swagger_client/apis/__init__.py @@ -2,5 +2,5 @@ from __future__ import absolute_import # import apis into api package from .user_api import UserApi -from .pet_api import PetApi from .store_api import StoreApi +from .pet_api import PetApi diff --git a/samples/client/petstore/python/swagger_client/apis/pet_api.py b/samples/client/petstore/python/swagger_client/apis/pet_api.py index ad053a7d72..b162cc534c 100644 --- a/samples/client/petstore/python/swagger_client/apis/pet_api.py +++ b/samples/client/petstore/python/swagger_client/apis/pet_api.py @@ -409,7 +409,7 @@ class PetApi(object): select_header_content_type([]) # Authentication setting - auth_settings = ['api_key', 'petstore_auth'] + auth_settings = ['petstore_auth', 'api_key'] response = self.api_client.call_api(resource_path, method, path_params, diff --git a/samples/client/petstore/python/swagger_client/rest.py b/samples/client/petstore/python/swagger_client/rest.py index 1481cbff3d..6279daedec 100644 --- a/samples/client/petstore/python/swagger_client/rest.py +++ b/samples/client/petstore/python/swagger_client/rest.py @@ -103,7 +103,7 @@ class RESTClientObject(object): and `multipart/form-data` """ method = method.upper() - assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH'] + assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH', 'OPTIONS'] if post_params and body: raise ValueError( @@ -138,7 +138,7 @@ class RESTClientObject(object): fields=post_params, encode_multipart=True, headers=headers) - # For `GET`, `HEAD`, `DELETE` + # For `GET`, `HEAD`, `DELETE`, `OPTIONS` else: r = self.pool_manager.request(method, url, fields=query_params, @@ -172,6 +172,11 @@ class RESTClientObject(object): headers=headers, query_params=query_params) + def OPTIONS(self, url, headers=None, query_params=None): + return self.request("OPTIONS", url, + headers=headers, + query_params=query_params) + def DELETE(self, url, headers=None, query_params=None): return self.request("DELETE", url, headers=headers, @@ -226,22 +231,3 @@ class ApiException(Exception): error_message += "HTTP response body: {0}\n".format(self.body) return error_message - - - - - - - - - - - - - - - - - - -