Skip to content

Commit

Permalink
internal/core/validate: fix validation of disjunctions for evalv3
Browse files Browse the repository at this point in the history
The v3 evaluator represents disjunctions slightly differently
from v2. The validator did not take this into account and did
not dereference disjunctions when needed.

Fixes #3422

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: Idb47d65d9ba44ebb7d133feee33dc71dddb13314
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1200732
Reviewed-by: Roger Peppe <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
mpvl committed Sep 5, 2024
1 parent 2d329b5 commit 2fb6f45
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 184 deletions.
4 changes: 2 additions & 2 deletions encoding/jsonschema/external_teststats.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ v2:

v3:
schema extract (pass / total): 1003 / 1637 = 61.3%
tests (pass / total): 3214 / 7175 = 44.8%
tests on extracted schemas (pass / total): 3214 / 3678 = 87.4%
tests (pass / total): 3259 / 7175 = 45.4%
tests on extracted schemas (pass / total): 3259 / 3678 = 88.6%
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,14 @@
"data": {
"foo": "baz"
},
"valid": false,
"skip": {
"v3": "unexpected success"
}
"valid": false
},
{
"description": "mismatch first",
"data": {
"bar": 2
},
"valid": false,
"skip": {
"v3": "unexpected success"
}
"valid": false
},
{
"description": "wrong type",
Expand Down Expand Up @@ -124,31 +118,22 @@
"bar": 2,
"baz": null
},
"valid": false,
"skip": {
"v3": "unexpected success"
}
"valid": false
},
{
"description": "mismatch second allOf",
"data": {
"foo": "quux",
"bar": 2
},
"valid": false,
"skip": {
"v3": "unexpected success"
}
"valid": false
},
{
"description": "mismatch both",
"data": {
"bar": 2
},
"valid": false,
"skip": {
"v3": "unexpected success"
}
"valid": false
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,14 @@
"data": {
"bar": 2
},
"valid": true,
"skip": {
"v3": "invalid value {bar:2} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:int},null | bool | number | string | [] | {foo!:string}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:1:1\n generated.cue:2:8\n instance.json:1:1\n"
}
"valid": true
},
{
"description": "second oneOf valid (complex)",
"data": {
"foo": "baz"
},
"valid": true,
"skip": {
"v3": "invalid value {foo:\"baz\"} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:int},null | bool | number | string | [] | {foo!:string}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:1:1\n generated.cue:2:8\n instance.json:1:1\n"
}
"valid": true
},
{
"description": "both oneOf valid (complex)",
Expand Down Expand Up @@ -330,20 +324,14 @@
"data": {
"bar": 8
},
"valid": true,
"skip": {
"v3": "invalid value {bar:8} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:_,baz?:_},null | bool | number | string | [] | {foo!:_}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:1:1\n generated.cue:2:8\n instance.json:1:1\n"
}
"valid": true
},
{
"description": "second oneOf valid",
"data": {
"foo": "foo"
},
"valid": true,
"skip": {
"v3": "invalid value {foo:\"foo\"} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:_,baz?:_},null | bool | number | string | [] | {foo!:_}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:1:1\n generated.cue:2:8\n instance.json:1:1\n"
}
"valid": true
},
{
"description": "both oneOf valid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,14 @@
"data": {
"foo": "baz"
},
"valid": false,
"skip": {
"v3": "unexpected success"
}
"valid": false
},
{
"description": "mismatch first",
"data": {
"bar": 2
},
"valid": false,
"skip": {
"v3": "unexpected success"
}
"valid": false
},
{
"description": "wrong type",
Expand Down Expand Up @@ -124,31 +118,22 @@
"bar": 2,
"baz": null
},
"valid": false,
"skip": {
"v3": "unexpected success"
}
"valid": false
},
{
"description": "mismatch second allOf",
"data": {
"foo": "quux",
"bar": 2
},
"valid": false,
"skip": {
"v3": "unexpected success"
}
"valid": false
},
{
"description": "mismatch both",
"data": {
"bar": 2
},
"valid": false,
"skip": {
"v3": "unexpected success"
}
"valid": false
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,14 @@
"data": {
"bar": 2
},
"valid": true,
"skip": {
"v3": "invalid value {bar:2} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:int},null | bool | number | string | [] | {foo!:string}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:1:1\n generated.cue:2:8\n instance.json:1:1\n"
}
"valid": true
},
{
"description": "second oneOf valid (complex)",
"data": {
"foo": "baz"
},
"valid": true,
"skip": {
"v3": "invalid value {foo:\"baz\"} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:int},null | bool | number | string | [] | {foo!:string}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:1:1\n generated.cue:2:8\n instance.json:1:1\n"
}
"valid": true
},
{
"description": "both oneOf valid (complex)",
Expand Down Expand Up @@ -330,20 +324,14 @@
"data": {
"bar": 8
},
"valid": true,
"skip": {
"v3": "invalid value {bar:8} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:_,baz?:_},null | bool | number | string | [] | {foo!:_}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:1:1\n generated.cue:2:8\n instance.json:1:1\n"
}
"valid": true
},
{
"description": "second oneOf valid",
"data": {
"foo": "foo"
},
"valid": true,
"skip": {
"v3": "invalid value {foo:\"foo\"} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:_,baz?:_},null | bool | number | string | [] | {foo!:_}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:1:1\n generated.cue:2:8\n instance.json:1:1\n"
}
"valid": true
},
{
"description": "both oneOf valid",
Expand Down
25 changes: 5 additions & 20 deletions encoding/jsonschema/testdata/external/tests/draft4/allOf.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,14 @@
"data": {
"foo": "baz"
},
"valid": false,
"skip": {
"v3": "unexpected success"
}
"valid": false
},
{
"description": "mismatch first",
"data": {
"bar": 2
},
"valid": false,
"skip": {
"v3": "unexpected success"
}
"valid": false
},
{
"description": "wrong type",
Expand Down Expand Up @@ -122,31 +116,22 @@
"bar": 2,
"baz": null
},
"valid": false,
"skip": {
"v3": "unexpected success"
}
"valid": false
},
{
"description": "mismatch second allOf",
"data": {
"foo": "quux",
"bar": 2
},
"valid": false,
"skip": {
"v3": "unexpected success"
}
"valid": false
},
{
"description": "mismatch both",
"data": {
"bar": 2
},
"valid": false,
"skip": {
"v3": "unexpected success"
}
"valid": false
}
]
},
Expand Down
20 changes: 4 additions & 16 deletions encoding/jsonschema/testdata/external/tests/draft4/oneOf.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,14 @@
"data": {
"bar": 2
},
"valid": true,
"skip": {
"v3": "invalid value {bar:2} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:int},null | bool | number | string | [] | {foo!:string}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n"
}
"valid": true
},
{
"description": "second oneOf valid (complex)",
"data": {
"foo": "baz"
},
"valid": true,
"skip": {
"v3": "invalid value {foo:\"baz\"} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:int},null | bool | number | string | [] | {foo!:string}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n"
}
"valid": true
},
{
"description": "both oneOf valid (complex)",
Expand Down Expand Up @@ -240,20 +234,14 @@
"data": {
"bar": 8
},
"valid": true,
"skip": {
"v3": "invalid value {bar:8} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:_,baz?:_},null | bool | number | string | [] | {foo!:_}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n"
}
"valid": true
},
{
"description": "second oneOf valid",
"data": {
"foo": "foo"
},
"valid": true,
"skip": {
"v3": "invalid value {foo:\"foo\"} (does not satisfy matchN(1, [null | bool | number | string | [] | {bar!:_,baz?:_},null | bool | number | string | [] | {foo!:_}])): 2 matched, expected 1:\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\n"
}
"valid": true
},
{
"description": "both oneOf valid",
Expand Down
25 changes: 5 additions & 20 deletions encoding/jsonschema/testdata/external/tests/draft6/allOf.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,14 @@
"data": {
"foo": "baz"
},
"valid": false,
"skip": {
"v3": "unexpected success"
}
"valid": false
},
{
"description": "mismatch first",
"data": {
"bar": 2
},
"valid": false,
"skip": {
"v3": "unexpected success"
}
"valid": false
},
{
"description": "wrong type",
Expand Down Expand Up @@ -122,31 +116,22 @@
"bar": 2,
"baz": null
},
"valid": false,
"skip": {
"v3": "unexpected success"
}
"valid": false
},
{
"description": "mismatch second allOf",
"data": {
"foo": "quux",
"bar": 2
},
"valid": false,
"skip": {
"v3": "unexpected success"
}
"valid": false
},
{
"description": "mismatch both",
"data": {
"bar": 2
},
"valid": false,
"skip": {
"v3": "unexpected success"
}
"valid": false
}
]
},
Expand Down
Loading

0 comments on commit 2fb6f45

Please sign in to comment.