Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1K
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda