[Python] Conditionally set auth attributes (#4988)

* Enhance python API keys

* Run python scripts under ./bin/openapi3

* fix unit test issue

* Fix unit tests

* Fix unit tests

* Invoke bin scripts
This commit is contained in:
Sebastien Rosset 2020-01-16 01:42:23 -08:00 committed by William Cheng
parent b94fe7a40f
commit fa0ef2be25
16 changed files with 440 additions and 235 deletions

View File

@ -520,9 +520,7 @@ class ApiClient(object):
for auth in auth_settings:
auth_setting = self.configuration.auth_settings().get(auth)
if auth_setting:
if not auth_setting['value']:
continue
elif auth_setting['in'] == 'cookie':
if auth_setting['in'] == 'cookie':
headers['Cookie'] = auth_setting['value']
elif auth_setting['in'] == 'header':
headers[auth_setting['key']] = auth_setting['value']

View File

@ -22,15 +22,38 @@ class Configuration(object):
Do not edit the class manually.
:param host: Base url
:param api_key: Dict to store API key(s)
:param api_key: Dict to store API key(s).
Each entry in the dict specifies an API key.
The dict key is the name of the security scheme in the OAS specification.
The dict value is the API key secret.
:param api_key_prefix: Dict to store API prefix (e.g. Bearer)
The dict key is the name of the security scheme in the OAS specification.
The dict value is an API key prefix when generating the auth data.
:param username: Username for HTTP basic authentication
:param password: Password for HTTP basic authentication
:Example:
Given the following security scheme in the OpenAPI specification:
components:
securitySchemes:
cookieAuth: # name for the security scheme
type: apiKey
in: cookie
name: JSESSIONID # cookie name
You can programmatically set the cookie:
conf = {{{packageName}}}.Configuration(
api_key={'cookieAuth': 'abc123'}
api_key_prefix={'cookieAuth': 'JSESSIONID'}
)
The following cookie will be added to the HTTP request:
Cookie: JSESSIONID abc123
"""
def __init__(self, host="{{{basePath}}}",
api_key=None, api_key_prefix=None,
username="", password=""):
username=None, password=None):
"""Constructor
"""
self.host = host
@ -247,8 +270,14 @@ class Configuration(object):
:return: The token for basic HTTP authentication.
"""
username = ""
if self.username is not None:
username = self.username
password = ""
if self.password is not None:
password = self.password
return urllib3.util.make_headers(
basic_auth=self.username + ':' + self.password
basic_auth=username + ':' + password
).get('authorization')
def auth_settings(self):
@ -256,30 +285,30 @@ class Configuration(object):
:return: The Auth Settings information dict.
"""
return {
auth = {}
{{#authMethods}}
{{#isApiKey}}
'{{name}}':
{
if '{{keyParamName}}' in self.api_key:
auth['{{name}}'] = {
'type': 'api_key',
'in': {{#isKeyInCookie}}'cookie'{{/isKeyInCookie}}{{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{#isKeyInQuery}}'query'{{/isKeyInQuery}},
'key': '{{keyParamName}}',
'value': self.get_api_key_with_prefix('{{keyParamName}}')
},
}
{{/isApiKey}}
{{#isBasic}}
{{^isBasicBearer}}
'{{name}}':
{
if self.username is not None and self.password is not None:
auth['{{name}}'] = {
'type': 'basic',
'in': 'header',
'key': 'Authorization',
'value': self.get_basic_auth_token()
},
}
{{/isBasicBearer}}
{{#isBasicBearer}}
'{{name}}':
{
if self.access_token is not None:
auth['{{name}}'] = {
'type': 'bearer',
'in': 'header',
{{#bearerFormat}}
@ -287,20 +316,20 @@ class Configuration(object):
{{/bearerFormat}}
'key': 'Authorization',
'value': 'Bearer ' + self.access_token
},
}
{{/isBasicBearer}}
{{/isBasic}}
{{#isOAuth}}
'{{name}}':
{
if self.access_token is not None:
auth['{{name}}'] = {
'type': 'oauth2',
'in': 'header',
'key': 'Authorization',
'value': 'Bearer ' + self.access_token
},
}
{{/isOAuth}}
{{/authMethods}}
}
return auth
def to_debug_report(self):
"""Gets the essential information for debugging.

View File

@ -530,9 +530,7 @@ class ApiClient(object):
for auth in auth_settings:
auth_setting = self.configuration.auth_settings().get(auth)
if auth_setting:
if not auth_setting['value']:
continue
elif auth_setting['in'] == 'cookie':
if auth_setting['in'] == 'cookie':
headers['Cookie'] = auth_setting['value']
elif auth_setting['in'] == 'header':
headers[auth_setting['key']] = auth_setting['value']

View File

@ -513,9 +513,7 @@ class ApiClient(object):
for auth in auth_settings:
auth_setting = self.configuration.auth_settings().get(auth)
if auth_setting:
if not auth_setting['value']:
continue
elif auth_setting['in'] == 'cookie':
if auth_setting['in'] == 'cookie':
headers['Cookie'] = auth_setting['value']
elif auth_setting['in'] == 'header':
headers[auth_setting['key']] = auth_setting['value']

View File

@ -27,15 +27,38 @@ class Configuration(object):
Do not edit the class manually.
:param host: Base url
:param api_key: Dict to store API key(s)
:param api_key: Dict to store API key(s).
Each entry in the dict specifies an API key.
The dict key is the name of the security scheme in the OAS specification.
The dict value is the API key secret.
:param api_key_prefix: Dict to store API prefix (e.g. Bearer)
The dict key is the name of the security scheme in the OAS specification.
The dict value is an API key prefix when generating the auth data.
:param username: Username for HTTP basic authentication
:param password: Password for HTTP basic authentication
:Example:
Given the following security scheme in the OpenAPI specification:
components:
securitySchemes:
cookieAuth: # name for the security scheme
type: apiKey
in: cookie
name: JSESSIONID # cookie name
You can programmatically set the cookie:
conf = petstore_api.Configuration(
api_key={'cookieAuth': 'abc123'}
api_key_prefix={'cookieAuth': 'JSESSIONID'}
)
The following cookie will be added to the HTTP request:
Cookie: JSESSIONID abc123
"""
def __init__(self, host="http://petstore.swagger.io:80/v2",
api_key=None, api_key_prefix=None,
username="", password=""):
username=None, password=None):
"""Constructor
"""
self.host = host
@ -232,8 +255,14 @@ class Configuration(object):
:return: The token for basic HTTP authentication.
"""
username = ""
if self.username is not None:
username = self.username
password = ""
if self.password is not None:
password = self.password
return urllib3.util.make_headers(
basic_auth=self.username + ':' + self.password
basic_auth=username + ':' + password
).get('authorization')
def auth_settings(self):
@ -241,36 +270,36 @@ class Configuration(object):
:return: The Auth Settings information dict.
"""
return {
'api_key':
{
auth = {}
if 'api_key' in self.api_key:
auth['api_key'] = {
'type': 'api_key',
'in': 'header',
'key': 'api_key',
'value': self.get_api_key_with_prefix('api_key')
},
'api_key_query':
{
}
if 'api_key_query' in self.api_key:
auth['api_key_query'] = {
'type': 'api_key',
'in': 'query',
'key': 'api_key_query',
'value': self.get_api_key_with_prefix('api_key_query')
},
'http_basic_test':
{
}
if self.username is not None and self.password is not None:
auth['http_basic_test'] = {
'type': 'basic',
'in': 'header',
'key': 'Authorization',
'value': self.get_basic_auth_token()
},
'petstore_auth':
{
}
if self.access_token is not None:
auth['petstore_auth'] = {
'type': 'oauth2',
'in': 'header',
'key': 'Authorization',
'value': 'Bearer ' + self.access_token
},
}
return auth
def to_debug_report(self):
"""Gets the essential information for debugging.

View File

@ -523,9 +523,7 @@ class ApiClient(object):
for auth in auth_settings:
auth_setting = self.configuration.auth_settings().get(auth)
if auth_setting:
if not auth_setting['value']:
continue
elif auth_setting['in'] == 'cookie':
if auth_setting['in'] == 'cookie':
headers['Cookie'] = auth_setting['value']
elif auth_setting['in'] == 'header':
headers[auth_setting['key']] = auth_setting['value']

View File

@ -28,15 +28,38 @@ class Configuration(object):
Do not edit the class manually.
:param host: Base url
:param api_key: Dict to store API key(s)
:param api_key: Dict to store API key(s).
Each entry in the dict specifies an API key.
The dict key is the name of the security scheme in the OAS specification.
The dict value is the API key secret.
:param api_key_prefix: Dict to store API prefix (e.g. Bearer)
The dict key is the name of the security scheme in the OAS specification.
The dict value is an API key prefix when generating the auth data.
:param username: Username for HTTP basic authentication
:param password: Password for HTTP basic authentication
:Example:
Given the following security scheme in the OpenAPI specification:
components:
securitySchemes:
cookieAuth: # name for the security scheme
type: apiKey
in: cookie
name: JSESSIONID # cookie name
You can programmatically set the cookie:
conf = petstore_api.Configuration(
api_key={'cookieAuth': 'abc123'}
api_key_prefix={'cookieAuth': 'JSESSIONID'}
)
The following cookie will be added to the HTTP request:
Cookie: JSESSIONID abc123
"""
def __init__(self, host="http://petstore.swagger.io:80/v2",
api_key=None, api_key_prefix=None,
username="", password=""):
username=None, password=None):
"""Constructor
"""
self.host = host
@ -236,8 +259,14 @@ class Configuration(object):
:return: The token for basic HTTP authentication.
"""
username = ""
if self.username is not None:
username = self.username
password = ""
if self.password is not None:
password = self.password
return urllib3.util.make_headers(
basic_auth=self.username + ':' + self.password
basic_auth=username + ':' + password
).get('authorization')
def auth_settings(self):
@ -245,36 +274,36 @@ class Configuration(object):
:return: The Auth Settings information dict.
"""
return {
'api_key':
{
auth = {}
if 'api_key' in self.api_key:
auth['api_key'] = {
'type': 'api_key',
'in': 'header',
'key': 'api_key',
'value': self.get_api_key_with_prefix('api_key')
},
'api_key_query':
{
}
if 'api_key_query' in self.api_key:
auth['api_key_query'] = {
'type': 'api_key',
'in': 'query',
'key': 'api_key_query',
'value': self.get_api_key_with_prefix('api_key_query')
},
'http_basic_test':
{
}
if self.username is not None and self.password is not None:
auth['http_basic_test'] = {
'type': 'basic',
'in': 'header',
'key': 'Authorization',
'value': self.get_basic_auth_token()
},
'petstore_auth':
{
}
if self.access_token is not None:
auth['petstore_auth'] = {
'type': 'oauth2',
'in': 'header',
'key': 'Authorization',
'value': 'Bearer ' + self.access_token
},
}
return auth
def to_debug_report(self):
"""Gets the essential information for debugging.

View File

@ -55,6 +55,29 @@ class ApiClientTests(unittest.TestCase):
self.assertEqual('test_username', client.configuration.username)
self.assertEqual('test_password', client.configuration.password)
# test api key without prefix
config.api_key['api_key'] = '123456'
config.api_key_prefix['api_key'] = None
# update parameters based on auth setting
client.update_params_for_auth(header_params, query_params, auth_settings)
self.assertEqual(header_params['api_key'], '123456')
# test api key with empty prefix
config.api_key['api_key'] = '123456'
config.api_key_prefix['api_key'] = ''
# update parameters based on auth setting
client.update_params_for_auth(header_params, query_params, auth_settings)
self.assertEqual(header_params['api_key'], '123456')
# test api key with prefix specified in the api_key, useful when the prefix
# must include '=' sign followed by the API key secret without space.
config.api_key['api_key'] = 'PREFIX=123456'
config.api_key_prefix['api_key'] = None
# update parameters based on auth setting
client.update_params_for_auth(header_params, query_params, auth_settings)
self.assertEqual(header_params['api_key'], 'PREFIX=123456')
def test_select_header_accept(self):
accepts = ['APPLICATION/JSON', 'APPLICATION/XML']
accept = self.api_client.select_header_accept(accepts)

View File

@ -73,6 +73,7 @@ class PetApiTests(unittest.TestCase):
def setUp(self):
config = Configuration()
config.host = HOST
config.access_token = 'ACCESS_TOKEN'
self.api_client = petstore_api.ApiClient(config)
self.pet_api = petstore_api.PetApi(self.api_client)
self.setUpModels()
@ -115,6 +116,26 @@ class PetApiTests(unittest.TestCase):
resp.close()
resp.release_conn()
def test_config(self):
config = Configuration(host=HOST)
self.assertIsNotNone(config.get_host_settings())
self.assertEquals(config.get_basic_auth_token(),
urllib3.util.make_headers(basic_auth=":").get('authorization'))
self.assertEquals(len(config.auth_settings()), 1)
self.assertIn("petstore_auth", config.auth_settings().keys())
config.username = "user"
config.password = "password"
self.assertEquals(
config.get_basic_auth_token(),
urllib3.util.make_headers(basic_auth="user:password").get('authorization'))
self.assertEquals(len(config.auth_settings()), 2)
self.assertIn("petstore_auth", config.auth_settings().keys())
self.assertIn("http_basic_test", config.auth_settings().keys())
config.username = None
config.password = None
self.assertEquals(len(config.auth_settings()), 1)
self.assertIn("petstore_auth", config.auth_settings().keys())
def test_timeout(self):
mock_pool = MockPoolManager(self)
self.api_client.rest_client.pool_manager = mock_pool
@ -122,13 +143,13 @@ class PetApiTests(unittest.TestCase):
mock_pool.expect_request('POST', 'http://localhost/v2/pet',
body=json.dumps(self.api_client.sanitize_for_serialization(self.pet)),
headers={'Content-Type': 'application/json',
'Authorization': 'Bearer ',
'Authorization': 'Bearer ACCESS_TOKEN',
'User-Agent': 'OpenAPI-Generator/1.0.0/python'},
preload_content=True, timeout=TimeoutWithEqual(total=5))
mock_pool.expect_request('POST', 'http://localhost/v2/pet',
body=json.dumps(self.api_client.sanitize_for_serialization(self.pet)),
headers={'Content-Type': 'application/json',
'Authorization': 'Bearer ',
'Authorization': 'Bearer ACCESS_TOKEN',
'User-Agent': 'OpenAPI-Generator/1.0.0/python'},
preload_content=True, timeout=TimeoutWithEqual(connect=1, read=2))
@ -325,7 +346,7 @@ class PetApiTests(unittest.TestCase):
'Accept': 'application/json',
'Content-Type': 'multipart/form-data',
'User-Agent': 'OpenAPI-Generator/1.0.0/python',
'Authorization': 'Bearer '
'Authorization': 'Bearer ACCESS_TOKEN'
},
post_params=[
('files', ('1px_pic1.png', b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x00\x00\x00\x00:~\x9bU\x00\x00\x00\nIDATx\x9cc\xfa\x0f\x00\x01\x05\x01\x02\xcf\xa0.\xcd\x00\x00\x00\x00IEND\xaeB`\x82', 'image/png')),

View File

@ -515,9 +515,7 @@ class ApiClient(object):
for auth in auth_settings:
auth_setting = self.configuration.auth_settings().get(auth)
if auth_setting:
if not auth_setting['value']:
continue
elif auth_setting['in'] == 'cookie':
if auth_setting['in'] == 'cookie':
headers['Cookie'] = auth_setting['value']
elif auth_setting['in'] == 'header':
headers[auth_setting['key']] = auth_setting['value']

View File

@ -28,15 +28,38 @@ class Configuration(object):
Do not edit the class manually.
:param host: Base url
:param api_key: Dict to store API key(s)
:param api_key: Dict to store API key(s).
Each entry in the dict specifies an API key.
The dict key is the name of the security scheme in the OAS specification.
The dict value is the API key secret.
:param api_key_prefix: Dict to store API prefix (e.g. Bearer)
The dict key is the name of the security scheme in the OAS specification.
The dict value is an API key prefix when generating the auth data.
:param username: Username for HTTP basic authentication
:param password: Password for HTTP basic authentication
:Example:
Given the following security scheme in the OpenAPI specification:
components:
securitySchemes:
cookieAuth: # name for the security scheme
type: apiKey
in: cookie
name: JSESSIONID # cookie name
You can programmatically set the cookie:
conf = petstore_api.Configuration(
api_key={'cookieAuth': 'abc123'}
api_key_prefix={'cookieAuth': 'JSESSIONID'}
)
The following cookie will be added to the HTTP request:
Cookie: JSESSIONID abc123
"""
def __init__(self, host="http://petstore.swagger.io:80/v2",
api_key=None, api_key_prefix=None,
username="", password=""):
username=None, password=None):
"""Constructor
"""
self.host = host
@ -236,8 +259,14 @@ class Configuration(object):
:return: The token for basic HTTP authentication.
"""
username = ""
if self.username is not None:
username = self.username
password = ""
if self.password is not None:
password = self.password
return urllib3.util.make_headers(
basic_auth=self.username + ':' + self.password
basic_auth=username + ':' + password
).get('authorization')
def auth_settings(self):
@ -245,36 +274,36 @@ class Configuration(object):
:return: The Auth Settings information dict.
"""
return {
'api_key':
{
auth = {}
if 'api_key' in self.api_key:
auth['api_key'] = {
'type': 'api_key',
'in': 'header',
'key': 'api_key',
'value': self.get_api_key_with_prefix('api_key')
},
'api_key_query':
{
}
if 'api_key_query' in self.api_key:
auth['api_key_query'] = {
'type': 'api_key',
'in': 'query',
'key': 'api_key_query',
'value': self.get_api_key_with_prefix('api_key_query')
},
'http_basic_test':
{
}
if self.username is not None and self.password is not None:
auth['http_basic_test'] = {
'type': 'basic',
'in': 'header',
'key': 'Authorization',
'value': self.get_basic_auth_token()
},
'petstore_auth':
{
}
if self.access_token is not None:
auth['petstore_auth'] = {
'type': 'oauth2',
'in': 'header',
'key': 'Authorization',
'value': 'Bearer ' + self.access_token
},
}
return auth
def to_debug_report(self):
"""Gets the essential information for debugging.

View File

@ -513,9 +513,7 @@ class ApiClient(object):
for auth in auth_settings:
auth_setting = self.configuration.auth_settings().get(auth)
if auth_setting:
if not auth_setting['value']:
continue
elif auth_setting['in'] == 'cookie':
if auth_setting['in'] == 'cookie':
headers['Cookie'] = auth_setting['value']
elif auth_setting['in'] == 'header':
headers[auth_setting['key']] = auth_setting['value']

View File

@ -28,15 +28,38 @@ class Configuration(object):
Do not edit the class manually.
:param host: Base url
:param api_key: Dict to store API key(s)
:param api_key: Dict to store API key(s).
Each entry in the dict specifies an API key.
The dict key is the name of the security scheme in the OAS specification.
The dict value is the API key secret.
:param api_key_prefix: Dict to store API prefix (e.g. Bearer)
The dict key is the name of the security scheme in the OAS specification.
The dict value is an API key prefix when generating the auth data.
:param username: Username for HTTP basic authentication
:param password: Password for HTTP basic authentication
:Example:
Given the following security scheme in the OpenAPI specification:
components:
securitySchemes:
cookieAuth: # name for the security scheme
type: apiKey
in: cookie
name: JSESSIONID # cookie name
You can programmatically set the cookie:
conf = petstore_api.Configuration(
api_key={'cookieAuth': 'abc123'}
api_key_prefix={'cookieAuth': 'JSESSIONID'}
)
The following cookie will be added to the HTTP request:
Cookie: JSESSIONID abc123
"""
def __init__(self, host="http://petstore.swagger.io:80/v2",
api_key=None, api_key_prefix=None,
username="", password=""):
username=None, password=None):
"""Constructor
"""
self.host = host
@ -236,8 +259,14 @@ class Configuration(object):
:return: The token for basic HTTP authentication.
"""
username = ""
if self.username is not None:
username = self.username
password = ""
if self.password is not None:
password = self.password
return urllib3.util.make_headers(
basic_auth=self.username + ':' + self.password
basic_auth=username + ':' + password
).get('authorization')
def auth_settings(self):
@ -245,36 +274,36 @@ class Configuration(object):
:return: The Auth Settings information dict.
"""
return {
'api_key':
{
auth = {}
if 'api_key' in self.api_key:
auth['api_key'] = {
'type': 'api_key',
'in': 'header',
'key': 'api_key',
'value': self.get_api_key_with_prefix('api_key')
},
'api_key_query':
{
}
if 'api_key_query' in self.api_key:
auth['api_key_query'] = {
'type': 'api_key',
'in': 'query',
'key': 'api_key_query',
'value': self.get_api_key_with_prefix('api_key_query')
},
'http_basic_test':
{
}
if self.username is not None and self.password is not None:
auth['http_basic_test'] = {
'type': 'basic',
'in': 'header',
'key': 'Authorization',
'value': self.get_basic_auth_token()
},
'petstore_auth':
{
}
if self.access_token is not None:
auth['petstore_auth'] = {
'type': 'oauth2',
'in': 'header',
'key': 'Authorization',
'value': 'Bearer ' + self.access_token
},
}
return auth
def to_debug_report(self):
"""Gets the essential information for debugging.

View File

@ -57,6 +57,7 @@ class PetApiTests(unittest.TestCase):
def setUp(self):
config = Configuration()
config.host = HOST
config.access_token = 'ACCESS_TOKEN'
self.api_client = petstore_api.ApiClient(config)
self.pet_api = petstore_api.PetApi(self.api_client)
self.setUpModels()
@ -107,13 +108,13 @@ class PetApiTests(unittest.TestCase):
mock_pool.expect_request('POST', HOST + '/pet',
body=json.dumps(self.api_client.sanitize_for_serialization(self.pet)),
headers={'Content-Type': 'application/json',
'Authorization': 'Bearer ',
'Authorization': 'Bearer ACCESS_TOKEN',
'User-Agent': 'OpenAPI-Generator/1.0.0/python'},
preload_content=True, timeout=TimeoutWithEqual(total=5))
mock_pool.expect_request('POST', HOST + '/pet',
body=json.dumps(self.api_client.sanitize_for_serialization(self.pet)),
headers={'Content-Type': 'application/json',
'Authorization': 'Bearer ',
'Authorization': 'Bearer ACCESS_TOKEN',
'User-Agent': 'OpenAPI-Generator/1.0.0/python'},
preload_content=True, timeout=TimeoutWithEqual(connect=1, read=2))

View File

@ -513,9 +513,7 @@ class ApiClient(object):
for auth in auth_settings:
auth_setting = self.configuration.auth_settings().get(auth)
if auth_setting:
if not auth_setting['value']:
continue
elif auth_setting['in'] == 'cookie':
if auth_setting['in'] == 'cookie':
headers['Cookie'] = auth_setting['value']
elif auth_setting['in'] == 'header':
headers[auth_setting['key']] = auth_setting['value']

View File

@ -28,15 +28,38 @@ class Configuration(object):
Do not edit the class manually.
:param host: Base url
:param api_key: Dict to store API key(s)
:param api_key: Dict to store API key(s).
Each entry in the dict specifies an API key.
The dict key is the name of the security scheme in the OAS specification.
The dict value is the API key secret.
:param api_key_prefix: Dict to store API prefix (e.g. Bearer)
The dict key is the name of the security scheme in the OAS specification.
The dict value is an API key prefix when generating the auth data.
:param username: Username for HTTP basic authentication
:param password: Password for HTTP basic authentication
:Example:
Given the following security scheme in the OpenAPI specification:
components:
securitySchemes:
cookieAuth: # name for the security scheme
type: apiKey
in: cookie
name: JSESSIONID # cookie name
You can programmatically set the cookie:
conf = petstore_api.Configuration(
api_key={'cookieAuth': 'abc123'}
api_key_prefix={'cookieAuth': 'JSESSIONID'}
)
The following cookie will be added to the HTTP request:
Cookie: JSESSIONID abc123
"""
def __init__(self, host="http://petstore.swagger.io:80/v2",
api_key=None, api_key_prefix=None,
username="", password=""):
username=None, password=None):
"""Constructor
"""
self.host = host
@ -236,8 +259,14 @@ class Configuration(object):
:return: The token for basic HTTP authentication.
"""
username = ""
if self.username is not None:
username = self.username
password = ""
if self.password is not None:
password = self.password
return urllib3.util.make_headers(
basic_auth=self.username + ':' + self.password
basic_auth=username + ':' + password
).get('authorization')
def auth_settings(self):
@ -245,44 +274,44 @@ class Configuration(object):
:return: The Auth Settings information dict.
"""
return {
'api_key':
{
auth = {}
if 'api_key' in self.api_key:
auth['api_key'] = {
'type': 'api_key',
'in': 'header',
'key': 'api_key',
'value': self.get_api_key_with_prefix('api_key')
},
'api_key_query':
{
}
if 'api_key_query' in self.api_key:
auth['api_key_query'] = {
'type': 'api_key',
'in': 'query',
'key': 'api_key_query',
'value': self.get_api_key_with_prefix('api_key_query')
},
'bearer_test':
{
}
if self.access_token is not None:
auth['bearer_test'] = {
'type': 'bearer',
'in': 'header',
'format': 'JWT',
'key': 'Authorization',
'value': 'Bearer ' + self.access_token
},
'http_basic_test':
{
}
if self.username is not None and self.password is not None:
auth['http_basic_test'] = {
'type': 'basic',
'in': 'header',
'key': 'Authorization',
'value': self.get_basic_auth_token()
},
'petstore_auth':
{
}
if self.access_token is not None:
auth['petstore_auth'] = {
'type': 'oauth2',
'in': 'header',
'key': 'Authorization',
'value': 'Bearer ' + self.access_token
},
}
return auth
def to_debug_report(self):
"""Gets the essential information for debugging.