如何在swagger中定义地图? [英] How to define a map in swagger?
问题描述
我正在开发一个 API,它也会生成 swagger 文档.问题是由于某些原因,请求模型/架构未显示在 swagger UI 中,但我也没有收到任何错误.我需要将映射表示为字符串数组.例如地图[字符串][]字符串.定义对象定义如下.
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"
}
}
}
}
}
推荐答案
UI 中仍然不支持地图 - https://github.com/swagger-api/swagger-ui/issues/913.
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.
这篇关于如何在swagger中定义地图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!