Skip to content

Commit 239b405

Browse files
committed
encoding/jsonschema: always allow x- keywords
The OpenAPI specification explicitly allows "x-"-prefixed keywords and JSON Schema allows all unknown keywords, so it seems reasonable to always allow them, as the `StrictKeywords` flag is more oriented towards finding misspelled keywords than explicitly "out-of-spec" keywords. Signed-off-by: Roger Peppe <[email protected]> Change-Id: Iaa287b25faeb3cfc03225b06b97547a949026ba7 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201112 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent bef55cb commit 239b405

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

encoding/jsonschema/decode.go

+7
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,13 @@ func (s *state) schemaState(n cue.Value, types cue.Kind, idRef []label, isLogica
699699
// do multiple passes over the constraints to ensure they are done in order.
700700
for pass := 0; pass < numPhases; pass++ {
701701
state.processMap(n, func(key string, value cue.Value) {
702+
if strings.HasPrefix(key, "x-") {
703+
// A keyword starting with a leading x- is clearly
704+
// not intended to be a valid keyword, and is explicitly
705+
// allowed by OpenAPI. It seems reasonable that
706+
// this is not an error even with StrictKeywords enabled.
707+
return
708+
}
702709
// Convert each constraint into a either a value or a functor.
703710
c := constraintMap[key]
704711
if c == nil {

encoding/jsonschema/testdata/txtar/strictkeywords.txtar

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
#strictKeywords
2+
3+
Note: x-bar does _not_ cause an error even with StrictKeywords
4+
enabled.
5+
26
-- schema.json --
37
{
48
"$schema": "https://json-schema.org/draft/2020-12/schema",
59
"type": "number",
610
"$dynamicAnchor": "bar",
7-
"foo": true
11+
"foo": true,
12+
"x-bar": true
813
}
914
-- out/decode/extract --
1015
ERROR:

0 commit comments

Comments
 (0)