Skip to content

Commit

Permalink
Release 8.0.3 (#230)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
js2me and prog13 authored Apr 8, 2021
1 parent 2232004 commit 25fbf67
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# next release


# 8.0.3

- Fixes encoding array query params in `fetch` http templates (thanks @prog13)

# 8.0.2

Fixes:
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swagger-typescript-api",
"version": "8.0.2",
"version": "8.0.3",
"description": "Generate typescript/javascript api from swagger schema",
"scripts": {
"cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",
Expand Down
17 changes: 12 additions & 5 deletions templates/base/http-clients/fetch-http-client.eta
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,28 @@ export class HttpClient<SecurityDataType = unknown> {
public setSecurityData = (data: SecurityDataType | null) => {
this.securityData = data;
}

private addQueryParam(query: QueryParamsType, key: string) {
const value = query[key];
const encodedKey = encodeURIComponent(key);
return `${encodedKey}=${encodeURIComponent(
typeof value === 'number' ? value : `${value}`,
)}`;
}

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

protected toQueryString(rawQuery?: QueryParamsType): string {
const query = rawQuery || {};
const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]);
return keys
.map((key) =>
typeof query[key] === "object" && !Array.isArray(query[key])
? this.toQueryString(query[key] as QueryParamsType)
: this.addArrayQueryParam(query, key),
Array.isArray(query[key])
? this.addArrayQueryParam(query, key)
: this.addQueryParam(query, key),
)
.join("&");
}
Expand Down

0 comments on commit 25fbf67

Please sign in to comment.