From bc2858fd53a00fa9a2ba500939777e5bc676d37b Mon Sep 17 00:00:00 2001 From: Carolyn Van Slyck Date: Wed, 25 Nov 2020 08:44:33 -0600 Subject: [PATCH] Fix path for additional properties validation When it fails validating a child, the error path should be for the child key, not the root. --- keywords_object.go | 10 ++++++---- schema_test.go | 12 ++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/keywords_object.go b/keywords_object.go index 62ce0de..f4f4d55 100644 --- a/keywords_object.go +++ b/keywords_object.go @@ -325,14 +325,16 @@ func (ap *AdditionalProperties) ValidateKeyword(ctx context.Context, currentStat if currentState.IsLocallyEvaluatedKey(key) { continue } - if ap.schemaType == schemaTypeFalse { - currentState.AddError(data, "additional properties are not allowed") - return - } + currentState.SetEvaluatedKey(key) subState.ClearState() subState.DescendInstanceFromState(currentState, key) + if ap.schemaType == schemaTypeFalse { + subState.AddError(data, "additional properties are not allowed") + return + } + (*Schema)(ap).ValidateKeyword(ctx, subState, obj[key]) currentState.UpdateEvaluatedPropsAndItems(subState) } diff --git a/schema_test.go b/schema_test.go index 1c30604..4defddf 100644 --- a/schema_test.go +++ b/schema_test.go @@ -666,6 +666,18 @@ func TestValidateBytes(t *testing.T) { `/1: false type should be string, got boolean`, `/2: type should be string, got null`, }}, + {`{ + "type": "object", + "properties" : { + }, + "additionalProperties" : false + }`, + `{ + "port": 80 +}`, + []string{ + `/port: {"port":80} additional properties are not allowed`, + }}, } for i, c := range cases {