You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have looked at the examples provided that may showcase my question here?
Package version eg. v9, v10:
10.16.0
Issue, Question or Enhancement:
I recently changed a few of the DTOs in my project to use pointers to support PATCH requests.
For the most part this was uneventful and the recent addition of omitnil came in handy, however trying to make required fields optional for PATCH requests threw up some inconsistent behaviour.
I added a custom validator is_patch to check if the request was a PATCH and the assumption that replacing all required validations with required|is_patch would give the desired behavior.
But this didn't work, I debugged and saw my validator wasn't even getting called.
It's due to the required validator not checking nils (even though the implementation seems to support nil pointer checks). The first validator within an or seems to determine whether validation will check nils or not.
Hence, is_patch|required works fine.
I would assume that the order of validators when using or would be irrelevant, I couldn't find anything in the docs about this.
In addition the error logged says that validation failed on is_patch, which was not strictly correct.
Although I have a working solution, thought it was worth logging this, or perhaps there is an alternative/better approach that I've missed?
Code sample, to showcase or reproduce:
N/A
The text was updated successfully, but these errors were encountered:
Package version eg. v9, v10:
10.16.0
Issue, Question or Enhancement:
I recently changed a few of the DTOs in my project to use pointers to support PATCH requests.
For the most part this was uneventful and the recent addition of
omitnil
came in handy, however trying to makerequired
fields optional for PATCH requests threw up some inconsistent behaviour.I added a custom validator
is_patch
to check if the request was a PATCH and the assumption that replacing allrequired
validations withrequired|is_patch
would give the desired behavior.Validator implementation:
My custom validator is registered with check null as true:
But this didn't work, I debugged and saw my validator wasn't even getting called.
It's due to the
required
validator not checking nils (even though the implementation seems to support nil pointer checks). The first validator within an or seems to determine whether validation will check nils or not.Hence,
is_patch|required
works fine.I would assume that the order of validators when using or would be irrelevant, I couldn't find anything in the docs about this.
In addition the error logged says that validation failed on
is_patch
, which was not strictly correct.Although I have a working solution, thought it was worth logging this, or perhaps there is an alternative/better approach that I've missed?
Code sample, to showcase or reproduce:
N/A
The text was updated successfully, but these errors were encountered: