Swagger UI Web Api documentation Present enums as strings?

后端 未结 20 2019
半阙折子戏
半阙折子戏 2020-11-27 11:31

Is there a way to display all enums as their string value in swagger instead of their int value?

I want to be able to submit POST actions and put enums according to

20条回答
  •  借酒劲吻你
    2020-11-27 11:38

    ASP NET SOLUTION

    In my api docs one enum was still shown as int despite the property being marked with StringEnumConverter. We couldn't afford using the global setting for all enums mentioned above. Adding this line in SwaggerConfig solved the issue:

    c.MapType(() => new Schema { type = "string", @enum = Enum.GetNames(typeof(ContactInfoType))});
    

提交回复
热议问题