govalidator
govalidator copied to clipboard
How can I cater for the case of conditional "required" ?
Hi.
I have a use case, for which I don't know how to set the flags from the validator.
Those are the required fields
{ "title": "This is the title", "caption": "This is the caption" }
title: []string{"required"}, caption: []string{"required"}
Now there may be a nested structure as such. The "attached_media" key is NOT required in the payload, BUT IF it is provided, then only some fields are required.
{ "title": "This is the title", "caption": "This is the caption", "attached_media": { "Yo": "Plop" } }
So this is my attempt at the settings, which fails,
title: []string{"required"}, caption: []string{"required"}` Yo: []string{"required"}
Bottom line, how can I set things u so that some nested keys are required ONLY if the parent key is there ?
@vcGF Unfortunately it doesn't have the feature right now. Hope next major release must have http.Request
object in rules and then you can make your own rules to this particular problem.
Hi . Just checking if there was any update on this feature :)
Need a PR to add this feature.