Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include child in failed validation path when disallowed additional properties are found #102

Merged
merged 1 commit into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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