From bd63c1d9d96a7cc99ea75a167bb297aa5d1f0488 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Tue, 15 Sep 2015 16:40:23 +0800 Subject: [PATCH 1/2] 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 84a1dca45ff..5ec6ddbcccc 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 1481cbff3d5..6279daedec3 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 f61c5d55262..6e7b59f36fd 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 1030bf9a838..a9d32c956ef 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 592a56e282d..c0e09458f95 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 ad053a7d72d..b162cc534c3 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 1481cbff3d5..6279daedec3 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 - - - - - - - - - - - - - - - - - - - From ade61c0701868c07b6ab9799a9e5772f3752a109 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Tue, 15 Sep 2015 17:48:59 +0800 Subject: [PATCH 2/2] Support http body in OPTIONS request in python client --- .../src/main/resources/python/api_client.mustache | 4 +++- .../src/main/resources/python/rest.mustache | 12 +++++++----- .../petstore/python/swagger_client/api_client.py | 4 +++- .../client/petstore/python/swagger_client/rest.py | 12 +++++++----- 4 files changed, 20 insertions(+), 12 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 5ec6ddbcccc..f62f341045b 100644 --- a/modules/swagger-codegen/src/main/resources/python/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/python/api_client.mustache @@ -341,7 +341,9 @@ class ApiClient(object): elif method == "OPTIONS": return self.rest_client.OPTIONS(url, query_params=query_params, - headers=headers) + headers=headers, + post_params=post_params, + body=body) 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 6279daedec3..07be648373a 100644 --- a/modules/swagger-codegen/src/main/resources/python/rest.mustache +++ b/modules/swagger-codegen/src/main/resources/python/rest.mustache @@ -117,8 +117,8 @@ class RESTClientObject(object): headers['Content-Type'] = 'application/json' try: - # For `POST`, `PUT`, `PATCH` - if method in ['POST', 'PUT', 'PATCH']: + # For `POST`, `PUT`, `PATCH`, `OPTIONS` + if method in ['POST', 'PUT', 'PATCH', 'OPTIONS']: if query_params: url += '?' + urlencode(query_params) if headers['Content-Type'] == 'application/json': @@ -138,7 +138,7 @@ class RESTClientObject(object): fields=post_params, encode_multipart=True, headers=headers) - # For `GET`, `HEAD`, `DELETE`, `OPTIONS` + # For `GET`, `HEAD`, `DELETE` else: r = self.pool_manager.request(method, url, fields=query_params, @@ -172,10 +172,12 @@ class RESTClientObject(object): headers=headers, query_params=query_params) - def OPTIONS(self, url, headers=None, query_params=None): + def OPTIONS(self, url, headers=None, query_params=None, post_params=None, body=None): return self.request("OPTIONS", url, headers=headers, - query_params=query_params) + query_params=query_params, + post_params=post_params, + body=body) def DELETE(self, url, headers=None, query_params=None): return self.request("DELETE", url, diff --git a/samples/client/petstore/python/swagger_client/api_client.py b/samples/client/petstore/python/swagger_client/api_client.py index a9d32c956ef..b44c4a321a6 100644 --- a/samples/client/petstore/python/swagger_client/api_client.py +++ b/samples/client/petstore/python/swagger_client/api_client.py @@ -341,7 +341,9 @@ class ApiClient(object): elif method == "OPTIONS": return self.rest_client.OPTIONS(url, query_params=query_params, - headers=headers) + headers=headers, + post_params=post_params, + body=body) elif method == "POST": return self.rest_client.POST(url, query_params=query_params, diff --git a/samples/client/petstore/python/swagger_client/rest.py b/samples/client/petstore/python/swagger_client/rest.py index 6279daedec3..07be648373a 100644 --- a/samples/client/petstore/python/swagger_client/rest.py +++ b/samples/client/petstore/python/swagger_client/rest.py @@ -117,8 +117,8 @@ class RESTClientObject(object): headers['Content-Type'] = 'application/json' try: - # For `POST`, `PUT`, `PATCH` - if method in ['POST', 'PUT', 'PATCH']: + # For `POST`, `PUT`, `PATCH`, `OPTIONS` + if method in ['POST', 'PUT', 'PATCH', 'OPTIONS']: if query_params: url += '?' + urlencode(query_params) if headers['Content-Type'] == 'application/json': @@ -138,7 +138,7 @@ class RESTClientObject(object): fields=post_params, encode_multipart=True, headers=headers) - # For `GET`, `HEAD`, `DELETE`, `OPTIONS` + # For `GET`, `HEAD`, `DELETE` else: r = self.pool_manager.request(method, url, fields=query_params, @@ -172,10 +172,12 @@ class RESTClientObject(object): headers=headers, query_params=query_params) - def OPTIONS(self, url, headers=None, query_params=None): + def OPTIONS(self, url, headers=None, query_params=None, post_params=None, body=None): return self.request("OPTIONS", url, headers=headers, - query_params=query_params) + query_params=query_params, + post_params=post_params, + body=body) def DELETE(self, url, headers=None, query_params=None): return self.request("DELETE", url,