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

Extending customizable schema with AtLeastOneOf, ExactlyOneOf, RequiredWith #3182

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion common/customizable_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,36 @@ func (s *CustomizableSchema) SetMinItems(value int) *CustomizableSchema {

func (s *CustomizableSchema) SetConflictsWith(value []string) *CustomizableSchema {
if len(value) == 0 {
panic("SetConflictsWith cannot take in empty list")
panic("SetConflictsWith cannot take in an empty list")
}
s.Schema.ConflictsWith = value
return s
}

func (s *CustomizableSchema) SetExactlyOneOf(value []string) *CustomizableSchema {
if len(value) == 0 {
panic("SetExactlyOneOf cannot take in an empty list")
}
s.Schema.ExactlyOneOf = value
return s
}

func (s *CustomizableSchema) SetAtLeastOneOf(value []string) *CustomizableSchema {
if len(value) == 0 {
panic("SetAtLeastOneOf cannot take in an empty list")
}
s.Schema.AtLeastOneOf = value
return s
}

func (s *CustomizableSchema) SetRequiredWith(value []string) *CustomizableSchema {
if len(value) == 0 {
panic("SetRequiredWith cannot take in an empty list")
}
s.Schema.RequiredWith = value
return s
}

func (s *CustomizableSchema) SetDeprecated(reason string) *CustomizableSchema {
s.Schema.Deprecated = reason
return s
Expand Down
14 changes: 14 additions & 0 deletions common/customizable_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ func TestCustomizableSchemaSetConflictsWith(t *testing.T) {
assert.Truef(t, len(testCustomizableSchemaScm["non_optional"].ConflictsWith) == 1, "conflictsWith should be set in field: non_optional")
}

func TestCustomizableSchemaSetExactlyOneOf(t *testing.T) {
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetExactlyOneOf([]string{"abc"})
assert.Truef(t, len(testCustomizableSchemaScm["non_optional"].ExactlyOneOf) == 1, "ExactlyOneOf should be set in field: non_optional")
}

func TestCustomizableSchemaAtLeastOneOf(t *testing.T) {
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetAtLeastOneOf([]string{"abc"})
assert.Truef(t, len(testCustomizableSchemaScm["non_optional"].AtLeastOneOf) == 1, "AtLeastOneOf should be set in field: non_optional")
}

func TestCustomizableSchemaSetRequiredWith(t *testing.T) {
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetRequiredWith([]string{"abc"})
assert.Truef(t, len(testCustomizableSchemaScm["non_optional"].RequiredWith) == 1, "RequiredWith should be set in field: non_optional")
}
func TestCustomizableSchemaSetDeprecated(t *testing.T) {
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetDeprecated("test reason")
assert.Truef(t, testCustomizableSchemaScm["non_optional"].Deprecated == "test reason", "deprecated should be overriden in field: non_optional")
Expand Down
Loading