From 4e5ba15fa07f7e2e4dd63e5a6da1f321f26ff09e Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Sat, 19 Mar 2016 16:51:02 +0000 Subject: [PATCH 1/2] Issue 2410: Suport HTTP body for DELETE operation --- .../src/main/resources/python/api_client.mustache | 3 ++- .../src/main/resources/python/rest.mustache | 11 ++++++----- .../petstore/python/swagger_client/api_client.py | 3 ++- .../client/petstore/python/swagger_client/rest.py | 12 +++++++----- 4 files changed, 17 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 98fee823591..07b9419e08f 100644 --- a/modules/swagger-codegen/src/main/resources/python/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/python/api_client.mustache @@ -371,7 +371,8 @@ class ApiClient(object): elif method == "DELETE": return self.rest_client.DELETE(url, query_params=query_params, - headers=headers) + headers=headers, + body=body) else: raise ValueError( "http method must be `GET`, `HEAD`," diff --git a/modules/swagger-codegen/src/main/resources/python/rest.mustache b/modules/swagger-codegen/src/main/resources/python/rest.mustache index c5b9a4e6f91..352bb503ac5 100644 --- a/modules/swagger-codegen/src/main/resources/python/rest.mustache +++ b/modules/swagger-codegen/src/main/resources/python/rest.mustache @@ -133,8 +133,8 @@ class RESTClientObject(object): headers['Content-Type'] = 'application/json' try: - # For `POST`, `PUT`, `PATCH`, `OPTIONS` - if method in ['POST', 'PUT', 'PATCH', 'OPTIONS']: + # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE` + if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']: if query_params: url += '?' + urlencode(query_params) if headers['Content-Type'] == 'application/json': @@ -154,7 +154,7 @@ class RESTClientObject(object): fields=post_params, encode_multipart=True, headers=headers) - # For `GET`, `HEAD`, `DELETE` + # For `GET`, `HEAD` else: r = self.pool_manager.request(method, url, fields=query_params, @@ -195,10 +195,11 @@ class RESTClientObject(object): post_params=post_params, body=body) - def DELETE(self, url, headers=None, query_params=None): + def DELETE(self, url, headers=None, query_params=None, body=None): return self.request("DELETE", url, headers=headers, - query_params=query_params) + query_params=query_params, + body=body) def POST(self, url, headers=None, query_params=None, post_params=None, body=None): return self.request("POST", url, diff --git a/samples/client/petstore/python/swagger_client/api_client.py b/samples/client/petstore/python/swagger_client/api_client.py index e598115e319..5d5a5fccc4c 100644 --- a/samples/client/petstore/python/swagger_client/api_client.py +++ b/samples/client/petstore/python/swagger_client/api_client.py @@ -371,7 +371,8 @@ class ApiClient(object): elif method == "DELETE": return self.rest_client.DELETE(url, query_params=query_params, - headers=headers) + headers=headers, + body=body) else: raise ValueError( "http method must be `GET`, `HEAD`," diff --git a/samples/client/petstore/python/swagger_client/rest.py b/samples/client/petstore/python/swagger_client/rest.py index c5b9a4e6f91..fbba5178c03 100644 --- a/samples/client/petstore/python/swagger_client/rest.py +++ b/samples/client/petstore/python/swagger_client/rest.py @@ -133,8 +133,9 @@ class RESTClientObject(object): headers['Content-Type'] = 'application/json' try: - # For `POST`, `PUT`, `PATCH`, `OPTIONS` - if method in ['POST', 'PUT', 'PATCH', 'OPTIONS']: + print(method) + # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE` + if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']: if query_params: url += '?' + urlencode(query_params) if headers['Content-Type'] == 'application/json': @@ -154,7 +155,7 @@ class RESTClientObject(object): fields=post_params, encode_multipart=True, headers=headers) - # For `GET`, `HEAD`, `DELETE` + # For `GET`, `HEAD` else: r = self.pool_manager.request(method, url, fields=query_params, @@ -195,10 +196,11 @@ class RESTClientObject(object): post_params=post_params, body=body) - def DELETE(self, url, headers=None, query_params=None): + def DELETE(self, url, headers=None, query_params=None, body=None): return self.request("DELETE", url, headers=headers, - query_params=query_params) + query_params=query_params, + body=body) def POST(self, url, headers=None, query_params=None, post_params=None, body=None): return self.request("POST", url, From a9409834dffb6990a55ffd378c98a19278ce308c Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Sat, 19 Mar 2016 20:37:56 +0000 Subject: [PATCH 2/2] Re-generate python client --- samples/client/petstore/python/swagger_client/rest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/client/petstore/python/swagger_client/rest.py b/samples/client/petstore/python/swagger_client/rest.py index fbba5178c03..352bb503ac5 100644 --- a/samples/client/petstore/python/swagger_client/rest.py +++ b/samples/client/petstore/python/swagger_client/rest.py @@ -133,7 +133,6 @@ class RESTClientObject(object): headers['Content-Type'] = 'application/json' try: - print(method) # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE` if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']: if query_params: