Morcatko / Morcatko.AspNetCore.JsonMergePatch

JsonMergePatch support for ASP.NET Core
MIT License
87 stars 20 forks source link

Calling `.AddSystemTextJsonMergePatch()` adds the `application/merge-patch+json` as default option in Swagger #61

Open harvzor opened 1 year ago

harvzor commented 1 year ago

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:

image

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
{
    // ...
}
Morcatko commented 1 year ago

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.