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

Building a route with array params doesn't work #1880

Open
jwoertink opened this issue Apr 29, 2024 · 1 comment
Open

Building a route with array params doesn't work #1880

jwoertink opened this issue Apr 29, 2024 · 1 comment
Labels

Comments

@jwoertink
Copy link
Member

If you have an action that specifies an array param, you're not able to build a route from that action.

class Reports::Query < ApiAction
  param codes : Array(String)

  get "/reports/query" do
    results = ReportQuery.new.codes(codes)

    json(ReportSerializer.for_collection(results))
  end
end

# then in your spec for this

it "doesn't work" do
  client = ApiClient.new
  response = client.exec(Reports::Query.with(codes: ["a", "b", "c"]))
  response.status_code.should eq(200) # but it's actually 400 here
end

The route that's built looks more like

/reports/query?codes=%5B%22a%22%2C+%22b%22%2C+%22c%22%5D

Which basically looks like

@query_params=URI::Params{"codes" => ["[\"a\", \"b\", \"c\"]"]},
@jwoertink jwoertink added the bug label Apr 29, 2024
@akadusei
Copy link
Contributor

I ran into a Lucky::MissingParamError with this a while back. My workaround looked like this:

params = URI::Params.encode({"code[]": ["a", "b"]})
response = client.get("#{Reports::Query.url_without_query_params}?#{params}")
response.status_code.should eq(200)

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

No branches or pull requests

2 participants