Swagger-ui: Swagger UI query parameters array of custom object get request

Created on 13 Nov 2019  路  5Comments  路  Source: swagger-api/swagger-ui

I have a customer array object in my get request with below query parameter

          {
            "name": "filters",
            "in": "query",
            "schema": {
              "type": "array",
              "items": {
                "$ref": "#/components/schemas/ColumnFilter"
              }
            }
          }

schema of custom object is:

      "ColumnFilter": {
        "type": "object",
        "properties": {
          "column": {
            "type": "string",
            "nullable": true
          },
          "value": {
            "type": "string",
            "nullable": true
          }
        }

I swagger UI what should i pass as value for this custom object
below manual url works for me:
https://localhost:8989/...?filters[0].Column=Site ID&filters[0].Value=Site_1

when i mention the below values in swagger UI for filters (array[objec])
column="Horizontal Beamwidth"&value="100" it is generating the below invalid url
https://localhost:8989/..?filters=column%3D%22Horizontal%20Beamwidth%22%26value%3D%22100%22

What should i enter in the swagger UI to generate a valid query parameter?

Most helpful comment

@dsr301 This is a limitation of the OpenAPI Specification (not Swagger UI) - currently it does not provide a way to serialize an array of objects into a query string like ?filters[0].Column=Site ID&filters[0].Value=Site_1. There's an existing feature request to support this serialization method as part of the deepObject style: https://github.com/OAI/OpenAPI-Specification/issues/1706.

All 5 comments

Is this your API definition or an API that you're trying to use?

Yes, below is the full defination:

  "paths": {
    "/dm/api/Cells": {
      "get": {
        "tags": [
          "Cells"
        ],
        "parameters": [
          {
            "name": "filters",
            "in": "query",
            "schema": {
              "type": "array",
              "items": {
                "$ref": "#/components/schemas/ColumnFilter"
              }
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "additionalProperties": false
                  }
                }
              },
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "additionalProperties": false
                  }
                }
              },
              "text/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "additionalProperties": false
                  }
                }
              },
              "text/csv": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "additionalProperties": false
                  }
                }
              }
            }
          }
        }
      },


       "components": {
    "schemas": {
      "ColumnFilter": {
        "type": "object",
        "properties": {
          "column": {
            "type": "string",
            "nullable": true
          },
          "value": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      }
    }
  }

@dsr301 This is a limitation of the OpenAPI Specification (not Swagger UI) - currently it does not provide a way to serialize an array of objects into a query string like ?filters[0].Column=Site ID&filters[0].Value=Site_1. There's an existing feature request to support this serialization method as part of the deepObject style: https://github.com/OAI/OpenAPI-Specification/issues/1706.

Closing as this a limitation of the OpenAPI Specification.

So... is there a workaround for this at all. Can I use swagger without OpenAPI... this is a pretty big limitation to swagger-ui.

Was this page helpful?
0 / 5 - 0 ratings