Skip to content

Commit 33fe828

Browse files
committed
encoding/jsonschema: add keyword TODOs
This adds entries for all the known JSON Schema keywords to the constraints map. This will enable us to distinguish unknown keywords from unimplemented keywords when implementing different strictness modes. It also acts as a handy reference for which features are unimplemented as yet. Signed-off-by: Roger Peppe <[email protected]> Change-Id: I9b2309f92cefaf6152d2ed397af2246e3c9a5aec Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1200533 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent e7175ba commit 33fe828

File tree

122 files changed

+844
-810
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+844
-810
lines changed

encoding/jsonschema/constraints.go

+34-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package jsonschema
1616

1717
import (
18+
"fmt"
19+
1820
"cuelang.org/go/cue"
1921
)
2022

@@ -44,6 +46,9 @@ var constraintMap = map[string]*constraint{}
4446

4547
func init() {
4648
for _, c := range constraints {
49+
if _, ok := constraintMap[c.key]; ok {
50+
panic(fmt.Errorf("duplicate constraint entry for %q", c.key))
51+
}
4752
constraintMap[c.key] = c
4853
}
4954
}
@@ -54,51 +59,74 @@ func init() {
5459
const numPhases = 5
5560

5661
var constraints = []*constraint{
62+
todo("$anchor", vfrom(VersionDraft2019_09)),
5763
p2d("$comment", constraintComment, vfrom(VersionDraft7)),
5864
p2("$defs", constraintAddDefinitions),
65+
todo("$dynamicAnchor", vfrom(VersionDraft2020_12)),
66+
todo("$dynamicRef", vfrom(VersionDraft2020_12)),
5967
p1d("$id", constraintID, vfrom(VersionDraft6)),
60-
p0("$schema", constraintSchema),
68+
todo("$recursiveAnchor", vbetween(VersionDraft2019_09, VersionDraft2020_12)),
69+
todo("$recursiveRef", vbetween(VersionDraft2019_09, VersionDraft2020_12)),
6170
p2("$ref", constraintRef),
62-
p2("additionalItems", constraintAdditionalItems),
71+
p0("$schema", constraintSchema),
72+
todo("$vocabulary", vfrom(VersionDraft2019_09)),
73+
p2d("additionalItems", constraintAdditionalItems, vto(VersionDraft2019_09)),
6374
p4("additionalProperties", constraintAdditionalProperties),
6475
p3("allOf", constraintAllOf),
6576
p3("anyOf", constraintAnyOf),
6677
p2d("const", constraintConst, vfrom(VersionDraft6)),
67-
p1d("minContains", constraintMinContains, vfrom(VersionDraft2019_09)),
68-
p1d("maxContains", constraintMaxContains, vfrom(VersionDraft2019_09)),
6978
p2d("contains", constraintContains, vfrom(VersionDraft6)),
7079
p2d("contentEncoding", constraintContentEncoding, vfrom(VersionDraft7)),
7180
p2d("contentMediaType", constraintContentMediaType, vfrom(VersionDraft7)),
81+
todo("contentSchema", vfrom(VersionDraft2019_09)),
7282
p2("default", constraintDefault),
7383
p2("definitions", constraintAddDefinitions),
7484
p2("dependencies", constraintDependencies),
85+
todo("dependentRequired", vfrom(VersionDraft2019_09)),
86+
todo("dependentSchemas", vfrom(VersionDraft2019_09)),
7587
p2("deprecated", constraintDeprecated),
7688
p2("description", constraintDescription),
89+
todo("else", vfrom(VersionDraft7)),
7790
p2("enum", constraintEnum),
7891
p2d("examples", constraintExamples, vfrom(VersionDraft6)),
7992
p2("exclusiveMaximum", constraintExclusiveMaximum),
8093
p2("exclusiveMinimum", constraintExclusiveMinimum),
94+
todo("format", allVersions),
8195
p1d("id", constraintID, vto(VersionDraft4)),
96+
todo("if", vfrom(VersionDraft7)),
8297
p2("items", constraintItems),
83-
p2("minItems", constraintMinItems),
98+
p1d("maxContains", constraintMaxContains, vfrom(VersionDraft2019_09)),
8499
p2("maxItems", constraintMaxItems),
85100
p2("maxLength", constraintMaxLength),
86101
p2("maxProperties", constraintMaxProperties),
87102
p3("maximum", constraintMaximum),
103+
p1d("minContains", constraintMinContains, vfrom(VersionDraft2019_09)),
104+
p2("minItems", constraintMinItems),
88105
p2("minLength", constraintMinLength),
106+
todo("minProperties", allVersions),
89107
p3("minimum", constraintMinimum),
90108
p2("multipleOf", constraintMultipleOf),
91109
p3("not", constraintNot),
92-
p3("oneOf", constraintOneOf),
93110
p2("nullable", constraintNullable),
111+
p3("oneOf", constraintOneOf),
94112
p2("pattern", constraintPattern),
95113
p3("patternProperties", constraintPatternProperties),
114+
todo("prefixItems", vfrom(VersionDraft2020_12)),
96115
p2("properties", constraintProperties),
97116
p2d("propertyNames", constraintPropertyNames, vfrom(VersionDraft6)),
117+
todo("readOnly", vfrom(VersionDraft7)),
98118
p3("required", constraintRequired),
119+
todo("then", vfrom(VersionDraft7)),
99120
p2("title", constraintTitle),
100121
p2("type", constraintType),
122+
todo("unevaluatedItems", vfrom(VersionDraft2019_09)),
123+
todo("unevaluatedProperties", vfrom(VersionDraft2019_09)),
101124
p2("uniqueItems", constraintUniqueItems),
125+
todo("writeOnly", vfrom(VersionDraft7)),
126+
}
127+
128+
func todo(name string, versions versionSet) *constraint {
129+
return &constraint{key: name, phase: 1, versions: versions, fn: constraintTODO}
102130
}
103131

104132
func p0(name string, f constraintFunc) *constraint {

encoding/jsonschema/constraints_meta.go

+6
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,9 @@ func constraintSchema(key string, n cue.Value, s *state) {
5959
s.schemaVersionPresent = true
6060
s.schemaVersion = sv
6161
}
62+
63+
func constraintTODO(key string, n cue.Value, s *state) {
64+
if s.cfg.Strict {
65+
s.errf(n, `keyword %q not yet implemented`, key)
66+
}
67+
}

encoding/jsonschema/testdata/external/tests/draft2019-09/additionalProperties.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@
281281
"additionalProperties": false
282282
},
283283
"skip": {
284-
"v2": "extract error: unsupported constraint \"dependentSchemas\"",
285-
"v3": "extract error: unsupported constraint \"dependentSchemas\""
284+
"v2": "extract error: keyword \"dependentSchemas\" not yet implemented",
285+
"v3": "extract error: keyword \"dependentSchemas\" not yet implemented"
286286
},
287287
"tests": [
288288
{

encoding/jsonschema/testdata/external/tests/draft2019-09/anchor.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@
141141
"$ref": "child1#my_anchor"
142142
},
143143
"skip": {
144-
"v2": "extract error: unsupported constraint \"$anchor\" (and 4 more errors)",
145-
"v3": "extract error: unsupported constraint \"$anchor\" (and 4 more errors)"
144+
"v2": "extract error: keyword \"$anchor\" not yet implemented (and 4 more errors)",
145+
"v3": "extract error: keyword \"$anchor\" not yet implemented (and 4 more errors)"
146146
},
147147
"tests": [
148148
{

encoding/jsonschema/testdata/external/tests/draft2019-09/contains.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@
202202
}
203203
},
204204
"skip": {
205-
"v2": "extract error: unsupported constraint \"if\" (and 1 more errors)",
206-
"v3": "extract error: unsupported constraint \"if\" (and 1 more errors)"
205+
"v2": "extract error: keyword \"if\" not yet implemented (and 1 more errors)",
206+
"v3": "extract error: keyword \"if\" not yet implemented (and 1 more errors)"
207207
},
208208
"tests": [
209209
{

encoding/jsonschema/testdata/external/tests/draft2019-09/content.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@
9696
}
9797
},
9898
"skip": {
99-
"v2": "extract error: unsupported constraint \"contentSchema\"",
100-
"v3": "extract error: unsupported constraint \"contentSchema\""
99+
"v2": "extract error: keyword \"contentSchema\" not yet implemented",
100+
"v3": "extract error: keyword \"contentSchema\" not yet implemented"
101101
},
102102
"tests": [
103103
{

encoding/jsonschema/testdata/external/tests/draft2019-09/dependentRequired.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
}
1111
},
1212
"skip": {
13-
"v2": "extract error: unsupported constraint \"dependentRequired\"",
14-
"v3": "extract error: unsupported constraint \"dependentRequired\""
13+
"v2": "extract error: keyword \"dependentRequired\" not yet implemented",
14+
"v3": "extract error: keyword \"dependentRequired\" not yet implemented"
1515
},
1616
"tests": [
1717
{
@@ -97,8 +97,8 @@
9797
}
9898
},
9999
"skip": {
100-
"v2": "extract error: unsupported constraint \"dependentRequired\"",
101-
"v3": "extract error: unsupported constraint \"dependentRequired\""
100+
"v2": "extract error: keyword \"dependentRequired\" not yet implemented",
101+
"v3": "extract error: keyword \"dependentRequired\" not yet implemented"
102102
},
103103
"tests": [
104104
{
@@ -144,8 +144,8 @@
144144
}
145145
},
146146
"skip": {
147-
"v2": "extract error: unsupported constraint \"dependentRequired\"",
148-
"v3": "extract error: unsupported constraint \"dependentRequired\""
147+
"v2": "extract error: keyword \"dependentRequired\" not yet implemented",
148+
"v3": "extract error: keyword \"dependentRequired\" not yet implemented"
149149
},
150150
"tests": [
151151
{
@@ -233,8 +233,8 @@
233233
}
234234
},
235235
"skip": {
236-
"v2": "extract error: unsupported constraint \"dependentRequired\"",
237-
"v3": "extract error: unsupported constraint \"dependentRequired\""
236+
"v2": "extract error: keyword \"dependentRequired\" not yet implemented",
237+
"v3": "extract error: keyword \"dependentRequired\" not yet implemented"
238238
},
239239
"tests": [
240240
{

encoding/jsonschema/testdata/external/tests/draft2019-09/dependentSchemas.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
}
1818
},
1919
"skip": {
20-
"v2": "extract error: unsupported constraint \"dependentSchemas\"",
21-
"v3": "extract error: unsupported constraint \"dependentSchemas\""
20+
"v2": "extract error: keyword \"dependentSchemas\" not yet implemented",
21+
"v3": "extract error: keyword \"dependentSchemas\" not yet implemented"
2222
},
2323
"tests": [
2424
{
@@ -121,8 +121,8 @@
121121
}
122122
},
123123
"skip": {
124-
"v2": "extract error: unsupported constraint \"dependentSchemas\"",
125-
"v3": "extract error: unsupported constraint \"dependentSchemas\""
124+
"v2": "extract error: keyword \"dependentSchemas\" not yet implemented",
125+
"v3": "extract error: keyword \"dependentSchemas\" not yet implemented"
126126
},
127127
"tests": [
128128
{
@@ -186,8 +186,8 @@
186186
}
187187
},
188188
"skip": {
189-
"v2": "extract error: unsupported constraint \"dependentSchemas\"",
190-
"v3": "extract error: unsupported constraint \"dependentSchemas\""
189+
"v2": "extract error: keyword \"dependentSchemas\" not yet implemented",
190+
"v3": "extract error: keyword \"dependentSchemas\" not yet implemented"
191191
},
192192
"tests": [
193193
{
@@ -259,8 +259,8 @@
259259
}
260260
},
261261
"skip": {
262-
"v2": "extract error: unsupported constraint \"dependentSchemas\"",
263-
"v3": "extract error: unsupported constraint \"dependentSchemas\""
262+
"v2": "extract error: keyword \"dependentSchemas\" not yet implemented",
263+
"v3": "extract error: keyword \"dependentSchemas\" not yet implemented"
264264
},
265265
"tests": [
266266
{

0 commit comments

Comments
 (0)