-
Notifications
You must be signed in to change notification settings - Fork 63
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
validation: Allow loose validation for sets #247
validation: Allow loose validation for sets #247
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: apelisse The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
typed/typed.go
Outdated
type ValidationOptions int | ||
|
||
const ( | ||
Loose ValidationOptions = iota |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I'm actually renaming this AllowDuplicates
since .. that's a lot closer to what it actually is.
If a set (or associative lists keys) has duplicated elements, then this will not fail the validation. Everything is still the same.
1f9a5be
to
db12191
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
easy to follow
/lgtm
// AsTyped accepts a value and a type and returns a TypedValue. 'v' must have | ||
// type 'typeName' in the schema. An error is returned if the v doesn't conform | ||
// to the schema. | ||
func AsTyped(v value.Value, s *schema.Schema, typeRef schema.TypeRef) (*TypedValue, error) { | ||
func AsTyped(v value.Value, s *schema.Schema, typeRef schema.TypeRef, opts ...ValidationOptions) (*TypedValue, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've decided to use that convention since we want to backport this code and I didn't want to break the compatibility with existing code (forcing me to bump the major version). Alternative could be to make a AsTypedWithDuplicates
/hold edit: whoops too late |
No worries, let me know what you want me to address, I'll focus on that before continuing. |
@@ -24,16 +24,24 @@ import ( | |||
"sigs.k8s.io/structured-merge-diff/v4/value" | |||
) | |||
|
|||
// ValidationOptions is the list of all the options available when running the validation. | |||
type ValidationOptions int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think it would be better if this was not an int and instead something like a func (v *validatingObjectWalker)
or something similar so that we aren't bound to very simple options in the future.
If a set (or associative lists keys) has duplicated elements, then this will not fail the validation. Everything else is still the same.
/assign @alexzielenski