From c8be1f910473a3460926a407d13f412dcb722f23 Mon Sep 17 00:00:00 2001 From: Victor Souza Date: Tue, 12 Mar 2024 23:36:34 -0300 Subject: [PATCH] test: check if empty dependentRequired is ignored --- schema_test.go | 4 ++++ validate_test.go | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/schema_test.go b/schema_test.go index 05134f81..99017395 100644 --- a/schema_test.go +++ b/schema_test.go @@ -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", @@ -452,6 +453,9 @@ func TestSchema(t *testing.T) { }, "dependent": { "type": "string" + }, + "ignored": { + "type": "string" } }, "dependentRequired": { diff --git a/validate_test.go b/validate_test.go index ab3e8641..a10eec0a 100644 --- a/validate_test.go +++ b/validate_test.go @@ -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"` @@ -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 {