forked from loafle/openapi-generator-original
[feature][python] Support aliasing of API keys (#6469)
* [python] Support aliasing of API keys * Support for aliasing and prefix * Make more realistic usage * Regenerate * Document alias in generated code * Support override of aliased keys * Use diferent id and name for api keys * ensure up-to-date * Simple example without x-auth-id-alias * regenerate docs * Regenerate * Provide separate spec for x-auth-id-alias * Apply suggestions from code review * regenerated
This commit is contained in:
@@ -341,15 +341,16 @@ conf = petstore_api.Configuration(
|
||||
self.__logger_format = value
|
||||
self.logger_formatter = logging.Formatter(self.__logger_format)
|
||||
|
||||
def get_api_key_with_prefix(self, identifier):
|
||||
def get_api_key_with_prefix(self, identifier, alias=None):
|
||||
"""Gets API key (with prefix if set).
|
||||
|
||||
:param identifier: The identifier of apiKey.
|
||||
:param alias: The alternative identifier of apiKey.
|
||||
:return: The token for api key authentication.
|
||||
"""
|
||||
if self.refresh_api_key_hook is not None:
|
||||
self.refresh_api_key_hook(self)
|
||||
key = self.api_key.get(identifier)
|
||||
key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None)
|
||||
if key:
|
||||
prefix = self.api_key_prefix.get(identifier)
|
||||
if prefix:
|
||||
@@ -383,14 +384,18 @@ conf = petstore_api.Configuration(
|
||||
'type': 'api_key',
|
||||
'in': 'header',
|
||||
'key': 'api_key',
|
||||
'value': self.get_api_key_with_prefix('api_key')
|
||||
'value': self.get_api_key_with_prefix(
|
||||
'api_key',
|
||||
),
|
||||
}
|
||||
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')
|
||||
'value': self.get_api_key_with_prefix(
|
||||
'api_key_query',
|
||||
),
|
||||
}
|
||||
if self.username is not None and self.password is not None:
|
||||
auth['http_basic_test'] = {
|
||||
|
||||
Reference in New Issue
Block a user