[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:
William Cheng
2019-02-08 11:48:37 +08:00
committed by GitHub
parent 7cee2b62e4
commit 36fa7102dd
24 changed files with 170 additions and 64 deletions

View File

@@ -82,6 +82,14 @@ class {{classname}}(object):
returns the request thread. returns the request thread.
""" """
{{#servers.0}}
local_var_hosts = [{{#servers}}'{{{url}}}'{{^-last}}, {{/-last}}{{/servers}}] # noqa: E501
local_var_host = local_var_hosts[0]
if kwargs.get('_host_index'):
if int(kwags.get('_host_index')) < 0 or int(kawgs.get('_host_index')) >= len(local_var_hosts):
raise ValueError("Invalid host index. Must be 0 <= index < %s" % len(local_var_host))
local_var_host = local_var_hosts[int(kwargs.get('_host_index'))]
{{/servers.0}}
local_var_params = locals() local_var_params = locals()
all_params = [{{#allParams}}'{{paramName}}'{{#hasMore}}, {{/hasMore}}{{/allParams}}] # noqa: E501 all_params = [{{#allParams}}'{{paramName}}'{{#hasMore}}, {{/hasMore}}{{/allParams}}] # noqa: E501
@@ -91,7 +99,7 @@ class {{classname}}(object):
all_params.append('_request_timeout') all_params.append('_request_timeout')
for key, val in six.iteritems(local_var_params['kwargs']): for key, val in six.iteritems(local_var_params['kwargs']):
if key not in all_params: if key not in all_params{{#servers.0}} and key != "_host_index"{{/servers.0}}:
raise TypeError( raise TypeError(
"Got an unexpected keyword argument '%s'" "Got an unexpected keyword argument '%s'"
" to method {{operationId}}" % key " to method {{operationId}}" % key
@@ -212,6 +220,9 @@ class {{classname}}(object):
_return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501
_preload_content=local_var_params.get('_preload_content', True), _preload_content=local_var_params.get('_preload_content', True),
_request_timeout=local_var_params.get('_request_timeout'), _request_timeout=local_var_params.get('_request_timeout'),
{{#servers.0}}
_host=local_var_host,
{{/servers.0}}
collection_formats=collection_formats) collection_formats=collection_formats)
{{/operation}} {{/operation}}
{{/operations}} {{/operations}}

View File

@@ -107,7 +107,7 @@ class ApiClient(object):
query_params=None, header_params=None, body=None, post_params=None, query_params=None, header_params=None, body=None, post_params=None,
files=None, response_type=None, auth_settings=None, files=None, response_type=None, auth_settings=None,
_return_http_data_only=None, collection_formats=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 config = self.configuration
@@ -154,7 +154,11 @@ class ApiClient(object):
body = self.sanitize_for_serialization(body) body = self.sanitize_for_serialization(body)
# request url # request url
if _host is None:
url = self.configuration.host + resource_path 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 # perform request and return response
response_data = {{#asyncio}}await {{/asyncio}}{{#tornado}}yield {{/tornado}}self.request( response_data = {{#asyncio}}await {{/asyncio}}{{#tornado}}yield {{/tornado}}self.request(
@@ -296,7 +300,7 @@ class ApiClient(object):
body=None, post_params=None, files=None, body=None, post_params=None, files=None,
response_type=None, auth_settings=None, async_req=None, response_type=None, auth_settings=None, async_req=None,
_return_http_data_only=None, collection_formats=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. """Makes the HTTP request (synchronous) and returns deserialized data.
To make an async_req request, set the async_req parameter. To make an async_req request, set the async_req parameter.
@@ -339,7 +343,7 @@ class ApiClient(object):
body, post_params, files, body, post_params, files,
response_type, auth_settings, response_type, auth_settings,
_return_http_data_only, collection_formats, _return_http_data_only, collection_formats,
_preload_content, _request_timeout) _preload_content, _request_timeout, _host)
else: else:
thread = self.pool.apply_async(self.__call_api, (resource_path, thread = self.pool.apply_async(self.__call_api, (resource_path,
method, path_params, query_params, method, path_params, query_params,
@@ -348,7 +352,9 @@ class ApiClient(object):
response_type, auth_settings, response_type, auth_settings,
_return_http_data_only, _return_http_data_only,
collection_formats, collection_formats,
_preload_content, _request_timeout)) _preload_content,
_request_timeout,
_host))
return thread return thread
def request(self, method, url, query_params=None, headers=None, def request(self, method, url, query_params=None, headers=None,

View File

@@ -30,6 +30,9 @@ paths:
string: string:
$ref: '#/components/schemas/Foo' $ref: '#/components/schemas/Foo'
/pet: /pet:
servers:
- url: 'http://petstore.swagger.io/v2'
- url: 'http://path-server-test.petstore.local/v2'
post: post:
tags: tags:
- pet - pet

View File

@@ -51,6 +51,7 @@ import petstore_api
from petstore_api.rest import ApiException from petstore_api.rest import ApiException
from pprint import pprint from pprint import pprint
# create an instance of the API class # create an instance of the API class
api_instance = petstore_api.AnotherFakeApi(petstore_api.ApiClient(configuration)) api_instance = petstore_api.AnotherFakeApi(petstore_api.ApiClient(configuration))
body = petstore_api.Client() # Client | client model body = petstore_api.Client() # Client | client model
@@ -158,16 +159,19 @@ Class | Method | HTTP request | Description
- **API key parameter name**: api_key - **API key parameter name**: api_key
- **Location**: HTTP header - **Location**: HTTP header
## api_key_query ## api_key_query
- **Type**: API key - **Type**: API key
- **API key parameter name**: api_key_query - **API key parameter name**: api_key_query
- **Location**: URL query string - **Location**: URL query string
## http_basic_test ## http_basic_test
- **Type**: HTTP basic authentication - **Type**: HTTP basic authentication
## petstore_auth ## petstore_auth
- **Type**: OAuth - **Type**: OAuth

View File

@@ -15,6 +15,7 @@ To test special tags
To test special tags and operation ID starting with number To test special tags and operation ID starting with number
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time

View File

@@ -27,6 +27,7 @@ creates an XmlItem
this route creates an XmlItem this route creates an XmlItem
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -74,6 +75,7 @@ No authorization required
Test serialization of outer boolean types Test serialization of outer boolean types
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -121,6 +123,7 @@ No authorization required
Test serialization of object with outer number type Test serialization of object with outer number type
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -168,6 +171,7 @@ No authorization required
Test serialization of outer number types Test serialization of outer number types
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -215,6 +219,7 @@ No authorization required
Test serialization of outer string types Test serialization of outer string types
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -262,6 +267,7 @@ No authorization required
For this test, the body for this request much reference a schema named `File`. For this test, the body for this request much reference a schema named `File`.
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -306,6 +312,7 @@ No authorization required
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -354,6 +361,7 @@ To test \"client\" model
To test \"client\" model To test \"client\" model
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -481,6 +489,7 @@ To test enum parameters
To test enum parameters To test enum parameters
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -542,6 +551,7 @@ Fake endpoint to test group parameters (optional)
Fake endpoint to test group parameters (optional) Fake endpoint to test group parameters (optional)
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -597,6 +607,7 @@ No authorization required
test inline additionalProperties test inline additionalProperties
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -642,6 +653,7 @@ No authorization required
test json serialization of form data test json serialization of form data
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time

View File

@@ -18,6 +18,7 @@ Delete purchase order by ID
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -116,6 +117,7 @@ Find purchase order by ID
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -162,6 +164,7 @@ No authorization required
Place an order for a pet Place an order for a pet
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time

View File

@@ -22,6 +22,7 @@ Create user
This can only be done by the logged in user. This can only be done by the logged in user.
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -67,6 +68,7 @@ No authorization required
Creates list of users with given input array Creates list of users with given input array
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -112,6 +114,7 @@ No authorization required
Creates list of users with given input array Creates list of users with given input array
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -159,6 +162,7 @@ Delete user
This can only be done by the logged in user. This can only be done by the logged in user.
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -204,6 +208,7 @@ No authorization required
Get user by user name Get user by user name
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -250,6 +255,7 @@ No authorization required
Logs user into the system Logs user into the system
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -298,6 +304,7 @@ No authorization required
Logs out current logged in user session Logs out current logged in user session
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -341,6 +348,7 @@ Updated user
This can only be done by the logged in user. This can only be done by the logged in user.
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time

View File

@@ -109,7 +109,7 @@ class ApiClient(object):
query_params=None, header_params=None, body=None, post_params=None, query_params=None, header_params=None, body=None, post_params=None,
files=None, response_type=None, auth_settings=None, files=None, response_type=None, auth_settings=None,
_return_http_data_only=None, collection_formats=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 config = self.configuration
@@ -156,7 +156,11 @@ class ApiClient(object):
body = self.sanitize_for_serialization(body) body = self.sanitize_for_serialization(body)
# request url # request url
if _host is None:
url = self.configuration.host + resource_path 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 # perform request and return response
response_data = await self.request( response_data = await self.request(
@@ -289,7 +293,7 @@ class ApiClient(object):
body=None, post_params=None, files=None, body=None, post_params=None, files=None,
response_type=None, auth_settings=None, async_req=None, response_type=None, auth_settings=None, async_req=None,
_return_http_data_only=None, collection_formats=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. """Makes the HTTP request (synchronous) and returns deserialized data.
To make an async_req request, set the async_req parameter. To make an async_req request, set the async_req parameter.
@@ -332,7 +336,7 @@ class ApiClient(object):
body, post_params, files, body, post_params, files,
response_type, auth_settings, response_type, auth_settings,
_return_http_data_only, collection_formats, _return_http_data_only, collection_formats,
_preload_content, _request_timeout) _preload_content, _request_timeout, _host)
else: else:
thread = self.pool.apply_async(self.__call_api, (resource_path, thread = self.pool.apply_async(self.__call_api, (resource_path,
method, path_params, query_params, method, path_params, query_params,
@@ -341,7 +345,9 @@ class ApiClient(object):
response_type, auth_settings, response_type, auth_settings,
_return_http_data_only, _return_http_data_only,
collection_formats, collection_formats,
_preload_content, _request_timeout)) _preload_content,
_request_timeout,
_host))
return thread return thread
def request(self, method, url, query_params=None, headers=None, def request(self, method, url, query_params=None, headers=None,

View File

@@ -59,10 +59,8 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
self.username = "" self.username = ""
# Password for HTTP basic authentication # Password for HTTP basic authentication
self.password = "" self.password = ""
# access token for OAuth/Bearer
# access token for OAuth
self.access_token = "" self.access_token = ""
# Logging Settings # Logging Settings
self.logger = {} self.logger = {}
self.logger["package_logger"] = logging.getLogger("petstore_api") self.logger["package_logger"] = logging.getLogger("petstore_api")
@@ -236,7 +234,6 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
'key': 'Authorization', 'key': 'Authorization',
'value': self.get_basic_auth_token() 'value': self.get_basic_auth_token()
}, },
'petstore_auth': 'petstore_auth':
{ {
'type': 'oauth2', 'type': 'oauth2',
@@ -244,7 +241,6 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
'key': 'Authorization', 'key': 'Authorization',
'value': 'Bearer ' + self.access_token 'value': 'Bearer ' + self.access_token
}, },
} }
def to_debug_report(self): def to_debug_report(self):
@@ -281,7 +277,7 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
servers = self.get_host_settings() servers = self.get_host_settings()
# check array index out of bound # check array index out of bound
if index < 0 or index > len(servers): if index < 0 or index >= len(servers):
raise ValueError( raise ValueError(
"Invalid index {} when selecting the host settings. Must be less than {}" # noqa: E501 "Invalid index {} when selecting the host settings. Must be less than {}" # noqa: E501
.format(index, len(servers))) .format(index, len(servers)))

View File

@@ -51,6 +51,7 @@ import petstore_api
from petstore_api.rest import ApiException from petstore_api.rest import ApiException
from pprint import pprint from pprint import pprint
# create an instance of the API class # create an instance of the API class
api_instance = petstore_api.AnotherFakeApi(petstore_api.ApiClient(configuration)) api_instance = petstore_api.AnotherFakeApi(petstore_api.ApiClient(configuration))
body = petstore_api.Client() # Client | client model body = petstore_api.Client() # Client | client model
@@ -158,16 +159,19 @@ Class | Method | HTTP request | Description
- **API key parameter name**: api_key - **API key parameter name**: api_key
- **Location**: HTTP header - **Location**: HTTP header
## api_key_query ## api_key_query
- **Type**: API key - **Type**: API key
- **API key parameter name**: api_key_query - **API key parameter name**: api_key_query
- **Location**: URL query string - **Location**: URL query string
## http_basic_test ## http_basic_test
- **Type**: HTTP basic authentication - **Type**: HTTP basic authentication
## petstore_auth ## petstore_auth
- **Type**: OAuth - **Type**: OAuth

View File

@@ -15,6 +15,7 @@ To test special tags
To test special tags and operation ID starting with number To test special tags and operation ID starting with number
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time

View File

@@ -27,6 +27,7 @@ creates an XmlItem
this route creates an XmlItem this route creates an XmlItem
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -74,6 +75,7 @@ No authorization required
Test serialization of outer boolean types Test serialization of outer boolean types
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -121,6 +123,7 @@ No authorization required
Test serialization of object with outer number type Test serialization of object with outer number type
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -168,6 +171,7 @@ No authorization required
Test serialization of outer number types Test serialization of outer number types
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -215,6 +219,7 @@ No authorization required
Test serialization of outer string types Test serialization of outer string types
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -262,6 +267,7 @@ No authorization required
For this test, the body for this request much reference a schema named `File`. For this test, the body for this request much reference a schema named `File`.
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -306,6 +312,7 @@ No authorization required
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -354,6 +361,7 @@ To test \"client\" model
To test \"client\" model To test \"client\" model
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -481,6 +489,7 @@ To test enum parameters
To test enum parameters To test enum parameters
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -542,6 +551,7 @@ Fake endpoint to test group parameters (optional)
Fake endpoint to test group parameters (optional) Fake endpoint to test group parameters (optional)
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -597,6 +607,7 @@ No authorization required
test inline additionalProperties test inline additionalProperties
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -642,6 +653,7 @@ No authorization required
test json serialization of form data test json serialization of form data
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time

View File

@@ -18,6 +18,7 @@ Delete purchase order by ID
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -116,6 +117,7 @@ Find purchase order by ID
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -162,6 +164,7 @@ No authorization required
Place an order for a pet Place an order for a pet
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time

View File

@@ -22,6 +22,7 @@ Create user
This can only be done by the logged in user. This can only be done by the logged in user.
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -67,6 +68,7 @@ No authorization required
Creates list of users with given input array Creates list of users with given input array
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -112,6 +114,7 @@ No authorization required
Creates list of users with given input array Creates list of users with given input array
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -159,6 +162,7 @@ Delete user
This can only be done by the logged in user. This can only be done by the logged in user.
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -204,6 +208,7 @@ No authorization required
Get user by user name Get user by user name
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -250,6 +255,7 @@ No authorization required
Logs user into the system Logs user into the system
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -298,6 +304,7 @@ No authorization required
Logs out current logged in user session Logs out current logged in user session
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time
@@ -341,6 +348,7 @@ Updated user
This can only be done by the logged in user. This can only be done by the logged in user.
### Example ### Example
```python ```python
from __future__ import print_function from __future__ import print_function
import time import time

View File

@@ -111,7 +111,7 @@ class ApiClient(object):
query_params=None, header_params=None, body=None, post_params=None, query_params=None, header_params=None, body=None, post_params=None,
files=None, response_type=None, auth_settings=None, files=None, response_type=None, auth_settings=None,
_return_http_data_only=None, collection_formats=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 config = self.configuration
@@ -158,7 +158,11 @@ class ApiClient(object):
body = self.sanitize_for_serialization(body) body = self.sanitize_for_serialization(body)
# request url # request url
if _host is None:
url = self.configuration.host + resource_path 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 # perform request and return response
response_data = yield self.request( response_data = yield self.request(
@@ -291,7 +295,7 @@ class ApiClient(object):
body=None, post_params=None, files=None, body=None, post_params=None, files=None,
response_type=None, auth_settings=None, async_req=None, response_type=None, auth_settings=None, async_req=None,
_return_http_data_only=None, collection_formats=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. """Makes the HTTP request (synchronous) and returns deserialized data.
To make an async_req request, set the async_req parameter. To make an async_req request, set the async_req parameter.
@@ -334,7 +338,7 @@ class ApiClient(object):
body, post_params, files, body, post_params, files,
response_type, auth_settings, response_type, auth_settings,
_return_http_data_only, collection_formats, _return_http_data_only, collection_formats,
_preload_content, _request_timeout) _preload_content, _request_timeout, _host)
else: else:
thread = self.pool.apply_async(self.__call_api, (resource_path, thread = self.pool.apply_async(self.__call_api, (resource_path,
method, path_params, query_params, method, path_params, query_params,
@@ -343,7 +347,9 @@ class ApiClient(object):
response_type, auth_settings, response_type, auth_settings,
_return_http_data_only, _return_http_data_only,
collection_formats, collection_formats,
_preload_content, _request_timeout)) _preload_content,
_request_timeout,
_host))
return thread return thread
def request(self, method, url, query_params=None, headers=None, def request(self, method, url, query_params=None, headers=None,

View File

@@ -59,10 +59,8 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
self.username = "" self.username = ""
# Password for HTTP basic authentication # Password for HTTP basic authentication
self.password = "" self.password = ""
# access token for OAuth/Bearer
# access token for OAuth
self.access_token = "" self.access_token = ""
# Logging Settings # Logging Settings
self.logger = {} self.logger = {}
self.logger["package_logger"] = logging.getLogger("petstore_api") self.logger["package_logger"] = logging.getLogger("petstore_api")
@@ -236,7 +234,6 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
'key': 'Authorization', 'key': 'Authorization',
'value': self.get_basic_auth_token() 'value': self.get_basic_auth_token()
}, },
'petstore_auth': 'petstore_auth':
{ {
'type': 'oauth2', 'type': 'oauth2',
@@ -244,7 +241,6 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
'key': 'Authorization', 'key': 'Authorization',
'value': 'Bearer ' + self.access_token 'value': 'Bearer ' + self.access_token
}, },
} }
def to_debug_report(self): def to_debug_report(self):
@@ -281,7 +277,7 @@ class Configuration(six.with_metaclass(TypeWithDefault, object)):
servers = self.get_host_settings() servers = self.get_host_settings()
# check array index out of bound # check array index out of bound
if index < 0 or index > len(servers): if index < 0 or index >= len(servers):
raise ValueError( raise ValueError(
"Invalid index {} when selecting the host settings. Must be less than {}" # noqa: E501 "Invalid index {} when selecting the host settings. Must be less than {}" # noqa: E501
.format(index, len(servers))) .format(index, len(servers)))

View File

@@ -109,7 +109,7 @@ class ApiClient(object):
query_params=None, header_params=None, body=None, post_params=None, query_params=None, header_params=None, body=None, post_params=None,
files=None, response_type=None, auth_settings=None, files=None, response_type=None, auth_settings=None,
_return_http_data_only=None, collection_formats=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 config = self.configuration
@@ -156,7 +156,11 @@ class ApiClient(object):
body = self.sanitize_for_serialization(body) body = self.sanitize_for_serialization(body)
# request url # request url
if _host is None:
url = self.configuration.host + resource_path 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 # perform request and return response
response_data = self.request( response_data = self.request(
@@ -289,7 +293,7 @@ class ApiClient(object):
body=None, post_params=None, files=None, body=None, post_params=None, files=None,
response_type=None, auth_settings=None, async_req=None, response_type=None, auth_settings=None, async_req=None,
_return_http_data_only=None, collection_formats=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. """Makes the HTTP request (synchronous) and returns deserialized data.
To make an async_req request, set the async_req parameter. To make an async_req request, set the async_req parameter.
@@ -332,7 +336,7 @@ class ApiClient(object):
body, post_params, files, body, post_params, files,
response_type, auth_settings, response_type, auth_settings,
_return_http_data_only, collection_formats, _return_http_data_only, collection_formats,
_preload_content, _request_timeout) _preload_content, _request_timeout, _host)
else: else:
thread = self.pool.apply_async(self.__call_api, (resource_path, thread = self.pool.apply_async(self.__call_api, (resource_path,
method, path_params, query_params, method, path_params, query_params,
@@ -341,7 +345,9 @@ class ApiClient(object):
response_type, auth_settings, response_type, auth_settings,
_return_http_data_only, _return_http_data_only,
collection_formats, collection_formats,
_preload_content, _request_timeout)) _preload_content,
_request_timeout,
_host))
return thread return thread
def request(self, method, url, query_params=None, headers=None, def request(self, method, url, query_params=None, headers=None,

View File

@@ -68,6 +68,12 @@ class PetApi(object):
returns the request thread. returns the request thread.
""" """
local_var_hosts = ['http://petstore.swagger.io/v2', 'http://path-server-test.petstore.local/v2'] # noqa: E501
local_var_host = local_var_hosts[0]
if kwargs.get('_host_index'):
if int(kwags.get('_host_index')) < 0 or int(kawgs.get('_host_index')) >= len(local_var_hosts):
raise ValueError("Invalid host index. Must be 0 <= index < %s" % len(local_var_host))
local_var_host = local_var_hosts[int(kwargs.get('_host_index'))]
local_var_params = locals() local_var_params = locals()
all_params = ['pet'] # noqa: E501 all_params = ['pet'] # noqa: E501
@@ -77,7 +83,7 @@ class PetApi(object):
all_params.append('_request_timeout') all_params.append('_request_timeout')
for key, val in six.iteritems(local_var_params['kwargs']): for key, val in six.iteritems(local_var_params['kwargs']):
if key not in all_params: if key not in all_params and key != "_host_index":
raise TypeError( raise TypeError(
"Got an unexpected keyword argument '%s'" "Got an unexpected keyword argument '%s'"
" to method add_pet" % key " to method add_pet" % key
@@ -124,6 +130,7 @@ class PetApi(object):
_return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501
_preload_content=local_var_params.get('_preload_content', True), _preload_content=local_var_params.get('_preload_content', True),
_request_timeout=local_var_params.get('_request_timeout'), _request_timeout=local_var_params.get('_request_timeout'),
_host=local_var_host,
collection_formats=collection_formats) collection_formats=collection_formats)
def delete_pet(self, pet_id, **kwargs): # noqa: E501 def delete_pet(self, pet_id, **kwargs): # noqa: E501
@@ -546,6 +553,12 @@ class PetApi(object):
returns the request thread. returns the request thread.
""" """
local_var_hosts = ['http://petstore.swagger.io/v2', 'http://path-server-test.petstore.local/v2'] # noqa: E501
local_var_host = local_var_hosts[0]
if kwargs.get('_host_index'):
if int(kwags.get('_host_index')) < 0 or int(kawgs.get('_host_index')) >= len(local_var_hosts):
raise ValueError("Invalid host index. Must be 0 <= index < %s" % len(local_var_host))
local_var_host = local_var_hosts[int(kwargs.get('_host_index'))]
local_var_params = locals() local_var_params = locals()
all_params = ['pet'] # noqa: E501 all_params = ['pet'] # noqa: E501
@@ -555,7 +568,7 @@ class PetApi(object):
all_params.append('_request_timeout') all_params.append('_request_timeout')
for key, val in six.iteritems(local_var_params['kwargs']): for key, val in six.iteritems(local_var_params['kwargs']):
if key not in all_params: if key not in all_params and key != "_host_index":
raise TypeError( raise TypeError(
"Got an unexpected keyword argument '%s'" "Got an unexpected keyword argument '%s'"
" to method update_pet" % key " to method update_pet" % key
@@ -602,6 +615,7 @@ class PetApi(object):
_return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501
_preload_content=local_var_params.get('_preload_content', True), _preload_content=local_var_params.get('_preload_content', True),
_request_timeout=local_var_params.get('_request_timeout'), _request_timeout=local_var_params.get('_request_timeout'),
_host=local_var_host,
collection_formats=collection_formats) collection_formats=collection_formats)
def update_pet_with_form(self, pet_id, **kwargs): # noqa: E501 def update_pet_with_form(self, pet_id, **kwargs): # noqa: E501

View File

@@ -109,7 +109,7 @@ class ApiClient(object):
query_params=None, header_params=None, body=None, post_params=None, query_params=None, header_params=None, body=None, post_params=None,
files=None, response_type=None, auth_settings=None, files=None, response_type=None, auth_settings=None,
_return_http_data_only=None, collection_formats=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 config = self.configuration
@@ -156,7 +156,11 @@ class ApiClient(object):
body = self.sanitize_for_serialization(body) body = self.sanitize_for_serialization(body)
# request url # request url
if _host is None:
url = self.configuration.host + resource_path 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 # perform request and return response
response_data = self.request( response_data = self.request(
@@ -289,7 +293,7 @@ class ApiClient(object):
body=None, post_params=None, files=None, body=None, post_params=None, files=None,
response_type=None, auth_settings=None, async_req=None, response_type=None, auth_settings=None, async_req=None,
_return_http_data_only=None, collection_formats=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. """Makes the HTTP request (synchronous) and returns deserialized data.
To make an async_req request, set the async_req parameter. To make an async_req request, set the async_req parameter.
@@ -332,7 +336,7 @@ class ApiClient(object):
body, post_params, files, body, post_params, files,
response_type, auth_settings, response_type, auth_settings,
_return_http_data_only, collection_formats, _return_http_data_only, collection_formats,
_preload_content, _request_timeout) _preload_content, _request_timeout, _host)
else: else:
thread = self.pool.apply_async(self.__call_api, (resource_path, thread = self.pool.apply_async(self.__call_api, (resource_path,
method, path_params, query_params, method, path_params, query_params,
@@ -341,7 +345,9 @@ class ApiClient(object):
response_type, auth_settings, response_type, auth_settings,
_return_http_data_only, _return_http_data_only,
collection_formats, collection_formats,
_preload_content, _request_timeout)) _preload_content,
_request_timeout,
_host))
return thread return thread
def request(self, method, url, query_params=None, headers=None, def request(self, method, url, query_params=None, headers=None,