Swagger UI Web Api documentation Present enums as strings?

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

    I just did this and it works fine!

    Startup.cs

    services.AddSwaggerGen(c => {
      c.DescribeAllEnumsAsStrings();
    });
    

    Model.cs

    public enum ColumnType {
      DATE = 0
    }
    

    swagger.json

    type: {
      enum: ["DATE"],
      type: "string"
    }
    

    I hope this helps you how it helped me!

提交回复
热议问题