Skip to content

Commit

Permalink
fix(validation): fix path for additional properties validation (#102)
Browse files Browse the repository at this point in the history
When it fails validating a child, the error path should be for the child key, not the root.
  • Loading branch information
carolynvs authored Jun 3, 2021
1 parent 36b0071 commit bc24978
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 6 additions & 4 deletions keywords_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
12 changes: 12 additions & 0 deletions schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit bc24978

Please sign in to comment.