Remove the necessity for tag in struct and slice validation
guiferpa opened this issue · 0 comments
guiferpa commented
It's a problem how gody works today because of necessity for tags in slice and struct.
An example about how it works today:
type Owner struct {
Name string `validate:"not_empty"`
}
type Task struct {
Title string `validate:"not_empty"`
Description string `validate:"max_bound=140"`
}
type TaskList struct {
Owner Owner `validate:"required"` // It's necessary
Tasks []Task `validate:"required"` // It's necessary
}
The tag with some value is necessary for validation of fields above (Owner
and Tasks
).
Take a look at line: https://github.com/guiferpa/gody/blob/master/serialize.go#L49-L53
There is the condition to serialize a field. However today it's just verified if it has a tag with any value or haven't, if it contains tag with some value it'll be serialize but if not it'll be ignored.
The purpose is to make the validation even if there's tag or not. Letting the struct typing more clean like this example below:
...
type TaskList struct {
Owner Owner // Tag isn't necessary anymore
Tasks []Task // Tag isn't necessary anymore
}