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

cannot access to array query parameter with defined parameter name when axios and fastify #354

Open
2 of 3 tasks
casheeeewnuts opened this issue Apr 14, 2022 · 0 comments · May be fixed by #355
Open
2 of 3 tasks
Labels
priority/1 planning to do next

Comments

@casheeeewnuts
Copy link

casheeeewnuts commented Apr 14, 2022

Description

Issue

cannot access to array query parameter with defined parameter name.

example, defined methods
api/something/index.ts

export type Methods = {
  get: {
    query: {
      value?: string[]
    },
    resBody: string
  }
}

but cannot access to query.value in controller even pass the query params.
and array query params is mapped to <name>[]

// api/something/controller.ts
export default defineController(() => ({
  get: ({query}) => {
    console.log(query.value) // undefined
    console.log(query['value[]']) // ['aspida', 'frourio']
  }
})

// client
apiClient.something.$get({
  query: {
    value: ['aspida', 'frourio']
  }
})

please check this behavior in this repo

Reason

axios is serializing array query parameters to "key[]=value0&key[]=value1&...&key[]=value".
but default fastify's querystring parser deserializing into

{
 "key[]": [value0, value1, ..., value]
} 

Environment

  • Package version: v0.32.6
  • OS:
    • Linux
    • Windows
    • macOS
  • Node.js version: 14.17.1
  • npm version: 8.3.1

Additional context

@casheeeewnuts casheeeewnuts changed the title axiosto cannot access to array query parameter with defined parameter name when axios and fastify Apr 14, 2022
@casheeeewnuts casheeeewnuts linked a pull request Apr 14, 2022 that will close this issue
4 tasks
@LumaKernel LumaKernel added the priority/1 planning to do next label May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/1 planning to do next
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants