How to define a map in swagger?

夙愿已清 提交于 2019-12-09 15:46:26

问题


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"
        }
      }
    }
  }
}

回答1:


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.



来源:https://stackoverflow.com/questions/28644595/how-to-define-a-map-in-swagger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!