-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## PR This PR does the following: - Reverts #1122 - Re-implements struct level validations in a different way which also support `or`s etc.. which previous implementation did not. - Adds special case to ignore `required` validation on non-pointer structs to preserve pre-struct level tag validation support. - Added new `WithRequiredStructEnabled` option to opt-in to this new behaviour, that will become the default in the next major version.
- Loading branch information
Showing
12 changed files
with
212 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package validator | ||
|
||
// Option represents a configurations option to be applied to validator during initialization. | ||
type Option func(*Validate) | ||
|
||
// WithRequiredStructEnabled enables required tag on non-pointer structs to be applied instead of ignored. | ||
// | ||
// This was made opt-in behaviour in order to maintain backward compatibility with the behaviour previous | ||
// to being able to apply struct level validations on struct fields directly. | ||
// | ||
// It is recommended you enabled this as it will be the default behaviour in v11+ | ||
func WithRequiredStructEnabled() Option { | ||
return func(v *Validate) { | ||
v.requiredStructEnabled = true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.