diff --git a/encoding/jsonschema/decode_test.go b/encoding/jsonschema/decode_test.go index 977cad6c7fd..160ffe20471 100644 --- a/encoding/jsonschema/decode_test.go +++ b/encoding/jsonschema/decode_test.go @@ -75,6 +75,10 @@ func TestDecode(t *testing.T) { } if versStr, ok := t.Value("version"); ok { + // TODO most schemas have neither an explicit $schema or a #version + // tag, so when we update the default version, they could break. + // We should probably change most of the tests to use an explicit $schema + // field apart from when we're explicitly testing the default version logic. if versStr == "openapi" { // OpenAPI doesn't have a JSON Schema URI so it gets a special case. cfg.DefaultVersion = jsonschema.VersionOpenAPI diff --git a/encoding/jsonschema/jsonschema.go b/encoding/jsonschema/jsonschema.go index 653bb1b96f4..f5b3e21e044 100644 --- a/encoding/jsonschema/jsonschema.go +++ b/encoding/jsonschema/jsonschema.go @@ -49,7 +49,7 @@ func Extract(data cue.InstanceOrValue, cfg *Config) (f *ast.File, err error) { cfg.MapURL = DefaultMapURL } if cfg.DefaultVersion == VersionUnknown { - cfg.DefaultVersion = VersionDraft7 + cfg.DefaultVersion = DefaultVersion } if cfg.Strict { cfg.StrictKeywords = true @@ -69,7 +69,7 @@ func Extract(data cue.InstanceOrValue, cfg *Config) (f *ast.File, err error) { // DefaultVersion defines the default schema version used when // there is no $schema field and no explicit [Config.DefaultVersion]. -const DefaultVersion = VersionDraft7 +const DefaultVersion = VersionDraft2020_12 // A Config configures a JSON Schema encoding or decoding. type Config struct { diff --git a/encoding/jsonschema/testdata/txtar/list.txtar b/encoding/jsonschema/testdata/txtar/list.txtar index 07e7947851a..2af7668f91b 100644 --- a/encoding/jsonschema/testdata/txtar/list.txtar +++ b/encoding/jsonschema/testdata/txtar/list.txtar @@ -1,4 +1,5 @@ -- schema.yaml -- +$schema: http://json-schema.org/draft-07/schema# type: object properties: @@ -43,6 +44,7 @@ additionalProperties: false -- out/decode/extract -- import "list" +@jsonschema(schema="http://json-schema.org/draft-07/schema#") foo?: [...string] tuple?: [string, int, 2] has?: list.MatchN(>=1, 3) @@ -51,8 +53,8 @@ size?: list.UniqueItems() & list.MaxItems(9) & [_, _, _, ...] additional?: [int, int, ...string] -- out/decode/testerr/err-foo-not-string -- foo.0: conflicting values true and string (mismatched types bool and string): - generated.cue:3:8 - generated.cue:3:11 + generated.cue:4:8 + generated.cue:4:11 test/err-foo-not-string.json:2:10 -- test/empty.json -- {}