Swagger UI Web Api documentation Present enums as strings?

后端 未结 20 1987
半阙折子戏
半阙折子戏 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

    If you are using newtonsof.json then use this

    using Newtonsoft.Json.Converters;
    
    
    [JsonConverter(typeof(StringEnumConverter))]
    public enum MyEnum
    {
        A, B
    }
    

    If you are using System.Text.Json.Serialization

    using System.Text.Json.Serialization;
    
    
    [JsonConverter(typeof(JsonStringEnumConverter))]
    public enum MyEnum
    {
        A, B
    }
    

提交回复
热议问题