SwaggerToCSharpClientGenerator: JSON output of JsonPatchDocument (HttpPatch) includes the operations property wrapper, causing model binding issues in the API
See original GitHub issueI’ve had some issues with a JsonPatchDocument serialisation.
The serialization of the JsonPatchDocument from the generated client sends the following:
{
"operations: [
{ "op": "add", "path": "/name", "value": "Carly" }
]
}
However, Web API 2 is expecting:
[
{ "op": "add", "path": "/name", "value": "Carly" }
]
As a result the request cannot be successfully bound to the controller method parameter.
A hacky fix is to take a copy the PatchAsync method and include it in the partial class/interface. All that method does is that it serializes the object.Operations rather than the object itself. I.e. Changing from this:
var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(customer, _settings.Value));
to this:
var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(customer.Operations, _settings.Value));
Is this a bug, or is there some other way to work around this, since this workaround feels rather ugly?
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (5 by maintainers)
@G4rce The following works:
@rebeccapowell @RSuter has there been any progress on this issue. Writing our own PatchAsync overload like Rebecca suggested would beat the whole point of code generation. Pls advise, regards.