-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
help-wantedA change up for grabs for contributions from the communityA change up for grabs for contributions from the communityp1High priorityHigh priority
Description
Using Swashbuckle.AspNetCore 6.2.3 with ASP.NET 6 minimal API, I have configured JSON serializer options per the docs.
services.Configure<JsonOptions>(options =>
{
options.SerializerOptions.Converters.Add(new JsonStringEnumConverter());
options.SerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
options.SerializerOptions.ReferenceHandler = ReferenceHandler.Preserve;
});
However, Swagger UI still reports enums as ints unless I add also use AddControllers().AddJsonOptions():
services.AddControllers()
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.Preserve;
});
Once the second block is added, the swagger UI output references the enum string values as expected. As far as I know, the latter simply does the former under the hood, but there seems to be some order of operations affecting the schema generation here?
ctolkien, JefSchraag, grisha0088, alexis-spx, vincent1405 and 30 more
Metadata
Metadata
Assignees
Labels
help-wantedA change up for grabs for contributions from the communityA change up for grabs for contributions from the communityp1High priorityHigh priority