From 2940d3219cb7bdfd072315962680e5fd6ec7e7e1 Mon Sep 17 00:00:00 2001 From: condorcorde <49915099+condorcorde@users.noreply.github.com> Date: Thu, 11 Jul 2024 08:38:16 +0200 Subject: [PATCH] [PowerShell] Support ApiKeyPrefix (#19133) * Support for ApiKeyPrefix * Additional files after build --- .../src/main/resources/powershell/api.mustache | 9 +++++++-- .../src/PSPetstore/Api/PSFakeClassnameTags123Api.ps1 | 7 ++++++- .../petstore/powershell/src/PSPetstore/Api/PSPetApi.ps1 | 7 ++++++- .../powershell/src/PSPetstore/Api/PSStoreApi.ps1 | 7 ++++++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/powershell/api.mustache b/modules/openapi-generator/src/main/resources/powershell/api.mustache index 79d632682cf..c13395de842 100644 --- a/modules/openapi-generator/src/main/resources/powershell/api.mustache +++ b/modules/openapi-generator/src/main/resources/powershell/api.mustache @@ -177,15 +177,20 @@ function {{{vendorExtensions.x-powershell-method-name}}} { {{/bodyParam}} {{#authMethods}} {{#isApiKey}} + if ($Configuration["ApiKeyPrefix"] -and $Configuration["ApiKeyPrefix"]["{{{keyParamName}}}"]) { + $apiKeyPrefix = $Configuration["ApiKeyPrefix"]["{{{keyParamName}}}"] + } else { + $apiKeyPrefix = "" + } {{#isKeyInHeader}} if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["{{{keyParamName}}}"]) { - $LocalVarHeaderParameters['{{{keyParamName}}}'] = $Configuration["ApiKey"]["{{{keyParamName}}}"] + $LocalVarHeaderParameters['{{{keyParamName}}}'] = $apiKeyPrefix + $Configuration["ApiKey"]["{{{keyParamName}}}"] Write-Verbose ("Using API key '{{{keyParamName}}}' in the header for authentication in {0}" -f $MyInvocation.MyCommand) } {{/isKeyInHeader}} {{#isKeyInQuery}} if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["{{{keyParamName}}}"]) { - $LocalVarQueryParameters['{{{keyParamName}}}'] = $Configuration["ApiKey"]["{{{keyParamName}}}"] + $LocalVarQueryParameters['{{{keyParamName}}}'] = $apiKeyPrefix + $Configuration["ApiKey"]["{{{keyParamName}}}"] Write-Verbose ("Using API key `{{{keyParamName}}}` in the URL query for authentication in {0}" -f $MyInvocation.MyCommand) } {{/isKeyInQuery}} diff --git a/samples/client/petstore/powershell/src/PSPetstore/Api/PSFakeClassnameTags123Api.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Api/PSFakeClassnameTags123Api.ps1 index 0ffb6cd7f3b..88d502e95c9 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/Api/PSFakeClassnameTags123Api.ps1 +++ b/samples/client/petstore/powershell/src/PSPetstore/Api/PSFakeClassnameTags123Api.ps1 @@ -63,8 +63,13 @@ function Test-PSClassname { $LocalVarBodyParameter = $Client | ConvertTo-Json -Depth 100 + if ($Configuration["ApiKeyPrefix"] -and $Configuration["ApiKeyPrefix"]["api_key_query_name"]) { + $apiKeyPrefix = $Configuration["ApiKeyPrefix"]["api_key_query_name"] + } else { + $apiKeyPrefix = "" + } if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["api_key_query_name"]) { - $LocalVarQueryParameters['api_key_query_name'] = $Configuration["ApiKey"]["api_key_query_name"] + $LocalVarQueryParameters['api_key_query_name'] = $apiKeyPrefix + $Configuration["ApiKey"]["api_key_query_name"] Write-Verbose ("Using API key `api_key_query_name` in the URL query for authentication in {0}" -f $MyInvocation.MyCommand) } diff --git a/samples/client/petstore/powershell/src/PSPetstore/Api/PSPetApi.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Api/PSPetApi.ps1 index e28ffcabca0..863d7864a1a 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/Api/PSPetApi.ps1 +++ b/samples/client/petstore/powershell/src/PSPetstore/Api/PSPetApi.ps1 @@ -405,8 +405,13 @@ function Get-PSPetById { } $LocalVarUri = $LocalVarUri.replace('{petId}', [System.Web.HTTPUtility]::UrlEncode($PetId)) + if ($Configuration["ApiKeyPrefix"] -and $Configuration["ApiKeyPrefix"]["api_key_name"]) { + $apiKeyPrefix = $Configuration["ApiKeyPrefix"]["api_key_name"] + } else { + $apiKeyPrefix = "" + } if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["api_key_name"]) { - $LocalVarHeaderParameters['api_key_name'] = $Configuration["ApiKey"]["api_key_name"] + $LocalVarHeaderParameters['api_key_name'] = $apiKeyPrefix + $Configuration["ApiKey"]["api_key_name"] Write-Verbose ("Using API key 'api_key_name' in the header for authentication in {0}" -f $MyInvocation.MyCommand) } diff --git a/samples/client/petstore/powershell/src/PSPetstore/Api/PSStoreApi.ps1 b/samples/client/petstore/powershell/src/PSPetstore/Api/PSStoreApi.ps1 index 40fd1e0c64f..6061c8c56c1 100644 --- a/samples/client/petstore/powershell/src/PSPetstore/Api/PSStoreApi.ps1 +++ b/samples/client/petstore/powershell/src/PSPetstore/Api/PSStoreApi.ps1 @@ -118,8 +118,13 @@ function Get-PSInventory { $LocalVarUri = '/store/inventory' + if ($Configuration["ApiKeyPrefix"] -and $Configuration["ApiKeyPrefix"]["api_key_name"]) { + $apiKeyPrefix = $Configuration["ApiKeyPrefix"]["api_key_name"] + } else { + $apiKeyPrefix = "" + } if ($Configuration["ApiKey"] -and $Configuration["ApiKey"]["api_key_name"]) { - $LocalVarHeaderParameters['api_key_name'] = $Configuration["ApiKey"]["api_key_name"] + $LocalVarHeaderParameters['api_key_name'] = $apiKeyPrefix + $Configuration["ApiKey"]["api_key_name"] Write-Verbose ("Using API key 'api_key_name' in the header for authentication in {0}" -f $MyInvocation.MyCommand) }