dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.46k stars 10.03k forks source link

Remove JsonPropertyNameAttribute from all properties of ProblemDetails #41005

Closed anreton closed 2 years ago

anreton commented 2 years ago

Background and Motivation

At the moment, all properties ProblemDetails have attribute JsonPropertyNameAttribute with camelCase-style.

ProblemDetails

But not everyone uses style camelCase-style in their projects, e.g. like this:

_ = services
    .AddControllers()
    .AddJsonOptions
    (
        jsonOptions =>
        {
            jsonOptions.JsonSerializerOptions.PropertyNamingPolicy = null;
        }
    );

For casing-style consistency with the rest of the project, it might make sense to remove the JsonPropertyNameAttribute from all properties of ProblemDetails.

Tornhoof commented 2 years ago

Problem Details is specified in RFC 7807 https://datatracker.ietf.org/doc/html/rfc7807 It is very specific about the spelling/casing of the individual properties. So you can't really remove the fixed values.

anreton commented 2 years ago

Problem Details is specified in RFC 7807 https://datatracker.ietf.org/doc/html/rfc7807 It is very specific about the spelling/casing of the individual properties. So you can't really remove the fixed values.

@Tornhoof, thank you for your response.

Looked through the specification Problem Details. But nowhere did I find a specific requirement about casing of the properties and that it must be strictly enforced.

Tornhoof commented 2 years ago

The RFC contains the literal spelling of the individual properties, they even quote each occurrence.

I don't think your goal of configuration is bad, just your suggested method, as it will break conformance with the RFC.

monterolebronhg commented 2 years ago

@anreton you can also create a new JsonConverter only for ProblemDetails

anreton commented 2 years ago

@monterolebronhg, indeed, thanks for the replies.

Perhaps I should close the issue.