Skip to content

Commit 2940d32

Browse files
authored
[PowerShell] Support ApiKeyPrefix (#19133)
* Support for ApiKeyPrefix * Additional files after build
1 parent 9948ed2 commit 2940d32

4 files changed

Lines changed: 25 additions & 5 deletions

File tree

modules/openapi-generator/src/main/resources/powershell/api.mustache

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,20 @@ function {{{vendorExtensions.x-powershell-method-name}}} {
177177
{{/bodyParam}}
178178
{{#authMethods}}
179179
{{#isApiKey}}
180+
if ($Configuration["ApiKeyPrefix"] -and $Configuration["ApiKeyPrefix"]["{{{keyParamName}}}"]) {
181+
$apiKeyPrefix = $Configuration["ApiKeyPrefix"]["{{{keyParamName}}}"]
182+
} else {
183+
$apiKeyPrefix = ""
184+
}
180185
{{#isKeyInHeader}}
181186
if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["{{{keyParamName}}}"]) {
182-
$LocalVarHeaderParameters['{{{keyParamName}}}'] = $Configuration["ApiKey"]["{{{keyParamName}}}"]
187+
$LocalVarHeaderParameters['{{{keyParamName}}}'] = $apiKeyPrefix + $Configuration["ApiKey"]["{{{keyParamName}}}"]
183188
Write-Verbose ("Using API key '{{{keyParamName}}}' in the header for authentication in {0}" -f $MyInvocation.MyCommand)
184189
}
185190
{{/isKeyInHeader}}
186191
{{#isKeyInQuery}}
187192
if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["{{{keyParamName}}}"]) {
188-
$LocalVarQueryParameters['{{{keyParamName}}}'] = $Configuration["ApiKey"]["{{{keyParamName}}}"]
193+
$LocalVarQueryParameters['{{{keyParamName}}}'] = $apiKeyPrefix + $Configuration["ApiKey"]["{{{keyParamName}}}"]
189194
Write-Verbose ("Using API key `{{{keyParamName}}}` in the URL query for authentication in {0}" -f $MyInvocation.MyCommand)
190195
}
191196
{{/isKeyInQuery}}

samples/client/petstore/powershell/src/PSPetstore/Api/PSFakeClassnameTags123Api.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,13 @@ function Test-PSClassname {
6363

6464
$LocalVarBodyParameter = $Client | ConvertTo-Json -Depth 100
6565

66+
if ($Configuration["ApiKeyPrefix"] -and $Configuration["ApiKeyPrefix"]["api_key_query_name"]) {
67+
$apiKeyPrefix = $Configuration["ApiKeyPrefix"]["api_key_query_name"]
68+
} else {
69+
$apiKeyPrefix = ""
70+
}
6671
if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["api_key_query_name"]) {
67-
$LocalVarQueryParameters['api_key_query_name'] = $Configuration["ApiKey"]["api_key_query_name"]
72+
$LocalVarQueryParameters['api_key_query_name'] = $apiKeyPrefix + $Configuration["ApiKey"]["api_key_query_name"]
6873
Write-Verbose ("Using API key `api_key_query_name` in the URL query for authentication in {0}" -f $MyInvocation.MyCommand)
6974
}
7075

samples/client/petstore/powershell/src/PSPetstore/Api/PSPetApi.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,13 @@ function Get-PSPetById {
405405
}
406406
$LocalVarUri = $LocalVarUri.replace('{petId}', [System.Web.HTTPUtility]::UrlEncode($PetId))
407407

408+
if ($Configuration["ApiKeyPrefix"] -and $Configuration["ApiKeyPrefix"]["api_key_name"]) {
409+
$apiKeyPrefix = $Configuration["ApiKeyPrefix"]["api_key_name"]
410+
} else {
411+
$apiKeyPrefix = ""
412+
}
408413
if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["api_key_name"]) {
409-
$LocalVarHeaderParameters['api_key_name'] = $Configuration["ApiKey"]["api_key_name"]
414+
$LocalVarHeaderParameters['api_key_name'] = $apiKeyPrefix + $Configuration["ApiKey"]["api_key_name"]
410415
Write-Verbose ("Using API key 'api_key_name' in the header for authentication in {0}" -f $MyInvocation.MyCommand)
411416
}
412417

samples/client/petstore/powershell/src/PSPetstore/Api/PSStoreApi.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,13 @@ function Get-PSInventory {
118118

119119
$LocalVarUri = '/store/inventory'
120120

121+
if ($Configuration["ApiKeyPrefix"] -and $Configuration["ApiKeyPrefix"]["api_key_name"]) {
122+
$apiKeyPrefix = $Configuration["ApiKeyPrefix"]["api_key_name"]
123+
} else {
124+
$apiKeyPrefix = ""
125+
}
121126
if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["api_key_name"]) {
122-
$LocalVarHeaderParameters['api_key_name'] = $Configuration["ApiKey"]["api_key_name"]
127+
$LocalVarHeaderParameters['api_key_name'] = $apiKeyPrefix + $Configuration["ApiKey"]["api_key_name"]
123128
Write-Verbose ("Using API key 'api_key_name' in the header for authentication in {0}" -f $MyInvocation.MyCommand)
124129
}
125130

0 commit comments

Comments
 (0)