[BUG] Angular-Typescript - Uninitalized Authorization queryParameters
Created by: bruceharrison1984
Description
Output from Angular-Typescript generator cannot be packaged/compiled because Authorization query parameter variable is not initialized.
public getKeyResult(id: number, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling getKeyResult.');
}
let headers = this.defaultHeaders;
// authentication (apiKeyHeader) required
if (this.configuration.apiKeys && this.configuration.apiKeys["Ocp-Apim-Subscription-Key"]) {
headers = headers.set('Ocp-Apim-Subscription-Key', this.configuration.apiKeys["Ocp-Apim-Subscription-Key"]);
}
// authentication (apiKeyQuery) required
if (this.configuration.apiKeys && this.configuration.apiKeys["subscription-key"]) {
queryParameters = queryParameters.set('subscription-key', this.configuration.apiKeys["subscription-key"]);
^^^^^^^^^^^^^^^ error is here
}
openapi-generator version
4.1.0
OpenAPI declaration file content or url
OpenAPI template is generated from an Azure Api Management Gateway. This condition only occurs when an API is not associated with a Product, and thus is considered not published
.
{
"swagger": "2.0",
"info": {
"title": "Swashbuckle",
"version": "1.0",
"description": "Swagger document by Swashbuckle"
},
"host": "example-api.net",
"basePath": "",
"schemes": [
"https"
],
"securityDefinitions": {
"apiKeyHeader": {
"type": "apiKey",
"name": "Ocp-Apim-Subscription-Key",
"in": "header"
},
"apiKeyQuery": {
"type": "apiKey",
"name": "subscription-key",
"in": "query"
}
},
"security": [
{
"apiKeyHeader": []
},
{
"apiKeyQuery": []
}
],
...
Command line used for generation
$libraryName="example-api"
$libraryVersion="0.0.1"
$angularVersion="7"
$ouputDir="./client"
$generatorVersion="4.1.0"
$swaggerFile="c:\development\example-api.json"
Write-Host "Download Swagger Doc from Azure API Management"
$ApiMgmtContext = New-AzApiManagementContext -ResourceGroupName "example-api" -ServiceName "example-api"
Export-AzApiManagementApi -Context $ApiMgmtContext `
-ApiId "example-api" `
-SpecificationFormat "Swagger" `
-SaveAs $swaggerFile
Write-Host "Download OpenAPI generator java library"
Invoke-WebRequest -OutFile openapi-generator-cli.jar "http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/$generatorVersion/openapi-generator-cli-$generatorVersion.jar"
Write-Host "generate example-api angular client libraries ($libraryVersion)"
java -jar openapi-generator-cli.jar generate `
-i $swaggerFile `
-g typescript-angular `
--additional-properties ngVersion=$angularVersion,npmName=$libraryName,npmVersion=$libraryVersion `
-o "$ouputDir"
Steps to reproduce
Generate Angular-Typescript client from a swagger doc that has a query parameter securityDefinition. Then do npm install
and npm run build
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/1535