thedevsaddam / govalidator

Validate Golang request data with simple rules. Highly inspired by Laravel's request validation.
MIT License
1.31k stars 124 forks source link

Nested validation doesn't working #124

Open ziasultan2 opened 10 months ago

ziasultan2 commented 10 months ago
{
    "pnr": "bddddd",
    "quantity": 100,
    "flightType": "direct",
    "platform": {
        "groupWindowOffice": true,
        "groupWindowB2B": false,
        "serpOffice": true,
        "serpB2B": false
    }
}

I want to validate the platform nested struct but it doesn't validating. Further more it gives me error if I try to create rules like document. So I've to do it like this way "platform.*"

    rules := govalidator.MapData{
        "pnr":         []string{"required"},
        "quantity":    []string{"required"},
        "platform.groupWindowOffice": []string{"required"},
        "platform.groupWindowB2B":    []string{"required"},
        "platform.serpOffice":        []string{"required"},
        "platform.serpB2B":           []string{"required"},
    }

But this is not validating the nested data it always shows me data required. Will you please help me to find the solution

Kirari04 commented 4 months ago

There is an example of a nested struct validation but it it might get things wrong if the nested struct has the same keys as the parent: https://github.com/thedevsaddam/govalidator/blob/master/doc/NESTED_STRUCT.md