[TypeScript Fetch] Optional URL query parameters not sent anymore (#6032)

* [TypeScript Fetch] Optional URL query parameters not sent anymore
This prevents empty URL parameters from being sent, e.g. http://some-api/endpoint?param=SOMETHING?v= will now be http://some-api/endpoint?param=SOMETHING.
Solution suggested by @TiFu. Fixes #6003.

* Fixed indentation

* fixed missing semicolon
This commit is contained in:
roberterdin 2017-07-22 19:12:41 +01:00 committed by wing328
parent a4d67d9115
commit e710405778
3 changed files with 22 additions and 16 deletions

View File

@ -98,11 +98,12 @@ export const {{classname}}FetchParamCreator = {
.replace(`{${"{{baseName}}"}}`, `${ params["{{paramName}}"] }`){{/pathParams}}; .replace(`{${"{{baseName}}"}}`, `${ params["{{paramName}}"] }`){{/pathParams}};
let urlObj = url.parse(baseUrl, true); let urlObj = url.parse(baseUrl, true);
{{#hasQueryParams}} {{#hasQueryParams}}
urlObj.query = {{#supportsES6}}Object.{{/supportsES6}}assign({}, urlObj.query, { urlObj.query = {{#supportsES6}}Object.{{/supportsES6}}assign({}, urlObj.query);
{{#queryParams}} {{#queryParams}}
"{{baseName}}": params["{{paramName}}"], if (params["{{paramName}}"] !== undefined) {
urlObj.query["{{baseName}}"] = params["{{paramName}}"];
}
{{/queryParams}} {{/queryParams}}
});
{{/hasQueryParams}} {{/hasQueryParams}}
let fetchOptions: RequestInit = {{#supportsES6}}Object.{{/supportsES6}}assign({}, { method: "{{httpMethod}}" }, options); let fetchOptions: RequestInit = {{#supportsES6}}Object.{{/supportsES6}}assign({}, { method: "{{httpMethod}}" }, options);

View File

@ -71,7 +71,7 @@ export const FakeApiFetchParamCreator = {
"test code inject */ ' " =end -- \r\n \n \r": params["test code inject * ' " =end rn n r"], "test code inject */ ' " =end -- \r\n \n \r": params["test code inject * ' " =end rn n r"],
}); });
if (contentTypeHeader) { if (contentTypeHeader) {
fetchOptions.headers = contentTypeHeader; fetchOptions.headers = assign({}, contentTypeHeader, fetchOptions.headers);
} }
return { return {

View File

@ -200,9 +200,10 @@ export const PetApiFetchParamCreator = {
} }
const baseUrl = `/pet/findByStatus`; const baseUrl = `/pet/findByStatus`;
let urlObj = url.parse(baseUrl, true); let urlObj = url.parse(baseUrl, true);
urlObj.query = assign({}, urlObj.query, { urlObj.query = assign({}, urlObj.query);
"status": params["status"], if (params["status"] !== undefined) {
}); urlObj.query["status"] = params["status"];
}
let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); let fetchOptions: RequestInit = assign({}, { method: "GET" }, options);
let contentTypeHeader: Dictionary<string> = {}; let contentTypeHeader: Dictionary<string> = {};
@ -234,9 +235,10 @@ export const PetApiFetchParamCreator = {
} }
const baseUrl = `/pet/findByTags`; const baseUrl = `/pet/findByTags`;
let urlObj = url.parse(baseUrl, true); let urlObj = url.parse(baseUrl, true);
urlObj.query = assign({}, urlObj.query, { urlObj.query = assign({}, urlObj.query);
"tags": params["tags"], if (params["tags"] !== undefined) {
}); urlObj.query["tags"] = params["tags"];
}
let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); let fetchOptions: RequestInit = assign({}, { method: "GET" }, options);
let contentTypeHeader: Dictionary<string> = {}; let contentTypeHeader: Dictionary<string> = {};
@ -1116,10 +1118,13 @@ export const UserApiFetchParamCreator = {
} }
const baseUrl = `/user/login`; const baseUrl = `/user/login`;
let urlObj = url.parse(baseUrl, true); let urlObj = url.parse(baseUrl, true);
urlObj.query = assign({}, urlObj.query, { urlObj.query = assign({}, urlObj.query);
"username": params["username"], if (params["username"] !== undefined) {
"password": params["password"], urlObj.query["username"] = params["username"];
}); }
if (params["password"] !== undefined) {
urlObj.query["password"] = params["password"];
}
let fetchOptions: RequestInit = assign({}, { method: "GET" }, options); let fetchOptions: RequestInit = assign({}, { method: "GET" }, options);
let contentTypeHeader: Dictionary<string> = {}; let contentTypeHeader: Dictionary<string> = {};