Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define constant string in Swagger open api 3.0 [duplicate]

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/

like image 581
Harsha Gayan Avatar asked Aug 10 '18 06:08

Harsha Gayan


People also ask

How do you declare an array of strings in Swagger?

Firstly, we start by specifying the array of strings in Swagger using YAML notation. In the schema section, we include type: array with items String.


1 Answers

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

like image 55
Dirk Avatar answered Sep 17 '22 12:09

Dirk