Skip to content

Commit

Permalink
refactor: url serialization for string array params (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz authored Apr 16, 2024
1 parent 7844dba commit 31b7126
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
7 changes: 0 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ If you have updated the generated chat code you'll have to fix the following iss

- 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
- 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`
- Fix the query param serizalization in the `gen/chat/MessagesApi.ts` file's `getManyMessagesRaw` function. This is the correct serialization:

```typescript
if (requestParameters.ids) {
queryParameters["ids"] = requestParameters.ids.join(",");
}
```

### Validate that the generated code works

Expand Down
18 changes: 9 additions & 9 deletions src/StreamClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,18 +517,18 @@ export class StreamClient {
queryParamsStringify: (params: HTTPQuery) => {
const newParams = [];
for (const k in params) {
if (Array.isArray(params[k]) || typeof params[k] === 'object') {
newParams.push(
`${k}=${encodeURIComponent(JSON.stringify(params[k]))}`,
);
const param = params[k];
if (Array.isArray(param)) {
newParams.push(`${k}=${encodeURIComponent(param.join(','))}`);
} else if (typeof param === 'object') {
newParams.push(`${k}=${encodeURIComponent(JSON.stringify(param))}`);
} else {
const value = params[k];
if (
typeof value === 'string' ||
typeof value === 'number' ||
typeof value === 'boolean'
typeof param === 'string' ||
typeof param === 'number' ||
typeof param === 'boolean'
) {
newParams.push(`${k}=${encodeURIComponent(value)}`);
newParams.push(`${k}=${encodeURIComponent(param)}`);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gen/chat/apis/MessagesApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ export class MessagesApi extends runtime.BaseAPI {
const queryParameters: any = {};

if (requestParameters.ids) {
queryParameters['ids'] = requestParameters.ids.join(',');
queryParameters['ids'] = requestParameters.ids;
}

const headerParameters: runtime.HTTPHeaders = {};
Expand Down

0 comments on commit 31b7126

Please sign in to comment.