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: Add KeysInValidator for validating fields containing specific keys #208

Merged
merged 6 commits into from
Jun 21, 2024

Conversation

bangadam
Copy link
Contributor

@bangadam bangadam commented Jun 17, 2024

References

Issue(s): #201
Discussion: None

Description

This validator ensures that all keys in the object under validation are part of the specified parameter slice. The main benefits of this addition are:

  • It provides a simple and efficient way to validate that an object contains only the allowed keys, which enhances data integrity and consistency.
  • It reduces the need for custom validation logic in individual projects, promoting code reusability and maintainability.

Possible drawbacks

  • The KeysIn validator assumes that the object being validated is a map[string]interface{}. If the context value is not of this type, the validation will fail

@System-Glitch System-Glitch self-requested a review June 18, 2024 07:49
Copy link
Member

@System-Glitch System-Glitch left a comment

Choose a reason for hiding this comment

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

You forgot to add the default language lines in lang/default.go.

validation/keysin_test.go Outdated Show resolved Hide resolved
validation/keysin_test.go Outdated Show resolved Hide resolved
validation/keysin.go Outdated Show resolved Hide resolved
@System-Glitch
Copy link
Member

The KeysIn validator assumes that the object being validated is a map[string]interface{}. If the context value is not of this type, the validation will fail

It is correct and this is how it should be done. 👍🏻

@coveralls
Copy link

coveralls commented Jun 18, 2024

Pull Request Test Coverage Report for Build 9555615659

Details

  • 10 of 19 (52.63%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.1%) to 97.174%

Changes Missing Coverage Covered Lines Changed/Added Lines %
validation/keysin.go 10 19 52.63%
Totals Coverage Status
Change from base Build 9526951349: -0.1%
Covered Lines: 6052
Relevant Lines: 6228

💛 - Coveralls

@System-Glitch
Copy link
Member

Implementation looks correct to me. The third test case should expect true instead of false.

@bangadam
Copy link
Contributor Author

Implementation looks correct to me. The third test case should expect true instead of false.

updated, please check

@coveralls
Copy link

coveralls commented Jun 19, 2024

Pull Request Test Coverage Report for Build 9573218396

Details

  • 21 of 23 (91.3%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.02%) to 97.288%

Changes Missing Coverage Covered Lines Changed/Added Lines %
validation/string.go 21 23 91.3%
Totals Coverage Status
Change from base Build 9526951349: -0.02%
Covered Lines: 6063
Relevant Lines: 6232

💛 - Coveralls

Copy link
Member

@System-Glitch System-Glitch left a comment

Choose a reason for hiding this comment

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

LGTM after these minor changes.

Can you move back the validator to a keysin.go file please? This doesn't belong to the string.go file since we are validating an object.

lang/default.go Outdated Show resolved Hide resolved
validation/string.go Outdated Show resolved Hide resolved
validation/string.go Outdated Show resolved Hide resolved
validation/string_test.go Outdated Show resolved Hide resolved
validation/string_test.go Outdated Show resolved Hide resolved
validation/string_test.go Outdated Show resolved Hide resolved
validation/string_test.go Outdated Show resolved Hide resolved
@System-Glitch System-Glitch self-assigned this Jun 21, 2024
@coveralls
Copy link

coveralls commented Jun 21, 2024

Pull Request Test Coverage Report for Build 9611514401

Details

  • 23 of 23 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 97.345%

Totals Coverage Status
Change from base Build 9611369421: 0.01%
Covered Lines: 6123
Relevant Lines: 6290

💛 - Coveralls

@System-Glitch System-Glitch merged commit e9e30ad into go-goyave:master Jun 21, 2024
4 checks passed
@System-Glitch
Copy link
Member

Thank you very much! 🎉

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.

3 participants