Search code examples
c#json.net-coreswagger

Swagger enum with names


Is it possilbe in Swashbuckle.AspNetCore.Swagger (6.1.1) to get such enum with names? I need better names for generate API client for frontend app.

public enum BasketResourceEnum
{
    Stocks = 1,
    Currencies
}

Now I get such representation in json, I need name instead of int values

  "BasketResourceEnum": {
    "enum": [
      1,
      2
    ],
    "type": "integer",
    "format": "int32"
  },

Solution

  • services
        .AddControllers()
        .AddJsonOptions(options => 
            options.SerializerSettings.Converters.Add(new StringEnumConverter()));