diff --git a/common/customizable_schema.go b/common/customizable_schema.go index 75f1308d8e..14396c2f16 100644 --- a/common/customizable_schema.go +++ b/common/customizable_schema.go @@ -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 diff --git a/common/customizable_schema_test.go b/common/customizable_schema_test.go index eda3b0e2da..7db449bb5a 100644 --- a/common/customizable_schema_test.go +++ b/common/customizable_schema_test.go @@ -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")