Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: omit anonymous embedded struct #1211

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

abemedia
Copy link

@abemedia abemedia commented Jan 10, 2024

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 option WithOmitAnonymousName would instead display Foo.Baz.

type Foo struct {
  Bar
}

type Bar struct {
  Baz string `validate:"required"`
}

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:

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

@go-playground/validator-maintainers

@abemedia abemedia requested a review from a team as a code owner January 10, 2024 18:20
@coveralls
Copy link

Coverage Status

coverage: 73.896% (-0.007%) from 73.903%
when pulling 80db7ad on abemedia:feat/omit-anonymous-embedded-struct
into 84254ae on go-playground:master.

@abemedia
Copy link
Author

@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.

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.

Method Struct(...) forms keys for embedded structures incorrectly
2 participants