简体   繁体   English

带有int值的Swagger枚举

[英]Swagger enum with int values

I would like to generate a swagger-json containing an enum. 我想生成一个包含枚举的swagger-json。 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). 我真正想要的是可能值的名称(第一,第二,第三)以及枚举值(0,1,2)背后的值。 Is it even possible to generate such a json (which is "swagger-valid") and if so, how? 甚至可以生成这样一个json(这是“swagger-valid”),如果是这样,怎么样?

I use NSwag and in the meantime Rico Suter from NSwag made the feature available. 我使用NSwag,与此同时,NSwag的Rico Suter提供了该功能。 Big props to him! 他的大道具!

The current version of the OpenAPI (fka. Swagger) do not propose this. 当前版本的OpenAPI(fka.Swagger)不建议这样做。 It will probably be added in next version (cf. https://github.com/OAI/OpenAPI-Specification/issues/348 ) 它可能会在下一个版本中添加(参见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. 同时有同样的问题,我结束了在属性描述中给出这些信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM