Skip to content

Commit 31b7126

Browse files
authored
refactor: url serialization for string array params (#26)
1 parent 7844dba commit 31b7126

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

CONTRIBUTING.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@ If you have updated the generated chat code you'll have to fix the following iss
5454

5555
- Add `/** @ts-expect-error */ ` (make sure to use this exact comment format otherwise they will be missing from `d.ts` files) for imports for `ImageSizeRequest`, `OnlyUserIDRequest` in the `gen/chat/FilesApi.ts` and `gen/chat/MessagesApi.ts` files
5656
- Add `/** @ts-expect-error */ ` (make sure to use this exact comment format otherwise they will be missing from `d.ts` files) for duplicate exports in `gen/chat/index.ts`
57-
- Fix the query param serizalization in the `gen/chat/MessagesApi.ts` file's `getManyMessagesRaw` function. This is the correct serialization:
58-
59-
```typescript
60-
if (requestParameters.ids) {
61-
queryParameters["ids"] = requestParameters.ids.join(",");
62-
}
63-
```
6457

6558
### Validate that the generated code works
6659

src/StreamClient.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -517,18 +517,18 @@ export class StreamClient {
517517
queryParamsStringify: (params: HTTPQuery) => {
518518
const newParams = [];
519519
for (const k in params) {
520-
if (Array.isArray(params[k]) || typeof params[k] === 'object') {
521-
newParams.push(
522-
`${k}=${encodeURIComponent(JSON.stringify(params[k]))}`,
523-
);
520+
const param = params[k];
521+
if (Array.isArray(param)) {
522+
newParams.push(`${k}=${encodeURIComponent(param.join(','))}`);
523+
} else if (typeof param === 'object') {
524+
newParams.push(`${k}=${encodeURIComponent(JSON.stringify(param))}`);
524525
} else {
525-
const value = params[k];
526526
if (
527-
typeof value === 'string' ||
528-
typeof value === 'number' ||
529-
typeof value === 'boolean'
527+
typeof param === 'string' ||
528+
typeof param === 'number' ||
529+
typeof param === 'boolean'
530530
) {
531-
newParams.push(`${k}=${encodeURIComponent(value)}`);
531+
newParams.push(`${k}=${encodeURIComponent(param)}`);
532532
}
533533
}
534534
}

src/gen/chat/apis/MessagesApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ export class MessagesApi extends runtime.BaseAPI {
462462
const queryParameters: any = {};
463463

464464
if (requestParameters.ids) {
465-
queryParameters['ids'] = requestParameters.ids.join(',');
465+
queryParameters['ids'] = requestParameters.ids;
466466
}
467467

468468
const headerParameters: runtime.HTTPHeaders = {};

0 commit comments

Comments
 (0)