mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 10:58:55 +00:00
[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:
parent
a4d67d9115
commit
e710405778
@ -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);
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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<string> = {};
|
||||
@ -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<string> = {};
|
||||
@ -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<string> = {};
|
||||
|
Loading…
Reference in New Issue
Block a user