You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After calling .AddSystemTextJsonMergePatch() in the startup, it adds the application/merge-patch+json content type to Swagger.
However, this means that other endpoints will default to this type, even if they're not PATCH:
[HttpPut("broken/{id:int}")]
public IActionResult BrokenUpdateCustomer([FromRoute] int id, [FromBody] BrokenCustomerPutDto brokenCustomerPutDto)
{
// ...
}
Probably it defaults to this because the list is in alphabetical order:
I think this is more of an issue on Swashbuckle's side. I'm not expecting this to be fixed (probably it can't be fixed here) - I just wanted this to be documented 😄
Workaround
Put [Consumes(MediaTypeNames.Application.Json)] on either every other method that accepts a body, or just apply it to the class:
[Consumes(MediaTypeNames.Application.Json)]
public class CustomersController : ControllerBase
{
// ...
}
The text was updated successfully, but these errors were encountered:
Interesting.
I never noticed it.
It seems to show all content types even if I remove AddNewtonsoftJsonMergePatch and comment out all non-default settings in swagger options in my application.
It looks like it is really a swagger issue but I have no time right now to investigate more.
That's because SystemTextJsonMergePatchInputFormatter does not implement GetSupportedContentTypes. It essentially declares that it supports every possible model type, which in reality it does not as its just going to fail on either getting the generic arguments of a non-generic type at
After calling
.AddSystemTextJsonMergePatch()
in the startup, it adds theapplication/merge-patch+json
content type to Swagger.However, this means that other endpoints will default to this type, even if they're not
PATCH
:Probably it defaults to this because the list is in alphabetical order:
I think this is more of an issue on Swashbuckle's side. I'm not expecting this to be fixed (probably it can't be fixed here) - I just wanted this to be documented 😄
Workaround
Put
[Consumes(MediaTypeNames.Application.Json)]
on either every other method that accepts a body, or just apply it to the class:The text was updated successfully, but these errors were encountered: