Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Property casing policy is ignored when using minimal APIs, camel casing always applied #3097

Open
antoinebj opened this issue Oct 6, 2024 · 1 comment
Labels
bug help-wanted A change up for grabs for contributions from the community

Comments

@antoinebj
Copy link

antoinebj commented Oct 6, 2024

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:

  "components": {
    "schemas": {
      "MyDto": {
        "type": "object",
        "properties": {
          "helloWorld": {
            "type": "string",
            "nullable": true,
            "readOnly": true
          }
        },
        "additionalProperties": false
      }
    }
  }

Steps to reproduce

Using this code in Program.cs:

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).

@antoinebj antoinebj added the bug label Oct 6, 2024
@martincostello martincostello added the help-wanted A change up for grabs for contributions from the community label Oct 7, 2024
@jgarciadelanoceda
Copy link
Contributor

jgarciadelanoceda commented Oct 22, 2024

@antoinebj can you see if this WA works for you?
I beleive that is the same issue: #2293 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help-wanted A change up for grabs for contributions from the community
Projects
None yet
Development

No branches or pull requests

3 participants