Skip to content

Commit 6b4a752

Browse files
committed
Allow aliasing of auth keys
1 parent caf5264 commit 6b4a752

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

modules/openapi-generator/src/main/resources/ruby-client/README.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ require '{{{gemName}}}'
7272
# Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}}
7373
config.access_token = 'YOUR_BEARER_TOKEN'{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}}
7474
# Configure API key authorization: {{{name}}}
75-
config.api_key['{{{keyParamName}}}'] = 'YOUR API KEY'
75+
config.api_key['{{{name}}}'] = 'YOUR API KEY'
7676
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
77-
#config.api_key_prefix['{{{keyParamName}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}}
77+
# config.api_key_prefix['{{{name}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}}
7878
# Configure OAuth2 access token for authorization: {{{name}}}
7979
config.access_token = 'YOUR ACCESS TOKEN'{{/isOAuth}}
8080
{{/authMethods}}end

modules/openapi-generator/src/main/resources/ruby-client/api_client.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ module {{moduleName}}
182182
case auth_setting[:in]
183183
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
184184
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
185-
else fail ArgumentError, 'Authentication token must be in `query` of `header`'
185+
else fail ArgumentError, 'Authentication token must be in `query` or `header`'
186186
end
187187
end
188188
end

modules/openapi-generator/src/main/resources/ruby-client/api_doc.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ require '{{{gemName}}}'
3737
# Configure Bearer authorization{{#bearerFormat}} ({{{.}}}){{/bearerFormat}}: {{{name}}}
3838
config.access_token = 'YOUR_BEARER_TOKEN'{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}}
3939
# Configure API key authorization: {{{name}}}
40-
config.api_key['{{{keyParamName}}}'] = 'YOUR API KEY'
40+
config.api_key['{{{name}}}'] = 'YOUR API KEY'
4141
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
42-
# config.api_key_prefix['{{{keyParamName}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}}
42+
# config.api_key_prefix['{{{name}}}'] = 'Bearer'{{/isApiKey}}{{#isOAuth}}
4343
# Configure OAuth2 access token for authorization: {{{name}}}
4444
config.access_token = 'YOUR ACCESS TOKEN'{{/isOAuth}}
4545
{{/authMethods}}end

modules/openapi-generator/src/main/resources/ruby-client/configuration.mustache

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,13 @@ module {{moduleName}}
169169

170170
# Gets API key (with prefix if set).
171171
# @param [String] param_name the parameter name of API key auth
172-
def api_key_with_prefix(param_name)
172+
def api_key_with_prefix(param_name, param_alias = nil)
173+
key = @api_key[param_name]
174+
key = @api_key.fetch(param_alias, key) unless param_alias.nil?
173175
if @api_key_prefix[param_name]
174-
"#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
176+
"#{@api_key_prefix[param_name]} #{key}"
175177
else
176-
@api_key[param_name]
178+
key
177179
end
178180
end
179181

@@ -192,7 +194,7 @@ module {{moduleName}}
192194
type: 'api_key',
193195
in: {{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{#isKeyInQuery}}'query'{{/isKeyInQuery}},
194196
key: '{{keyParamName}}',
195-
value: api_key_with_prefix('{{keyParamName}}')
197+
value: api_key_with_prefix('{{name}}'{{#vendorExtensions.x-auth-id-alias}}, '{{.}}'{{/vendorExtensions.x-auth-id-alias}})
196198
},
197199
{{/isApiKey}}
198200
{{#isBasic}}

0 commit comments

Comments
 (0)