Skip to content

Conversation

@arxeiss
Copy link

@arxeiss arxeiss commented May 7, 2025

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:

  • Tests exist or have been written that cover this particular change.

@go-playground/validator-maintainers

Fixing #1413 and #776

@arxeiss arxeiss requested a review from a team as a code owner May 7, 2025 13:51
@coveralls
Copy link

Coverage Status

coverage: 73.672% (+0.02%) from 73.655%
when pulling f881394 on arxeiss:master
into 20f7df6 on go-playground:master.

@ns-vchen
Copy link

@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

@deankarn
Copy link
Contributor

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:

  1. Allow blank values in the cache extraction.
  2. 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.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants