orval
orval copied to clipboard
fix(fetch): properly append array values to `normalizedParams` object
Status
WIP
Description
I experienced a problem with array values.
For example I want to send this: Foo: [0, 1] this will be added by this line of code to the URLSearchParams instance, which in turn will by stringified to Foo=0,1 and appended to the API url in generated code.
Shouldn't this be done according to this example in the MDN docs? Resulting in Foo=0&Foo=1 as stringified value.
This PR addresses that. Let me know if I need to anything else within this PR.
Thanks @soartec-lab for the great work on the fetch client 🎉
Related PRs
List related PRs against other branches:
- https://github.com/orval-labs/orval/issues/1387
Todos
- [ ] Tests
- [ ] Documentation
- [ ] Changelog Entry (unreleased)
Looks like the build is failing?
Looks like the build is failing?
I can now reproduce locally, I'm working on a fix 👍
Thanks! I'm wondering if I should make it optional and selectable. Because this is currently working.
I've found the cause of the error, it's because the strong typed pet store example /samples/**/models/listPetsParams.ts doesn't contain any parameters that have an array type. In the generated example it only is
export type ListPetsParams = {
/**
* How many items to return at one time (max 100)
*/
limit?: string;
};
this is based on the /samples/**/petstore.yaml
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: string
The error claims that the code value instanceof Array is never true, because it is inferred that value can only be of type string not of any kind of Array
So then the proposed change of the PR would have to be dynamically included based on whether the type is an array or not. I haven't figured out how / where to do this best. If you have any idea on how to do this properly, don't hesitate to do so 😉
This means changing the conditions for constructing query parameters depending on the type of OpenAPI, right?
I will also look for ways to change it 👍
Hi, @n2k3 I looked into this. A reasonable way to accomplish this is to parse the generated query params string and verify whether it contains an array. Also, consider cases where there are only array-type fields.
@n2k3
I created #1604 based on this PR. Does control with explode property solve your problem?
I'll close this PR. Because, this issue fixed by #1604.