这是对我拥有的某个参数的描述:
{
"name": "myParam",
"description": "My param description",
"required": true,
"paramType": "query",
"type": "string",
"defaultValue":"myValue"
}
defaultValue是参数唯一可以拥有的值,那么有没有方法来声明它呢?在swagger-ui的上下文中,我需要参数的textbox是只读的。我使用的是swagger 1.2。
谢谢
发布于 2014-10-16 17:54:43
声明这一点的正确方法是:
{
"name": "myParam",
"description": "My param description",
"required": true,
"paramType": "query",
"type": "string",
"enum": [ "myValue" ]
}
"enum“属性设置可能的值。一旦您为它设置了一个值,它就是唯一可以使用的值,并且它将在UI中可供用户选择。
发布于 2021-10-13 04:34:55
你也可以使用字符串的'pattern‘来避免枚举-这在Swagger中看起来会更好:
{
"openapi": "3.0.0",
"components": {
"schemas": {
"object": {
"type": "object",
"required": [
"myParam"
],
"properties": {
"myParam": {
"type": "string",
"pattern": "onlyAllowedValue$"
}
}
}
}
}
}
发布于 2021-11-09 01:38:41
我玩得有点晚,但使用OpenAPI 3.1你可以做到以下几点:
defaultValue:
type: string
const:
- myValue
https://stackoverflow.com/questions/26039399
复制