Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1K
Views
Pass array as query parameter in Swagger OpenApi 3.0

Ive currently given the below code to get an array of values as query paramters (in Node-express, nodejs v14.17 and OpenAPI version 3.0.1),

       - name: abcd
          description:  abcd
          in: query
          required: false
          schema:
            type: array
            items:
              type: string

but it send the req as an array of values(type is object) only if there are atleast two of them. For a single value, the type is string.How to always get req as array itself?

enter image description here

For example, if i give a single value say "Hello", console.log(typeof(req.query["abcd"]),req.query["abcd"]) O/P: string Hello but if i give "Hello" and "World", O/P: object ['Hello','World']

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

As this answer explains, when a query parameter gets passed a single value, e.g. ?abcd=hello, Express parses it as a regular value (i.e. string) rather than an array.

To pass a one-value array, you need to append [] at the end of the query parameter name, i.e. ?abcd[]=hello. This means you need to change the parameter name in your OpenAPI file:

       - name: abcd[]    # <------------
         description:  abcd
         in: query
         required: false
         schema:
           type: array
           items:
             type: string
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!