DescribeAllEnumsAsStrings is obsolete
See original GitHub issueIn Swashbuckle.AspNetCore.SwaggerGen-5.0.0-rc3, the DescribeAllEnumsAsStrings method is marked obsolete and to-be-deprecated because it will automatically be applied if that convention is present in the serializer. However, the functionality is only present if Newtonsoft.Json is used as the serializer. If using the new default Json serializer in .NET Core 3, the StringEnumConverter is not respected.
Reproduction Code
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers()
.AddJsonOptions(x =>
{
x.JsonSerializerOptions.WriteIndented = !Environment.IsProduction();
x.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
});
services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, @"MyApi.xml"));
});
}
...
}
public enum Result
{
Success,
Failed
}

Edit: Completely understand that this is obviously not removed from the API yet, and it does work if I add the DescribeAllEnumsAsStrings() and ignore the warning. More it’s just an observation of functionality being reported obsolete that may be required if using the default serializer and wondering if there is a plan to implement that convention for the new serializer?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:26
- Comments:21 (4 by maintainers)
Top Related StackOverflow Question
I solved it using ShemaFilter like this:
And in Startup.cs:
Seems like this is fixed in version 5.0.0. Am I missing something?
Just added the following code in ConfigureServices, no need to set DescribeAllEnumsAsStrings in Swagger config
And heres the generated schema: