Skip to content

Commit 1940e1a

Browse files
authored
Extending customizable schema with AtLeastOneOf, ExactlyOneOf, RequiredWith (#3182)
* adding more customizable attributes * adding unit tests
1 parent d3acc7b commit 1940e1a

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

common/customizable_schema.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,36 @@ func (s *CustomizableSchema) SetMinItems(value int) *CustomizableSchema {
108108

109109
func (s *CustomizableSchema) SetConflictsWith(value []string) *CustomizableSchema {
110110
if len(value) == 0 {
111-
panic("SetConflictsWith cannot take in empty list")
111+
panic("SetConflictsWith cannot take in an empty list")
112112
}
113113
s.Schema.ConflictsWith = value
114114
return s
115115
}
116116

117+
func (s *CustomizableSchema) SetExactlyOneOf(value []string) *CustomizableSchema {
118+
if len(value) == 0 {
119+
panic("SetExactlyOneOf cannot take in an empty list")
120+
}
121+
s.Schema.ExactlyOneOf = value
122+
return s
123+
}
124+
125+
func (s *CustomizableSchema) SetAtLeastOneOf(value []string) *CustomizableSchema {
126+
if len(value) == 0 {
127+
panic("SetAtLeastOneOf cannot take in an empty list")
128+
}
129+
s.Schema.AtLeastOneOf = value
130+
return s
131+
}
132+
133+
func (s *CustomizableSchema) SetRequiredWith(value []string) *CustomizableSchema {
134+
if len(value) == 0 {
135+
panic("SetRequiredWith cannot take in an empty list")
136+
}
137+
s.Schema.RequiredWith = value
138+
return s
139+
}
140+
117141
func (s *CustomizableSchema) SetDeprecated(reason string) *CustomizableSchema {
118142
s.Schema.Deprecated = reason
119143
return s

common/customizable_schema_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ func TestCustomizableSchemaSetConflictsWith(t *testing.T) {
7373
assert.Truef(t, len(testCustomizableSchemaScm["non_optional"].ConflictsWith) == 1, "conflictsWith should be set in field: non_optional")
7474
}
7575

76+
func TestCustomizableSchemaSetExactlyOneOf(t *testing.T) {
77+
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetExactlyOneOf([]string{"abc"})
78+
assert.Truef(t, len(testCustomizableSchemaScm["non_optional"].ExactlyOneOf) == 1, "ExactlyOneOf should be set in field: non_optional")
79+
}
80+
81+
func TestCustomizableSchemaAtLeastOneOf(t *testing.T) {
82+
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetAtLeastOneOf([]string{"abc"})
83+
assert.Truef(t, len(testCustomizableSchemaScm["non_optional"].AtLeastOneOf) == 1, "AtLeastOneOf should be set in field: non_optional")
84+
}
85+
86+
func TestCustomizableSchemaSetRequiredWith(t *testing.T) {
87+
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetRequiredWith([]string{"abc"})
88+
assert.Truef(t, len(testCustomizableSchemaScm["non_optional"].RequiredWith) == 1, "RequiredWith should be set in field: non_optional")
89+
}
7690
func TestCustomizableSchemaSetDeprecated(t *testing.T) {
7791
CustomizeSchemaPath(testCustomizableSchemaScm, "non_optional").SetDeprecated("test reason")
7892
assert.Truef(t, testCustomizableSchemaScm["non_optional"].Deprecated == "test reason", "deprecated should be overriden in field: non_optional")

0 commit comments

Comments
 (0)