Open sudixi opened 4 years ago
Thanks for contacting us. We'll look into this and get back to you as soon as we have more details about what's going on here. Please don't expect an immediate outcome as we prioritize this with many other work items.
Thanks for the update!
Looking forward to hear from you!
Looks like this is also a problem in https://github.com/dotnet/aspnetcore/issues/19510
We have an ASP.NET core web API help pages with Swagger (swashbuckle). If there is any error , then we want to send the error with the content-type set to “application/*+json”.
Something like this appears to works:
.. but we expect the ProblemDetailsClientErrorFactory to handle this automatically, which it appears to do, but it does not stick when the Produces Attribute is present:
If the Produces Attribute is not used, the correct content type is returned, but the metadata is incomplete (application/problem+json is missing).
We feel the issue is here:
The JsonOutputFormatter defines three media types (text/plan, application/json and application/+json). The application/+json is never returned through the API Explorer because of the wildcard handling. The API Explorer requests all supported content types from the the OutputFormatter (GetSupportedContentTypes) by passing the null value (from GetApiResponseTypes). The issue is that wildcard media types are handled differently and are never returned when null is passed.
For more details, see:
https://github.com/aspnet/AspNetCore/blob/master/src/Mvc/Mvc.NewtonsoftJson/src/NewtonsoftJsonOutputFormatter.cs [https://github.com/aspnet/AspNetCore/blob/master/src/Mvc/Mvc.ApiExplorer/src/ApiResponseTypeProvider.cs (GetApiResponseTypes)](https://github.com/aspnet/AspNetCore/blob/master/src/Mvc/Mvc.ApiExplorer/src/ApiResponseTypeProvider.cs (GetApiResponseTypes)) [https://github.com/aspnet/AspNetCore/blob/master/src/Mvc/Mvc.Core/src/Formatters/OutputFormatter.cs (GetSupportedContentTypes)](https://github.com/aspnet/AspNetCore/blob/master/src/Mvc/Mvc.Core/src/Formatters/OutputFormatter.cs (GetSupportedContentTypes))
The JsonOutputFormatter adds application/*+json
The ApiResponseTypeProvider adds a null content type
… and then requests the SupportedContentTypes with null:
This is where we believe the issue is (OutputFormatter). If the media type is not a wildcard (ex: text/plain) and you pass null, it will be added (else branch). If it’s a wildcard though (like application/*+json), it won’t be added (if branch).
Is this supposed to work like this..?