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

[BUG] [typescript-fetch] uniqueItems in query params does not work #12317

Closed
2 of 6 tasks
Nikos410 opened this issue May 9, 2022 · 0 comments · Fixed by #12318
Closed
2 of 6 tasks

[BUG] [typescript-fetch] uniqueItems in query params does not work #12317

Nikos410 opened this issue May 9, 2022 · 0 comments · Fixed by #12318

Comments

@Nikos410
Copy link
Contributor

Nikos410 commented May 9, 2022

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

If uniqueItems is true for an array, the typescript-fetch generator uses a Set instead of an array. This does not work for query parameters however, because the querystring function does not support Sets:

export function querystring(params: HTTPQuery, prefix: string = ''): string {
return Object.keys(params)
.map((key) => {
const fullKey = prefix + (prefix.length ? `[${key}]` : key);
const value = params[key];
if (value instanceof Array) {
const multiValue = value.map(singleValue => encodeURIComponent(String(singleValue)))
.join(`&${encodeURIComponent(fullKey)}=`);
return `${encodeURIComponent(fullKey)}=${multiValue}`;
}
if (value instanceof Date) {
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`;
}
if (value instanceof Object) {
return querystring(value as HTTPQuery, fullKey);
}
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
})
.filter(part => part.length > 0)
.join('&');
}
)

openapi-generator version

master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant