如何在 Swagger open api 3.0 中定义常量字符串
How to define constant string in Swagger open api 3.0
如何在 swagger open api 3.0 中定义常量字符串变量?
如果我定义枚举,它会像下面这样
"StatusCode": {
"title": "StatusCode",
"enum": [
"success",
"fail"
],
"type": "string"
}
但是枚举可以是值列表,有没有办法在 swagger open 中定义字符串常量 api 3.0
中执行
You can define a constant parameter as a required parameter with only one possible value
但是如果你有多个参数,它就不能是一个常量。在api中,如果有多项选择,所有值都可以更改。
参考:
https://swagger.io/docs/specification/2-0/describing-parameters/
正如@Helen 已经指出的那样,您可以在链接的答案中阅读,目前它似乎并不比只有一个值的 enum
更好。可以粘贴到 http://editor.swagger.io/:
中的完整示例
{
"openapi": "3.0.0",
"info": {
"title": "Some API",
"version": "Some version"
},
"paths": {},
"components": {
"schemas": {
"StatusCode": {
"title": "StatusCode",
"enum": [
"The only possible value"
],
"type": "string"
}
}
}
}
Github 上有一个相关主题目前尚未解决:
https://github.com/OAI/OpenAPI-Specification/issues/1313
如何在 swagger open api 3.0 中定义常量字符串变量? 如果我定义枚举,它会像下面这样
"StatusCode": {
"title": "StatusCode",
"enum": [
"success",
"fail"
],
"type": "string"
}
但是枚举可以是值列表,有没有办法在 swagger open 中定义字符串常量 api 3.0
中执行You can define a constant parameter as a required parameter with only one possible value
但是如果你有多个参数,它就不能是一个常量。在api中,如果有多项选择,所有值都可以更改。
参考: https://swagger.io/docs/specification/2-0/describing-parameters/
正如@Helen 已经指出的那样,您可以在链接的答案中阅读,目前它似乎并不比只有一个值的 enum
更好。可以粘贴到 http://editor.swagger.io/:
{
"openapi": "3.0.0",
"info": {
"title": "Some API",
"version": "Some version"
},
"paths": {},
"components": {
"schemas": {
"StatusCode": {
"title": "StatusCode",
"enum": [
"The only possible value"
],
"type": "string"
}
}
}
}
Github 上有一个相关主题目前尚未解决: https://github.com/OAI/OpenAPI-Specification/issues/1313