Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: url serialization for string array params #26

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading