No matter which naming policy is set in general JSON serializer options when using minimal APIs, Swashbuckle applies camel casing. It therefore does not comply with the actual output of the endpoint.
Expected behavior
With the null naming policy, the property name should have been taken without modification, i.e. it should have been HelloWorld.
var builder = WebApplication.CreateSlimBuilder(args);
builder.Services.ConfigureHttpJsonOptions(options =>
{
options.SerializerOptions.PropertyNamingPolicy = null;
});
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// This needs to be added because of some other open issue
builder.Services.Configure<RouteOptions>(
options => options.SetParameterPolicy<RegexInlineRouteConstraint>("regex"));
builder.WebHost.UseKestrelHttpsConfiguration();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.MapGet("/hello", () => new MyDto());
app.Run();
internal sealed class MyDto
{
public string HelloWorld => "hello";
}
Exception(s) (if any)
No response
Swashbuckle.AspNetCore version
6.8.1
.NET Version
8.0.400
Anything else?
NSwag correctly applies the configured property naming policy, using the same code (aside from the 3 Swashbuckle calls replaced with NSwag ones).
Describe the bug
No matter which naming policy is set in general JSON serializer options when using minimal APIs, Swashbuckle applies camel casing. It therefore does not comply with the actual output of the endpoint.
Expected behavior
With the null naming policy, the property name should have been taken without modification, i.e. it should have been
HelloWorld
.Actual behavior
The property name was modified to camel case.
This is what I get in the document:
Steps to reproduce
Using this code in Program.cs:
Exception(s) (if any)
No response
Swashbuckle.AspNetCore version
6.8.1
.NET Version
8.0.400
Anything else?
NSwag correctly applies the configured property naming policy, using the same code (aside from the 3 Swashbuckle calls replaced with NSwag ones).