Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1K
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda