Skip to content

Commit d67e4d7

Browse files
committed
Merge branch 'zhenjun115-new_python_with_http_info'
2 parents 7e867dc + 50ef914 commit d67e4d7

File tree

14 files changed

+1181
-85
lines changed

14 files changed

+1181
-85
lines changed

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,40 @@ class {{classname}}(object):
5151
>>> thread = api.{{operationId}}({{#allParams}}{{#required}}{{paramName}}={{paramName}}_value, {{/required}}{{/allParams}}callback=callback_function)
5252
{{/sortParamsByRequiredFlag}}
5353

54+
:param callback function: The callback function
55+
for asynchronous request. (optional)
56+
{{#allParams}}
57+
:param {{dataType}} {{paramName}}: {{{description}}}{{#required}} (required){{/required}}{{#optional}}(optional){{/optional}}
58+
{{/allParams}}
59+
:return: {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}None{{/returnType}}
60+
If the method is called asynchronously,
61+
returns the request thread.
62+
"""
63+
kwargs['_return_http_data_only'] = True
64+
if kwargs.get('callback'):
65+
return self.{{operationId}}_with_http_info({{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs)
66+
else:
67+
(data) = self.{{operationId}}_with_http_info({{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs)
68+
return data
69+
70+
def {{operationId}}_with_http_info(self, {{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs):
71+
"""
72+
{{{summary}}}
73+
{{{notes}}}
74+
75+
This method makes a synchronous HTTP request by default. To make an
76+
asynchronous HTTP request, please define a `callback` function
77+
to be invoked when receiving the response.
78+
>>> def callback_function(response):
79+
>>> pprint(response)
80+
>>>
81+
{{#sortParamsByRequiredFlag}}
82+
>>> thread = api.{{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}callback=callback_function)
83+
{{/sortParamsByRequiredFlag}}
84+
{{^sortParamsByRequiredFlag}}
85+
>>> thread = api.{{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}={{paramName}}_value, {{/required}}{{/allParams}}callback=callback_function)
86+
{{/sortParamsByRequiredFlag}}
87+
5488
:param callback function: The callback function
5589
for asynchronous request. (optional)
5690
{{#allParams}}
@@ -63,6 +97,7 @@ class {{classname}}(object):
6397

6498
all_params = [{{#allParams}}'{{paramName}}'{{#hasMore}}, {{/hasMore}}{{/allParams}}]
6599
all_params.append('callback')
100+
all_params.append('_return_http_data_only')
66101

67102
params = locals()
68103
for key, val in iteritems(params['kwargs']):
@@ -150,7 +185,7 @@ class {{classname}}(object):
150185
# Authentication setting
151186
auth_settings = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}]
152187

153-
response = self.api_client.call_api(resource_path, '{{httpMethod}}',
188+
return self.api_client.call_api(resource_path, '{{httpMethod}}',
154189
path_params,
155190
query_params,
156191
header_params,
@@ -159,7 +194,7 @@ class {{classname}}(object):
159194
files=local_var_files,
160195
response_type={{#returnType}}'{{returnType}}'{{/returnType}}{{^returnType}}None{{/returnType}},
161196
auth_settings=auth_settings,
162-
callback=params.get('callback'))
163-
return response
197+
callback=params.get('callback'),
198+
_return_http_data_only=params.get('_return_http_data_only'))
164199
{{/operation}}
165200
{{/operations}}

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class ApiClient(object):
103103
def __call_api(self, resource_path, method,
104104
path_params=None, query_params=None, header_params=None,
105105
body=None, post_params=None, files=None,
106-
response_type=None, auth_settings=None, callback=None):
106+
response_type=None, auth_settings=None, callback=None, _return_http_data_only=None):
107107

108108
# headers parameters
109109
header_params = header_params or {}
@@ -157,9 +157,12 @@ class ApiClient(object):
157157
deserialized_data = None
158158

159159
if callback:
160-
callback(deserialized_data)
160+
callback(deserialized_data) if _return_http_data_only else callback((deserialized_data, response_data.status, response_data.getheaders()))
161+
elif _return_http_data_only:
162+
return ( deserialized_data );
161163
else:
162-
return deserialized_data
164+
return (deserialized_data, response_data.status, response_data.getheaders())
165+
163166

164167
def to_path_value(self, obj):
165168
"""
@@ -287,7 +290,7 @@ class ApiClient(object):
287290
def call_api(self, resource_path, method,
288291
path_params=None, query_params=None, header_params=None,
289292
body=None, post_params=None, files=None,
290-
response_type=None, auth_settings=None, callback=None):
293+
response_type=None, auth_settings=None, callback=None, _return_http_data_only=None):
291294
"""
292295
Makes the HTTP request (synchronous) and return the deserialized data.
293296
To make an async request, define a function for callback.
@@ -308,6 +311,7 @@ class ApiClient(object):
308311
:param callback function: Callback function for asynchronous request.
309312
If provide this parameter,
310313
the request will be called asynchronously.
314+
:param _return_http_data_only: response data without head status code and headers
311315
:return:
312316
If provide parameter callback,
313317
the request will be called asynchronously.
@@ -319,15 +323,15 @@ class ApiClient(object):
319323
return self.__call_api(resource_path, method,
320324
path_params, query_params, header_params,
321325
body, post_params, files,
322-
response_type, auth_settings, callback)
326+
response_type, auth_settings, callback, _return_http_data_only)
323327
else:
324328
thread = threading.Thread(target=self.__call_api,
325329
args=(resource_path, method,
326330
path_params, query_params,
327331
header_params, body,
328332
post_params, files,
329333
response_type, auth_settings,
330-
callback))
334+
callback,_return_http_data_only))
331335
thread.start()
332336
return thread
333337

samples/client/petstore/python/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This Python package is automatically generated by the [Swagger Codegen](https://
55

66
- API version: 1.0.0
77
- Package version: 1.0.0
8-
- Build date: 2016-06-17T00:41:00.422+08:00
8+
- Build date: 2016-06-20T11:55:16.948+08:00
99
- Build package: class io.swagger.codegen.languages.PythonClientCodegen
1010

1111
## Requirements.

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def set_default_header(self, header_name, header_value):
103103
def __call_api(self, resource_path, method,
104104
path_params=None, query_params=None, header_params=None,
105105
body=None, post_params=None, files=None,
106-
response_type=None, auth_settings=None, callback=None):
106+
response_type=None, auth_settings=None, callback=None, _return_http_data_only=None):
107107

108108
# headers parameters
109109
header_params = header_params or {}
@@ -157,9 +157,12 @@ def __call_api(self, resource_path, method,
157157
deserialized_data = None
158158

159159
if callback:
160-
callback(deserialized_data)
160+
callback(deserialized_data) if _return_http_data_only else callback((deserialized_data, response_data.status, response_data.getheaders()))
161+
elif _return_http_data_only:
162+
return ( deserialized_data );
161163
else:
162-
return deserialized_data
164+
return (deserialized_data, response_data.status, response_data.getheaders())
165+
163166

164167
def to_path_value(self, obj):
165168
"""
@@ -287,7 +290,7 @@ def __deserialize(self, data, klass):
287290
def call_api(self, resource_path, method,
288291
path_params=None, query_params=None, header_params=None,
289292
body=None, post_params=None, files=None,
290-
response_type=None, auth_settings=None, callback=None):
293+
response_type=None, auth_settings=None, callback=None, _return_http_data_only=None):
291294
"""
292295
Makes the HTTP request (synchronous) and return the deserialized data.
293296
To make an async request, define a function for callback.
@@ -308,6 +311,7 @@ def call_api(self, resource_path, method,
308311
:param callback function: Callback function for asynchronous request.
309312
If provide this parameter,
310313
the request will be called asynchronously.
314+
:param _return_http_data_only: response data without head status code and headers
311315
:return:
312316
If provide parameter callback,
313317
the request will be called asynchronously.
@@ -319,15 +323,15 @@ def call_api(self, resource_path, method,
319323
return self.__call_api(resource_path, method,
320324
path_params, query_params, header_params,
321325
body, post_params, files,
322-
response_type, auth_settings, callback)
326+
response_type, auth_settings, callback, _return_http_data_only)
323327
else:
324328
thread = threading.Thread(target=self.__call_api,
325329
args=(resource_path, method,
326330
path_params, query_params,
327331
header_params, body,
328332
post_params, files,
329333
response_type, auth_settings,
330-
callback))
334+
callback,_return_http_data_only))
331335
thread.start()
332336
return thread
333337

samples/client/petstore/python/petstore_api/apis/fake_api.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,44 @@ def test_endpoint_parameters(self, number, double, string, byte, **kwargs):
6464
>>>
6565
>>> thread = api.test_endpoint_parameters(number, double, string, byte, callback=callback_function)
6666
67+
:param callback function: The callback function
68+
for asynchronous request. (optional)
69+
:param float number: None (required)
70+
:param float double: None (required)
71+
:param str string: None (required)
72+
:param str byte: None (required)
73+
:param int integer: None
74+
:param int int32: None
75+
:param int int64: None
76+
:param float float: None
77+
:param str binary: None
78+
:param date date: None
79+
:param datetime date_time: None
80+
:param str password: None
81+
:return: None
82+
If the method is called asynchronously,
83+
returns the request thread.
84+
"""
85+
kwargs['_return_http_data_only'] = True
86+
if kwargs.get('callback'):
87+
return self.test_endpoint_parameters_with_http_info(number, double, string, byte, **kwargs)
88+
else:
89+
(data) = self.test_endpoint_parameters_with_http_info(number, double, string, byte, **kwargs)
90+
return data
91+
92+
def test_endpoint_parameters_with_http_info(self, number, double, string, byte, **kwargs):
93+
"""
94+
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
95+
Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
96+
97+
This method makes a synchronous HTTP request by default. To make an
98+
asynchronous HTTP request, please define a `callback` function
99+
to be invoked when receiving the response.
100+
>>> def callback_function(response):
101+
>>> pprint(response)
102+
>>>
103+
>>> thread = api.test_endpoint_parameters_with_http_info(number, double, string, byte, callback=callback_function)
104+
67105
:param callback function: The callback function
68106
for asynchronous request. (optional)
69107
:param float number: None (required)
@@ -85,6 +123,7 @@ def test_endpoint_parameters(self, number, double, string, byte, **kwargs):
85123

86124
all_params = ['number', 'double', 'string', 'byte', 'integer', 'int32', 'int64', 'float', 'binary', 'date', 'date_time', 'password']
87125
all_params.append('callback')
126+
all_params.append('_return_http_data_only')
88127

89128
params = locals()
90129
for key, val in iteritems(params['kwargs']):
@@ -181,7 +220,7 @@ def test_endpoint_parameters(self, number, double, string, byte, **kwargs):
181220
# Authentication setting
182221
auth_settings = []
183222

184-
response = self.api_client.call_api(resource_path, 'POST',
223+
return self.api_client.call_api(resource_path, 'POST',
185224
path_params,
186225
query_params,
187226
header_params,
@@ -190,5 +229,5 @@ def test_endpoint_parameters(self, number, double, string, byte, **kwargs):
190229
files=local_var_files,
191230
response_type=None,
192231
auth_settings=auth_settings,
193-
callback=params.get('callback'))
194-
return response
232+
callback=params.get('callback'),
233+
_return_http_data_only=params.get('_return_http_data_only'))

0 commit comments

Comments
 (0)