This PR adds an option to omit the names of anonymous embedded structs.
For example right now the code below would produce a namespace of Foo.Bar.Baz, with this code the option WithOmitAnonymousName would instead display Foo.Baz.
type Foo struct {
Bar
}
type Bar struct {
Baz string `validate:"required"`
}
Fixes #776
I'm not that familiar with the inner workings of validator so apologies if this is implemented in a terrible way. Happy to change it if the concept is acceptable and I get some pointers.
Make sure that you've checked the boxes below before you submit PR:
[x] Tests exist or have been written that cover this particular change.
coverage: 73.896% (-0.007%) from 73.903%
when pulling 80db7adbfa709bff4e2a37d8c757a8e607f3dd1d on abemedia:feat/omit-anonymous-embedded-struct
into 84254aeb5a59e615ec0b66ab53b988bc0677f55e on go-playground:master.
@deankarn any chance of getting this in?
If the approach using an option is not preferable I'm also happy to implement an alternative approach, for example having an inline tag the way the stdlib does for JSON.
Fixes Or Enhances
This PR adds an option to omit the names of anonymous embedded structs.
For example right now the code below would produce a namespace of
Foo.Bar.Baz
, with this code the optionWithOmitAnonymousName
would instead displayFoo.Baz
.I'm not that familiar with the inner workings of
validator
so apologies if this is implemented in a terrible way. Happy to change it if the concept is acceptable and I get some pointers.Make sure that you've checked the boxes below before you submit PR:
@go-playground/validator-maintainers