diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/api.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/api.mustache index deb227d02f..ad6e13e69b 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/api.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-Fetch/api.mustache @@ -98,11 +98,12 @@ export const {{classname}}FetchParamCreator = { .replace(`{${"{{baseName}}"}}`, `${ params["{{paramName}}"] }`){{/pathParams}}; let urlObj = url.parse(baseUrl, true); {{#hasQueryParams}} - urlObj.query = {{#supportsES6}}Object.{{/supportsES6}}assign({}, urlObj.query, { - {{#queryParams}} - "{{baseName}}": params["{{paramName}}"], - {{/queryParams}} - }); + urlObj.query = {{#supportsES6}}Object.{{/supportsES6}}assign({}, urlObj.query); + {{#queryParams}} + if (params["{{paramName}}"] !== undefined) { + urlObj.query["{{baseName}}"] = params["{{paramName}}"]; + } + {{/queryParams}} {{/hasQueryParams}} let fetchOptions: RequestInit = {{#supportsES6}}Object.{{/supportsES6}}assign({}, { method: "{{httpMethod}}" }, options); diff --git a/samples/client/petstore-security-test/typescript-fetch/api.ts b/samples/client/petstore-security-test/typescript-fetch/api.ts index 4fe998131e..d4b0fbf3e8 100644 --- a/samples/client/petstore-security-test/typescript-fetch/api.ts +++ b/samples/client/petstore-security-test/typescript-fetch/api.ts @@ -71,7 +71,7 @@ export const FakeApiFetchParamCreator = { "test code inject */ ' " =end -- \r\n \n \r": params["test code inject * ' " =end rn n r"], }); if (contentTypeHeader) { - fetchOptions.headers = contentTypeHeader; + fetchOptions.headers = assign({}, contentTypeHeader, fetchOptions.headers); } return { diff --git a/samples/client/petstore/typescript-fetch/builds/default/api.ts b/samples/client/petstore/typescript-fetch/builds/default/api.ts index ffd2fc8ecc..378f912d8a 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/api.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/api.ts @@ -200,9 +200,10 @@ export const PetApiFetchParamCreator = { } const baseUrl = `/pet/findByStatus`; let urlObj = url.parse(baseUrl, true); - urlObj.query = assign({}, urlObj.query, { - "status": params["status"], - }); + urlObj.query = assign({}, urlObj.query); + if (params["status"] !== undefined) { + urlObj.query["status"] = params["status"]; + } let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); let contentTypeHeader: Dictionary = {}; @@ -234,9 +235,10 @@ export const PetApiFetchParamCreator = { } const baseUrl = `/pet/findByTags`; let urlObj = url.parse(baseUrl, true); - urlObj.query = assign({}, urlObj.query, { - "tags": params["tags"], - }); + urlObj.query = assign({}, urlObj.query); + if (params["tags"] !== undefined) { + urlObj.query["tags"] = params["tags"]; + } let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); let contentTypeHeader: Dictionary = {}; @@ -1116,10 +1118,13 @@ export const UserApiFetchParamCreator = { } const baseUrl = `/user/login`; let urlObj = url.parse(baseUrl, true); - urlObj.query = assign({}, urlObj.query, { - "username": params["username"], - "password": params["password"], - }); + urlObj.query = assign({}, urlObj.query); + if (params["username"] !== undefined) { + urlObj.query["username"] = params["username"]; + } + if (params["password"] !== undefined) { + urlObj.query["password"] = params["password"]; + } let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); let contentTypeHeader: Dictionary = {};