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

fix: Generate proper error message for 'unique' validation tag #967

Merged
merged 1 commit into from
Jan 6, 2025

Conversation

jackchenjc
Copy link
Contributor

fixes #966

If your build fails due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/go-mod-core-contracts/blob/main/.github/Contributing.md

PR Checklist

Please check if your PR fulfills the following requirements:

  • I am not introducing a breaking change (if you are, flag in conventional commit message with BREAKING CHANGE: describing the break)
  • I am not introducing a new dependency (add notes below if you are)
  • I have added unit tests for the new feature or bug fix (if not, why?)
  • I have fully tested (add details below) this the new feature or bug fix (if not, why?)
  • I have opened a PR for the related docs change (if not, why?)

Testing Instructions

type User struct {
	Name  string
	Roles []string `validate:"unique"`
}

type Group struct {
	Users []User `validate:"unique=Name"` // only one field can be specified
}

func main() {
	user := User{
		Name:  "admin",
		Roles: []string{"admin", "admin"},
	}

	err := common.Validate(user)
	// User.Roles field should only contain unique elements

	group := Group{
		Users: []User{
			{
				Name: "user1",
			},
			{
				Name: "user1",
			},
		},
	}

	err = common.Validate(group)
	// Group.Users field should only contain unique elements with unique 'Name' values
}

New Dependency Instructions (If applicable)

@jackchenjc jackchenjc requested a review from cloudxxx8 January 6, 2025 09:48
Copy link
Member

@cloudxxx8 cloudxxx8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cloudxxx8 cloudxxx8 merged commit 2aec29e into edgexfoundry:main Jan 6, 2025
3 checks passed
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.

The 'unique' validation tag should return a proper error message
2 participants