this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <rogpeppe@gmail.com>
Change-Id: Iaa287b25faeb3cfc03225b06b97547a949026ba7
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201112
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+13 -1
+7
encoding/jsonschema/decode.go
··· 699 699 // do multiple passes over the constraints to ensure they are done in order. 700 700 for pass := 0; pass < numPhases; pass++ { 701 701 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 + } 702 709 // Convert each constraint into a either a value or a functor. 703 710 c := constraintMap[key] 704 711 if c == nil {
+6 -1
encoding/jsonschema/testdata/txtar/strictkeywords.txtar
··· 1 1 #strictKeywords 2 + 3 + Note: x-bar does _not_ cause an error even with StrictKeywords 4 + enabled. 5 + 2 6 -- schema.json -- 3 7 { 4 8 "$schema": "https://json-schema.org/draft/2020-12/schema", 5 9 "type": "number", 6 10 "$dynamicAnchor": "bar", 7 - "foo": true 11 + "foo": true, 12 + "x-bar": true 8 13 } 9 14 -- out/decode/extract -- 10 15 ERROR: