Skip to content

Commit

Permalink
test: check if empty dependentRequired is ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
victoraugustolls committed Mar 13, 2024
1 parent 64fddff commit c8be1f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ func TestSchema(t *testing.T) {
input: struct {
Value string `json:"value,omitempty" dependentRequired:"dependent"`
Dependent string `json:"dependent,omitempty"`
Ignored string `json:"ignored,omitempty" dependentRequired:""`
}{},
expected: `{
"type": "object",
Expand All @@ -452,6 +453,9 @@ func TestSchema(t *testing.T) {
},
"dependent": {
"type": "string"
},
"ignored": {
"type": "string"
}
},
"dependentRequired": {
Expand Down
11 changes: 10 additions & 1 deletion validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ var validateTests = []struct {
errs: []string{"expected length >= 1"},
},
{
name: "dependentRequired empty success ",
name: "dependentRequired empty success",
typ: reflect.TypeOf(struct {
Value string `json:"value,omitempty" dependentRequired:"dependent"`
Dependent string `json:"dependent,omitempty"`
Expand All @@ -1036,6 +1036,15 @@ var validateTests = []struct {
input: map[string]any{"value": "abc", "dependent": "123"},
errs: nil,
},
{
name: "dependentRequired ignored success",
typ: reflect.TypeOf(struct {
Value string `json:"value,omitempty" dependentRequired:""`
Dependent string `json:"dependent,omitempty"`
}{}),
input: map[string]any{},
errs: nil,
},
{
name: "dependentRequired failure",
typ: reflect.TypeOf(struct {
Expand Down

0 comments on commit c8be1f9

Please sign in to comment.