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

Problem Details camel case RFC 7807 "compliant casing" #59396

Open
1 task done
hmiguel opened this issue Dec 9, 2024 · 3 comments · May be fixed by #59545
Open
1 task done

Problem Details camel case RFC 7807 "compliant casing" #59396

hmiguel opened this issue Dec 9, 2024 · 3 comments · May be fixed by #59545
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates help wanted Up for grabs. We would accept a PR to help resolve this issue

Comments

@hmiguel
Copy link

hmiguel commented Dec 9, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Hi,

Following the discussion in this issue, it seems that starting with .NET 9, Problem Details are now always serialized using camelCase, reportedly, due to RFC 7807 compliance.

However, after reviewing the RFC, I couldn’t find any section that explicitly mandates the use of camelCase. Instead, the RFC states:

A problem type definition MAY specify additional members on the problem details object. For example, an extension might use typed links (RFC 5988) to another resource that can be used by machines to resolve the problem.

If such additional members are defined, their names SHOULD start with a letter (ALPHA, as per RFC 5234, Appendix B.1) and SHOULD consist of characters from ALPHA, DIGIT (RFC 5234, Appendix B.1), and "_", and they SHOULD be three characters or longer.

I’ve also noticed that the traceId field was recently introduced in the Problem Details object in .NET9, which now results, e.g., in the following JSON:

{
  "type": "https://tools.ietf.org/html/rfc9110#section-15.5.5",
  "title": "Not Found",
  "status": 404,
  "traceId": "00-fb5a4583138884ff98c3ba7caf310619-83734512fdab2295-00"
}

In my opinion, the response body should respect the SerializerOptions.PropertyNamingPolicy (e.g., camelCase or snake_case), with the only exception being kebab-case, which is not compliant with the RFC due to its use of hyphens.

For example, when using SerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower , the response body should produce the following result:

{
  "type": "https://tools.ietf.org/html/rfc9110#section-15.5.5",
  "title": "Not Found",
  "status": 404,
  "trace_id": "00-fb5a4583138884ff98c3ba7caf310619-83734512fdab2295-00"
}

Could you please clarify why this change is being enforced?

Thanks!

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

9.0.100

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Dec 9, 2024
@gfoidl gfoidl added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Dec 9, 2024
@captainsafia
Copy link
Member

@hmiguel Thanks for filing this issue!

The change that we merged into .NET 8 was specifically around using the prescribed casing for well-defined properties in the ProblemDetails object, like title and instance as defined in this portion of the spec.

traceId is cased this way as a result of this bit of code which should probably be fixed.

For all other extension keys, the implementation will use the serializer options configured in the JsonOptions.

Would you be interested in opening a PR to resolve this issue? It should be something like this:

- context.ProblemDetails.Extensions["traceId"] = traceId;
+ var tradeIdKeyName = _serializerOptions.PropertyNamingPolicy.ConvertName("traceId");
context.ProblemDetails.Extensions[traceIdKeyName] = traceId;

@captainsafia captainsafia added the help wanted Up for grabs. We would accept a PR to help resolve this issue label Dec 17, 2024
Copy link
Contributor

Looks like this issue has been identified as a candidate for community contribution. If you're considering sending a PR for this issue, look for the Summary Comment link in the issue description. That comment has been left by an engineer on our team to help you get started with handling this issue. You can learn more about our Help Wanted process here

@shethaadit
Copy link
Contributor

Hi @captainsafia, I will raise PR for this soon. :)

@shethaadit shethaadit linked a pull request Dec 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates help wanted Up for grabs. We would accept a PR to help resolve this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants