Pass array as query parameter in Swagger OpenApi 3.0


Fractal 397

I currently give the following code to get a set of values ​​as query parameters (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 only sends the request as an array of values ​​(of type ) if objectthere are at least two values . For a single value, the type is string.How to always have req as the array itself?

enter image description here

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

Helen

As this answer explains, when a query parameter is passed a single value, for example ?abcd=hello, Express parses it as a regular value (i.e. a string) instead of an array.

To pass a single-valued array, you need to append []to the end of the query parameter name , ie ?abcd[]=hello. This means you need to change the parameter name in the OpenAPI file:

       - name: abcd[]    # <------------
         description:  abcd
         in: query
         required: false
         schema:
           type: array
           items:
             type: string

Related


Pass parameter to $ref in OpenAPI 3

some development Suppose I have the following schema for later use $ref: "schemas": { "Order": { "type": "object", "properties": { "id": { "type": "integer", "format": "int64" }, "petI

Pass parameter to $ref in OpenAPI 3

some development Suppose I have the following schema for later use $ref: "schemas": { "Order": { "type": "object", "properties": { "id": { "type": "integer", "format": "int64" }, "petI

Elasticsearch - pass array as parameter in query

KimioN42 : I am trying to make a query in Elasticsearch using an array as a query parameter. For example, I want to search for [apples, oranges, pineapples] in the "Fruits" field. But in my case I want to search an array of companyIds. I came up with this quer

Elasticsearch - pass array as parameter in query

KimioN42 : I am trying to make a query in Elasticsearch using an array as a query parameter. For example, I want to search for [apples, oranges, pineapples] in the "Fruits" field. But in my case I want to search an array of companyIds. I came up with this quer

Elasticsearch - pass array as parameter in query

KimioN42 : I am trying to make a query in Elasticsearch using an array as a query parameter. For example, I want to search for [apples, oranges, pineapples] in the "Fruits" field. But in my case I want to search an array of companyIds. I came up with this quer

Elasticsearch - pass array as parameter in query

KimioN42 : I am trying to make a query in Elasticsearch using an array as a query parameter. For example, I want to search for [apples, oranges, pineapples] in the "Fruits" field. But in my case I want to search an array of companyIds. I came up with this quer

Elasticsearch - pass array as parameter in query

KimioN42 : I am trying to make a query in Elasticsearch using an array as a query parameter. For example, I want to search for [apples, oranges, pineapples] in the "Fruits" field. But in my case I want to search an array of companyIds. I came up with this quer

Swagger/OpenAPI ResponseBodies parameter with slight differences

ForEachLoop How can I change part of $ref or add it to it? I have an OpenAPI 3.x response body: ordernumber: $ref: '#/components/requestBodies/ordernumber' The descriptive text applies to every instance I use in it, except the last line. Every product cha

Swagger/OpenAPI ResponseBodies parameter with slight differences

ForEachLoop How can I change part of $ref, or add it to it? I have an OpenAPI 3.x response body: ordernumber: $ref: '#/components/requestBodies/ordernumber' The descriptive text applies to every instance I use in it, except the last line. Every product ch

Swagger/OpenAPI ResponseBodies parameter with slight differences

ForEachLoop How can I change part of $ref or add it to it? I have an OpenAPI 3.x response body: ordernumber: $ref: '#/components/requestBodies/ordernumber' The descriptive text applies to every instance I use in it, except the last line. Every product cha

Swagger/OpenAPI ResponseBodies parameter with slight differences

ForEachLoop How can I change part of $ref or add it to it? I have an OpenAPI 3.x response body: ordernumber: $ref: '#/components/requestBodies/ordernumber' The descriptive text applies to every instance I use in it, except the last line. Every product cha

Swagger/OpenAPI ResponseBodies parameter with slight differences

ForEachLoop How can I change part of $ref or add it to it? I have an OpenAPI 3.x response body: ordernumber: $ref: '#/components/requestBodies/ordernumber' The descriptive text applies to every instance I use in it, except the last line. Every product cha

Pass array as query parameter to link to helper

Adam Cooper I have a queryParam in my controller which is an array like this: export default Ember.Controller.extend({ queryParams: ['customFilters'], customFilters: [] // Other code goes here } Now, I want to link to this controller and provide cust

How to pass array in Wiremock query parameter

Sofian Benamore It's been a few days now and I'm stuck with Wiremock. I can't figure out how to send an array parameter in the GET method. I want to send this GET http://localhost/test?filter[]=full&token=any. so my json looks like { "request": { "

Pass string array as parameter in Hive Query (HQL)

Mohini I'm working on HQL and I need to pass an array of strings as a parameter: select * from table_1 where id not in ('${idListToFilter}') I want to pass idListToFilteras parameter in Hive query . try using values like idListToFilter="'1','2','3'" but got

Pass string array as parameter in Hive Query (HQL)

Mohini I'm working on HQL and I need to pass an array of strings as a parameter: select * from table_1 where id not in ('${idListToFilter}') I want to pass idListToFilteras parameter in Hive query . try using values like idListToFilter="'1','2','3'" but got

Pass string array as parameter in Hive Query (HQL)

Mohini I'm working on HQL and I need to pass an array of strings as a parameter: select * from table_1 where id not in ('${idListToFilter}') I want to pass idListToFilteras parameter in Hive query . try using values like idListToFilter="'1','2','3'" but got

Pass array as query parameter to link to helper

Adam Cooper I have a queryParam in my controller which is an array like this: export default Ember.Controller.extend({ queryParams: ['customFilters'], customFilters: [] // Other code goes here } Now, I want to link to this controller and provide cust

How to pass array in query parameter URL

winner I'm using a multi-select dropdown and what I want is whatever I select in the dropdown to be sent to the server to fit those dropdown results by calling an api that includes query parameters. I did a series of selected projects. Array(3) [ "contact", "f

How to pass array in Wiremock query parameter

Sofian Benamore It's been a few days now and I'm stuck with Wiremock. I can't figure out how to send an array parameter in the GET method. I want to send this GET http://localhost/test?filter[]=full&token=any. so my json looks like { "request": { "

Pass string array as parameter in Hive Query (HQL)

Mohini I'm working on HQL and I need to pass an array of strings as a parameter: select * from table_1 where id not in ('${idListToFilter}') I want to pass idListToFilteras parameter in Hive query . try using values like idListToFilter="'1','2','3'" but got

How to pass array in query parameter URL

winner I'm using a multi-select dropdown and what I want is whatever I select in the dropdown to be sent to the server to fit those dropdown results by calling an api that includes query parameters. I did a series of selected projects. Array(3) [ "contact", "f

How to pass array in Wiremock query parameter

Sofian Benamore It's been a few days now and I'm stuck with Wiremock. I can't figure out how to send an array parameter in the GET method. I want to send this GET http://localhost/test?filter[]=full&token=any. so my json looks like { "request": { "

How to pass array in Wiremock query parameter

Sofian Benamore It's been a few days now and I'm stuck with Wiremock. I can't figure out how to send an array parameter in the GET method. I want to send this GET http://localhost/test?filter[]=full&token=any. so my json looks like { "request": { "

Pass string array as parameter in Hive Query (HQL)

Mohini I'm working on HQL and I need to pass an array of strings as a parameter: select * from table_1 where id not in ('${idListToFilter}') I want to pass idListToFilteras parameter in Hive query . try using values like idListToFilter="'1','2','3'" but got