aspnetcore
aspnetcore copied to clipboard
(Http)(Validation)ProblemDetails converters should obey JsonOptions.JsonNamingPolicy
Hi, I think this may be related, but the casing for ProblemDetails is also inconsistent. ProblemDetails itself defaults to camel case, but as you can see above when describing the "Summary" field, it's capitalized. Shouldn't that be lower case, assuming @TanvirArjel is using the default naming policy?
I've also noticed ProblemDetails does not obey JsonOptions
settings, e.g., setting
services.Configure<JsonOptions>(opt =>
{
opt.JsonSerializerOptions.PropertyNamingPolicy = null; // don't convert to camel case
});
should give a response like
{
"Type": "https://tools.ietf.org/html/rfc7231#section-6.5.4",
"Title": "Not Found",
"Status": 404,
"Detail": "Account 1 not found.",
"TraceId": "00-50f63c5d7921484e4797d82687f43033-915b95474bf55ff2-00"
}
but it does not, at least from what I can tell. Maybe this is by design since the spec (https://www.rfc-editor.org/rfc/rfc7807) explicitly lists the properties lower/regular camel case, but it also doesn't seem to explicitly call out camelcase must be used. I think anyone who is using problem details should be able to use whatever casing their API uses already rather than being forced to either a) have inconsistent casing returned or b) use camel case.
Originally posted by @jchoca in https://github.com/dotnet/aspnetcore/issues/43261#issuecomment-1248777800
Repro:: https://github.com/jchoca/ProblemDetailsJsonSettings