【问题标题】:Display enum property of model definitions显示模型定义的枚举属性
【发布时间】:2014-11-27 10:37:09
【问题描述】:

我正在尝试在模型描述中显示模型的枚举。 我的模型的模式在定义下定义并使用枚举作为操作属性,因为只允许这三种类型。 (见下面的代码)

我使用的是 swagger 2.0 版。在 1.2 版中,这似乎可行:http://petstore.swagger.wordnik.com/ 您可以在 store/order 下找到示例。 他们还使用枚举,它显示在模型视图中的属性后面。 新版本如何才能达到同样的效果?

感谢您的帮助!

   "paths": {
    "/event": {
        "post": {
            "tags": [
                "event"
            ],
            "summary": "Add an new Event.",
            "description": "TEST",
            "operationId": "addEvent",
            "consumes": [
                "application/json"
            ],
            "produces": [
                "application/json"
            ],
            "parameters": [
                {
                    "in": "body",
                    "name": "data",
                    "description": "",
                    "required": true,
                    "schema": {
                        "$ref": "#/definitions/Event"
                    }
                }
            ],
            "responses": {
                "405": {
                    "description": "Invalid input"
                }
            }
        }
    }
}
"definitions": {
    "Event": {
        "id": "eventModel",
        "required": [
            "action"
        ],
        "properties": {
            "action": {
                "type": "string",
                "default": "START",
                "enum": [ 
                    "START",
                    "UPDATE",
                    "END"
                ],
                "description": "blabla"
            }
        }
    }
}

PS:我现在认识到的另一个错误是,显示的数组模型描述错过了右括号]。

【问题讨论】:

    标签: enums swagger swagger-ui


    【解决方案1】:

    您的定义很好,swagger-ui 中有一个已知错误 - https://github.com/swagger-api/swagger-ui/issues/672。随意订阅问题并关注那里的进展。

    附带说明一下,Swagger 2.0 中的模型中没有 "id" 属性。

    【讨论】:

      猜你喜欢
      • 2017-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多