Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger enum with int values

I would like to generate a swagger-json containing an enum. My problem is the way the enum gets rendered:

"MyEnumType": {
  "typeName": "MyEnumType",
  "type": "string",
  "enum": [
    "first",
    "second",
    "third"
  ]
}

What I really want is the name of the possible values (first, second, third) as well as the value behind that enum-values (0, 1, 2). Is it even possible to generate such a json (which is "swagger-valid") and if so, how?

like image 833
Domenic Avatar asked Dec 01 '15 10:12

Domenic


2 Answers

I use NSwag and in the meantime Rico Suter from NSwag made the feature available. Big props to him!

like image 140
Domenic Avatar answered Sep 20 '22 14:09

Domenic


The current version of the OpenAPI (fka. Swagger) do not propose this. It will probably be added in next version (cf. https://github.com/OAI/OpenAPI-Specification/issues/348)

In the meanwhile having the same issue I ended giving these informations in the property's description.

like image 44
Arnaud Lauret Avatar answered Sep 20 '22 14:09

Arnaud Lauret