Open akalcik opened 5 years ago
Seems to be relevant #6077
Same problem here. I'm also using overload
patch.ApplyTo(model, ModelState);
and if(!ModelState.IsValid)
leads to unexpected behavior
Thanks for contacting us, @akalcik. Feel free to send a PR for this and we'll happily consider it. As this will potentially be a breaking change, this should be backed by some compatibility option.
Assigned to @pranavkm for further conversations on JsonPatch support.
Thanks for contacting us.
We're moving this issue to the .NET 8 Planning
milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.
When
ModelState.IsValid
is called on model which is provided as a input parameter and the model isn't valid,ProblemDetails
is generated and provided as a body output by all operations with status code >= 400.In case above when
ToDoInsertModel
validation fails becauseDescription
is null,BadRequest
returns following response:Now implementation of
HttpPatch
Method withJsonPatchDocument.ApplyTo<T>
.The output is different.
The reason for this is that
patch.ApplyTo(toDoFromDatabase, ModelState);
doesn't invoke validation on the target model, which should be expected behavior. Because of thisTryValidateModel(toDoFromDatabase);
need to be called explicitly, andModeState
object must be provided as an input forBadRequest
object, which leads to inconsistent output. Need to notice when you don't provideModeState
you don't get any validation details errors.