Skip to content

Commit

Permalink
fix not keyword preventing validation of allOf etc. keywords, closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin authored Jul 4, 2021
1 parent 4706efd commit 674688c
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lib/compile/validate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,11 @@ export class KeywordCxt implements KeywordErrorCxt {
}

result(condition: Code, successAction?: () => void, failAction?: () => void): void {
this.gen.if(not(condition))
this.failResult(not(condition), successAction, failAction)
}

failResult(condition: Code, successAction?: () => void, failAction?: () => void): void {
this.gen.if(condition)
if (failAction) failAction()
else this.error()
if (successAction) {
Expand All @@ -383,7 +387,7 @@ export class KeywordCxt implements KeywordErrorCxt {
}

pass(condition: Code, failAction?: () => void): void {
this.result(condition, undefined, failAction)
this.failResult(not(condition), undefined, failAction)
}

fail(condition?: Code): void {
Expand Down
6 changes: 3 additions & 3 deletions lib/vocabularies/applicator/not.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ const def: CodeKeywordDefinition = {
valid
)

cxt.result(
cxt.failResult(
valid,
() => cxt.error(),
() => cxt.reset()
() => cxt.reset(),
() => cxt.error()
)
},
error: {message: "must NOT be valid"},
Expand Down
104 changes: 104 additions & 0 deletions spec/tests/issues/1668_not_with_other_keywords.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
[
{
"description": "not with allOf",
"schema": {
"allOf": [{"const": 1}],
"not": {"const": true}
},
"tests": [
{
"description": "valid",
"data": 1,
"valid": true
},
{
"description": "invalid (const)",
"data": 3,
"valid": false
},
{
"description": "invalid (not)",
"data": true,
"valid": false
}
]
},
{
"description": "not with anyOf",
"schema": {
"anyOf": [{"const": 1}],
"not": {"const": true}
},
"tests": [
{
"description": "valid",
"data": 1,
"valid": true
},
{
"description": "invalid (const)",
"data": 3,
"valid": false
},
{
"description": "invalid (not)",
"data": true,
"valid": false
}
]
},
{
"description": "not with oneOf",
"schema": {
"oneOf": [{"const": 1}],
"not": {"const": true}
},
"tests": [
{
"description": "valid",
"data": 1,
"valid": true
},
{
"description": "invalid (const)",
"data": 3,
"valid": false
},
{
"description": "invalid (not)",
"data": true,
"valid": false
}
]
},
{
"description": "not with properties",
"schema": {
"not": {
"properties": {
"foo": {"const": true}
}
},
"properties": {
"foo": {"const": 1}
}
},
"tests": [
{
"description": "valid",
"data": {"foo": 1},
"valid": true
},
{
"description": "invalid (const)",
"data": {"foo": 3},
"valid": false
},
{
"description": "invalid (not)",
"data": {"foo": true},
"valid": false
}
]
}
]

0 comments on commit 674688c

Please sign in to comment.