如何在Swagger Open API 3.0中定义常量字符串 [英] How to define constant string in Swagger open api 3.0

查看:541
本文介绍了如何在Swagger Open API 3.0中定义常量字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

 } 

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

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

执行代码

解决方案

正如@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

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"          

 } 

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

code can be executed form the 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"
      }
    }
  }
}

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

这篇关于如何在Swagger Open API 3.0中定义常量字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆