Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions modules/openapi-generator/src/main/resources/python/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ class {{classname}}(object):
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:param _request_auth: set to override the auth_settings for an a single
request; this effectively ignores the authentication
in the spec for a single request.
:type _request_auth: dict, optional
:return: Returns the result object.
If the method is called asynchronously,
returns the request thread.
Expand Down Expand Up @@ -137,7 +141,8 @@ class {{classname}}(object):
'async_req',
'_return_http_data_only',
'_preload_content',
'_request_timeout'
'_request_timeout',
'_request_auth'
]
)

Expand Down Expand Up @@ -266,6 +271,7 @@ class {{classname}}(object):
{{#servers.0}}
_host=local_var_host,
{{/servers.0}}
collection_formats=collection_formats)
collection_formats=collection_formats,
_request_auth=local_var_params.get('_request_auth'))
{{/operation}}
{{/operations}}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ class ApiClient(object):
query_params=None, header_params=None, body=None, post_params=None,
files=None, response_type=None, auth_settings=None,
_return_http_data_only=None, collection_formats=None,
_preload_content=True, _request_timeout=None, _host=None):
_preload_content=True, _request_timeout=None, _host=None,
_request_auth=None):

config = self.configuration

Expand Down Expand Up @@ -173,7 +174,9 @@ class ApiClient(object):
post_params.extend(self.files_parameters(files))

# auth setting
self.update_params_for_auth(header_params, query_params, auth_settings)
self.update_params_for_auth(
header_params, query_params, auth_settings,
request_auth=_request_auth)

# body
if body:
Expand Down Expand Up @@ -347,7 +350,8 @@ class ApiClient(object):
body=None, post_params=None, files=None,
response_type=None, auth_settings=None, async_req=None,
_return_http_data_only=None, collection_formats=None,
_preload_content=True, _request_timeout=None, _host=None):
_preload_content=True, _request_timeout=None, _host=None,
_request_auth=None):
"""Makes the HTTP request (synchronous) and returns deserialized data.

To make an async_req request, set the async_req parameter.
Expand Down Expand Up @@ -377,6 +381,10 @@ class ApiClient(object):
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:param _request_auth: set to override the auth_settings for an a single
request; this effectively ignores the authentication
in the spec for a single request.
:type _request_token: dict, optional
:return:
If async_req parameter is True,
the request will be called asynchronously.
Expand All @@ -390,7 +398,8 @@ class ApiClient(object):
body, post_params, files,
response_type, auth_settings,
_return_http_data_only, collection_formats,
_preload_content, _request_timeout, _host)
_preload_content, _request_timeout, _host,
_request_auth)

return self.pool.apply_async(self.__call_api, (resource_path,
method, path_params,
Expand All @@ -403,7 +412,7 @@ class ApiClient(object):
collection_formats,
_preload_content,
_request_timeout,
_host))
_host, _request_auth))

def request(self, method, url, query_params=None, headers=None,
post_params=None, body=None, _preload_content=True,
Expand Down Expand Up @@ -550,29 +559,45 @@ class ApiClient(object):
else:
return content_types[0]

def update_params_for_auth(self, headers, querys, auth_settings):
def update_params_for_auth(self, headers, querys, auth_settings,
request_auth=None):
"""Updates header and query params based on authentication setting.

:param headers: Header parameters dict to be updated.
:param querys: Query parameters tuple list to be updated.
:param auth_settings: Authentication setting identifiers list.
:param request_auth: if set, the provided settings will
override the token in the configuration.
"""
if not auth_settings:
return

if request_auth:
self._apply_auth_params(headers, querys, request_auth)
return

for auth in auth_settings:
auth_setting = self.configuration.auth_settings().get(auth)
if auth_setting:
if auth_setting['in'] == 'cookie':
headers['Cookie'] = auth_setting['value']
elif auth_setting['in'] == 'header':
headers[auth_setting['key']] = auth_setting['value']
elif auth_setting['in'] == 'query':
querys.append((auth_setting['key'], auth_setting['value']))
else:
raise ApiValueError(
'Authentication token must be in `query` or `header`'
)
self._apply_auth_params(headers, querys, auth_setting)

def _apply_auth_params(self, headers, querys, auth_setting):
"""Updates the request parameters based on a single auth_setting

:param headers: Header parameters dict to be updated.
:param querys: Query parameters tuple list to be updated.
:param auth_setting: auth settings for the endpoint
"""
if auth_setting['in'] == 'cookie':
headers['Cookie'] = auth_setting['value']
elif auth_setting['in'] == 'header':
headers[auth_setting['key']] = auth_setting['value']
elif auth_setting['in'] == 'query':
querys.append((auth_setting['key'], auth_setting['value']))
else:
raise ApiValueError(
'Authentication token must be in `query` or `header`'
)

def __deserialize_file(self, response):
"""Deserializes body to file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E5
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:param _request_auth: set to override the auth_settings for an a single
request; this effectively ignores the authentication
in the spec for a single request.
:type _request_auth: dict, optional
:return: Returns the result object.
If the method is called asynchronously,
returns the request thread.
Expand All @@ -107,7 +111,8 @@ def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E5
'async_req',
'_return_http_data_only',
'_preload_content',
'_request_timeout'
'_request_timeout',
'_request_auth'
]
)

Expand Down Expand Up @@ -163,4 +168,5 @@ def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E5
_return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501
_preload_content=local_var_params.get('_preload_content', True),
_request_timeout=local_var_params.get('_request_timeout'),
collection_formats=collection_formats)
collection_formats=collection_formats,
_request_auth=local_var_params.get('_request_auth'))
Loading