JSON Patch Support with Swagger and ASP.NET Core 3.1

Getting Swagger and JsonPatchDocument to play nice

Introduction .NET Core has great support for JsonPatch which looks a little something like this public async Task<ActionResult> UpdateUser(string id,[FromBody] JsonPatchDocument<UserUpdateModel> patchDoc) { ... } And we expect a request to come in with a body like [{ "value": "Gordon", "path": "/name", "op": "replace" }, { "value": "Freeman", "path": "/surname", "op": "replace" }] However if you’re using the Swashbuckle.AspNetCore.Swagger library it will generate a description for the parameter type which is normally fine, but in this case it’s JsonPatchDocument<UserUpdateModel> which doesn’t represent the expected patch request doument. [Read More]

How to add JSON Patch support to ASP.NET Web API

In this post we’ll look at how to introduce support for the JSON Patch content type (RFC 6902) to ASP.NET Web API. There’s an unlimited number of ways to introduce HTTP Patch support into your API as there’s no single specification on how to represent the set of changes to make to a resource. The PATCH method requests that a set of changes described in the request entity be applied to the resource identified by the Request- URI. [Read More]