The user with no hat
The user with no hat

Reputation: 10856

How to define a map in swagger?

I'm working on an API which also generates swagger documentation. The issue is that for some reasons the request model/schema is not displayed in swagger UI but I don't get any error either. I need to represent map to an array of strings . e.g. map[string][]string. Definition object definition is below.

{
  "definitions": {
    "versions": {
      "type": "string",
      "additionalProperties": {
        "type": "array",
        "items": {
          "type": "string"
        }
      }
    }
  }
}

Upvotes: 11

Views: 28323

Answers (1)

Ron
Ron

Reputation: 14840

The support for maps is still not available in the UI - https://github.com/swagger-api/swagger-ui/issues/913.

You'd also want to change your definitions like this:

{
  "definitions": {
    "versions": {
      "type": "object",
      "additionalProperties": {
        "type": "array",
        "items": {
          "type": "string"
        }
      }
    }
  }
}

To be clear, this defines a map where the values are arrays of strings.

Upvotes: 7

Related Questions