forked from loafle/openapi-generator-original
Merge branch 'new_python_with_http_info' of https://github.com/zhenjun115/swagger-codegen into zhenjun115-new_python_with_http_info
Conflicts: modules/swagger-codegen/src/main/resources/python/api.mustache samples/client/petstore/python/swagger_client/__init__.py samples/client/petstore/python/swagger_client/api_client.py samples/client/petstore/python/swagger_client/apis/pet_api.py samples/client/petstore/python/swagger_client/apis/store_api.py samples/client/petstore/python/swagger_client/apis/user_api.py samples/client/petstore/python/swagger_client/models/__init__.py samples/client/petstore/python/swagger_client/models/name.py
This commit is contained in:
@@ -51,6 +51,40 @@ class {{classname}}(object):
|
||||
>>> thread = api.{{operationId}}({{#allParams}}{{#required}}{{paramName}}={{paramName}}_value, {{/required}}{{/allParams}}callback=callback_function)
|
||||
{{/sortParamsByRequiredFlag}}
|
||||
|
||||
:param callback function: The callback function
|
||||
for asynchronous request. (optional)
|
||||
{{#allParams}}
|
||||
:param {{dataType}} {{paramName}}: {{{description}}}{{#required}} (required){{/required}}{{#optional}}(optional){{/optional}}
|
||||
{{/allParams}}
|
||||
:return: {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}None{{/returnType}}
|
||||
If the method is called asynchronously,
|
||||
returns the request thread.
|
||||
"""
|
||||
kwargs['_return_http_data_only'] = True
|
||||
if kwargs.get('callback'):
|
||||
return self.{{operationId}}_with_http_info({{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs)
|
||||
else:
|
||||
(data) = self.{{operationId}}_with_http_info({{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs)
|
||||
return data
|
||||
|
||||
def {{operationId}}_with_http_info(self, {{#sortParamsByRequiredFlag}}{{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}{{/sortParamsByRequiredFlag}}**kwargs):
|
||||
"""
|
||||
{{{summary}}}
|
||||
{{{notes}}}
|
||||
|
||||
This method makes a synchronous HTTP request by default. To make an
|
||||
asynchronous HTTP request, please define a `callback` function
|
||||
to be invoked when receiving the response.
|
||||
>>> def callback_function(response):
|
||||
>>> pprint(response)
|
||||
>>>
|
||||
{{#sortParamsByRequiredFlag}}
|
||||
>>> thread = api.{{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}callback=callback_function)
|
||||
{{/sortParamsByRequiredFlag}}
|
||||
{{^sortParamsByRequiredFlag}}
|
||||
>>> thread = api.{{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}={{paramName}}_value, {{/required}}{{/allParams}}callback=callback_function)
|
||||
{{/sortParamsByRequiredFlag}}
|
||||
|
||||
:param callback function: The callback function
|
||||
for asynchronous request. (optional)
|
||||
{{#allParams}}
|
||||
@@ -63,6 +97,7 @@ class {{classname}}(object):
|
||||
|
||||
all_params = [{{#allParams}}'{{paramName}}'{{#hasMore}}, {{/hasMore}}{{/allParams}}]
|
||||
all_params.append('callback')
|
||||
all_params.append('_return_http_data_only')
|
||||
|
||||
params = locals()
|
||||
for key, val in iteritems(params['kwargs']):
|
||||
@@ -150,7 +185,7 @@ class {{classname}}(object):
|
||||
# Authentication setting
|
||||
auth_settings = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}]
|
||||
|
||||
response = self.api_client.call_api(resource_path, '{{httpMethod}}',
|
||||
return self.api_client.call_api(resource_path, '{{httpMethod}}',
|
||||
path_params,
|
||||
query_params,
|
||||
header_params,
|
||||
@@ -159,7 +194,7 @@ class {{classname}}(object):
|
||||
files=local_var_files,
|
||||
response_type={{#returnType}}'{{returnType}}'{{/returnType}}{{^returnType}}None{{/returnType}},
|
||||
auth_settings=auth_settings,
|
||||
callback=params.get('callback'))
|
||||
return response
|
||||
callback=params.get('callback'),
|
||||
_return_http_data_only=params.get('_return_http_data_only'))
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
|
||||
@@ -103,7 +103,7 @@ class ApiClient(object):
|
||||
def __call_api(self, resource_path, method,
|
||||
path_params=None, query_params=None, header_params=None,
|
||||
body=None, post_params=None, files=None,
|
||||
response_type=None, auth_settings=None, callback=None):
|
||||
response_type=None, auth_settings=None, callback=None, _return_http_data_only=None):
|
||||
|
||||
# headers parameters
|
||||
header_params = header_params or {}
|
||||
@@ -157,9 +157,12 @@ class ApiClient(object):
|
||||
deserialized_data = None
|
||||
|
||||
if callback:
|
||||
callback(deserialized_data)
|
||||
callback(deserialized_data) if _return_http_data_only else callback((deserialized_data, response_data.status, response_data.getheaders()))
|
||||
elif _return_http_data_only:
|
||||
return ( deserialized_data );
|
||||
else:
|
||||
return deserialized_data
|
||||
return (deserialized_data, response_data.status, response_data.getheaders())
|
||||
|
||||
|
||||
def to_path_value(self, obj):
|
||||
"""
|
||||
@@ -287,7 +290,7 @@ class ApiClient(object):
|
||||
def call_api(self, resource_path, method,
|
||||
path_params=None, query_params=None, header_params=None,
|
||||
body=None, post_params=None, files=None,
|
||||
response_type=None, auth_settings=None, callback=None):
|
||||
response_type=None, auth_settings=None, callback=None, _return_http_data_only=None):
|
||||
"""
|
||||
Makes the HTTP request (synchronous) and return the deserialized data.
|
||||
To make an async request, define a function for callback.
|
||||
@@ -308,6 +311,7 @@ class ApiClient(object):
|
||||
:param callback function: Callback function for asynchronous request.
|
||||
If provide this parameter,
|
||||
the request will be called asynchronously.
|
||||
:param _return_http_data_only: response data without head status code and headers
|
||||
:return:
|
||||
If provide parameter callback,
|
||||
the request will be called asynchronously.
|
||||
@@ -319,7 +323,7 @@ class ApiClient(object):
|
||||
return self.__call_api(resource_path, method,
|
||||
path_params, query_params, header_params,
|
||||
body, post_params, files,
|
||||
response_type, auth_settings, callback)
|
||||
response_type, auth_settings, callback, _return_http_data_only)
|
||||
else:
|
||||
thread = threading.Thread(target=self.__call_api,
|
||||
args=(resource_path, method,
|
||||
@@ -327,7 +331,7 @@ class ApiClient(object):
|
||||
header_params, body,
|
||||
post_params, files,
|
||||
response_type, auth_settings,
|
||||
callback))
|
||||
callback,_return_http_data_only))
|
||||
thread.start()
|
||||
return thread
|
||||
|
||||
|
||||
Reference in New Issue
Block a user