Skip to content

Map of arrays in a GET request #5698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
betabandido opened this issue Nov 5, 2019 · 1 comment
Closed

Map of arrays in a GET request #5698

betabandido opened this issue Nov 5, 2019 · 1 comment

Comments

@betabandido
Copy link

betabandido commented Nov 5, 2019

Q&A (please complete the following information)

  • Method of installation: dist assets
  • Swagger-UI version: master
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

Example Swagger/OpenAPI definition:

{
  "openapi": "3.0.0",
  "info": {
    "title": "test",
    "version": "v1"
  },
  "paths": {
    "/endpoint": {
      "get": {
        "summary": "test",
        "parameters": [
          {
            "description": "test",
            "in": "query",
            "name": "param",
            "style": "deepObject",
            "schema": {
              "type": "object",
              "additionalProperties": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "example": {
              "key": [
                "value1",
                "value2"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          }
        }
      }
    }
  }
}

Describe the bug you're encountering

According to the OpenAPI 3.0 specification a map where the keys are strings and the values are string arrays should be a valid parameter type:

A dictionary (also known as a map, hashmap or associative array) is a set of key/value pairs. OpenAPI lets you define dictionaries where the keys are strings. To define a dictionary, use type: object and use the additionalProperties keyword to specify the type of values in key/value pairs.

The additionalProperties keyword specifies the type of values in the dictionary. Values can be primitives (strings, numbers or boolean values), arrays or objects.

The swagger.json shown above includes an example where a map value is an array of two elements. I would expect this to be a valid configuration. But, swagger UI doesn't seem to accept it. When sending a request to the endpoint using swagger (with the example shown above) the curl command is: curl -X GET "http://localhost:8000/endpoint" -H "accept: */*". Notice that the query string is missing.

Expected behavior

The map containing arrays as values gets encoded as a query string.

Additional context or thoughts

Are map where the values are arrays only supported in a request body (e.g., using POST method)? Or should this also work in a query string as part of a GET request?

@hkosova
Copy link
Contributor

hkosova commented Nov 18, 2019

Currently OpenAPI Specification does not support this scenario. The issue is that the deepObject behavior is only defined for simple objects with primitive properties (such as a string-to-string dictionary) but not for arrays or nested objects (such as a string-to-array dictionary).

This feature requires a change to the OpenAPI Specification (OAI/OpenAPI-Specification#1706) before it could be implemented in Swagger UI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants