How to define constant string in Swagger open api 3.0

浪尽此生 提交于 2020-01-13 09:24:57

问题


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/


回答1:


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




回答2:


You can define a constant parameter as a required parameter with only one possible value

But if you have more than one parameter it can't be an constant. In the api all value can be changed if have an multiple choice.

Ref: https://swagger.io/docs/specification/2-0/describing-parameters/



来源:https://stackoverflow.com/questions/51780038/how-to-define-constant-string-in-swagger-open-api-3-0

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