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
fix: allow array query parameter for a single value #6542
fix: allow array query parameter for a single value #6542
Conversation
55f3d49
to
1783d44
Compare
packages/rest/src/__tests__/acceptance/routing/routing.acceptance.ts
Outdated
Show resolved
Hide resolved
packages/rest/src/__tests__/acceptance/routing/routing.acceptance.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @mrmodise for the pull request
I'd like to discuss several implementation & testing details, PTAL at my comment below.
I'd also like to discuss one important edge case: let's say we have a parameter accepting a two-dimensional array (an array of an arrays of strings). How are we going to coerce such values? Request values to consider:
- a "full" value:
[[1, 2], [3, 4]]
- a single item at top level, containing an array:
[[1, 2]]
- multi values at top level, containing a single time array:
[[1], [3]]
- a single item array at top level containing a single item array:
[[1]]
Can you please check how is swagger-ui (API Explorer) converting such values into query string parameters and ensure that our coercion code handles them correctly?
Using qs
with {arrayFormat: 'repeat'}
:
> qs.stringify({foo: [1]}, {arrayFormat: 'repeat'})
'foo=1' // this is your use case, right?
> qs.stringify({foo: [[1,2],[3,4]]}, {arrayFormat: 'repeat'})
'foo=1&foo=2&foo=3&foo=4' // uh oh, information was lost :(
> qs.stringify({foo: [[1,2]]}, {arrayFormat: 'repeat'})
'foo=1&foo=2'
> qs.stringify({foo: [[1],[3]]}, {arrayFormat: 'repeat'})
'foo=1&foo=3'
> qs.stringify({foo: [[1]]}, {arrayFormat: 'repeat'})
'foo=1'
Based on the above, I am not sure if it's a good idea to support coercion of singular values into an array for all array types. I guess it should be fine if we limit coercion only to itemType
of string
, number
or boolean
as suggested by @raymondfeng.
packages/rest/src/__tests__/acceptance/routing/routing.acceptance.ts
Outdated
Show resolved
Hide resolved
packages/rest/src/__tests__/acceptance/routing/routing.acceptance.ts
Outdated
Show resolved
Hide resolved
d047fdc
to
a133736
Compare
Interesting, below are the results of these tests:
@bajtos @raymondfeng done the changes as requested. Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good now.
I am little bit concerned about handling parameters accepting an array of arrays, but I guess that's something we can fix later, if there is ever any user demand for that.
@raymondfeng can you please review the new version too?
a133736
to
f71ee0e
Compare
960b02b
to
84e4345
Compare
Signed-off-by: mrmodise <modisemorebodi@gmail.com> refactor: return array data for other spec Signed-off-by: mrmodise <modisemorebodi@gmail.com>
84e4345
to
bc2ce05
Compare
@mrmodise PR is landed. Thank you for the contribution with great patience. |
PR fixes an issue where by passing only a single query parameter throws an error with code
INVALID_PARAMETER_VALUE
and messageshould be array
Fixes: #6514
Checklist
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated