From 7beebe693ac426d91a29941add30ba7f068ef48e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Neto?= Date: Wed, 14 Sep 2022 16:39:34 +0200 Subject: [PATCH] Fix applying optional query parameters (#13419) * add query params * update samples --- .../Javascript/libraries/apollo/ApiClient.mustache | 6 ++++-- samples/client/petstore/javascript-apollo/src/ApiClient.js | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Javascript/libraries/apollo/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Javascript/libraries/apollo/ApiClient.mustache index 44d7eb3ded0..4f84ef57bdc 100644 --- a/modules/openapi-generator/src/main/resources/Javascript/libraries/apollo/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Javascript/libraries/apollo/ApiClient.mustache @@ -185,10 +185,12 @@ export default class ApiClient extends RESTDataSource { queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts, returnType, requestInit) { + var normalizedQueryParams = this.normalizeParams(queryParams); + var parameterizedPath = this.parametrizePath(path, pathParams); var fetchOptions = { headers: headerParams, - params: queryParams + params: normalizedQueryParams }; this.applyAuthOptions(fetchOptions, authNames); @@ -210,7 +212,7 @@ export default class ApiClient extends RESTDataSource { var httpMethodFn = httpMethod.toLowerCase(); if (httpMethodFn == 'get' || httpMethodFn == 'delete') { - response = await this[httpMethodFn](parameterizedPath, [], requestInit); + response = await this[httpMethodFn](parameterizedPath, normalizedQueryParams, requestInit); } else { response = await this[httpMethodFn](parameterizedPath, body, requestInit) } diff --git a/samples/client/petstore/javascript-apollo/src/ApiClient.js b/samples/client/petstore/javascript-apollo/src/ApiClient.js index f9d78afa472..97d65f916f3 100644 --- a/samples/client/petstore/javascript-apollo/src/ApiClient.js +++ b/samples/client/petstore/javascript-apollo/src/ApiClient.js @@ -186,10 +186,12 @@ export default class ApiClient extends RESTDataSource { queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts, returnType, requestInit) { + var normalizedQueryParams = this.normalizeParams(queryParams); + var parameterizedPath = this.parametrizePath(path, pathParams); var fetchOptions = { headers: headerParams, - params: queryParams + params: normalizedQueryParams }; this.applyAuthOptions(fetchOptions, authNames); @@ -211,7 +213,7 @@ export default class ApiClient extends RESTDataSource { var httpMethodFn = httpMethod.toLowerCase(); if (httpMethodFn == 'get' || httpMethodFn == 'delete') { - response = await this[httpMethodFn](parameterizedPath, [], requestInit); + response = await this[httpMethodFn](parameterizedPath, normalizedQueryParams, requestInit); } else { response = await this[httpMethodFn](parameterizedPath, body, requestInit) }