Skip to content

Commit e7175ba

Browse files
committed
encoding/jsonschema: implement "not"
This change implements the "not" keyword using `matchN`. No test regressions were encountered when updating the external test data. One regression was encountered when updating the regular test data, and filed as a comment under issue #3422. This required updating the test data to get the test to pass. Signed-off-by: Roger Peppe <[email protected]> Change-Id: Ib2537af7424895843eebc1b915bc643894637afa Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1200530 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
1 parent 32865bc commit e7175ba

File tree

22 files changed

+222
-928
lines changed

22 files changed

+222
-928
lines changed

cue.mod/pkg/github.com/SchemaStore/schemastore/src/schemas/json/github-workflow.cue

+20-2
Original file line numberDiff line numberDiff line change
@@ -624,15 +624,33 @@ import "strings"
624624

625625
#path: #globs
626626

627-
#ref: null | {
627+
#ref: matchN(1, [matchN(3, [matchN(0, [null | bool | number | string | [...] | {
628+
branches!: _
629+
"branches-ignore"!: _
630+
...
631+
}]) & {
632+
...
633+
}, matchN(0, [null | bool | number | string | [...] | {
634+
tags!: _
635+
"tags-ignore"!: _
636+
...
637+
}]) & {
638+
...
639+
}, matchN(0, [null | bool | number | string | [...] | {
640+
paths!: _
641+
"paths-ignore"!: _
642+
...
643+
}]) & {
644+
...
645+
}]), null]) & (null | {
628646
branches?: #branch
629647
"branches-ignore"?: #branch
630648
tags?: #branch
631649
"tags-ignore"?: #branch
632650
paths?: #path
633651
"paths-ignore"?: #path
634652
...
635-
}
653+
})
636654

637655
#shell: matchN(>=1, [string, "bash" | "pwsh" | "python" | "sh" | "cmd" | "powershell"])
638656

encoding/jsonschema/constraints.go

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ var constraints = []*constraint{
8888
p2("minLength", constraintMinLength),
8989
p3("minimum", constraintMinimum),
9090
p2("multipleOf", constraintMultipleOf),
91+
p3("not", constraintNot),
9192
p3("oneOf", constraintOneOf),
9293
p2("nullable", constraintNullable),
9394
p2("pattern", constraintPattern),

encoding/jsonschema/constraints_combinator.go

+12
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,15 @@ func constraintOneOf(key string, n cue.Value, s *state) {
136136
// TODO: oneOf({a:x}, {b:y}, ..., not(anyOf({a:x}, {b:y}, ...))),
137137
// can be translated to {} | {a:x}, {b:y}, ...
138138
}
139+
140+
func constraintNot(key string, n cue.Value, s *state) {
141+
subSchema := s.schema(n)
142+
s.all.add(n, ast.NewCall(
143+
ast.NewIdent("matchN"),
144+
&ast.BasicLit{
145+
Kind: token.INT,
146+
Value: "0",
147+
},
148+
ast.NewList(subSchema),
149+
))
150+
}
+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Generated by teststats. DO NOT EDIT
22
v2:
3-
schema extract (pass / total): 975 / 1637 = 59.6%
4-
tests (pass / total): 3140 / 7175 = 43.8%
5-
tests on extracted schemas (pass / total): 3140 / 3546 = 88.6%
3+
schema extract (pass / total): 1015 / 1637 = 62.0%
4+
tests (pass / total): 3308 / 7175 = 46.1%
5+
tests on extracted schemas (pass / total): 3308 / 3722 = 88.9%
66

77
v3:
8-
schema extract (pass / total): 967 / 1637 = 59.1%
9-
tests (pass / total): 3074 / 7175 = 42.8%
10-
tests on extracted schemas (pass / total): 3074 / 3538 = 86.9%
8+
schema extract (pass / total): 1003 / 1637 = 61.3%
9+
tests (pass / total): 3214 / 7175 = 44.8%
10+
tests on extracted schemas (pass / total): 3214 / 3678 = 87.4%

0 commit comments

Comments
 (0)