如何在 Swagger open api 3.0 中定义常量字符串常量、字符串、定义、如何在

2023-09-07 14:21:25 作者:入骨爱人

swagger open api 3.0 中如何定义常量字符串变量?如果我定义枚举,它将如下所示

How to define constant string variable in swagger open api 3.0 ? If I define enum it would be like as follows

"StatusCode": {
        "title": "StatusCode",
        "enum": [
          "success",
          "fail"
        ],
        "type": "string"          

 } 

但是枚举可以是值列表,有没有办法在swagger open api 3.0中定义字符串常量

But enums can be list of values, Is there any way to define string constant in swagger open api 3.0

代码可以从 http://editor.swagger.io/

推荐答案

正如@Helen 已经指出的那样,正如您在链接的答案中看到的那样,目前它似乎没有比 enum 只有一个值.可以粘贴到 http://editor.swagger.io/ 的完整示例:

As @Helen already pointed out, and as you can read in the linked answer, currently it does not seem to get any better than an enum with only one value. Full example that can be pasted into 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

There is a related topic on Github which is unsolved as of now: https://github.com/OAI/OpenAPI-Specification/issues/1313