Skip to content

Commit 53e13ae

Browse files
committed
Merge pull request #1234 from geekerzp/python_http_verb
[Python] Enhancements http verbs of python client
2 parents ec05dc4 + ade61c0 commit 53e13ae

File tree

7 files changed

+39
-51
lines changed

7 files changed

+39
-51
lines changed

modules/swagger-codegen/src/main/resources/python/api_client.mustache

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,12 @@ class ApiClient(object):
338338
return self.rest_client.HEAD(url,
339339
query_params=query_params,
340340
headers=headers)
341+
elif method == "OPTIONS":
342+
return self.rest_client.OPTIONS(url,
343+
query_params=query_params,
344+
headers=headers,
345+
post_params=post_params,
346+
body=body)
341347
elif method == "POST":
342348
return self.rest_client.POST(url,
343349
query_params=query_params,

modules/swagger-codegen/src/main/resources/python/rest.mustache

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class RESTClientObject(object):
103103
and `multipart/form-data`
104104
"""
105105
method = method.upper()
106-
assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH']
106+
assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH', 'OPTIONS']
107107

108108
if post_params and body:
109109
raise ValueError(
@@ -117,8 +117,8 @@ class RESTClientObject(object):
117117
headers['Content-Type'] = 'application/json'
118118

119119
try:
120-
# For `POST`, `PUT`, `PATCH`
121-
if method in ['POST', 'PUT', 'PATCH']:
120+
# For `POST`, `PUT`, `PATCH`, `OPTIONS`
121+
if method in ['POST', 'PUT', 'PATCH', 'OPTIONS']:
122122
if query_params:
123123
url += '?' + urlencode(query_params)
124124
if headers['Content-Type'] == 'application/json':
@@ -172,6 +172,13 @@ class RESTClientObject(object):
172172
headers=headers,
173173
query_params=query_params)
174174

175+
def OPTIONS(self, url, headers=None, query_params=None, post_params=None, body=None):
176+
return self.request("OPTIONS", url,
177+
headers=headers,
178+
query_params=query_params,
179+
post_params=post_params,
180+
body=body)
181+
175182
def DELETE(self, url, headers=None, query_params=None):
176183
return self.request("DELETE", url,
177184
headers=headers,
@@ -226,22 +233,3 @@ class ApiException(Exception):
226233
error_message += "HTTP response body: {0}\n".format(self.body)
227234

228235
return error_message
229-
230-
231-
232-
233-
234-
235-
236-
237-
238-
239-
240-
241-
242-
243-
244-
245-
246-
247-

samples/client/petstore/python/swagger_client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
# import apis into sdk package
1111
from .apis.user_api import UserApi
12-
from .apis.pet_api import PetApi
1312
from .apis.store_api import StoreApi
13+
from .apis.pet_api import PetApi
1414

1515
# import ApiClient
1616
from .api_client import ApiClient

samples/client/petstore/python/swagger_client/api_client.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def __deserialize(self, data, klass):
270270
if klass in [int, float, str, bool]:
271271
return self.__deserialize_primitive(data, klass)
272272
elif klass == object:
273-
return self.__deserialize_object()
273+
return self.__deserialize_object(data)
274274
elif klass == date:
275275
return self.__deserialize_date(data)
276276
elif klass == datetime:
@@ -338,6 +338,12 @@ def request(self, method, url, query_params=None, headers=None,
338338
return self.rest_client.HEAD(url,
339339
query_params=query_params,
340340
headers=headers)
341+
elif method == "OPTIONS":
342+
return self.rest_client.OPTIONS(url,
343+
query_params=query_params,
344+
headers=headers,
345+
post_params=post_params,
346+
body=body)
341347
elif method == "POST":
342348
return self.rest_client.POST(url,
343349
query_params=query_params,
@@ -495,13 +501,13 @@ def __deserialize_primitive(self, data, klass):
495501
value = data
496502
return value
497503

498-
def __deserialize_object(self):
504+
def __deserialize_object(self, value):
499505
"""
500-
Deserializes empty object.
506+
Return a original value.
501507
502508
:return: object.
503509
"""
504-
return object()
510+
return value
505511

506512
def __deserialize_date(self, string):
507513
"""

samples/client/petstore/python/swagger_client/apis/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
# import apis into api package
44
from .user_api import UserApi
5-
from .pet_api import PetApi
65
from .store_api import StoreApi
6+
from .pet_api import PetApi

samples/client/petstore/python/swagger_client/apis/pet_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def get_pet_by_id(self, pet_id, **kwargs):
409409
select_header_content_type([])
410410

411411
# Authentication setting
412-
auth_settings = ['api_key', 'petstore_auth']
412+
auth_settings = ['petstore_auth', 'api_key']
413413

414414
response = self.api_client.call_api(resource_path, method,
415415
path_params,

samples/client/petstore/python/swagger_client/rest.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def request(self, method, url, query_params=None, headers=None,
103103
and `multipart/form-data`
104104
"""
105105
method = method.upper()
106-
assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH']
106+
assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH', 'OPTIONS']
107107

108108
if post_params and body:
109109
raise ValueError(
@@ -117,8 +117,8 @@ def request(self, method, url, query_params=None, headers=None,
117117
headers['Content-Type'] = 'application/json'
118118

119119
try:
120-
# For `POST`, `PUT`, `PATCH`
121-
if method in ['POST', 'PUT', 'PATCH']:
120+
# For `POST`, `PUT`, `PATCH`, `OPTIONS`
121+
if method in ['POST', 'PUT', 'PATCH', 'OPTIONS']:
122122
if query_params:
123123
url += '?' + urlencode(query_params)
124124
if headers['Content-Type'] == 'application/json':
@@ -172,6 +172,13 @@ def HEAD(self, url, headers=None, query_params=None):
172172
headers=headers,
173173
query_params=query_params)
174174

175+
def OPTIONS(self, url, headers=None, query_params=None, post_params=None, body=None):
176+
return self.request("OPTIONS", url,
177+
headers=headers,
178+
query_params=query_params,
179+
post_params=post_params,
180+
body=body)
181+
175182
def DELETE(self, url, headers=None, query_params=None):
176183
return self.request("DELETE", url,
177184
headers=headers,
@@ -226,22 +233,3 @@ def __str__(self):
226233
error_message += "HTTP response body: {0}\n".format(self.body)
227234

228235
return error_message
229-
230-
231-
232-
233-
234-
235-
236-
237-
238-
239-
240-
241-
242-
243-
244-
245-
246-
247-

0 commit comments

Comments
 (0)