Closed zygimantas closed 8 years ago
@zygimantas might be simpler to change your two route templates so they aren't identical e.g. [HttpPatch("items1/{id}")]
and [HttpPatch("items2/{id}")]
.
Well, in my situation I have the endpoint /items/{id} to the document
{
"a": {
"b": []
"c": 1
}
}
and the first controller action
[HttpPatch("items/{id}")]
public IActionResult PatchAsync(string id, [FromBody]JsonPatchDocument<Document1> document1)
{
}
[{
"op": "replace",
"path": "/a",
"value": {"b": [], "c": 2}
}]
would allow me to replace the "a" property completely, while the second one
[HttpPatch("items/{id}")]
public IActionResult PatchAsync(string id, [FromBody]JsonPatchDocument<Document2> document2)
{
}
[{
"op": "add",
"path": "/a/b/-",
"value": 1
}]
would allow to add new thing into "b" array.
I have asked because I don't see it how a "shared" patch document can be created (because of different paths).
The only option I can think of right now is to have an action method
[HttpPatch("items/{id}/a")]
public IActionResult PatchAsync(string id, [FromBody]JsonPatchDocument<Document2> document2)
{
}
[{
"op": "add",
"path": "/b/-",
"value": 1
}]
but that does not look nice personally, to move "path" from the patch document to the route configuration, because it will expand the surface of the API and will require 2 endpoints:
I would suggest to have a built-in "path" constraint, if that is possible.
My issue "almost" makes no sense. It is possible to create such "shared" patch document. I am closing this issue.
Is it possible to have multiple controller actions which has a different signature?
I am getting the "Microsoft.AspNetCore.Mvc.Internal.AmbiguousActionException: Multiple actions matched." exception. Should I use a custom constraint in such case or JsonPatch has something built-in for such scenario?