Swagger: is it possible to make an operation parameter constant / readonly?

旧巷老猫 提交于 2019-12-09 14:54:31

问题


This is the description of a certain parameter I have:

{
    "name": "myParam",
    "description": "My param description",
    "required": true,
    "paramType": "query",
    "type": "string",
    "defaultValue":"myValue"
}

The defaultValue is the only value the parameter can have, so is there a way to declare this? Seen in the context of the swagger-ui, I need the parameter's textbox to be read-only. I'm using swagger 1.2.

Thanks


回答1:


The proper way to declare this would be:

{
    "name": "myParam",
    "description": "My param description",
    "required": true,
    "paramType": "query",
    "type": "string",
    "enum": [ "myValue" ]
}

The "enum" property sets the possible values. Once you set a single value to it, that's the only one that could be used and that would be available in the UI for the user to choose from.



来源:https://stackoverflow.com/questions/26039399/swagger-is-it-possible-to-make-an-operation-parameter-constant-readonly

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