Feat: add tag to skip namespace in embedded structures
Enhances
Introducing new skipns validate tag, that allows to skip the name of embedded struct, when printing invalid field namspace.
type Outer struct {
Embedded `validate:"skipns"`
}
See #1413 for more extensive examples and discussion.
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.
@go-playground/validator-maintainers
Fixing #1413 and #776
coverage: 73.672% (+0.02%) from 73.655% when pulling f88139422ea70e9af9a12fb5e1056d42344530e6 on arxeiss:master into 20f7df64bdd443294349535a5da244ad0b2af71a on go-playground:master.
@arxeiss thanks for having this PR, I'm expecting the merge BTW, I notice that you also need to change the code here.
it is widely used by the struct-level validation
I'm going to have to think about this one because tags are for validation or guiding validation but this adds in a new paradigm where tags outside of validations themselves can dynamically affect other aspects of the validation runtime.
There's also the matter to think about order and ability to override or needing to become a core part of the runtime like omitempty.
I'm thinking this maybe could be better handled in the RegisterTagNameFunc function. With a few minor tweaks to:
- Allow blank values in the cache extraction.
- Add a few checks to ensure if the alt name is blank not to append to the namespace.
Here is a quick example where I did just that custom, just for the below case a few more checks would be necessary, but you get the idea. There would also be a question of backward compatibility, technically RegisterTagNameFunc was already supposed to act like this but hasn't been for a long time.