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

Support arrays as query parameters #516

Closed
mattyb opened this issue Mar 27, 2020 · 1 comment · Fixed by #550
Closed

Support arrays as query parameters #516

mattyb opened this issue Mar 27, 2020 · 1 comment · Fixed by #550

Comments

@mattyb
Copy link

mattyb commented Mar 27, 2020

Standard libraries construct array query parameters as below:

http://hostname/endpoint?colors[]=blue&colors[]=green

If plumber sees this for an endpoint with a colors parameter, it should construct a list and pass it to the function.

@meztez
Copy link
Collaborator

meztez commented Mar 30, 2020

Square bracket are kind of not supported in the query parameter per RFC 3986

Currently, it should work when using http://hostname/endpoint?colors=blue&colors=green and treating colors as a vector (not a list) in your plumber.R function.

library(plumber)

#* Sort letters
#* @param letters
#* @json
#* @get /letters
function(letters) {
  sort(letters)
}

http://hostname:port/letters?letters=t&letters=a&letters=z&letters=f&letters=e

["a","e","f","t","z"]

But something could be done by defining plumber param as

#* @param number:numeric[] a numeric array

so that the Swagger UI picks it up since it is supported in OpenApi

Would need to modify the following, obviously dynamically.

ret$paths$`/letters`$get$parameters[[1]]$schema$type = "array"
ret$paths$`/letters`$get$parameters[[1]]$schema$items$type = "integer"
ret$paths$`/letters`$get$parameters[[1]]$style = "form"
ret$paths$`/letters`$get$parameters[[1]]$explode = "true"
ret$paths$`/letters`$get$parameters[[1]]$schema$minItems = "1"

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

Successfully merging a pull request may close this issue.

2 participants