forked from loafle/openapi-generator-original
[Python] Add "servers" support in path, operation (#2052)
* add servers to path, operation * add path/operation server support to python client * update python samples * fix index * fix python code style
This commit is contained in:
@@ -109,7 +109,7 @@ 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):
|
||||
_preload_content=True, _request_timeout=None, _host=None):
|
||||
|
||||
config = self.configuration
|
||||
|
||||
@@ -156,7 +156,11 @@ class ApiClient(object):
|
||||
body = self.sanitize_for_serialization(body)
|
||||
|
||||
# request url
|
||||
url = self.configuration.host + resource_path
|
||||
if _host is None:
|
||||
url = self.configuration.host + resource_path
|
||||
else:
|
||||
# use server/host defined in path or operation instead
|
||||
url = _host + resource_path
|
||||
|
||||
# perform request and return response
|
||||
response_data = await self.request(
|
||||
@@ -289,7 +293,7 @@ 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):
|
||||
_preload_content=True, _request_timeout=None, _host=None):
|
||||
"""Makes the HTTP request (synchronous) and returns deserialized data.
|
||||
|
||||
To make an async_req request, set the async_req parameter.
|
||||
@@ -332,7 +336,7 @@ class ApiClient(object):
|
||||
body, post_params, files,
|
||||
response_type, auth_settings,
|
||||
_return_http_data_only, collection_formats,
|
||||
_preload_content, _request_timeout)
|
||||
_preload_content, _request_timeout, _host)
|
||||
else:
|
||||
thread = self.pool.apply_async(self.__call_api, (resource_path,
|
||||
method, path_params, query_params,
|
||||
@@ -341,7 +345,9 @@ class ApiClient(object):
|
||||
response_type, auth_settings,
|
||||
_return_http_data_only,
|
||||
collection_formats,
|
||||
_preload_content, _request_timeout))
|
||||
_preload_content,
|
||||
_request_timeout,
|
||||
_host))
|
||||
return thread
|
||||
|
||||
def request(self, method, url, query_params=None, headers=None,
|
||||
|
||||
@@ -59,10 +59,8 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
|
||||
self.username = ""
|
||||
# Password for HTTP basic authentication
|
||||
self.password = ""
|
||||
|
||||
# access token for OAuth
|
||||
# access token for OAuth/Bearer
|
||||
self.access_token = ""
|
||||
|
||||
# Logging Settings
|
||||
self.logger = {}
|
||||
self.logger["package_logger"] = logging.getLogger("petstore_api")
|
||||
@@ -236,7 +234,6 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
|
||||
'key': 'Authorization',
|
||||
'value': self.get_basic_auth_token()
|
||||
},
|
||||
|
||||
'petstore_auth':
|
||||
{
|
||||
'type': 'oauth2',
|
||||
@@ -244,7 +241,6 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
|
||||
'key': 'Authorization',
|
||||
'value': 'Bearer ' + self.access_token
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
def to_debug_report(self):
|
||||
@@ -281,7 +277,7 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
|
||||
servers = self.get_host_settings()
|
||||
|
||||
# check array index out of bound
|
||||
if index < 0 or index > len(servers):
|
||||
if index < 0 or index >= len(servers):
|
||||
raise ValueError(
|
||||
"Invalid index {} when selecting the host settings. Must be less than {}" # noqa: E501
|
||||
.format(index, len(servers)))
|
||||
|
||||
Reference in New Issue
Block a user