Add hasQueryParamsOrAuth to reflect apiKey in query (#10582)

Compilation fails in generated typescript-angular client when an
`apiKey` is passed in query due to an uninitialised variable.

This change adds `getHasQueryParamsOrAuth()` to reflect if there's at
least one query parameter or passing API keys in query in the
`hasQueryParamsOrAuth` template variable.
This commit is contained in:
yongmingl
2021-10-14 14:16:22 +08:00
committed by GitHub
parent 2bd2c23115
commit b0e2ab67a6
2 changed files with 13 additions and 4 deletions

View File

@@ -87,6 +87,15 @@ public class CodegenOperation {
return nonempty(queryParams);
}
/**
* Check if there's at least one query parameter or passing API keys in query
*
* @return true if query parameter exists or passing API keys in query, false otherwise
*/
public boolean getHasQueryParamsOrAuth() {
return getHasQueryParams() || (authMethods != null && authMethods.stream().anyMatch(authMethod -> authMethod.isKeyInQuery));
}
/**
* Check if there's at least one header parameter
*

View File

@@ -178,7 +178,7 @@ export class {{classname}} {
{{/required}}
{{/allParams}}
{{#hasQueryParams}}
{{#hasQueryParamsOrAuth}}
let localVarQueryParameters = new HttpParams({encoder: this.encoder});
{{#queryParams}}
{{#isArray}}
@@ -209,7 +209,7 @@ export class {{classname}} {
{{/isArray}}
{{/queryParams}}
{{/hasQueryParams}}
{{/hasQueryParamsOrAuth}}
let localVarHeaders = this.defaultHeaders;
{{#headerParams}}
{{#isArray}}
@@ -359,9 +359,9 @@ export class {{classname}} {
{{#httpContextInOptions}}
context: localVarHttpContext,
{{/httpContextInOptions}}
{{#hasQueryParams}}
{{#hasQueryParamsOrAuth}}
params: localVarQueryParameters,
{{/hasQueryParams}}
{{/hasQueryParamsOrAuth}}
{{#isResponseFile}}
responseType: "blob",
{{/isResponseFile}}