Skip to content

Commit 25fbf67

Browse files
js2meprog13
andauthored
Release 8.0.3 (#230)
* fix: incorrect handler for primitive parameters (#229) * fix: incorrect handler for primitive parameters * fix: incorrect handler for primitive parameters 2 * fix: incorrect handler for primitive parameters 3 * bump: up version to 8.0.3 Co-authored-by: Aleksey Gavrilov <[email protected]>
1 parent 2232004 commit 25fbf67

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# next release
22

3+
4+
# 8.0.3
5+
6+
- Fixes encoding array query params in `fetch` http templates (thanks @prog13)
7+
38
# 8.0.2
49

510
Fixes:

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swagger-typescript-api",
3-
"version": "8.0.2",
3+
"version": "8.0.3",
44
"description": "Generate typescript/javascript api from swagger schema",
55
"scripts": {
66
"cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",

templates/base/http-clients/fetch-http-client.eta

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,28 @@ export class HttpClient<SecurityDataType = unknown> {
6868
public setSecurityData = (data: SecurityDataType | null) => {
6969
this.securityData = data;
7070
}
71+
72+
private addQueryParam(query: QueryParamsType, key: string) {
73+
const value = query[key];
74+
const encodedKey = encodeURIComponent(key);
75+
return `${encodedKey}=${encodeURIComponent(
76+
typeof value === 'number' ? value : `${value}`,
77+
)}`;
78+
}
7179

7280
private addArrayQueryParam(query: QueryParamsType, key: string) {
7381
const value = query[key];
74-
const encodedKey = encodeURIComponent(key);
75-
return `${value.map((val: any) => `${encodedKey}=${encodeURIComponent(typeof val === "number" ? val : `${val}`)}`).join('&')}`;
82+
return `${value.map(this.addQueryParam).join('&')}`;
7683
}
7784

7885
protected toQueryString(rawQuery?: QueryParamsType): string {
7986
const query = rawQuery || {};
8087
const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]);
8188
return keys
8289
.map((key) =>
83-
typeof query[key] === "object" && !Array.isArray(query[key])
84-
? this.toQueryString(query[key] as QueryParamsType)
85-
: this.addArrayQueryParam(query, key),
90+
Array.isArray(query[key])
91+
? this.addArrayQueryParam(query, key)
92+
: this.addQueryParam(query, key),
8693
)
8794
.join("&");
8895
}

0 commit comments

Comments
 (0)