RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.67k stars 1.23k forks source link

Partial PATCH request #4400

Open miquelvir opened 1 year ago

miquelvir commented 1 year ago

I need to access an external API to PATCH a resource. I need to send only the fields that I want to modify.

For instance, if I want to change the description and set asignee to null I need to send:

PATCH /tasks/123

{
  "description": "deprioritized, working on other stuff",
  "asignee": null
}

And if I only want to modify the description, I need to send:

PATCH /tasks/123

{
  "description": "deprioritized, working on other stuff"
}

We are using NSwag to generate a client from the OpenAPI spec.

How could we only send some fields in the PATCH request? Right now, all fields are always sent as null, which is setting the assignee as null when we don't want to edit it :(

Tiberriver256 commented 9 months ago

I'm hunting for some of the same features. It seems, for APIs implementing JSON Merge PATCH. You'd want to either:

  1. Make the properties themselves wrapped in a different type that can be serialized, like Optional<T> or something like that.
  2. Implement some sort of a 'builder' pattern for the patch requests