diff --git a/encoding/jsonschema/external_test.go b/encoding/jsonschema/external_test.go new file mode 100644 index 000000000..4e60fe0b5 --- /dev/null +++ b/encoding/jsonschema/external_test.go @@ -0,0 +1,184 @@ +package jsonschema_test + +import ( + "bytes" + stdjson "encoding/json" + "fmt" + "os" + "path" + "path/filepath" + "sort" + "strings" + "testing" + + "github.com/go-quicktest/qt" + + "cuelang.org/go/cue" + "cuelang.org/go/cue/cuecontext" + "cuelang.org/go/cue/errors" + "cuelang.org/go/cue/format" + "cuelang.org/go/encoding/json" + "cuelang.org/go/encoding/jsonschema" + "cuelang.org/go/encoding/jsonschema/internal/externaltest" + "cuelang.org/go/internal/cuetest" +) + +// TestExternal runs the externally defined JSON Schema test suite, +// as defined in https://github.com/json-schema-org/JSON-Schema-Test-Suite. +func TestExternal(t *testing.T) { + tests, err := externaltest.ReadTestDir("testdata/external") + qt.Assert(t, qt.IsNil(err)) + + t.Logf("read %d test files", len(tests)) + // Group the tests under a single subtest so that we can use + // t.Parallel and still guarantee that all tests have completed + // by the end. + t.Run("tests", func(t *testing.T) { + // Run tests in deterministic order so we get some consistency between runs. + for _, filename := range sortedKeys(tests) { + schemas := tests[filename] + t.Run(strings.ReplaceAll(filename, "/", "__"), func(t *testing.T) { + for _, s := range schemas { + t.Run(strings.ReplaceAll(s.Description, "/", "__"), func(t *testing.T) { + runExternalSchemaTests(t, filename, s) + }) + } + }) + } + }) + if !cuetest.UpdateGoldenFiles { + return + } + for filename, schemas := range tests { + filename = filepath.Join("testdata/external", filename) + data, err := stdjson.MarshalIndent(schemas, "", "\t") + qt.Assert(t, qt.IsNil(err)) + data = append(data, '\n') + oldData, err := os.ReadFile(filename) + qt.Assert(t, qt.IsNil(err)) + if bytes.Equal(oldData, data) { + continue + } + err = os.WriteFile(filename, data, 0o666) + qt.Assert(t, qt.IsNil(err)) + } +} + +func runExternalSchemaTests(t *testing.T, filename string, s *externaltest.Schema) { + t.Logf("file %v", path.Join("testdata/external", filename)) + ctx := cuecontext.New() + jsonSchemaAST, err := json.Extract("schema.json", s.Schema) + qt.Assert(t, qt.IsNil(err)) + jsonSchemav := ctx.BuildExpr(jsonSchemaAST) + qt.Assert(t, qt.IsNil(jsonSchemav.Err())) + versStr, _, _ := strings.Cut(strings.TrimPrefix(filename, "tests/"), "/") + vers, ok := extVersionToVersion[versStr] + if !ok { + t.Fatalf("unknown JSON schema version for file %q", filename) + } + if vers == jsonschema.VersionUnknown { + t.Skipf("skipping test for unknown schema version %v", versStr) + } + schemaAST, extractErr := jsonschema.Extract(jsonSchemav, &jsonschema.Config{ + Strict: true, + DefaultVersion: vers, + }) + var schemav cue.Value + if extractErr == nil { + // Round-trip via bytes because that's what will usually happen + // to the generated schema. + b, err := format.Node(schemaAST, format.Simplify()) + qt.Assert(t, qt.IsNil(err)) + schemav = ctx.CompileBytes(b, cue.Filename("generated.cue")) + if err := schemav.Err(); err != nil { + extractErr = fmt.Errorf("cannot compile resulting schema: %v", errors.Details(err, nil)) + } + } + + if extractErr != nil { + if cuetest.UpdateGoldenFiles { + s.Skip = fmt.Sprintf("extract error: %v", extractErr) + for _, t := range s.Tests { + t.Skip = "could not compile schema" + } + return + } + if s.Skip != "" { + t.SkipNow() + } + t.Fatalf("extract error: %v", extractErr) + } + if s.Skip != "" { + t.Errorf("unexpected test success on skipped test") + } + + for _, test := range s.Tests { + t.Run("", func(t *testing.T) { + t.Logf("description: %s", test.Description) + instAST, err := json.Extract("instance.json", test.Data) + if err != nil { + t.Fatal(err) + } + + qt.Assert(t, qt.IsNil(err), qt.Commentf("test data: %q; details: %v", test.Data, errors.Details(err, nil))) + + instv := ctx.BuildExpr(instAST) + qt.Assert(t, qt.IsNil(instv.Err())) + err = instv.Unify(schemav).Err() + if test.Valid { + if cuetest.UpdateGoldenFiles { + if err == nil { + test.Skip = "" + } else { + test.Skip = errors.Details(err, nil) + } + return + } + if err != nil { + if test.Skip != "" { + t.SkipNow() + } + t.Fatalf("error: %v", errors.Details(err, nil)) + } else if test.Skip != "" { + t.Error("unexpectedly more correct behavior (test success) on skipped test") + } + } else { + if cuetest.UpdateGoldenFiles { + if err != nil { + test.Skip = "" + } else { + test.Skip = "unexpected success" + } + return + } + if err == nil { + if test.Skip != "" { + t.SkipNow() + } + t.Fatal("unexpected success") + } else if test.Skip != "" { + t.Error("unexpectedly more correct behavior (test failure) on skipped test") + } + } + }) + } +} + +var extVersionToVersion = map[string]jsonschema.Version{ + "draft3": jsonschema.VersionUnknown, + "draft4": jsonschema.VersionDraft4, + "draft6": jsonschema.VersionDraft6, + "draft7": jsonschema.VersionDraft7, + "draft2019-09": jsonschema.VersionDraft2019_09, + "draft2020-12": jsonschema.VersionDraft2020_12, + "draft-next": jsonschema.VersionUnknown, +} + +func sortedKeys[T any](m map[string]T) []string { + ks := make([]string, 0, len(m)) + for k := range m { + ks = append(ks, k) + } + sort.Strings(ks) + return ks +} diff --git a/encoding/jsonschema/internal/externaltest/tests.go b/encoding/jsonschema/internal/externaltest/tests.go new file mode 100644 index 000000000..89badd730 --- /dev/null +++ b/encoding/jsonschema/internal/externaltest/tests.go @@ -0,0 +1,65 @@ +package externaltest + +import ( + "bytes" + stdjson "encoding/json" + "os" + + "cuelang.org/go/cue" + "cuelang.org/go/cue/cuecontext" + "cuelang.org/go/cue/interpreter/embed" + "cuelang.org/go/cue/load" +) + +type Schema struct { + Description string `json:"description"` + Comment string `json:"comment,omitempty"` + Schema stdjson.RawMessage `json:"schema"` + Skip string `json:"skip,omitempty"` + Tests []*Test `json:"tests"` +} + +type Test struct { + Description string `json:"description"` + Comment string `json:"comment,omitempty"` + Data stdjson.RawMessage `json:"data"` + Valid bool `json:"valid"` + Skip string `json:"skip,omitempty"` +} + +func ReadTestDir(dir string) (tests map[string][]*Schema, err error) { + os.Setenv("CUE_EXPERIMENT", "embed") + inst := load.Instances([]string{"."}, &load.Config{ + Dir: dir, + })[0] + if err != nil { + return nil, err + } + ctx := cuecontext.New(cuecontext.Interpreter(embed.New())) + instVal := ctx.BuildInstance(inst) + if err := instVal.Err(); err != nil { + return nil, err + } + val := instVal.LookupPath(cue.MakePath(cue.Str("allTests"))) + if err := val.Err(); err != nil { + return nil, err + } + if err := val.Decode(&tests); err != nil { + return nil, err + } + // Fix up the raw JSON data to avoid running into some decode issues. + for _, schemas := range tests { + for _, schema := range schemas { + for _, test := range schema.Tests { + if len(test.Data) == 0 { + // See https://github.com/cue-lang/cue/issues/3397 + test.Data = []byte("null") + continue + } + // See https://github.com/cue-lang/cue/issues/3398 + test.Data = bytes.ReplaceAll(test.Data, []byte("\ufeff"), []byte(`\ufeff`)) + } + } + } + return tests, nil +} diff --git a/encoding/jsonschema/testdata/external/config.cue b/encoding/jsonschema/testdata/external/config.cue new file mode 100644 index 000000000..3a522be9b --- /dev/null +++ b/encoding/jsonschema/testdata/external/config.cue @@ -0,0 +1,37 @@ +@extern(embed) + +package external + +allTests: _ @embed(glob=tests/*/*.json) +allTests: _ @embed(glob=tests/*/*/*.json) +allTests: _ @embed(glob=tests/*/*/*/*.json) + +allTests: [_]: [... #Schema] +#Schema: { + description!: string + comment?: string + specification?: _ + schema!: _ + tests!: [... #Test] + + // skip is not part of the orginal test data, but + // is inserted by our test logic (when CUE_UPDATE=1) + // to indicate which tests are passing and which + // are failing. The text indicates some reason as to + // why the schema is skipped. + skip?: string +} + +#Test: { + description!: string + comment?: string + data!: _ + valid!: bool + + // skip is not part of the orginal test data, but + // is inserted by our test logic (when CUE_UPDATE=1) + // to indicate which tests are passing and which + // are failing. The text indicates some reason as to + // why the test is skipped. + skip?: string +} diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/additionalItems.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/additionalItems.json new file mode 100644 index 000000000..81207b80b --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/additionalItems.json @@ -0,0 +1,339 @@ +[ + { + "description": "additionalItems as schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + {} + ], + "additionalItems": { + "type": "integer" + } + }, + "tests": [ + { + "description": "additional items match schema", + "data": [ + null, + 2, + 3, + 4 + ], + "valid": true + }, + { + "description": "additional items do not match schema", + "data": [ + null, + 2, + 3, + "foo" + ], + "valid": false + } + ] + }, + { + "description": "when items is schema, additionalItems does nothing", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": { + "type": "integer" + }, + "additionalItems": { + "type": "string" + } + }, + "tests": [ + { + "description": "valid with a array of type integers", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "invalid with a array of mixed types", + "data": [ + 1, + "2", + "3" + ], + "valid": false + } + ] + }, + { + "description": "when items is schema, boolean additionalItems does nothing", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": {}, + "additionalItems": false + }, + "tests": [ + { + "description": "all items match schema", + "data": [ + 1, + 2, + 3, + 4, + 5 + ], + "valid": true + } + ] + }, + { + "description": "array of items with no additionalItems permitted", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + {}, + {}, + {} + ], + "additionalItems": false + }, + "tests": [ + { + "description": "empty array", + "data": [], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:45\n instance.json:1:1\nconflicting values bool and [] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "fewer number of items present (1)", + "data": [ + 1 + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:45\n instance.json:1:1\nconflicting values bool and [1] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "fewer number of items present (2)", + "data": [ + 1, + 2 + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1,2] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:45\n instance.json:1:1\nconflicting values bool and [1,2] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,2] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,2] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,2] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "equal number of items present", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "additional items are not permitted", + "data": [ + 1, + 2, + 3, + 4 + ], + "valid": false + } + ] + }, + { + "description": "additionalItems as false without items", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "additionalItems": false + }, + "tests": [ + { + "description": "items defaults to empty schema so everything is valid", + "data": [ + 1, + 2, + 3, + 4, + 5 + ], + "valid": true + }, + { + "description": "ignores non-arrays", + "data": { + "foo": "bar" + }, + "valid": true + } + ] + }, + { + "description": "additionalItems are allowed by default", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { + "type": "integer" + } + ] + }, + "tests": [ + { + "description": "only the first item is validated", + "data": [ + 1, + "foo", + false + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1,\"foo\",false] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:41\n instance.json:1:1\nconflicting values bool and [1,\"foo\",false] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,\"foo\",false] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,\"foo\",false] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,\"foo\",false] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + } + ] + }, + { + "description": "additionalItems does not look in applicators, valid case", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "items": [ + { + "type": "integer" + } + ] + } + ], + "additionalItems": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "items defined in allOf are not examined", + "data": [ + 1, + null + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1,null] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:41\n instance.json:1:1\nconflicting values bool and [1,null] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,null] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,null] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,null] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + } + ] + }, + { + "description": "additionalItems does not look in applicators, invalid case", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "items": [ + { + "type": "integer" + }, + { + "type": "string" + } + ] + } + ], + "items": [ + { + "type": "integer" + } + ], + "additionalItems": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "items defined in allOf are not examined", + "data": [ + 1, + "hello" + ], + "valid": false + } + ] + }, + { + "description": "items validation adjusts the starting index for additionalItems", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { + "type": "string" + } + ], + "additionalItems": { + "type": "integer" + } + }, + "tests": [ + { + "description": "valid items", + "data": [ + "x", + 2, + 3 + ], + "valid": true + }, + { + "description": "wrong type of second item", + "data": [ + "x", + "y" + ], + "valid": false + } + ] + }, + { + "description": "additionalItems with heterogeneous array", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + {} + ], + "additionalItems": false + }, + "tests": [ + { + "description": "heterogeneous invalid instance", + "data": [ + "foo", + "bar", + 37 + ], + "valid": false + }, + { + "description": "valid instance", + "data": [ + null + ], + "valid": true + } + ] + }, + { + "description": "additionalItems with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "additionalItems": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ + null + ], + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/additionalProperties.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/additionalProperties.json new file mode 100644 index 000000000..49ecb592b --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/additionalProperties.json @@ -0,0 +1,297 @@ +[ + { + "description": "additionalProperties being false does not allow other properties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": {}, + "bar": {} + }, + "patternProperties": { + "^v": {} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "no additional properties is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "an additional property is invalid", + "data": { + "foo": 1, + "bar": 2, + "quux": "boom" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ignores arrays", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobarbaz", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "patternProperties are not additional properties", + "data": { + "foo": 1, + "vroom": 2 + }, + "valid": true + } + ] + }, + { + "description": "non-ASCII pattern with additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "patternProperties": { + "^á": {} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "matching the pattern is valid", + "data": { + "ármányos": 2 + }, + "valid": true + }, + { + "description": "not matching the pattern is invalid", + "data": { + "élmény": 2 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "additionalProperties with schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": {}, + "bar": {} + }, + "additionalProperties": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "no additional properties is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "an additional valid property is valid", + "data": { + "foo": 1, + "bar": 2, + "quux": true + }, + "valid": true + }, + { + "description": "an additional invalid property is invalid", + "data": { + "foo": 1, + "bar": 2, + "quux": 12 + }, + "valid": false + } + ] + }, + { + "description": "additionalProperties can exist by itself", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "additionalProperties": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "an additional valid property is valid", + "data": { + "foo": true + }, + "valid": true + }, + { + "description": "an additional invalid property is invalid", + "data": { + "foo": 1 + }, + "valid": false + } + ] + }, + { + "description": "additionalProperties are allowed by default", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": {}, + "bar": {} + } + }, + "tests": [ + { + "description": "additional properties are allowed", + "data": { + "foo": 1, + "bar": 2, + "quux": true + }, + "valid": true + } + ] + }, + { + "description": "additionalProperties does not look in applicators", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "properties": { + "foo": {} + } + } + ], + "additionalProperties": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "properties defined in allOf are not examined", + "data": { + "foo": 1, + "bar": true + }, + "valid": false + } + ] + }, + { + "description": "additionalProperties with null valued instance properties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "additionalProperties": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null values", + "data": { + "foo": null + }, + "valid": true + } + ] + }, + { + "description": "additionalProperties with propertyNames", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "propertyNames": { + "maxLength": 5 + }, + "additionalProperties": { + "type": "number" + } + }, + "skip": "extract error: cannot compile resulting schema: reference \"strings\" in label expression refers to field against which it would be matched:\n generated.cue:5:3\n", + "tests": [ + { + "description": "Valid against both keywords", + "data": { + "apple": 4 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Valid against propertyNames, but not additionalProperties", + "data": { + "fig": 2, + "pear": "available" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "dependentSchemas with additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo2": {} + }, + "dependentSchemas": { + "foo": {}, + "foo2": { + "properties": { + "bar": {} + } + } + }, + "additionalProperties": false + }, + "skip": "extract error: unsupported constraint \"dependentSchemas\"", + "tests": [ + { + "description": "additionalProperties doesn't consider dependentSchemas", + "data": { + "foo": "" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "additionalProperties can't see bar", + "data": { + "bar": "" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "additionalProperties can't see bar even when foo2 is present", + "data": { + "foo2": "", + "bar": "" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/allOf.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/allOf.json new file mode 100644 index 000000000..bb723349e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/allOf.json @@ -0,0 +1,396 @@ +[ + { + "description": "allOf", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "properties": { + "bar": { + "type": "integer" + } + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + } + ] + }, + "tests": [ + { + "description": "allOf", + "data": { + "foo": "baz", + "bar": 2 + }, + "valid": true + }, + { + "description": "mismatch second", + "data": { + "foo": "baz" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "mismatch first", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "wrong type", + "data": { + "foo": "baz", + "bar": "quux" + }, + "valid": false + } + ] + }, + { + "description": "allOf with base schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "bar": { + "type": "integer" + } + }, + "required": [ + "bar" + ], + "allOf": [ + { + "properties": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + }, + { + "properties": { + "baz": { + "type": "null" + } + }, + "required": [ + "baz" + ] + } + ] + }, + "tests": [ + { + "description": "valid", + "data": { + "foo": "quux", + "bar": 2, + "baz": null + }, + "valid": true + }, + { + "description": "mismatch base schema", + "data": { + "foo": "quux", + "baz": null + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "mismatch first allOf", + "data": { + "bar": 2, + "baz": null + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "mismatch second allOf", + "data": { + "foo": "quux", + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "mismatch both", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "allOf simple types", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "maximum": 30 + }, + { + "minimum": 20 + } + ] + }, + "tests": [ + { + "description": "valid", + "data": 25, + "valid": true + }, + { + "description": "mismatch one", + "data": 35, + "valid": false + } + ] + }, + { + "description": "allOf with boolean schemas, all true", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + true, + true + ] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "allOf with boolean schemas, some false", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + true, + false + ] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "allOf with boolean schemas, all false", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + false, + false + ] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "allOf with one empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + {} + ] + }, + "tests": [ + { + "description": "any data is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "allOf with two empty schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + {}, + {} + ] + }, + "tests": [ + { + "description": "any data is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "allOf with the first empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + {}, + { + "type": "number" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "allOf with the last empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "type": "number" + }, + {} + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "nested allOf, to check validation semantics", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "allOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "allOf combined with anyOf, oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "multipleOf": 2 + } + ], + "anyOf": [ + { + "multipleOf": 3 + } + ], + "oneOf": [ + { + "multipleOf": 5 + } + ] + }, + "tests": [ + { + "description": "allOf: false, anyOf: false, oneOf: false", + "data": 1, + "valid": false + }, + { + "description": "allOf: false, anyOf: false, oneOf: true", + "data": 5, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: false", + "data": 3, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: true", + "data": 15, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: false", + "data": 2, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: true", + "data": 10, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: false", + "data": 6, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: true", + "data": 30, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/anchor.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/anchor.json new file mode 100644 index 000000000..8bfcd8689 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/anchor.json @@ -0,0 +1,132 @@ +[ + { + "description": "Location-independent identifier", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "#foo", + "$defs": { + "A": { + "$anchor": "foo", + "type": "integer" + } + } + }, + "skip": "extract error: anchors (foo) not supported (and 1 more errors)", + "tests": [ + { + "description": "match", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "Location-independent identifier with absolute URI", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://localhost:1234/draft2019-09/bar#foo", + "$defs": { + "A": { + "$id": "http://localhost:1234/draft2019-09/bar", + "$anchor": "foo", + "type": "integer" + } + } + }, + "skip": "extract error: anchors (foo) not supported (and 1 more errors)", + "tests": [ + { + "description": "match", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "Location-independent identifier with base URI change in subschema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/root", + "$ref": "http://localhost:1234/draft2019-09/nested.json#foo", + "$defs": { + "A": { + "$id": "nested.json", + "$defs": { + "B": { + "$anchor": "foo", + "type": "integer" + } + } + } + } + }, + "skip": "extract error: anchors (foo) not supported (and 1 more errors)", + "tests": [ + { + "description": "match", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "same $anchor with different base uri", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/foobar", + "$defs": { + "A": { + "$id": "child1", + "allOf": [ + { + "$id": "child2", + "$anchor": "my_anchor", + "type": "number" + }, + { + "$anchor": "my_anchor", + "type": "string" + } + ] + } + }, + "$ref": "child1#my_anchor" + }, + "skip": "extract error: unsupported constraint \"$anchor\" (and 4 more errors)", + "tests": [ + { + "description": "$ref resolves to /$defs/A/allOf/1", + "data": "a", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "$ref does not resolve to /$defs/A/allOf/0", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/anyOf.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/anyOf.json new file mode 100644 index 000000000..263b900a9 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/anyOf.json @@ -0,0 +1,234 @@ +[ + { + "description": "anyOf", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "anyOf": [ + { + "type": "integer" + }, + { + "minimum": 2 + } + ] + }, + "tests": [ + { + "description": "first anyOf valid", + "data": 1, + "valid": true + }, + { + "description": "second anyOf valid", + "data": 2.5, + "valid": true + }, + { + "description": "both anyOf valid", + "data": 3, + "valid": true + }, + { + "description": "neither anyOf valid", + "data": 1.5, + "valid": false + } + ] + }, + { + "description": "anyOf with base schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "string", + "anyOf": [ + { + "maxLength": 2 + }, + { + "minLength": 4 + } + ] + }, + "tests": [ + { + "description": "mismatch base schema", + "data": 3, + "valid": false + }, + { + "description": "one anyOf valid", + "data": "foobar", + "valid": true + }, + { + "description": "both anyOf invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "anyOf with boolean schemas, all true", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "anyOf": [ + true, + true + ] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "anyOf with boolean schemas, some true", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "anyOf": [ + true, + false + ] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "anyOf with boolean schemas, all false", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "anyOf": [ + false, + false + ] + }, + "skip": "extract error: cannot compile resulting schema: 2 errors in empty disjunction:\nexplicit error (_|_ literal) in source:\n generated.cue:2:1\nexplicit error (_|_ literal) in source:\n generated.cue:2:7\n", + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "anyOf complex types", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "anyOf": [ + { + "properties": { + "bar": { + "type": "integer" + } + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + } + ] + }, + "tests": [ + { + "description": "first anyOf valid (complex)", + "data": { + "bar": 2 + }, + "valid": true + }, + { + "description": "second anyOf valid (complex)", + "data": { + "foo": "baz" + }, + "valid": true + }, + { + "description": "both anyOf valid (complex)", + "data": { + "foo": "baz", + "bar": 2 + }, + "valid": true + }, + { + "description": "neither anyOf valid (complex)", + "data": { + "foo": 2, + "bar": "quux" + }, + "valid": false + } + ] + }, + { + "description": "anyOf with one empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "anyOf": [ + { + "type": "number" + }, + {} + ] + }, + "tests": [ + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "number is valid", + "data": 123, + "valid": true + } + ] + }, + { + "description": "nested anyOf, to check validation semantics", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "anyOf": [ + { + "anyOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/boolean_schema.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/boolean_schema.json new file mode 100644 index 000000000..dd0e5677f --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/boolean_schema.json @@ -0,0 +1,122 @@ +[ + { + "description": "boolean schema 'true'", + "schema": true, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "boolean true is valid", + "data": true, + "valid": true + }, + { + "description": "boolean false is valid", + "data": false, + "valid": true + }, + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "object is valid", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + }, + { + "description": "array is valid", + "data": [ + "foo" + ], + "valid": true + }, + { + "description": "empty array is valid", + "data": [], + "valid": true + } + ] + }, + { + "description": "boolean schema 'false'", + "schema": false, + "skip": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n generated.cue:2:1\n", + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "null is invalid", + "data": null, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "object is invalid", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "array is invalid", + "data": [ + "foo" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/const.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/const.json new file mode 100644 index 000000000..5d126b464 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/const.json @@ -0,0 +1,452 @@ +[ + { + "description": "const validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": 2 + }, + "tests": [ + { + "description": "same value is valid", + "data": 2, + "valid": true + }, + { + "description": "another value is invalid", + "data": 5, + "valid": false + }, + { + "description": "another type is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "const with object", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": { + "foo": "bar", + "baz": "bax" + } + }, + "tests": [ + { + "description": "same object is valid", + "data": { + "foo": "bar", + "baz": "bax" + }, + "valid": true + }, + { + "description": "same object with different property order is valid", + "data": { + "baz": "bax", + "foo": "bar" + }, + "valid": true + }, + { + "description": "another object is invalid", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "another type is invalid", + "data": [ + 1, + 2 + ], + "valid": false + } + ] + }, + { + "description": "const with array", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": [ + { + "foo": "bar" + } + ] + }, + "tests": [ + { + "description": "same array is valid", + "data": [ + { + "foo": "bar" + } + ], + "valid": true + }, + { + "description": "another array item is invalid", + "data": [ + 2 + ], + "valid": false + }, + { + "description": "array with additional items is invalid", + "data": [ + 1, + 2, + 3 + ], + "valid": false + } + ] + }, + { + "description": "const with null", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": null + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "not null is invalid", + "data": 0, + "valid": false + } + ] + }, + { + "description": "const with false does not match 0", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": false + }, + "tests": [ + { + "description": "false is valid", + "data": false, + "valid": true + }, + { + "description": "integer zero is invalid", + "data": 0, + "valid": false + }, + { + "description": "float zero is invalid", + "data": 0.0, + "valid": false + } + ] + }, + { + "description": "const with true does not match 1", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": true + }, + "tests": [ + { + "description": "true is valid", + "data": true, + "valid": true + }, + { + "description": "integer one is invalid", + "data": 1, + "valid": false + }, + { + "description": "float one is invalid", + "data": 1.0, + "valid": false + } + ] + }, + { + "description": "const with [false] does not match [0]", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": [ + false + ] + }, + "tests": [ + { + "description": "[false] is valid", + "data": [ + false + ], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [ + 0 + ], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [ + 0.0 + ], + "valid": false + } + ] + }, + { + "description": "const with [true] does not match [1]", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": [ + true + ] + }, + "tests": [ + { + "description": "[true] is valid", + "data": [ + true + ], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [ + 1 + ], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [ + 1.0 + ], + "valid": false + } + ] + }, + { + "description": "const with {\"a\": false} does not match {\"a\": 0}", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": { + "a": false + } + }, + "tests": [ + { + "description": "{\"a\": false} is valid", + "data": { + "a": false + }, + "valid": true + }, + { + "description": "{\"a\": 0} is invalid", + "data": { + "a": 0 + }, + "valid": false + }, + { + "description": "{\"a\": 0.0} is invalid", + "data": { + "a": 0.0 + }, + "valid": false + } + ] + }, + { + "description": "const with {\"a\": true} does not match {\"a\": 1}", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": { + "a": true + } + }, + "tests": [ + { + "description": "{\"a\": true} is valid", + "data": { + "a": true + }, + "valid": true + }, + { + "description": "{\"a\": 1} is invalid", + "data": { + "a": 1 + }, + "valid": false + }, + { + "description": "{\"a\": 1.0} is invalid", + "data": { + "a": 1.0 + }, + "valid": false + } + ] + }, + { + "description": "const with 0 does not match other zero-like types", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": 0 + }, + "tests": [ + { + "description": "false is invalid", + "data": false, + "valid": false + }, + { + "description": "integer zero is valid", + "data": 0, + "valid": true + }, + { + "description": "float zero is valid", + "data": 0.0, + "valid": true, + "skip": "conflicting values 0.0 and 0 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + }, + { + "description": "empty string is invalid", + "data": "", + "valid": false + } + ] + }, + { + "description": "const with 1 does not match true", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": 1 + }, + "tests": [ + { + "description": "true is invalid", + "data": true, + "valid": false + }, + { + "description": "integer one is valid", + "data": 1, + "valid": true + }, + { + "description": "float one is valid", + "data": 1.0, + "valid": true, + "skip": "conflicting values 1.0 and 1 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + } + ] + }, + { + "description": "const with -2.0 matches integer and float types", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": -2.0 + }, + "tests": [ + { + "description": "integer -2 is valid", + "data": -2, + "valid": true, + "skip": "conflicting values -2 and -2.0 (mismatched types int and float):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "integer 2 is invalid", + "data": 2, + "valid": false + }, + { + "description": "float -2.0 is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float 2.0 is invalid", + "data": 2.0, + "valid": false + }, + { + "description": "float -2.00001 is invalid", + "data": -2.00001, + "valid": false + } + ] + }, + { + "description": "float and integers are equal up to 64-bit representation limits", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": 9007199254740992 + }, + "tests": [ + { + "description": "integer is valid", + "data": 9007199254740992, + "valid": true + }, + { + "description": "integer minus one is invalid", + "data": 9007199254740991, + "valid": false + }, + { + "description": "float is valid", + "data": 9007199254740992.0, + "valid": true, + "skip": "conflicting values 9007199254740992.0 and 9007199254740992 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "float minus one is invalid", + "data": 9007199254740991.0, + "valid": false + } + ] + }, + { + "description": "nul characters in strings", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "const": "hello\u0000there" + }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/contains.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/contains.json new file mode 100644 index 000000000..c70cae1f5 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/contains.json @@ -0,0 +1,240 @@ +[ + { + "description": "contains keyword validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": { + "minimum": 5 + } + }, + "tests": [ + { + "description": "array with item matching schema (5) is valid", + "data": [ + 3, + 4, + 5 + ], + "valid": true + }, + { + "description": "array with item matching schema (6) is valid", + "data": [ + 3, + 4, + 6 + ], + "valid": true + }, + { + "description": "array with two items matching schema (5, 6) is valid", + "data": [ + 3, + 4, + 5, + 6 + ], + "valid": true + }, + { + "description": "array without items matching schema is invalid", + "data": [ + 2, + 3, + 4 + ], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + }, + { + "description": "not array is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "contains keyword with const keyword", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": { + "const": 5 + } + }, + "tests": [ + { + "description": "array with item 5 is valid", + "data": [ + 3, + 4, + 5 + ], + "valid": true + }, + { + "description": "array with two items 5 is valid", + "data": [ + 3, + 4, + 5, + 5 + ], + "valid": true + }, + { + "description": "array without item 5 is invalid", + "data": [ + 1, + 2, + 3, + 4 + ], + "valid": false + } + ] + }, + { + "description": "contains keyword with boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": true + }, + "tests": [ + { + "description": "any non-empty array is valid", + "data": [ + "foo" + ], + "valid": true + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + } + ] + }, + { + "description": "contains keyword with boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": false + }, + "tests": [ + { + "description": "any non-empty array is invalid", + "data": [ + "foo" + ], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + }, + { + "description": "non-arrays are valid", + "data": "contains does not apply to strings", + "valid": true + } + ] + }, + { + "description": "items + contains", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": { + "multipleOf": 2 + }, + "contains": { + "multipleOf": 3 + } + }, + "tests": [ + { + "description": "matches items, does not match contains", + "data": [ + 2, + 4, + 8 + ], + "valid": false + }, + { + "description": "does not match items, matches contains", + "data": [ + 3, + 6, + 9 + ], + "valid": false + }, + { + "description": "matches both items and contains", + "data": [ + 6, + 12 + ], + "valid": true + }, + { + "description": "matches neither items nor contains", + "data": [ + 1, + 5 + ], + "valid": false + } + ] + }, + { + "description": "contains with false if subschema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": { + "if": false, + "else": true + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 1 more errors)", + "tests": [ + { + "description": "any non-empty array is valid", + "data": [ + "foo" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "contains with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null items", + "data": [ + null + ], + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/content.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/content.json new file mode 100644 index 000000000..364e70201 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/content.json @@ -0,0 +1,150 @@ +[ + { + "description": "validation of string-encoded content based on media type", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contentMediaType": "application/json" + }, + "tests": [ + { + "description": "a valid JSON document", + "data": "{\"foo\": \"bar\"}", + "valid": true + }, + { + "description": "an invalid JSON document; validates true", + "data": "{:}", + "valid": true + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + }, + { + "description": "validation of binary string-encoding", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contentEncoding": "base64" + }, + "tests": [ + { + "description": "a valid base64 string", + "data": "eyJmb28iOiAiYmFyIn0K", + "valid": true + }, + { + "description": "an invalid base64 string (% is not a valid character); validates true", + "data": "eyJmb28iOi%iYmFyIn0K", + "valid": true + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + }, + { + "description": "validation of binary-encoded media type documents", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contentMediaType": "application/json", + "contentEncoding": "base64" + }, + "tests": [ + { + "description": "a valid base64-encoded JSON document", + "data": "eyJmb28iOiAiYmFyIn0K", + "valid": true + }, + { + "description": "a validly-encoded invalid JSON document; validates true", + "data": "ezp9Cg==", + "valid": true + }, + { + "description": "an invalid base64 string that is valid JSON; validates true", + "data": "{}", + "valid": true + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + }, + { + "description": "validation of binary-encoded media type documents with schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contentMediaType": "application/json", + "contentEncoding": "base64", + "contentSchema": { + "type": "object", + "required": [ + "foo" + ], + "properties": { + "foo": { + "type": "string" + } + } + } + }, + "skip": "extract error: unsupported constraint \"contentSchema\"", + "tests": [ + { + "description": "a valid base64-encoded JSON document", + "data": "eyJmb28iOiAiYmFyIn0K", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "another valid base64-encoded JSON document", + "data": "eyJib28iOiAyMCwgImZvbyI6ICJiYXoifQ==", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid base64-encoded JSON document; validates true", + "data": "eyJib28iOiAyMH0=", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an empty object as a base64-encoded JSON document; validates true", + "data": "e30=", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an empty array as a base64-encoded JSON document", + "data": "W10=", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a validly-encoded invalid JSON document; validates true", + "data": "ezp9Cg==", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid base64 string that is valid JSON; validates true", + "data": "{}", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/default.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/default.json new file mode 100644 index 000000000..1acad9084 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/default.json @@ -0,0 +1,91 @@ +[ + { + "description": "invalid type for default", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": { + "type": "integer", + "default": [] + } + } + }, + "tests": [ + { + "description": "valid when property is specified", + "data": { + "foo": 13 + }, + "valid": true + }, + { + "description": "still valid when the invalid default is used", + "data": {}, + "valid": true + } + ] + }, + { + "description": "invalid string value for default", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "bar": { + "type": "string", + "minLength": 4, + "default": "bad" + } + } + }, + "tests": [ + { + "description": "valid when property is specified", + "data": { + "bar": "good" + }, + "valid": true + }, + { + "description": "still valid when the invalid default is used", + "data": {}, + "valid": true + } + ] + }, + { + "description": "the default keyword does not do anything if the property is missing", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "alpha": { + "type": "number", + "maximum": 3, + "default": 5 + } + } + }, + "tests": [ + { + "description": "an explicit property value is checked against maximum (passing)", + "data": { + "alpha": 1 + }, + "valid": true + }, + { + "description": "an explicit property value is checked against maximum (failing)", + "data": { + "alpha": 5 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "missing properties are not filled in with the default", + "data": {}, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/defs.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/defs.json new file mode 100644 index 000000000..568513a5a --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/defs.json @@ -0,0 +1,36 @@ +[ + { + "description": "validate definition against metaschema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "https://json-schema.org/draft/2019-09/schema" + }, + "skip": "extract error: cannot compile resulting schema: package \"json-schema.org/draft/2019-09/schema\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "valid definition schema", + "data": { + "$defs": { + "foo": { + "type": "integer" + } + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid definition schema", + "data": { + "$defs": { + "foo": { + "type": 1 + } + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/dependentRequired.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/dependentRequired.json new file mode 100644 index 000000000..9e42a7920 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/dependentRequired.json @@ -0,0 +1,217 @@ +[ + { + "description": "single dependency", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependentRequired": { + "bar": [ + "foo" + ] + } + }, + "skip": "extract error: unsupported constraint \"dependentRequired\"", + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "nondependant", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with dependency", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "missing dependency", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ignores arrays", + "data": [ + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "empty dependents", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependentRequired": { + "bar": [] + } + }, + "skip": "extract error: unsupported constraint \"dependentRequired\"", + "tests": [ + { + "description": "empty object", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "object with one property", + "data": { + "bar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "non-object is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "multiple dependents required", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependentRequired": { + "quux": [ + "foo", + "bar" + ] + } + }, + "skip": "extract error: unsupported constraint \"dependentRequired\"", + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "nondependants", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with dependencies", + "data": { + "foo": 1, + "bar": 2, + "quux": 3 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "missing dependency", + "data": { + "foo": 1, + "quux": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "missing other dependency", + "data": { + "bar": 1, + "quux": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "missing both dependencies", + "data": { + "quux": 1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependentRequired": { + "foo\nbar": [ + "foo\rbar" + ], + "foo\"bar": [ + "foo'bar" + ] + } + }, + "skip": "extract error: unsupported constraint \"dependentRequired\"", + "tests": [ + { + "description": "CRLF", + "data": { + "foo\nbar": 1, + "foo\rbar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "quoted quotes", + "data": { + "foo'bar": 1, + "foo\"bar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "CRLF missing dependent", + "data": { + "foo\nbar": 1, + "foo": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "quoted quotes missing dependent", + "data": { + "foo\"bar": 2 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/dependentSchemas.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/dependentSchemas.json new file mode 100644 index 000000000..328f443f1 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/dependentSchemas.json @@ -0,0 +1,241 @@ +[ + { + "description": "single dependency", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependentSchemas": { + "bar": { + "properties": { + "foo": { + "type": "integer" + }, + "bar": { + "type": "integer" + } + } + } + } + }, + "skip": "extract error: unsupported constraint \"dependentSchemas\"", + "tests": [ + { + "description": "valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "no dependency", + "data": { + "foo": "quux" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "wrong type", + "data": { + "foo": "quux", + "bar": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "wrong type other", + "data": { + "foo": 2, + "bar": "quux" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "wrong type both", + "data": { + "foo": "quux", + "bar": "quux" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ignores arrays", + "data": [ + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "boolean subschemas", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependentSchemas": { + "foo": true, + "bar": false + } + }, + "skip": "extract error: unsupported constraint \"dependentSchemas\"", + "tests": [ + { + "description": "object with property having schema true is valid", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "object with property having schema false is invalid", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "object with both properties is invalid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependentSchemas": { + "foo\tbar": { + "minProperties": 4 + }, + "foo'bar": { + "required": [ + "foo\"bar" + ] + } + } + }, + "skip": "extract error: unsupported constraint \"dependentSchemas\"", + "tests": [ + { + "description": "quoted tab", + "data": { + "foo\tbar": 1, + "a": 2, + "b": 3, + "c": 4 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "quoted quote", + "data": { + "foo'bar": { + "foo\"bar": 1 + } + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "quoted tab invalid under dependent schema", + "data": { + "foo\tbar": 1, + "a": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "quoted quote invalid under dependent schema", + "data": { + "foo'bar": 1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "dependent subschema incompatible with root", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": {} + }, + "dependentSchemas": { + "foo": { + "properties": { + "bar": {} + }, + "additionalProperties": false + } + } + }, + "skip": "extract error: unsupported constraint \"dependentSchemas\"", + "tests": [ + { + "description": "matches root", + "data": { + "foo": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "matches dependency", + "data": { + "bar": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "matches both", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no dependency", + "data": { + "baz": 1 + }, + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/enum.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/enum.json new file mode 100644 index 000000000..bcf939c71 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/enum.json @@ -0,0 +1,463 @@ +[ + { + "description": "simple enum validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [ + 1, + 2, + 3 + ] + }, + "tests": [ + { + "description": "one of the enum is valid", + "data": 1, + "valid": true + }, + { + "description": "something else is invalid", + "data": 4, + "valid": false + } + ] + }, + { + "description": "heterogeneous enum validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [ + 6, + "foo", + [], + true, + { + "foo": 12 + } + ] + }, + "tests": [ + { + "description": "one of the enum is valid", + "data": [], + "valid": true + }, + { + "description": "something else is invalid", + "data": null, + "valid": false + }, + { + "description": "objects are deep compared", + "data": { + "foo": false + }, + "valid": false + }, + { + "description": "valid object matches", + "data": { + "foo": 12 + }, + "valid": true + }, + { + "description": "extra properties in object is invalid", + "data": { + "foo": 12, + "boo": 42 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "heterogeneous enum-with-null validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [ + 6, + null + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "number is valid", + "data": 6, + "valid": true + }, + { + "description": "something else is invalid", + "data": "test", + "valid": false + } + ] + }, + { + "description": "enums in properties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { + "enum": [ + "foo" + ] + }, + "bar": { + "enum": [ + "bar" + ] + } + }, + "required": [ + "bar" + ] + }, + "tests": [ + { + "description": "both properties are valid", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "wrong foo value", + "data": { + "foo": "foot", + "bar": "bar" + }, + "valid": false + }, + { + "description": "wrong bar value", + "data": { + "foo": "foo", + "bar": "bart" + }, + "valid": false + }, + { + "description": "missing optional property is valid", + "data": { + "bar": "bar" + }, + "valid": true + }, + { + "description": "missing required property is invalid", + "data": { + "foo": "foo" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "missing all properties is invalid", + "data": {}, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "enum with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [ + "foo\nbar", + "foo\rbar" + ] + }, + "tests": [ + { + "description": "member 1 is valid", + "data": "foo\nbar", + "valid": true + }, + { + "description": "member 2 is valid", + "data": "foo\rbar", + "valid": true + }, + { + "description": "another string is invalid", + "data": "abc", + "valid": false + } + ] + }, + { + "description": "enum with false does not match 0", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [ + false + ] + }, + "tests": [ + { + "description": "false is valid", + "data": false, + "valid": true + }, + { + "description": "integer zero is invalid", + "data": 0, + "valid": false + }, + { + "description": "float zero is invalid", + "data": 0.0, + "valid": false + } + ] + }, + { + "description": "enum with [false] does not match [0]", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [ + [ + false + ] + ] + }, + "tests": [ + { + "description": "[false] is valid", + "data": [ + false + ], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [ + 0 + ], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [ + 0.0 + ], + "valid": false + } + ] + }, + { + "description": "enum with true does not match 1", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [ + true + ] + }, + "tests": [ + { + "description": "true is valid", + "data": true, + "valid": true + }, + { + "description": "integer one is invalid", + "data": 1, + "valid": false + }, + { + "description": "float one is invalid", + "data": 1.0, + "valid": false + } + ] + }, + { + "description": "enum with [true] does not match [1]", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [ + [ + true + ] + ] + }, + "tests": [ + { + "description": "[true] is valid", + "data": [ + true + ], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [ + 1 + ], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [ + 1.0 + ], + "valid": false + } + ] + }, + { + "description": "enum with 0 does not match false", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [ + 0 + ] + }, + "tests": [ + { + "description": "false is invalid", + "data": false, + "valid": false + }, + { + "description": "integer zero is valid", + "data": 0, + "valid": true + }, + { + "description": "float zero is valid", + "data": 0.0, + "valid": true, + "skip": "conflicting values 0.0 and 0 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + } + ] + }, + { + "description": "enum with [0] does not match [false]", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [ + [ + 0 + ] + ] + }, + "tests": [ + { + "description": "[false] is invalid", + "data": [ + false + ], + "valid": false + }, + { + "description": "[0] is valid", + "data": [ + 0 + ], + "valid": true + }, + { + "description": "[0.0] is valid", + "data": [ + 0.0 + ], + "valid": true, + "skip": "0: conflicting values 0.0 and 0 (mismatched types float and int):\n generated.cue:2:1\n generated.cue:2:2\n instance.json:1:2\n" + } + ] + }, + { + "description": "enum with 1 does not match true", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [ + 1 + ] + }, + "tests": [ + { + "description": "true is invalid", + "data": true, + "valid": false + }, + { + "description": "integer one is valid", + "data": 1, + "valid": true + }, + { + "description": "float one is valid", + "data": 1.0, + "valid": true, + "skip": "conflicting values 1.0 and 1 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + } + ] + }, + { + "description": "enum with [1] does not match [true]", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [ + [ + 1 + ] + ] + }, + "tests": [ + { + "description": "[true] is invalid", + "data": [ + true + ], + "valid": false + }, + { + "description": "[1] is valid", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "[1.0] is valid", + "data": [ + 1.0 + ], + "valid": true, + "skip": "0: conflicting values 1.0 and 1 (mismatched types float and int):\n generated.cue:2:1\n generated.cue:2:2\n instance.json:1:2\n" + } + ] + }, + { + "description": "nul characters in strings", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "enum": [ + "hello\u0000there" + ] + }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/exclusiveMaximum.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/exclusiveMaximum.json new file mode 100644 index 000000000..c35cd44cf --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/exclusiveMaximum.json @@ -0,0 +1,31 @@ +[ + { + "description": "exclusiveMaximum validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "exclusiveMaximum": 3.0 + }, + "tests": [ + { + "description": "below the exclusiveMaximum is valid", + "data": 2.2, + "valid": true + }, + { + "description": "boundary point is invalid", + "data": 3.0, + "valid": false + }, + { + "description": "above the exclusiveMaximum is invalid", + "data": 3.5, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/exclusiveMinimum.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/exclusiveMinimum.json new file mode 100644 index 000000000..82ac17f05 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/exclusiveMinimum.json @@ -0,0 +1,31 @@ +[ + { + "description": "exclusiveMinimum validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "exclusiveMinimum": 1.1 + }, + "tests": [ + { + "description": "above the exclusiveMinimum is valid", + "data": 1.2, + "valid": true + }, + { + "description": "boundary point is invalid", + "data": 1.1, + "valid": false + }, + { + "description": "below the exclusiveMinimum is invalid", + "data": 0.6, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/format.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/format.json new file mode 100644 index 000000000..05f7508e6 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/format.json @@ -0,0 +1,876 @@ +[ + { + "description": "email format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "email" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "idn-email format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "idn-email" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "regex format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "regex" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ipv4 format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "ipv4" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ipv6 format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "ipv6" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "idn-hostname format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "idn-hostname" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "hostname format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "hostname" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "date format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "date" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "date-time format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "date-time" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "time format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "time" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "json-pointer format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "json-pointer" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "relative-json-pointer format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "relative-json-pointer" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "iri format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "iri" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "iri-reference format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "iri-reference" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "uri format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "uri" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "uri-reference format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "uri-reference" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "uri-template format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "uri-template" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "uuid format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "uuid" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "duration format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "duration" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/if-then-else.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/if-then-else.json new file mode 100644 index 000000000..17a737511 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/if-then-else.json @@ -0,0 +1,318 @@ +[ + { + "description": "ignore if without then or else", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "const": 0 + } + }, + "skip": "extract error: unsupported constraint \"if\"", + "tests": [ + { + "description": "valid when valid against lone if", + "data": 0, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid when invalid against lone if", + "data": "hello", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ignore then without if", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "then": { + "const": 0 + } + }, + "skip": "extract error: unsupported constraint \"then\"", + "tests": [ + { + "description": "valid when valid against lone then", + "data": 0, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid when invalid against lone then", + "data": "hello", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ignore else without if", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "else": { + "const": 0 + } + }, + "skip": "extract error: unsupported constraint \"else\"", + "tests": [ + { + "description": "valid when valid against lone else", + "data": 0, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid when invalid against lone else", + "data": "hello", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "if and then without else", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "exclusiveMaximum": 0 + }, + "then": { + "minimum": -10 + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 1 more errors)", + "tests": [ + { + "description": "valid through then", + "data": -1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid through then", + "data": -100, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid when if test fails", + "data": 3, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "if and else without then", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "exclusiveMaximum": 0 + }, + "else": { + "multipleOf": 2 + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 1 more errors)", + "tests": [ + { + "description": "valid when if test passes", + "data": -1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid through else", + "data": 4, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid through else", + "data": 3, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "validate against correct branch, then vs else", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "exclusiveMaximum": 0 + }, + "then": { + "minimum": -10 + }, + "else": { + "multipleOf": 2 + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 2 more errors)", + "tests": [ + { + "description": "valid through then", + "data": -1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid through then", + "data": -100, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid through else", + "data": 4, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid through else", + "data": 3, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "non-interference across combined schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "if": { + "exclusiveMaximum": 0 + } + }, + { + "then": { + "minimum": -10 + } + }, + { + "else": { + "multipleOf": 2 + } + } + ] + }, + "skip": "extract error: unsupported constraint \"if\" (and 2 more errors)", + "tests": [ + { + "description": "valid, but would have been invalid through then", + "data": -100, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid, but would have been invalid through else", + "data": 3, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "if with boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": true, + "then": { + "const": "then" + }, + "else": { + "const": "else" + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 2 more errors)", + "tests": [ + { + "description": "boolean schema true in if always chooses the then path (valid)", + "data": "then", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "boolean schema true in if always chooses the then path (invalid)", + "data": "else", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "if with boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": false, + "then": { + "const": "then" + }, + "else": { + "const": "else" + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 2 more errors)", + "tests": [ + { + "description": "boolean schema false in if always chooses the else path (invalid)", + "data": "then", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean schema false in if always chooses the else path (valid)", + "data": "else", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "if appears at the end when serialized (keyword processing sequence)", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "then": { + "const": "yes" + }, + "else": { + "const": "other" + }, + "if": { + "maxLength": 4 + } + }, + "skip": "extract error: unsupported constraint \"then\" (and 2 more errors)", + "tests": [ + { + "description": "yes redirects to then and passes", + "data": "yes", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "other redirects to else and passes", + "data": "other", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "no redirects to then and fails", + "data": "no", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid redirects to else and fails", + "data": "invalid", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/infinite-loop-detection.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/infinite-loop-detection.json new file mode 100644 index 000000000..dc293c928 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/infinite-loop-detection.json @@ -0,0 +1,43 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "int": { + "type": "integer" + } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/$defs/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/$defs/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "failing case", + "data": { + "foo": "a string" + }, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/items.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/items.json new file mode 100644 index 000000000..f88fc7745 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/items.json @@ -0,0 +1,564 @@ +[ + { + "description": "a schema given for items", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": { + "type": "integer" + } + }, + "tests": [ + { + "description": "valid items", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "wrong type of items", + "data": [ + 1, + "x" + ], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "JavaScript pseudo-array is valid", + "data": { + "0": "invalid", + "length": 1 + }, + "valid": true + } + ] + }, + { + "description": "an array of schemas for items", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { + "type": "integer" + }, + { + "type": "string" + } + ] + }, + "tests": [ + { + "description": "correct types", + "data": [ + 1, + "foo" + ], + "valid": true + }, + { + "description": "wrong types", + "data": [ + "foo", + 1 + ], + "valid": false + }, + { + "description": "incomplete array of items", + "data": [ + 1 + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:49\n instance.json:1:1\nconflicting values bool and [1] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "array with additional items", + "data": [ + 1, + "foo", + true + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1,\"foo\",true] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:49\n instance.json:1:1\nconflicting values bool and [1,\"foo\",true] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,\"foo\",true] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,\"foo\",true] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,\"foo\",true] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "empty array", + "data": [], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:49\n instance.json:1:1\nconflicting values bool and [] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "JavaScript pseudo-array is valid", + "data": { + "0": "invalid", + "1": "valid", + "length": 2 + }, + "valid": true + } + ] + }, + { + "description": "items with boolean schema (true)", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": true + }, + "skip": "extract error: value of \"items\" must be an object or array", + "tests": [ + { + "description": "any array is valid", + "data": [ + 1, + "foo", + true + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "empty array is valid", + "data": [], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "items with boolean schema (false)", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": false + }, + "skip": "extract error: value of \"items\" must be an object or array", + "tests": [ + { + "description": "any non-empty array is invalid", + "data": [ + 1, + "foo", + true + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty array is valid", + "data": [], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "items with boolean schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + true, + false + ] + }, + "tests": [ + { + "description": "array with one item is valid", + "data": [ + 1 + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:44\n instance.json:1:1\nconflicting values bool and [1] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "array with two items is invalid", + "data": [ + 1, + "foo" + ], + "valid": false + }, + { + "description": "empty array is valid", + "data": [], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:44\n instance.json:1:1\nconflicting values bool and [] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + } + ] + }, + { + "description": "items and subitems", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "item": { + "type": "array", + "additionalItems": false, + "items": [ + { + "$ref": "#/$defs/sub-item" + }, + { + "$ref": "#/$defs/sub-item" + } + ] + }, + "sub-item": { + "type": "object", + "required": [ + "foo" + ] + } + }, + "type": "array", + "additionalItems": false, + "items": [ + { + "$ref": "#/$defs/item" + }, + { + "$ref": "#/$defs/item" + }, + { + "$ref": "#/$defs/item" + } + ] + }, + "tests": [ + { + "description": "valid items", + "data": [ + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": true + }, + { + "description": "too many items", + "data": [ + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": false + }, + { + "description": "too many sub-items", + "data": [ + [ + { + "foo": null + }, + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": false + }, + { + "description": "wrong item", + "data": [ + { + "foo": null + }, + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": false + }, + { + "description": "wrong sub-item", + "data": [ + [ + {}, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": false, + "skip": "unexpected success" + }, + { + "description": "fewer items is valid", + "data": [ + [ + { + "foo": null + } + ], + [ + { + "foo": null + } + ] + ], + "valid": true, + "skip": "incompatible list lengths (2 and 3)\n" + } + ] + }, + { + "description": "nested items", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "array", + "items": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "number" + } + } + } + } + }, + "tests": [ + { + "description": "valid nested array", + "data": [ + [ + [ + [ + 1 + ] + ], + [ + [ + 2 + ], + [ + 3 + ] + ] + ], + [ + [ + [ + 4 + ], + [ + 5 + ], + [ + 6 + ] + ] + ] + ], + "valid": true + }, + { + "description": "nested array with invalid type", + "data": [ + [ + [ + [ + "1" + ] + ], + [ + [ + 2 + ], + [ + 3 + ] + ] + ], + [ + [ + [ + 4 + ], + [ + 5 + ], + [ + 6 + ] + ] + ] + ], + "valid": false + }, + { + "description": "not deep enough", + "data": [ + [ + [ + 1 + ], + [ + 2 + ], + [ + 3 + ] + ], + [ + [ + 4 + ], + [ + 5 + ], + [ + 6 + ] + ] + ], + "valid": false + } + ] + }, + { + "description": "single-form items with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ + null + ], + "valid": true + } + ] + }, + { + "description": "array-form items with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { + "type": "null" + } + ] + }, + "tests": [ + { + "description": "allows null elements", + "data": [ + null + ], + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/maxContains.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/maxContains.json new file mode 100644 index 000000000..01e8d828f --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/maxContains.json @@ -0,0 +1,141 @@ +[ + { + "description": "maxContains without contains is ignored", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maxContains": 1 + }, + "tests": [ + { + "description": "one item valid against lone maxContains", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "two items still valid against lone maxContains", + "data": [ + 1, + 2 + ], + "valid": true + } + ] + }, + { + "description": "maxContains with contains", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": { + "const": 1 + }, + "maxContains": 1 + }, + "tests": [ + { + "description": "empty data", + "data": [], + "valid": false + }, + { + "description": "all elements match, valid maxContains", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "all elements match, invalid maxContains", + "data": [ + 1, + 1 + ], + "valid": false + }, + { + "description": "some elements match, valid maxContains", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "some elements match, invalid maxContains", + "data": [ + 1, + 2, + 1 + ], + "valid": false + } + ] + }, + { + "description": "maxContains with contains, value with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": { + "const": 1 + }, + "maxContains": 1.0 + }, + "skip": "extract error: value of \"maxContains\" must be a non-negative integer value", + "tests": [ + { + "description": "one element matches, valid maxContains", + "data": [ + 1 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too many elements match, invalid maxContains", + "data": [ + 1, + 1 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "minContains \u003c maxContains", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": { + "const": 1 + }, + "minContains": 1, + "maxContains": 3 + }, + "tests": [ + { + "description": "actual \u003c minContains \u003c maxContains", + "data": [], + "valid": false + }, + { + "description": "minContains \u003c actual \u003c maxContains", + "data": [ + 1, + 1 + ], + "valid": true + }, + { + "description": "minContains \u003c maxContains \u003c actual", + "data": [ + 1, + 1, + 1, + 1 + ], + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/maxItems.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/maxItems.json new file mode 100644 index 000000000..058d5a40c --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/maxItems.json @@ -0,0 +1,68 @@ +[ + { + "description": "maxItems validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maxItems": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "exact length is valid", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "too long is invalid", + "data": [ + 1, + 2, + 3 + ], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": "foobar", + "valid": true + } + ] + }, + { + "description": "maxItems validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maxItems": 2.0 + }, + "skip": "extract error: invalid uint", + "tests": [ + { + "description": "shorter is valid", + "data": [ + 1 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too long is invalid", + "data": [ + 1, + 2, + 3 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/maxLength.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/maxLength.json new file mode 100644 index 000000000..7e1442a96 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/maxLength.json @@ -0,0 +1,56 @@ +[ + { + "description": "maxLength validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maxLength": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true + }, + { + "description": "exact length is valid", + "data": "fo", + "valid": true + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + }, + { + "description": "two graphemes is long enough", + "data": "💩💩", + "valid": true + } + ] + }, + { + "description": "maxLength validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maxLength": 2.0 + }, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values \"f\" and [...] (mismatched types string and list):\n generated.cue:4:1\n generated.cue:4:48\n instance.json:1:1\nconflicting values \"f\" and bool (mismatched types string and bool):\n generated.cue:4:1\n generated.cue:4:8\n instance.json:1:1\nconflicting values \"f\" and null (mismatched types string and null):\n generated.cue:4:1\n instance.json:1:1\nconflicting values \"f\" and number (mismatched types string and number):\n generated.cue:4:1\n generated.cue:4:15\n instance.json:1:1\nconflicting values \"f\" and {...} (mismatched types string and struct):\n generated.cue:4:1\n generated.cue:4:56\n instance.json:1:1\ncannot use 2.0 (type float) as int in argument 2 to strings.MaxRunes:\n generated.cue:4:41\n" + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/maxProperties.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/maxProperties.json new file mode 100644 index 000000000..408eb6cf0 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/maxProperties.json @@ -0,0 +1,103 @@ +[ + { + "description": "maxProperties validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maxProperties": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "exact length is valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "too long is invalid", + "data": { + "foo": 1, + "bar": 2, + "baz": 3 + }, + "valid": false + }, + { + "description": "ignores arrays", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "maxProperties validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maxProperties": 2.0 + }, + "skip": "extract error: invalid uint", + "tests": [ + { + "description": "shorter is valid", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too long is invalid", + "data": { + "foo": 1, + "bar": 2, + "baz": 3 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "maxProperties = 0 means the object is empty", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maxProperties": 0 + }, + "tests": [ + { + "description": "no properties is valid", + "data": {}, + "valid": true + }, + { + "description": "one property is invalid", + "data": { + "foo": 1 + }, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/maximum.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/maximum.json new file mode 100644 index 000000000..3e037eab8 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/maximum.json @@ -0,0 +1,60 @@ +[ + { + "description": "maximum validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maximum": 3.0 + }, + "tests": [ + { + "description": "below the maximum is valid", + "data": 2.6, + "valid": true + }, + { + "description": "boundary point is valid", + "data": 3.0, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 3.5, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + }, + { + "description": "maximum validation with unsigned integer", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maximum": 300 + }, + "tests": [ + { + "description": "below the maximum is invalid", + "data": 299.97, + "valid": true + }, + { + "description": "boundary point integer is valid", + "data": 300, + "valid": true + }, + { + "description": "boundary point float is valid", + "data": 300.00, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 300.5, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/minContains.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/minContains.json new file mode 100644 index 000000000..a00b6a9f2 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/minContains.json @@ -0,0 +1,299 @@ +[ + { + "description": "minContains without contains is ignored", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "minContains": 1 + }, + "tests": [ + { + "description": "one item valid against lone minContains", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "zero items still valid against lone minContains", + "data": [], + "valid": true + } + ] + }, + { + "description": "minContains=1 with contains", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": { + "const": 1 + }, + "minContains": 1 + }, + "tests": [ + { + "description": "empty data", + "data": [], + "valid": false + }, + { + "description": "no elements match", + "data": [ + 2 + ], + "valid": false + }, + { + "description": "single element matches, valid minContains", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "some elements match, valid minContains", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "all elements match, valid minContains", + "data": [ + 1, + 1 + ], + "valid": true + } + ] + }, + { + "description": "minContains=2 with contains", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": { + "const": 1 + }, + "minContains": 2 + }, + "tests": [ + { + "description": "empty data", + "data": [], + "valid": false + }, + { + "description": "all elements match, invalid minContains", + "data": [ + 1 + ], + "valid": false + }, + { + "description": "some elements match, invalid minContains", + "data": [ + 1, + 2 + ], + "valid": false + }, + { + "description": "all elements match, valid minContains (exactly as needed)", + "data": [ + 1, + 1 + ], + "valid": true + }, + { + "description": "all elements match, valid minContains (more than needed)", + "data": [ + 1, + 1, + 1 + ], + "valid": true + }, + { + "description": "some elements match, valid minContains", + "data": [ + 1, + 2, + 1 + ], + "valid": true + } + ] + }, + { + "description": "minContains=2 with contains with a decimal value", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": { + "const": 1 + }, + "minContains": 2.0 + }, + "skip": "extract error: value of \"minContains\" must be a non-negative integer value", + "tests": [ + { + "description": "one element matches, invalid minContains", + "data": [ + 1 + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "both elements match, valid minContains", + "data": [ + 1, + 1 + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "maxContains = minContains", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": { + "const": 1 + }, + "maxContains": 2, + "minContains": 2 + }, + "tests": [ + { + "description": "empty data", + "data": [], + "valid": false + }, + { + "description": "all elements match, invalid minContains", + "data": [ + 1 + ], + "valid": false + }, + { + "description": "all elements match, invalid maxContains", + "data": [ + 1, + 1, + 1 + ], + "valid": false + }, + { + "description": "all elements match, valid maxContains and minContains", + "data": [ + 1, + 1 + ], + "valid": true + } + ] + }, + { + "description": "maxContains \u003c minContains", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": { + "const": 1 + }, + "maxContains": 1, + "minContains": 3 + }, + "tests": [ + { + "description": "empty data", + "data": [], + "valid": false + }, + { + "description": "invalid minContains", + "data": [ + 1 + ], + "valid": false + }, + { + "description": "invalid maxContains", + "data": [ + 1, + 1, + 1 + ], + "valid": false + }, + { + "description": "invalid maxContains and minContains", + "data": [ + 1, + 1 + ], + "valid": false + } + ] + }, + { + "description": "minContains = 0 with no maxContains", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": { + "const": 1 + }, + "minContains": 0 + }, + "tests": [ + { + "description": "empty data", + "data": [], + "valid": true + }, + { + "description": "minContains = 0 makes contains always pass", + "data": [ + 2 + ], + "valid": true + } + ] + }, + { + "description": "minContains = 0 with maxContains", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "contains": { + "const": 1 + }, + "minContains": 0, + "maxContains": 1 + }, + "tests": [ + { + "description": "empty data", + "data": [], + "valid": true + }, + { + "description": "not more than maxContains", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "too many", + "data": [ + 1, + 1 + ], + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/minItems.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/minItems.json new file mode 100644 index 000000000..47d15419c --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/minItems.json @@ -0,0 +1,61 @@ +[ + { + "description": "minItems validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "minItems": 1 + }, + "tests": [ + { + "description": "longer is valid", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "exact length is valid", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "too short is invalid", + "data": [], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": "", + "valid": true + } + ] + }, + { + "description": "minItems validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "minItems": 1.0 + }, + "skip": "extract error: invalid uint", + "tests": [ + { + "description": "longer is valid", + "data": [ + 1, + 2 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too short is invalid", + "data": [], + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/minLength.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/minLength.json new file mode 100644 index 000000000..0d19db6b7 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/minLength.json @@ -0,0 +1,56 @@ +[ + { + "description": "minLength validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "minLength": 2 + }, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true + }, + { + "description": "exact length is valid", + "data": "fo", + "valid": true + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + }, + { + "description": "ignores non-strings", + "data": 1, + "valid": true + }, + { + "description": "one grapheme is not long enough", + "data": "💩", + "valid": false + } + ] + }, + { + "description": "minLength validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "minLength": 2.0 + }, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values \"foo\" and [...] (mismatched types string and list):\n generated.cue:4:1\n generated.cue:4:48\n instance.json:1:1\nconflicting values \"foo\" and bool (mismatched types string and bool):\n generated.cue:4:1\n generated.cue:4:8\n instance.json:1:1\nconflicting values \"foo\" and null (mismatched types string and null):\n generated.cue:4:1\n instance.json:1:1\nconflicting values \"foo\" and number (mismatched types string and number):\n generated.cue:4:1\n generated.cue:4:15\n instance.json:1:1\nconflicting values \"foo\" and {...} (mismatched types string and struct):\n generated.cue:4:1\n generated.cue:4:56\n instance.json:1:1\ncannot use 2.0 (type float) as int in argument 2 to strings.MinRunes:\n generated.cue:4:41\n" + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/minProperties.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/minProperties.json new file mode 100644 index 000000000..3ac17d3f7 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/minProperties.json @@ -0,0 +1,78 @@ +[ + { + "description": "minProperties validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "minProperties": 1 + }, + "skip": "extract error: unsupported constraint \"minProperties\"", + "tests": [ + { + "description": "longer is valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "exact length is valid", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ignores arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores strings", + "data": "", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "minProperties validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "minProperties": 1.0 + }, + "skip": "extract error: unsupported constraint \"minProperties\"", + "tests": [ + { + "description": "longer is valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/minimum.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/minimum.json new file mode 100644 index 000000000..70f9d5740 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/minimum.json @@ -0,0 +1,75 @@ +[ + { + "description": "minimum validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "minimum": 1.1 + }, + "tests": [ + { + "description": "above the minimum is valid", + "data": 2.6, + "valid": true + }, + { + "description": "boundary point is valid", + "data": 1.1, + "valid": true + }, + { + "description": "below the minimum is invalid", + "data": 0.6, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + }, + { + "description": "minimum validation with signed integer", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "minimum": -2 + }, + "tests": [ + { + "description": "negative above the minimum is valid", + "data": -1, + "valid": true + }, + { + "description": "positive above the minimum is valid", + "data": 0, + "valid": true + }, + { + "description": "boundary point is valid", + "data": -2, + "valid": true + }, + { + "description": "boundary point with float is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float below the minimum is invalid", + "data": -2.0001, + "valid": false + }, + { + "description": "int below the minimum is invalid", + "data": -3, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/multipleOf.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/multipleOf.json new file mode 100644 index 000000000..3d1d06435 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/multipleOf.json @@ -0,0 +1,99 @@ +[ + { + "description": "by int", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "multipleOf": 2 + }, + "tests": [ + { + "description": "int by int", + "data": 10, + "valid": true + }, + { + "description": "int by int fail", + "data": 7, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "by number", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "multipleOf": 1.5 + }, + "tests": [ + { + "description": "zero is multiple of anything", + "data": 0, + "valid": true + }, + { + "description": "4.5 is multiple of 1.5", + "data": 4.5, + "valid": true + }, + { + "description": "35 is not multiple of 1.5", + "data": 35, + "valid": false + } + ] + }, + { + "description": "by small number", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "multipleOf": 0.0001 + }, + "tests": [ + { + "description": "0.0075 is multiple of 0.0001", + "data": 0.0075, + "valid": true + }, + { + "description": "0.00751 is not multiple of 0.0001", + "data": 0.00751, + "valid": false + } + ] + }, + { + "description": "float division = inf", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "integer", + "multipleOf": 0.123456789 + }, + "tests": [ + { + "description": "always invalid, but naive implementations may raise an overflow error", + "data": 1E+308, + "valid": false + } + ] + }, + { + "description": "small multiple of large integer", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "integer", + "multipleOf": 1E-8 + }, + "tests": [ + { + "description": "any integer is a multiple of 1e-8", + "data": 12391239123, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/not.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/not.json new file mode 100644 index 000000000..50d0d788e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/not.json @@ -0,0 +1,389 @@ +[ + { + "description": "not", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "not": { + "type": "integer" + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "allowed", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "disallowed", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "not multiple types", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "not": { + "type": [ + "integer", + "boolean" + ] + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "other mismatch", + "data": true, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "not more complex schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "not": { + "type": "object", + "properties": { + "foo": { + "type": "string" + } + } + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "match", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "other match", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "forbidden property", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": { + "not": {} + } + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "property present", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "property absent", + "data": { + "bar": 1, + "baz": 2 + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "forbid everything with empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "not": {} + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "null is invalid", + "data": null, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "object is invalid", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "array is invalid", + "data": [ + "foo" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "forbid everything with boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "not": true + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "null is invalid", + "data": null, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "object is invalid", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "array is invalid", + "data": [ + "foo" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "allow everything with boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "not": false + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string is valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "boolean true is valid", + "data": true, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "boolean false is valid", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "null is valid", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "object is valid", + "data": { + "foo": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "array is valid", + "data": [ + "foo" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "empty array is valid", + "data": [], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "double negation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "not": { + "not": {} + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "collect annotations inside a 'not', even if collection is disabled", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "not": { + "$comment": "this subschema must still produce annotations internally, even though the 'not' will ultimately discard them", + "anyOf": [ + true, + { + "properties": { + "foo": true + } + } + ], + "unevaluatedProperties": false + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "unevaluated property", + "data": { + "bar": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "annotations are still collected inside a 'not'", + "data": { + "foo": 1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/oneOf.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/oneOf.json new file mode 100644 index 000000000..276d6d28b --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/oneOf.json @@ -0,0 +1,375 @@ +[ + { + "description": "oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "oneOf": [ + { + "type": "integer" + }, + { + "minimum": 2 + } + ] + }, + "tests": [ + { + "description": "first oneOf valid", + "data": 1, + "valid": true + }, + { + "description": "second oneOf valid", + "data": 2.5, + "valid": true + }, + { + "description": "both oneOf valid", + "data": 3, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "neither oneOf valid", + "data": 1.5, + "valid": false + } + ] + }, + { + "description": "oneOf with base schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "string", + "oneOf": [ + { + "minLength": 2 + }, + { + "maxLength": 4 + } + ] + }, + "tests": [ + { + "description": "mismatch base schema", + "data": 3, + "valid": false + }, + { + "description": "one oneOf valid", + "data": "foobar", + "valid": true + }, + { + "description": "both oneOf valid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with boolean schemas, all true", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "oneOf": [ + true, + true, + true + ] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with boolean schemas, one true", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "oneOf": [ + true, + false, + false + ] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "oneOf with boolean schemas, more than one true", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "oneOf": [ + true, + true, + false + ] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with boolean schemas, all false", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "oneOf": [ + false, + false, + false + ] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf complex types", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "oneOf": [ + { + "properties": { + "bar": { + "type": "integer" + } + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + } + ] + }, + "tests": [ + { + "description": "first oneOf valid (complex)", + "data": { + "bar": 2 + }, + "valid": true + }, + { + "description": "second oneOf valid (complex)", + "data": { + "foo": "baz" + }, + "valid": true + }, + { + "description": "both oneOf valid (complex)", + "data": { + "foo": "baz", + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "neither oneOf valid (complex)", + "data": { + "foo": 2, + "bar": "quux" + }, + "valid": false + } + ] + }, + { + "description": "oneOf with empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "oneOf": [ + { + "type": "number" + }, + {} + ] + }, + "tests": [ + { + "description": "one valid - valid", + "data": "foo", + "valid": true + }, + { + "description": "both valid - invalid", + "data": 123, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with required", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "oneOf": [ + { + "required": [ + "foo", + "bar" + ] + }, + { + "required": [ + "foo", + "baz" + ] + } + ] + }, + "tests": [ + { + "description": "both invalid - invalid", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "first valid - valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "second valid - valid", + "data": { + "foo": 1, + "baz": 3 + }, + "valid": true + }, + { + "description": "both valid - invalid", + "data": { + "foo": 1, + "bar": 2, + "baz": 3 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with missing optional property", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "oneOf": [ + { + "properties": { + "bar": true, + "baz": true + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "foo": true + }, + "required": [ + "foo" + ] + } + ] + }, + "tests": [ + { + "description": "first oneOf valid", + "data": { + "bar": 8 + }, + "valid": true + }, + { + "description": "second oneOf valid", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "both oneOf valid", + "data": { + "foo": "foo", + "bar": 8 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "neither oneOf valid", + "data": { + "baz": "quux" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "nested oneOf, to check validation semantics", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "oneOf": [ + { + "oneOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/anchor.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/anchor.json new file mode 100644 index 000000000..31f5a7aaf --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/anchor.json @@ -0,0 +1,69 @@ +[ + { + "description": "$anchor inside an enum is not a real identifier", + "comment": "the implementation must not be confused by an $anchor buried in the enum", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "anchor_in_enum": { + "enum": [ + { + "$anchor": "my_anchor", + "type": "null" + } + ] + }, + "real_identifier_in_schema": { + "$anchor": "my_anchor", + "type": "string" + }, + "zzz_anchor_in_const": { + "const": { + "$anchor": "my_anchor", + "type": "null" + } + } + }, + "anyOf": [ + { + "$ref": "#/$defs/anchor_in_enum" + }, + { + "$ref": "#my_anchor" + } + ] + }, + "skip": "extract error: unsupported constraint \"$anchor\" (and 1 more errors)", + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "$anchor": "my_anchor", + "type": "null" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "in implementations that strip $anchor, this may match either $def", + "data": { + "type": "null" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "match $ref to $anchor", + "data": "a string to match #/$defs/anchor_in_enum", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "no match on enum or $ref to $anchor", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/bignum.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/bignum.json new file mode 100644 index 000000000..5a984da1c --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/bignum.json @@ -0,0 +1,110 @@ +[ + { + "description": "integer", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "integer" + }, + "tests": [ + { + "description": "a bignum is an integer", + "data": 12345678910111213141516171819202122232425262728293031, + "valid": true + }, + { + "description": "a negative bignum is an integer", + "data": -12345678910111213141516171819202122232425262728293031, + "valid": true + } + ] + }, + { + "description": "number", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "number" + }, + "tests": [ + { + "description": "a bignum is a number", + "data": 98249283749234923498293171823948729348710298301928331, + "valid": true + }, + { + "description": "a negative bignum is a number", + "data": -98249283749234923498293171823948729348710298301928331, + "valid": true + } + ] + }, + { + "description": "string", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "string" + }, + "tests": [ + { + "description": "a bignum is not a string", + "data": 98249283749234923498293171823948729348710298301928331, + "valid": false + } + ] + }, + { + "description": "maximum integer comparison", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "maximum": 18446744073709551615 + }, + "tests": [ + { + "description": "comparison works for high numbers", + "data": 18446744073709551600, + "valid": true + } + ] + }, + { + "description": "float comparison with high precision", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "exclusiveMaximum": 972783798187987123879878123.18878137 + }, + "tests": [ + { + "description": "comparison works for high numbers", + "data": 972783798187987123879878123.188781371, + "valid": false + } + ] + }, + { + "description": "minimum integer comparison", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "minimum": -18446744073709551615 + }, + "tests": [ + { + "description": "comparison works for very negative numbers", + "data": -18446744073709551600, + "valid": true + } + ] + }, + { + "description": "float comparison with high precision on negative numbers", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "exclusiveMinimum": -972783798187987123879878123.18878137 + }, + "tests": [ + { + "description": "comparison works for very negative numbers", + "data": -972783798187987123879878123.188781371, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/cross-draft.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/cross-draft.json new file mode 100644 index 000000000..093596562 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/cross-draft.json @@ -0,0 +1,63 @@ +[ + { + "description": "refs to future drafts are processed as future drafts", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "array", + "$ref": "http://localhost:1234/draft2020-12/prefixItems.json" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2020-12/prefixItems.json:prefixItems\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "first item not a string is invalid", + "comment": "if the implementation is not processing the $ref as a 2020-12 schema, this test will fail", + "data": [ + 1, + 2, + 3 + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "first item is a string is valid", + "data": [ + "a string", + 1, + 2, + 3 + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "refs to historic drafts are processed as historic drafts", + "schema": { + "type": "object", + "allOf": [ + { + "properties": { + "foo": true + } + }, + { + "$ref": "http://localhost:1234/draft7/ignore-dependentRequired.json" + } + ] + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft7/ignore-dependentRequired.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "missing bar is valid", + "comment": "if the implementation is not processing the $ref as a draft 7 schema, this test will fail", + "data": { + "foo": "any value" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/dependencies-compatibility.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/dependencies-compatibility.json new file mode 100644 index 000000000..eb101366a --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/dependencies-compatibility.json @@ -0,0 +1,374 @@ +[ + { + "description": "single dependency", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependencies": { + "bar": [ + "foo" + ] + } + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependant", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "with dependency", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "missing dependency", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ignores arrays", + "data": [ + "bar" + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "empty dependents", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependencies": { + "bar": [] + } + }, + "tests": [ + { + "description": "empty object", + "data": {}, + "valid": true + }, + { + "description": "object with one property", + "data": { + "bar": 2 + }, + "valid": true + }, + { + "description": "non-object is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "multiple dependents required", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependencies": { + "quux": [ + "foo", + "bar" + ] + } + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependants", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "with dependencies", + "data": { + "foo": 1, + "bar": 2, + "quux": 3 + }, + "valid": true + }, + { + "description": "missing dependency", + "data": { + "foo": 1, + "quux": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "missing other dependency", + "data": { + "bar": 1, + "quux": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "missing both dependencies", + "data": { + "quux": 1 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependencies": { + "foo\nbar": [ + "foo\rbar" + ], + "foo\"bar": [ + "foo'bar" + ] + } + }, + "tests": [ + { + "description": "CRLF", + "data": { + "foo\nbar": 1, + "foo\rbar": 2 + }, + "valid": true + }, + { + "description": "quoted quotes", + "data": { + "foo'bar": 1, + "foo\"bar": 2 + }, + "valid": true + }, + { + "description": "CRLF missing dependent", + "data": { + "foo\nbar": 1, + "foo": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "quoted quotes missing dependent", + "data": { + "foo\"bar": 2 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "single schema dependency", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependencies": { + "bar": { + "properties": { + "foo": { + "type": "integer" + }, + "bar": { + "type": "integer" + } + } + } + } + }, + "tests": [ + { + "description": "valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "no dependency", + "data": { + "foo": "quux" + }, + "valid": true + }, + { + "description": "wrong type", + "data": { + "foo": "quux", + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "wrong type other", + "data": { + "foo": 2, + "bar": "quux" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "wrong type both", + "data": { + "foo": "quux", + "bar": "quux" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ignores arrays", + "data": [ + "bar" + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "boolean subschemas", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependencies": { + "foo": true, + "bar": false + } + }, + "tests": [ + { + "description": "object with property having schema true is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "object with property having schema false is invalid", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "object with both properties is invalid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "schema dependencies with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "dependencies": { + "foo\tbar": { + "minProperties": 4 + }, + "foo'bar": { + "required": [ + "foo\"bar" + ] + } + } + }, + "tests": [ + { + "description": "quoted tab", + "data": { + "foo\tbar": 1, + "a": 2, + "b": 3, + "c": 4 + }, + "valid": true + }, + { + "description": "quoted quote", + "data": { + "foo'bar": { + "foo\"bar": 1 + } + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "quoted tab invalid under dependent schema", + "data": { + "foo\tbar": 1, + "a": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "quoted quote invalid under dependent schema", + "data": { + "foo'bar": 1 + }, + "valid": false, + "skip": "unexpected success" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/ecmascript-regex.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/ecmascript-regex.json new file mode 100644 index 000000000..bade17f43 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/ecmascript-regex.json @@ -0,0 +1,650 @@ +[ + { + "description": "ECMA 262 regex $ does not match trailing newline", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "string", + "pattern": "^abc$" + }, + "tests": [ + { + "description": "matches in Python, but not in ECMA 262", + "data": "abc\\n", + "valid": false + }, + { + "description": "matches", + "data": "abc", + "valid": true + } + ] + }, + { + "description": "ECMA 262 regex converts \\t to horizontal tab", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "string", + "pattern": "^\\t$" + }, + "tests": [ + { + "description": "does not match", + "data": "\\t", + "valid": false + }, + { + "description": "matches", + "data": "\t", + "valid": true + } + ] + }, + { + "description": "ECMA 262 regex escapes control codes with \\c and upper letter", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "string", + "pattern": "^\\cC$" + }, + "skip": "extract error: unsupported regexp: error parsing regexp: invalid escape sequence: `\\c`", + "tests": [ + { + "description": "does not match", + "data": "\\cC", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "matches", + "data": "\u0003", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ECMA 262 regex escapes control codes with \\c and lower letter", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "string", + "pattern": "^\\cc$" + }, + "skip": "extract error: unsupported regexp: error parsing regexp: invalid escape sequence: `\\c`", + "tests": [ + { + "description": "does not match", + "data": "\\cc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "matches", + "data": "\u0003", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ECMA 262 \\d matches ascii digits only", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "string", + "pattern": "^\\d$" + }, + "tests": [ + { + "description": "ASCII zero matches", + "data": "0", + "valid": true + }, + { + "description": "NKO DIGIT ZERO does not match (unlike e.g. Python)", + "data": "߀", + "valid": false + }, + { + "description": "NKO DIGIT ZERO (as \\u escape) does not match", + "data": "߀", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\D matches everything but ascii digits", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "string", + "pattern": "^\\D$" + }, + "tests": [ + { + "description": "ASCII zero does not match", + "data": "0", + "valid": false + }, + { + "description": "NKO DIGIT ZERO matches (unlike e.g. Python)", + "data": "߀", + "valid": true + }, + { + "description": "NKO DIGIT ZERO (as \\u escape) matches", + "data": "߀", + "valid": true + } + ] + }, + { + "description": "ECMA 262 \\w matches ascii letters only", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "string", + "pattern": "^\\w$" + }, + "tests": [ + { + "description": "ASCII 'a' matches", + "data": "a", + "valid": true + }, + { + "description": "latin-1 e-acute does not match (unlike e.g. Python)", + "data": "é", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\W matches everything but ascii letters", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "string", + "pattern": "^\\W$" + }, + "tests": [ + { + "description": "ASCII 'a' does not match", + "data": "a", + "valid": false + }, + { + "description": "latin-1 e-acute matches (unlike e.g. Python)", + "data": "é", + "valid": true + } + ] + }, + { + "description": "ECMA 262 \\s matches whitespace", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "string", + "pattern": "^\\s$" + }, + "tests": [ + { + "description": "ASCII space matches", + "data": " ", + "valid": true + }, + { + "description": "Character tabulation matches", + "data": "\t", + "valid": true + }, + { + "description": "Line tabulation matches", + "data": "\u000b", + "valid": true, + "skip": "invalid value \"\\v\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n generated.cue:1:1\n instance.json:1:1\n" + }, + { + "description": "Form feed matches", + "data": "\f", + "valid": true + }, + { + "description": "latin-1 non-breaking-space matches", + "data": " ", + "valid": true, + "skip": "invalid value \"\\u00a0\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n generated.cue:1:1\n instance.json:1:1\n" + }, + { + "description": "zero-width whitespace matches", + "data": "\ufeff", + "valid": true, + "skip": "invalid value \"\\ufeff\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n generated.cue:1:1\n instance.json:1:1\n" + }, + { + "description": "line feed matches (line terminator)", + "data": "\n", + "valid": true + }, + { + "description": "paragraph separator matches (line terminator)", + "data": "\u2029", + "valid": true, + "skip": "invalid value \"\\u2029\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n generated.cue:1:1\n instance.json:1:1\n" + }, + { + "description": "EM SPACE matches (Space_Separator)", + "data": " ", + "valid": true, + "skip": "invalid value \"\\u2003\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n generated.cue:1:1\n instance.json:1:1\n" + }, + { + "description": "Non-whitespace control does not match", + "data": "\u0001", + "valid": false + }, + { + "description": "Non-whitespace does not match", + "data": "–", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\S matches everything but whitespace", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "string", + "pattern": "^\\S$" + }, + "tests": [ + { + "description": "ASCII space does not match", + "data": " ", + "valid": false + }, + { + "description": "Character tabulation does not match", + "data": "\t", + "valid": false + }, + { + "description": "Line tabulation does not match", + "data": "\u000b", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "Form feed does not match", + "data": "\f", + "valid": false + }, + { + "description": "latin-1 non-breaking-space does not match", + "data": " ", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "zero-width whitespace does not match", + "data": "\ufeff", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "line feed does not match (line terminator)", + "data": "\n", + "valid": false + }, + { + "description": "paragraph separator does not match (line terminator)", + "data": "\u2029", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "EM SPACE does not match (Space_Separator)", + "data": " ", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "Non-whitespace control matches", + "data": "\u0001", + "valid": true + }, + { + "description": "Non-whitespace matches", + "data": "–", + "valid": true + } + ] + }, + { + "description": "patterns always use unicode semantics with pattern", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "pattern": "\\p{Letter}cole" + }, + "skip": "extract error: unsupported regexp: error parsing regexp: invalid character class range: `\\p{Letter}`", + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ÉTAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ÉCOLE, L'ÉGLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ÉTAIT SUR LA PATINOIRE.", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "\\w in patterns matches [A-Za-z0-9_], not unicode letters", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "pattern": "\\wcole" + }, + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": false + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ÉTAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ÉCOLE, L'ÉGLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ÉTAIT SUR LA PATINOIRE.", + "valid": false + } + ] + }, + { + "description": "pattern with ASCII ranges", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "pattern": "[a-z]cole" + }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": false + }, + { + "description": "ascii characters match", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + } + ] + }, + { + "description": "\\d in pattern matches [0-9], not unicode digits", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "pattern": "^\\d+$" + }, + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "৪২", + "valid": false + } + ] + }, + { + "description": "pattern with non-ASCII digits", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "pattern": "^\\p{digit}+$" + }, + "skip": "extract error: unsupported regexp: error parsing regexp: invalid character class range: `\\p{digit}`", + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "৪২", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "patterns always use unicode semantics with patternProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "patternProperties": { + "\\p{Letter}cole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { + "l'ecole": "pas de vraie vie" + }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": true + }, + { + "description": "unicode character in hex format in string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": true + }, + { + "description": "unicode matching is case-sensitive", + "data": { + "L'ÉCOLE": "PAS DE VRAIE VIE" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "\\w in patternProperties matches [A-Za-z0-9_], not unicode letters", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "patternProperties": { + "\\wcole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { + "l'ecole": "pas de vraie vie" + }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "unicode character in hex format in string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "unicode matching is case-sensitive", + "data": { + "L'ÉCOLE": "PAS DE VRAIE VIE" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "patternProperties with ASCII ranges", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "patternProperties": { + "[a-z]cole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "unicode character in hex format in string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ascii characters match", + "data": { + "l'ecole": "pas de vraie vie" + }, + "valid": true + } + ] + }, + { + "description": "\\d in patternProperties matches [0-9], not unicode digits", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "patternProperties": { + "^\\d+$": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { + "42": "life, the universe, and everything" + }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { + "-%#": "spending the year dead for tax reasons" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { + "৪২": "khajit has wares if you have coin" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "patternProperties with non-ASCII digits", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "patternProperties": { + "^\\p{digit}+$": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { + "42": "life, the universe, and everything" + }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { + "-%#": "spending the year dead for tax reasons" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { + "৪২": "khajit has wares if you have coin" + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/float-overflow.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/float-overflow.json new file mode 100644 index 000000000..d22b5f34e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/float-overflow.json @@ -0,0 +1,18 @@ +[ + { + "description": "all integers are multiples of 0.5, if overflow is handled", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "integer", + "multipleOf": 0.5 + }, + "tests": [ + { + "description": "valid if optional overflow handling is implemented", + "data": 1E+308, + "valid": true, + "skip": "conflicting values 1E+308 and int (mismatched types float and int):\n generated.cue:4:1\n instance.json:1:1\n" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/date-time.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/date-time.json new file mode 100644 index 000000000..01969352b --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/date-time.json @@ -0,0 +1,162 @@ +[ + { + "description": "validation of date-time strings", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "date-time" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time string", + "data": "1963-06-19T08:30:06.283185Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time string without second fraction", + "data": "1963-06-19T08:30:06Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time string with plus offset", + "data": "1937-01-01T12:00:27.87+00:20", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time string with minus offset", + "data": "1990-12-31T15:59:50.123-08:00", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time with a leap second, UTC", + "data": "1998-12-31T23:59:60Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time with a leap second, with minus offset", + "data": "1998-12-31T15:59:60.123-08:00", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid date-time past leap second, UTC", + "data": "1998-12-31T23:59:61Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid date-time with leap second on a wrong minute, UTC", + "data": "1998-12-31T23:58:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid date-time with leap second on a wrong hour, UTC", + "data": "1998-12-31T22:59:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid day in date-time string", + "data": "1990-02-31T15:59:59.123-08:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid offset in date-time string", + "data": "1990-12-31T15:59:59-24:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid closing Z after time-zone offset", + "data": "1963-06-19T08:30:06.28123+01:00Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid date-time string", + "data": "06/19/1963 08:30:06 PST", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "case-insensitive T and Z", + "data": "1963-06-19t08:30:06.283185z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "2013-350T01:01:01", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-padded month dates", + "data": "1963-6-19T08:30:06.283185Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-padded day dates", + "data": "1963-06-1T08:30:06.283185Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4) in date portion", + "data": "1963-06-1৪T00:00:00Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4) in time portion", + "data": "1963-06-11T0৪:00:00Z", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/date.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/date.json new file mode 100644 index 000000000..e3248c916 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/date.json @@ -0,0 +1,294 @@ +[ + { + "description": "validation of date strings", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "date" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date string", + "data": "1963-06-19", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in January", + "data": "2020-01-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in January", + "data": "2020-01-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 28 days in February (normal)", + "data": "2021-02-28", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 29 days in February (normal)", + "data": "2021-02-29", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 29 days in February (leap)", + "data": "2020-02-29", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 30 days in February (leap)", + "data": "2020-02-30", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in March", + "data": "2020-03-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in March", + "data": "2020-03-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 30 days in April", + "data": "2020-04-30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 31 days in April", + "data": "2020-04-31", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in May", + "data": "2020-05-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in May", + "data": "2020-05-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 30 days in June", + "data": "2020-06-30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 31 days in June", + "data": "2020-06-31", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in July", + "data": "2020-07-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in July", + "data": "2020-07-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in August", + "data": "2020-08-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in August", + "data": "2020-08-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 30 days in September", + "data": "2020-09-30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 31 days in September", + "data": "2020-09-31", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in October", + "data": "2020-10-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in October", + "data": "2020-10-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 30 days in November", + "data": "2020-11-30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 31 days in November", + "data": "2020-11-31", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in December", + "data": "2020-12-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in December", + "data": "2020-12-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with invalid month", + "data": "2020-13-01", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid date string", + "data": "06/19/1963", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "2013-350", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "non-padded month dates are not valid", + "data": "1998-1-20", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "non-padded day dates are not valid", + "data": "1998-01-1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid month", + "data": "1998-13-01", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid month-day combination", + "data": "1998-04-31", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "2021 is not a leap year", + "data": "2021-02-29", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "2020 is a leap year", + "data": "2020-02-29", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4)", + "data": "1963-06-1৪", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ISO8601 / non-RFC3339: YYYYMMDD without dashes (2023-03-28)", + "data": "20230328", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ISO8601 / non-RFC3339: week number implicit day of week (2023-01-02)", + "data": "2023-W01", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ISO8601 / non-RFC3339: week number with day of week (2023-03-28)", + "data": "2023-W13-2", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ISO8601 / non-RFC3339: week number rollover to next year (2023-01-01)", + "data": "2022W527", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/duration.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/duration.json new file mode 100644 index 000000000..0fc908215 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/duration.json @@ -0,0 +1,162 @@ +[ + { + "description": "validation of duration strings", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "duration" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid duration string", + "data": "P4DT12H30M5S", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid duration string", + "data": "PT1D", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no elements present", + "data": "P", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no time elements present", + "data": "P1YT", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no date or time elements present", + "data": "PT", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "elements out of order", + "data": "P2D1Y", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "missing time separator", + "data": "P1D2H", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "time element in the date position", + "data": "P2S", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "four years duration", + "data": "P4Y", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "zero time, in seconds", + "data": "PT0S", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "zero time, in days", + "data": "P0D", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "one month duration", + "data": "P1M", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "one minute duration", + "data": "PT1M", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "one and a half days, in hours", + "data": "PT36H", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "one and a half days, in days and hours", + "data": "P1DT12H", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "two weeks", + "data": "P2W", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "weeks cannot be combined with other units", + "data": "P1Y2W", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '২' (a Bengali 2)", + "data": "P২Y", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "element without unit", + "data": "P1", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/email.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/email.json new file mode 100644 index 000000000..2860011ad --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/email.json @@ -0,0 +1,102 @@ +[ + { + "description": "validation of e-mail addresses", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "email" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid e-mail address", + "data": "joe.bloggs@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid e-mail address", + "data": "2962", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "tilde in local part is valid", + "data": "te~st@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "tilde before local part is valid", + "data": "~test@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "tilde after local part is valid", + "data": "test~@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "dot before local part is not valid", + "data": ".test@example.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "dot after local part is not valid", + "data": "test.@example.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "two separated dots inside local part are valid", + "data": "te.s.t@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "two subsequent dots inside local part are not valid", + "data": "te..st@example.com", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/hostname.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/hostname.json new file mode 100644 index 000000000..9fdd42592 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/hostname.json @@ -0,0 +1,150 @@ +[ + { + "description": "validation of host names", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "hostname" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid host name", + "data": "www.example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid punycoded IDN hostname", + "data": "xn--4gbwdl.xn--wgbh1c", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a host name starting with an illegal character", + "data": "-a-host-name-that-starts-with--", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a host name containing illegal characters", + "data": "not_a_valid_host_name", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a host name with a component too long", + "data": "a-vvvvvvvvvvvvvvvveeeeeeeeeeeeeeeerrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy-long-host-name-component", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "starts with hyphen", + "data": "-hostname", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ends with hyphen", + "data": "hostname-", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "starts with underscore", + "data": "_hostname", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ends with underscore", + "data": "hostname_", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "contains underscore", + "data": "host_name", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "exceeds maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "single label", + "data": "hostname", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label with hyphen", + "data": "host-name", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label with digits", + "data": "h0stn4me", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label starting with digit", + "data": "1host", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label ending with digit", + "data": "hostnam3", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/idn-email.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/idn-email.json new file mode 100644 index 000000000..3136248cd --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/idn-email.json @@ -0,0 +1,72 @@ +[ + { + "description": "validation of an internationalized e-mail addresses", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "idn-email" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid idn e-mail (example@example.test in Hangul)", + "data": "실례@실례.테스트", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid idn e-mail address", + "data": "2962", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid e-mail address", + "data": "joe.bloggs@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid e-mail address", + "data": "2962", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/idn-hostname.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/idn-hostname.json new file mode 100644 index 000000000..3945dded3 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/idn-hostname.json @@ -0,0 +1,389 @@ +[ + { + "description": "validation of internationalized host names", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "idn-hostname" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid host name (example.test in Hangul)", + "data": "실례.테스트", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "illegal first char U+302E Hangul single dot tone mark", + "data": "〮실례.테스트", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "contains illegal char U+302E Hangul single dot tone mark", + "data": "실〮례.테스트", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a host name with a component too long", + "data": "실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실례례테스트례례례례례례례례례례례례례례례례례테스트례례례례례례례례례례례례례례례례례례례테스트례례례례례례례례례례례례테스트례례실례.테스트", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid label, correct Punycode", + "comment": "https://tools.ietf.org/html/rfc5890#section-2.3.2.1 https://tools.ietf.org/html/rfc5891#section-4.4 https://tools.ietf.org/html/rfc3492#section-7.1", + "data": "-\u003e $1.00 \u003c--", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid Chinese Punycode", + "comment": "https://tools.ietf.org/html/rfc5890#section-2.3.2.1 https://tools.ietf.org/html/rfc5891#section-4.4", + "data": "xn--ihqwcrb4cv8a8dqg056pqjye", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid Punycode", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.4 https://tools.ietf.org/html/rfc5890#section-2.3.2.1", + "data": "xn--X", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "U-label contains \"--\" in the 3rd and 4th position", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1 https://tools.ietf.org/html/rfc5890#section-2.3.2.1", + "data": "XN--aa---o47jg78q", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "U-label starts with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "-hello", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "U-label ends with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "hello-", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "U-label starts and ends with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "-hello-", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Begins with a Spacing Combining Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "ःhello", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Begins with a Nonspacing Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "̀hello", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Begins with an Enclosing Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "҈hello", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Exceptions that are PVALID, left-to-right chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "ßς་〇", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Exceptions that are PVALID, right-to-left chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "۽۾", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Exceptions that are DISALLOWED, right-to-left chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "ـߺ", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Exceptions that are DISALLOWED, left-to-right chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6 Note: The two combining marks (U+302E and U+302F) are in the middle and not at the start", + "data": "〱〲〳〴〵〮〯〻", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "MIDDLE DOT with no preceding 'l'", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "a·l", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "MIDDLE DOT with nothing preceding", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "·l", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "MIDDLE DOT with no following 'l'", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l·a", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "MIDDLE DOT with nothing following", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l·", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "MIDDLE DOT with surrounding 'l's", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l·l", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Greek KERAIA not followed by Greek", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "α͵S", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Greek KERAIA not followed by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "α͵", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Greek KERAIA followed by Greek", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "α͵β", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Hebrew GERESH not preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "A׳ב", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Hebrew GERESH not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "׳ב", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Hebrew GERESH preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "א׳ב", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Hebrew GERSHAYIM not preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "A״ב", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Hebrew GERSHAYIM not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "״ב", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Hebrew GERSHAYIM preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "א״ב", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "KATAKANA MIDDLE DOT with no Hiragana, Katakana, or Han", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "def・abc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "KATAKANA MIDDLE DOT with no other characters", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "・", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "KATAKANA MIDDLE DOT with Hiragana", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "・ぁ", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "KATAKANA MIDDLE DOT with Katakana", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "・ァ", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "KATAKANA MIDDLE DOT with Han", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "・丈", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Arabic-Indic digits mixed with Extended Arabic-Indic digits", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8", + "data": "ب٠۰", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Arabic-Indic digits not mixed with Extended Arabic-Indic digits", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8", + "data": "ب٠ب", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Extended Arabic-Indic digits not mixed with Arabic-Indic digits", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.9", + "data": "۰0", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ZERO WIDTH JOINER not preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "क‍ष", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ZERO WIDTH JOINER not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "‍ष", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ZERO WIDTH JOINER preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "क्‍ष", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ZERO WIDTH NON-JOINER preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1", + "data": "क्‌ष", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ZERO WIDTH NON-JOINER not preceded by Virama but matches regexp", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1 https://www.w3.org/TR/alreq/#h_disjoining_enforcement", + "data": "بي‌بي", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label", + "data": "hostname", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label with hyphen", + "data": "host-name", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label with digits", + "data": "h0stn4me", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label starting with digit", + "data": "1host", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label ending with digit", + "data": "hostnam3", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/ipv4.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/ipv4.json new file mode 100644 index 000000000..b4010263c --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/ipv4.json @@ -0,0 +1,109 @@ +[ + { + "description": "validation of IP addresses", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "ipv4" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IP address", + "data": "192.168.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an IP address with too many components", + "data": "127.0.0.0.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IP address with out-of-range values", + "data": "256.256.256.256", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IP address without 4 components", + "data": "127.0", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IP address as an integer", + "data": "0x7f000001", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IP address as an integer (decimal)", + "data": "2130706433", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid leading zeroes, as they are treated as octals", + "comment": "see https://sick.codes/universal-netmask-npm-package-used-by-270000-projects-vulnerable-to-octal-input-data-server-side-request-forgery-remote-file-inclusion-local-file-inclusion-and-more-cve-2021-28918/", + "data": "087.10.0.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "value without leading zero is valid", + "data": "87.10.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '২' (a Bengali 2)", + "data": "1২7.0.0.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "netmask is not a part of ipv4 address", + "data": "192.168.1.0/24", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/ipv6.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/ipv6.json new file mode 100644 index 000000000..0e9cbec5c --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/ipv6.json @@ -0,0 +1,252 @@ +[ + { + "description": "validation of IPv6 addresses", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "ipv6" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IPv6 address", + "data": "::1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an IPv6 address with out-of-range values", + "data": "12345::", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "trailing 4 hex symbols is valid", + "data": "::abef", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "trailing 5 hex symbols is invalid", + "data": "::abcef", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IPv6 address with too many components", + "data": "1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IPv6 address containing illegal characters", + "data": "::laptop", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no digits is valid", + "data": "::", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "leading colons is valid", + "data": "::42:ff:1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "trailing colons is valid", + "data": "d6::", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "missing leading octet is invalid", + "data": ":2:3:4:5:6:7:8", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "missing trailing octet is invalid", + "data": "1:2:3:4:5:6:7:", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "missing leading octet with omitted octets later", + "data": ":2:3:4::8", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "single set of double colons in the middle is valid", + "data": "1:d6::42", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "two sets of double colons is invalid", + "data": "1::d6::42", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "mixed format with the ipv4 section as decimal octets", + "data": "1::d6:192.168.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mixed format with double colons between the sections", + "data": "1:2::192.168.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mixed format with ipv4 section with octet out of range", + "data": "1::2:192.168.256.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "mixed format with ipv4 section with a hex octet", + "data": "1::2:192.168.ff.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "mixed format with leading double colons (ipv4-mapped ipv6 address)", + "data": "::ffff:192.168.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "triple colons is invalid", + "data": "1:2:3:4:5:::8", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "8 octets", + "data": "1:2:3:4:5:6:7:8", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "insufficient octets without double colons", + "data": "1:2:3:4:5:6:7", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no colons is invalid", + "data": "1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ipv4 is not ipv6", + "data": "127.0.0.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ipv4 segment must have 4 octets", + "data": "1:2:3:4:1.2.3", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "leading whitespace is invalid", + "data": " ::1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "trailing whitespace is invalid", + "data": "::1 ", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "netmask is not a part of ipv6 address", + "data": "fe80::/64", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "zone id is not a part of ipv6 address", + "data": "fe80::a%eth1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a long valid ipv6", + "data": "1000:1000:1000:1000:1000:1000:255.255.255.255", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a long invalid ipv6, below length limit, first", + "data": "100:100:100:100:100:100:255.255.255.255.255", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a long invalid ipv6, below length limit, second", + "data": "100:100:100:100:100:100:100:255.255.255.255", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4)", + "data": "1:2:3:4:5:6:7:৪", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4) in the IPv4 portion", + "data": "1:2::192.16৪.0.1", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/iri-reference.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/iri-reference.json new file mode 100644 index 000000000..0200643ea --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/iri-reference.json @@ -0,0 +1,90 @@ +[ + { + "description": "validation of IRI References", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "iri-reference" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI", + "data": "http://ƒøø.ßår/?∂éœ=πîx#πîüx", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid protocol-relative IRI Reference", + "data": "//ƒøø.ßår/?∂éœ=πîx#πîüx", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid relative IRI Reference", + "data": "/âππ", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid IRI Reference", + "data": "\\\\WINDOWS\\filëßåré", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI Reference", + "data": "âππ", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI fragment", + "data": "#ƒrägmênt", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid IRI fragment", + "data": "#ƒräg\\mênt", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/iri.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/iri.json new file mode 100644 index 000000000..a09e13bca --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/iri.json @@ -0,0 +1,102 @@ +[ + { + "description": "validation of IRIs", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "iri" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI with anchor tag", + "data": "http://ƒøø.ßår/?∂éœ=πîx#πîüx", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI with anchor tag and parentheses", + "data": "http://ƒøø.com/blah_(wîkïpédiå)_blah#ßité-1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI with URL-encoded stuff", + "data": "http://ƒøø.ßår/?q=Test%20URL-encoded%20stuff", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI with many special characters", + "data": "http://-.~_!$\u0026'()*+,;=:%40:80%2f::::::@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI based on IPv6", + "data": "http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid IRI based on IPv6", + "data": "http://2001:0db8:85a3:0000:0000:8a2e:0370:7334", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid relative IRI Reference", + "data": "/abc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid IRI", + "data": "\\\\WINDOWS\\filëßåré", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid IRI though valid IRI reference", + "data": "âππ", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/json-pointer.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/json-pointer.json new file mode 100644 index 000000000..72675c858 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/json-pointer.json @@ -0,0 +1,240 @@ +[ + { + "description": "validation of JSON-pointers (JSON String Representation)", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "json-pointer" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid JSON-pointer", + "data": "/foo/bar~0/baz~1/%a", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (~ not escaped)", + "data": "/foo/bar~", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer with empty segment", + "data": "/foo//bar", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer with the last empty segment", + "data": "/foo/bar/", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #1", + "data": "", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #2", + "data": "/foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #3", + "data": "/foo/0", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #4", + "data": "/", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #5", + "data": "/a~1b", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #6", + "data": "/c%d", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #7", + "data": "/e^f", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #8", + "data": "/g|h", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #9", + "data": "/i\\j", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #10", + "data": "/k\"l", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #11", + "data": "/ ", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #12", + "data": "/m~0n", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer used adding to the last array position", + "data": "/foo/-", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer (- used as object member name)", + "data": "/foo/-/bar", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer (multiple escaped characters)", + "data": "/~1~0~0~1~1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer (escaped with fraction part) #1", + "data": "/~1.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer (escaped with fraction part) #2", + "data": "/~0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #1", + "data": "#", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #2", + "data": "#/", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #3", + "data": "#a", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (some escaped, but not all) #1", + "data": "/~0~", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (some escaped, but not all) #2", + "data": "/~0/~", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (wrong escape character) #1", + "data": "/~2", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (wrong escape character) #2", + "data": "/~-1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (multiple characters not escaped)", + "data": "/~~", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #1", + "data": "a", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #2", + "data": "0", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #3", + "data": "a/a", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/regex.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/regex.json new file mode 100644 index 000000000..a979bb6e6 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/regex.json @@ -0,0 +1,60 @@ +[ + { + "description": "validation of regular expressions", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "regex" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid regular expression", + "data": "([abc])+\\s+$", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a regular expression with unclosed parens is invalid", + "data": "^(abc]", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/relative-json-pointer.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/relative-json-pointer.json new file mode 100644 index 000000000..9ffbde61b --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/relative-json-pointer.json @@ -0,0 +1,120 @@ +[ + { + "description": "validation of Relative JSON Pointers (RJP)", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "relative-json-pointer" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid upwards RJP", + "data": "1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid downwards RJP", + "data": "0/foo/bar", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid up and then down RJP, with array index", + "data": "2/0/baz/1/zip", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid RJP taking the member or index name", + "data": "0#", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid RJP that is a valid JSON Pointer", + "data": "/foo/bar", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "negative prefix", + "data": "-1/foo/bar", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "explicit positive prefix", + "data": "+1/foo/bar", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "## is not a valid json-pointer", + "data": "0##", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "zero cannot be followed by other digits, plus json-pointer", + "data": "01/a", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "zero cannot be followed by other digits, plus octothorpe", + "data": "01#", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty string", + "data": "", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "multi-digit integer prefix", + "data": "120/foo/bar", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/time.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/time.json new file mode 100644 index 000000000..504b9b32a --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/time.json @@ -0,0 +1,282 @@ +[ + { + "description": "validation of time strings", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "time" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid time string", + "data": "08:30:06Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid time string with extra leading zeros", + "data": "008:030:006Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid time string with no leading zero for single digit", + "data": "8:3:6Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "hour, minute, second must be two digits", + "data": "8:0030:6Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid time string with leap second, Zulu", + "data": "23:59:60Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, Zulu (wrong hour)", + "data": "22:59:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, Zulu (wrong minute)", + "data": "23:58:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid leap second, zero time-offset", + "data": "23:59:60+00:00", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, zero time-offset (wrong hour)", + "data": "22:59:60+00:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, zero time-offset (wrong minute)", + "data": "23:58:60+00:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid leap second, positive time-offset", + "data": "01:29:60+01:30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid leap second, large positive time-offset", + "data": "23:29:60+23:30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, positive time-offset (wrong hour)", + "data": "23:59:60+01:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, positive time-offset (wrong minute)", + "data": "23:59:60+00:30", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid leap second, negative time-offset", + "data": "15:59:60-08:00", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid leap second, large negative time-offset", + "data": "00:29:60-23:30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, negative time-offset (wrong hour)", + "data": "23:59:60-01:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, negative time-offset (wrong minute)", + "data": "23:59:60-00:30", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid time string with second fraction", + "data": "23:20:50.52Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid time string with precise second fraction", + "data": "08:30:06.283185Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid time string with plus offset", + "data": "08:30:06+00:20", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid time string with minus offset", + "data": "08:30:06-08:00", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "hour, minute in time-offset must be two digits", + "data": "08:30:06-8:000", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid time string with case-insensitive Z", + "data": "08:30:06z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid hour", + "data": "24:00:00Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid minute", + "data": "00:60:00Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid second", + "data": "00:00:61Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid leap second (wrong hour)", + "data": "22:59:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid leap second (wrong minute)", + "data": "23:58:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid time numoffset hour", + "data": "01:02:03+24:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid time numoffset minute", + "data": "01:02:03+00:60", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid time with both Z and numoffset", + "data": "01:02:03Z+00:30", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid offset indicator", + "data": "08:30:06 PST", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "01:01:01,1111", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no time offset", + "data": "12:00:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no time offset with second fraction", + "data": "12:00:00.52", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '২' (a Bengali 2)", + "data": "1২:00:00Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "offset not starting with plus or minus", + "data": "08:30:06#00:20", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "contains letters", + "data": "ab:cd:ef", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/unknown.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/unknown.json new file mode 100644 index 000000000..df661aeab --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/unknown.json @@ -0,0 +1,54 @@ +[ + { + "description": "unknown format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "unknown" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "unknown formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore strings", + "data": "string", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/uri-reference.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/uri-reference.json new file mode 100644 index 000000000..5f0d1ef9a --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/uri-reference.json @@ -0,0 +1,90 @@ +[ + { + "description": "validation of URI References", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "uri-reference" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URI", + "data": "http://foo.bar/?baz=qux#quux", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid protocol-relative URI Reference", + "data": "//foo.bar/?baz=qux#quux", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid relative URI Reference", + "data": "/abc", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI Reference", + "data": "\\\\WINDOWS\\fileshare", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid URI Reference", + "data": "abc", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URI fragment", + "data": "#fragment", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI fragment", + "data": "#frag\\ment", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/uri-template.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/uri-template.json new file mode 100644 index 000000000..11a29eb41 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/uri-template.json @@ -0,0 +1,72 @@ +[ + { + "description": "format: uri-template", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "uri-template" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid uri-template", + "data": "http://example.com/dictionary/{term:1}/{term}", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid uri-template", + "data": "http://example.com/dictionary/{term:1}/{term", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid uri-template without variables", + "data": "http://example.com/dictionary", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid relative uri-template", + "data": "dictionary/{term:1}/{term}", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/uri.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/uri.json new file mode 100644 index 000000000..cb819d591 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/uri.json @@ -0,0 +1,168 @@ +[ + { + "description": "validation of URIs", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "uri" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with anchor tag", + "data": "http://foo.bar/?baz=qux#quux", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with anchor tag and parentheses", + "data": "http://foo.com/blah_(wikipedia)_blah#cite-1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with URL-encoded stuff", + "data": "http://foo.bar/?q=Test%20URL-encoded%20stuff", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid puny-coded URL ", + "data": "http://xn--nw2a.xn--j6w193g/", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with many special characters", + "data": "http://-.~_!$\u0026'()*+,;=:%40:80%2f::::::@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL based on IPv4", + "data": "http://223.255.255.254", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with ftp scheme", + "data": "ftp://ftp.is.co.za/rfc/rfc1808.txt", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL for a simple text file", + "data": "http://www.ietf.org/rfc/rfc2396.txt", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL ", + "data": "ldap://[2001:db8::7]/c=GB?objectClass?one", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid mailto URI", + "data": "mailto:John.Doe@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid newsgroup URI", + "data": "news:comp.infosystems.www.servers.unix", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid tel URI", + "data": "tel:+1-816-555-1212", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URN", + "data": "urn:oasis:names:specification:docbook:dtd:xml:4.1.2", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid protocol-relative URI Reference", + "data": "//foo.bar/?baz=qux#quux", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid relative URI Reference", + "data": "/abc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI", + "data": "\\\\WINDOWS\\fileshare", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI though valid URI reference", + "data": "abc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI with spaces", + "data": "http:// shouldfail.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI with spaces and missing scheme", + "data": ":// should fail", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI with comma in scheme", + "data": "bar,baz:foo", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/uuid.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/uuid.json new file mode 100644 index 000000000..218bda311 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/format/uuid.json @@ -0,0 +1,138 @@ +[ + { + "description": "uuid format", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "format": "uuid" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all upper-case", + "data": "2EB8AA08-AA98-11EA-B4AA-73B441D16380", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all lower-case", + "data": "2eb8aa08-aa98-11ea-b4aa-73b441d16380", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mixed case", + "data": "2eb8aa08-AA98-11ea-B4Aa-73B441D16380", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all zeroes is valid", + "data": "00000000-0000-0000-0000-000000000000", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "wrong length", + "data": "2eb8aa08-aa98-11ea-b4aa-73b441d1638", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "missing section", + "data": "2eb8aa08-aa98-11ea-73b441d16380", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "bad characters (not hex)", + "data": "2eb8aa08-aa98-11ea-b4ga-73b441d16380", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no dashes", + "data": "2eb8aa08aa9811eab4aa73b441d16380", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "too few dashes", + "data": "2eb8aa08aa98-11ea-b4aa73b441d16380", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "too many dashes", + "data": "2eb8-aa08-aa98-11ea-b4aa73b44-1d16380", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "dashes in the wrong spot", + "data": "2eb8aa08aa9811eab4aa73b441d16380----", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid version 4", + "data": "98d80576-482e-427f-8434-7f86890ab222", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid version 5", + "data": "99c17cbb-656f-564a-940f-1a4568f03487", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "hypothetical version 6", + "data": "99c17cbb-656f-664a-940f-1a4568f03487", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "hypothetical version 15", + "data": "99c17cbb-656f-f64a-940f-1a4568f03487", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/id.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/id.json new file mode 100644 index 000000000..f5669c4e4 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/id.json @@ -0,0 +1,61 @@ +[ + { + "description": "$id inside an enum is not a real identifier", + "comment": "the implementation must not be confused by an $id buried in the enum", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "id_in_enum": { + "enum": [ + { + "$id": "https://localhost:1234/draft2019-09/id/my_identifier.json", + "type": "null" + } + ] + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/draft2019-09/id/my_identifier.json", + "type": "string" + }, + "zzz_id_in_const": { + "const": { + "$id": "https://localhost:1234/draft2019-09/id/my_identifier.json", + "type": "null" + } + } + }, + "anyOf": [ + { + "$ref": "#/$defs/id_in_enum" + }, + { + "$ref": "https://localhost:1234/draft2019-09/id/my_identifier.json" + } + ] + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2019-09/id/my_identifier.json:my_identifier\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "$id": "https://localhost:1234/draft2019-09/id/my_identifier.json", + "type": "null" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "match $ref to $id", + "data": "a string to match #/$defs/id_in_enum", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "no match on enum or $ref to $id", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/no-schema.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/no-schema.json new file mode 100644 index 000000000..45f3f5125 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/no-schema.json @@ -0,0 +1,26 @@ +[ + { + "description": "validation without $schema", + "comment": "minLength is the same across all drafts", + "schema": { + "minLength": 2 + }, + "tests": [ + { + "description": "a 3-character string is valid", + "data": "foo", + "valid": true + }, + { + "description": "a 1-character string is not valid", + "data": "a", + "valid": false + }, + { + "description": "a non-string is valid", + "data": 5, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/non-bmp-regex.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/non-bmp-regex.json new file mode 100644 index 000000000..1f886f359 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/non-bmp-regex.json @@ -0,0 +1,96 @@ +[ + { + "description": "Proper UTF-16 surrogate pair handling: pattern", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "pattern": "^🐲*$" + }, + "tests": [ + { + "description": "matches empty", + "data": "", + "valid": true + }, + { + "description": "matches single", + "data": "🐲", + "valid": true + }, + { + "description": "matches two", + "data": "🐲🐲", + "valid": true + }, + { + "description": "doesn't match one", + "data": "🐉", + "valid": false + }, + { + "description": "doesn't match two", + "data": "🐉🐉", + "valid": false + }, + { + "description": "doesn't match one ASCII", + "data": "D", + "valid": false + }, + { + "description": "doesn't match two ASCII", + "data": "DD", + "valid": false + } + ] + }, + { + "description": "Proper UTF-16 surrogate pair handling: patternProperties", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "patternProperties": { + "^🐲*$": { + "type": "integer" + } + } + }, + "tests": [ + { + "description": "matches empty", + "data": { + "": 1 + }, + "valid": true + }, + { + "description": "matches single", + "data": { + "🐲": 1 + }, + "valid": true + }, + { + "description": "matches two", + "data": { + "🐲🐲": 1 + }, + "valid": true + }, + { + "description": "doesn't match one", + "data": { + "🐲": "hello" + }, + "valid": false + }, + { + "description": "doesn't match two", + "data": { + "🐲🐲": "hello" + }, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/refOfUnknownKeyword.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/refOfUnknownKeyword.json new file mode 100644 index 000000000..88ef3ce1b --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/refOfUnknownKeyword.json @@ -0,0 +1,98 @@ +[ + { + "description": "reference of a root arbitrary keyword ", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "unknown-keyword": { + "type": "integer" + }, + "properties": { + "bar": { + "$ref": "#/unknown-keyword" + } + } + }, + "skip": "extract error: unsupported constraint \"unknown-keyword\"", + "tests": [ + { + "description": "match", + "data": { + "bar": 3 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": { + "bar": true + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "reference of an arbitrary keyword of a sub-schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": { + "unknown-keyword": { + "type": "integer" + } + }, + "bar": { + "$ref": "#/properties/foo/unknown-keyword" + } + } + }, + "skip": "extract error: unsupported constraint \"unknown-keyword\"", + "tests": [ + { + "description": "match", + "data": { + "bar": 3 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": { + "bar": true + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "reference internals of known non-applicator", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "/base", + "examples": [ + { + "type": "string" + } + ], + "$ref": "#/examples/0" + }, + "skip": "extract error: reference to non-existing value \"examples\"", + "tests": [ + { + "description": "match", + "data": "a string", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": 42, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/unknownKeyword.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/unknownKeyword.json new file mode 100644 index 000000000..b5cd7c0cb --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/optional/unknownKeyword.json @@ -0,0 +1,67 @@ +[ + { + "description": "$id inside an unknown keyword is not a real identifier", + "comment": "the implementation must not be confused by an $id in locations we do not know how to parse", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "id_in_unknown0": { + "not": { + "array_of_schemas": [ + { + "$id": "https://localhost:1234/draft2019-09/unknownKeyword/my_identifier.json", + "type": "null" + } + ] + } + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/draft2019-09/unknownKeyword/my_identifier.json", + "type": "string" + }, + "id_in_unknown1": { + "not": { + "object_of_schemas": { + "foo": { + "$id": "https://localhost:1234/draft2019-09/unknownKeyword/my_identifier.json", + "type": "integer" + } + } + } + } + }, + "anyOf": [ + { + "$ref": "#/$defs/id_in_unknown0" + }, + { + "$ref": "#/$defs/id_in_unknown1" + }, + { + "$ref": "https://localhost:1234/draft2019-09/unknownKeyword/my_identifier.json" + } + ] + }, + "skip": "extract error: unsupported constraint \"not\" (and 1 more errors)", + "tests": [ + { + "description": "type matches second anyOf, which has a real schema in it", + "data": "a string", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "type matches non-schema in first anyOf", + "data": null, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "type matches non-schema in third anyOf", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/pattern.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/pattern.json new file mode 100644 index 000000000..823068621 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/pattern.json @@ -0,0 +1,65 @@ +[ + { + "description": "pattern validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "pattern": "^a*$" + }, + "tests": [ + { + "description": "a matching pattern is valid", + "data": "aaa", + "valid": true + }, + { + "description": "a non-matching pattern is invalid", + "data": "abc", + "valid": false + }, + { + "description": "ignores booleans", + "data": true, + "valid": true + }, + { + "description": "ignores integers", + "data": 123, + "valid": true + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true + }, + { + "description": "ignores objects", + "data": {}, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores null", + "data": null, + "valid": true + } + ] + }, + { + "description": "pattern is not anchored", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "pattern": "a+" + }, + "tests": [ + { + "description": "matches a substring", + "data": "xxaayy", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/patternProperties.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/patternProperties.json new file mode 100644 index 000000000..883519064 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/patternProperties.json @@ -0,0 +1,233 @@ +[ + { + "description": "patternProperties validates properties matching a regex", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "patternProperties": { + "f.*o": { + "type": "integer" + } + } + }, + "tests": [ + { + "description": "a single valid match is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "multiple valid matches is valid", + "data": { + "foo": 1, + "foooooo": 2 + }, + "valid": true + }, + { + "description": "a single invalid match is invalid", + "data": { + "foo": "bar", + "fooooo": 2 + }, + "valid": false + }, + { + "description": "multiple invalid matches is invalid", + "data": { + "foo": "bar", + "foooooo": "baz" + }, + "valid": false + }, + { + "description": "ignores arrays", + "data": [ + "foo" + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foo", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "multiple simultaneous patternProperties are validated", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "patternProperties": { + "a*": { + "type": "integer" + }, + "aaa*": { + "maximum": 20 + } + } + }, + "tests": [ + { + "description": "a single valid match is valid", + "data": { + "a": 21 + }, + "valid": true + }, + { + "description": "a simultaneous match is valid", + "data": { + "aaaa": 18 + }, + "valid": true + }, + { + "description": "multiple matches is valid", + "data": { + "a": 21, + "aaaa": 18 + }, + "valid": true + }, + { + "description": "an invalid due to one is invalid", + "data": { + "a": "bar" + }, + "valid": false + }, + { + "description": "an invalid due to the other is invalid", + "data": { + "aaaa": 31 + }, + "valid": false + }, + { + "description": "an invalid due to both is invalid", + "data": { + "aaa": "foo", + "aaaa": 31 + }, + "valid": false + } + ] + }, + { + "description": "regexes are not anchored by default and are case sensitive", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "patternProperties": { + "[0-9]{2,}": { + "type": "boolean" + }, + "X_": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "non recognized members are ignored", + "data": { + "answer 1": "42" + }, + "valid": true + }, + { + "description": "recognized members are accounted for", + "data": { + "a31b": null + }, + "valid": false + }, + { + "description": "regexes are case sensitive", + "data": { + "a_x_3": 3 + }, + "valid": true + }, + { + "description": "regexes are case sensitive, 2", + "data": { + "a_X_3": 3 + }, + "valid": false + } + ] + }, + { + "description": "patternProperties with boolean schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "patternProperties": { + "f.*": true, + "b.*": false + } + }, + "tests": [ + { + "description": "object with property matching schema true is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "object with property matching schema false is invalid", + "data": { + "bar": 2 + }, + "valid": false + }, + { + "description": "object with both properties is invalid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false + }, + { + "description": "object with a property matching both true and false is invalid", + "data": { + "foobar": 1 + }, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "patternProperties with null valued instance properties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "patternProperties": { + "^.*bar$": { + "type": "null" + } + } + }, + "tests": [ + { + "description": "allows null values", + "data": { + "foobar": null + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/properties.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/properties.json new file mode 100644 index 000000000..8ec30e01e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/properties.json @@ -0,0 +1,338 @@ +[ + { + "description": "object properties validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": { + "type": "integer" + }, + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "both properties present and valid is valid", + "data": { + "foo": 1, + "bar": "baz" + }, + "valid": true + }, + { + "description": "one property invalid is invalid", + "data": { + "foo": 1, + "bar": {} + }, + "valid": false + }, + { + "description": "both properties invalid is invalid", + "data": { + "foo": [], + "bar": {} + }, + "valid": false + }, + { + "description": "doesn't invalidate other properties", + "data": { + "quux": [] + }, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "properties, patternProperties, additionalProperties interaction", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": { + "type": "array", + "maxItems": 3 + }, + "bar": { + "type": "array" + } + }, + "patternProperties": { + "f.o": { + "minItems": 2 + } + }, + "additionalProperties": { + "type": "integer" + } + }, + "tests": [ + { + "description": "property validates property", + "data": { + "foo": [ + 1, + 2 + ] + }, + "valid": true + }, + { + "description": "property invalidates property", + "data": { + "foo": [ + 1, + 2, + 3, + 4 + ] + }, + "valid": false + }, + { + "description": "patternProperty invalidates property", + "data": { + "foo": [] + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "patternProperty validates nonproperty", + "data": { + "fxo": [ + 1, + 2 + ] + }, + "valid": true + }, + { + "description": "patternProperty invalidates nonproperty", + "data": { + "fxo": [] + }, + "valid": false + }, + { + "description": "additionalProperty ignores property", + "data": { + "bar": [] + }, + "valid": true + }, + { + "description": "additionalProperty validates others", + "data": { + "quux": 3 + }, + "valid": true + }, + { + "description": "additionalProperty invalidates others", + "data": { + "quux": "foo" + }, + "valid": false + } + ] + }, + { + "description": "properties with boolean schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": true, + "bar": false + } + }, + "tests": [ + { + "description": "no property present is valid", + "data": {}, + "valid": true + }, + { + "description": "only 'true' property present is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "only 'false' property present is invalid", + "data": { + "bar": 2 + }, + "valid": false + }, + { + "description": "both properties present is invalid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false + } + ] + }, + { + "description": "properties with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo\nbar": { + "type": "number" + }, + "foo\"bar": { + "type": "number" + }, + "foo\\bar": { + "type": "number" + }, + "foo\rbar": { + "type": "number" + }, + "foo\tbar": { + "type": "number" + }, + "foo\fbar": { + "type": "number" + } + } + }, + "tests": [ + { + "description": "object with all numbers is valid", + "data": { + "foo\nbar": 1, + "foo\"bar": 1, + "foo\\bar": 1, + "foo\rbar": 1, + "foo\tbar": 1, + "foo\fbar": 1 + }, + "valid": true + }, + { + "description": "object with strings is invalid", + "data": { + "foo\nbar": "1", + "foo\"bar": "1", + "foo\\bar": "1", + "foo\rbar": "1", + "foo\tbar": "1", + "foo\fbar": "1" + }, + "valid": false + } + ] + }, + { + "description": "properties with null valued instance properties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": { + "type": "null" + } + } + }, + "tests": [ + { + "description": "allows null values", + "data": { + "foo": null + }, + "valid": true + } + ] + }, + { + "description": "properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "__proto__": { + "type": "number" + }, + "toString": { + "properties": { + "length": { + "type": "string" + } + } + }, + "constructor": { + "type": "number" + } + } + }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": true + }, + { + "description": "__proto__ not valid", + "data": { + "__proto__": "foo" + }, + "valid": false + }, + { + "description": "toString not valid", + "data": { + "toString": { + "length": 37 + } + }, + "valid": false + }, + { + "description": "constructor not valid", + "data": { + "constructor": { + "length": 37 + } + }, + "valid": false + }, + { + "description": "all present and valid", + "data": { + "__proto__": 12, + "toString": { + "length": "foo" + }, + "constructor": 37 + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/propertyNames.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/propertyNames.json new file mode 100644 index 000000000..a33147ce9 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/propertyNames.json @@ -0,0 +1,136 @@ +[ + { + "description": "propertyNames validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "propertyNames": { + "maxLength": 3 + } + }, + "skip": "extract error: cannot compile resulting schema: reference \"strings\" in label expression refers to field against which it would be matched:\n generated.cue:5:3\n", + "tests": [ + { + "description": "all property names valid", + "data": { + "f": {}, + "foo": {} + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "some property names invalid", + "data": { + "foo": {}, + "foobar": {} + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "object without properties is valid", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores arrays", + "data": [ + 1, + 2, + 3, + 4 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "propertyNames validation with pattern", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "propertyNames": { + "pattern": "^a+$" + } + }, + "tests": [ + { + "description": "matching property names valid", + "data": { + "a": {}, + "aa": {}, + "aaa": {} + }, + "valid": true + }, + { + "description": "non-matching property name is invalid", + "data": { + "aaA": {} + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "object without properties is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "propertyNames with boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "propertyNames": true + }, + "tests": [ + { + "description": "object with any properties is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "propertyNames with boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "propertyNames": false + }, + "tests": [ + { + "description": "object with any properties is invalid", + "data": { + "foo": 1 + }, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/recursiveRef.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/recursiveRef.json new file mode 100644 index 000000000..c5a2a8718 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/recursiveRef.json @@ -0,0 +1,600 @@ +[ + { + "description": "$recursiveRef without $recursiveAnchor works like $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": { + "$recursiveRef": "#" + } + }, + "additionalProperties": false + }, + "skip": "extract error: unsupported constraint \"$recursiveRef\"", + "tests": [ + { + "description": "match", + "data": { + "foo": false + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "recursive match", + "data": { + "foo": { + "foo": false + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": { + "bar": false + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "recursive mismatch", + "data": { + "foo": { + "bar": false + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$recursiveRef without using nesting", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:4242/draft2019-09/recursiveRef2/schema.json", + "$defs": { + "myobject": { + "$id": "myobject.json", + "$recursiveAnchor": true, + "anyOf": [ + { + "type": "string" + }, + { + "type": "object", + "additionalProperties": { + "$recursiveRef": "#" + } + } + ] + } + }, + "anyOf": [ + { + "type": "integer" + }, + { + "$ref": "#/$defs/myobject" + } + ] + }, + "skip": "extract error: unsupported constraint \"$recursiveAnchor\" (and 1 more errors)", + "tests": [ + { + "description": "integer matches at the outer level", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single level match", + "data": { + "foo": "hi" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "integer does not match as a property value", + "data": { + "foo": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "two levels, properties match with inner definition", + "data": { + "foo": { + "bar": "hi" + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "two levels, no match", + "data": { + "foo": { + "bar": 1 + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$recursiveRef with nesting", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:4242/draft2019-09/recursiveRef3/schema.json", + "$recursiveAnchor": true, + "$defs": { + "myobject": { + "$id": "myobject.json", + "$recursiveAnchor": true, + "anyOf": [ + { + "type": "string" + }, + { + "type": "object", + "additionalProperties": { + "$recursiveRef": "#" + } + } + ] + } + }, + "anyOf": [ + { + "type": "integer" + }, + { + "$ref": "#/$defs/myobject" + } + ] + }, + "skip": "extract error: unsupported constraint \"$recursiveAnchor\" (and 2 more errors)", + "tests": [ + { + "description": "integer matches at the outer level", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single level match", + "data": { + "foo": "hi" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "integer now matches as a property value", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "two levels, properties match with inner definition", + "data": { + "foo": { + "bar": "hi" + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "two levels, properties match with $recursiveRef", + "data": { + "foo": { + "bar": 1 + } + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$recursiveRef with $recursiveAnchor: false works like $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:4242/draft2019-09/recursiveRef4/schema.json", + "$recursiveAnchor": false, + "$defs": { + "myobject": { + "$id": "myobject.json", + "$recursiveAnchor": false, + "anyOf": [ + { + "type": "string" + }, + { + "type": "object", + "additionalProperties": { + "$recursiveRef": "#" + } + } + ] + } + }, + "anyOf": [ + { + "type": "integer" + }, + { + "$ref": "#/$defs/myobject" + } + ] + }, + "skip": "extract error: unsupported constraint \"$recursiveAnchor\" (and 2 more errors)", + "tests": [ + { + "description": "integer matches at the outer level", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single level match", + "data": { + "foo": "hi" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "integer does not match as a property value", + "data": { + "foo": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "two levels, properties match with inner definition", + "data": { + "foo": { + "bar": "hi" + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "two levels, integer does not match as a property value", + "data": { + "foo": { + "bar": 1 + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$recursiveRef with no $recursiveAnchor works like $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:4242/draft2019-09/recursiveRef5/schema.json", + "$defs": { + "myobject": { + "$id": "myobject.json", + "$recursiveAnchor": false, + "anyOf": [ + { + "type": "string" + }, + { + "type": "object", + "additionalProperties": { + "$recursiveRef": "#" + } + } + ] + } + }, + "anyOf": [ + { + "type": "integer" + }, + { + "$ref": "#/$defs/myobject" + } + ] + }, + "skip": "extract error: unsupported constraint \"$recursiveAnchor\" (and 1 more errors)", + "tests": [ + { + "description": "integer matches at the outer level", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single level match", + "data": { + "foo": "hi" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "integer does not match as a property value", + "data": { + "foo": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "two levels, properties match with inner definition", + "data": { + "foo": { + "bar": "hi" + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "two levels, integer does not match as a property value", + "data": { + "foo": { + "bar": 1 + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$recursiveRef with no $recursiveAnchor in the initial target schema resource", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:4242/draft2019-09/recursiveRef6/base.json", + "$recursiveAnchor": true, + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "object", + "additionalProperties": { + "$id": "http://localhost:4242/draft2019-09/recursiveRef6/inner.json", + "$comment": "there is no $recursiveAnchor: true here, so we do NOT recurse to the base", + "anyOf": [ + { + "type": "integer" + }, + { + "type": "object", + "additionalProperties": { + "$recursiveRef": "#" + } + } + ] + } + } + ] + }, + "skip": "extract error: unsupported constraint \"$recursiveAnchor\" (and 1 more errors)", + "tests": [ + { + "description": "leaf node does not match; no recursion", + "data": { + "foo": true + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "leaf node matches: recursion uses the inner schema", + "data": { + "foo": { + "bar": 1 + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "leaf node does not match: recursion uses the inner schema", + "data": { + "foo": { + "bar": true + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$recursiveRef with no $recursiveAnchor in the outer schema resource", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:4242/draft2019-09/recursiveRef7/base.json", + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "object", + "additionalProperties": { + "$id": "http://localhost:4242/draft2019-09/recursiveRef7/inner.json", + "$recursiveAnchor": true, + "anyOf": [ + { + "type": "integer" + }, + { + "type": "object", + "additionalProperties": { + "$recursiveRef": "#" + } + } + ] + } + } + ] + }, + "skip": "extract error: unsupported constraint \"$recursiveAnchor\" (and 1 more errors)", + "tests": [ + { + "description": "leaf node does not match; no recursion", + "data": { + "foo": true + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "leaf node matches: recursion only uses inner schema", + "data": { + "foo": { + "bar": 1 + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "leaf node does not match: recursion only uses inner schema", + "data": { + "foo": { + "bar": true + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "multiple dynamic paths to the $recursiveRef keyword", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://example.com/recursiveRef8_main.json", + "$defs": { + "inner": { + "$id": "recursiveRef8_inner.json", + "$recursiveAnchor": true, + "title": "inner", + "additionalProperties": { + "$recursiveRef": "#" + } + } + }, + "if": { + "propertyNames": { + "pattern": "^[a-m]" + } + }, + "then": { + "title": "any type of node", + "$id": "recursiveRef8_anyLeafNode.json", + "$recursiveAnchor": true, + "$ref": "recursiveRef8_inner.json" + }, + "else": { + "title": "integer node", + "$id": "recursiveRef8_integerNode.json", + "$recursiveAnchor": true, + "type": [ + "object", + "integer" + ], + "$ref": "recursiveRef8_inner.json" + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 4 more errors)", + "tests": [ + { + "description": "recurse to anyLeafNode - floats are allowed", + "data": { + "alpha": 1.1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "recurse to integerNode - floats are not allowed", + "data": { + "november": 1.1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "dynamic $recursiveRef destination (not predictable at schema compile time)", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://example.com/main.json", + "$defs": { + "inner": { + "$id": "inner.json", + "$recursiveAnchor": true, + "title": "inner", + "additionalProperties": { + "$recursiveRef": "#" + } + } + }, + "if": { + "propertyNames": { + "pattern": "^[a-m]" + } + }, + "then": { + "title": "any type of node", + "$id": "anyLeafNode.json", + "$recursiveAnchor": true, + "$ref": "main.json#/$defs/inner" + }, + "else": { + "title": "integer node", + "$id": "integerNode.json", + "$recursiveAnchor": true, + "type": [ + "object", + "integer" + ], + "$ref": "main.json#/$defs/inner" + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 4 more errors)", + "tests": [ + { + "description": "numeric node", + "data": { + "alpha": 1.1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "integer node", + "data": { + "november": 1.1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/ref.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/ref.json new file mode 100644 index 000000000..282b3664a --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/ref.json @@ -0,0 +1,1358 @@ +[ + { + "description": "root pointer ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": { + "$ref": "#" + } + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "match", + "data": { + "foo": false + }, + "valid": true + }, + { + "description": "recursive match", + "data": { + "foo": { + "foo": false + } + }, + "valid": true + }, + { + "description": "mismatch", + "data": { + "bar": false + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "recursive mismatch", + "data": { + "foo": { + "bar": false + } + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "relative pointer ref to object", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": { + "type": "integer" + }, + "bar": { + "$ref": "#/properties/foo" + } + } + }, + "skip": "extract error: cannot compile resulting schema: bar: reference \"foo\" not found:\n generated.cue:4:10\n", + "tests": [ + { + "description": "match", + "data": { + "bar": 3 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": { + "bar": true + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "relative pointer ref to array", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { + "type": "integer" + }, + { + "$ref": "#/items/0" + } + ] + }, + "skip": "extract error: referring to field \"items\" not yet supported", + "tests": [ + { + "description": "match array", + "data": [ + 1, + 2 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch array", + "data": [ + 1, + "foo" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "escaped pointer ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "tilde~field": { + "type": "integer" + }, + "slash/field": { + "type": "integer" + }, + "percent%field": { + "type": "integer" + } + }, + "properties": { + "tilde": { + "$ref": "#/$defs/tilde~0field" + }, + "slash": { + "$ref": "#/$defs/slash~1field" + }, + "percent": { + "$ref": "#/$defs/percent%25field" + } + } + }, + "tests": [ + { + "description": "slash invalid", + "data": { + "slash": "aoeu" + }, + "valid": false + }, + { + "description": "tilde invalid", + "data": { + "tilde": "aoeu" + }, + "valid": false + }, + { + "description": "percent invalid", + "data": { + "percent": "aoeu" + }, + "valid": false + }, + { + "description": "slash valid", + "data": { + "slash": 123 + }, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values [...] and {slash:123} (mismatched types list and struct):\n generated.cue:2:33\n instance.json:1:1\nconflicting values bool and {slash:123} (mismatched types bool and struct):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and {slash:123} (mismatched types null and struct):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and {slash:123} (mismatched types number and struct):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and {slash:123} (mismatched types string and struct):\n generated.cue:2:24\n instance.json:1:1\nslash: undefined field: \"slash~1field\":\n generated.cue:4:14\n" + }, + { + "description": "tilde valid", + "data": { + "tilde": 123 + }, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values [...] and {tilde:123} (mismatched types list and struct):\n generated.cue:2:33\n instance.json:1:1\nconflicting values bool and {tilde:123} (mismatched types bool and struct):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and {tilde:123} (mismatched types null and struct):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and {tilde:123} (mismatched types number and struct):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and {tilde:123} (mismatched types string and struct):\n generated.cue:2:24\n instance.json:1:1\ntilde: undefined field: \"tilde~0field\":\n generated.cue:3:14\n" + }, + { + "description": "percent valid", + "data": { + "percent": 123 + }, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values [...] and {percent:123} (mismatched types list and struct):\n generated.cue:2:33\n instance.json:1:1\nconflicting values bool and {percent:123} (mismatched types bool and struct):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and {percent:123} (mismatched types null and struct):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and {percent:123} (mismatched types number and struct):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and {percent:123} (mismatched types string and struct):\n generated.cue:2:24\n instance.json:1:1\npercent: undefined field: \"percent%25field\":\n generated.cue:5:14\n" + } + ] + }, + { + "description": "nested refs", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "a": { + "type": "integer" + }, + "b": { + "$ref": "#/$defs/a" + }, + "c": { + "$ref": "#/$defs/b" + } + }, + "$ref": "#/$defs/c" + }, + "tests": [ + { + "description": "nested ref valid", + "data": 5, + "valid": true + }, + { + "description": "nested ref invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "ref applies alongside sibling keywords", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "reffed": { + "type": "array" + } + }, + "properties": { + "foo": { + "$ref": "#/$defs/reffed", + "maxItems": 2 + } + } + }, + "tests": [ + { + "description": "ref valid, maxItems valid", + "data": { + "foo": [] + }, + "valid": true + }, + { + "description": "ref valid, maxItems invalid", + "data": { + "foo": [ + 1, + 2, + 3 + ] + }, + "valid": false + }, + { + "description": "ref invalid", + "data": { + "foo": "string" + }, + "valid": false + } + ] + }, + { + "description": "remote ref, containing refs itself", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "https://json-schema.org/draft/2019-09/schema" + }, + "skip": "extract error: cannot compile resulting schema: package \"json-schema.org/draft/2019-09/schema\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "remote ref valid", + "data": { + "minLength": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "remote ref invalid", + "data": { + "minLength": -1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "property named $ref that is not a reference", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "$ref": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": { + "$ref": "a" + }, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": { + "$ref": 2 + }, + "valid": false + } + ] + }, + { + "description": "property named $ref, containing an actual $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "$ref": { + "$ref": "#/$defs/is-string" + } + }, + "$defs": { + "is-string": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": { + "$ref": "a" + }, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": { + "$ref": 2 + }, + "valid": false + } + ] + }, + { + "description": "$ref to boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "#/$defs/bool", + "$defs": { + "bool": true + } + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "$ref to boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "#/$defs/bool", + "$defs": { + "bool": false + } + }, + "skip": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n generated.cue:4:8\n", + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "Recursive references between schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/tree", + "description": "tree of nodes", + "type": "object", + "properties": { + "meta": { + "type": "string" + }, + "nodes": { + "type": "array", + "items": { + "$ref": "node" + } + } + }, + "required": [ + "meta", + "nodes" + ], + "$defs": { + "node": { + "$id": "http://localhost:1234/draft2019-09/node", + "description": "node", + "type": "object", + "properties": { + "value": { + "type": "number" + }, + "subtree": { + "$ref": "tree" + } + }, + "required": [ + "value" + ] + } + } + }, + "skip": "extract error: cannot compile resulting schema: builtin package \"localhost:1234/draft2019-09/node\" undefined:\n generated.cue:1:8\n_schema.nodes: reference \"node\" not found:\n generated.cue:9:14\n", + "tests": [ + { + "description": "valid tree", + "data": { + "meta": "root", + "nodes": [ + { + "value": 1, + "subtree": { + "meta": "child", + "nodes": [ + { + "value": 1.1 + }, + { + "value": 1.2 + } + ] + } + }, + { + "value": 2, + "subtree": { + "meta": "child", + "nodes": [ + { + "value": 2.1 + }, + { + "value": 2.2 + } + ] + } + } + ] + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid tree", + "data": { + "meta": "root", + "nodes": [ + { + "value": 1, + "subtree": { + "meta": "child", + "nodes": [ + { + "value": "string is invalid" + }, + { + "value": 1.2 + } + ] + } + }, + { + "value": 2, + "subtree": { + "meta": "child", + "nodes": [ + { + "value": 2.1 + }, + { + "value": 2.2 + } + ] + } + } + ] + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "refs with quote", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo\"bar": { + "$ref": "#/$defs/foo%22bar" + } + }, + "$defs": { + "foo\"bar": { + "type": "number" + } + } + }, + "tests": [ + { + "description": "object with numbers is valid", + "data": { + "foo\"bar": 1 + }, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values [...] and {\"foo\\\"bar\":1} (mismatched types list and struct):\n generated.cue:2:33\n instance.json:1:1\nconflicting values bool and {\"foo\\\"bar\":1} (mismatched types bool and struct):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and {\"foo\\\"bar\":1} (mismatched types null and struct):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and {\"foo\\\"bar\":1} (mismatched types number and struct):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and {\"foo\\\"bar\":1} (mismatched types string and struct):\n generated.cue:2:24\n instance.json:1:1\n\"foo\\\"bar\": undefined field: \"foo%22bar\":\n generated.cue:3:17\n" + }, + { + "description": "object with strings is invalid", + "data": { + "foo\"bar": "1" + }, + "valid": false + } + ] + }, + { + "description": "ref creates new scope when adjacent to keywords", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "A": { + "unevaluatedProperties": false + } + }, + "properties": { + "prop1": { + "type": "string" + } + }, + "$ref": "#/$defs/A" + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "referenced subschema doesn't see annotations from properties", + "data": { + "prop1": "match" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "naive replacement of $ref with its destination is not correct", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "a_string": { + "type": "string" + } + }, + "enum": [ + { + "$ref": "#/$defs/a_string" + } + ] + }, + "tests": [ + { + "description": "do not evaluate the $ref inside the enum, matching any string", + "data": "this is a string", + "valid": false + }, + { + "description": "do not evaluate the $ref inside the enum, definition exact match", + "data": { + "type": "string" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "match the enum exactly", + "data": { + "$ref": "#/$defs/a_string" + }, + "valid": true + } + ] + }, + { + "description": "refs with relative uris and defs", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://example.com/schema-relative-uri-defs1.json", + "properties": { + "foo": { + "$id": "schema-relative-uri-defs2.json", + "$defs": { + "inner": { + "properties": { + "bar": { + "type": "string" + } + } + } + }, + "$ref": "#/$defs/inner" + } + }, + "$ref": "schema-relative-uri-defs2.json" + }, + "skip": "extract error: cannot compile resulting schema: package \"example.com/schema-relative-uri-defs2.json:schema\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "invalid on inner field", + "data": { + "foo": { + "bar": 1 + }, + "bar": "a" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid on outer field", + "data": { + "foo": { + "bar": "a" + }, + "bar": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid on both fields", + "data": { + "foo": { + "bar": "a" + }, + "bar": "a" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "relative refs with absolute uris and defs", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://example.com/schema-refs-absolute-uris-defs1.json", + "properties": { + "foo": { + "$id": "http://example.com/schema-refs-absolute-uris-defs2.json", + "$defs": { + "inner": { + "properties": { + "bar": { + "type": "string" + } + } + } + }, + "$ref": "#/$defs/inner" + } + }, + "$ref": "schema-refs-absolute-uris-defs2.json" + }, + "skip": "extract error: cannot compile resulting schema: package \"example.com/schema-refs-absolute-uris-defs2.json:schema\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "invalid on inner field", + "data": { + "foo": { + "bar": 1 + }, + "bar": "a" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid on outer field", + "data": { + "foo": { + "bar": "a" + }, + "bar": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid on both fields", + "data": { + "foo": { + "bar": "a" + }, + "bar": "a" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$id must be resolved against nearest parent, not just immediate parent", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://example.com/a.json", + "$defs": { + "x": { + "$id": "http://example.com/b/c.json", + "not": { + "$defs": { + "y": { + "$id": "d.json", + "type": "number" + } + } + } + } + }, + "allOf": [ + { + "$ref": "http://example.com/b/d.json" + } + ] + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "order of evaluation: $id and $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "https://example.com/draft2019-09/ref-and-id1/base.json", + "$ref": "int.json", + "$defs": { + "bigint": { + "$comment": "canonical uri: https://example.com/draft2019-09/ref-and-id1/int.json", + "$id": "int.json", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: https://example.com/draft2019-09/ref-and-id1-int.json", + "$id": "/draft2019-09/ref-and-id1-int.json", + "maximum": 2 + } + } + }, + "skip": "extract error: cannot compile resulting schema: package \"example.com/draft2019-09/ref-and-id1/int.json:int\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "order of evaluation: $id and $anchor and $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$id": "https://example.com/draft2019-09/ref-and-id2/base.json", + "$ref": "#bigint", + "$defs": { + "bigint": { + "$comment": "canonical uri: https://example.com/draft2019-09/ref-and-id2/base.json#/$defs/bigint; another valid uri for this location: https://example.com/ref-and-id2/base.json#bigint", + "$anchor": "bigint", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: https://example.com/draft2019-09/ref-and-id2#/$defs/smallint; another valid uri for this location: https://example.com/ref-and-id2/#bigint", + "$id": "/draft2019-09/ref-and-id2/", + "$anchor": "bigint", + "maximum": 2 + } + } + }, + "skip": "extract error: anchors (bigint) not supported (and 2 more errors)", + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "simple URN base URI with $ref via the URN", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$comment": "URIs do not have to have HTTP(s) schemes", + "$id": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed", + "minimum": 30, + "properties": { + "foo": { + "$ref": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed" + } + } + }, + "tests": [ + { + "description": "valid under the URN IDed schema", + "data": { + "foo": 37 + }, + "valid": true + }, + { + "description": "invalid under the URN IDed schema", + "data": { + "foo": 12 + }, + "valid": false + } + ] + }, + { + "description": "simple URN base URI with JSON pointer", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$comment": "URIs do not have to have HTTP(s) schemes", + "$id": "urn:uuid:deadbeef-1234-00ff-ff00-4321feebdaed", + "properties": { + "foo": { + "$ref": "#/$defs/bar" + } + }, + "$defs": { + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false + } + ] + }, + { + "description": "URN base URI with NSS", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$comment": "RFC 8141 §2.2", + "$id": "urn:example:1/406/47452/2", + "properties": { + "foo": { + "$ref": "#/$defs/bar" + } + }, + "$defs": { + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false + } + ] + }, + { + "description": "URN base URI with r-component", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$comment": "RFC 8141 §2.3.1", + "$id": "urn:example:foo-bar-baz-qux?+CCResolve:cc=uk", + "properties": { + "foo": { + "$ref": "#/$defs/bar" + } + }, + "$defs": { + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false + } + ] + }, + { + "description": "URN base URI with q-component", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$comment": "RFC 8141 §2.3.2", + "$id": "urn:example:weather?=op=map\u0026lat=39.56\u0026lon=-104.85\u0026datetime=1969-07-21T02:56:15Z", + "properties": { + "foo": { + "$ref": "#/$defs/bar" + } + }, + "$defs": { + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false + } + ] + }, + { + "description": "URN base URI with URN and JSON pointer ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed", + "properties": { + "foo": { + "$ref": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed#/$defs/bar" + } + }, + "$defs": { + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false + } + ] + }, + { + "description": "URN base URI with URN and anchor ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed", + "properties": { + "foo": { + "$ref": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed#something" + } + }, + "$defs": { + "bar": { + "$anchor": "something", + "type": "string" + } + } + }, + "skip": "extract error: anchors (something) not supported (and 1 more errors)", + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "URN ref with nested pointer ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed", + "$defs": { + "foo": { + "$id": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed", + "$defs": { + "bar": { + "type": "string" + } + }, + "$ref": "#/$defs/bar" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": "bar", + "valid": true, + "skip": "conflicting values \"bar\" and {_schema:{#foo:string},#foo:string} (mismatched types string and struct):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "a non-string is invalid", + "data": 12, + "valid": false + } + ] + }, + { + "description": "ref to if", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://example.com/ref/if", + "if": { + "$id": "http://example.com/ref/if", + "type": "integer" + } + }, + "skip": "extract error: unsupported constraint \"if\"", + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ref to then", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://example.com/ref/then", + "then": { + "$id": "http://example.com/ref/then", + "type": "integer" + } + }, + "skip": "extract error: unsupported constraint \"then\"", + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ref to else", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://example.com/ref/else", + "else": { + "$id": "http://example.com/ref/else", + "type": "integer" + } + }, + "skip": "extract error: unsupported constraint \"else\"", + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ref with absolute-path-reference", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://example.com/ref/absref.json", + "$defs": { + "a": { + "$id": "http://example.com/ref/absref/foobar.json", + "type": "number" + }, + "b": { + "$id": "http://example.com/absref/foobar.json", + "type": "string" + } + }, + "$ref": "/absref/foobar.json" + }, + "skip": "extract error: cannot compile resulting schema: package \"example.com/absref/foobar.json:foobar\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "a string is valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an integer is invalid", + "data": 12, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$id with file URI still resolves pointers - *nix", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "file:///folder/file.json", + "$defs": { + "foo": { + "type": "number" + } + }, + "$ref": "#/$defs/foo" + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "$id with file URI still resolves pointers - windows", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "file:///c:/folder/file.json", + "$defs": { + "foo": { + "type": "number" + } + }, + "$ref": "#/$defs/foo" + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "empty tokens in $ref json-pointer", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "": { + "$defs": { + "": { + "type": "number" + } + } + } + }, + "allOf": [ + { + "$ref": "#/$defs//$defs/" + } + ] + }, + "skip": "extract error: cannot refer to $defs section: must refer to one of its elements", + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$ref with $recursiveAnchor", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://example.com/schemas/unevaluated-items-are-disallowed", + "$ref": "/schemas/unevaluated-items-are-allowed", + "$recursiveAnchor": true, + "unevaluatedItems": false, + "$defs": { + "/schemas/unevaluated-items-are-allowed": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "/schemas/unevaluated-items-are-allowed", + "$recursiveAnchor": true, + "type": "array", + "items": [ + { + "type": "string" + }, + { + "$ref": "#" + } + ] + } + } + }, + "skip": "extract error: unsupported constraint \"$recursiveAnchor\" (and 2 more errors)", + "tests": [ + { + "description": "extra items allowed for inner arrays", + "data": [ + "foo", + [ + "bar", + [], + 8 + ] + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "extra items disallowed for root", + "data": [ + "foo", + [ + "bar", + [], + 8 + ], + 8 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/refRemote.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/refRemote.json new file mode 100644 index 000000000..0e5276c5b --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/refRemote.json @@ -0,0 +1,434 @@ +[ + { + "description": "remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://localhost:1234/draft2019-09/integer.json" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2019-09/integer.json:integer\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "remote ref valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "remote ref invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "fragment within remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://localhost:1234/draft2019-09/subSchemas.json#/$defs/integer" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2019-09/subSchemas.json:subSchemas\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "remote fragment valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "remote fragment invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "anchor within remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://localhost:1234/draft2019-09/locationIndependentIdentifier.json#foo" + }, + "skip": "extract error: anchors (foo) not supported", + "tests": [ + { + "description": "remote anchor valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "remote anchor invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ref within remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://localhost:1234/draft2019-09/subSchemas.json#/$defs/refToInteger" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2019-09/subSchemas.json:subSchemas\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "ref within ref valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ref within ref invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "base URI change", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/", + "items": { + "$id": "baseUriChange/", + "items": { + "$ref": "folderInteger.json" + } + } + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2019-09/baseUriChange/folderInteger.json:folderInteger\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "base URI change ref valid", + "data": [ + [ + 1 + ] + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "base URI change ref invalid", + "data": [ + [ + "a" + ] + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "base URI change - change folder", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/scope_change_defs1.json", + "type": "object", + "properties": { + "list": { + "$ref": "baseUriChangeFolder/" + } + }, + "$defs": { + "baz": { + "$id": "baseUriChangeFolder/", + "type": "array", + "items": { + "$ref": "folderInteger.json" + } + } + } + }, + "skip": "extract error: cannot determine package name from import path \"localhost:1234/draft2019-09/baseUriChangeFolder/\"", + "tests": [ + { + "description": "number is valid", + "data": { + "list": [ + 1 + ] + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": { + "list": [ + "a" + ] + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "base URI change - change folder in subschema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/scope_change_defs2.json", + "type": "object", + "properties": { + "list": { + "$ref": "baseUriChangeFolderInSubschema/#/$defs/bar" + } + }, + "$defs": { + "baz": { + "$id": "baseUriChangeFolderInSubschema/", + "$defs": { + "bar": { + "type": "array", + "items": { + "$ref": "folderInteger.json" + } + } + } + } + } + }, + "skip": "extract error: cannot determine package name from import path \"localhost:1234/draft2019-09/baseUriChangeFolderInSubschema/\"", + "tests": [ + { + "description": "number is valid", + "data": { + "list": [ + 1 + ] + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": { + "list": [ + "a" + ] + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "root ref in remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/object", + "type": "object", + "properties": { + "name": { + "$ref": "name-defs.json#/$defs/orNull" + } + } + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2019-09/name-defs.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "string is valid", + "data": { + "name": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "null is valid", + "data": { + "name": null + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "object is invalid", + "data": { + "name": { + "name": null + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "remote ref with ref to defs", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/schema-remote-ref-ref-defs1.json", + "$ref": "ref-and-defs.json" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2019-09/ref-and-defs.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "invalid", + "data": { + "bar": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid", + "data": { + "bar": "a" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "Location-independent identifier in remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://localhost:1234/draft2019-09/locationIndependentIdentifier.json#/$defs/refToInteger" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2019-09/locationIndependentIdentifier.json:locationIndependentIdentifier\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "integer is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "retrieved nested refs resolve relative to their URI not $id", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "http://localhost:1234/draft2019-09/some-id", + "properties": { + "name": { + "$ref": "nested/foo-ref-string.json" + } + } + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2019-09/nested/foo-ref-string.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is invalid", + "data": { + "name": { + "foo": 1 + } + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is valid", + "data": { + "name": { + "foo": "a" + } + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "remote HTTP ref with different $id", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://localhost:1234/different-id-ref-string.json" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/different-id-ref-string.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "remote HTTP ref with different URN $id", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://localhost:1234/urn-ref-string.json" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/urn-ref-string.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "remote HTTP ref with nested absolute ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://localhost:1234/nested-absolute-ref-to-string.json" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/nested-absolute-ref-to-string.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$ref to $ref finds detached $anchor", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "http://localhost:1234/draft2019-09/detached-ref.json#/$defs/foo" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2019-09/detached-ref.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/required.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/required.json new file mode 100644 index 000000000..d1fba2885 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/required.json @@ -0,0 +1,186 @@ +[ + { + "description": "required validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": {}, + "bar": {} + }, + "required": [ + "foo" + ] + }, + "tests": [ + { + "description": "present required property is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "non-present required property is invalid", + "data": { + "bar": 1 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", + "data": "", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "required default validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": {} + } + }, + "tests": [ + { + "description": "not required by default", + "data": {}, + "valid": true + } + ] + }, + { + "description": "required with empty array", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": {} + }, + "required": [] + }, + "tests": [ + { + "description": "property not required", + "data": {}, + "valid": true + } + ] + }, + { + "description": "required with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "required": [ + "foo\nbar", + "foo\"bar", + "foo\\bar", + "foo\rbar", + "foo\tbar", + "foo\fbar" + ] + }, + "tests": [ + { + "description": "object with all properties present is valid", + "data": { + "foo\nbar": 1, + "foo\"bar": 1, + "foo\\bar": 1, + "foo\rbar": 1, + "foo\tbar": 1, + "foo\fbar": 1 + }, + "valid": true + }, + { + "description": "object with some properties missing is invalid", + "data": { + "foo\nbar": "1", + "foo\"bar": "1" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "required properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "required": [ + "__proto__", + "toString", + "constructor" + ] + }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "__proto__ present", + "data": { + "__proto__": "foo" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "toString present", + "data": { + "toString": { + "length": 37 + } + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "constructor present", + "data": { + "constructor": { + "length": 37 + } + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "all present", + "data": { + "__proto__": 12, + "toString": { + "length": "foo" + }, + "constructor": 37 + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/type.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/type.json new file mode 100644 index 000000000..e8feb1adc --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/type.json @@ -0,0 +1,526 @@ +[ + { + "description": "integer type matches integers", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "integer" + }, + "tests": [ + { + "description": "an integer is an integer", + "data": 1, + "valid": true + }, + { + "description": "a float with zero fractional part is an integer", + "data": 1.0, + "valid": true, + "skip": "conflicting values 1.0 and int (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "a float is not an integer", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an integer", + "data": "foo", + "valid": false + }, + { + "description": "a string is still not an integer, even if it looks like one", + "data": "1", + "valid": false + }, + { + "description": "an object is not an integer", + "data": {}, + "valid": false + }, + { + "description": "an array is not an integer", + "data": [], + "valid": false + }, + { + "description": "a boolean is not an integer", + "data": true, + "valid": false + }, + { + "description": "null is not an integer", + "data": null, + "valid": false + } + ] + }, + { + "description": "number type matches numbers", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "number" + }, + "tests": [ + { + "description": "an integer is a number", + "data": 1, + "valid": true + }, + { + "description": "a float with zero fractional part is a number (and an integer)", + "data": 1.0, + "valid": true + }, + { + "description": "a float is a number", + "data": 1.1, + "valid": true + }, + { + "description": "a string is not a number", + "data": "foo", + "valid": false + }, + { + "description": "a string is still not a number, even if it looks like one", + "data": "1", + "valid": false + }, + { + "description": "an object is not a number", + "data": {}, + "valid": false + }, + { + "description": "an array is not a number", + "data": [], + "valid": false + }, + { + "description": "a boolean is not a number", + "data": true, + "valid": false + }, + { + "description": "null is not a number", + "data": null, + "valid": false + } + ] + }, + { + "description": "string type matches strings", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "string" + }, + "tests": [ + { + "description": "1 is not a string", + "data": 1, + "valid": false + }, + { + "description": "a float is not a string", + "data": 1.1, + "valid": false + }, + { + "description": "a string is a string", + "data": "foo", + "valid": true + }, + { + "description": "a string is still a string, even if it looks like a number", + "data": "1", + "valid": true + }, + { + "description": "an empty string is still a string", + "data": "", + "valid": true + }, + { + "description": "an object is not a string", + "data": {}, + "valid": false + }, + { + "description": "an array is not a string", + "data": [], + "valid": false + }, + { + "description": "a boolean is not a string", + "data": true, + "valid": false + }, + { + "description": "null is not a string", + "data": null, + "valid": false + } + ] + }, + { + "description": "object type matches objects", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object" + }, + "tests": [ + { + "description": "an integer is not an object", + "data": 1, + "valid": false + }, + { + "description": "a float is not an object", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an object", + "data": "foo", + "valid": false + }, + { + "description": "an object is an object", + "data": {}, + "valid": true + }, + { + "description": "an array is not an object", + "data": [], + "valid": false + }, + { + "description": "a boolean is not an object", + "data": true, + "valid": false + }, + { + "description": "null is not an object", + "data": null, + "valid": false + } + ] + }, + { + "description": "array type matches arrays", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "array" + }, + "tests": [ + { + "description": "an integer is not an array", + "data": 1, + "valid": false + }, + { + "description": "a float is not an array", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an array", + "data": "foo", + "valid": false + }, + { + "description": "an object is not an array", + "data": {}, + "valid": false + }, + { + "description": "an array is an array", + "data": [], + "valid": true + }, + { + "description": "a boolean is not an array", + "data": true, + "valid": false + }, + { + "description": "null is not an array", + "data": null, + "valid": false + } + ] + }, + { + "description": "boolean type matches booleans", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "boolean" + }, + "tests": [ + { + "description": "an integer is not a boolean", + "data": 1, + "valid": false + }, + { + "description": "zero is not a boolean", + "data": 0, + "valid": false + }, + { + "description": "a float is not a boolean", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not a boolean", + "data": "foo", + "valid": false + }, + { + "description": "an empty string is not a boolean", + "data": "", + "valid": false + }, + { + "description": "an object is not a boolean", + "data": {}, + "valid": false + }, + { + "description": "an array is not a boolean", + "data": [], + "valid": false + }, + { + "description": "true is a boolean", + "data": true, + "valid": true + }, + { + "description": "false is a boolean", + "data": false, + "valid": true + }, + { + "description": "null is not a boolean", + "data": null, + "valid": false + } + ] + }, + { + "description": "null type matches only the null object", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "null" + }, + "tests": [ + { + "description": "an integer is not null", + "data": 1, + "valid": false + }, + { + "description": "a float is not null", + "data": 1.1, + "valid": false + }, + { + "description": "zero is not null", + "data": 0, + "valid": false + }, + { + "description": "a string is not null", + "data": "foo", + "valid": false + }, + { + "description": "an empty string is not null", + "data": "", + "valid": false + }, + { + "description": "an object is not null", + "data": {}, + "valid": false + }, + { + "description": "an array is not null", + "data": [], + "valid": false + }, + { + "description": "true is not null", + "data": true, + "valid": false + }, + { + "description": "false is not null", + "data": false, + "valid": false + }, + { + "description": "null is null", + "data": null, + "valid": true + } + ] + }, + { + "description": "multiple types can be specified in an array", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": [ + "integer", + "string" + ] + }, + "tests": [ + { + "description": "an integer is valid", + "data": 1, + "valid": true + }, + { + "description": "a string is valid", + "data": "foo", + "valid": true + }, + { + "description": "a float is invalid", + "data": 1.1, + "valid": false + }, + { + "description": "an object is invalid", + "data": {}, + "valid": false + }, + { + "description": "an array is invalid", + "data": [], + "valid": false + }, + { + "description": "a boolean is invalid", + "data": true, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + } + ] + }, + { + "description": "type as array with one item", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": [ + "string" + ] + }, + "tests": [ + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "type: array or object", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": [ + "array", + "object" + ] + }, + "tests": [ + { + "description": "array is valid", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "object is valid", + "data": { + "foo": 123 + }, + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + } + ] + }, + { + "description": "type: array, object or null", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": [ + "array", + "object", + "null" + ] + }, + "tests": [ + { + "description": "array is valid", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "object is valid", + "data": { + "foo": 123 + }, + "valid": true + }, + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/unevaluatedItems.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/unevaluatedItems.json new file mode 100644 index 000000000..21cee85c7 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/unevaluatedItems.json @@ -0,0 +1,1014 @@ +[ + { + "description": "unevaluatedItems true", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "unevaluatedItems": true + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "with no unevaluated items", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated items", + "data": [ + "foo" + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems false", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "with no unevaluated items", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated items", + "data": [ + "foo" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems as schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "unevaluatedItems": { + "type": "string" + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "with no unevaluated items", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with valid unevaluated items", + "data": [ + "foo" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with invalid unevaluated items", + "data": [ + 42 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with uniform items", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": { + "type": "string" + }, + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "unevaluatedItems doesn't apply", + "data": [ + "foo", + "bar" + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with tuple", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { + "type": "string" + } + ], + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "with no unevaluated items", + "data": [ + "foo" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated items", + "data": [ + "foo", + "bar" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with items and additionalItems", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { + "type": "string" + } + ], + "additionalItems": true, + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "unevaluatedItems doesn't apply", + "data": [ + "foo", + 42 + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with ignored additionalItems", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "additionalItems": { + "type": "number" + }, + "unevaluatedItems": { + "type": "string" + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "invalid under unevaluatedItems", + "comment": "additionalItems is entirely ignored when items isn't present, so all elements need to be valid against the unevaluatedItems schema", + "data": [ + "foo", + 1 + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "all valid under unevaluatedItems", + "data": [ + "foo", + "bar", + "baz" + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with ignored applicator additionalItems", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "additionalItems": { + "type": "number" + } + } + ], + "unevaluatedItems": { + "type": "string" + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "invalid under unevaluatedItems", + "comment": "additionalItems is entirely ignored when items isn't present, so all elements need to be valid against the unevaluatedItems schema", + "data": [ + "foo", + 1 + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "all valid under unevaluatedItems", + "data": [ + "foo", + "bar", + "baz" + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with nested tuple", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { + "type": "string" + } + ], + "allOf": [ + { + "items": [ + true, + { + "type": "number" + } + ] + } + ], + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "with no unevaluated items", + "data": [ + "foo", + 42 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated items", + "data": [ + "foo", + 42, + true + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with nested items", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "unevaluatedItems": { + "type": "boolean" + }, + "anyOf": [ + { + "items": { + "type": "string" + } + }, + true + ] + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "with only (valid) additional items", + "data": [ + true, + false + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with no additional items", + "data": [ + "yes", + "no" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with invalid additional item", + "data": [ + "yes", + false + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with nested items and additionalItems", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "items": [ + { + "type": "string" + } + ], + "additionalItems": true + } + ], + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "with no additional items", + "data": [ + "foo" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with additional items", + "data": [ + "foo", + 42, + true + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with nested unevaluatedItems", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "items": [ + { + "type": "string" + } + ] + }, + { + "unevaluatedItems": true + } + ], + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\" (and 1 more errors)", + "tests": [ + { + "description": "with no additional items", + "data": [ + "foo" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with additional items", + "data": [ + "foo", + 42, + true + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with anyOf", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { + "const": "foo" + } + ], + "anyOf": [ + { + "items": [ + true, + { + "const": "bar" + } + ] + }, + { + "items": [ + true, + true, + { + "const": "baz" + } + ] + } + ], + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "when one schema matches and has no unevaluated items", + "data": [ + "foo", + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "when one schema matches and has unevaluated items", + "data": [ + "foo", + "bar", + 42 + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "when two schemas match and has no unevaluated items", + "data": [ + "foo", + "bar", + "baz" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "when two schemas match and has unevaluated items", + "data": [ + "foo", + "bar", + "baz", + 42 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { + "const": "foo" + } + ], + "oneOf": [ + { + "items": [ + true, + { + "const": "bar" + } + ] + }, + { + "items": [ + true, + { + "const": "baz" + } + ] + } + ], + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "with no unevaluated items", + "data": [ + "foo", + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated items", + "data": [ + "foo", + "bar", + 42 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with not", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { + "const": "foo" + } + ], + "not": { + "not": { + "items": [ + true, + { + "const": "bar" + } + ] + } + }, + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"not\" (and 1 more errors)", + "tests": [ + { + "description": "with unevaluated items", + "data": [ + "foo", + "bar" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with if/then/else", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { + "const": "foo" + } + ], + "if": { + "items": [ + true, + { + "const": "bar" + } + ] + }, + "then": { + "items": [ + true, + true, + { + "const": "then" + } + ] + }, + "else": { + "items": [ + true, + true, + true, + { + "const": "else" + } + ] + }, + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"if\" (and 3 more errors)", + "tests": [ + { + "description": "when if matches and it has no unevaluated items", + "data": [ + "foo", + "bar", + "then" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "when if matches and it has unevaluated items", + "data": [ + "foo", + "bar", + "then", + "else" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "when if doesn't match and it has no unevaluated items", + "data": [ + "foo", + 42, + 42, + "else" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "when if doesn't match and it has unevaluated items", + "data": [ + "foo", + 42, + 42, + "else", + 42 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with boolean schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + true + ], + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "with no unevaluated items", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated items", + "data": [ + "foo" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$ref": "#/$defs/bar", + "items": [ + { + "type": "string" + } + ], + "unevaluatedItems": false, + "$defs": { + "bar": { + "items": [ + true, + { + "type": "string" + } + ] + } + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "with no unevaluated items", + "data": [ + "foo", + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated items", + "data": [ + "foo", + "bar", + "baz" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems before $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "unevaluatedItems": false, + "items": [ + { + "type": "string" + } + ], + "$ref": "#/$defs/bar", + "$defs": { + "bar": { + "items": [ + true, + { + "type": "string" + } + ] + } + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "with no unevaluated items", + "data": [ + "foo", + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated items", + "data": [ + "foo", + "bar", + "baz" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with $recursiveRef", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://example.com/unevaluated-items-with-recursive-ref/extended-tree", + "$recursiveAnchor": true, + "$ref": "./tree", + "items": [ + true, + true, + { + "type": "string" + } + ], + "$defs": { + "tree": { + "$id": "./tree", + "$recursiveAnchor": true, + "type": "array", + "items": [ + { + "type": "number" + }, + { + "$comment": "unevaluatedItems comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering", + "unevaluatedItems": false, + "$recursiveRef": "#" + } + ] + } + } + }, + "skip": "extract error: unsupported constraint \"$recursiveAnchor\" (and 3 more errors)", + "tests": [ + { + "description": "with no unevaluated items", + "data": [ + 1, + [ + 2, + [], + "b" + ], + "a" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated items", + "data": [ + 1, + [ + 2, + [], + "b", + "too many" + ], + "a" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems can't see inside cousins", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "items": [ + true + ] + }, + { + "unevaluatedItems": false + } + ] + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "always fails", + "data": [ + 1 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "item is evaluated in an uncle schema to unevaluatedItems", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo": { + "items": [ + { + "type": "string" + } + ], + "unevaluatedItems": false + } + }, + "anyOf": [ + { + "properties": { + "foo": { + "items": [ + true, + { + "type": "string" + } + ] + } + } + } + ] + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "no extra items", + "data": { + "foo": [ + "test" + ] + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "uncle keyword evaluation is not significant", + "data": { + "foo": [ + "test", + "test" + ] + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "non-array instances are valid", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "ignores booleans", + "data": true, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores integers", + "data": 123, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores strings", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores null", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "unevaluatedItems": { + "type": "null" + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "allows null elements", + "data": [ + null + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems can see annotations from if without then and else", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "items": [ + { + "const": "a" + } + ] + }, + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"if\" (and 1 more errors)", + "tests": [ + { + "description": "valid in case if is evaluated", + "data": [ + "a" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid in case if is evaluated", + "data": [ + "b" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/unevaluatedProperties.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/unevaluatedProperties.json new file mode 100644 index 000000000..dd6b0bccf --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/unevaluatedProperties.json @@ -0,0 +1,2059 @@ +[ + { + "description": "unevaluatedProperties true", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "unevaluatedProperties": true + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no unevaluated properties", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties schema", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "unevaluatedProperties": { + "type": "string", + "minLength": 3 + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no unevaluated properties", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with valid unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with invalid unevaluated properties", + "data": { + "foo": "fo" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties false", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no unevaluated properties", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with adjacent properties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with adjacent patternProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "patternProperties": { + "^foo": { + "type": "string" + } + }, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with adjacent additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "additionalProperties": true, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no additional properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with additional properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with nested properties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "allOf": [ + { + "properties": { + "bar": { + "type": "string" + } + } + } + ], + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no additional properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with additional properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with nested patternProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "allOf": [ + { + "patternProperties": { + "^bar": { + "type": "string" + } + } + } + ], + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no additional properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with additional properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with nested additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "allOf": [ + { + "additionalProperties": true + } + ], + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no additional properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with additional properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with nested unevaluatedProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "allOf": [ + { + "unevaluatedProperties": true + } + ], + "unevaluatedProperties": { + "type": "string", + "maxLength": 2 + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\" (and 1 more errors)", + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with anyOf", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "anyOf": [ + { + "properties": { + "bar": { + "const": "bar" + } + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "baz": { + "const": "baz" + } + }, + "required": [ + "baz" + ] + }, + { + "properties": { + "quux": { + "const": "quux" + } + }, + "required": [ + "quux" + ] + } + ], + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "when one matches and has no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "when one matches and has unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "not-baz" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "when two match and has no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "when two match and has unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz", + "quux": "not-quux" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "oneOf": [ + { + "properties": { + "bar": { + "const": "bar" + } + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "baz": { + "const": "baz" + } + }, + "required": [ + "baz" + ] + } + ], + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "quux": "quux" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with not", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "not": { + "not": { + "properties": { + "bar": { + "const": "bar" + } + }, + "required": [ + "bar" + ] + } + }, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"not\" (and 1 more errors)", + "tests": [ + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with if/then/else", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "if": { + "properties": { + "foo": { + "const": "then" + } + }, + "required": [ + "foo" + ] + }, + "then": { + "properties": { + "bar": { + "type": "string" + } + }, + "required": [ + "bar" + ] + }, + "else": { + "properties": { + "baz": { + "type": "string" + } + }, + "required": [ + "baz" + ] + }, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"if\" (and 3 more errors)", + "tests": [ + { + "description": "when if is true and has no unevaluated properties", + "data": { + "foo": "then", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "when if is true and has unevaluated properties", + "data": { + "foo": "then", + "bar": "bar", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "when if is false and has no unevaluated properties", + "data": { + "baz": "baz" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "when if is false and has unevaluated properties", + "data": { + "foo": "else", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with if/then/else, then not defined", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "if": { + "properties": { + "foo": { + "const": "then" + } + }, + "required": [ + "foo" + ] + }, + "else": { + "properties": { + "baz": { + "type": "string" + } + }, + "required": [ + "baz" + ] + }, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"if\" (and 2 more errors)", + "tests": [ + { + "description": "when if is true and has no unevaluated properties", + "data": { + "foo": "then", + "bar": "bar" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "when if is true and has unevaluated properties", + "data": { + "foo": "then", + "bar": "bar", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "when if is false and has no unevaluated properties", + "data": { + "baz": "baz" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "when if is false and has unevaluated properties", + "data": { + "foo": "else", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with if/then/else, else not defined", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "if": { + "properties": { + "foo": { + "const": "then" + } + }, + "required": [ + "foo" + ] + }, + "then": { + "properties": { + "bar": { + "type": "string" + } + }, + "required": [ + "bar" + ] + }, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"if\" (and 2 more errors)", + "tests": [ + { + "description": "when if is true and has no unevaluated properties", + "data": { + "foo": "then", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "when if is true and has unevaluated properties", + "data": { + "foo": "then", + "bar": "bar", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "when if is false and has no unevaluated properties", + "data": { + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "when if is false and has unevaluated properties", + "data": { + "foo": "else", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with dependentSchemas", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "dependentSchemas": { + "foo": { + "properties": { + "bar": { + "const": "bar" + } + }, + "required": [ + "bar" + ] + } + }, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"dependentSchemas\" (and 1 more errors)", + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated properties", + "data": { + "bar": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with boolean schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "allOf": [ + true + ], + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated properties", + "data": { + "bar": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "$ref": "#/$defs/bar", + "properties": { + "foo": { + "type": "string" + } + }, + "unevaluatedProperties": false, + "$defs": { + "bar": { + "properties": { + "bar": { + "type": "string" + } + } + } + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties before $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "unevaluatedProperties": false, + "properties": { + "foo": { + "type": "string" + } + }, + "$ref": "#/$defs/bar", + "$defs": { + "bar": { + "properties": { + "bar": { + "type": "string" + } + } + } + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with $recursiveRef", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "https://example.com/unevaluated-properties-with-recursive-ref/extended-tree", + "$recursiveAnchor": true, + "$ref": "./tree", + "properties": { + "name": { + "type": "string" + } + }, + "$defs": { + "tree": { + "$id": "./tree", + "$recursiveAnchor": true, + "type": "object", + "properties": { + "node": true, + "branches": { + "$comment": "unevaluatedProperties comes first so it's more likely to bugs errors with implementations that are sensitive to keyword ordering", + "unevaluatedProperties": false, + "$recursiveRef": "#" + } + }, + "required": [ + "node" + ] + } + } + }, + "skip": "extract error: unsupported constraint \"$recursiveAnchor\" (and 3 more errors)", + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "name": "a", + "node": 1, + "branches": { + "name": "b", + "node": 2 + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated properties", + "data": { + "name": "a", + "node": 1, + "branches": { + "foo": "b", + "node": 2 + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties can't see inside cousins", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "properties": { + "foo": true + } + }, + { + "unevaluatedProperties": false + } + ] + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "always fails", + "data": { + "foo": 1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties can't see inside cousins (reverse order)", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "allOf": [ + { + "unevaluatedProperties": false + }, + { + "properties": { + "foo": true + } + } + ] + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "always fails", + "data": { + "foo": 1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "nested unevaluatedProperties, outer false, inner true, properties outside", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "allOf": [ + { + "unevaluatedProperties": true + } + ], + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\" (and 1 more errors)", + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "nested unevaluatedProperties, outer false, inner true, properties inside", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": { + "type": "string" + } + }, + "unevaluatedProperties": true + } + ], + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\" (and 1 more errors)", + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "nested unevaluatedProperties, outer true, inner false, properties outside", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "allOf": [ + { + "unevaluatedProperties": false + } + ], + "unevaluatedProperties": true + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\" (and 1 more errors)", + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "nested unevaluatedProperties, outer true, inner false, properties inside", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": { + "type": "string" + } + }, + "unevaluatedProperties": false + } + ], + "unevaluatedProperties": true + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\" (and 1 more errors)", + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "cousin unevaluatedProperties, true and false, true with properties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": { + "type": "string" + } + }, + "unevaluatedProperties": true + }, + { + "unevaluatedProperties": false + } + ] + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\" (and 1 more errors)", + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "cousin unevaluatedProperties, true and false, false with properties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "allOf": [ + { + "unevaluatedProperties": true + }, + { + "properties": { + "foo": { + "type": "string" + } + }, + "unevaluatedProperties": false + } + ] + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\" (and 1 more errors)", + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "property is evaluated in an uncle schema to unevaluatedProperties", + "comment": "see https://stackoverflow.com/questions/66936884/deeply-nested-unevaluatedproperties-and-their-expectations", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "foo": { + "type": "object", + "properties": { + "bar": { + "type": "string" + } + }, + "unevaluatedProperties": false + } + }, + "anyOf": [ + { + "properties": { + "foo": { + "properties": { + "faz": { + "type": "string" + } + } + } + } + } + ] + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "no extra properties", + "data": { + "foo": { + "bar": "test" + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "uncle keyword evaluation is not significant", + "data": { + "foo": { + "bar": "test", + "faz": "test" + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "in-place applicator siblings, allOf has unevaluated", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": true + }, + "unevaluatedProperties": false + } + ], + "anyOf": [ + { + "properties": { + "bar": true + } + } + ] + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "base case: both properties present", + "data": { + "foo": 1, + "bar": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "in place applicator siblings, bar is missing", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "in place applicator siblings, foo is missing", + "data": { + "bar": 1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "in-place applicator siblings, anyOf has unevaluated", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": true + } + } + ], + "anyOf": [ + { + "properties": { + "bar": true + }, + "unevaluatedProperties": false + } + ] + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "base case: both properties present", + "data": { + "foo": 1, + "bar": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "in place applicator siblings, bar is missing", + "data": { + "foo": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "in place applicator siblings, foo is missing", + "data": { + "bar": 1 + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties + single cyclic ref", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "x": { + "$ref": "#" + } + }, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "Empty is valid", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Single is valid", + "data": { + "x": {} + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Unevaluated on 1st level is invalid", + "data": { + "x": {}, + "y": {} + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Nested is valid", + "data": { + "x": { + "x": {} + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Unevaluated on 2nd level is invalid", + "data": { + "x": { + "x": {}, + "y": {} + } + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Deep nested is valid", + "data": { + "x": { + "x": { + "x": {} + } + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Unevaluated on 3rd level is invalid", + "data": { + "x": { + "x": { + "x": {}, + "y": {} + } + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties + ref inside allOf / oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "one": { + "properties": { + "a": true + } + }, + "two": { + "required": [ + "x" + ], + "properties": { + "x": true + } + } + }, + "allOf": [ + { + "$ref": "#/$defs/one" + }, + { + "properties": { + "b": true + } + }, + { + "oneOf": [ + { + "$ref": "#/$defs/two" + }, + { + "required": [ + "y" + ], + "properties": { + "y": true + } + } + ] + } + ], + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "Empty is invalid (no x or y)", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a and b are invalid (no x or y)", + "data": { + "a": 1, + "b": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "x and y are invalid", + "data": { + "x": 1, + "y": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a and x are valid", + "data": { + "a": 1, + "x": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a and y are valid", + "data": { + "a": 1, + "y": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a and b and x are valid", + "data": { + "a": 1, + "b": 1, + "x": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a and b and y are valid", + "data": { + "a": 1, + "b": 1, + "y": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a and b and x and y are invalid", + "data": { + "a": 1, + "b": 1, + "x": 1, + "y": 1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "dynamic evalation inside nested refs", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$defs": { + "one": { + "oneOf": [ + { + "$ref": "#/$defs/two" + }, + { + "required": [ + "b" + ], + "properties": { + "b": true + } + }, + { + "required": [ + "xx" + ], + "patternProperties": { + "x": true + } + }, + { + "required": [ + "all" + ], + "unevaluatedProperties": true + } + ] + }, + "two": { + "oneOf": [ + { + "required": [ + "c" + ], + "properties": { + "c": true + } + }, + { + "required": [ + "d" + ], + "properties": { + "d": true + } + } + ] + } + }, + "oneOf": [ + { + "$ref": "#/$defs/one" + }, + { + "required": [ + "a" + ], + "properties": { + "a": true + } + } + ], + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\" (and 1 more errors)", + "tests": [ + { + "description": "Empty is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a is valid", + "data": { + "a": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "b is valid", + "data": { + "b": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "c is valid", + "data": { + "c": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "d is valid", + "data": { + "d": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a + b is invalid", + "data": { + "a": 1, + "b": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a + c is invalid", + "data": { + "a": 1, + "c": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a + d is invalid", + "data": { + "a": 1, + "d": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "b + c is invalid", + "data": { + "b": 1, + "c": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "b + d is invalid", + "data": { + "b": 1, + "d": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "c + d is invalid", + "data": { + "c": 1, + "d": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "xx is valid", + "data": { + "xx": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "xx + foox is valid", + "data": { + "xx": 1, + "foox": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "xx + foo is invalid", + "data": { + "xx": 1, + "foo": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "xx + a is invalid", + "data": { + "xx": 1, + "a": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "xx + b is invalid", + "data": { + "xx": 1, + "b": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "xx + c is invalid", + "data": { + "xx": 1, + "c": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "xx + d is invalid", + "data": { + "xx": 1, + "d": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "all is valid", + "data": { + "all": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all + foo is valid", + "data": { + "all": 1, + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all + a is invalid", + "data": { + "all": 1, + "a": 1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "non-object instances are valid", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "ignores booleans", + "data": true, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores integers", + "data": 123, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores strings", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores null", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with null valued instance properties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "unevaluatedProperties": { + "type": "null" + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "allows null valued properties", + "data": { + "foo": null + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties not affected by propertyNames", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "propertyNames": { + "maxLength": 1 + }, + "unevaluatedProperties": { + "type": "number" + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "allows only number properties", + "data": { + "a": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string property is invalid", + "data": { + "a": "b" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties can see annotations from if without then and else", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "if": { + "patternProperties": { + "foo": { + "type": "string" + } + } + }, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"if\" (and 1 more errors)", + "tests": [ + { + "description": "valid in case if is evaluated", + "data": { + "foo": "a" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid in case if is evaluated", + "data": { + "bar": "a" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "dependentSchemas with unevaluatedProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "properties": { + "foo2": {} + }, + "dependentSchemas": { + "foo": {}, + "foo2": { + "properties": { + "bar": {} + } + } + }, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"dependentSchemas\" (and 1 more errors)", + "tests": [ + { + "description": "unevaluatedProperties doesn't consider dependentSchemas", + "data": { + "foo": "" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "unevaluatedProperties doesn't see bar when foo2 is absent", + "data": { + "bar": "" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "unevaluatedProperties sees bar when foo2 is present", + "data": { + "foo2": "", + "bar": "" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/uniqueItems.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/uniqueItems.json new file mode 100644 index 000000000..bccd3253e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/uniqueItems.json @@ -0,0 +1,838 @@ +[ + { + "description": "uniqueItems validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "uniqueItems": true + }, + "tests": [ + { + "description": "unique array of integers is valid", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "non-unique array of integers is invalid", + "data": [ + 1, + 1 + ], + "valid": false + }, + { + "description": "non-unique array of more than two integers is invalid", + "data": [ + 1, + 2, + 1 + ], + "valid": false + }, + { + "description": "numbers are unique if mathematically unequal", + "data": [ + 1.0, + 1.00, + 1 + ], + "valid": false, + "skip": "unexpected success" + }, + { + "description": "false is not equal to zero", + "data": [ + 0, + false + ], + "valid": true + }, + { + "description": "true is not equal to one", + "data": [ + 1, + true + ], + "valid": true + }, + { + "description": "unique array of strings is valid", + "data": [ + "foo", + "bar", + "baz" + ], + "valid": true + }, + { + "description": "non-unique array of strings is invalid", + "data": [ + "foo", + "bar", + "foo" + ], + "valid": false + }, + { + "description": "unique array of objects is valid", + "data": [ + { + "foo": "bar" + }, + { + "foo": "baz" + } + ], + "valid": true + }, + { + "description": "non-unique array of objects is invalid", + "data": [ + { + "foo": "bar" + }, + { + "foo": "bar" + } + ], + "valid": false + }, + { + "description": "property order of array of objects is ignored", + "data": [ + { + "foo": "bar", + "bar": "foo" + }, + { + "bar": "foo", + "foo": "bar" + } + ], + "valid": false, + "skip": "unexpected success" + }, + { + "description": "unique array of nested objects is valid", + "data": [ + { + "foo": { + "bar": { + "baz": true + } + } + }, + { + "foo": { + "bar": { + "baz": false + } + } + } + ], + "valid": true + }, + { + "description": "non-unique array of nested objects is invalid", + "data": [ + { + "foo": { + "bar": { + "baz": true + } + } + }, + { + "foo": { + "bar": { + "baz": true + } + } + } + ], + "valid": false + }, + { + "description": "unique array of arrays is valid", + "data": [ + [ + "foo" + ], + [ + "bar" + ] + ], + "valid": true + }, + { + "description": "non-unique array of arrays is invalid", + "data": [ + [ + "foo" + ], + [ + "foo" + ] + ], + "valid": false + }, + { + "description": "non-unique array of more than two arrays is invalid", + "data": [ + [ + "foo" + ], + [ + "bar" + ], + [ + "foo" + ] + ], + "valid": false + }, + { + "description": "1 and true are unique", + "data": [ + 1, + true + ], + "valid": true + }, + { + "description": "0 and false are unique", + "data": [ + 0, + false + ], + "valid": true + }, + { + "description": "[1] and [true] are unique", + "data": [ + [ + 1 + ], + [ + true + ] + ], + "valid": true + }, + { + "description": "[0] and [false] are unique", + "data": [ + [ + 0 + ], + [ + false + ] + ], + "valid": true + }, + { + "description": "nested [1] and [true] are unique", + "data": [ + [ + [ + 1 + ], + "foo" + ], + [ + [ + true + ], + "foo" + ] + ], + "valid": true + }, + { + "description": "nested [0] and [false] are unique", + "data": [ + [ + [ + 0 + ], + "foo" + ], + [ + [ + false + ], + "foo" + ] + ], + "valid": true + }, + { + "description": "unique heterogeneous types are valid", + "data": [ + {}, + [ + 1 + ], + true, + null, + 1, + "{}" + ], + "valid": true + }, + { + "description": "non-unique heterogeneous types are invalid", + "data": [ + {}, + [ + 1 + ], + true, + null, + {}, + 1 + ], + "valid": false + }, + { + "description": "different objects are unique", + "data": [ + { + "a": 1, + "b": 2 + }, + { + "a": 2, + "b": 1 + } + ], + "valid": true + }, + { + "description": "objects are non-unique despite key order", + "data": [ + { + "a": 1, + "b": 2 + }, + { + "b": 2, + "a": 1 + } + ], + "valid": false, + "skip": "unexpected success" + }, + { + "description": "{\"a\": false} and {\"a\": 0} are unique", + "data": [ + { + "a": false + }, + { + "a": 0 + } + ], + "valid": true + }, + { + "description": "{\"a\": true} and {\"a\": 1} are unique", + "data": [ + { + "a": true + }, + { + "a": 1 + } + ], + "valid": true + } + ] + }, + { + "description": "uniqueItems with an array of items", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { + "type": "boolean" + }, + { + "type": "boolean" + } + ], + "uniqueItems": true + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [ + false, + true + ], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [ + true, + false + ], + "valid": true + }, + { + "description": "[false, false] from items array is not valid", + "data": [ + false, + false + ], + "valid": false + }, + { + "description": "[true, true] from items array is not valid", + "data": [ + true, + true + ], + "valid": false + }, + { + "description": "unique array extended from [false, true] is valid", + "data": [ + false, + true, + "foo", + "bar" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [false,true,\"foo\",\"bar\"] and {...} (mismatched types list and struct):\n generated.cue:4:1\n generated.cue:4:69\n instance.json:1:1\nconflicting values bool and [false,true,\"foo\",\"bar\"] (mismatched types bool and list):\n generated.cue:4:8\n instance.json:1:1\nconflicting values null and [false,true,\"foo\",\"bar\"] (mismatched types null and list):\n generated.cue:4:1\n instance.json:1:1\nconflicting values number and [false,true,\"foo\",\"bar\"] (mismatched types number and list):\n generated.cue:4:15\n instance.json:1:1\nconflicting values string and [false,true,\"foo\",\"bar\"] (mismatched types string and list):\n generated.cue:4:24\n instance.json:1:1\n" + }, + { + "description": "unique array extended from [true, false] is valid", + "data": [ + true, + false, + "foo", + "bar" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [true,false,\"foo\",\"bar\"] and {...} (mismatched types list and struct):\n generated.cue:4:1\n generated.cue:4:69\n instance.json:1:1\nconflicting values bool and [true,false,\"foo\",\"bar\"] (mismatched types bool and list):\n generated.cue:4:8\n instance.json:1:1\nconflicting values null and [true,false,\"foo\",\"bar\"] (mismatched types null and list):\n generated.cue:4:1\n instance.json:1:1\nconflicting values number and [true,false,\"foo\",\"bar\"] (mismatched types number and list):\n generated.cue:4:15\n instance.json:1:1\nconflicting values string and [true,false,\"foo\",\"bar\"] (mismatched types string and list):\n generated.cue:4:24\n instance.json:1:1\n" + }, + { + "description": "non-unique array extended from [false, true] is not valid", + "data": [ + false, + true, + "foo", + "foo" + ], + "valid": false + }, + { + "description": "non-unique array extended from [true, false] is not valid", + "data": [ + true, + false, + "foo", + "foo" + ], + "valid": false + } + ] + }, + { + "description": "uniqueItems with an array of items and additionalItems=false", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { + "type": "boolean" + }, + { + "type": "boolean" + } + ], + "uniqueItems": true, + "additionalItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [ + false, + true + ], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [ + true, + false + ], + "valid": true + }, + { + "description": "[false, false] from items array is not valid", + "data": [ + false, + false + ], + "valid": false + }, + { + "description": "[true, true] from items array is not valid", + "data": [ + true, + true + ], + "valid": false + }, + { + "description": "extra items are invalid even if unique", + "data": [ + false, + true, + null + ], + "valid": false + } + ] + }, + { + "description": "uniqueItems=false validation", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "uniqueItems": false + }, + "tests": [ + { + "description": "unique array of integers is valid", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "non-unique array of integers is valid", + "data": [ + 1, + 1 + ], + "valid": true + }, + { + "description": "numbers are unique if mathematically unequal", + "data": [ + 1.0, + 1.00, + 1 + ], + "valid": true + }, + { + "description": "false is not equal to zero", + "data": [ + 0, + false + ], + "valid": true + }, + { + "description": "true is not equal to one", + "data": [ + 1, + true + ], + "valid": true + }, + { + "description": "unique array of objects is valid", + "data": [ + { + "foo": "bar" + }, + { + "foo": "baz" + } + ], + "valid": true + }, + { + "description": "non-unique array of objects is valid", + "data": [ + { + "foo": "bar" + }, + { + "foo": "bar" + } + ], + "valid": true + }, + { + "description": "unique array of nested objects is valid", + "data": [ + { + "foo": { + "bar": { + "baz": true + } + } + }, + { + "foo": { + "bar": { + "baz": false + } + } + } + ], + "valid": true + }, + { + "description": "non-unique array of nested objects is valid", + "data": [ + { + "foo": { + "bar": { + "baz": true + } + } + }, + { + "foo": { + "bar": { + "baz": true + } + } + } + ], + "valid": true + }, + { + "description": "unique array of arrays is valid", + "data": [ + [ + "foo" + ], + [ + "bar" + ] + ], + "valid": true + }, + { + "description": "non-unique array of arrays is valid", + "data": [ + [ + "foo" + ], + [ + "foo" + ] + ], + "valid": true + }, + { + "description": "1 and true are unique", + "data": [ + 1, + true + ], + "valid": true + }, + { + "description": "0 and false are unique", + "data": [ + 0, + false + ], + "valid": true + }, + { + "description": "unique heterogeneous types are valid", + "data": [ + {}, + [ + 1 + ], + true, + null, + 1 + ], + "valid": true + }, + { + "description": "non-unique heterogeneous types are valid", + "data": [ + {}, + [ + 1 + ], + true, + null, + {}, + 1 + ], + "valid": true + } + ] + }, + { + "description": "uniqueItems=false with an array of items", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { + "type": "boolean" + }, + { + "type": "boolean" + } + ], + "uniqueItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [ + false, + true + ], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [ + true, + false + ], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [ + false, + false + ], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [ + true, + true + ], + "valid": true + }, + { + "description": "unique array extended from [false, true] is valid", + "data": [ + false, + true, + "foo", + "bar" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [false,true,\"foo\",\"bar\"] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:48\n instance.json:1:1\nconflicting values bool and [false,true,\"foo\",\"bar\"] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [false,true,\"foo\",\"bar\"] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [false,true,\"foo\",\"bar\"] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [false,true,\"foo\",\"bar\"] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "unique array extended from [true, false] is valid", + "data": [ + true, + false, + "foo", + "bar" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [true,false,\"foo\",\"bar\"] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:48\n instance.json:1:1\nconflicting values bool and [true,false,\"foo\",\"bar\"] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [true,false,\"foo\",\"bar\"] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [true,false,\"foo\",\"bar\"] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [true,false,\"foo\",\"bar\"] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "non-unique array extended from [false, true] is valid", + "data": [ + false, + true, + "foo", + "foo" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [false,true,\"foo\",\"foo\"] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:48\n instance.json:1:1\nconflicting values bool and [false,true,\"foo\",\"foo\"] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [false,true,\"foo\",\"foo\"] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [false,true,\"foo\",\"foo\"] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [false,true,\"foo\",\"foo\"] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "non-unique array extended from [true, false] is valid", + "data": [ + true, + false, + "foo", + "foo" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [true,false,\"foo\",\"foo\"] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:48\n instance.json:1:1\nconflicting values bool and [true,false,\"foo\",\"foo\"] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [true,false,\"foo\",\"foo\"] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [true,false,\"foo\",\"foo\"] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [true,false,\"foo\",\"foo\"] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + } + ] + }, + { + "description": "uniqueItems=false with an array of items and additionalItems=false", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "items": [ + { + "type": "boolean" + }, + { + "type": "boolean" + } + ], + "uniqueItems": false, + "additionalItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [ + false, + true + ], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [ + true, + false + ], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [ + false, + false + ], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [ + true, + true + ], + "valid": true + }, + { + "description": "extra items are invalid even if unique", + "data": [ + false, + true, + null + ], + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2019-09/vocabulary.json b/encoding/jsonschema/testdata/external/tests/draft2019-09/vocabulary.json new file mode 100644 index 000000000..a9f6149aa --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2019-09/vocabulary.json @@ -0,0 +1,64 @@ +[ + { + "description": "schema that uses custom metaschema with with no validation vocabulary", + "schema": { + "$id": "https://schema/using/no/validation", + "$schema": "http://localhost:1234/draft2019-09/metaschema-no-validation.json", + "properties": { + "badProperty": false, + "numberProperty": { + "minimum": 10 + } + } + }, + "skip": "extract error: invalid $schema URL \"http://localhost:1234/draft2019-09/metaschema-no-validation.json\": $schema URI not recognized", + "tests": [ + { + "description": "applicator vocabulary still works", + "data": { + "badProperty": "this property should not exist" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no validation: valid number", + "data": { + "numberProperty": 20 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "no validation: invalid number, but it still validates", + "data": { + "numberProperty": 1 + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ignore unrecognized optional vocabulary", + "schema": { + "$schema": "http://localhost:1234/draft2019-09/metaschema-optional-vocabulary.json", + "type": "number" + }, + "skip": "extract error: invalid $schema URL \"http://localhost:1234/draft2019-09/metaschema-optional-vocabulary.json\": $schema URI not recognized", + "tests": [ + { + "description": "string value", + "data": "foobar", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "number value", + "data": 20, + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/additionalProperties.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/additionalProperties.json new file mode 100644 index 000000000..e8bae45e1 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/additionalProperties.json @@ -0,0 +1,297 @@ +[ + { + "description": "additionalProperties being false does not allow other properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": {}, + "bar": {} + }, + "patternProperties": { + "^v": {} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "no additional properties is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "an additional property is invalid", + "data": { + "foo": 1, + "bar": 2, + "quux": "boom" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ignores arrays", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobarbaz", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "patternProperties are not additional properties", + "data": { + "foo": 1, + "vroom": 2 + }, + "valid": true + } + ] + }, + { + "description": "non-ASCII pattern with additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "patternProperties": { + "^á": {} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "matching the pattern is valid", + "data": { + "ármányos": 2 + }, + "valid": true + }, + { + "description": "not matching the pattern is invalid", + "data": { + "élmény": 2 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "additionalProperties with schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": {}, + "bar": {} + }, + "additionalProperties": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "no additional properties is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "an additional valid property is valid", + "data": { + "foo": 1, + "bar": 2, + "quux": true + }, + "valid": true + }, + { + "description": "an additional invalid property is invalid", + "data": { + "foo": 1, + "bar": 2, + "quux": 12 + }, + "valid": false + } + ] + }, + { + "description": "additionalProperties can exist by itself", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "additionalProperties": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "an additional valid property is valid", + "data": { + "foo": true + }, + "valid": true + }, + { + "description": "an additional invalid property is invalid", + "data": { + "foo": 1 + }, + "valid": false + } + ] + }, + { + "description": "additionalProperties are allowed by default", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": {}, + "bar": {} + } + }, + "tests": [ + { + "description": "additional properties are allowed", + "data": { + "foo": 1, + "bar": 2, + "quux": true + }, + "valid": true + } + ] + }, + { + "description": "additionalProperties does not look in applicators", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "properties": { + "foo": {} + } + } + ], + "additionalProperties": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "properties defined in allOf are not examined", + "data": { + "foo": 1, + "bar": true + }, + "valid": false + } + ] + }, + { + "description": "additionalProperties with null valued instance properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "additionalProperties": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null values", + "data": { + "foo": null + }, + "valid": true + } + ] + }, + { + "description": "additionalProperties with propertyNames", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "propertyNames": { + "maxLength": 5 + }, + "additionalProperties": { + "type": "number" + } + }, + "skip": "extract error: cannot compile resulting schema: reference \"strings\" in label expression refers to field against which it would be matched:\n generated.cue:5:3\n", + "tests": [ + { + "description": "Valid against both keywords", + "data": { + "apple": 4 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Valid against propertyNames, but not additionalProperties", + "data": { + "fig": 2, + "pear": "available" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "dependentSchemas with additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo2": {} + }, + "dependentSchemas": { + "foo": {}, + "foo2": { + "properties": { + "bar": {} + } + } + }, + "additionalProperties": false + }, + "skip": "extract error: unsupported constraint \"dependentSchemas\"", + "tests": [ + { + "description": "additionalProperties doesn't consider dependentSchemas", + "data": { + "foo": "" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "additionalProperties can't see bar", + "data": { + "bar": "" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "additionalProperties can't see bar even when foo2 is present", + "data": { + "foo2": "", + "bar": "" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/allOf.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/allOf.json new file mode 100644 index 000000000..0f8b7f233 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/allOf.json @@ -0,0 +1,396 @@ +[ + { + "description": "allOf", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "properties": { + "bar": { + "type": "integer" + } + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + } + ] + }, + "tests": [ + { + "description": "allOf", + "data": { + "foo": "baz", + "bar": 2 + }, + "valid": true + }, + { + "description": "mismatch second", + "data": { + "foo": "baz" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "mismatch first", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "wrong type", + "data": { + "foo": "baz", + "bar": "quux" + }, + "valid": false + } + ] + }, + { + "description": "allOf with base schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "bar": { + "type": "integer" + } + }, + "required": [ + "bar" + ], + "allOf": [ + { + "properties": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + }, + { + "properties": { + "baz": { + "type": "null" + } + }, + "required": [ + "baz" + ] + } + ] + }, + "tests": [ + { + "description": "valid", + "data": { + "foo": "quux", + "bar": 2, + "baz": null + }, + "valid": true + }, + { + "description": "mismatch base schema", + "data": { + "foo": "quux", + "baz": null + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "mismatch first allOf", + "data": { + "bar": 2, + "baz": null + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "mismatch second allOf", + "data": { + "foo": "quux", + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "mismatch both", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "allOf simple types", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "maximum": 30 + }, + { + "minimum": 20 + } + ] + }, + "tests": [ + { + "description": "valid", + "data": 25, + "valid": true + }, + { + "description": "mismatch one", + "data": 35, + "valid": false + } + ] + }, + { + "description": "allOf with boolean schemas, all true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + true, + true + ] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "allOf with boolean schemas, some false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + true, + false + ] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "allOf with boolean schemas, all false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + false, + false + ] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "allOf with one empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + {} + ] + }, + "tests": [ + { + "description": "any data is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "allOf with two empty schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + {}, + {} + ] + }, + "tests": [ + { + "description": "any data is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "allOf with the first empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + {}, + { + "type": "number" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "allOf with the last empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "type": "number" + }, + {} + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "nested allOf, to check validation semantics", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "allOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "allOf combined with anyOf, oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "multipleOf": 2 + } + ], + "anyOf": [ + { + "multipleOf": 3 + } + ], + "oneOf": [ + { + "multipleOf": 5 + } + ] + }, + "tests": [ + { + "description": "allOf: false, anyOf: false, oneOf: false", + "data": 1, + "valid": false + }, + { + "description": "allOf: false, anyOf: false, oneOf: true", + "data": 5, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: false", + "data": 3, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: true", + "data": 15, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: false", + "data": 2, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: true", + "data": 10, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: false", + "data": 6, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: true", + "data": 30, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/anchor.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/anchor.json new file mode 100644 index 000000000..9af847b86 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/anchor.json @@ -0,0 +1,132 @@ +[ + { + "description": "Location-independent identifier", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "#foo", + "$defs": { + "A": { + "$anchor": "foo", + "type": "integer" + } + } + }, + "skip": "extract error: anchors (foo) not supported (and 1 more errors)", + "tests": [ + { + "description": "match", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "Location-independent identifier with absolute URI", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "http://localhost:1234/draft2020-12/bar#foo", + "$defs": { + "A": { + "$id": "http://localhost:1234/draft2020-12/bar", + "$anchor": "foo", + "type": "integer" + } + } + }, + "skip": "extract error: anchors (foo) not supported (and 1 more errors)", + "tests": [ + { + "description": "match", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "Location-independent identifier with base URI change in subschema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/root", + "$ref": "http://localhost:1234/draft2020-12/nested.json#foo", + "$defs": { + "A": { + "$id": "nested.json", + "$defs": { + "B": { + "$anchor": "foo", + "type": "integer" + } + } + } + } + }, + "skip": "extract error: anchors (foo) not supported (and 1 more errors)", + "tests": [ + { + "description": "match", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "same $anchor with different base uri", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/foobar", + "$defs": { + "A": { + "$id": "child1", + "allOf": [ + { + "$id": "child2", + "$anchor": "my_anchor", + "type": "number" + }, + { + "$anchor": "my_anchor", + "type": "string" + } + ] + } + }, + "$ref": "child1#my_anchor" + }, + "skip": "extract error: unsupported constraint \"$anchor\" (and 4 more errors)", + "tests": [ + { + "description": "$ref resolves to /$defs/A/allOf/1", + "data": "a", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "$ref does not resolve to /$defs/A/allOf/0", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/anyOf.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/anyOf.json new file mode 100644 index 000000000..5fd2721c2 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/anyOf.json @@ -0,0 +1,234 @@ +[ + { + "description": "anyOf", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "anyOf": [ + { + "type": "integer" + }, + { + "minimum": 2 + } + ] + }, + "tests": [ + { + "description": "first anyOf valid", + "data": 1, + "valid": true + }, + { + "description": "second anyOf valid", + "data": 2.5, + "valid": true + }, + { + "description": "both anyOf valid", + "data": 3, + "valid": true + }, + { + "description": "neither anyOf valid", + "data": 1.5, + "valid": false + } + ] + }, + { + "description": "anyOf with base schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "anyOf": [ + { + "maxLength": 2 + }, + { + "minLength": 4 + } + ] + }, + "tests": [ + { + "description": "mismatch base schema", + "data": 3, + "valid": false + }, + { + "description": "one anyOf valid", + "data": "foobar", + "valid": true + }, + { + "description": "both anyOf invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "anyOf with boolean schemas, all true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "anyOf": [ + true, + true + ] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "anyOf with boolean schemas, some true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "anyOf": [ + true, + false + ] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "anyOf with boolean schemas, all false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "anyOf": [ + false, + false + ] + }, + "skip": "extract error: cannot compile resulting schema: 2 errors in empty disjunction:\nexplicit error (_|_ literal) in source:\n generated.cue:2:1\nexplicit error (_|_ literal) in source:\n generated.cue:2:7\n", + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "anyOf complex types", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "anyOf": [ + { + "properties": { + "bar": { + "type": "integer" + } + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + } + ] + }, + "tests": [ + { + "description": "first anyOf valid (complex)", + "data": { + "bar": 2 + }, + "valid": true + }, + { + "description": "second anyOf valid (complex)", + "data": { + "foo": "baz" + }, + "valid": true + }, + { + "description": "both anyOf valid (complex)", + "data": { + "foo": "baz", + "bar": 2 + }, + "valid": true + }, + { + "description": "neither anyOf valid (complex)", + "data": { + "foo": 2, + "bar": "quux" + }, + "valid": false + } + ] + }, + { + "description": "anyOf with one empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "anyOf": [ + { + "type": "number" + }, + {} + ] + }, + "tests": [ + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "number is valid", + "data": 123, + "valid": true + } + ] + }, + { + "description": "nested anyOf, to check validation semantics", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "anyOf": [ + { + "anyOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/boolean_schema.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/boolean_schema.json new file mode 100644 index 000000000..dd0e5677f --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/boolean_schema.json @@ -0,0 +1,122 @@ +[ + { + "description": "boolean schema 'true'", + "schema": true, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "boolean true is valid", + "data": true, + "valid": true + }, + { + "description": "boolean false is valid", + "data": false, + "valid": true + }, + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "object is valid", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + }, + { + "description": "array is valid", + "data": [ + "foo" + ], + "valid": true + }, + { + "description": "empty array is valid", + "data": [], + "valid": true + } + ] + }, + { + "description": "boolean schema 'false'", + "schema": false, + "skip": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n generated.cue:2:1\n", + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "null is invalid", + "data": null, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "object is invalid", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "array is invalid", + "data": [ + "foo" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/const.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/const.json new file mode 100644 index 000000000..2b8d777e2 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/const.json @@ -0,0 +1,452 @@ +[ + { + "description": "const validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": 2 + }, + "tests": [ + { + "description": "same value is valid", + "data": 2, + "valid": true + }, + { + "description": "another value is invalid", + "data": 5, + "valid": false + }, + { + "description": "another type is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "const with object", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": { + "foo": "bar", + "baz": "bax" + } + }, + "tests": [ + { + "description": "same object is valid", + "data": { + "foo": "bar", + "baz": "bax" + }, + "valid": true + }, + { + "description": "same object with different property order is valid", + "data": { + "baz": "bax", + "foo": "bar" + }, + "valid": true + }, + { + "description": "another object is invalid", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "another type is invalid", + "data": [ + 1, + 2 + ], + "valid": false + } + ] + }, + { + "description": "const with array", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": [ + { + "foo": "bar" + } + ] + }, + "tests": [ + { + "description": "same array is valid", + "data": [ + { + "foo": "bar" + } + ], + "valid": true + }, + { + "description": "another array item is invalid", + "data": [ + 2 + ], + "valid": false + }, + { + "description": "array with additional items is invalid", + "data": [ + 1, + 2, + 3 + ], + "valid": false + } + ] + }, + { + "description": "const with null", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": null + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "not null is invalid", + "data": 0, + "valid": false + } + ] + }, + { + "description": "const with false does not match 0", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": false + }, + "tests": [ + { + "description": "false is valid", + "data": false, + "valid": true + }, + { + "description": "integer zero is invalid", + "data": 0, + "valid": false + }, + { + "description": "float zero is invalid", + "data": 0.0, + "valid": false + } + ] + }, + { + "description": "const with true does not match 1", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": true + }, + "tests": [ + { + "description": "true is valid", + "data": true, + "valid": true + }, + { + "description": "integer one is invalid", + "data": 1, + "valid": false + }, + { + "description": "float one is invalid", + "data": 1.0, + "valid": false + } + ] + }, + { + "description": "const with [false] does not match [0]", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": [ + false + ] + }, + "tests": [ + { + "description": "[false] is valid", + "data": [ + false + ], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [ + 0 + ], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [ + 0.0 + ], + "valid": false + } + ] + }, + { + "description": "const with [true] does not match [1]", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": [ + true + ] + }, + "tests": [ + { + "description": "[true] is valid", + "data": [ + true + ], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [ + 1 + ], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [ + 1.0 + ], + "valid": false + } + ] + }, + { + "description": "const with {\"a\": false} does not match {\"a\": 0}", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": { + "a": false + } + }, + "tests": [ + { + "description": "{\"a\": false} is valid", + "data": { + "a": false + }, + "valid": true + }, + { + "description": "{\"a\": 0} is invalid", + "data": { + "a": 0 + }, + "valid": false + }, + { + "description": "{\"a\": 0.0} is invalid", + "data": { + "a": 0.0 + }, + "valid": false + } + ] + }, + { + "description": "const with {\"a\": true} does not match {\"a\": 1}", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": { + "a": true + } + }, + "tests": [ + { + "description": "{\"a\": true} is valid", + "data": { + "a": true + }, + "valid": true + }, + { + "description": "{\"a\": 1} is invalid", + "data": { + "a": 1 + }, + "valid": false + }, + { + "description": "{\"a\": 1.0} is invalid", + "data": { + "a": 1.0 + }, + "valid": false + } + ] + }, + { + "description": "const with 0 does not match other zero-like types", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": 0 + }, + "tests": [ + { + "description": "false is invalid", + "data": false, + "valid": false + }, + { + "description": "integer zero is valid", + "data": 0, + "valid": true + }, + { + "description": "float zero is valid", + "data": 0.0, + "valid": true, + "skip": "conflicting values 0.0 and 0 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + }, + { + "description": "empty string is invalid", + "data": "", + "valid": false + } + ] + }, + { + "description": "const with 1 does not match true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": 1 + }, + "tests": [ + { + "description": "true is invalid", + "data": true, + "valid": false + }, + { + "description": "integer one is valid", + "data": 1, + "valid": true + }, + { + "description": "float one is valid", + "data": 1.0, + "valid": true, + "skip": "conflicting values 1.0 and 1 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + } + ] + }, + { + "description": "const with -2.0 matches integer and float types", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": -2.0 + }, + "tests": [ + { + "description": "integer -2 is valid", + "data": -2, + "valid": true, + "skip": "conflicting values -2 and -2.0 (mismatched types int and float):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "integer 2 is invalid", + "data": 2, + "valid": false + }, + { + "description": "float -2.0 is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float 2.0 is invalid", + "data": 2.0, + "valid": false + }, + { + "description": "float -2.00001 is invalid", + "data": -2.00001, + "valid": false + } + ] + }, + { + "description": "float and integers are equal up to 64-bit representation limits", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": 9007199254740992 + }, + "tests": [ + { + "description": "integer is valid", + "data": 9007199254740992, + "valid": true + }, + { + "description": "integer minus one is invalid", + "data": 9007199254740991, + "valid": false + }, + { + "description": "float is valid", + "data": 9007199254740992.0, + "valid": true, + "skip": "conflicting values 9007199254740992.0 and 9007199254740992 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "float minus one is invalid", + "data": 9007199254740991.0, + "valid": false + } + ] + }, + { + "description": "nul characters in strings", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "const": "hello\u0000there" + }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/contains.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/contains.json new file mode 100644 index 000000000..19c477901 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/contains.json @@ -0,0 +1,240 @@ +[ + { + "description": "contains keyword validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": { + "minimum": 5 + } + }, + "tests": [ + { + "description": "array with item matching schema (5) is valid", + "data": [ + 3, + 4, + 5 + ], + "valid": true + }, + { + "description": "array with item matching schema (6) is valid", + "data": [ + 3, + 4, + 6 + ], + "valid": true + }, + { + "description": "array with two items matching schema (5, 6) is valid", + "data": [ + 3, + 4, + 5, + 6 + ], + "valid": true + }, + { + "description": "array without items matching schema is invalid", + "data": [ + 2, + 3, + 4 + ], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + }, + { + "description": "not array is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "contains keyword with const keyword", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": { + "const": 5 + } + }, + "tests": [ + { + "description": "array with item 5 is valid", + "data": [ + 3, + 4, + 5 + ], + "valid": true + }, + { + "description": "array with two items 5 is valid", + "data": [ + 3, + 4, + 5, + 5 + ], + "valid": true + }, + { + "description": "array without item 5 is invalid", + "data": [ + 1, + 2, + 3, + 4 + ], + "valid": false + } + ] + }, + { + "description": "contains keyword with boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": true + }, + "tests": [ + { + "description": "any non-empty array is valid", + "data": [ + "foo" + ], + "valid": true + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + } + ] + }, + { + "description": "contains keyword with boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": false + }, + "tests": [ + { + "description": "any non-empty array is invalid", + "data": [ + "foo" + ], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + }, + { + "description": "non-arrays are valid", + "data": "contains does not apply to strings", + "valid": true + } + ] + }, + { + "description": "items + contains", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "items": { + "multipleOf": 2 + }, + "contains": { + "multipleOf": 3 + } + }, + "tests": [ + { + "description": "matches items, does not match contains", + "data": [ + 2, + 4, + 8 + ], + "valid": false + }, + { + "description": "does not match items, matches contains", + "data": [ + 3, + 6, + 9 + ], + "valid": false + }, + { + "description": "matches both items and contains", + "data": [ + 6, + 12 + ], + "valid": true + }, + { + "description": "matches neither items nor contains", + "data": [ + 1, + 5 + ], + "valid": false + } + ] + }, + { + "description": "contains with false if subschema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": { + "if": false, + "else": true + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 1 more errors)", + "tests": [ + { + "description": "any non-empty array is valid", + "data": [ + "foo" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "contains with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null items", + "data": [ + null + ], + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/content.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/content.json new file mode 100644 index 000000000..57fb12a6a --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/content.json @@ -0,0 +1,150 @@ +[ + { + "description": "validation of string-encoded content based on media type", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contentMediaType": "application/json" + }, + "tests": [ + { + "description": "a valid JSON document", + "data": "{\"foo\": \"bar\"}", + "valid": true + }, + { + "description": "an invalid JSON document; validates true", + "data": "{:}", + "valid": true + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + }, + { + "description": "validation of binary string-encoding", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contentEncoding": "base64" + }, + "tests": [ + { + "description": "a valid base64 string", + "data": "eyJmb28iOiAiYmFyIn0K", + "valid": true + }, + { + "description": "an invalid base64 string (% is not a valid character); validates true", + "data": "eyJmb28iOi%iYmFyIn0K", + "valid": true + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + }, + { + "description": "validation of binary-encoded media type documents", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contentMediaType": "application/json", + "contentEncoding": "base64" + }, + "tests": [ + { + "description": "a valid base64-encoded JSON document", + "data": "eyJmb28iOiAiYmFyIn0K", + "valid": true + }, + { + "description": "a validly-encoded invalid JSON document; validates true", + "data": "ezp9Cg==", + "valid": true + }, + { + "description": "an invalid base64 string that is valid JSON; validates true", + "data": "{}", + "valid": true + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + }, + { + "description": "validation of binary-encoded media type documents with schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contentMediaType": "application/json", + "contentEncoding": "base64", + "contentSchema": { + "type": "object", + "required": [ + "foo" + ], + "properties": { + "foo": { + "type": "string" + } + } + } + }, + "skip": "extract error: unsupported constraint \"contentSchema\"", + "tests": [ + { + "description": "a valid base64-encoded JSON document", + "data": "eyJmb28iOiAiYmFyIn0K", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "another valid base64-encoded JSON document", + "data": "eyJib28iOiAyMCwgImZvbyI6ICJiYXoifQ==", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid base64-encoded JSON document; validates true", + "data": "eyJib28iOiAyMH0=", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an empty object as a base64-encoded JSON document; validates true", + "data": "e30=", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an empty array as a base64-encoded JSON document", + "data": "W10=", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a validly-encoded invalid JSON document; validates true", + "data": "ezp9Cg==", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid base64 string that is valid JSON; validates true", + "data": "{}", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/default.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/default.json new file mode 100644 index 000000000..6ef8a1b96 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/default.json @@ -0,0 +1,91 @@ +[ + { + "description": "invalid type for default", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": { + "type": "integer", + "default": [] + } + } + }, + "tests": [ + { + "description": "valid when property is specified", + "data": { + "foo": 13 + }, + "valid": true + }, + { + "description": "still valid when the invalid default is used", + "data": {}, + "valid": true + } + ] + }, + { + "description": "invalid string value for default", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "bar": { + "type": "string", + "minLength": 4, + "default": "bad" + } + } + }, + "tests": [ + { + "description": "valid when property is specified", + "data": { + "bar": "good" + }, + "valid": true + }, + { + "description": "still valid when the invalid default is used", + "data": {}, + "valid": true + } + ] + }, + { + "description": "the default keyword does not do anything if the property is missing", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "alpha": { + "type": "number", + "maximum": 3, + "default": 5 + } + } + }, + "tests": [ + { + "description": "an explicit property value is checked against maximum (passing)", + "data": { + "alpha": 1 + }, + "valid": true + }, + { + "description": "an explicit property value is checked against maximum (failing)", + "data": { + "alpha": 5 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "missing properties are not filled in with the default", + "data": {}, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/defs.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/defs.json new file mode 100644 index 000000000..78ec83c54 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/defs.json @@ -0,0 +1,36 @@ +[ + { + "description": "validate definition against metaschema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "https://json-schema.org/draft/2020-12/schema" + }, + "skip": "extract error: cannot compile resulting schema: package \"json-schema.org/draft/2020-12/schema\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "valid definition schema", + "data": { + "$defs": { + "foo": { + "type": "integer" + } + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid definition schema", + "data": { + "$defs": { + "foo": { + "type": 1 + } + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/dependentRequired.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/dependentRequired.json new file mode 100644 index 000000000..4675b88f0 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/dependentRequired.json @@ -0,0 +1,217 @@ +[ + { + "description": "single dependency", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependentRequired": { + "bar": [ + "foo" + ] + } + }, + "skip": "extract error: unsupported constraint \"dependentRequired\"", + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "nondependant", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with dependency", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "missing dependency", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ignores arrays", + "data": [ + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "empty dependents", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependentRequired": { + "bar": [] + } + }, + "skip": "extract error: unsupported constraint \"dependentRequired\"", + "tests": [ + { + "description": "empty object", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "object with one property", + "data": { + "bar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "non-object is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "multiple dependents required", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependentRequired": { + "quux": [ + "foo", + "bar" + ] + } + }, + "skip": "extract error: unsupported constraint \"dependentRequired\"", + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "nondependants", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with dependencies", + "data": { + "foo": 1, + "bar": 2, + "quux": 3 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "missing dependency", + "data": { + "foo": 1, + "quux": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "missing other dependency", + "data": { + "bar": 1, + "quux": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "missing both dependencies", + "data": { + "quux": 1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependentRequired": { + "foo\nbar": [ + "foo\rbar" + ], + "foo\"bar": [ + "foo'bar" + ] + } + }, + "skip": "extract error: unsupported constraint \"dependentRequired\"", + "tests": [ + { + "description": "CRLF", + "data": { + "foo\nbar": 1, + "foo\rbar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "quoted quotes", + "data": { + "foo'bar": 1, + "foo\"bar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "CRLF missing dependent", + "data": { + "foo\nbar": 1, + "foo": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "quoted quotes missing dependent", + "data": { + "foo\"bar": 2 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/dependentSchemas.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/dependentSchemas.json new file mode 100644 index 000000000..09f5a7276 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/dependentSchemas.json @@ -0,0 +1,241 @@ +[ + { + "description": "single dependency", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependentSchemas": { + "bar": { + "properties": { + "foo": { + "type": "integer" + }, + "bar": { + "type": "integer" + } + } + } + } + }, + "skip": "extract error: unsupported constraint \"dependentSchemas\"", + "tests": [ + { + "description": "valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "no dependency", + "data": { + "foo": "quux" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "wrong type", + "data": { + "foo": "quux", + "bar": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "wrong type other", + "data": { + "foo": 2, + "bar": "quux" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "wrong type both", + "data": { + "foo": "quux", + "bar": "quux" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ignores arrays", + "data": [ + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "boolean subschemas", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependentSchemas": { + "foo": true, + "bar": false + } + }, + "skip": "extract error: unsupported constraint \"dependentSchemas\"", + "tests": [ + { + "description": "object with property having schema true is valid", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "object with property having schema false is invalid", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "object with both properties is invalid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependentSchemas": { + "foo\tbar": { + "minProperties": 4 + }, + "foo'bar": { + "required": [ + "foo\"bar" + ] + } + } + }, + "skip": "extract error: unsupported constraint \"dependentSchemas\"", + "tests": [ + { + "description": "quoted tab", + "data": { + "foo\tbar": 1, + "a": 2, + "b": 3, + "c": 4 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "quoted quote", + "data": { + "foo'bar": { + "foo\"bar": 1 + } + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "quoted tab invalid under dependent schema", + "data": { + "foo\tbar": 1, + "a": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "quoted quote invalid under dependent schema", + "data": { + "foo'bar": 1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "dependent subschema incompatible with root", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": {} + }, + "dependentSchemas": { + "foo": { + "properties": { + "bar": {} + }, + "additionalProperties": false + } + } + }, + "skip": "extract error: unsupported constraint \"dependentSchemas\"", + "tests": [ + { + "description": "matches root", + "data": { + "foo": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "matches dependency", + "data": { + "bar": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "matches both", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no dependency", + "data": { + "baz": 1 + }, + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/dynamicRef.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/dynamicRef.json new file mode 100644 index 000000000..719a7e4cf --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/dynamicRef.json @@ -0,0 +1,1008 @@ +[ + { + "description": "A $dynamicRef to a $dynamicAnchor in the same schema resource behaves like a normal $ref to an $anchor", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamicRef-dynamicAnchor-same-schema/root", + "type": "array", + "items": { + "$dynamicRef": "#items" + }, + "$defs": { + "foo": { + "$dynamicAnchor": "items", + "type": "string" + } + } + }, + "skip": "extract error: unsupported constraint \"$dynamicRef\" (and 1 more errors)", + "tests": [ + { + "description": "An array of strings is valid", + "data": [ + "foo", + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "An array containing non-strings is invalid", + "data": [ + "foo", + 42 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "A $dynamicRef to an $anchor in the same schema resource behaves like a normal $ref to an $anchor", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamicRef-anchor-same-schema/root", + "type": "array", + "items": { + "$dynamicRef": "#items" + }, + "$defs": { + "foo": { + "$anchor": "items", + "type": "string" + } + } + }, + "skip": "extract error: unsupported constraint \"$dynamicRef\" (and 1 more errors)", + "tests": [ + { + "description": "An array of strings is valid", + "data": [ + "foo", + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "An array containing non-strings is invalid", + "data": [ + "foo", + 42 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "A $ref to a $dynamicAnchor in the same schema resource behaves like a normal $ref to an $anchor", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/ref-dynamicAnchor-same-schema/root", + "type": "array", + "items": { + "$ref": "#items" + }, + "$defs": { + "foo": { + "$dynamicAnchor": "items", + "type": "string" + } + } + }, + "skip": "extract error: anchors (items) not supported (and 1 more errors)", + "tests": [ + { + "description": "An array of strings is valid", + "data": [ + "foo", + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "An array containing non-strings is invalid", + "data": [ + "foo", + 42 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "A $dynamicRef resolves to the first $dynamicAnchor still in scope that is encountered when the schema is evaluated", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/typical-dynamic-resolution/root", + "$ref": "list", + "$defs": { + "foo": { + "$dynamicAnchor": "items", + "type": "string" + }, + "list": { + "$id": "list", + "type": "array", + "items": { + "$dynamicRef": "#items" + }, + "$defs": { + "items": { + "$comment": "This is only needed to satisfy the bookending requirement", + "$dynamicAnchor": "items" + } + } + } + } + }, + "skip": "extract error: unsupported constraint \"$dynamicAnchor\" (and 2 more errors)", + "tests": [ + { + "description": "An array of strings is valid", + "data": [ + "foo", + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "An array containing non-strings is invalid", + "data": [ + "foo", + 42 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "A $dynamicRef without anchor in fragment behaves identical to $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamicRef-without-anchor/root", + "$ref": "list", + "$defs": { + "foo": { + "$dynamicAnchor": "items", + "type": "string" + }, + "list": { + "$id": "list", + "type": "array", + "items": { + "$dynamicRef": "#/$defs/items" + }, + "$defs": { + "items": { + "$comment": "This is only needed to satisfy the bookending requirement", + "$dynamicAnchor": "items", + "type": "number" + } + } + } + } + }, + "skip": "extract error: unsupported constraint \"$dynamicAnchor\" (and 2 more errors)", + "tests": [ + { + "description": "An array of strings is invalid", + "data": [ + "foo", + "bar" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "An array of numbers is valid", + "data": [ + 24, + 42 + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "A $dynamicRef with intermediate scopes that don't include a matching $dynamicAnchor does not affect dynamic scope resolution", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamic-resolution-with-intermediate-scopes/root", + "$ref": "intermediate-scope", + "$defs": { + "foo": { + "$dynamicAnchor": "items", + "type": "string" + }, + "intermediate-scope": { + "$id": "intermediate-scope", + "$ref": "list" + }, + "list": { + "$id": "list", + "type": "array", + "items": { + "$dynamicRef": "#items" + }, + "$defs": { + "items": { + "$comment": "This is only needed to satisfy the bookending requirement", + "$dynamicAnchor": "items" + } + } + } + } + }, + "skip": "extract error: unsupported constraint \"$dynamicAnchor\" (and 2 more errors)", + "tests": [ + { + "description": "An array of strings is valid", + "data": [ + "foo", + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "An array containing non-strings is invalid", + "data": [ + "foo", + 42 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "An $anchor with the same name as a $dynamicAnchor is not used for dynamic scope resolution", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamic-resolution-ignores-anchors/root", + "$ref": "list", + "$defs": { + "foo": { + "$anchor": "items", + "type": "string" + }, + "list": { + "$id": "list", + "type": "array", + "items": { + "$dynamicRef": "#items" + }, + "$defs": { + "items": { + "$comment": "This is only needed to satisfy the bookending requirement", + "$dynamicAnchor": "items" + } + } + } + } + }, + "skip": "extract error: unsupported constraint \"$anchor\" (and 2 more errors)", + "tests": [ + { + "description": "Any array is valid", + "data": [ + "foo", + 42 + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "A $dynamicRef without a matching $dynamicAnchor in the same schema resource behaves like a normal $ref to $anchor", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamic-resolution-without-bookend/root", + "$ref": "list", + "$defs": { + "foo": { + "$dynamicAnchor": "items", + "type": "string" + }, + "list": { + "$id": "list", + "type": "array", + "items": { + "$dynamicRef": "#items" + }, + "$defs": { + "items": { + "$comment": "This is only needed to give the reference somewhere to resolve to when it behaves like $ref", + "$anchor": "items" + } + } + } + } + }, + "skip": "extract error: unsupported constraint \"$dynamicAnchor\" (and 2 more errors)", + "tests": [ + { + "description": "Any array is valid", + "data": [ + "foo", + 42 + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "A $dynamicRef with a non-matching $dynamicAnchor in the same schema resource behaves like a normal $ref to $anchor", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/unmatched-dynamic-anchor/root", + "$ref": "list", + "$defs": { + "foo": { + "$dynamicAnchor": "items", + "type": "string" + }, + "list": { + "$id": "list", + "type": "array", + "items": { + "$dynamicRef": "#items" + }, + "$defs": { + "items": { + "$comment": "This is only needed to give the reference somewhere to resolve to when it behaves like $ref", + "$anchor": "items", + "$dynamicAnchor": "foo" + } + } + } + } + }, + "skip": "extract error: unsupported constraint \"$dynamicAnchor\" (and 3 more errors)", + "tests": [ + { + "description": "Any array is valid", + "data": [ + "foo", + 42 + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "A $dynamicRef that initially resolves to a schema with a matching $dynamicAnchor resolves to the first $dynamicAnchor in the dynamic scope", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/relative-dynamic-reference/root", + "$dynamicAnchor": "meta", + "type": "object", + "properties": { + "foo": { + "const": "pass" + } + }, + "$ref": "extended", + "$defs": { + "extended": { + "$id": "extended", + "$dynamicAnchor": "meta", + "type": "object", + "properties": { + "bar": { + "$ref": "bar" + } + } + }, + "bar": { + "$id": "bar", + "type": "object", + "properties": { + "baz": { + "$dynamicRef": "extended#meta" + } + } + } + } + }, + "skip": "extract error: unsupported constraint \"$dynamicAnchor\" (and 2 more errors)", + "tests": [ + { + "description": "The recursive part is valid against the root", + "data": { + "foo": "pass", + "bar": { + "baz": { + "foo": "pass" + } + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "The recursive part is not valid against the root", + "data": { + "foo": "pass", + "bar": { + "baz": { + "foo": "fail" + } + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "A $dynamicRef that initially resolves to a schema without a matching $dynamicAnchor behaves like a normal $ref to $anchor", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/relative-dynamic-reference-without-bookend/root", + "$dynamicAnchor": "meta", + "type": "object", + "properties": { + "foo": { + "const": "pass" + } + }, + "$ref": "extended", + "$defs": { + "extended": { + "$id": "extended", + "$anchor": "meta", + "type": "object", + "properties": { + "bar": { + "$ref": "bar" + } + } + }, + "bar": { + "$id": "bar", + "type": "object", + "properties": { + "baz": { + "$dynamicRef": "extended#meta" + } + } + } + } + }, + "skip": "extract error: unsupported constraint \"$dynamicAnchor\" (and 2 more errors)", + "tests": [ + { + "description": "The recursive part doesn't need to validate against the root", + "data": { + "foo": "pass", + "bar": { + "baz": { + "foo": "fail" + } + } + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "multiple dynamic paths to the $dynamicRef keyword", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamic-ref-with-multiple-paths/main", + "if": { + "properties": { + "kindOfList": { + "const": "numbers" + } + }, + "required": [ + "kindOfList" + ] + }, + "then": { + "$ref": "numberList" + }, + "else": { + "$ref": "stringList" + }, + "$defs": { + "genericList": { + "$id": "genericList", + "properties": { + "list": { + "items": { + "$dynamicRef": "#itemType" + } + } + }, + "$defs": { + "defaultItemType": { + "$comment": "Only needed to satisfy bookending requirement", + "$dynamicAnchor": "itemType" + } + } + }, + "numberList": { + "$id": "numberList", + "$defs": { + "itemType": { + "$dynamicAnchor": "itemType", + "type": "number" + } + }, + "$ref": "genericList" + }, + "stringList": { + "$id": "stringList", + "$defs": { + "itemType": { + "$dynamicAnchor": "itemType", + "type": "string" + } + }, + "$ref": "genericList" + } + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 6 more errors)", + "tests": [ + { + "description": "number list with number values", + "data": { + "kindOfList": "numbers", + "list": [ + 1.1 + ] + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "number list with string values", + "data": { + "kindOfList": "numbers", + "list": [ + "foo" + ] + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string list with number values", + "data": { + "kindOfList": "strings", + "list": [ + 1.1 + ] + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string list with string values", + "data": { + "kindOfList": "strings", + "list": [ + "foo" + ] + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "after leaving a dynamic scope, it is not used by a $dynamicRef", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamic-ref-leaving-dynamic-scope/main", + "if": { + "$id": "first_scope", + "$defs": { + "thingy": { + "$comment": "this is first_scope#thingy", + "$dynamicAnchor": "thingy", + "type": "number" + } + } + }, + "then": { + "$id": "second_scope", + "$ref": "start", + "$defs": { + "thingy": { + "$comment": "this is second_scope#thingy, the final destination of the $dynamicRef", + "$dynamicAnchor": "thingy", + "type": "null" + } + } + }, + "$defs": { + "start": { + "$comment": "this is the landing spot from $ref", + "$id": "start", + "$dynamicRef": "inner_scope#thingy" + }, + "thingy": { + "$comment": "this is the first stop for the $dynamicRef", + "$id": "inner_scope", + "$dynamicAnchor": "thingy", + "type": "string" + } + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 3 more errors)", + "tests": [ + { + "description": "string matches /$defs/thingy, but the $dynamicRef does not stop here", + "data": "a string", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "first_scope is not in dynamic scope for the $dynamicRef", + "data": 42, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "/then/$defs/thingy is the final stop for the $dynamicRef", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "strict-tree schema, guards against misspelled properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/strict-tree.json", + "$dynamicAnchor": "node", + "$ref": "tree.json", + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"$dynamicAnchor\" (and 1 more errors)", + "tests": [ + { + "description": "instance with misspelled field", + "data": { + "children": [ + { + "daat": 1 + } + ] + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "instance with correct field", + "data": { + "children": [ + { + "data": 1 + } + ] + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "tests for implementation dynamic anchor and reference link", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/strict-extendible.json", + "$ref": "extendible-dynamic-ref.json", + "$defs": { + "elements": { + "$dynamicAnchor": "elements", + "properties": { + "a": true + }, + "required": [ + "a" + ], + "additionalProperties": false + } + } + }, + "skip": "extract error: unsupported constraint \"$dynamicAnchor\"", + "tests": [ + { + "description": "incorrect parent schema", + "data": { + "a": true + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "incorrect extended schema", + "data": { + "elements": [ + { + "b": 1 + } + ] + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "correct extended schema", + "data": { + "elements": [ + { + "a": 1 + } + ] + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$ref and $dynamicAnchor are independent of order - $defs first", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/strict-extendible-allof-defs-first.json", + "allOf": [ + { + "$ref": "extendible-dynamic-ref.json" + }, + { + "$defs": { + "elements": { + "$dynamicAnchor": "elements", + "properties": { + "a": true + }, + "required": [ + "a" + ], + "additionalProperties": false + } + } + } + ] + }, + "skip": "extract error: unsupported constraint \"$dynamicAnchor\"", + "tests": [ + { + "description": "incorrect parent schema", + "data": { + "a": true + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "incorrect extended schema", + "data": { + "elements": [ + { + "b": 1 + } + ] + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "correct extended schema", + "data": { + "elements": [ + { + "a": 1 + } + ] + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$ref and $dynamicAnchor are independent of order - $ref first", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/strict-extendible-allof-ref-first.json", + "allOf": [ + { + "$defs": { + "elements": { + "$dynamicAnchor": "elements", + "properties": { + "a": true + }, + "required": [ + "a" + ], + "additionalProperties": false + } + } + }, + { + "$ref": "extendible-dynamic-ref.json" + } + ] + }, + "skip": "extract error: unsupported constraint \"$dynamicAnchor\"", + "tests": [ + { + "description": "incorrect parent schema", + "data": { + "a": true + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "incorrect extended schema", + "data": { + "elements": [ + { + "b": 1 + } + ] + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "correct extended schema", + "data": { + "elements": [ + { + "a": 1 + } + ] + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$ref to $dynamicRef finds detached $dynamicAnchor", + "schema": { + "$ref": "http://localhost:1234/draft2020-12/detached-dynamicref.json#/$defs/foo" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2020-12/detached-dynamicref.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$dynamicRef points to a boolean schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "true": true, + "false": false + }, + "properties": { + "true": { + "$dynamicRef": "#/$defs/true" + }, + "false": { + "$dynamicRef": "#/$defs/false" + } + } + }, + "skip": "extract error: unsupported constraint \"$dynamicRef\" (and 1 more errors)", + "tests": [ + { + "description": "follow $dynamicRef to a true schema", + "data": { + "true": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "follow $dynamicRef to a false schema", + "data": { + "false": 1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$dynamicRef skips over intermediate resources - direct reference", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/main", + "type": "object", + "properties": { + "bar-item": { + "$ref": "item" + } + }, + "$defs": { + "bar": { + "$id": "bar", + "type": "array", + "items": { + "$ref": "item" + }, + "$defs": { + "item": { + "$id": "item", + "type": "object", + "properties": { + "content": { + "$dynamicRef": "#content" + } + }, + "$defs": { + "defaultContent": { + "$dynamicAnchor": "content", + "type": "integer" + } + } + }, + "content": { + "$dynamicAnchor": "content", + "type": "string" + } + } + } + } + }, + "skip": "extract error: unsupported constraint \"$dynamicRef\" (and 2 more errors)", + "tests": [ + { + "description": "integer property passes", + "data": { + "bar-item": { + "content": 42 + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string property fails", + "data": { + "bar-item": { + "content": "value" + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/enum.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/enum.json new file mode 100644 index 000000000..946334c4b --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/enum.json @@ -0,0 +1,463 @@ +[ + { + "description": "simple enum validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [ + 1, + 2, + 3 + ] + }, + "tests": [ + { + "description": "one of the enum is valid", + "data": 1, + "valid": true + }, + { + "description": "something else is invalid", + "data": 4, + "valid": false + } + ] + }, + { + "description": "heterogeneous enum validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [ + 6, + "foo", + [], + true, + { + "foo": 12 + } + ] + }, + "tests": [ + { + "description": "one of the enum is valid", + "data": [], + "valid": true + }, + { + "description": "something else is invalid", + "data": null, + "valid": false + }, + { + "description": "objects are deep compared", + "data": { + "foo": false + }, + "valid": false + }, + { + "description": "valid object matches", + "data": { + "foo": 12 + }, + "valid": true + }, + { + "description": "extra properties in object is invalid", + "data": { + "foo": 12, + "boo": 42 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "heterogeneous enum-with-null validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [ + 6, + null + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "number is valid", + "data": 6, + "valid": true + }, + { + "description": "something else is invalid", + "data": "test", + "valid": false + } + ] + }, + { + "description": "enums in properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { + "enum": [ + "foo" + ] + }, + "bar": { + "enum": [ + "bar" + ] + } + }, + "required": [ + "bar" + ] + }, + "tests": [ + { + "description": "both properties are valid", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "wrong foo value", + "data": { + "foo": "foot", + "bar": "bar" + }, + "valid": false + }, + { + "description": "wrong bar value", + "data": { + "foo": "foo", + "bar": "bart" + }, + "valid": false + }, + { + "description": "missing optional property is valid", + "data": { + "bar": "bar" + }, + "valid": true + }, + { + "description": "missing required property is invalid", + "data": { + "foo": "foo" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "missing all properties is invalid", + "data": {}, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "enum with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [ + "foo\nbar", + "foo\rbar" + ] + }, + "tests": [ + { + "description": "member 1 is valid", + "data": "foo\nbar", + "valid": true + }, + { + "description": "member 2 is valid", + "data": "foo\rbar", + "valid": true + }, + { + "description": "another string is invalid", + "data": "abc", + "valid": false + } + ] + }, + { + "description": "enum with false does not match 0", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [ + false + ] + }, + "tests": [ + { + "description": "false is valid", + "data": false, + "valid": true + }, + { + "description": "integer zero is invalid", + "data": 0, + "valid": false + }, + { + "description": "float zero is invalid", + "data": 0.0, + "valid": false + } + ] + }, + { + "description": "enum with [false] does not match [0]", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [ + [ + false + ] + ] + }, + "tests": [ + { + "description": "[false] is valid", + "data": [ + false + ], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [ + 0 + ], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [ + 0.0 + ], + "valid": false + } + ] + }, + { + "description": "enum with true does not match 1", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [ + true + ] + }, + "tests": [ + { + "description": "true is valid", + "data": true, + "valid": true + }, + { + "description": "integer one is invalid", + "data": 1, + "valid": false + }, + { + "description": "float one is invalid", + "data": 1.0, + "valid": false + } + ] + }, + { + "description": "enum with [true] does not match [1]", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [ + [ + true + ] + ] + }, + "tests": [ + { + "description": "[true] is valid", + "data": [ + true + ], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [ + 1 + ], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [ + 1.0 + ], + "valid": false + } + ] + }, + { + "description": "enum with 0 does not match false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [ + 0 + ] + }, + "tests": [ + { + "description": "false is invalid", + "data": false, + "valid": false + }, + { + "description": "integer zero is valid", + "data": 0, + "valid": true + }, + { + "description": "float zero is valid", + "data": 0.0, + "valid": true, + "skip": "conflicting values 0.0 and 0 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + } + ] + }, + { + "description": "enum with [0] does not match [false]", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [ + [ + 0 + ] + ] + }, + "tests": [ + { + "description": "[false] is invalid", + "data": [ + false + ], + "valid": false + }, + { + "description": "[0] is valid", + "data": [ + 0 + ], + "valid": true + }, + { + "description": "[0.0] is valid", + "data": [ + 0.0 + ], + "valid": true, + "skip": "0: conflicting values 0.0 and 0 (mismatched types float and int):\n generated.cue:2:1\n generated.cue:2:2\n instance.json:1:2\n" + } + ] + }, + { + "description": "enum with 1 does not match true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [ + 1 + ] + }, + "tests": [ + { + "description": "true is invalid", + "data": true, + "valid": false + }, + { + "description": "integer one is valid", + "data": 1, + "valid": true + }, + { + "description": "float one is valid", + "data": 1.0, + "valid": true, + "skip": "conflicting values 1.0 and 1 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + } + ] + }, + { + "description": "enum with [1] does not match [true]", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [ + [ + 1 + ] + ] + }, + "tests": [ + { + "description": "[true] is invalid", + "data": [ + true + ], + "valid": false + }, + { + "description": "[1] is valid", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "[1.0] is valid", + "data": [ + 1.0 + ], + "valid": true, + "skip": "0: conflicting values 1.0 and 1 (mismatched types float and int):\n generated.cue:2:1\n generated.cue:2:2\n instance.json:1:2\n" + } + ] + }, + { + "description": "nul characters in strings", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "enum": [ + "hello\u0000there" + ] + }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/exclusiveMaximum.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/exclusiveMaximum.json new file mode 100644 index 000000000..7e57fcffa --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/exclusiveMaximum.json @@ -0,0 +1,31 @@ +[ + { + "description": "exclusiveMaximum validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "exclusiveMaximum": 3.0 + }, + "tests": [ + { + "description": "below the exclusiveMaximum is valid", + "data": 2.2, + "valid": true + }, + { + "description": "boundary point is invalid", + "data": 3.0, + "valid": false + }, + { + "description": "above the exclusiveMaximum is invalid", + "data": 3.5, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/exclusiveMinimum.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/exclusiveMinimum.json new file mode 100644 index 000000000..b815539ae --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/exclusiveMinimum.json @@ -0,0 +1,31 @@ +[ + { + "description": "exclusiveMinimum validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "exclusiveMinimum": 1.1 + }, + "tests": [ + { + "description": "above the exclusiveMinimum is valid", + "data": 1.2, + "valid": true + }, + { + "description": "boundary point is invalid", + "data": 1.1, + "valid": false + }, + { + "description": "below the exclusiveMinimum is invalid", + "data": 0.6, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/format.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/format.json new file mode 100644 index 000000000..83c2cab39 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/format.json @@ -0,0 +1,990 @@ +[ + { + "description": "email format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "email" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid email string is only an annotation by default", + "data": "2962", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "idn-email format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "idn-email" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid idn-email string is only an annotation by default", + "data": "2962", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "regex format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "regex" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid regex string is only an annotation by default", + "data": "^(abc]", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ipv4 format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "ipv4" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid ipv4 string is only an annotation by default", + "data": "127.0.0.0.1", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ipv6 format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "ipv6" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid ipv6 string is only an annotation by default", + "data": "12345::", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "idn-hostname format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "idn-hostname" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid idn-hostname string is only an annotation by default", + "data": "〮실례.테스트", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "hostname format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "hostname" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid hostname string is only an annotation by default", + "data": "-a-host-name-that-starts-with--", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "date format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "date" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid date string is only an annotation by default", + "data": "06/19/1963", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "date-time format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "date-time" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid date-time string is only an annotation by default", + "data": "1990-02-31T15:59:60.123-08:00", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "time format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "time" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid time string is only an annotation by default", + "data": "08:30:06 PST", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "json-pointer format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "json-pointer" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid json-pointer string is only an annotation by default", + "data": "/foo/bar~", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "relative-json-pointer format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "relative-json-pointer" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid relative-json-pointer string is only an annotation by default", + "data": "/foo/bar", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "iri format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "iri" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid iri string is only an annotation by default", + "data": "http://2001:0db8:85a3:0000:0000:8a2e:0370:7334", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "iri-reference format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "iri-reference" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid iri-reference string is only an annotation by default", + "data": "\\\\WINDOWS\\filëßåré", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "uri format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "uri" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid uri string is only an annotation by default", + "data": "//foo.bar/?baz=qux#quux", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "uri-reference format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "uri-reference" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid uri-reference string is only an annotation by default", + "data": "\\\\WINDOWS\\fileshare", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "uri-template format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "uri-template" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid uri-template string is only an annotation by default", + "data": "http://example.com/dictionary/{term:1}/{term", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "uuid format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "uuid" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid uuid string is only an annotation by default", + "data": "2eb8aa08-aa98-11ea-b4aa-73b441d1638", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "duration format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "duration" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid duration string is only an annotation by default", + "data": "PT1D", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/if-then-else.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/if-then-else.json new file mode 100644 index 000000000..feace0fa0 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/if-then-else.json @@ -0,0 +1,318 @@ +[ + { + "description": "ignore if without then or else", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "const": 0 + } + }, + "skip": "extract error: unsupported constraint \"if\"", + "tests": [ + { + "description": "valid when valid against lone if", + "data": 0, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid when invalid against lone if", + "data": "hello", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ignore then without if", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "then": { + "const": 0 + } + }, + "skip": "extract error: unsupported constraint \"then\"", + "tests": [ + { + "description": "valid when valid against lone then", + "data": 0, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid when invalid against lone then", + "data": "hello", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ignore else without if", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "else": { + "const": 0 + } + }, + "skip": "extract error: unsupported constraint \"else\"", + "tests": [ + { + "description": "valid when valid against lone else", + "data": 0, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid when invalid against lone else", + "data": "hello", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "if and then without else", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "exclusiveMaximum": 0 + }, + "then": { + "minimum": -10 + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 1 more errors)", + "tests": [ + { + "description": "valid through then", + "data": -1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid through then", + "data": -100, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid when if test fails", + "data": 3, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "if and else without then", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "exclusiveMaximum": 0 + }, + "else": { + "multipleOf": 2 + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 1 more errors)", + "tests": [ + { + "description": "valid when if test passes", + "data": -1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid through else", + "data": 4, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid through else", + "data": 3, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "validate against correct branch, then vs else", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "exclusiveMaximum": 0 + }, + "then": { + "minimum": -10 + }, + "else": { + "multipleOf": 2 + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 2 more errors)", + "tests": [ + { + "description": "valid through then", + "data": -1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid through then", + "data": -100, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid through else", + "data": 4, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid through else", + "data": 3, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "non-interference across combined schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "if": { + "exclusiveMaximum": 0 + } + }, + { + "then": { + "minimum": -10 + } + }, + { + "else": { + "multipleOf": 2 + } + } + ] + }, + "skip": "extract error: unsupported constraint \"if\" (and 2 more errors)", + "tests": [ + { + "description": "valid, but would have been invalid through then", + "data": -100, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid, but would have been invalid through else", + "data": 3, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "if with boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": true, + "then": { + "const": "then" + }, + "else": { + "const": "else" + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 2 more errors)", + "tests": [ + { + "description": "boolean schema true in if always chooses the then path (valid)", + "data": "then", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "boolean schema true in if always chooses the then path (invalid)", + "data": "else", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "if with boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": false, + "then": { + "const": "then" + }, + "else": { + "const": "else" + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 2 more errors)", + "tests": [ + { + "description": "boolean schema false in if always chooses the else path (invalid)", + "data": "then", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean schema false in if always chooses the else path (valid)", + "data": "else", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "if appears at the end when serialized (keyword processing sequence)", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "then": { + "const": "yes" + }, + "else": { + "const": "other" + }, + "if": { + "maxLength": 4 + } + }, + "skip": "extract error: unsupported constraint \"then\" (and 2 more errors)", + "tests": [ + { + "description": "yes redirects to then and passes", + "data": "yes", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "other redirects to else and passes", + "data": "other", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "no redirects to then and fails", + "data": "no", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid redirects to else and fails", + "data": "invalid", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/infinite-loop-detection.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/infinite-loop-detection.json new file mode 100644 index 000000000..cb60e1864 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/infinite-loop-detection.json @@ -0,0 +1,43 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "int": { + "type": "integer" + } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/$defs/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/$defs/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "failing case", + "data": { + "foo": "a string" + }, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/items.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/items.json new file mode 100644 index 000000000..d96420926 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/items.json @@ -0,0 +1,615 @@ +[ + { + "description": "a schema given for items", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "items": { + "type": "integer" + } + }, + "tests": [ + { + "description": "valid items", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "wrong type of items", + "data": [ + 1, + "x" + ], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "JavaScript pseudo-array is valid", + "data": { + "0": "invalid", + "length": 1 + }, + "valid": true + } + ] + }, + { + "description": "items with boolean schema (true)", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "items": true + }, + "skip": "extract error: value of \"items\" must be an object or array", + "tests": [ + { + "description": "any array is valid", + "data": [ + 1, + "foo", + true + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "empty array is valid", + "data": [], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "items with boolean schema (false)", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "items": false + }, + "skip": "extract error: value of \"items\" must be an object or array", + "tests": [ + { + "description": "any non-empty array is invalid", + "data": [ + 1, + "foo", + true + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty array is valid", + "data": [], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "items and subitems", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "item": { + "type": "array", + "items": false, + "prefixItems": [ + { + "$ref": "#/$defs/sub-item" + }, + { + "$ref": "#/$defs/sub-item" + } + ] + }, + "sub-item": { + "type": "object", + "required": [ + "foo" + ] + } + }, + "type": "array", + "items": false, + "prefixItems": [ + { + "$ref": "#/$defs/item" + }, + { + "$ref": "#/$defs/item" + }, + { + "$ref": "#/$defs/item" + } + ] + }, + "skip": "extract error: unsupported constraint \"prefixItems\" (and 3 more errors)", + "tests": [ + { + "description": "valid items", + "data": [ + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too many items", + "data": [ + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "too many sub-items", + "data": [ + [ + { + "foo": null + }, + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "wrong item", + "data": [ + { + "foo": null + }, + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "wrong sub-item", + "data": [ + [ + {}, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "fewer items is valid", + "data": [ + [ + { + "foo": null + } + ], + [ + { + "foo": null + } + ] + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "nested items", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "array", + "items": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "number" + } + } + } + } + }, + "tests": [ + { + "description": "valid nested array", + "data": [ + [ + [ + [ + 1 + ] + ], + [ + [ + 2 + ], + [ + 3 + ] + ] + ], + [ + [ + [ + 4 + ], + [ + 5 + ], + [ + 6 + ] + ] + ] + ], + "valid": true + }, + { + "description": "nested array with invalid type", + "data": [ + [ + [ + [ + "1" + ] + ], + [ + [ + 2 + ], + [ + 3 + ] + ] + ], + [ + [ + [ + 4 + ], + [ + 5 + ], + [ + 6 + ] + ] + ] + ], + "valid": false + }, + { + "description": "not deep enough", + "data": [ + [ + [ + 1 + ], + [ + 2 + ], + [ + 3 + ] + ], + [ + [ + 4 + ], + [ + 5 + ], + [ + 6 + ] + ] + ], + "valid": false + } + ] + }, + { + "description": "prefixItems with no additional items allowed", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + {}, + {}, + {} + ], + "items": false + }, + "skip": "extract error: unsupported constraint \"prefixItems\" (and 1 more errors)", + "tests": [ + { + "description": "empty array", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "fewer number of items present (1)", + "data": [ + 1 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "fewer number of items present (2)", + "data": [ + 1, + 2 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "equal number of items present", + "data": [ + 1, + 2, + 3 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "additional items are not permitted", + "data": [ + 1, + 2, + 3, + 4 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "items does not look in applicators, valid case", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "prefixItems": [ + { + "minimum": 3 + } + ] + } + ], + "items": { + "minimum": 5 + } + }, + "skip": "extract error: unsupported constraint \"prefixItems\"", + "tests": [ + { + "description": "prefixItems in allOf does not constrain items, invalid case", + "data": [ + 3, + 5 + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "prefixItems in allOf does not constrain items, valid case", + "data": [ + 5, + 5 + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "prefixItems validation adjusts the starting index for items", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { + "type": "string" + } + ], + "items": { + "type": "integer" + } + }, + "skip": "extract error: unsupported constraint \"prefixItems\"", + "tests": [ + { + "description": "valid items", + "data": [ + "x", + 2, + 3 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "wrong type of second item", + "data": [ + "x", + "y" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "items with heterogeneous array", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + {} + ], + "items": false + }, + "skip": "extract error: unsupported constraint \"prefixItems\" (and 1 more errors)", + "tests": [ + { + "description": "heterogeneous invalid instance", + "data": [ + "foo", + "bar", + 37 + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid instance", + "data": [ + null + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "items with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "items": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ + null + ], + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/maxContains.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/maxContains.json new file mode 100644 index 000000000..ec25c3a3c --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/maxContains.json @@ -0,0 +1,141 @@ +[ + { + "description": "maxContains without contains is ignored", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maxContains": 1 + }, + "tests": [ + { + "description": "one item valid against lone maxContains", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "two items still valid against lone maxContains", + "data": [ + 1, + 2 + ], + "valid": true + } + ] + }, + { + "description": "maxContains with contains", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": { + "const": 1 + }, + "maxContains": 1 + }, + "tests": [ + { + "description": "empty data", + "data": [], + "valid": false + }, + { + "description": "all elements match, valid maxContains", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "all elements match, invalid maxContains", + "data": [ + 1, + 1 + ], + "valid": false + }, + { + "description": "some elements match, valid maxContains", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "some elements match, invalid maxContains", + "data": [ + 1, + 2, + 1 + ], + "valid": false + } + ] + }, + { + "description": "maxContains with contains, value with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": { + "const": 1 + }, + "maxContains": 1.0 + }, + "skip": "extract error: value of \"maxContains\" must be a non-negative integer value", + "tests": [ + { + "description": "one element matches, valid maxContains", + "data": [ + 1 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too many elements match, invalid maxContains", + "data": [ + 1, + 1 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "minContains \u003c maxContains", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": { + "const": 1 + }, + "minContains": 1, + "maxContains": 3 + }, + "tests": [ + { + "description": "actual \u003c minContains \u003c maxContains", + "data": [], + "valid": false + }, + { + "description": "minContains \u003c actual \u003c maxContains", + "data": [ + 1, + 1 + ], + "valid": true + }, + { + "description": "minContains \u003c maxContains \u003c actual", + "data": [ + 1, + 1, + 1, + 1 + ], + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/maxItems.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/maxItems.json new file mode 100644 index 000000000..349440f11 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/maxItems.json @@ -0,0 +1,68 @@ +[ + { + "description": "maxItems validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maxItems": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "exact length is valid", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "too long is invalid", + "data": [ + 1, + 2, + 3 + ], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": "foobar", + "valid": true + } + ] + }, + { + "description": "maxItems validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maxItems": 2.0 + }, + "skip": "extract error: invalid uint", + "tests": [ + { + "description": "shorter is valid", + "data": [ + 1 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too long is invalid", + "data": [ + 1, + 2, + 3 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/maxLength.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/maxLength.json new file mode 100644 index 000000000..1b2cfffd6 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/maxLength.json @@ -0,0 +1,56 @@ +[ + { + "description": "maxLength validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maxLength": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true + }, + { + "description": "exact length is valid", + "data": "fo", + "valid": true + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + }, + { + "description": "two graphemes is long enough", + "data": "💩💩", + "valid": true + } + ] + }, + { + "description": "maxLength validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maxLength": 2.0 + }, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values \"f\" and [...] (mismatched types string and list):\n generated.cue:4:1\n generated.cue:4:48\n instance.json:1:1\nconflicting values \"f\" and bool (mismatched types string and bool):\n generated.cue:4:1\n generated.cue:4:8\n instance.json:1:1\nconflicting values \"f\" and null (mismatched types string and null):\n generated.cue:4:1\n instance.json:1:1\nconflicting values \"f\" and number (mismatched types string and number):\n generated.cue:4:1\n generated.cue:4:15\n instance.json:1:1\nconflicting values \"f\" and {...} (mismatched types string and struct):\n generated.cue:4:1\n generated.cue:4:56\n instance.json:1:1\ncannot use 2.0 (type float) as int in argument 2 to strings.MaxRunes:\n generated.cue:4:41\n" + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/maxProperties.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/maxProperties.json new file mode 100644 index 000000000..cfa72b6b6 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/maxProperties.json @@ -0,0 +1,103 @@ +[ + { + "description": "maxProperties validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maxProperties": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "exact length is valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "too long is invalid", + "data": { + "foo": 1, + "bar": 2, + "baz": 3 + }, + "valid": false + }, + { + "description": "ignores arrays", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "maxProperties validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maxProperties": 2.0 + }, + "skip": "extract error: invalid uint", + "tests": [ + { + "description": "shorter is valid", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too long is invalid", + "data": { + "foo": 1, + "bar": 2, + "baz": 3 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "maxProperties = 0 means the object is empty", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maxProperties": 0 + }, + "tests": [ + { + "description": "no properties is valid", + "data": {}, + "valid": true + }, + { + "description": "one property is invalid", + "data": { + "foo": 1 + }, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/maximum.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/maximum.json new file mode 100644 index 000000000..d87282b52 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/maximum.json @@ -0,0 +1,60 @@ +[ + { + "description": "maximum validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maximum": 3.0 + }, + "tests": [ + { + "description": "below the maximum is valid", + "data": 2.6, + "valid": true + }, + { + "description": "boundary point is valid", + "data": 3.0, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 3.5, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + }, + { + "description": "maximum validation with unsigned integer", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maximum": 300 + }, + "tests": [ + { + "description": "below the maximum is invalid", + "data": 299.97, + "valid": true + }, + { + "description": "boundary point integer is valid", + "data": 300, + "valid": true + }, + { + "description": "boundary point float is valid", + "data": 300.00, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 300.5, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/minContains.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/minContains.json new file mode 100644 index 000000000..b6a4316b0 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/minContains.json @@ -0,0 +1,299 @@ +[ + { + "description": "minContains without contains is ignored", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "minContains": 1 + }, + "tests": [ + { + "description": "one item valid against lone minContains", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "zero items still valid against lone minContains", + "data": [], + "valid": true + } + ] + }, + { + "description": "minContains=1 with contains", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": { + "const": 1 + }, + "minContains": 1 + }, + "tests": [ + { + "description": "empty data", + "data": [], + "valid": false + }, + { + "description": "no elements match", + "data": [ + 2 + ], + "valid": false + }, + { + "description": "single element matches, valid minContains", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "some elements match, valid minContains", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "all elements match, valid minContains", + "data": [ + 1, + 1 + ], + "valid": true + } + ] + }, + { + "description": "minContains=2 with contains", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": { + "const": 1 + }, + "minContains": 2 + }, + "tests": [ + { + "description": "empty data", + "data": [], + "valid": false + }, + { + "description": "all elements match, invalid minContains", + "data": [ + 1 + ], + "valid": false + }, + { + "description": "some elements match, invalid minContains", + "data": [ + 1, + 2 + ], + "valid": false + }, + { + "description": "all elements match, valid minContains (exactly as needed)", + "data": [ + 1, + 1 + ], + "valid": true + }, + { + "description": "all elements match, valid minContains (more than needed)", + "data": [ + 1, + 1, + 1 + ], + "valid": true + }, + { + "description": "some elements match, valid minContains", + "data": [ + 1, + 2, + 1 + ], + "valid": true + } + ] + }, + { + "description": "minContains=2 with contains with a decimal value", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": { + "const": 1 + }, + "minContains": 2.0 + }, + "skip": "extract error: value of \"minContains\" must be a non-negative integer value", + "tests": [ + { + "description": "one element matches, invalid minContains", + "data": [ + 1 + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "both elements match, valid minContains", + "data": [ + 1, + 1 + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "maxContains = minContains", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": { + "const": 1 + }, + "maxContains": 2, + "minContains": 2 + }, + "tests": [ + { + "description": "empty data", + "data": [], + "valid": false + }, + { + "description": "all elements match, invalid minContains", + "data": [ + 1 + ], + "valid": false + }, + { + "description": "all elements match, invalid maxContains", + "data": [ + 1, + 1, + 1 + ], + "valid": false + }, + { + "description": "all elements match, valid maxContains and minContains", + "data": [ + 1, + 1 + ], + "valid": true + } + ] + }, + { + "description": "maxContains \u003c minContains", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": { + "const": 1 + }, + "maxContains": 1, + "minContains": 3 + }, + "tests": [ + { + "description": "empty data", + "data": [], + "valid": false + }, + { + "description": "invalid minContains", + "data": [ + 1 + ], + "valid": false + }, + { + "description": "invalid maxContains", + "data": [ + 1, + 1, + 1 + ], + "valid": false + }, + { + "description": "invalid maxContains and minContains", + "data": [ + 1, + 1 + ], + "valid": false + } + ] + }, + { + "description": "minContains = 0", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": { + "const": 1 + }, + "minContains": 0 + }, + "tests": [ + { + "description": "empty data", + "data": [], + "valid": true + }, + { + "description": "minContains = 0 makes contains always pass", + "data": [ + 2 + ], + "valid": true + } + ] + }, + { + "description": "minContains = 0 with maxContains", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "contains": { + "const": 1 + }, + "minContains": 0, + "maxContains": 1 + }, + "tests": [ + { + "description": "empty data", + "data": [], + "valid": true + }, + { + "description": "not more than maxContains", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "too many", + "data": [ + 1, + 1 + ], + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/minItems.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/minItems.json new file mode 100644 index 000000000..f6aaefe1b --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/minItems.json @@ -0,0 +1,61 @@ +[ + { + "description": "minItems validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "minItems": 1 + }, + "tests": [ + { + "description": "longer is valid", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "exact length is valid", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "too short is invalid", + "data": [], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": "", + "valid": true + } + ] + }, + { + "description": "minItems validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "minItems": 1.0 + }, + "skip": "extract error: invalid uint", + "tests": [ + { + "description": "longer is valid", + "data": [ + 1, + 2 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too short is invalid", + "data": [], + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/minLength.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/minLength.json new file mode 100644 index 000000000..99235a853 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/minLength.json @@ -0,0 +1,56 @@ +[ + { + "description": "minLength validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "minLength": 2 + }, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true + }, + { + "description": "exact length is valid", + "data": "fo", + "valid": true + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + }, + { + "description": "ignores non-strings", + "data": 1, + "valid": true + }, + { + "description": "one grapheme is not long enough", + "data": "💩", + "valid": false + } + ] + }, + { + "description": "minLength validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "minLength": 2.0 + }, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values \"foo\" and [...] (mismatched types string and list):\n generated.cue:4:1\n generated.cue:4:48\n instance.json:1:1\nconflicting values \"foo\" and bool (mismatched types string and bool):\n generated.cue:4:1\n generated.cue:4:8\n instance.json:1:1\nconflicting values \"foo\" and null (mismatched types string and null):\n generated.cue:4:1\n instance.json:1:1\nconflicting values \"foo\" and number (mismatched types string and number):\n generated.cue:4:1\n generated.cue:4:15\n instance.json:1:1\nconflicting values \"foo\" and {...} (mismatched types string and struct):\n generated.cue:4:1\n generated.cue:4:56\n instance.json:1:1\ncannot use 2.0 (type float) as int in argument 2 to strings.MinRunes:\n generated.cue:4:41\n" + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/minProperties.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/minProperties.json new file mode 100644 index 000000000..4273f846c --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/minProperties.json @@ -0,0 +1,78 @@ +[ + { + "description": "minProperties validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "minProperties": 1 + }, + "skip": "extract error: unsupported constraint \"minProperties\"", + "tests": [ + { + "description": "longer is valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "exact length is valid", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ignores arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores strings", + "data": "", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "minProperties validation with a decimal", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "minProperties": 1.0 + }, + "skip": "extract error: unsupported constraint \"minProperties\"", + "tests": [ + { + "description": "longer is valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/minimum.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/minimum.json new file mode 100644 index 000000000..73cd937d7 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/minimum.json @@ -0,0 +1,75 @@ +[ + { + "description": "minimum validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "minimum": 1.1 + }, + "tests": [ + { + "description": "above the minimum is valid", + "data": 2.6, + "valid": true + }, + { + "description": "boundary point is valid", + "data": 1.1, + "valid": true + }, + { + "description": "below the minimum is invalid", + "data": 0.6, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + }, + { + "description": "minimum validation with signed integer", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "minimum": -2 + }, + "tests": [ + { + "description": "negative above the minimum is valid", + "data": -1, + "valid": true + }, + { + "description": "positive above the minimum is valid", + "data": 0, + "valid": true + }, + { + "description": "boundary point is valid", + "data": -2, + "valid": true + }, + { + "description": "boundary point with float is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float below the minimum is invalid", + "data": -2.0001, + "valid": false + }, + { + "description": "int below the minimum is invalid", + "data": -3, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/multipleOf.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/multipleOf.json new file mode 100644 index 000000000..daa230b31 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/multipleOf.json @@ -0,0 +1,99 @@ +[ + { + "description": "by int", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "multipleOf": 2 + }, + "tests": [ + { + "description": "int by int", + "data": 10, + "valid": true + }, + { + "description": "int by int fail", + "data": 7, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "by number", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "multipleOf": 1.5 + }, + "tests": [ + { + "description": "zero is multiple of anything", + "data": 0, + "valid": true + }, + { + "description": "4.5 is multiple of 1.5", + "data": 4.5, + "valid": true + }, + { + "description": "35 is not multiple of 1.5", + "data": 35, + "valid": false + } + ] + }, + { + "description": "by small number", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "multipleOf": 0.0001 + }, + "tests": [ + { + "description": "0.0075 is multiple of 0.0001", + "data": 0.0075, + "valid": true + }, + { + "description": "0.00751 is not multiple of 0.0001", + "data": 0.00751, + "valid": false + } + ] + }, + { + "description": "float division = inf", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "integer", + "multipleOf": 0.123456789 + }, + "tests": [ + { + "description": "always invalid, but naive implementations may raise an overflow error", + "data": 1E+308, + "valid": false + } + ] + }, + { + "description": "small multiple of large integer", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "integer", + "multipleOf": 1E-8 + }, + "tests": [ + { + "description": "any integer is a multiple of 1e-8", + "data": 12391239123, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/not.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/not.json new file mode 100644 index 000000000..ff6bfc9ec --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/not.json @@ -0,0 +1,389 @@ +[ + { + "description": "not", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "not": { + "type": "integer" + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "allowed", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "disallowed", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "not multiple types", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "not": { + "type": [ + "integer", + "boolean" + ] + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "other mismatch", + "data": true, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "not more complex schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "not": { + "type": "object", + "properties": { + "foo": { + "type": "string" + } + } + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "match", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "other match", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "forbidden property", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": { + "not": {} + } + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "property present", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "property absent", + "data": { + "bar": 1, + "baz": 2 + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "forbid everything with empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "not": {} + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "null is invalid", + "data": null, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "object is invalid", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "array is invalid", + "data": [ + "foo" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "forbid everything with boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "not": true + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "null is invalid", + "data": null, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "object is invalid", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "array is invalid", + "data": [ + "foo" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "allow everything with boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "not": false + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string is valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "boolean true is valid", + "data": true, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "boolean false is valid", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "null is valid", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "object is valid", + "data": { + "foo": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "array is valid", + "data": [ + "foo" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "empty array is valid", + "data": [], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "double negation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "not": { + "not": {} + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "collect annotations inside a 'not', even if collection is disabled", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "not": { + "$comment": "this subschema must still produce annotations internally, even though the 'not' will ultimately discard them", + "anyOf": [ + true, + { + "properties": { + "foo": true + } + } + ], + "unevaluatedProperties": false + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "unevaluated property", + "data": { + "bar": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "annotations are still collected inside a 'not'", + "data": { + "foo": 1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/oneOf.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/oneOf.json new file mode 100644 index 000000000..6f7cf3bf7 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/oneOf.json @@ -0,0 +1,375 @@ +[ + { + "description": "oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [ + { + "type": "integer" + }, + { + "minimum": 2 + } + ] + }, + "tests": [ + { + "description": "first oneOf valid", + "data": 1, + "valid": true + }, + { + "description": "second oneOf valid", + "data": 2.5, + "valid": true + }, + { + "description": "both oneOf valid", + "data": 3, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "neither oneOf valid", + "data": 1.5, + "valid": false + } + ] + }, + { + "description": "oneOf with base schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "oneOf": [ + { + "minLength": 2 + }, + { + "maxLength": 4 + } + ] + }, + "tests": [ + { + "description": "mismatch base schema", + "data": 3, + "valid": false + }, + { + "description": "one oneOf valid", + "data": "foobar", + "valid": true + }, + { + "description": "both oneOf valid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with boolean schemas, all true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [ + true, + true, + true + ] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with boolean schemas, one true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [ + true, + false, + false + ] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "oneOf with boolean schemas, more than one true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [ + true, + true, + false + ] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with boolean schemas, all false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [ + false, + false, + false + ] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf complex types", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [ + { + "properties": { + "bar": { + "type": "integer" + } + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + } + ] + }, + "tests": [ + { + "description": "first oneOf valid (complex)", + "data": { + "bar": 2 + }, + "valid": true + }, + { + "description": "second oneOf valid (complex)", + "data": { + "foo": "baz" + }, + "valid": true + }, + { + "description": "both oneOf valid (complex)", + "data": { + "foo": "baz", + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "neither oneOf valid (complex)", + "data": { + "foo": 2, + "bar": "quux" + }, + "valid": false + } + ] + }, + { + "description": "oneOf with empty schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [ + { + "type": "number" + }, + {} + ] + }, + "tests": [ + { + "description": "one valid - valid", + "data": "foo", + "valid": true + }, + { + "description": "both valid - invalid", + "data": 123, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with required", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "oneOf": [ + { + "required": [ + "foo", + "bar" + ] + }, + { + "required": [ + "foo", + "baz" + ] + } + ] + }, + "tests": [ + { + "description": "both invalid - invalid", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "first valid - valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "second valid - valid", + "data": { + "foo": 1, + "baz": 3 + }, + "valid": true + }, + { + "description": "both valid - invalid", + "data": { + "foo": 1, + "bar": 2, + "baz": 3 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with missing optional property", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [ + { + "properties": { + "bar": true, + "baz": true + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "foo": true + }, + "required": [ + "foo" + ] + } + ] + }, + "tests": [ + { + "description": "first oneOf valid", + "data": { + "bar": 8 + }, + "valid": true + }, + { + "description": "second oneOf valid", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "both oneOf valid", + "data": { + "foo": "foo", + "bar": 8 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "neither oneOf valid", + "data": { + "baz": "quux" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "nested oneOf, to check validation semantics", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "oneOf": [ + { + "oneOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/anchor.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/anchor.json new file mode 100644 index 000000000..fb89ef1d1 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/anchor.json @@ -0,0 +1,69 @@ +[ + { + "description": "$anchor inside an enum is not a real identifier", + "comment": "the implementation must not be confused by an $anchor buried in the enum", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "anchor_in_enum": { + "enum": [ + { + "$anchor": "my_anchor", + "type": "null" + } + ] + }, + "real_identifier_in_schema": { + "$anchor": "my_anchor", + "type": "string" + }, + "zzz_anchor_in_const": { + "const": { + "$anchor": "my_anchor", + "type": "null" + } + } + }, + "anyOf": [ + { + "$ref": "#/$defs/anchor_in_enum" + }, + { + "$ref": "#my_anchor" + } + ] + }, + "skip": "extract error: unsupported constraint \"$anchor\" (and 1 more errors)", + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "$anchor": "my_anchor", + "type": "null" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "in implementations that strip $anchor, this may match either $def", + "data": { + "type": "null" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "match $ref to $anchor", + "data": "a string to match #/$defs/anchor_in_enum", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "no match on enum or $ref to $anchor", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/bignum.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/bignum.json new file mode 100644 index 000000000..4f82fc750 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/bignum.json @@ -0,0 +1,110 @@ +[ + { + "description": "integer", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "integer" + }, + "tests": [ + { + "description": "a bignum is an integer", + "data": 12345678910111213141516171819202122232425262728293031, + "valid": true + }, + { + "description": "a negative bignum is an integer", + "data": -12345678910111213141516171819202122232425262728293031, + "valid": true + } + ] + }, + { + "description": "number", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "number" + }, + "tests": [ + { + "description": "a bignum is a number", + "data": 98249283749234923498293171823948729348710298301928331, + "valid": true + }, + { + "description": "a negative bignum is a number", + "data": -98249283749234923498293171823948729348710298301928331, + "valid": true + } + ] + }, + { + "description": "string", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string" + }, + "tests": [ + { + "description": "a bignum is not a string", + "data": 98249283749234923498293171823948729348710298301928331, + "valid": false + } + ] + }, + { + "description": "maximum integer comparison", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "maximum": 18446744073709551615 + }, + "tests": [ + { + "description": "comparison works for high numbers", + "data": 18446744073709551600, + "valid": true + } + ] + }, + { + "description": "float comparison with high precision", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "exclusiveMaximum": 972783798187987123879878123.18878137 + }, + "tests": [ + { + "description": "comparison works for high numbers", + "data": 972783798187987123879878123.188781371, + "valid": false + } + ] + }, + { + "description": "minimum integer comparison", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "minimum": -18446744073709551615 + }, + "tests": [ + { + "description": "comparison works for very negative numbers", + "data": -18446744073709551600, + "valid": true + } + ] + }, + { + "description": "float comparison with high precision on negative numbers", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "exclusiveMinimum": -972783798187987123879878123.18878137 + }, + "tests": [ + { + "description": "comparison works for very negative numbers", + "data": -972783798187987123879878123.188781371, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/cross-draft.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/cross-draft.json new file mode 100644 index 000000000..d3706150b --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/cross-draft.json @@ -0,0 +1,24 @@ +[ + { + "description": "refs to historic drafts are processed as historic drafts", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "array", + "$ref": "http://localhost:1234/draft2019-09/ignore-prefixItems.json" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2019-09/ignore-prefixItems.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "first item not a string is valid", + "comment": "if the implementation is not processing the $ref as a 2019-09 schema, this test will fail", + "data": [ + 1, + 2, + 3 + ], + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/dependencies-compatibility.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/dependencies-compatibility.json new file mode 100644 index 000000000..60abadc04 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/dependencies-compatibility.json @@ -0,0 +1,374 @@ +[ + { + "description": "single dependency", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependencies": { + "bar": [ + "foo" + ] + } + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependant", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "with dependency", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "missing dependency", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ignores arrays", + "data": [ + "bar" + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "empty dependents", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependencies": { + "bar": [] + } + }, + "tests": [ + { + "description": "empty object", + "data": {}, + "valid": true + }, + { + "description": "object with one property", + "data": { + "bar": 2 + }, + "valid": true + }, + { + "description": "non-object is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "multiple dependents required", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependencies": { + "quux": [ + "foo", + "bar" + ] + } + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependants", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "with dependencies", + "data": { + "foo": 1, + "bar": 2, + "quux": 3 + }, + "valid": true + }, + { + "description": "missing dependency", + "data": { + "foo": 1, + "quux": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "missing other dependency", + "data": { + "bar": 1, + "quux": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "missing both dependencies", + "data": { + "quux": 1 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependencies": { + "foo\nbar": [ + "foo\rbar" + ], + "foo\"bar": [ + "foo'bar" + ] + } + }, + "tests": [ + { + "description": "CRLF", + "data": { + "foo\nbar": 1, + "foo\rbar": 2 + }, + "valid": true + }, + { + "description": "quoted quotes", + "data": { + "foo'bar": 1, + "foo\"bar": 2 + }, + "valid": true + }, + { + "description": "CRLF missing dependent", + "data": { + "foo\nbar": 1, + "foo": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "quoted quotes missing dependent", + "data": { + "foo\"bar": 2 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "single schema dependency", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependencies": { + "bar": { + "properties": { + "foo": { + "type": "integer" + }, + "bar": { + "type": "integer" + } + } + } + } + }, + "tests": [ + { + "description": "valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "no dependency", + "data": { + "foo": "quux" + }, + "valid": true + }, + { + "description": "wrong type", + "data": { + "foo": "quux", + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "wrong type other", + "data": { + "foo": 2, + "bar": "quux" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "wrong type both", + "data": { + "foo": "quux", + "bar": "quux" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ignores arrays", + "data": [ + "bar" + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "boolean subschemas", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependencies": { + "foo": true, + "bar": false + } + }, + "tests": [ + { + "description": "object with property having schema true is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "object with property having schema false is invalid", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "object with both properties is invalid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "schema dependencies with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "dependencies": { + "foo\tbar": { + "minProperties": 4 + }, + "foo'bar": { + "required": [ + "foo\"bar" + ] + } + } + }, + "tests": [ + { + "description": "quoted tab", + "data": { + "foo\tbar": 1, + "a": 2, + "b": 3, + "c": 4 + }, + "valid": true + }, + { + "description": "quoted quote", + "data": { + "foo'bar": { + "foo\"bar": 1 + } + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "quoted tab invalid under dependent schema", + "data": { + "foo\tbar": 1, + "a": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "quoted quote invalid under dependent schema", + "data": { + "foo'bar": 1 + }, + "valid": false, + "skip": "unexpected success" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/dynamicRef.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/dynamicRef.json new file mode 100644 index 000000000..8261c26a3 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/dynamicRef.json @@ -0,0 +1,68 @@ +[ + { + "description": "$dynamicRef skips over intermediate resources - pointer reference across resource boundary", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/optional/main", + "type": "object", + "properties": { + "bar-item": { + "$ref": "bar#/$defs/item" + } + }, + "$defs": { + "bar": { + "$id": "bar", + "type": "array", + "items": { + "$ref": "item" + }, + "$defs": { + "item": { + "$id": "item", + "type": "object", + "properties": { + "content": { + "$dynamicRef": "#content" + } + }, + "$defs": { + "defaultContent": { + "$dynamicAnchor": "content", + "type": "integer" + } + } + }, + "content": { + "$dynamicAnchor": "content", + "type": "string" + } + } + } + } + }, + "skip": "extract error: unsupported constraint \"$dynamicRef\" (and 2 more errors)", + "tests": [ + { + "description": "integer property passes", + "data": { + "bar-item": { + "content": 42 + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string property fails", + "data": { + "bar-item": { + "content": "value" + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/ecmascript-regex.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/ecmascript-regex.json new file mode 100644 index 000000000..f3f9d0a73 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/ecmascript-regex.json @@ -0,0 +1,666 @@ +[ + { + "description": "ECMA 262 regex $ does not match trailing newline", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "pattern": "^abc$" + }, + "tests": [ + { + "description": "matches in Python, but not in ECMA 262", + "data": "abc\\n", + "valid": false + }, + { + "description": "matches", + "data": "abc", + "valid": true + } + ] + }, + { + "description": "ECMA 262 regex converts \\t to horizontal tab", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "pattern": "^\\t$" + }, + "tests": [ + { + "description": "does not match", + "data": "\\t", + "valid": false + }, + { + "description": "matches", + "data": "\t", + "valid": true + } + ] + }, + { + "description": "ECMA 262 regex escapes control codes with \\c and upper letter", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "pattern": "^\\cC$" + }, + "skip": "extract error: unsupported regexp: error parsing regexp: invalid escape sequence: `\\c`", + "tests": [ + { + "description": "does not match", + "data": "\\cC", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "matches", + "data": "\u0003", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ECMA 262 regex escapes control codes with \\c and lower letter", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "pattern": "^\\cc$" + }, + "skip": "extract error: unsupported regexp: error parsing regexp: invalid escape sequence: `\\c`", + "tests": [ + { + "description": "does not match", + "data": "\\cc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "matches", + "data": "\u0003", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ECMA 262 \\d matches ascii digits only", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "pattern": "^\\d$" + }, + "tests": [ + { + "description": "ASCII zero matches", + "data": "0", + "valid": true + }, + { + "description": "NKO DIGIT ZERO does not match (unlike e.g. Python)", + "data": "߀", + "valid": false + }, + { + "description": "NKO DIGIT ZERO (as \\u escape) does not match", + "data": "߀", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\D matches everything but ascii digits", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "pattern": "^\\D$" + }, + "tests": [ + { + "description": "ASCII zero does not match", + "data": "0", + "valid": false + }, + { + "description": "NKO DIGIT ZERO matches (unlike e.g. Python)", + "data": "߀", + "valid": true + }, + { + "description": "NKO DIGIT ZERO (as \\u escape) matches", + "data": "߀", + "valid": true + } + ] + }, + { + "description": "ECMA 262 \\w matches ascii letters only", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "pattern": "^\\w$" + }, + "tests": [ + { + "description": "ASCII 'a' matches", + "data": "a", + "valid": true + }, + { + "description": "latin-1 e-acute does not match (unlike e.g. Python)", + "data": "é", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\W matches everything but ascii letters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "pattern": "^\\W$" + }, + "tests": [ + { + "description": "ASCII 'a' does not match", + "data": "a", + "valid": false + }, + { + "description": "latin-1 e-acute matches (unlike e.g. Python)", + "data": "é", + "valid": true + } + ] + }, + { + "description": "ECMA 262 \\s matches whitespace", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "pattern": "^\\s$" + }, + "tests": [ + { + "description": "ASCII space matches", + "data": " ", + "valid": true + }, + { + "description": "Character tabulation matches", + "data": "\t", + "valid": true + }, + { + "description": "Line tabulation matches", + "data": "\u000b", + "valid": true, + "skip": "invalid value \"\\v\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n generated.cue:1:1\n instance.json:1:1\n" + }, + { + "description": "Form feed matches", + "data": "\f", + "valid": true + }, + { + "description": "latin-1 non-breaking-space matches", + "data": " ", + "valid": true, + "skip": "invalid value \"\\u00a0\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n generated.cue:1:1\n instance.json:1:1\n" + }, + { + "description": "zero-width whitespace matches", + "data": "\ufeff", + "valid": true, + "skip": "invalid value \"\\ufeff\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n generated.cue:1:1\n instance.json:1:1\n" + }, + { + "description": "line feed matches (line terminator)", + "data": "\n", + "valid": true + }, + { + "description": "paragraph separator matches (line terminator)", + "data": "\u2029", + "valid": true, + "skip": "invalid value \"\\u2029\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n generated.cue:1:1\n instance.json:1:1\n" + }, + { + "description": "EM SPACE matches (Space_Separator)", + "data": " ", + "valid": true, + "skip": "invalid value \"\\u2003\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n generated.cue:1:1\n instance.json:1:1\n" + }, + { + "description": "Non-whitespace control does not match", + "data": "\u0001", + "valid": false + }, + { + "description": "Non-whitespace does not match", + "data": "–", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\S matches everything but whitespace", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string", + "pattern": "^\\S$" + }, + "tests": [ + { + "description": "ASCII space does not match", + "data": " ", + "valid": false + }, + { + "description": "Character tabulation does not match", + "data": "\t", + "valid": false + }, + { + "description": "Line tabulation does not match", + "data": "\u000b", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "Form feed does not match", + "data": "\f", + "valid": false + }, + { + "description": "latin-1 non-breaking-space does not match", + "data": " ", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "zero-width whitespace does not match", + "data": "\ufeff", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "line feed does not match (line terminator)", + "data": "\n", + "valid": false + }, + { + "description": "paragraph separator does not match (line terminator)", + "data": "\u2029", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "EM SPACE does not match (Space_Separator)", + "data": " ", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "Non-whitespace control matches", + "data": "\u0001", + "valid": true + }, + { + "description": "Non-whitespace matches", + "data": "–", + "valid": true + } + ] + }, + { + "description": "patterns always use unicode semantics with pattern", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "pattern": "\\p{Letter}cole" + }, + "skip": "extract error: unsupported regexp: error parsing regexp: invalid character class range: `\\p{Letter}`", + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ÉTAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ÉCOLE, L'ÉGLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ÉTAIT SUR LA PATINOIRE.", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "\\w in patterns matches [A-Za-z0-9_], not unicode letters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "pattern": "\\wcole" + }, + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": false + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ÉTAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ÉCOLE, L'ÉGLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ÉTAIT SUR LA PATINOIRE.", + "valid": false + } + ] + }, + { + "description": "pattern with ASCII ranges", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "pattern": "[a-z]cole" + }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": false + }, + { + "description": "ascii characters match", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + } + ] + }, + { + "description": "\\d in pattern matches [0-9], not unicode digits", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "pattern": "^\\d+$" + }, + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "৪২", + "valid": false + } + ] + }, + { + "description": "\\a is not an ECMA 262 control escape", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "regex" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "when used as a pattern", + "data": "\\a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "pattern with non-ASCII digits", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "pattern": "^\\p{digit}+$" + }, + "skip": "extract error: unsupported regexp: error parsing regexp: invalid character class range: `\\p{digit}`", + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "৪২", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "patterns always use unicode semantics with patternProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "patternProperties": { + "\\p{Letter}cole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { + "l'ecole": "pas de vraie vie" + }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": true + }, + { + "description": "unicode character in hex format in string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": true + }, + { + "description": "unicode matching is case-sensitive", + "data": { + "L'ÉCOLE": "PAS DE VRAIE VIE" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "\\w in patternProperties matches [A-Za-z0-9_], not unicode letters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "patternProperties": { + "\\wcole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { + "l'ecole": "pas de vraie vie" + }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "unicode character in hex format in string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "unicode matching is case-sensitive", + "data": { + "L'ÉCOLE": "PAS DE VRAIE VIE" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "patternProperties with ASCII ranges", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "patternProperties": { + "[a-z]cole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "unicode character in hex format in string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ascii characters match", + "data": { + "l'ecole": "pas de vraie vie" + }, + "valid": true + } + ] + }, + { + "description": "\\d in patternProperties matches [0-9], not unicode digits", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "patternProperties": { + "^\\d+$": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { + "42": "life, the universe, and everything" + }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { + "-%#": "spending the year dead for tax reasons" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { + "৪২": "khajit has wares if you have coin" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "patternProperties with non-ASCII digits", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "patternProperties": { + "^\\p{digit}+$": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { + "42": "life, the universe, and everything" + }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { + "-%#": "spending the year dead for tax reasons" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { + "৪২": "khajit has wares if you have coin" + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/float-overflow.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/float-overflow.json new file mode 100644 index 000000000..0d26704a1 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/float-overflow.json @@ -0,0 +1,18 @@ +[ + { + "description": "all integers are multiples of 0.5, if overflow is handled", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "integer", + "multipleOf": 0.5 + }, + "tests": [ + { + "description": "valid if optional overflow handling is implemented", + "data": 1E+308, + "valid": true, + "skip": "conflicting values 1E+308 and int (mismatched types float and int):\n generated.cue:4:1\n instance.json:1:1\n" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format-assertion.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format-assertion.json new file mode 100644 index 000000000..cc71d60eb --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format-assertion.json @@ -0,0 +1,48 @@ +[ + { + "description": "schema that uses custom metaschema with format-assertion: false", + "schema": { + "$id": "https://schema/using/format-assertion/false", + "$schema": "http://localhost:1234/draft2020-12/format-assertion-false.json", + "format": "ipv4" + }, + "skip": "extract error: invalid $schema URL \"http://localhost:1234/draft2020-12/format-assertion-false.json\": $schema URI not recognized (and 1 more errors)", + "tests": [ + { + "description": "format-assertion: false: valid string", + "data": "127.0.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "format-assertion: false: invalid string", + "data": "not-an-ipv4", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "schema that uses custom metaschema with format-assertion: true", + "schema": { + "$id": "https://schema/using/format-assertion/true", + "$schema": "http://localhost:1234/draft2020-12/format-assertion-true.json", + "format": "ipv4" + }, + "skip": "extract error: invalid $schema URL \"http://localhost:1234/draft2020-12/format-assertion-true.json\": $schema URI not recognized (and 1 more errors)", + "tests": [ + { + "description": "format-assertion: true: valid string", + "data": "127.0.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "format-assertion: true: invalid string", + "data": "not-an-ipv4", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/date-time.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/date-time.json new file mode 100644 index 000000000..3c2969744 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/date-time.json @@ -0,0 +1,162 @@ +[ + { + "description": "validation of date-time strings", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "date-time" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time string", + "data": "1963-06-19T08:30:06.283185Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time string without second fraction", + "data": "1963-06-19T08:30:06Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time string with plus offset", + "data": "1937-01-01T12:00:27.87+00:20", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time string with minus offset", + "data": "1990-12-31T15:59:50.123-08:00", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time with a leap second, UTC", + "data": "1998-12-31T23:59:60Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time with a leap second, with minus offset", + "data": "1998-12-31T15:59:60.123-08:00", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid date-time past leap second, UTC", + "data": "1998-12-31T23:59:61Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid date-time with leap second on a wrong minute, UTC", + "data": "1998-12-31T23:58:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid date-time with leap second on a wrong hour, UTC", + "data": "1998-12-31T22:59:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid day in date-time string", + "data": "1990-02-31T15:59:59.123-08:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid offset in date-time string", + "data": "1990-12-31T15:59:59-24:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid closing Z after time-zone offset", + "data": "1963-06-19T08:30:06.28123+01:00Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid date-time string", + "data": "06/19/1963 08:30:06 PST", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "case-insensitive T and Z", + "data": "1963-06-19t08:30:06.283185z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "2013-350T01:01:01", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-padded month dates", + "data": "1963-6-19T08:30:06.283185Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-padded day dates", + "data": "1963-06-1T08:30:06.283185Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4) in date portion", + "data": "1963-06-1৪T00:00:00Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4) in time portion", + "data": "1963-06-11T0৪:00:00Z", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/date.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/date.json new file mode 100644 index 000000000..036037d0c --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/date.json @@ -0,0 +1,294 @@ +[ + { + "description": "validation of date strings", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "date" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date string", + "data": "1963-06-19", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in January", + "data": "2020-01-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in January", + "data": "2020-01-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 28 days in February (normal)", + "data": "2021-02-28", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 29 days in February (normal)", + "data": "2021-02-29", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 29 days in February (leap)", + "data": "2020-02-29", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 30 days in February (leap)", + "data": "2020-02-30", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in March", + "data": "2020-03-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in March", + "data": "2020-03-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 30 days in April", + "data": "2020-04-30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 31 days in April", + "data": "2020-04-31", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in May", + "data": "2020-05-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in May", + "data": "2020-05-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 30 days in June", + "data": "2020-06-30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 31 days in June", + "data": "2020-06-31", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in July", + "data": "2020-07-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in July", + "data": "2020-07-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in August", + "data": "2020-08-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in August", + "data": "2020-08-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 30 days in September", + "data": "2020-09-30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 31 days in September", + "data": "2020-09-31", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in October", + "data": "2020-10-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in October", + "data": "2020-10-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 30 days in November", + "data": "2020-11-30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 31 days in November", + "data": "2020-11-31", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in December", + "data": "2020-12-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in December", + "data": "2020-12-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with invalid month", + "data": "2020-13-01", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid date string", + "data": "06/19/1963", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "2013-350", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "non-padded month dates are not valid", + "data": "1998-1-20", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "non-padded day dates are not valid", + "data": "1998-01-1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid month", + "data": "1998-13-01", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid month-day combination", + "data": "1998-04-31", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "2021 is not a leap year", + "data": "2021-02-29", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "2020 is a leap year", + "data": "2020-02-29", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4)", + "data": "1963-06-1৪", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ISO8601 / non-RFC3339: YYYYMMDD without dashes (2023-03-28)", + "data": "20230328", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ISO8601 / non-RFC3339: week number implicit day of week (2023-01-02)", + "data": "2023-W01", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ISO8601 / non-RFC3339: week number with day of week (2023-03-28)", + "data": "2023-W13-2", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ISO8601 / non-RFC3339: week number rollover to next year (2023-01-01)", + "data": "2022W527", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/duration.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/duration.json new file mode 100644 index 000000000..d966dbec5 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/duration.json @@ -0,0 +1,162 @@ +[ + { + "description": "validation of duration strings", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "duration" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid duration string", + "data": "P4DT12H30M5S", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid duration string", + "data": "PT1D", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no elements present", + "data": "P", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no time elements present", + "data": "P1YT", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no date or time elements present", + "data": "PT", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "elements out of order", + "data": "P2D1Y", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "missing time separator", + "data": "P1D2H", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "time element in the date position", + "data": "P2S", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "four years duration", + "data": "P4Y", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "zero time, in seconds", + "data": "PT0S", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "zero time, in days", + "data": "P0D", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "one month duration", + "data": "P1M", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "one minute duration", + "data": "PT1M", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "one and a half days, in hours", + "data": "PT36H", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "one and a half days, in days and hours", + "data": "P1DT12H", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "two weeks", + "data": "P2W", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "weeks cannot be combined with other units", + "data": "P1Y2W", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '২' (a Bengali 2)", + "data": "P২Y", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "element without unit", + "data": "P1", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/email.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/email.json new file mode 100644 index 000000000..093a55887 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/email.json @@ -0,0 +1,144 @@ +[ + { + "description": "validation of e-mail addresses", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "email" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid e-mail address", + "data": "joe.bloggs@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid e-mail address", + "data": "2962", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "tilde in local part is valid", + "data": "te~st@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "tilde before local part is valid", + "data": "~test@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "tilde after local part is valid", + "data": "test~@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a quoted string with a space in the local part is valid", + "data": "\"joe bloggs\"@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a quoted string with a double dot in the local part is valid", + "data": "\"joe..bloggs\"@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a quoted string with a @ in the local part is valid", + "data": "\"joe@bloggs\"@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an IPv4-address-literal after the @ is valid", + "data": "joe.bloggs@[127.0.0.1]", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an IPv6-address-literal after the @ is valid", + "data": "joe.bloggs@[IPv6:::1]", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "dot before local part is not valid", + "data": ".test@example.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "dot after local part is not valid", + "data": "test.@example.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "two separated dots inside local part are valid", + "data": "te.s.t@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "two subsequent dots inside local part are not valid", + "data": "te..st@example.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid domain", + "data": "joe.bloggs@invalid=domain.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid IPv4-address-literal", + "data": "joe.bloggs@[127.0.0.300]", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/hostname.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/hostname.json new file mode 100644 index 000000000..1ca5890be --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/hostname.json @@ -0,0 +1,150 @@ +[ + { + "description": "validation of host names", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "hostname" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid host name", + "data": "www.example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid punycoded IDN hostname", + "data": "xn--4gbwdl.xn--wgbh1c", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a host name starting with an illegal character", + "data": "-a-host-name-that-starts-with--", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a host name containing illegal characters", + "data": "not_a_valid_host_name", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a host name with a component too long", + "data": "a-vvvvvvvvvvvvvvvveeeeeeeeeeeeeeeerrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy-long-host-name-component", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "starts with hyphen", + "data": "-hostname", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ends with hyphen", + "data": "hostname-", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "starts with underscore", + "data": "_hostname", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ends with underscore", + "data": "hostname_", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "contains underscore", + "data": "host_name", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "exceeds maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "single label", + "data": "hostname", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label with hyphen", + "data": "host-name", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label with digits", + "data": "h0stn4me", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label starting with digit", + "data": "1host", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label ending with digit", + "data": "hostnam3", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/idn-email.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/idn-email.json new file mode 100644 index 000000000..d54116677 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/idn-email.json @@ -0,0 +1,72 @@ +[ + { + "description": "validation of an internationalized e-mail addresses", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "idn-email" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid idn e-mail (example@example.test in Hangul)", + "data": "실례@실례.테스트", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid idn e-mail address", + "data": "2962", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid e-mail address", + "data": "joe.bloggs@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid e-mail address", + "data": "2962", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/idn-hostname.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/idn-hostname.json new file mode 100644 index 000000000..d6d8c9851 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/idn-hostname.json @@ -0,0 +1,389 @@ +[ + { + "description": "validation of internationalized host names", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "idn-hostname" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid host name (example.test in Hangul)", + "data": "실례.테스트", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "illegal first char U+302E Hangul single dot tone mark", + "data": "〮실례.테스트", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "contains illegal char U+302E Hangul single dot tone mark", + "data": "실〮례.테스트", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a host name with a component too long", + "data": "실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실례례테스트례례례례례례례례례례례례례례례례례테스트례례례례례례례례례례례례례례례례례례례테스트례례례례례례례례례례례례테스트례례실례.테스트", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid label, correct Punycode", + "comment": "https://tools.ietf.org/html/rfc5890#section-2.3.2.1 https://tools.ietf.org/html/rfc5891#section-4.4 https://tools.ietf.org/html/rfc3492#section-7.1", + "data": "-\u003e $1.00 \u003c--", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid Chinese Punycode", + "comment": "https://tools.ietf.org/html/rfc5890#section-2.3.2.1 https://tools.ietf.org/html/rfc5891#section-4.4", + "data": "xn--ihqwcrb4cv8a8dqg056pqjye", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid Punycode", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.4 https://tools.ietf.org/html/rfc5890#section-2.3.2.1", + "data": "xn--X", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "U-label contains \"--\" in the 3rd and 4th position", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1 https://tools.ietf.org/html/rfc5890#section-2.3.2.1", + "data": "XN--aa---o47jg78q", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "U-label starts with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "-hello", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "U-label ends with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "hello-", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "U-label starts and ends with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "-hello-", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Begins with a Spacing Combining Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "ःhello", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Begins with a Nonspacing Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "̀hello", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Begins with an Enclosing Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "҈hello", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Exceptions that are PVALID, left-to-right chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "ßς་〇", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Exceptions that are PVALID, right-to-left chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "۽۾", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Exceptions that are DISALLOWED, right-to-left chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "ـߺ", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Exceptions that are DISALLOWED, left-to-right chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6 Note: The two combining marks (U+302E and U+302F) are in the middle and not at the start", + "data": "〱〲〳〴〵〮〯〻", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "MIDDLE DOT with no preceding 'l'", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "a·l", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "MIDDLE DOT with nothing preceding", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "·l", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "MIDDLE DOT with no following 'l'", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l·a", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "MIDDLE DOT with nothing following", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l·", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "MIDDLE DOT with surrounding 'l's", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l·l", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Greek KERAIA not followed by Greek", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "α͵S", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Greek KERAIA not followed by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "α͵", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Greek KERAIA followed by Greek", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "α͵β", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Hebrew GERESH not preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "A׳ב", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Hebrew GERESH not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "׳ב", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Hebrew GERESH preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "א׳ב", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Hebrew GERSHAYIM not preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "A״ב", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Hebrew GERSHAYIM not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "״ב", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Hebrew GERSHAYIM preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "א״ב", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "KATAKANA MIDDLE DOT with no Hiragana, Katakana, or Han", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "def・abc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "KATAKANA MIDDLE DOT with no other characters", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "・", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "KATAKANA MIDDLE DOT with Hiragana", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "・ぁ", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "KATAKANA MIDDLE DOT with Katakana", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "・ァ", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "KATAKANA MIDDLE DOT with Han", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "・丈", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Arabic-Indic digits mixed with Extended Arabic-Indic digits", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8", + "data": "ب٠۰", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Arabic-Indic digits not mixed with Extended Arabic-Indic digits", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8", + "data": "ب٠ب", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Extended Arabic-Indic digits not mixed with Arabic-Indic digits", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.9", + "data": "۰0", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ZERO WIDTH JOINER not preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "क‍ष", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ZERO WIDTH JOINER not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "‍ष", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ZERO WIDTH JOINER preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "क्‍ष", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ZERO WIDTH NON-JOINER preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1", + "data": "क्‌ष", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ZERO WIDTH NON-JOINER not preceded by Virama but matches regexp", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1 https://www.w3.org/TR/alreq/#h_disjoining_enforcement", + "data": "بي‌بي", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label", + "data": "hostname", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label with hyphen", + "data": "host-name", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label with digits", + "data": "h0stn4me", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label starting with digit", + "data": "1host", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label ending with digit", + "data": "hostnam3", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/ipv4.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/ipv4.json new file mode 100644 index 000000000..4c2822bff --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/ipv4.json @@ -0,0 +1,109 @@ +[ + { + "description": "validation of IP addresses", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "ipv4" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IP address", + "data": "192.168.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an IP address with too many components", + "data": "127.0.0.0.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IP address with out-of-range values", + "data": "256.256.256.256", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IP address without 4 components", + "data": "127.0", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IP address as an integer", + "data": "0x7f000001", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IP address as an integer (decimal)", + "data": "2130706433", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid leading zeroes, as they are treated as octals", + "comment": "see https://sick.codes/universal-netmask-npm-package-used-by-270000-projects-vulnerable-to-octal-input-data-server-side-request-forgery-remote-file-inclusion-local-file-inclusion-and-more-cve-2021-28918/", + "data": "087.10.0.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "value without leading zero is valid", + "data": "87.10.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '২' (a Bengali 2)", + "data": "1২7.0.0.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "netmask is not a part of ipv4 address", + "data": "192.168.1.0/24", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/ipv6.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/ipv6.json new file mode 100644 index 000000000..d0ed88f29 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/ipv6.json @@ -0,0 +1,252 @@ +[ + { + "description": "validation of IPv6 addresses", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "ipv6" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IPv6 address", + "data": "::1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an IPv6 address with out-of-range values", + "data": "12345::", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "trailing 4 hex symbols is valid", + "data": "::abef", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "trailing 5 hex symbols is invalid", + "data": "::abcef", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IPv6 address with too many components", + "data": "1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IPv6 address containing illegal characters", + "data": "::laptop", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no digits is valid", + "data": "::", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "leading colons is valid", + "data": "::42:ff:1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "trailing colons is valid", + "data": "d6::", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "missing leading octet is invalid", + "data": ":2:3:4:5:6:7:8", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "missing trailing octet is invalid", + "data": "1:2:3:4:5:6:7:", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "missing leading octet with omitted octets later", + "data": ":2:3:4::8", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "single set of double colons in the middle is valid", + "data": "1:d6::42", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "two sets of double colons is invalid", + "data": "1::d6::42", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "mixed format with the ipv4 section as decimal octets", + "data": "1::d6:192.168.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mixed format with double colons between the sections", + "data": "1:2::192.168.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mixed format with ipv4 section with octet out of range", + "data": "1::2:192.168.256.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "mixed format with ipv4 section with a hex octet", + "data": "1::2:192.168.ff.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "mixed format with leading double colons (ipv4-mapped ipv6 address)", + "data": "::ffff:192.168.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "triple colons is invalid", + "data": "1:2:3:4:5:::8", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "8 octets", + "data": "1:2:3:4:5:6:7:8", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "insufficient octets without double colons", + "data": "1:2:3:4:5:6:7", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no colons is invalid", + "data": "1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ipv4 is not ipv6", + "data": "127.0.0.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ipv4 segment must have 4 octets", + "data": "1:2:3:4:1.2.3", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "leading whitespace is invalid", + "data": " ::1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "trailing whitespace is invalid", + "data": "::1 ", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "netmask is not a part of ipv6 address", + "data": "fe80::/64", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "zone id is not a part of ipv6 address", + "data": "fe80::a%eth1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a long valid ipv6", + "data": "1000:1000:1000:1000:1000:1000:255.255.255.255", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a long invalid ipv6, below length limit, first", + "data": "100:100:100:100:100:100:255.255.255.255.255", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a long invalid ipv6, below length limit, second", + "data": "100:100:100:100:100:100:100:255.255.255.255", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4)", + "data": "1:2:3:4:5:6:7:৪", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4) in the IPv4 portion", + "data": "1:2::192.16৪.0.1", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/iri-reference.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/iri-reference.json new file mode 100644 index 000000000..0a7e6ce04 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/iri-reference.json @@ -0,0 +1,90 @@ +[ + { + "description": "validation of IRI References", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "iri-reference" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI", + "data": "http://ƒøø.ßår/?∂éœ=πîx#πîüx", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid protocol-relative IRI Reference", + "data": "//ƒøø.ßår/?∂éœ=πîx#πîüx", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid relative IRI Reference", + "data": "/âππ", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid IRI Reference", + "data": "\\\\WINDOWS\\filëßåré", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI Reference", + "data": "âππ", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI fragment", + "data": "#ƒrägmênt", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid IRI fragment", + "data": "#ƒräg\\mênt", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/iri.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/iri.json new file mode 100644 index 000000000..61ecb7199 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/iri.json @@ -0,0 +1,102 @@ +[ + { + "description": "validation of IRIs", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "iri" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI with anchor tag", + "data": "http://ƒøø.ßår/?∂éœ=πîx#πîüx", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI with anchor tag and parentheses", + "data": "http://ƒøø.com/blah_(wîkïpédiå)_blah#ßité-1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI with URL-encoded stuff", + "data": "http://ƒøø.ßår/?q=Test%20URL-encoded%20stuff", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI with many special characters", + "data": "http://-.~_!$\u0026'()*+,;=:%40:80%2f::::::@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI based on IPv6", + "data": "http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid IRI based on IPv6", + "data": "http://2001:0db8:85a3:0000:0000:8a2e:0370:7334", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid relative IRI Reference", + "data": "/abc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid IRI", + "data": "\\\\WINDOWS\\filëßåré", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid IRI though valid IRI reference", + "data": "âππ", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/json-pointer.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/json-pointer.json new file mode 100644 index 000000000..45cadb117 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/json-pointer.json @@ -0,0 +1,240 @@ +[ + { + "description": "validation of JSON-pointers (JSON String Representation)", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "json-pointer" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid JSON-pointer", + "data": "/foo/bar~0/baz~1/%a", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (~ not escaped)", + "data": "/foo/bar~", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer with empty segment", + "data": "/foo//bar", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer with the last empty segment", + "data": "/foo/bar/", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #1", + "data": "", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #2", + "data": "/foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #3", + "data": "/foo/0", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #4", + "data": "/", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #5", + "data": "/a~1b", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #6", + "data": "/c%d", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #7", + "data": "/e^f", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #8", + "data": "/g|h", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #9", + "data": "/i\\j", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #10", + "data": "/k\"l", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #11", + "data": "/ ", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #12", + "data": "/m~0n", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer used adding to the last array position", + "data": "/foo/-", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer (- used as object member name)", + "data": "/foo/-/bar", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer (multiple escaped characters)", + "data": "/~1~0~0~1~1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer (escaped with fraction part) #1", + "data": "/~1.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer (escaped with fraction part) #2", + "data": "/~0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #1", + "data": "#", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #2", + "data": "#/", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #3", + "data": "#a", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (some escaped, but not all) #1", + "data": "/~0~", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (some escaped, but not all) #2", + "data": "/~0/~", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (wrong escape character) #1", + "data": "/~2", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (wrong escape character) #2", + "data": "/~-1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (multiple characters not escaped)", + "data": "/~~", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #1", + "data": "a", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #2", + "data": "0", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #3", + "data": "a/a", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/regex.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/regex.json new file mode 100644 index 000000000..44ecb6290 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/regex.json @@ -0,0 +1,60 @@ +[ + { + "description": "validation of regular expressions", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "regex" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid regular expression", + "data": "([abc])+\\s+$", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a regular expression with unclosed parens is invalid", + "data": "^(abc]", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/relative-json-pointer.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/relative-json-pointer.json new file mode 100644 index 000000000..35db5456e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/relative-json-pointer.json @@ -0,0 +1,120 @@ +[ + { + "description": "validation of Relative JSON Pointers (RJP)", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "relative-json-pointer" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid upwards RJP", + "data": "1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid downwards RJP", + "data": "0/foo/bar", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid up and then down RJP, with array index", + "data": "2/0/baz/1/zip", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid RJP taking the member or index name", + "data": "0#", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid RJP that is a valid JSON Pointer", + "data": "/foo/bar", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "negative prefix", + "data": "-1/foo/bar", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "explicit positive prefix", + "data": "+1/foo/bar", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "## is not a valid json-pointer", + "data": "0##", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "zero cannot be followed by other digits, plus json-pointer", + "data": "01/a", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "zero cannot be followed by other digits, plus octothorpe", + "data": "01#", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty string", + "data": "", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "multi-digit integer prefix", + "data": "120/foo/bar", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/time.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/time.json new file mode 100644 index 000000000..5b9327254 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/time.json @@ -0,0 +1,282 @@ +[ + { + "description": "validation of time strings", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "time" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid time string", + "data": "08:30:06Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid time string with extra leading zeros", + "data": "008:030:006Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid time string with no leading zero for single digit", + "data": "8:3:6Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "hour, minute, second must be two digits", + "data": "8:0030:6Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid time string with leap second, Zulu", + "data": "23:59:60Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, Zulu (wrong hour)", + "data": "22:59:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, Zulu (wrong minute)", + "data": "23:58:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid leap second, zero time-offset", + "data": "23:59:60+00:00", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, zero time-offset (wrong hour)", + "data": "22:59:60+00:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, zero time-offset (wrong minute)", + "data": "23:58:60+00:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid leap second, positive time-offset", + "data": "01:29:60+01:30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid leap second, large positive time-offset", + "data": "23:29:60+23:30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, positive time-offset (wrong hour)", + "data": "23:59:60+01:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, positive time-offset (wrong minute)", + "data": "23:59:60+00:30", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid leap second, negative time-offset", + "data": "15:59:60-08:00", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid leap second, large negative time-offset", + "data": "00:29:60-23:30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, negative time-offset (wrong hour)", + "data": "23:59:60-01:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, negative time-offset (wrong minute)", + "data": "23:59:60-00:30", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid time string with second fraction", + "data": "23:20:50.52Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid time string with precise second fraction", + "data": "08:30:06.283185Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid time string with plus offset", + "data": "08:30:06+00:20", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid time string with minus offset", + "data": "08:30:06-08:00", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "hour, minute in time-offset must be two digits", + "data": "08:30:06-8:000", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid time string with case-insensitive Z", + "data": "08:30:06z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid hour", + "data": "24:00:00Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid minute", + "data": "00:60:00Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid second", + "data": "00:00:61Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid leap second (wrong hour)", + "data": "22:59:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid leap second (wrong minute)", + "data": "23:58:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid time numoffset hour", + "data": "01:02:03+24:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid time numoffset minute", + "data": "01:02:03+00:60", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid time with both Z and numoffset", + "data": "01:02:03Z+00:30", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid offset indicator", + "data": "08:30:06 PST", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "01:01:01,1111", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no time offset", + "data": "12:00:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no time offset with second fraction", + "data": "12:00:00.52", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '২' (a Bengali 2)", + "data": "1২:00:00Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "offset not starting with plus or minus", + "data": "08:30:06#00:20", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "contains letters", + "data": "ab:cd:ef", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/unknown.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/unknown.json new file mode 100644 index 000000000..77916769c --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/unknown.json @@ -0,0 +1,54 @@ +[ + { + "description": "unknown format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "unknown" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "unknown formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore strings", + "data": "string", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/uri-reference.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/uri-reference.json new file mode 100644 index 000000000..636d850c1 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/uri-reference.json @@ -0,0 +1,90 @@ +[ + { + "description": "validation of URI References", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "uri-reference" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URI", + "data": "http://foo.bar/?baz=qux#quux", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid protocol-relative URI Reference", + "data": "//foo.bar/?baz=qux#quux", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid relative URI Reference", + "data": "/abc", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI Reference", + "data": "\\\\WINDOWS\\fileshare", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid URI Reference", + "data": "abc", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URI fragment", + "data": "#fragment", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI fragment", + "data": "#frag\\ment", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/uri-template.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/uri-template.json new file mode 100644 index 000000000..50031744b --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/uri-template.json @@ -0,0 +1,72 @@ +[ + { + "description": "format: uri-template", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "uri-template" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid uri-template", + "data": "http://example.com/dictionary/{term:1}/{term}", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid uri-template", + "data": "http://example.com/dictionary/{term:1}/{term", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid uri-template without variables", + "data": "http://example.com/dictionary", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid relative uri-template", + "data": "dictionary/{term:1}/{term}", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/uri.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/uri.json new file mode 100644 index 000000000..79fe2eb13 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/uri.json @@ -0,0 +1,168 @@ +[ + { + "description": "validation of URIs", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "uri" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with anchor tag", + "data": "http://foo.bar/?baz=qux#quux", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with anchor tag and parentheses", + "data": "http://foo.com/blah_(wikipedia)_blah#cite-1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with URL-encoded stuff", + "data": "http://foo.bar/?q=Test%20URL-encoded%20stuff", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid puny-coded URL ", + "data": "http://xn--nw2a.xn--j6w193g/", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with many special characters", + "data": "http://-.~_!$\u0026'()*+,;=:%40:80%2f::::::@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL based on IPv4", + "data": "http://223.255.255.254", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with ftp scheme", + "data": "ftp://ftp.is.co.za/rfc/rfc1808.txt", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL for a simple text file", + "data": "http://www.ietf.org/rfc/rfc2396.txt", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL ", + "data": "ldap://[2001:db8::7]/c=GB?objectClass?one", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid mailto URI", + "data": "mailto:John.Doe@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid newsgroup URI", + "data": "news:comp.infosystems.www.servers.unix", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid tel URI", + "data": "tel:+1-816-555-1212", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URN", + "data": "urn:oasis:names:specification:docbook:dtd:xml:4.1.2", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid protocol-relative URI Reference", + "data": "//foo.bar/?baz=qux#quux", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid relative URI Reference", + "data": "/abc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI", + "data": "\\\\WINDOWS\\fileshare", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI though valid URI reference", + "data": "abc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI with spaces", + "data": "http:// shouldfail.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI with spaces and missing scheme", + "data": ":// should fail", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI with comma in scheme", + "data": "bar,baz:foo", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/uuid.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/uuid.json new file mode 100644 index 000000000..e0aaaea01 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/format/uuid.json @@ -0,0 +1,138 @@ +[ + { + "description": "uuid format", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "format": "uuid" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all upper-case", + "data": "2EB8AA08-AA98-11EA-B4AA-73B441D16380", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all lower-case", + "data": "2eb8aa08-aa98-11ea-b4aa-73b441d16380", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mixed case", + "data": "2eb8aa08-AA98-11ea-B4Aa-73B441D16380", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all zeroes is valid", + "data": "00000000-0000-0000-0000-000000000000", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "wrong length", + "data": "2eb8aa08-aa98-11ea-b4aa-73b441d1638", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "missing section", + "data": "2eb8aa08-aa98-11ea-73b441d16380", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "bad characters (not hex)", + "data": "2eb8aa08-aa98-11ea-b4ga-73b441d16380", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no dashes", + "data": "2eb8aa08aa9811eab4aa73b441d16380", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "too few dashes", + "data": "2eb8aa08aa98-11ea-b4aa73b441d16380", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "too many dashes", + "data": "2eb8-aa08-aa98-11ea-b4aa73b44-1d16380", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "dashes in the wrong spot", + "data": "2eb8aa08aa9811eab4aa73b441d16380----", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid version 4", + "data": "98d80576-482e-427f-8434-7f86890ab222", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid version 5", + "data": "99c17cbb-656f-564a-940f-1a4568f03487", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "hypothetical version 6", + "data": "99c17cbb-656f-664a-940f-1a4568f03487", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "hypothetical version 15", + "data": "99c17cbb-656f-f64a-940f-1a4568f03487", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/id.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/id.json new file mode 100644 index 000000000..bc9363cf7 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/id.json @@ -0,0 +1,61 @@ +[ + { + "description": "$id inside an enum is not a real identifier", + "comment": "the implementation must not be confused by an $id buried in the enum", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "id_in_enum": { + "enum": [ + { + "$id": "https://localhost:1234/draft2020-12/id/my_identifier.json", + "type": "null" + } + ] + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/draft2020-12/id/my_identifier.json", + "type": "string" + }, + "zzz_id_in_const": { + "const": { + "$id": "https://localhost:1234/draft2020-12/id/my_identifier.json", + "type": "null" + } + } + }, + "anyOf": [ + { + "$ref": "#/$defs/id_in_enum" + }, + { + "$ref": "https://localhost:1234/draft2020-12/id/my_identifier.json" + } + ] + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2020-12/id/my_identifier.json:my_identifier\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "$id": "https://localhost:1234/draft2020-12/id/my_identifier.json", + "type": "null" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "match $ref to $id", + "data": "a string to match #/$defs/id_in_enum", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "no match on enum or $ref to $id", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/no-schema.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/no-schema.json new file mode 100644 index 000000000..45f3f5125 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/no-schema.json @@ -0,0 +1,26 @@ +[ + { + "description": "validation without $schema", + "comment": "minLength is the same across all drafts", + "schema": { + "minLength": 2 + }, + "tests": [ + { + "description": "a 3-character string is valid", + "data": "foo", + "valid": true + }, + { + "description": "a 1-character string is not valid", + "data": "a", + "valid": false + }, + { + "description": "a non-string is valid", + "data": 5, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/non-bmp-regex.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/non-bmp-regex.json new file mode 100644 index 000000000..d80b04405 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/non-bmp-regex.json @@ -0,0 +1,96 @@ +[ + { + "description": "Proper UTF-16 surrogate pair handling: pattern", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "pattern": "^🐲*$" + }, + "tests": [ + { + "description": "matches empty", + "data": "", + "valid": true + }, + { + "description": "matches single", + "data": "🐲", + "valid": true + }, + { + "description": "matches two", + "data": "🐲🐲", + "valid": true + }, + { + "description": "doesn't match one", + "data": "🐉", + "valid": false + }, + { + "description": "doesn't match two", + "data": "🐉🐉", + "valid": false + }, + { + "description": "doesn't match one ASCII", + "data": "D", + "valid": false + }, + { + "description": "doesn't match two ASCII", + "data": "DD", + "valid": false + } + ] + }, + { + "description": "Proper UTF-16 surrogate pair handling: patternProperties", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "patternProperties": { + "^🐲*$": { + "type": "integer" + } + } + }, + "tests": [ + { + "description": "matches empty", + "data": { + "": 1 + }, + "valid": true + }, + { + "description": "matches single", + "data": { + "🐲": 1 + }, + "valid": true + }, + { + "description": "matches two", + "data": { + "🐲🐲": 1 + }, + "valid": true + }, + { + "description": "doesn't match one", + "data": { + "🐲": "hello" + }, + "valid": false + }, + { + "description": "doesn't match two", + "data": { + "🐲🐲": "hello" + }, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/refOfUnknownKeyword.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/refOfUnknownKeyword.json new file mode 100644 index 000000000..59dae8ed5 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/refOfUnknownKeyword.json @@ -0,0 +1,98 @@ +[ + { + "description": "reference of a root arbitrary keyword ", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unknown-keyword": { + "type": "integer" + }, + "properties": { + "bar": { + "$ref": "#/unknown-keyword" + } + } + }, + "skip": "extract error: unsupported constraint \"unknown-keyword\"", + "tests": [ + { + "description": "match", + "data": { + "bar": 3 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": { + "bar": true + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "reference of an arbitrary keyword of a sub-schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": { + "unknown-keyword": { + "type": "integer" + } + }, + "bar": { + "$ref": "#/properties/foo/unknown-keyword" + } + } + }, + "skip": "extract error: unsupported constraint \"unknown-keyword\"", + "tests": [ + { + "description": "match", + "data": { + "bar": 3 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": { + "bar": true + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "reference internals of known non-applicator", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "/base", + "examples": [ + { + "type": "string" + } + ], + "$ref": "#/examples/0" + }, + "skip": "extract error: reference to non-existing value \"examples\"", + "tests": [ + { + "description": "match", + "data": "a string", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": 42, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/unknownKeyword.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/unknownKeyword.json new file mode 100644 index 000000000..e69744a08 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/optional/unknownKeyword.json @@ -0,0 +1,67 @@ +[ + { + "description": "$id inside an unknown keyword is not a real identifier", + "comment": "the implementation must not be confused by an $id in locations we do not know how to parse", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "id_in_unknown0": { + "not": { + "array_of_schemas": [ + { + "$id": "https://localhost:1234/draft2020-12/unknownKeyword/my_identifier.json", + "type": "null" + } + ] + } + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/draft2020-12/unknownKeyword/my_identifier.json", + "type": "string" + }, + "id_in_unknown1": { + "not": { + "object_of_schemas": { + "foo": { + "$id": "https://localhost:1234/draft2020-12/unknownKeyword/my_identifier.json", + "type": "integer" + } + } + } + } + }, + "anyOf": [ + { + "$ref": "#/$defs/id_in_unknown0" + }, + { + "$ref": "#/$defs/id_in_unknown1" + }, + { + "$ref": "https://localhost:1234/draft2020-12/unknownKeyword/my_identifier.json" + } + ] + }, + "skip": "extract error: unsupported constraint \"not\" (and 1 more errors)", + "tests": [ + { + "description": "type matches second anyOf, which has a real schema in it", + "data": "a string", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "type matches non-schema in first anyOf", + "data": null, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "type matches non-schema in third anyOf", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/pattern.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/pattern.json new file mode 100644 index 000000000..4e5f3fc24 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/pattern.json @@ -0,0 +1,65 @@ +[ + { + "description": "pattern validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "pattern": "^a*$" + }, + "tests": [ + { + "description": "a matching pattern is valid", + "data": "aaa", + "valid": true + }, + { + "description": "a non-matching pattern is invalid", + "data": "abc", + "valid": false + }, + { + "description": "ignores booleans", + "data": true, + "valid": true + }, + { + "description": "ignores integers", + "data": 123, + "valid": true + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true + }, + { + "description": "ignores objects", + "data": {}, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores null", + "data": null, + "valid": true + } + ] + }, + { + "description": "pattern is not anchored", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "pattern": "a+" + }, + "tests": [ + { + "description": "matches a substring", + "data": "xxaayy", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/patternProperties.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/patternProperties.json new file mode 100644 index 000000000..d23b30094 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/patternProperties.json @@ -0,0 +1,233 @@ +[ + { + "description": "patternProperties validates properties matching a regex", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "patternProperties": { + "f.*o": { + "type": "integer" + } + } + }, + "tests": [ + { + "description": "a single valid match is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "multiple valid matches is valid", + "data": { + "foo": 1, + "foooooo": 2 + }, + "valid": true + }, + { + "description": "a single invalid match is invalid", + "data": { + "foo": "bar", + "fooooo": 2 + }, + "valid": false + }, + { + "description": "multiple invalid matches is invalid", + "data": { + "foo": "bar", + "foooooo": "baz" + }, + "valid": false + }, + { + "description": "ignores arrays", + "data": [ + "foo" + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foo", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "multiple simultaneous patternProperties are validated", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "patternProperties": { + "a*": { + "type": "integer" + }, + "aaa*": { + "maximum": 20 + } + } + }, + "tests": [ + { + "description": "a single valid match is valid", + "data": { + "a": 21 + }, + "valid": true + }, + { + "description": "a simultaneous match is valid", + "data": { + "aaaa": 18 + }, + "valid": true + }, + { + "description": "multiple matches is valid", + "data": { + "a": 21, + "aaaa": 18 + }, + "valid": true + }, + { + "description": "an invalid due to one is invalid", + "data": { + "a": "bar" + }, + "valid": false + }, + { + "description": "an invalid due to the other is invalid", + "data": { + "aaaa": 31 + }, + "valid": false + }, + { + "description": "an invalid due to both is invalid", + "data": { + "aaa": "foo", + "aaaa": 31 + }, + "valid": false + } + ] + }, + { + "description": "regexes are not anchored by default and are case sensitive", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "patternProperties": { + "[0-9]{2,}": { + "type": "boolean" + }, + "X_": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "non recognized members are ignored", + "data": { + "answer 1": "42" + }, + "valid": true + }, + { + "description": "recognized members are accounted for", + "data": { + "a31b": null + }, + "valid": false + }, + { + "description": "regexes are case sensitive", + "data": { + "a_x_3": 3 + }, + "valid": true + }, + { + "description": "regexes are case sensitive, 2", + "data": { + "a_X_3": 3 + }, + "valid": false + } + ] + }, + { + "description": "patternProperties with boolean schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "patternProperties": { + "f.*": true, + "b.*": false + } + }, + "tests": [ + { + "description": "object with property matching schema true is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "object with property matching schema false is invalid", + "data": { + "bar": 2 + }, + "valid": false + }, + { + "description": "object with both properties is invalid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false + }, + { + "description": "object with a property matching both true and false is invalid", + "data": { + "foobar": 1 + }, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "patternProperties with null valued instance properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "patternProperties": { + "^.*bar$": { + "type": "null" + } + } + }, + "tests": [ + { + "description": "allows null values", + "data": { + "foobar": null + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/prefixItems.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/prefixItems.json new file mode 100644 index 000000000..5c83a1a55 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/prefixItems.json @@ -0,0 +1,153 @@ +[ + { + "description": "a schema given for prefixItems", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { + "type": "integer" + }, + { + "type": "string" + } + ] + }, + "skip": "extract error: unsupported constraint \"prefixItems\"", + "tests": [ + { + "description": "correct types", + "data": [ + 1, + "foo" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "wrong types", + "data": [ + "foo", + 1 + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "incomplete array of items", + "data": [ + 1 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "array with additional items", + "data": [ + 1, + "foo", + true + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "empty array", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "JavaScript pseudo-array is valid", + "data": { + "0": "invalid", + "1": "valid", + "length": 2 + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "prefixItems with boolean schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + true, + false + ] + }, + "skip": "extract error: unsupported constraint \"prefixItems\"", + "tests": [ + { + "description": "array with one item is valid", + "data": [ + 1 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "array with two items is invalid", + "data": [ + 1, + "foo" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty array is valid", + "data": [], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "additional items are allowed by default", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { + "type": "integer" + } + ] + }, + "skip": "extract error: unsupported constraint \"prefixItems\"", + "tests": [ + { + "description": "only the first item is validated", + "data": [ + 1, + "foo", + false + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "prefixItems with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { + "type": "null" + } + ] + }, + "skip": "extract error: unsupported constraint \"prefixItems\"", + "tests": [ + { + "description": "allows null elements", + "data": [ + null + ], + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/properties.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/properties.json new file mode 100644 index 000000000..3dfc1f46f --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/properties.json @@ -0,0 +1,338 @@ +[ + { + "description": "object properties validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": { + "type": "integer" + }, + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "both properties present and valid is valid", + "data": { + "foo": 1, + "bar": "baz" + }, + "valid": true + }, + { + "description": "one property invalid is invalid", + "data": { + "foo": 1, + "bar": {} + }, + "valid": false + }, + { + "description": "both properties invalid is invalid", + "data": { + "foo": [], + "bar": {} + }, + "valid": false + }, + { + "description": "doesn't invalidate other properties", + "data": { + "quux": [] + }, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "properties, patternProperties, additionalProperties interaction", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": { + "type": "array", + "maxItems": 3 + }, + "bar": { + "type": "array" + } + }, + "patternProperties": { + "f.o": { + "minItems": 2 + } + }, + "additionalProperties": { + "type": "integer" + } + }, + "tests": [ + { + "description": "property validates property", + "data": { + "foo": [ + 1, + 2 + ] + }, + "valid": true + }, + { + "description": "property invalidates property", + "data": { + "foo": [ + 1, + 2, + 3, + 4 + ] + }, + "valid": false + }, + { + "description": "patternProperty invalidates property", + "data": { + "foo": [] + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "patternProperty validates nonproperty", + "data": { + "fxo": [ + 1, + 2 + ] + }, + "valid": true + }, + { + "description": "patternProperty invalidates nonproperty", + "data": { + "fxo": [] + }, + "valid": false + }, + { + "description": "additionalProperty ignores property", + "data": { + "bar": [] + }, + "valid": true + }, + { + "description": "additionalProperty validates others", + "data": { + "quux": 3 + }, + "valid": true + }, + { + "description": "additionalProperty invalidates others", + "data": { + "quux": "foo" + }, + "valid": false + } + ] + }, + { + "description": "properties with boolean schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": true, + "bar": false + } + }, + "tests": [ + { + "description": "no property present is valid", + "data": {}, + "valid": true + }, + { + "description": "only 'true' property present is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "only 'false' property present is invalid", + "data": { + "bar": 2 + }, + "valid": false + }, + { + "description": "both properties present is invalid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false + } + ] + }, + { + "description": "properties with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo\nbar": { + "type": "number" + }, + "foo\"bar": { + "type": "number" + }, + "foo\\bar": { + "type": "number" + }, + "foo\rbar": { + "type": "number" + }, + "foo\tbar": { + "type": "number" + }, + "foo\fbar": { + "type": "number" + } + } + }, + "tests": [ + { + "description": "object with all numbers is valid", + "data": { + "foo\nbar": 1, + "foo\"bar": 1, + "foo\\bar": 1, + "foo\rbar": 1, + "foo\tbar": 1, + "foo\fbar": 1 + }, + "valid": true + }, + { + "description": "object with strings is invalid", + "data": { + "foo\nbar": "1", + "foo\"bar": "1", + "foo\\bar": "1", + "foo\rbar": "1", + "foo\tbar": "1", + "foo\fbar": "1" + }, + "valid": false + } + ] + }, + { + "description": "properties with null valued instance properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": { + "type": "null" + } + } + }, + "tests": [ + { + "description": "allows null values", + "data": { + "foo": null + }, + "valid": true + } + ] + }, + { + "description": "properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "__proto__": { + "type": "number" + }, + "toString": { + "properties": { + "length": { + "type": "string" + } + } + }, + "constructor": { + "type": "number" + } + } + }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": true + }, + { + "description": "__proto__ not valid", + "data": { + "__proto__": "foo" + }, + "valid": false + }, + { + "description": "toString not valid", + "data": { + "toString": { + "length": 37 + } + }, + "valid": false + }, + { + "description": "constructor not valid", + "data": { + "constructor": { + "length": 37 + } + }, + "valid": false + }, + { + "description": "all present and valid", + "data": { + "__proto__": 12, + "toString": { + "length": "foo" + }, + "constructor": 37 + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/propertyNames.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/propertyNames.json new file mode 100644 index 000000000..d33d0c9e2 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/propertyNames.json @@ -0,0 +1,103 @@ +[ + { + "description": "propertyNames validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "propertyNames": { + "maxLength": 3 + } + }, + "skip": "extract error: cannot compile resulting schema: reference \"strings\" in label expression refers to field against which it would be matched:\n generated.cue:5:3\n", + "tests": [ + { + "description": "all property names valid", + "data": { + "f": {}, + "foo": {} + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "some property names invalid", + "data": { + "foo": {}, + "foobar": {} + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "object without properties is valid", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores arrays", + "data": [ + 1, + 2, + 3, + 4 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "propertyNames with boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "propertyNames": true + }, + "tests": [ + { + "description": "object with any properties is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "propertyNames with boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "propertyNames": false + }, + "tests": [ + { + "description": "object with any properties is invalid", + "data": { + "foo": 1 + }, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/ref.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/ref.json new file mode 100644 index 000000000..e939f5120 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/ref.json @@ -0,0 +1,1302 @@ +[ + { + "description": "root pointer ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": { + "$ref": "#" + } + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "match", + "data": { + "foo": false + }, + "valid": true + }, + { + "description": "recursive match", + "data": { + "foo": { + "foo": false + } + }, + "valid": true + }, + { + "description": "mismatch", + "data": { + "bar": false + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "recursive mismatch", + "data": { + "foo": { + "bar": false + } + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "relative pointer ref to object", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": { + "type": "integer" + }, + "bar": { + "$ref": "#/properties/foo" + } + } + }, + "skip": "extract error: cannot compile resulting schema: bar: reference \"foo\" not found:\n generated.cue:4:10\n", + "tests": [ + { + "description": "match", + "data": { + "bar": 3 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": { + "bar": true + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "relative pointer ref to array", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { + "type": "integer" + }, + { + "$ref": "#/prefixItems/0" + } + ] + }, + "skip": "extract error: unsupported constraint \"prefixItems\"", + "tests": [ + { + "description": "match array", + "data": [ + 1, + 2 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch array", + "data": [ + 1, + "foo" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "escaped pointer ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "tilde~field": { + "type": "integer" + }, + "slash/field": { + "type": "integer" + }, + "percent%field": { + "type": "integer" + } + }, + "properties": { + "tilde": { + "$ref": "#/$defs/tilde~0field" + }, + "slash": { + "$ref": "#/$defs/slash~1field" + }, + "percent": { + "$ref": "#/$defs/percent%25field" + } + } + }, + "tests": [ + { + "description": "slash invalid", + "data": { + "slash": "aoeu" + }, + "valid": false + }, + { + "description": "tilde invalid", + "data": { + "tilde": "aoeu" + }, + "valid": false + }, + { + "description": "percent invalid", + "data": { + "percent": "aoeu" + }, + "valid": false + }, + { + "description": "slash valid", + "data": { + "slash": 123 + }, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values [...] and {slash:123} (mismatched types list and struct):\n generated.cue:2:33\n instance.json:1:1\nconflicting values bool and {slash:123} (mismatched types bool and struct):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and {slash:123} (mismatched types null and struct):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and {slash:123} (mismatched types number and struct):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and {slash:123} (mismatched types string and struct):\n generated.cue:2:24\n instance.json:1:1\nslash: undefined field: \"slash~1field\":\n generated.cue:4:14\n" + }, + { + "description": "tilde valid", + "data": { + "tilde": 123 + }, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values [...] and {tilde:123} (mismatched types list and struct):\n generated.cue:2:33\n instance.json:1:1\nconflicting values bool and {tilde:123} (mismatched types bool and struct):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and {tilde:123} (mismatched types null and struct):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and {tilde:123} (mismatched types number and struct):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and {tilde:123} (mismatched types string and struct):\n generated.cue:2:24\n instance.json:1:1\ntilde: undefined field: \"tilde~0field\":\n generated.cue:3:14\n" + }, + { + "description": "percent valid", + "data": { + "percent": 123 + }, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values [...] and {percent:123} (mismatched types list and struct):\n generated.cue:2:33\n instance.json:1:1\nconflicting values bool and {percent:123} (mismatched types bool and struct):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and {percent:123} (mismatched types null and struct):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and {percent:123} (mismatched types number and struct):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and {percent:123} (mismatched types string and struct):\n generated.cue:2:24\n instance.json:1:1\npercent: undefined field: \"percent%25field\":\n generated.cue:5:14\n" + } + ] + }, + { + "description": "nested refs", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "a": { + "type": "integer" + }, + "b": { + "$ref": "#/$defs/a" + }, + "c": { + "$ref": "#/$defs/b" + } + }, + "$ref": "#/$defs/c" + }, + "tests": [ + { + "description": "nested ref valid", + "data": 5, + "valid": true + }, + { + "description": "nested ref invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "ref applies alongside sibling keywords", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "reffed": { + "type": "array" + } + }, + "properties": { + "foo": { + "$ref": "#/$defs/reffed", + "maxItems": 2 + } + } + }, + "tests": [ + { + "description": "ref valid, maxItems valid", + "data": { + "foo": [] + }, + "valid": true + }, + { + "description": "ref valid, maxItems invalid", + "data": { + "foo": [ + 1, + 2, + 3 + ] + }, + "valid": false + }, + { + "description": "ref invalid", + "data": { + "foo": "string" + }, + "valid": false + } + ] + }, + { + "description": "remote ref, containing refs itself", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "https://json-schema.org/draft/2020-12/schema" + }, + "skip": "extract error: cannot compile resulting schema: package \"json-schema.org/draft/2020-12/schema\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "remote ref valid", + "data": { + "minLength": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "remote ref invalid", + "data": { + "minLength": -1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "property named $ref that is not a reference", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "$ref": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": { + "$ref": "a" + }, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": { + "$ref": 2 + }, + "valid": false + } + ] + }, + { + "description": "property named $ref, containing an actual $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "$ref": { + "$ref": "#/$defs/is-string" + } + }, + "$defs": { + "is-string": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": { + "$ref": "a" + }, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": { + "$ref": 2 + }, + "valid": false + } + ] + }, + { + "description": "$ref to boolean schema true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "#/$defs/bool", + "$defs": { + "bool": true + } + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "$ref to boolean schema false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "#/$defs/bool", + "$defs": { + "bool": false + } + }, + "skip": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n generated.cue:4:8\n", + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "Recursive references between schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/tree", + "description": "tree of nodes", + "type": "object", + "properties": { + "meta": { + "type": "string" + }, + "nodes": { + "type": "array", + "items": { + "$ref": "node" + } + } + }, + "required": [ + "meta", + "nodes" + ], + "$defs": { + "node": { + "$id": "http://localhost:1234/draft2020-12/node", + "description": "node", + "type": "object", + "properties": { + "value": { + "type": "number" + }, + "subtree": { + "$ref": "tree" + } + }, + "required": [ + "value" + ] + } + } + }, + "skip": "extract error: cannot compile resulting schema: builtin package \"localhost:1234/draft2020-12/node\" undefined:\n generated.cue:1:8\n_schema.nodes: reference \"node\" not found:\n generated.cue:9:14\n", + "tests": [ + { + "description": "valid tree", + "data": { + "meta": "root", + "nodes": [ + { + "value": 1, + "subtree": { + "meta": "child", + "nodes": [ + { + "value": 1.1 + }, + { + "value": 1.2 + } + ] + } + }, + { + "value": 2, + "subtree": { + "meta": "child", + "nodes": [ + { + "value": 2.1 + }, + { + "value": 2.2 + } + ] + } + } + ] + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid tree", + "data": { + "meta": "root", + "nodes": [ + { + "value": 1, + "subtree": { + "meta": "child", + "nodes": [ + { + "value": "string is invalid" + }, + { + "value": 1.2 + } + ] + } + }, + { + "value": 2, + "subtree": { + "meta": "child", + "nodes": [ + { + "value": 2.1 + }, + { + "value": 2.2 + } + ] + } + } + ] + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "refs with quote", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo\"bar": { + "$ref": "#/$defs/foo%22bar" + } + }, + "$defs": { + "foo\"bar": { + "type": "number" + } + } + }, + "tests": [ + { + "description": "object with numbers is valid", + "data": { + "foo\"bar": 1 + }, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values [...] and {\"foo\\\"bar\":1} (mismatched types list and struct):\n generated.cue:2:33\n instance.json:1:1\nconflicting values bool and {\"foo\\\"bar\":1} (mismatched types bool and struct):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and {\"foo\\\"bar\":1} (mismatched types null and struct):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and {\"foo\\\"bar\":1} (mismatched types number and struct):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and {\"foo\\\"bar\":1} (mismatched types string and struct):\n generated.cue:2:24\n instance.json:1:1\n\"foo\\\"bar\": undefined field: \"foo%22bar\":\n generated.cue:3:17\n" + }, + { + "description": "object with strings is invalid", + "data": { + "foo\"bar": "1" + }, + "valid": false + } + ] + }, + { + "description": "ref creates new scope when adjacent to keywords", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "A": { + "unevaluatedProperties": false + } + }, + "properties": { + "prop1": { + "type": "string" + } + }, + "$ref": "#/$defs/A" + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "referenced subschema doesn't see annotations from properties", + "data": { + "prop1": "match" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "naive replacement of $ref with its destination is not correct", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "a_string": { + "type": "string" + } + }, + "enum": [ + { + "$ref": "#/$defs/a_string" + } + ] + }, + "tests": [ + { + "description": "do not evaluate the $ref inside the enum, matching any string", + "data": "this is a string", + "valid": false + }, + { + "description": "do not evaluate the $ref inside the enum, definition exact match", + "data": { + "type": "string" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "match the enum exactly", + "data": { + "$ref": "#/$defs/a_string" + }, + "valid": true + } + ] + }, + { + "description": "refs with relative uris and defs", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://example.com/schema-relative-uri-defs1.json", + "properties": { + "foo": { + "$id": "schema-relative-uri-defs2.json", + "$defs": { + "inner": { + "properties": { + "bar": { + "type": "string" + } + } + } + }, + "$ref": "#/$defs/inner" + } + }, + "$ref": "schema-relative-uri-defs2.json" + }, + "skip": "extract error: cannot compile resulting schema: package \"example.com/schema-relative-uri-defs2.json:schema\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "invalid on inner field", + "data": { + "foo": { + "bar": 1 + }, + "bar": "a" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid on outer field", + "data": { + "foo": { + "bar": "a" + }, + "bar": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid on both fields", + "data": { + "foo": { + "bar": "a" + }, + "bar": "a" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "relative refs with absolute uris and defs", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://example.com/schema-refs-absolute-uris-defs1.json", + "properties": { + "foo": { + "$id": "http://example.com/schema-refs-absolute-uris-defs2.json", + "$defs": { + "inner": { + "properties": { + "bar": { + "type": "string" + } + } + } + }, + "$ref": "#/$defs/inner" + } + }, + "$ref": "schema-refs-absolute-uris-defs2.json" + }, + "skip": "extract error: cannot compile resulting schema: package \"example.com/schema-refs-absolute-uris-defs2.json:schema\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "invalid on inner field", + "data": { + "foo": { + "bar": 1 + }, + "bar": "a" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid on outer field", + "data": { + "foo": { + "bar": "a" + }, + "bar": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid on both fields", + "data": { + "foo": { + "bar": "a" + }, + "bar": "a" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$id must be resolved against nearest parent, not just immediate parent", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://example.com/a.json", + "$defs": { + "x": { + "$id": "http://example.com/b/c.json", + "not": { + "$defs": { + "y": { + "$id": "d.json", + "type": "number" + } + } + } + } + }, + "allOf": [ + { + "$ref": "http://example.com/b/d.json" + } + ] + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "order of evaluation: $id and $ref", + "schema": { + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/draft2020-12/ref-and-id1/base.json", + "$ref": "int.json", + "$defs": { + "bigint": { + "$comment": "canonical uri: https://example.com/ref-and-id1/int.json", + "$id": "int.json", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: https://example.com/ref-and-id1-int.json", + "$id": "/draft2020-12/ref-and-id1-int.json", + "maximum": 2 + } + } + }, + "skip": "extract error: cannot compile resulting schema: package \"example.com/draft2020-12/ref-and-id1/int.json:int\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "order of evaluation: $id and $anchor and $ref", + "schema": { + "$comment": "$id must be evaluated before $ref to get the proper $ref destination", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/draft2020-12/ref-and-id2/base.json", + "$ref": "#bigint", + "$defs": { + "bigint": { + "$comment": "canonical uri: /ref-and-id2/base.json#/$defs/bigint; another valid uri for this location: /ref-and-id2/base.json#bigint", + "$anchor": "bigint", + "maximum": 10 + }, + "smallint": { + "$comment": "canonical uri: https://example.com/ref-and-id2#/$defs/smallint; another valid uri for this location: https://example.com/ref-and-id2/#bigint", + "$id": "https://example.com/draft2020-12/ref-and-id2/", + "$anchor": "bigint", + "maximum": 2 + } + } + }, + "skip": "extract error: anchors (bigint) not supported (and 2 more errors)", + "tests": [ + { + "description": "data is valid against first definition", + "data": 5, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "data is invalid against first definition", + "data": 50, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "simple URN base URI with $ref via the URN", + "schema": { + "$comment": "URIs do not have to have HTTP(s) schemes", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed", + "minimum": 30, + "properties": { + "foo": { + "$ref": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed" + } + } + }, + "tests": [ + { + "description": "valid under the URN IDed schema", + "data": { + "foo": 37 + }, + "valid": true + }, + { + "description": "invalid under the URN IDed schema", + "data": { + "foo": 12 + }, + "valid": false + } + ] + }, + { + "description": "simple URN base URI with JSON pointer", + "schema": { + "$comment": "URIs do not have to have HTTP(s) schemes", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "urn:uuid:deadbeef-1234-00ff-ff00-4321feebdaed", + "properties": { + "foo": { + "$ref": "#/$defs/bar" + } + }, + "$defs": { + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false + } + ] + }, + { + "description": "URN base URI with NSS", + "schema": { + "$comment": "RFC 8141 §2.2", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "urn:example:1/406/47452/2", + "properties": { + "foo": { + "$ref": "#/$defs/bar" + } + }, + "$defs": { + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false + } + ] + }, + { + "description": "URN base URI with r-component", + "schema": { + "$comment": "RFC 8141 §2.3.1", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "urn:example:foo-bar-baz-qux?+CCResolve:cc=uk", + "properties": { + "foo": { + "$ref": "#/$defs/bar" + } + }, + "$defs": { + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false + } + ] + }, + { + "description": "URN base URI with q-component", + "schema": { + "$comment": "RFC 8141 §2.3.2", + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "urn:example:weather?=op=map\u0026lat=39.56\u0026lon=-104.85\u0026datetime=1969-07-21T02:56:15Z", + "properties": { + "foo": { + "$ref": "#/$defs/bar" + } + }, + "$defs": { + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false + } + ] + }, + { + "description": "URN base URI with URN and JSON pointer ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed", + "properties": { + "foo": { + "$ref": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed#/$defs/bar" + } + }, + "$defs": { + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false + } + ] + }, + { + "description": "URN base URI with URN and anchor ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed", + "properties": { + "foo": { + "$ref": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed#something" + } + }, + "$defs": { + "bar": { + "$anchor": "something", + "type": "string" + } + } + }, + "skip": "extract error: anchors (something) not supported (and 1 more errors)", + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "URN ref with nested pointer ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed", + "$defs": { + "foo": { + "$id": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed", + "$defs": { + "bar": { + "type": "string" + } + }, + "$ref": "#/$defs/bar" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": "bar", + "valid": true, + "skip": "conflicting values \"bar\" and {_schema:{#foo:string},#foo:string} (mismatched types string and struct):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "a non-string is invalid", + "data": 12, + "valid": false + } + ] + }, + { + "description": "ref to if", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "http://example.com/ref/if", + "if": { + "$id": "http://example.com/ref/if", + "type": "integer" + } + }, + "skip": "extract error: unsupported constraint \"if\"", + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ref to then", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "http://example.com/ref/then", + "then": { + "$id": "http://example.com/ref/then", + "type": "integer" + } + }, + "skip": "extract error: unsupported constraint \"then\"", + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ref to else", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "http://example.com/ref/else", + "else": { + "$id": "http://example.com/ref/else", + "type": "integer" + } + }, + "skip": "extract error: unsupported constraint \"else\"", + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ref with absolute-path-reference", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://example.com/ref/absref.json", + "$defs": { + "a": { + "$id": "http://example.com/ref/absref/foobar.json", + "type": "number" + }, + "b": { + "$id": "http://example.com/absref/foobar.json", + "type": "string" + } + }, + "$ref": "/absref/foobar.json" + }, + "skip": "extract error: cannot compile resulting schema: package \"example.com/absref/foobar.json:foobar\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "a string is valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an integer is invalid", + "data": 12, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$id with file URI still resolves pointers - *nix", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "file:///folder/file.json", + "$defs": { + "foo": { + "type": "number" + } + }, + "$ref": "#/$defs/foo" + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "$id with file URI still resolves pointers - windows", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "file:///c:/folder/file.json", + "$defs": { + "foo": { + "type": "number" + } + }, + "$ref": "#/$defs/foo" + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "empty tokens in $ref json-pointer", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "": { + "$defs": { + "": { + "type": "number" + } + } + } + }, + "allOf": [ + { + "$ref": "#/$defs//$defs/" + } + ] + }, + "skip": "extract error: cannot refer to $defs section: must refer to one of its elements", + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/refRemote.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/refRemote.json new file mode 100644 index 000000000..36365ad4e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/refRemote.json @@ -0,0 +1,434 @@ +[ + { + "description": "remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "http://localhost:1234/draft2020-12/integer.json" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2020-12/integer.json:integer\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "remote ref valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "remote ref invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "fragment within remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "http://localhost:1234/draft2020-12/subSchemas.json#/$defs/integer" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2020-12/subSchemas.json:subSchemas\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "remote fragment valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "remote fragment invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "anchor within remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "http://localhost:1234/draft2020-12/locationIndependentIdentifier.json#foo" + }, + "skip": "extract error: anchors (foo) not supported", + "tests": [ + { + "description": "remote anchor valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "remote anchor invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ref within remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "http://localhost:1234/draft2020-12/subSchemas.json#/$defs/refToInteger" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2020-12/subSchemas.json:subSchemas\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "ref within ref valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ref within ref invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "base URI change", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/", + "items": { + "$id": "baseUriChange/", + "items": { + "$ref": "folderInteger.json" + } + } + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2020-12/baseUriChange/folderInteger.json:folderInteger\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "base URI change ref valid", + "data": [ + [ + 1 + ] + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "base URI change ref invalid", + "data": [ + [ + "a" + ] + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "base URI change - change folder", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/scope_change_defs1.json", + "type": "object", + "properties": { + "list": { + "$ref": "baseUriChangeFolder/" + } + }, + "$defs": { + "baz": { + "$id": "baseUriChangeFolder/", + "type": "array", + "items": { + "$ref": "folderInteger.json" + } + } + } + }, + "skip": "extract error: cannot determine package name from import path \"localhost:1234/draft2020-12/baseUriChangeFolder/\"", + "tests": [ + { + "description": "number is valid", + "data": { + "list": [ + 1 + ] + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": { + "list": [ + "a" + ] + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "base URI change - change folder in subschema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/scope_change_defs2.json", + "type": "object", + "properties": { + "list": { + "$ref": "baseUriChangeFolderInSubschema/#/$defs/bar" + } + }, + "$defs": { + "baz": { + "$id": "baseUriChangeFolderInSubschema/", + "$defs": { + "bar": { + "type": "array", + "items": { + "$ref": "folderInteger.json" + } + } + } + } + } + }, + "skip": "extract error: cannot determine package name from import path \"localhost:1234/draft2020-12/baseUriChangeFolderInSubschema/\"", + "tests": [ + { + "description": "number is valid", + "data": { + "list": [ + 1 + ] + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": { + "list": [ + "a" + ] + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "root ref in remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/object", + "type": "object", + "properties": { + "name": { + "$ref": "name-defs.json#/$defs/orNull" + } + } + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2020-12/name-defs.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "string is valid", + "data": { + "name": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "null is valid", + "data": { + "name": null + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "object is invalid", + "data": { + "name": { + "name": null + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "remote ref with ref to defs", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/schema-remote-ref-ref-defs1.json", + "$ref": "ref-and-defs.json" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2020-12/ref-and-defs.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "invalid", + "data": { + "bar": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid", + "data": { + "bar": "a" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "Location-independent identifier in remote ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "http://localhost:1234/draft2020-12/locationIndependentIdentifier.json#/$defs/refToInteger" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2020-12/locationIndependentIdentifier.json:locationIndependentIdentifier\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "integer is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "retrieved nested refs resolve relative to their URI not $id", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "http://localhost:1234/draft2020-12/some-id", + "properties": { + "name": { + "$ref": "nested/foo-ref-string.json" + } + } + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2020-12/nested/foo-ref-string.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is invalid", + "data": { + "name": { + "foo": 1 + } + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is valid", + "data": { + "name": { + "foo": "a" + } + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "remote HTTP ref with different $id", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "http://localhost:1234/different-id-ref-string.json" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/different-id-ref-string.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "remote HTTP ref with different URN $id", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "http://localhost:1234/urn-ref-string.json" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/urn-ref-string.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "remote HTTP ref with nested absolute ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "http://localhost:1234/nested-absolute-ref-to-string.json" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/nested-absolute-ref-to-string.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$ref to $ref finds detached $anchor", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "http://localhost:1234/draft2020-12/detached-ref.json#/$defs/foo" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2020-12/detached-ref.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/required.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/required.json new file mode 100644 index 000000000..f8f47c71d --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/required.json @@ -0,0 +1,186 @@ +[ + { + "description": "required validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": {}, + "bar": {} + }, + "required": [ + "foo" + ] + }, + "tests": [ + { + "description": "present required property is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "non-present required property is invalid", + "data": { + "bar": 1 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", + "data": "", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "required default validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": {} + } + }, + "tests": [ + { + "description": "not required by default", + "data": {}, + "valid": true + } + ] + }, + { + "description": "required with empty array", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": {} + }, + "required": [] + }, + "tests": [ + { + "description": "property not required", + "data": {}, + "valid": true + } + ] + }, + { + "description": "required with escaped characters", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "required": [ + "foo\nbar", + "foo\"bar", + "foo\\bar", + "foo\rbar", + "foo\tbar", + "foo\fbar" + ] + }, + "tests": [ + { + "description": "object with all properties present is valid", + "data": { + "foo\nbar": 1, + "foo\"bar": 1, + "foo\\bar": 1, + "foo\rbar": 1, + "foo\tbar": 1, + "foo\fbar": 1 + }, + "valid": true + }, + { + "description": "object with some properties missing is invalid", + "data": { + "foo\nbar": "1", + "foo\"bar": "1" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "required properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "required": [ + "__proto__", + "toString", + "constructor" + ] + }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "__proto__ present", + "data": { + "__proto__": "foo" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "toString present", + "data": { + "toString": { + "length": 37 + } + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "constructor present", + "data": { + "constructor": { + "length": 37 + } + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "all present", + "data": { + "__proto__": 12, + "toString": { + "length": "foo" + }, + "constructor": 37 + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/type.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/type.json new file mode 100644 index 000000000..1b17aba3c --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/type.json @@ -0,0 +1,526 @@ +[ + { + "description": "integer type matches integers", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "integer" + }, + "tests": [ + { + "description": "an integer is an integer", + "data": 1, + "valid": true + }, + { + "description": "a float with zero fractional part is an integer", + "data": 1.0, + "valid": true, + "skip": "conflicting values 1.0 and int (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "a float is not an integer", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an integer", + "data": "foo", + "valid": false + }, + { + "description": "a string is still not an integer, even if it looks like one", + "data": "1", + "valid": false + }, + { + "description": "an object is not an integer", + "data": {}, + "valid": false + }, + { + "description": "an array is not an integer", + "data": [], + "valid": false + }, + { + "description": "a boolean is not an integer", + "data": true, + "valid": false + }, + { + "description": "null is not an integer", + "data": null, + "valid": false + } + ] + }, + { + "description": "number type matches numbers", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "number" + }, + "tests": [ + { + "description": "an integer is a number", + "data": 1, + "valid": true + }, + { + "description": "a float with zero fractional part is a number (and an integer)", + "data": 1.0, + "valid": true + }, + { + "description": "a float is a number", + "data": 1.1, + "valid": true + }, + { + "description": "a string is not a number", + "data": "foo", + "valid": false + }, + { + "description": "a string is still not a number, even if it looks like one", + "data": "1", + "valid": false + }, + { + "description": "an object is not a number", + "data": {}, + "valid": false + }, + { + "description": "an array is not a number", + "data": [], + "valid": false + }, + { + "description": "a boolean is not a number", + "data": true, + "valid": false + }, + { + "description": "null is not a number", + "data": null, + "valid": false + } + ] + }, + { + "description": "string type matches strings", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "string" + }, + "tests": [ + { + "description": "1 is not a string", + "data": 1, + "valid": false + }, + { + "description": "a float is not a string", + "data": 1.1, + "valid": false + }, + { + "description": "a string is a string", + "data": "foo", + "valid": true + }, + { + "description": "a string is still a string, even if it looks like a number", + "data": "1", + "valid": true + }, + { + "description": "an empty string is still a string", + "data": "", + "valid": true + }, + { + "description": "an object is not a string", + "data": {}, + "valid": false + }, + { + "description": "an array is not a string", + "data": [], + "valid": false + }, + { + "description": "a boolean is not a string", + "data": true, + "valid": false + }, + { + "description": "null is not a string", + "data": null, + "valid": false + } + ] + }, + { + "description": "object type matches objects", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object" + }, + "tests": [ + { + "description": "an integer is not an object", + "data": 1, + "valid": false + }, + { + "description": "a float is not an object", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an object", + "data": "foo", + "valid": false + }, + { + "description": "an object is an object", + "data": {}, + "valid": true + }, + { + "description": "an array is not an object", + "data": [], + "valid": false + }, + { + "description": "a boolean is not an object", + "data": true, + "valid": false + }, + { + "description": "null is not an object", + "data": null, + "valid": false + } + ] + }, + { + "description": "array type matches arrays", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "array" + }, + "tests": [ + { + "description": "an integer is not an array", + "data": 1, + "valid": false + }, + { + "description": "a float is not an array", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an array", + "data": "foo", + "valid": false + }, + { + "description": "an object is not an array", + "data": {}, + "valid": false + }, + { + "description": "an array is an array", + "data": [], + "valid": true + }, + { + "description": "a boolean is not an array", + "data": true, + "valid": false + }, + { + "description": "null is not an array", + "data": null, + "valid": false + } + ] + }, + { + "description": "boolean type matches booleans", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "boolean" + }, + "tests": [ + { + "description": "an integer is not a boolean", + "data": 1, + "valid": false + }, + { + "description": "zero is not a boolean", + "data": 0, + "valid": false + }, + { + "description": "a float is not a boolean", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not a boolean", + "data": "foo", + "valid": false + }, + { + "description": "an empty string is not a boolean", + "data": "", + "valid": false + }, + { + "description": "an object is not a boolean", + "data": {}, + "valid": false + }, + { + "description": "an array is not a boolean", + "data": [], + "valid": false + }, + { + "description": "true is a boolean", + "data": true, + "valid": true + }, + { + "description": "false is a boolean", + "data": false, + "valid": true + }, + { + "description": "null is not a boolean", + "data": null, + "valid": false + } + ] + }, + { + "description": "null type matches only the null object", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "null" + }, + "tests": [ + { + "description": "an integer is not null", + "data": 1, + "valid": false + }, + { + "description": "a float is not null", + "data": 1.1, + "valid": false + }, + { + "description": "zero is not null", + "data": 0, + "valid": false + }, + { + "description": "a string is not null", + "data": "foo", + "valid": false + }, + { + "description": "an empty string is not null", + "data": "", + "valid": false + }, + { + "description": "an object is not null", + "data": {}, + "valid": false + }, + { + "description": "an array is not null", + "data": [], + "valid": false + }, + { + "description": "true is not null", + "data": true, + "valid": false + }, + { + "description": "false is not null", + "data": false, + "valid": false + }, + { + "description": "null is null", + "data": null, + "valid": true + } + ] + }, + { + "description": "multiple types can be specified in an array", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": [ + "integer", + "string" + ] + }, + "tests": [ + { + "description": "an integer is valid", + "data": 1, + "valid": true + }, + { + "description": "a string is valid", + "data": "foo", + "valid": true + }, + { + "description": "a float is invalid", + "data": 1.1, + "valid": false + }, + { + "description": "an object is invalid", + "data": {}, + "valid": false + }, + { + "description": "an array is invalid", + "data": [], + "valid": false + }, + { + "description": "a boolean is invalid", + "data": true, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + } + ] + }, + { + "description": "type as array with one item", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": [ + "string" + ] + }, + "tests": [ + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "type: array or object", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": [ + "array", + "object" + ] + }, + "tests": [ + { + "description": "array is valid", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "object is valid", + "data": { + "foo": 123 + }, + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + } + ] + }, + { + "description": "type: array, object or null", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": [ + "array", + "object", + "null" + ] + }, + "tests": [ + { + "description": "array is valid", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "object is valid", + "data": { + "foo": 123 + }, + "valid": true + }, + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/unevaluatedItems.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/unevaluatedItems.json new file mode 100644 index 000000000..1a9a6a74a --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/unevaluatedItems.json @@ -0,0 +1,1174 @@ +[ + { + "description": "unevaluatedItems true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unevaluatedItems": true + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "with no unevaluated items", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated items", + "data": [ + "foo" + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "with no unevaluated items", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated items", + "data": [ + "foo" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems as schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unevaluatedItems": { + "type": "string" + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "with no unevaluated items", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with valid unevaluated items", + "data": [ + "foo" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with invalid unevaluated items", + "data": [ + 42 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with uniform items", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "items": { + "type": "string" + }, + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "unevaluatedItems doesn't apply", + "data": [ + "foo", + "bar" + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with tuple", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { + "type": "string" + } + ], + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"prefixItems\" (and 1 more errors)", + "tests": [ + { + "description": "with no unevaluated items", + "data": [ + "foo" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated items", + "data": [ + "foo", + "bar" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with items and prefixItems", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { + "type": "string" + } + ], + "items": true, + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"prefixItems\" (and 2 more errors)", + "tests": [ + { + "description": "unevaluatedItems doesn't apply", + "data": [ + "foo", + 42 + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with items", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "items": { + "type": "number" + }, + "unevaluatedItems": { + "type": "string" + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "valid under items", + "comment": "no elements are considered by unevaluatedItems", + "data": [ + 5, + 6, + 7, + 8 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid under items", + "data": [ + "foo", + "bar", + "baz" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with nested tuple", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { + "type": "string" + } + ], + "allOf": [ + { + "prefixItems": [ + true, + { + "type": "number" + } + ] + } + ], + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"prefixItems\" (and 2 more errors)", + "tests": [ + { + "description": "with no unevaluated items", + "data": [ + "foo", + 42 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated items", + "data": [ + "foo", + 42, + true + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with nested items", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unevaluatedItems": { + "type": "boolean" + }, + "anyOf": [ + { + "items": { + "type": "string" + } + }, + true + ] + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "with only (valid) additional items", + "data": [ + true, + false + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with no additional items", + "data": [ + "yes", + "no" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with invalid additional item", + "data": [ + "yes", + false + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with nested prefixItems and items", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "prefixItems": [ + { + "type": "string" + } + ], + "items": true + } + ], + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\" (and 2 more errors)", + "tests": [ + { + "description": "with no additional items", + "data": [ + "foo" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with additional items", + "data": [ + "foo", + 42, + true + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with nested unevaluatedItems", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "prefixItems": [ + { + "type": "string" + } + ] + }, + { + "unevaluatedItems": true + } + ], + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\" (and 2 more errors)", + "tests": [ + { + "description": "with no additional items", + "data": [ + "foo" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with additional items", + "data": [ + "foo", + 42, + true + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with anyOf", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { + "const": "foo" + } + ], + "anyOf": [ + { + "prefixItems": [ + true, + { + "const": "bar" + } + ] + }, + { + "prefixItems": [ + true, + true, + { + "const": "baz" + } + ] + } + ], + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"prefixItems\" (and 3 more errors)", + "tests": [ + { + "description": "when one schema matches and has no unevaluated items", + "data": [ + "foo", + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "when one schema matches and has unevaluated items", + "data": [ + "foo", + "bar", + 42 + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "when two schemas match and has no unevaluated items", + "data": [ + "foo", + "bar", + "baz" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "when two schemas match and has unevaluated items", + "data": [ + "foo", + "bar", + "baz", + 42 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { + "const": "foo" + } + ], + "oneOf": [ + { + "prefixItems": [ + true, + { + "const": "bar" + } + ] + }, + { + "prefixItems": [ + true, + { + "const": "baz" + } + ] + } + ], + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"prefixItems\" (and 3 more errors)", + "tests": [ + { + "description": "with no unevaluated items", + "data": [ + "foo", + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated items", + "data": [ + "foo", + "bar", + 42 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with not", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { + "const": "foo" + } + ], + "not": { + "not": { + "prefixItems": [ + true, + { + "const": "bar" + } + ] + } + }, + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"prefixItems\" (and 2 more errors)", + "tests": [ + { + "description": "with unevaluated items", + "data": [ + "foo", + "bar" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with if/then/else", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { + "const": "foo" + } + ], + "if": { + "prefixItems": [ + true, + { + "const": "bar" + } + ] + }, + "then": { + "prefixItems": [ + true, + true, + { + "const": "then" + } + ] + }, + "else": { + "prefixItems": [ + true, + true, + true, + { + "const": "else" + } + ] + }, + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"prefixItems\" (and 4 more errors)", + "tests": [ + { + "description": "when if matches and it has no unevaluated items", + "data": [ + "foo", + "bar", + "then" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "when if matches and it has unevaluated items", + "data": [ + "foo", + "bar", + "then", + "else" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "when if doesn't match and it has no unevaluated items", + "data": [ + "foo", + 42, + 42, + "else" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "when if doesn't match and it has unevaluated items", + "data": [ + "foo", + 42, + 42, + "else", + 42 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with boolean schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + true + ], + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "with no unevaluated items", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated items", + "data": [ + "foo" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$ref": "#/$defs/bar", + "prefixItems": [ + { + "type": "string" + } + ], + "unevaluatedItems": false, + "$defs": { + "bar": { + "prefixItems": [ + true, + { + "type": "string" + } + ] + } + } + }, + "skip": "extract error: unsupported constraint \"prefixItems\" (and 2 more errors)", + "tests": [ + { + "description": "with no unevaluated items", + "data": [ + "foo", + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated items", + "data": [ + "foo", + "bar", + "baz" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems before $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unevaluatedItems": false, + "prefixItems": [ + { + "type": "string" + } + ], + "$ref": "#/$defs/bar", + "$defs": { + "bar": { + "prefixItems": [ + true, + { + "type": "string" + } + ] + } + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\" (and 2 more errors)", + "tests": [ + { + "description": "with no unevaluated items", + "data": [ + "foo", + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated items", + "data": [ + "foo", + "bar", + "baz" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with $dynamicRef", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/unevaluated-items-with-dynamic-ref/derived", + "$ref": "./baseSchema", + "$defs": { + "derived": { + "$dynamicAnchor": "addons", + "prefixItems": [ + true, + { + "type": "string" + } + ] + }, + "baseSchema": { + "$id": "./baseSchema", + "$comment": "unevaluatedItems comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering", + "unevaluatedItems": false, + "type": "array", + "prefixItems": [ + { + "type": "string" + } + ], + "$dynamicRef": "#addons", + "$defs": { + "defaultAddons": { + "$comment": "Needed to satisfy the bookending requirement", + "$dynamicAnchor": "addons" + } + } + } + } + }, + "skip": "extract error: unsupported constraint \"$dynamicAnchor\" (and 5 more errors)", + "tests": [ + { + "description": "with no unevaluated items", + "data": [ + "foo", + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated items", + "data": [ + "foo", + "bar", + "baz" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems can't see inside cousins", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "prefixItems": [ + true + ] + }, + { + "unevaluatedItems": false + } + ] + }, + "skip": "extract error: unsupported constraint \"prefixItems\" (and 1 more errors)", + "tests": [ + { + "description": "always fails", + "data": [ + 1 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "item is evaluated in an uncle schema to unevaluatedItems", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo": { + "prefixItems": [ + { + "type": "string" + } + ], + "unevaluatedItems": false + } + }, + "anyOf": [ + { + "properties": { + "foo": { + "prefixItems": [ + true, + { + "type": "string" + } + ] + } + } + } + ] + }, + "skip": "extract error: unsupported constraint \"prefixItems\" (and 2 more errors)", + "tests": [ + { + "description": "no extra items", + "data": { + "foo": [ + "test" + ] + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "uncle keyword evaluation is not significant", + "data": { + "foo": [ + "test", + "test" + ] + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems depends on adjacent contains", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + true + ], + "contains": { + "type": "string" + }, + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"prefixItems\" (and 1 more errors)", + "tests": [ + { + "description": "second item is evaluated by contains", + "data": [ + 1, + "foo" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "contains fails, second item is not evaluated", + "data": [ + 1, + 2 + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "contains passes, second item is not evaluated", + "data": [ + 1, + 2, + "foo" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems depends on multiple nested contains", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "contains": { + "multipleOf": 2 + } + }, + { + "contains": { + "multipleOf": 3 + } + } + ], + "unevaluatedItems": { + "multipleOf": 5 + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "5 not evaluated, passes unevaluatedItems", + "data": [ + 2, + 3, + 4, + 5, + 6 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "7 not evaluated, fails unevaluatedItems", + "data": [ + 2, + 3, + 4, + 7, + 8 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems and contains interact to control item dependency relationship", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "contains": { + "const": "a" + } + }, + "then": { + "if": { + "contains": { + "const": "b" + } + }, + "then": { + "if": { + "contains": { + "const": "c" + } + } + } + }, + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"if\" (and 2 more errors)", + "tests": [ + { + "description": "empty array is valid", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "only a's are valid", + "data": [ + "a", + "a" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a's and b's are valid", + "data": [ + "a", + "b", + "a", + "b", + "a" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a's, b's and c's are valid", + "data": [ + "c", + "a", + "c", + "c", + "b", + "a" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "only b's are invalid", + "data": [ + "b", + "b" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "only c's are invalid", + "data": [ + "c", + "c" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "only b's and c's are invalid", + "data": [ + "c", + "b", + "c", + "b", + "c" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "only a's and c's are invalid", + "data": [ + "c", + "a", + "c", + "a", + "c" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "non-array instances are valid", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "ignores booleans", + "data": true, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores integers", + "data": 123, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores strings", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores null", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems with null instance elements", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unevaluatedItems": { + "type": "null" + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedItems\"", + "tests": [ + { + "description": "allows null elements", + "data": [ + null + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedItems can see annotations from if without then and else", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "prefixItems": [ + { + "const": "a" + } + ] + }, + "unevaluatedItems": false + }, + "skip": "extract error: unsupported constraint \"if\" (and 1 more errors)", + "tests": [ + { + "description": "valid in case if is evaluated", + "data": [ + "a" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid in case if is evaluated", + "data": [ + "b" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/unevaluatedProperties.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/unevaluatedProperties.json new file mode 100644 index 000000000..784f29d9d --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/unevaluatedProperties.json @@ -0,0 +1,2056 @@ +[ + { + "description": "unevaluatedProperties true", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "unevaluatedProperties": true + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no unevaluated properties", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties schema", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "unevaluatedProperties": { + "type": "string", + "minLength": 3 + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no unevaluated properties", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with valid unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with invalid unevaluated properties", + "data": { + "foo": "fo" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no unevaluated properties", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with adjacent properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with adjacent patternProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "patternProperties": { + "^foo": { + "type": "string" + } + }, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with adjacent additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "additionalProperties": true, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no additional properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with additional properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with nested properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "allOf": [ + { + "properties": { + "bar": { + "type": "string" + } + } + } + ], + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no additional properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with additional properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with nested patternProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "allOf": [ + { + "patternProperties": { + "^bar": { + "type": "string" + } + } + } + ], + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no additional properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with additional properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with nested additionalProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "allOf": [ + { + "additionalProperties": true + } + ], + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no additional properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with additional properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with nested unevaluatedProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "allOf": [ + { + "unevaluatedProperties": true + } + ], + "unevaluatedProperties": { + "type": "string", + "maxLength": 2 + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\" (and 1 more errors)", + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with anyOf", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "anyOf": [ + { + "properties": { + "bar": { + "const": "bar" + } + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "baz": { + "const": "baz" + } + }, + "required": [ + "baz" + ] + }, + { + "properties": { + "quux": { + "const": "quux" + } + }, + "required": [ + "quux" + ] + } + ], + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "when one matches and has no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "when one matches and has unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "not-baz" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "when two match and has no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "when two match and has unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz", + "quux": "not-quux" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "oneOf": [ + { + "properties": { + "bar": { + "const": "bar" + } + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "baz": { + "const": "baz" + } + }, + "required": [ + "baz" + ] + } + ], + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "quux": "quux" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with not", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "not": { + "not": { + "properties": { + "bar": { + "const": "bar" + } + }, + "required": [ + "bar" + ] + } + }, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"not\" (and 1 more errors)", + "tests": [ + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with if/then/else", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "if": { + "properties": { + "foo": { + "const": "then" + } + }, + "required": [ + "foo" + ] + }, + "then": { + "properties": { + "bar": { + "type": "string" + } + }, + "required": [ + "bar" + ] + }, + "else": { + "properties": { + "baz": { + "type": "string" + } + }, + "required": [ + "baz" + ] + }, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"if\" (and 3 more errors)", + "tests": [ + { + "description": "when if is true and has no unevaluated properties", + "data": { + "foo": "then", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "when if is true and has unevaluated properties", + "data": { + "foo": "then", + "bar": "bar", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "when if is false and has no unevaluated properties", + "data": { + "baz": "baz" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "when if is false and has unevaluated properties", + "data": { + "foo": "else", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with if/then/else, then not defined", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "if": { + "properties": { + "foo": { + "const": "then" + } + }, + "required": [ + "foo" + ] + }, + "else": { + "properties": { + "baz": { + "type": "string" + } + }, + "required": [ + "baz" + ] + }, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"if\" (and 2 more errors)", + "tests": [ + { + "description": "when if is true and has no unevaluated properties", + "data": { + "foo": "then", + "bar": "bar" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "when if is true and has unevaluated properties", + "data": { + "foo": "then", + "bar": "bar", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "when if is false and has no unevaluated properties", + "data": { + "baz": "baz" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "when if is false and has unevaluated properties", + "data": { + "foo": "else", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with if/then/else, else not defined", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "if": { + "properties": { + "foo": { + "const": "then" + } + }, + "required": [ + "foo" + ] + }, + "then": { + "properties": { + "bar": { + "type": "string" + } + }, + "required": [ + "bar" + ] + }, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"if\" (and 2 more errors)", + "tests": [ + { + "description": "when if is true and has no unevaluated properties", + "data": { + "foo": "then", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "when if is true and has unevaluated properties", + "data": { + "foo": "then", + "bar": "bar", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "when if is false and has no unevaluated properties", + "data": { + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "when if is false and has unevaluated properties", + "data": { + "foo": "else", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with dependentSchemas", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "dependentSchemas": { + "foo": { + "properties": { + "bar": { + "const": "bar" + } + }, + "required": [ + "bar" + ] + } + }, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"dependentSchemas\" (and 1 more errors)", + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated properties", + "data": { + "bar": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with boolean schemas", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "allOf": [ + true + ], + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated properties", + "data": { + "bar": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "$ref": "#/$defs/bar", + "properties": { + "foo": { + "type": "string" + } + }, + "unevaluatedProperties": false, + "$defs": { + "bar": { + "properties": { + "bar": { + "type": "string" + } + } + } + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties before $ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "unevaluatedProperties": false, + "properties": { + "foo": { + "type": "string" + } + }, + "$ref": "#/$defs/bar", + "$defs": { + "bar": { + "properties": { + "bar": { + "type": "string" + } + } + } + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with $dynamicRef", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://example.com/unevaluated-properties-with-dynamic-ref/derived", + "$ref": "./baseSchema", + "$defs": { + "derived": { + "$dynamicAnchor": "addons", + "properties": { + "bar": { + "type": "string" + } + } + }, + "baseSchema": { + "$id": "./baseSchema", + "$comment": "unevaluatedProperties comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering", + "unevaluatedProperties": false, + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "$dynamicRef": "#addons", + "$defs": { + "defaultAddons": { + "$comment": "Needed to satisfy the bookending requirement", + "$dynamicAnchor": "addons" + } + } + } + } + }, + "skip": "extract error: unsupported constraint \"$dynamicAnchor\" (and 3 more errors)", + "tests": [ + { + "description": "with no unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar", + "baz": "baz" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties can't see inside cousins", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "properties": { + "foo": true + } + }, + { + "unevaluatedProperties": false + } + ] + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "always fails", + "data": { + "foo": 1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties can't see inside cousins (reverse order)", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "allOf": [ + { + "unevaluatedProperties": false + }, + { + "properties": { + "foo": true + } + } + ] + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "always fails", + "data": { + "foo": 1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "nested unevaluatedProperties, outer false, inner true, properties outside", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "allOf": [ + { + "unevaluatedProperties": true + } + ], + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\" (and 1 more errors)", + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "nested unevaluatedProperties, outer false, inner true, properties inside", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": { + "type": "string" + } + }, + "unevaluatedProperties": true + } + ], + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\" (and 1 more errors)", + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "nested unevaluatedProperties, outer true, inner false, properties outside", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { + "type": "string" + } + }, + "allOf": [ + { + "unevaluatedProperties": false + } + ], + "unevaluatedProperties": true + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\" (and 1 more errors)", + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "nested unevaluatedProperties, outer true, inner false, properties inside", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": { + "type": "string" + } + }, + "unevaluatedProperties": false + } + ], + "unevaluatedProperties": true + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\" (and 1 more errors)", + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "cousin unevaluatedProperties, true and false, true with properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": { + "type": "string" + } + }, + "unevaluatedProperties": true + }, + { + "unevaluatedProperties": false + } + ] + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\" (and 1 more errors)", + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "cousin unevaluatedProperties, true and false, false with properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "allOf": [ + { + "unevaluatedProperties": true + }, + { + "properties": { + "foo": { + "type": "string" + } + }, + "unevaluatedProperties": false + } + ] + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\" (and 1 more errors)", + "tests": [ + { + "description": "with no nested unevaluated properties", + "data": { + "foo": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "with nested unevaluated properties", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "property is evaluated in an uncle schema to unevaluatedProperties", + "comment": "see https://stackoverflow.com/questions/66936884/deeply-nested-unevaluatedproperties-and-their-expectations", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "foo": { + "type": "object", + "properties": { + "bar": { + "type": "string" + } + }, + "unevaluatedProperties": false + } + }, + "anyOf": [ + { + "properties": { + "foo": { + "properties": { + "faz": { + "type": "string" + } + } + } + } + } + ] + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "no extra properties", + "data": { + "foo": { + "bar": "test" + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "uncle keyword evaluation is not significant", + "data": { + "foo": { + "bar": "test", + "faz": "test" + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "in-place applicator siblings, allOf has unevaluated", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": true + }, + "unevaluatedProperties": false + } + ], + "anyOf": [ + { + "properties": { + "bar": true + } + } + ] + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "base case: both properties present", + "data": { + "foo": 1, + "bar": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "in place applicator siblings, bar is missing", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "in place applicator siblings, foo is missing", + "data": { + "bar": 1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "in-place applicator siblings, anyOf has unevaluated", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "allOf": [ + { + "properties": { + "foo": true + } + } + ], + "anyOf": [ + { + "properties": { + "bar": true + }, + "unevaluatedProperties": false + } + ] + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "base case: both properties present", + "data": { + "foo": 1, + "bar": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "in place applicator siblings, bar is missing", + "data": { + "foo": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "in place applicator siblings, foo is missing", + "data": { + "bar": 1 + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties + single cyclic ref", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "x": { + "$ref": "#" + } + }, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "Empty is valid", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Single is valid", + "data": { + "x": {} + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Unevaluated on 1st level is invalid", + "data": { + "x": {}, + "y": {} + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Nested is valid", + "data": { + "x": { + "x": {} + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Unevaluated on 2nd level is invalid", + "data": { + "x": { + "x": {}, + "y": {} + } + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Deep nested is valid", + "data": { + "x": { + "x": { + "x": {} + } + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Unevaluated on 3rd level is invalid", + "data": { + "x": { + "x": { + "x": {}, + "y": {} + } + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties + ref inside allOf / oneOf", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "one": { + "properties": { + "a": true + } + }, + "two": { + "required": [ + "x" + ], + "properties": { + "x": true + } + } + }, + "allOf": [ + { + "$ref": "#/$defs/one" + }, + { + "properties": { + "b": true + } + }, + { + "oneOf": [ + { + "$ref": "#/$defs/two" + }, + { + "required": [ + "y" + ], + "properties": { + "y": true + } + } + ] + } + ], + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "Empty is invalid (no x or y)", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a and b are invalid (no x or y)", + "data": { + "a": 1, + "b": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "x and y are invalid", + "data": { + "x": 1, + "y": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a and x are valid", + "data": { + "a": 1, + "x": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a and y are valid", + "data": { + "a": 1, + "y": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a and b and x are valid", + "data": { + "a": 1, + "b": 1, + "x": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a and b and y are valid", + "data": { + "a": 1, + "b": 1, + "y": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a and b and x and y are invalid", + "data": { + "a": 1, + "b": 1, + "x": 1, + "y": 1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "dynamic evalation inside nested refs", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "one": { + "oneOf": [ + { + "$ref": "#/$defs/two" + }, + { + "required": [ + "b" + ], + "properties": { + "b": true + } + }, + { + "required": [ + "xx" + ], + "patternProperties": { + "x": true + } + }, + { + "required": [ + "all" + ], + "unevaluatedProperties": true + } + ] + }, + "two": { + "oneOf": [ + { + "required": [ + "c" + ], + "properties": { + "c": true + } + }, + { + "required": [ + "d" + ], + "properties": { + "d": true + } + } + ] + } + }, + "oneOf": [ + { + "$ref": "#/$defs/one" + }, + { + "required": [ + "a" + ], + "properties": { + "a": true + } + } + ], + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\" (and 1 more errors)", + "tests": [ + { + "description": "Empty is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a is valid", + "data": { + "a": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "b is valid", + "data": { + "b": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "c is valid", + "data": { + "c": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "d is valid", + "data": { + "d": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a + b is invalid", + "data": { + "a": 1, + "b": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a + c is invalid", + "data": { + "a": 1, + "c": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a + d is invalid", + "data": { + "a": 1, + "d": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "b + c is invalid", + "data": { + "b": 1, + "c": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "b + d is invalid", + "data": { + "b": 1, + "d": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "c + d is invalid", + "data": { + "c": 1, + "d": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "xx is valid", + "data": { + "xx": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "xx + foox is valid", + "data": { + "xx": 1, + "foox": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "xx + foo is invalid", + "data": { + "xx": 1, + "foo": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "xx + a is invalid", + "data": { + "xx": 1, + "a": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "xx + b is invalid", + "data": { + "xx": 1, + "b": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "xx + c is invalid", + "data": { + "xx": 1, + "c": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "xx + d is invalid", + "data": { + "xx": 1, + "d": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "all is valid", + "data": { + "all": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all + foo is valid", + "data": { + "all": 1, + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all + a is invalid", + "data": { + "all": 1, + "a": 1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "non-object instances are valid", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "ignores booleans", + "data": true, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores integers", + "data": 123, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores strings", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores null", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties with null valued instance properties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "unevaluatedProperties": { + "type": "null" + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "allows null valued properties", + "data": { + "foo": null + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties not affected by propertyNames", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "propertyNames": { + "maxLength": 1 + }, + "unevaluatedProperties": { + "type": "number" + } + }, + "skip": "extract error: unsupported constraint \"unevaluatedProperties\"", + "tests": [ + { + "description": "allows only number properties", + "data": { + "a": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string property is invalid", + "data": { + "a": "b" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "unevaluatedProperties can see annotations from if without then and else", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "if": { + "patternProperties": { + "foo": { + "type": "string" + } + } + }, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"if\" (and 1 more errors)", + "tests": [ + { + "description": "valid in case if is evaluated", + "data": { + "foo": "a" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid in case if is evaluated", + "data": { + "bar": "a" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "dependentSchemas with unevaluatedProperties", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "properties": { + "foo2": {} + }, + "dependentSchemas": { + "foo": {}, + "foo2": { + "properties": { + "bar": {} + } + } + }, + "unevaluatedProperties": false + }, + "skip": "extract error: unsupported constraint \"dependentSchemas\" (and 1 more errors)", + "tests": [ + { + "description": "unevaluatedProperties doesn't consider dependentSchemas", + "data": { + "foo": "" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "unevaluatedProperties doesn't see bar when foo2 is absent", + "data": { + "bar": "" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "unevaluatedProperties sees bar when foo2 is present", + "data": { + "foo2": "", + "bar": "" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/uniqueItems.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/uniqueItems.json new file mode 100644 index 000000000..5237983ca --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/uniqueItems.json @@ -0,0 +1,862 @@ +[ + { + "description": "uniqueItems validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "uniqueItems": true + }, + "tests": [ + { + "description": "unique array of integers is valid", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "non-unique array of integers is invalid", + "data": [ + 1, + 1 + ], + "valid": false + }, + { + "description": "non-unique array of more than two integers is invalid", + "data": [ + 1, + 2, + 1 + ], + "valid": false + }, + { + "description": "numbers are unique if mathematically unequal", + "data": [ + 1.0, + 1.00, + 1 + ], + "valid": false, + "skip": "unexpected success" + }, + { + "description": "false is not equal to zero", + "data": [ + 0, + false + ], + "valid": true + }, + { + "description": "true is not equal to one", + "data": [ + 1, + true + ], + "valid": true + }, + { + "description": "unique array of strings is valid", + "data": [ + "foo", + "bar", + "baz" + ], + "valid": true + }, + { + "description": "non-unique array of strings is invalid", + "data": [ + "foo", + "bar", + "foo" + ], + "valid": false + }, + { + "description": "unique array of objects is valid", + "data": [ + { + "foo": "bar" + }, + { + "foo": "baz" + } + ], + "valid": true + }, + { + "description": "non-unique array of objects is invalid", + "data": [ + { + "foo": "bar" + }, + { + "foo": "bar" + } + ], + "valid": false + }, + { + "description": "property order of array of objects is ignored", + "data": [ + { + "foo": "bar", + "bar": "foo" + }, + { + "bar": "foo", + "foo": "bar" + } + ], + "valid": false, + "skip": "unexpected success" + }, + { + "description": "unique array of nested objects is valid", + "data": [ + { + "foo": { + "bar": { + "baz": true + } + } + }, + { + "foo": { + "bar": { + "baz": false + } + } + } + ], + "valid": true + }, + { + "description": "non-unique array of nested objects is invalid", + "data": [ + { + "foo": { + "bar": { + "baz": true + } + } + }, + { + "foo": { + "bar": { + "baz": true + } + } + } + ], + "valid": false + }, + { + "description": "unique array of arrays is valid", + "data": [ + [ + "foo" + ], + [ + "bar" + ] + ], + "valid": true + }, + { + "description": "non-unique array of arrays is invalid", + "data": [ + [ + "foo" + ], + [ + "foo" + ] + ], + "valid": false + }, + { + "description": "non-unique array of more than two arrays is invalid", + "data": [ + [ + "foo" + ], + [ + "bar" + ], + [ + "foo" + ] + ], + "valid": false + }, + { + "description": "1 and true are unique", + "data": [ + 1, + true + ], + "valid": true + }, + { + "description": "0 and false are unique", + "data": [ + 0, + false + ], + "valid": true + }, + { + "description": "[1] and [true] are unique", + "data": [ + [ + 1 + ], + [ + true + ] + ], + "valid": true + }, + { + "description": "[0] and [false] are unique", + "data": [ + [ + 0 + ], + [ + false + ] + ], + "valid": true + }, + { + "description": "nested [1] and [true] are unique", + "data": [ + [ + [ + 1 + ], + "foo" + ], + [ + [ + true + ], + "foo" + ] + ], + "valid": true + }, + { + "description": "nested [0] and [false] are unique", + "data": [ + [ + [ + 0 + ], + "foo" + ], + [ + [ + false + ], + "foo" + ] + ], + "valid": true + }, + { + "description": "unique heterogeneous types are valid", + "data": [ + {}, + [ + 1 + ], + true, + null, + 1, + "{}" + ], + "valid": true + }, + { + "description": "non-unique heterogeneous types are invalid", + "data": [ + {}, + [ + 1 + ], + true, + null, + {}, + 1 + ], + "valid": false + }, + { + "description": "different objects are unique", + "data": [ + { + "a": 1, + "b": 2 + }, + { + "a": 2, + "b": 1 + } + ], + "valid": true + }, + { + "description": "objects are non-unique despite key order", + "data": [ + { + "a": 1, + "b": 2 + }, + { + "b": 2, + "a": 1 + } + ], + "valid": false, + "skip": "unexpected success" + }, + { + "description": "{\"a\": false} and {\"a\": 0} are unique", + "data": [ + { + "a": false + }, + { + "a": 0 + } + ], + "valid": true + }, + { + "description": "{\"a\": true} and {\"a\": 1} are unique", + "data": [ + { + "a": true + }, + { + "a": 1 + } + ], + "valid": true + } + ] + }, + { + "description": "uniqueItems with an array of items", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { + "type": "boolean" + }, + { + "type": "boolean" + } + ], + "uniqueItems": true + }, + "skip": "extract error: unsupported constraint \"prefixItems\"", + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [ + false, + true + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "[true, false] from items array is valid", + "data": [ + true, + false + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "[false, false] from items array is not valid", + "data": [ + false, + false + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "[true, true] from items array is not valid", + "data": [ + true, + true + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "unique array extended from [false, true] is valid", + "data": [ + false, + true, + "foo", + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unique array extended from [true, false] is valid", + "data": [ + true, + false, + "foo", + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "non-unique array extended from [false, true] is not valid", + "data": [ + false, + true, + "foo", + "foo" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "non-unique array extended from [true, false] is not valid", + "data": [ + true, + false, + "foo", + "foo" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "uniqueItems with an array of items and additionalItems=false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { + "type": "boolean" + }, + { + "type": "boolean" + } + ], + "uniqueItems": true, + "items": false + }, + "skip": "extract error: unsupported constraint \"prefixItems\" (and 1 more errors)", + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [ + false, + true + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "[true, false] from items array is valid", + "data": [ + true, + false + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "[false, false] from items array is not valid", + "data": [ + false, + false + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "[true, true] from items array is not valid", + "data": [ + true, + true + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "extra items are invalid even if unique", + "data": [ + false, + true, + null + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "uniqueItems=false validation", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "uniqueItems": false + }, + "tests": [ + { + "description": "unique array of integers is valid", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "non-unique array of integers is valid", + "data": [ + 1, + 1 + ], + "valid": true + }, + { + "description": "numbers are unique if mathematically unequal", + "data": [ + 1.0, + 1.00, + 1 + ], + "valid": true + }, + { + "description": "false is not equal to zero", + "data": [ + 0, + false + ], + "valid": true + }, + { + "description": "true is not equal to one", + "data": [ + 1, + true + ], + "valid": true + }, + { + "description": "unique array of objects is valid", + "data": [ + { + "foo": "bar" + }, + { + "foo": "baz" + } + ], + "valid": true + }, + { + "description": "non-unique array of objects is valid", + "data": [ + { + "foo": "bar" + }, + { + "foo": "bar" + } + ], + "valid": true + }, + { + "description": "unique array of nested objects is valid", + "data": [ + { + "foo": { + "bar": { + "baz": true + } + } + }, + { + "foo": { + "bar": { + "baz": false + } + } + } + ], + "valid": true + }, + { + "description": "non-unique array of nested objects is valid", + "data": [ + { + "foo": { + "bar": { + "baz": true + } + } + }, + { + "foo": { + "bar": { + "baz": true + } + } + } + ], + "valid": true + }, + { + "description": "unique array of arrays is valid", + "data": [ + [ + "foo" + ], + [ + "bar" + ] + ], + "valid": true + }, + { + "description": "non-unique array of arrays is valid", + "data": [ + [ + "foo" + ], + [ + "foo" + ] + ], + "valid": true + }, + { + "description": "1 and true are unique", + "data": [ + 1, + true + ], + "valid": true + }, + { + "description": "0 and false are unique", + "data": [ + 0, + false + ], + "valid": true + }, + { + "description": "unique heterogeneous types are valid", + "data": [ + {}, + [ + 1 + ], + true, + null, + 1 + ], + "valid": true + }, + { + "description": "non-unique heterogeneous types are valid", + "data": [ + {}, + [ + 1 + ], + true, + null, + {}, + 1 + ], + "valid": true + } + ] + }, + { + "description": "uniqueItems=false with an array of items", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { + "type": "boolean" + }, + { + "type": "boolean" + } + ], + "uniqueItems": false + }, + "skip": "extract error: unsupported constraint \"prefixItems\"", + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [ + false, + true + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "[true, false] from items array is valid", + "data": [ + true, + false + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "[false, false] from items array is valid", + "data": [ + false, + false + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "[true, true] from items array is valid", + "data": [ + true, + true + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unique array extended from [false, true] is valid", + "data": [ + false, + true, + "foo", + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unique array extended from [true, false] is valid", + "data": [ + true, + false, + "foo", + "bar" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "non-unique array extended from [false, true] is valid", + "data": [ + false, + true, + "foo", + "foo" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "non-unique array extended from [true, false] is valid", + "data": [ + true, + false, + "foo", + "foo" + ], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "uniqueItems=false with an array of items and additionalItems=false", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "prefixItems": [ + { + "type": "boolean" + }, + { + "type": "boolean" + } + ], + "uniqueItems": false, + "items": false + }, + "skip": "extract error: unsupported constraint \"prefixItems\" (and 1 more errors)", + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [ + false, + true + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "[true, false] from items array is valid", + "data": [ + true, + false + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "[false, false] from items array is valid", + "data": [ + false, + false + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "[true, true] from items array is valid", + "data": [ + true, + true + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "extra items are invalid even if unique", + "data": [ + false, + true, + null + ], + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft2020-12/vocabulary.json b/encoding/jsonschema/testdata/external/tests/draft2020-12/vocabulary.json new file mode 100644 index 000000000..ed73ee763 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft2020-12/vocabulary.json @@ -0,0 +1,64 @@ +[ + { + "description": "schema that uses custom metaschema with with no validation vocabulary", + "schema": { + "$id": "https://schema/using/no/validation", + "$schema": "http://localhost:1234/draft2020-12/metaschema-no-validation.json", + "properties": { + "badProperty": false, + "numberProperty": { + "minimum": 10 + } + } + }, + "skip": "extract error: invalid $schema URL \"http://localhost:1234/draft2020-12/metaschema-no-validation.json\": $schema URI not recognized", + "tests": [ + { + "description": "applicator vocabulary still works", + "data": { + "badProperty": "this property should not exist" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no validation: valid number", + "data": { + "numberProperty": 20 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "no validation: invalid number, but it still validates", + "data": { + "numberProperty": 1 + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ignore unrecognized optional vocabulary", + "schema": { + "$schema": "http://localhost:1234/draft2020-12/metaschema-optional-vocabulary.json", + "type": "number" + }, + "skip": "extract error: invalid $schema URL \"http://localhost:1234/draft2020-12/metaschema-optional-vocabulary.json\": $schema URI not recognized", + "tests": [ + { + "description": "string value", + "data": "foobar", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "number value", + "data": 20, + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/additionalItems.json b/encoding/jsonschema/testdata/external/tests/draft4/additionalItems.json new file mode 100644 index 000000000..2ec8c02cf --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/additionalItems.json @@ -0,0 +1,297 @@ +[ + { + "description": "additionalItems as schema", + "schema": { + "items": [ + {} + ], + "additionalItems": { + "type": "integer" + } + }, + "tests": [ + { + "description": "additional items match schema", + "data": [ + null, + 2, + 3, + 4 + ], + "valid": true + }, + { + "description": "additional items do not match schema", + "data": [ + null, + 2, + 3, + "foo" + ], + "valid": false + } + ] + }, + { + "description": "when items is schema, additionalItems does nothing", + "schema": { + "items": {}, + "additionalItems": false + }, + "tests": [ + { + "description": "all items match schema", + "data": [ + 1, + 2, + 3, + 4, + 5 + ], + "valid": true + } + ] + }, + { + "description": "array of items with no additionalItems permitted", + "schema": { + "items": [ + {}, + {}, + {} + ], + "additionalItems": false + }, + "tests": [ + { + "description": "empty array", + "data": [], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:45\n instance.json:1:1\nconflicting values bool and [] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "fewer number of items present (1)", + "data": [ + 1 + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:45\n instance.json:1:1\nconflicting values bool and [1] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "fewer number of items present (2)", + "data": [ + 1, + 2 + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1,2] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:45\n instance.json:1:1\nconflicting values bool and [1,2] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,2] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,2] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,2] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "equal number of items present", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "additional items are not permitted", + "data": [ + 1, + 2, + 3, + 4 + ], + "valid": false + } + ] + }, + { + "description": "additionalItems as false without items", + "schema": { + "additionalItems": false + }, + "tests": [ + { + "description": "items defaults to empty schema so everything is valid", + "data": [ + 1, + 2, + 3, + 4, + 5 + ], + "valid": true + }, + { + "description": "ignores non-arrays", + "data": { + "foo": "bar" + }, + "valid": true + } + ] + }, + { + "description": "additionalItems are allowed by default", + "schema": { + "items": [ + { + "type": "integer" + } + ] + }, + "tests": [ + { + "description": "only the first item is validated", + "data": [ + 1, + "foo", + false + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1,\"foo\",false] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:41\n instance.json:1:1\nconflicting values bool and [1,\"foo\",false] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,\"foo\",false] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,\"foo\",false] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,\"foo\",false] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + } + ] + }, + { + "description": "additionalItems does not look in applicators, valid case", + "schema": { + "allOf": [ + { + "items": [ + { + "type": "integer" + } + ] + } + ], + "additionalItems": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "items defined in allOf are not examined", + "data": [ + 1, + null + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1,null] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:41\n instance.json:1:1\nconflicting values bool and [1,null] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,null] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,null] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,null] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + } + ] + }, + { + "description": "additionalItems does not look in applicators, invalid case", + "schema": { + "allOf": [ + { + "items": [ + { + "type": "integer" + }, + { + "type": "string" + } + ] + } + ], + "items": [ + { + "type": "integer" + } + ], + "additionalItems": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "items defined in allOf are not examined", + "data": [ + 1, + "hello" + ], + "valid": false + } + ] + }, + { + "description": "items validation adjusts the starting index for additionalItems", + "schema": { + "items": [ + { + "type": "string" + } + ], + "additionalItems": { + "type": "integer" + } + }, + "tests": [ + { + "description": "valid items", + "data": [ + "x", + 2, + 3 + ], + "valid": true + }, + { + "description": "wrong type of second item", + "data": [ + "x", + "y" + ], + "valid": false + } + ] + }, + { + "description": "additionalItems with heterogeneous array", + "schema": { + "items": [ + {} + ], + "additionalItems": false + }, + "tests": [ + { + "description": "heterogeneous invalid instance", + "data": [ + "foo", + "bar", + 37 + ], + "valid": false + }, + { + "description": "valid instance", + "data": [ + null + ], + "valid": true + } + ] + }, + { + "description": "additionalItems with null instance elements", + "schema": { + "additionalItems": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ + null + ], + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/additionalProperties.json b/encoding/jsonschema/testdata/external/tests/draft4/additionalProperties.json new file mode 100644 index 000000000..dfc0faecb --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/additionalProperties.json @@ -0,0 +1,212 @@ +[ + { + "description": "additionalProperties being false does not allow other properties", + "schema": { + "properties": { + "foo": {}, + "bar": {} + }, + "patternProperties": { + "^v": {} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "no additional properties is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "an additional property is invalid", + "data": { + "foo": 1, + "bar": 2, + "quux": "boom" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ignores arrays", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobarbaz", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "patternProperties are not additional properties", + "data": { + "foo": 1, + "vroom": 2 + }, + "valid": true + } + ] + }, + { + "description": "non-ASCII pattern with additionalProperties", + "schema": { + "patternProperties": { + "^á": {} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "matching the pattern is valid", + "data": { + "ármányos": 2 + }, + "valid": true + }, + { + "description": "not matching the pattern is invalid", + "data": { + "élmény": 2 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "additionalProperties with schema", + "schema": { + "properties": { + "foo": {}, + "bar": {} + }, + "additionalProperties": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "no additional properties is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "an additional valid property is valid", + "data": { + "foo": 1, + "bar": 2, + "quux": true + }, + "valid": true + }, + { + "description": "an additional invalid property is invalid", + "data": { + "foo": 1, + "bar": 2, + "quux": 12 + }, + "valid": false + } + ] + }, + { + "description": "additionalProperties can exist by itself", + "schema": { + "additionalProperties": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "an additional valid property is valid", + "data": { + "foo": true + }, + "valid": true + }, + { + "description": "an additional invalid property is invalid", + "data": { + "foo": 1 + }, + "valid": false + } + ] + }, + { + "description": "additionalProperties are allowed by default", + "schema": { + "properties": { + "foo": {}, + "bar": {} + } + }, + "tests": [ + { + "description": "additional properties are allowed", + "data": { + "foo": 1, + "bar": 2, + "quux": true + }, + "valid": true + } + ] + }, + { + "description": "additionalProperties does not look in applicators", + "schema": { + "allOf": [ + { + "properties": { + "foo": {} + } + } + ], + "additionalProperties": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "properties defined in allOf are not examined", + "data": { + "foo": 1, + "bar": true + }, + "valid": false + } + ] + }, + { + "description": "additionalProperties with null valued instance properties", + "schema": { + "additionalProperties": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null values", + "data": { + "foo": null + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/allOf.json b/encoding/jsonschema/testdata/external/tests/draft4/allOf.json new file mode 100644 index 000000000..b971afbf1 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/allOf.json @@ -0,0 +1,334 @@ +[ + { + "description": "allOf", + "schema": { + "allOf": [ + { + "properties": { + "bar": { + "type": "integer" + } + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + } + ] + }, + "tests": [ + { + "description": "allOf", + "data": { + "foo": "baz", + "bar": 2 + }, + "valid": true + }, + { + "description": "mismatch second", + "data": { + "foo": "baz" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "mismatch first", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "wrong type", + "data": { + "foo": "baz", + "bar": "quux" + }, + "valid": false + } + ] + }, + { + "description": "allOf with base schema", + "schema": { + "properties": { + "bar": { + "type": "integer" + } + }, + "required": [ + "bar" + ], + "allOf": [ + { + "properties": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + }, + { + "properties": { + "baz": { + "type": "null" + } + }, + "required": [ + "baz" + ] + } + ] + }, + "tests": [ + { + "description": "valid", + "data": { + "foo": "quux", + "bar": 2, + "baz": null + }, + "valid": true + }, + { + "description": "mismatch base schema", + "data": { + "foo": "quux", + "baz": null + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "mismatch first allOf", + "data": { + "bar": 2, + "baz": null + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "mismatch second allOf", + "data": { + "foo": "quux", + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "mismatch both", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "allOf simple types", + "schema": { + "allOf": [ + { + "maximum": 30 + }, + { + "minimum": 20 + } + ] + }, + "tests": [ + { + "description": "valid", + "data": 25, + "valid": true + }, + { + "description": "mismatch one", + "data": 35, + "valid": false + } + ] + }, + { + "description": "allOf with one empty schema", + "schema": { + "allOf": [ + {} + ] + }, + "tests": [ + { + "description": "any data is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "allOf with two empty schemas", + "schema": { + "allOf": [ + {}, + {} + ] + }, + "tests": [ + { + "description": "any data is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "allOf with the first empty schema", + "schema": { + "allOf": [ + {}, + { + "type": "number" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "allOf with the last empty schema", + "schema": { + "allOf": [ + { + "type": "number" + }, + {} + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "nested allOf, to check validation semantics", + "schema": { + "allOf": [ + { + "allOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "allOf combined with anyOf, oneOf", + "schema": { + "allOf": [ + { + "multipleOf": 2 + } + ], + "anyOf": [ + { + "multipleOf": 3 + } + ], + "oneOf": [ + { + "multipleOf": 5 + } + ] + }, + "tests": [ + { + "description": "allOf: false, anyOf: false, oneOf: false", + "data": 1, + "valid": false + }, + { + "description": "allOf: false, anyOf: false, oneOf: true", + "data": 5, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: false", + "data": 3, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: true", + "data": 15, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: false", + "data": 2, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: true", + "data": 10, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: false", + "data": 6, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: true", + "data": 30, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/anyOf.json b/encoding/jsonschema/testdata/external/tests/draft4/anyOf.json new file mode 100644 index 000000000..7c157961c --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/anyOf.json @@ -0,0 +1,176 @@ +[ + { + "description": "anyOf", + "schema": { + "anyOf": [ + { + "type": "integer" + }, + { + "minimum": 2 + } + ] + }, + "tests": [ + { + "description": "first anyOf valid", + "data": 1, + "valid": true + }, + { + "description": "second anyOf valid", + "data": 2.5, + "valid": true + }, + { + "description": "both anyOf valid", + "data": 3, + "valid": true + }, + { + "description": "neither anyOf valid", + "data": 1.5, + "valid": false + } + ] + }, + { + "description": "anyOf with base schema", + "schema": { + "type": "string", + "anyOf": [ + { + "maxLength": 2 + }, + { + "minLength": 4 + } + ] + }, + "tests": [ + { + "description": "mismatch base schema", + "data": 3, + "valid": false + }, + { + "description": "one anyOf valid", + "data": "foobar", + "valid": true + }, + { + "description": "both anyOf invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "anyOf complex types", + "schema": { + "anyOf": [ + { + "properties": { + "bar": { + "type": "integer" + } + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + } + ] + }, + "tests": [ + { + "description": "first anyOf valid (complex)", + "data": { + "bar": 2 + }, + "valid": true + }, + { + "description": "second anyOf valid (complex)", + "data": { + "foo": "baz" + }, + "valid": true + }, + { + "description": "both anyOf valid (complex)", + "data": { + "foo": "baz", + "bar": 2 + }, + "valid": true + }, + { + "description": "neither anyOf valid (complex)", + "data": { + "foo": 2, + "bar": "quux" + }, + "valid": false + } + ] + }, + { + "description": "anyOf with one empty schema", + "schema": { + "anyOf": [ + { + "type": "number" + }, + {} + ] + }, + "tests": [ + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "number is valid", + "data": 123, + "valid": true + } + ] + }, + { + "description": "nested anyOf, to check validation semantics", + "schema": { + "anyOf": [ + { + "anyOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/default.json b/encoding/jsonschema/testdata/external/tests/draft4/default.json new file mode 100644 index 000000000..587423d4a --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/default.json @@ -0,0 +1,88 @@ +[ + { + "description": "invalid type for default", + "schema": { + "properties": { + "foo": { + "type": "integer", + "default": [] + } + } + }, + "tests": [ + { + "description": "valid when property is specified", + "data": { + "foo": 13 + }, + "valid": true + }, + { + "description": "still valid when the invalid default is used", + "data": {}, + "valid": true + } + ] + }, + { + "description": "invalid string value for default", + "schema": { + "properties": { + "bar": { + "type": "string", + "minLength": 4, + "default": "bad" + } + } + }, + "tests": [ + { + "description": "valid when property is specified", + "data": { + "bar": "good" + }, + "valid": true + }, + { + "description": "still valid when the invalid default is used", + "data": {}, + "valid": true + } + ] + }, + { + "description": "the default keyword does not do anything if the property is missing", + "schema": { + "type": "object", + "properties": { + "alpha": { + "type": "number", + "maximum": 3, + "default": 5 + } + } + }, + "tests": [ + { + "description": "an explicit property value is checked against maximum (passing)", + "data": { + "alpha": 1 + }, + "valid": true + }, + { + "description": "an explicit property value is checked against maximum (failing)", + "data": { + "alpha": 5 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "missing properties are not filled in with the default", + "data": {}, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/definitions.json b/encoding/jsonschema/testdata/external/tests/draft4/definitions.json new file mode 100644 index 000000000..864359b64 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/definitions.json @@ -0,0 +1,35 @@ +[ + { + "description": "validate definition against metaschema", + "schema": { + "$ref": "http://json-schema.org/draft-04/schema#" + }, + "skip": "extract error: cannot compile resulting schema: package \"json-schema.org/draft-04/schema\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "valid definition schema", + "data": { + "definitions": { + "foo": { + "type": "integer" + } + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid definition schema", + "data": { + "definitions": { + "foo": { + "type": 1 + } + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/dependencies.json b/encoding/jsonschema/testdata/external/tests/draft4/dependencies.json new file mode 100644 index 000000000..3eb28bc87 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/dependencies.json @@ -0,0 +1,313 @@ +[ + { + "description": "dependencies", + "schema": { + "dependencies": { + "bar": [ + "foo" + ] + } + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependant", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "with dependency", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "missing dependency", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ignores arrays", + "data": [ + "bar" + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "multiple dependencies", + "schema": { + "dependencies": { + "quux": [ + "foo", + "bar" + ] + } + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependants", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "with dependencies", + "data": { + "foo": 1, + "bar": 2, + "quux": 3 + }, + "valid": true + }, + { + "description": "missing dependency", + "data": { + "foo": 1, + "quux": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "missing other dependency", + "data": { + "bar": 1, + "quux": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "missing both dependencies", + "data": { + "quux": 1 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "multiple dependencies subschema", + "schema": { + "dependencies": { + "bar": { + "properties": { + "foo": { + "type": "integer" + }, + "bar": { + "type": "integer" + } + } + } + } + }, + "tests": [ + { + "description": "valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "no dependency", + "data": { + "foo": "quux" + }, + "valid": true + }, + { + "description": "wrong type", + "data": { + "foo": "quux", + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "wrong type other", + "data": { + "foo": 2, + "bar": "quux" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "wrong type both", + "data": { + "foo": "quux", + "bar": "quux" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "dependencies": { + "foo\nbar": [ + "foo\rbar" + ], + "foo\tbar": { + "minProperties": 4 + }, + "foo'bar": { + "required": [ + "foo\"bar" + ] + }, + "foo\"bar": [ + "foo'bar" + ] + } + }, + "tests": [ + { + "description": "valid object 1", + "data": { + "foo\nbar": 1, + "foo\rbar": 2 + }, + "valid": true + }, + { + "description": "valid object 2", + "data": { + "foo\tbar": 1, + "a": 2, + "b": 3, + "c": 4 + }, + "valid": true + }, + { + "description": "valid object 3", + "data": { + "foo'bar": 1, + "foo\"bar": 2 + }, + "valid": true + }, + { + "description": "invalid object 1", + "data": { + "foo\nbar": 1, + "foo": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "invalid object 2", + "data": { + "foo\tbar": 1, + "a": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "invalid object 3", + "data": { + "foo'bar": 1 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "invalid object 4", + "data": { + "foo\"bar": 2 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "dependent subschema incompatible with root", + "schema": { + "properties": { + "foo": {} + }, + "dependencies": { + "foo": { + "properties": { + "bar": {} + }, + "additionalProperties": false + } + } + }, + "tests": [ + { + "description": "matches root", + "data": { + "foo": 1 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "matches dependency", + "data": { + "bar": 1 + }, + "valid": true + }, + { + "description": "matches both", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "no dependency", + "data": { + "baz": 1 + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/enum.json b/encoding/jsonschema/testdata/external/tests/draft4/enum.json new file mode 100644 index 000000000..3158bea80 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/enum.json @@ -0,0 +1,449 @@ +[ + { + "description": "simple enum validation", + "schema": { + "enum": [ + 1, + 2, + 3 + ] + }, + "tests": [ + { + "description": "one of the enum is valid", + "data": 1, + "valid": true + }, + { + "description": "something else is invalid", + "data": 4, + "valid": false + } + ] + }, + { + "description": "heterogeneous enum validation", + "schema": { + "enum": [ + 6, + "foo", + [], + true, + { + "foo": 12 + } + ] + }, + "tests": [ + { + "description": "one of the enum is valid", + "data": [], + "valid": true + }, + { + "description": "something else is invalid", + "data": null, + "valid": false + }, + { + "description": "objects are deep compared", + "data": { + "foo": false + }, + "valid": false + }, + { + "description": "valid object matches", + "data": { + "foo": 12 + }, + "valid": true + }, + { + "description": "extra properties in object is invalid", + "data": { + "foo": 12, + "boo": 42 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "heterogeneous enum-with-null validation", + "schema": { + "enum": [ + 6, + null + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "number is valid", + "data": 6, + "valid": true + }, + { + "description": "something else is invalid", + "data": "test", + "valid": false + } + ] + }, + { + "description": "enums in properties", + "schema": { + "type": "object", + "properties": { + "foo": { + "enum": [ + "foo" + ] + }, + "bar": { + "enum": [ + "bar" + ] + } + }, + "required": [ + "bar" + ] + }, + "tests": [ + { + "description": "both properties are valid", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "wrong foo value", + "data": { + "foo": "foot", + "bar": "bar" + }, + "valid": false + }, + { + "description": "wrong bar value", + "data": { + "foo": "foo", + "bar": "bart" + }, + "valid": false + }, + { + "description": "missing optional property is valid", + "data": { + "bar": "bar" + }, + "valid": true + }, + { + "description": "missing required property is invalid", + "data": { + "foo": "foo" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "missing all properties is invalid", + "data": {}, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "enum with escaped characters", + "schema": { + "enum": [ + "foo\nbar", + "foo\rbar" + ] + }, + "tests": [ + { + "description": "member 1 is valid", + "data": "foo\nbar", + "valid": true + }, + { + "description": "member 2 is valid", + "data": "foo\rbar", + "valid": true + }, + { + "description": "another string is invalid", + "data": "abc", + "valid": false + } + ] + }, + { + "description": "enum with false does not match 0", + "schema": { + "enum": [ + false + ] + }, + "tests": [ + { + "description": "false is valid", + "data": false, + "valid": true + }, + { + "description": "integer zero is invalid", + "data": 0, + "valid": false + }, + { + "description": "float zero is invalid", + "data": 0.0, + "valid": false + } + ] + }, + { + "description": "enum with [false] does not match [0]", + "schema": { + "enum": [ + [ + false + ] + ] + }, + "tests": [ + { + "description": "[false] is valid", + "data": [ + false + ], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [ + 0 + ], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [ + 0.0 + ], + "valid": false + } + ] + }, + { + "description": "enum with true does not match 1", + "schema": { + "enum": [ + true + ] + }, + "tests": [ + { + "description": "true is valid", + "data": true, + "valid": true + }, + { + "description": "integer one is invalid", + "data": 1, + "valid": false + }, + { + "description": "float one is invalid", + "data": 1.0, + "valid": false + } + ] + }, + { + "description": "enum with [true] does not match [1]", + "schema": { + "enum": [ + [ + true + ] + ] + }, + "tests": [ + { + "description": "[true] is valid", + "data": [ + true + ], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [ + 1 + ], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [ + 1.0 + ], + "valid": false + } + ] + }, + { + "description": "enum with 0 does not match false", + "schema": { + "enum": [ + 0 + ] + }, + "tests": [ + { + "description": "false is invalid", + "data": false, + "valid": false + }, + { + "description": "integer zero is valid", + "data": 0, + "valid": true + }, + { + "description": "float zero is valid", + "data": 0.0, + "valid": true, + "skip": "conflicting values 0.0 and 0 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + } + ] + }, + { + "description": "enum with [0] does not match [false]", + "schema": { + "enum": [ + [ + 0 + ] + ] + }, + "tests": [ + { + "description": "[false] is invalid", + "data": [ + false + ], + "valid": false + }, + { + "description": "[0] is valid", + "data": [ + 0 + ], + "valid": true + }, + { + "description": "[0.0] is valid", + "data": [ + 0.0 + ], + "valid": true, + "skip": "0: conflicting values 0.0 and 0 (mismatched types float and int):\n generated.cue:2:1\n generated.cue:2:2\n instance.json:1:2\n" + } + ] + }, + { + "description": "enum with 1 does not match true", + "schema": { + "enum": [ + 1 + ] + }, + "tests": [ + { + "description": "true is invalid", + "data": true, + "valid": false + }, + { + "description": "integer one is valid", + "data": 1, + "valid": true + }, + { + "description": "float one is valid", + "data": 1.0, + "valid": true, + "skip": "conflicting values 1.0 and 1 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + } + ] + }, + { + "description": "enum with [1] does not match [true]", + "schema": { + "enum": [ + [ + 1 + ] + ] + }, + "tests": [ + { + "description": "[true] is invalid", + "data": [ + true + ], + "valid": false + }, + { + "description": "[1] is valid", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "[1.0] is valid", + "data": [ + 1.0 + ], + "valid": true, + "skip": "0: conflicting values 1.0 and 1 (mismatched types float and int):\n generated.cue:2:1\n generated.cue:2:2\n instance.json:1:2\n" + } + ] + }, + { + "description": "nul characters in strings", + "schema": { + "enum": [ + "hello\u0000there" + ] + }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/format.json b/encoding/jsonschema/testdata/external/tests/draft4/format.json new file mode 100644 index 000000000..e5df7263e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/format.json @@ -0,0 +1,272 @@ +[ + { + "description": "email format", + "schema": { + "format": "email" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ipv4 format", + "schema": { + "format": "ipv4" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ipv6 format", + "schema": { + "format": "ipv6" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "hostname format", + "schema": { + "format": "hostname" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "date-time format", + "schema": { + "format": "date-time" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "uri format", + "schema": { + "format": "uri" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/infinite-loop-detection.json b/encoding/jsonschema/testdata/external/tests/draft4/infinite-loop-detection.json new file mode 100644 index 000000000..fe96bb563 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/infinite-loop-detection.json @@ -0,0 +1,42 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "definitions": { + "int": { + "type": "integer" + } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/definitions/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/definitions/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "failing case", + "data": { + "foo": "a string" + }, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/items.json b/encoding/jsonschema/testdata/external/tests/draft4/items.json new file mode 100644 index 000000000..3eb94e431 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/items.json @@ -0,0 +1,472 @@ +[ + { + "description": "a schema given for items", + "schema": { + "items": { + "type": "integer" + } + }, + "tests": [ + { + "description": "valid items", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "wrong type of items", + "data": [ + 1, + "x" + ], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "JavaScript pseudo-array is valid", + "data": { + "0": "invalid", + "length": 1 + }, + "valid": true + } + ] + }, + { + "description": "an array of schemas for items", + "schema": { + "items": [ + { + "type": "integer" + }, + { + "type": "string" + } + ] + }, + "tests": [ + { + "description": "correct types", + "data": [ + 1, + "foo" + ], + "valid": true + }, + { + "description": "wrong types", + "data": [ + "foo", + 1 + ], + "valid": false + }, + { + "description": "incomplete array of items", + "data": [ + 1 + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:49\n instance.json:1:1\nconflicting values bool and [1] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "array with additional items", + "data": [ + 1, + "foo", + true + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1,\"foo\",true] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:49\n instance.json:1:1\nconflicting values bool and [1,\"foo\",true] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,\"foo\",true] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,\"foo\",true] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,\"foo\",true] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "empty array", + "data": [], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:49\n instance.json:1:1\nconflicting values bool and [] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "JavaScript pseudo-array is valid", + "data": { + "0": "invalid", + "1": "valid", + "length": 2 + }, + "valid": true + } + ] + }, + { + "description": "items and subitems", + "schema": { + "definitions": { + "item": { + "type": "array", + "additionalItems": false, + "items": [ + { + "$ref": "#/definitions/sub-item" + }, + { + "$ref": "#/definitions/sub-item" + } + ] + }, + "sub-item": { + "type": "object", + "required": [ + "foo" + ] + } + }, + "type": "array", + "additionalItems": false, + "items": [ + { + "$ref": "#/definitions/item" + }, + { + "$ref": "#/definitions/item" + }, + { + "$ref": "#/definitions/item" + } + ] + }, + "tests": [ + { + "description": "valid items", + "data": [ + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": true + }, + { + "description": "too many items", + "data": [ + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": false + }, + { + "description": "too many sub-items", + "data": [ + [ + { + "foo": null + }, + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": false + }, + { + "description": "wrong item", + "data": [ + { + "foo": null + }, + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": false + }, + { + "description": "wrong sub-item", + "data": [ + [ + {}, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": false, + "skip": "unexpected success" + }, + { + "description": "fewer items is valid", + "data": [ + [ + { + "foo": null + } + ], + [ + { + "foo": null + } + ] + ], + "valid": true, + "skip": "incompatible list lengths (2 and 3)\n" + } + ] + }, + { + "description": "nested items", + "schema": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "number" + } + } + } + } + }, + "tests": [ + { + "description": "valid nested array", + "data": [ + [ + [ + [ + 1 + ] + ], + [ + [ + 2 + ], + [ + 3 + ] + ] + ], + [ + [ + [ + 4 + ], + [ + 5 + ], + [ + 6 + ] + ] + ] + ], + "valid": true + }, + { + "description": "nested array with invalid type", + "data": [ + [ + [ + [ + "1" + ] + ], + [ + [ + 2 + ], + [ + 3 + ] + ] + ], + [ + [ + [ + 4 + ], + [ + 5 + ], + [ + 6 + ] + ] + ] + ], + "valid": false + }, + { + "description": "not deep enough", + "data": [ + [ + [ + 1 + ], + [ + 2 + ], + [ + 3 + ] + ], + [ + [ + 4 + ], + [ + 5 + ], + [ + 6 + ] + ] + ], + "valid": false + } + ] + }, + { + "description": "items with null instance elements", + "schema": { + "items": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ + null + ], + "valid": true + } + ] + }, + { + "description": "array-form items with null instance elements", + "schema": { + "items": [ + { + "type": "null" + } + ] + }, + "tests": [ + { + "description": "allows null elements", + "data": [ + null + ], + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/maxItems.json b/encoding/jsonschema/testdata/external/tests/draft4/maxItems.json new file mode 100644 index 000000000..87e6f956c --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/maxItems.json @@ -0,0 +1,39 @@ +[ + { + "description": "maxItems validation", + "schema": { + "maxItems": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "exact length is valid", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "too long is invalid", + "data": [ + 1, + 2, + 3 + ], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": "foobar", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/maxLength.json b/encoding/jsonschema/testdata/external/tests/draft4/maxLength.json new file mode 100644 index 000000000..508c1c767 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/maxLength.json @@ -0,0 +1,35 @@ +[ + { + "description": "maxLength validation", + "schema": { + "maxLength": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true + }, + { + "description": "exact length is valid", + "data": "fo", + "valid": true + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + }, + { + "description": "two graphemes is long enough", + "data": "💩💩", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/maxProperties.json b/encoding/jsonschema/testdata/external/tests/draft4/maxProperties.json new file mode 100644 index 000000000..1c9572b4e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/maxProperties.json @@ -0,0 +1,73 @@ +[ + { + "description": "maxProperties validation", + "schema": { + "maxProperties": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "exact length is valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "too long is invalid", + "data": { + "foo": 1, + "bar": 2, + "baz": 3 + }, + "valid": false + }, + { + "description": "ignores arrays", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "maxProperties = 0 means the object is empty", + "schema": { + "maxProperties": 0 + }, + "tests": [ + { + "description": "no properties is valid", + "data": {}, + "valid": true + }, + { + "description": "one property is invalid", + "data": { + "foo": 1 + }, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/maximum.json b/encoding/jsonschema/testdata/external/tests/draft4/maximum.json new file mode 100644 index 000000000..e381606f2 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/maximum.json @@ -0,0 +1,107 @@ +[ + { + "description": "maximum validation", + "schema": { + "maximum": 3.0 + }, + "tests": [ + { + "description": "below the maximum is valid", + "data": 2.6, + "valid": true + }, + { + "description": "boundary point is valid", + "data": 3.0, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 3.5, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + }, + { + "description": "maximum validation with unsigned integer", + "schema": { + "maximum": 300 + }, + "tests": [ + { + "description": "below the maximum is invalid", + "data": 299.97, + "valid": true + }, + { + "description": "boundary point integer is valid", + "data": 300, + "valid": true + }, + { + "description": "boundary point float is valid", + "data": 300.00, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 300.5, + "valid": false + } + ] + }, + { + "description": "maximum validation (explicit false exclusivity)", + "schema": { + "maximum": 3.0, + "exclusiveMaximum": false + }, + "tests": [ + { + "description": "below the maximum is valid", + "data": 2.6, + "valid": true + }, + { + "description": "boundary point is valid", + "data": 3.0, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values 3.0 and [...] (mismatched types float and list):\n generated.cue:2:1\n generated.cue:2:31\n instance.json:1:1\nconflicting values 3.0 and bool (mismatched types float and bool):\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\nconflicting values 3.0 and null (mismatched types float and null):\n generated.cue:2:1\n instance.json:1:1\nconflicting values 3.0 and string (mismatched types float and string):\n generated.cue:2:1\n generated.cue:2:22\n instance.json:1:1\nconflicting values 3.0 and {...} (mismatched types float and struct):\n generated.cue:2:1\n generated.cue:2:39\n instance.json:1:1\ninvalid value 3.0 (out of bound \u003c3.0):\n generated.cue:2:15\n instance.json:1:1\n" + }, + { + "description": "above the maximum is invalid", + "data": 3.5, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + }, + { + "description": "exclusiveMaximum validation", + "schema": { + "maximum": 3.0, + "exclusiveMaximum": true + }, + "tests": [ + { + "description": "below the maximum is still valid", + "data": 2.2, + "valid": true + }, + { + "description": "boundary point is invalid", + "data": 3.0, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/minItems.json b/encoding/jsonschema/testdata/external/tests/draft4/minItems.json new file mode 100644 index 000000000..1dce2ec07 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/minItems.json @@ -0,0 +1,35 @@ +[ + { + "description": "minItems validation", + "schema": { + "minItems": 1 + }, + "tests": [ + { + "description": "longer is valid", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "exact length is valid", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "too short is invalid", + "data": [], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": "", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/minLength.json b/encoding/jsonschema/testdata/external/tests/draft4/minLength.json new file mode 100644 index 000000000..3d7450b98 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/minLength.json @@ -0,0 +1,35 @@ +[ + { + "description": "minLength validation", + "schema": { + "minLength": 2 + }, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true + }, + { + "description": "exact length is valid", + "data": "fo", + "valid": true + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + }, + { + "description": "ignores non-strings", + "data": 1, + "valid": true + }, + { + "description": "one grapheme is not long enough", + "data": "💩", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/minProperties.json b/encoding/jsonschema/testdata/external/tests/draft4/minProperties.json new file mode 100644 index 000000000..88255c399 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/minProperties.json @@ -0,0 +1,52 @@ +[ + { + "description": "minProperties validation", + "schema": { + "minProperties": 1 + }, + "skip": "extract error: unsupported constraint \"minProperties\"", + "tests": [ + { + "description": "longer is valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "exact length is valid", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ignores arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores strings", + "data": "", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/minimum.json b/encoding/jsonschema/testdata/external/tests/draft4/minimum.json new file mode 100644 index 000000000..cb793c830 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/minimum.json @@ -0,0 +1,122 @@ +[ + { + "description": "minimum validation", + "schema": { + "minimum": 1.1 + }, + "tests": [ + { + "description": "above the minimum is valid", + "data": 2.6, + "valid": true + }, + { + "description": "boundary point is valid", + "data": 1.1, + "valid": true + }, + { + "description": "below the minimum is invalid", + "data": 0.6, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + }, + { + "description": "minimum validation (explicit false exclusivity)", + "schema": { + "minimum": 1.1, + "exclusiveMinimum": false + }, + "tests": [ + { + "description": "above the minimum is valid", + "data": 2.6, + "valid": true + }, + { + "description": "boundary point is valid", + "data": 1.1, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values 1.1 and [...] (mismatched types float and list):\n generated.cue:2:1\n generated.cue:2:31\n instance.json:1:1\nconflicting values 1.1 and bool (mismatched types float and bool):\n generated.cue:2:1\n generated.cue:2:8\n instance.json:1:1\nconflicting values 1.1 and null (mismatched types float and null):\n generated.cue:2:1\n instance.json:1:1\nconflicting values 1.1 and string (mismatched types float and string):\n generated.cue:2:1\n generated.cue:2:22\n instance.json:1:1\nconflicting values 1.1 and {...} (mismatched types float and struct):\n generated.cue:2:1\n generated.cue:2:39\n instance.json:1:1\ninvalid value 1.1 (out of bound \u003e1.1):\n generated.cue:2:15\n instance.json:1:1\n" + }, + { + "description": "below the minimum is invalid", + "data": 0.6, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + }, + { + "description": "exclusiveMinimum validation", + "schema": { + "minimum": 1.1, + "exclusiveMinimum": true + }, + "tests": [ + { + "description": "above the minimum is still valid", + "data": 1.2, + "valid": true + }, + { + "description": "boundary point is invalid", + "data": 1.1, + "valid": false + } + ] + }, + { + "description": "minimum validation with signed integer", + "schema": { + "minimum": -2 + }, + "tests": [ + { + "description": "negative above the minimum is valid", + "data": -1, + "valid": true + }, + { + "description": "positive above the minimum is valid", + "data": 0, + "valid": true + }, + { + "description": "boundary point is valid", + "data": -2, + "valid": true + }, + { + "description": "boundary point with float is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float below the minimum is invalid", + "data": -2.0001, + "valid": false + }, + { + "description": "int below the minimum is invalid", + "data": -3, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/multipleOf.json b/encoding/jsonschema/testdata/external/tests/draft4/multipleOf.json new file mode 100644 index 000000000..5a965df2e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/multipleOf.json @@ -0,0 +1,94 @@ +[ + { + "description": "by int", + "schema": { + "multipleOf": 2 + }, + "tests": [ + { + "description": "int by int", + "data": 10, + "valid": true + }, + { + "description": "int by int fail", + "data": 7, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "by number", + "schema": { + "multipleOf": 1.5 + }, + "tests": [ + { + "description": "zero is multiple of anything", + "data": 0, + "valid": true + }, + { + "description": "4.5 is multiple of 1.5", + "data": 4.5, + "valid": true + }, + { + "description": "35 is not multiple of 1.5", + "data": 35, + "valid": false + } + ] + }, + { + "description": "by small number", + "schema": { + "multipleOf": 0.0001 + }, + "tests": [ + { + "description": "0.0075 is multiple of 0.0001", + "data": 0.0075, + "valid": true + }, + { + "description": "0.00751 is not multiple of 0.0001", + "data": 0.00751, + "valid": false + } + ] + }, + { + "description": "float division = inf", + "schema": { + "type": "integer", + "multipleOf": 0.123456789 + }, + "tests": [ + { + "description": "invalid, but naive implementations may raise an overflow error", + "data": 1E+308, + "valid": false + } + ] + }, + { + "description": "small multiple of large integer", + "schema": { + "type": "integer", + "multipleOf": 1E-8 + }, + "tests": [ + { + "description": "any integer is a multiple of 1e-8", + "data": 12391239123, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/not.json b/encoding/jsonschema/testdata/external/tests/draft4/not.json new file mode 100644 index 000000000..65ec403bd --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/not.json @@ -0,0 +1,210 @@ +[ + { + "description": "not", + "schema": { + "not": { + "type": "integer" + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "allowed", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "disallowed", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "not multiple types", + "schema": { + "not": { + "type": [ + "integer", + "boolean" + ] + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "other mismatch", + "data": true, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "not more complex schema", + "schema": { + "not": { + "type": "object", + "properties": { + "foo": { + "type": "string" + } + } + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "match", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "other match", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "forbidden property", + "schema": { + "properties": { + "foo": { + "not": {} + } + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "property present", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "property absent", + "data": { + "bar": 1, + "baz": 2 + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "forbid everything with empty schema", + "schema": { + "not": {} + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "null is invalid", + "data": null, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "object is invalid", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "array is invalid", + "data": [ + "foo" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "double negation", + "schema": { + "not": { + "not": {} + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/oneOf.json b/encoding/jsonschema/testdata/external/tests/draft4/oneOf.json new file mode 100644 index 000000000..eadca68be --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/oneOf.json @@ -0,0 +1,293 @@ +[ + { + "description": "oneOf", + "schema": { + "oneOf": [ + { + "type": "integer" + }, + { + "minimum": 2 + } + ] + }, + "tests": [ + { + "description": "first oneOf valid", + "data": 1, + "valid": true + }, + { + "description": "second oneOf valid", + "data": 2.5, + "valid": true + }, + { + "description": "both oneOf valid", + "data": 3, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "neither oneOf valid", + "data": 1.5, + "valid": false + } + ] + }, + { + "description": "oneOf with base schema", + "schema": { + "type": "string", + "oneOf": [ + { + "minLength": 2 + }, + { + "maxLength": 4 + } + ] + }, + "tests": [ + { + "description": "mismatch base schema", + "data": 3, + "valid": false + }, + { + "description": "one oneOf valid", + "data": "foobar", + "valid": true + }, + { + "description": "both oneOf valid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf complex types", + "schema": { + "oneOf": [ + { + "properties": { + "bar": { + "type": "integer" + } + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + } + ] + }, + "tests": [ + { + "description": "first oneOf valid (complex)", + "data": { + "bar": 2 + }, + "valid": true + }, + { + "description": "second oneOf valid (complex)", + "data": { + "foo": "baz" + }, + "valid": true + }, + { + "description": "both oneOf valid (complex)", + "data": { + "foo": "baz", + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "neither oneOf valid (complex)", + "data": { + "foo": 2, + "bar": "quux" + }, + "valid": false + } + ] + }, + { + "description": "oneOf with empty schema", + "schema": { + "oneOf": [ + { + "type": "number" + }, + {} + ] + }, + "tests": [ + { + "description": "one valid - valid", + "data": "foo", + "valid": true + }, + { + "description": "both valid - invalid", + "data": 123, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with required", + "schema": { + "type": "object", + "oneOf": [ + { + "required": [ + "foo", + "bar" + ] + }, + { + "required": [ + "foo", + "baz" + ] + } + ] + }, + "tests": [ + { + "description": "both invalid - invalid", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "first valid - valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "second valid - valid", + "data": { + "foo": 1, + "baz": 3 + }, + "valid": true + }, + { + "description": "both valid - invalid", + "data": { + "foo": 1, + "bar": 2, + "baz": 3 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with missing optional property", + "schema": { + "oneOf": [ + { + "properties": { + "bar": {}, + "baz": {} + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "foo": {} + }, + "required": [ + "foo" + ] + } + ] + }, + "tests": [ + { + "description": "first oneOf valid", + "data": { + "bar": 8 + }, + "valid": true + }, + { + "description": "second oneOf valid", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "both oneOf valid", + "data": { + "foo": "foo", + "bar": 8 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "neither oneOf valid", + "data": { + "baz": "quux" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "nested oneOf, to check validation semantics", + "schema": { + "oneOf": [ + { + "oneOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/optional/bignum.json b/encoding/jsonschema/testdata/external/tests/draft4/optional/bignum.json new file mode 100644 index 000000000..038c1fbd8 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/optional/bignum.json @@ -0,0 +1,105 @@ +[ + { + "description": "integer", + "schema": { + "type": "integer" + }, + "tests": [ + { + "description": "a bignum is an integer", + "data": 12345678910111213141516171819202122232425262728293031, + "valid": true + }, + { + "description": "a negative bignum is an integer", + "data": -12345678910111213141516171819202122232425262728293031, + "valid": true + } + ] + }, + { + "description": "number", + "schema": { + "type": "number" + }, + "tests": [ + { + "description": "a bignum is a number", + "data": 98249283749234923498293171823948729348710298301928331, + "valid": true + }, + { + "description": "a negative bignum is a number", + "data": -98249283749234923498293171823948729348710298301928331, + "valid": true + } + ] + }, + { + "description": "string", + "schema": { + "type": "string" + }, + "tests": [ + { + "description": "a bignum is not a string", + "data": 98249283749234923498293171823948729348710298301928331, + "valid": false + } + ] + }, + { + "description": "maximum integer comparison", + "schema": { + "maximum": 18446744073709551615 + }, + "tests": [ + { + "description": "comparison works for high numbers", + "data": 18446744073709551600, + "valid": true + } + ] + }, + { + "description": "float comparison with high precision", + "schema": { + "maximum": 972783798187987123879878123.18878137, + "exclusiveMaximum": true + }, + "tests": [ + { + "description": "comparison works for high numbers", + "data": 972783798187987123879878123.188781371, + "valid": false + } + ] + }, + { + "description": "minimum integer comparison", + "schema": { + "minimum": -18446744073709551615 + }, + "tests": [ + { + "description": "comparison works for very negative numbers", + "data": -18446744073709551600, + "valid": true + } + ] + }, + { + "description": "float comparison with high precision on negative numbers", + "schema": { + "minimum": -972783798187987123879878123.18878137, + "exclusiveMinimum": true + }, + "tests": [ + { + "description": "comparison works for very negative numbers", + "data": -972783798187987123879878123.188781371, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/optional/ecmascript-regex.json b/encoding/jsonschema/testdata/external/tests/draft4/optional/ecmascript-regex.json new file mode 100644 index 000000000..5770bfc44 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/optional/ecmascript-regex.json @@ -0,0 +1,630 @@ +[ + { + "description": "ECMA 262 regex $ does not match trailing newline", + "schema": { + "type": "string", + "pattern": "^abc$" + }, + "tests": [ + { + "description": "matches in Python, but not in ECMA 262", + "data": "abc\\n", + "valid": false + }, + { + "description": "matches", + "data": "abc", + "valid": true + } + ] + }, + { + "description": "ECMA 262 regex converts \\t to horizontal tab", + "schema": { + "type": "string", + "pattern": "^\\t$" + }, + "tests": [ + { + "description": "does not match", + "data": "\\t", + "valid": false + }, + { + "description": "matches", + "data": "\t", + "valid": true + } + ] + }, + { + "description": "ECMA 262 regex escapes control codes with \\c and upper letter", + "schema": { + "type": "string", + "pattern": "^\\cC$" + }, + "skip": "extract error: unsupported regexp: error parsing regexp: invalid escape sequence: `\\c`", + "tests": [ + { + "description": "does not match", + "data": "\\cC", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "matches", + "data": "\u0003", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ECMA 262 regex escapes control codes with \\c and lower letter", + "schema": { + "type": "string", + "pattern": "^\\cc$" + }, + "skip": "extract error: unsupported regexp: error parsing regexp: invalid escape sequence: `\\c`", + "tests": [ + { + "description": "does not match", + "data": "\\cc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "matches", + "data": "\u0003", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ECMA 262 \\d matches ascii digits only", + "schema": { + "type": "string", + "pattern": "^\\d$" + }, + "tests": [ + { + "description": "ASCII zero matches", + "data": "0", + "valid": true + }, + { + "description": "NKO DIGIT ZERO does not match (unlike e.g. Python)", + "data": "߀", + "valid": false + }, + { + "description": "NKO DIGIT ZERO (as \\u escape) does not match", + "data": "߀", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\D matches everything but ascii digits", + "schema": { + "type": "string", + "pattern": "^\\D$" + }, + "tests": [ + { + "description": "ASCII zero does not match", + "data": "0", + "valid": false + }, + { + "description": "NKO DIGIT ZERO matches (unlike e.g. Python)", + "data": "߀", + "valid": true + }, + { + "description": "NKO DIGIT ZERO (as \\u escape) matches", + "data": "߀", + "valid": true + } + ] + }, + { + "description": "ECMA 262 \\w matches ascii letters only", + "schema": { + "type": "string", + "pattern": "^\\w$" + }, + "tests": [ + { + "description": "ASCII 'a' matches", + "data": "a", + "valid": true + }, + { + "description": "latin-1 e-acute does not match (unlike e.g. Python)", + "data": "é", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\W matches everything but ascii letters", + "schema": { + "type": "string", + "pattern": "^\\W$" + }, + "tests": [ + { + "description": "ASCII 'a' does not match", + "data": "a", + "valid": false + }, + { + "description": "latin-1 e-acute matches (unlike e.g. Python)", + "data": "é", + "valid": true + } + ] + }, + { + "description": "ECMA 262 \\s matches whitespace", + "schema": { + "type": "string", + "pattern": "^\\s$" + }, + "tests": [ + { + "description": "ASCII space matches", + "data": " ", + "valid": true + }, + { + "description": "Character tabulation matches", + "data": "\t", + "valid": true + }, + { + "description": "Line tabulation matches", + "data": "\u000b", + "valid": true, + "skip": "invalid value \"\\v\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "Form feed matches", + "data": "\f", + "valid": true + }, + { + "description": "latin-1 non-breaking-space matches", + "data": " ", + "valid": true, + "skip": "invalid value \"\\u00a0\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "zero-width whitespace matches", + "data": "\ufeff", + "valid": true, + "skip": "invalid value \"\\ufeff\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "line feed matches (line terminator)", + "data": "\n", + "valid": true + }, + { + "description": "paragraph separator matches (line terminator)", + "data": "\u2029", + "valid": true, + "skip": "invalid value \"\\u2029\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "EM SPACE matches (Space_Separator)", + "data": " ", + "valid": true, + "skip": "invalid value \"\\u2003\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "Non-whitespace control does not match", + "data": "\u0001", + "valid": false + }, + { + "description": "Non-whitespace does not match", + "data": "–", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\S matches everything but whitespace", + "schema": { + "type": "string", + "pattern": "^\\S$" + }, + "tests": [ + { + "description": "ASCII space does not match", + "data": " ", + "valid": false + }, + { + "description": "Character tabulation does not match", + "data": "\t", + "valid": false + }, + { + "description": "Line tabulation does not match", + "data": "\u000b", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "Form feed does not match", + "data": "\f", + "valid": false + }, + { + "description": "latin-1 non-breaking-space does not match", + "data": " ", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "zero-width whitespace does not match", + "data": "\ufeff", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "line feed does not match (line terminator)", + "data": "\n", + "valid": false + }, + { + "description": "paragraph separator does not match (line terminator)", + "data": "\u2029", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "EM SPACE does not match (Space_Separator)", + "data": " ", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "Non-whitespace control matches", + "data": "\u0001", + "valid": true + }, + { + "description": "Non-whitespace matches", + "data": "–", + "valid": true + } + ] + }, + { + "description": "patterns always use unicode semantics with pattern", + "schema": { + "pattern": "\\p{Letter}cole" + }, + "skip": "extract error: unsupported regexp: error parsing regexp: invalid character class range: `\\p{Letter}`", + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ÉTAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ÉCOLE, L'ÉGLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ÉTAIT SUR LA PATINOIRE.", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "\\w in patterns matches [A-Za-z0-9_], not unicode letters", + "schema": { + "pattern": "\\wcole" + }, + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": false + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ÉTAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ÉCOLE, L'ÉGLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ÉTAIT SUR LA PATINOIRE.", + "valid": false + } + ] + }, + { + "description": "pattern with ASCII ranges", + "schema": { + "pattern": "[a-z]cole" + }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": false + }, + { + "description": "ascii characters match", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + } + ] + }, + { + "description": "\\d in pattern matches [0-9], not unicode digits", + "schema": { + "pattern": "^\\d+$" + }, + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "৪২", + "valid": false + } + ] + }, + { + "description": "pattern with non-ASCII digits", + "schema": { + "pattern": "^\\p{digit}+$" + }, + "skip": "extract error: unsupported regexp: error parsing regexp: invalid character class range: `\\p{digit}`", + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "৪২", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "patterns always use unicode semantics with patternProperties", + "schema": { + "type": "object", + "patternProperties": { + "\\p{Letter}cole": {} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { + "l'ecole": "pas de vraie vie" + }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": true + }, + { + "description": "unicode character in hex format in string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": true + }, + { + "description": "unicode matching is case-sensitive", + "data": { + "L'ÉCOLE": "PAS DE VRAIE VIE" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "\\w in patternProperties matches [A-Za-z0-9_], not unicode letters", + "schema": { + "type": "object", + "patternProperties": { + "\\wcole": {} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { + "l'ecole": "pas de vraie vie" + }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "unicode character in hex format in string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "unicode matching is case-sensitive", + "data": { + "L'ÉCOLE": "PAS DE VRAIE VIE" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "patternProperties with ASCII ranges", + "schema": { + "type": "object", + "patternProperties": { + "[a-z]cole": {} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "unicode character in hex format in string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ascii characters match", + "data": { + "l'ecole": "pas de vraie vie" + }, + "valid": true + } + ] + }, + { + "description": "\\d in patternProperties matches [0-9], not unicode digits", + "schema": { + "type": "object", + "patternProperties": { + "^\\d+$": {} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { + "42": "life, the universe, and everything" + }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { + "-%#": "spending the year dead for tax reasons" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { + "৪২": "khajit has wares if you have coin" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "patternProperties with non-ASCII digits", + "schema": { + "type": "object", + "patternProperties": { + "^\\p{digit}+$": {} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { + "42": "life, the universe, and everything" + }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { + "-%#": "spending the year dead for tax reasons" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { + "৪২": "khajit has wares if you have coin" + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/optional/float-overflow.json b/encoding/jsonschema/testdata/external/tests/draft4/optional/float-overflow.json new file mode 100644 index 000000000..765d86b4f --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/optional/float-overflow.json @@ -0,0 +1,16 @@ +[ + { + "description": "all integers are multiples of 0.5, if overflow is handled", + "schema": { + "type": "number", + "multipleOf": 0.5 + }, + "tests": [ + { + "description": "valid if optional overflow handling is implemented", + "data": 1E+308, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/optional/format/date-time.json b/encoding/jsonschema/testdata/external/tests/draft4/optional/format/date-time.json new file mode 100644 index 000000000..970385b11 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/optional/format/date-time.json @@ -0,0 +1,161 @@ +[ + { + "description": "validation of date-time strings", + "schema": { + "format": "date-time" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time string", + "data": "1963-06-19T08:30:06.283185Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time string without second fraction", + "data": "1963-06-19T08:30:06Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time string with plus offset", + "data": "1937-01-01T12:00:27.87+00:20", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time string with minus offset", + "data": "1990-12-31T15:59:50.123-08:00", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time with a leap second, UTC", + "data": "1998-12-31T23:59:60Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time with a leap second, with minus offset", + "data": "1998-12-31T15:59:60.123-08:00", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid date-time past leap second, UTC", + "data": "1998-12-31T23:59:61Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid date-time with leap second on a wrong minute, UTC", + "data": "1998-12-31T23:58:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid date-time with leap second on a wrong hour, UTC", + "data": "1998-12-31T22:59:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid day in date-time string", + "data": "1990-02-31T15:59:59.123-08:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid offset in date-time string", + "data": "1990-12-31T15:59:59-24:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid closing Z after time-zone offset", + "data": "1963-06-19T08:30:06.28123+01:00Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid date-time string", + "data": "06/19/1963 08:30:06 PST", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "case-insensitive T and Z", + "data": "1963-06-19t08:30:06.283185z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "2013-350T01:01:01", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-padded month dates", + "data": "1963-6-19T08:30:06.283185Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-padded day dates", + "data": "1963-06-1T08:30:06.283185Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4) in date portion", + "data": "1963-06-1৪T00:00:00Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4) in time portion", + "data": "1963-06-11T0৪:00:00Z", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/optional/format/email.json b/encoding/jsonschema/testdata/external/tests/draft4/optional/format/email.json new file mode 100644 index 000000000..3d9734d2f --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/optional/format/email.json @@ -0,0 +1,101 @@ +[ + { + "description": "validation of e-mail addresses", + "schema": { + "format": "email" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid e-mail address", + "data": "joe.bloggs@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid e-mail address", + "data": "2962", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "tilde in local part is valid", + "data": "te~st@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "tilde before local part is valid", + "data": "~test@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "tilde after local part is valid", + "data": "test~@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "dot before local part is not valid", + "data": ".test@example.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "dot after local part is not valid", + "data": "test.@example.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "two separated dots inside local part are valid", + "data": "te.s.t@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "two subsequent dots inside local part are not valid", + "data": "te..st@example.com", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/optional/format/hostname.json b/encoding/jsonschema/testdata/external/tests/draft4/optional/format/hostname.json new file mode 100644 index 000000000..848785f52 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/optional/format/hostname.json @@ -0,0 +1,143 @@ +[ + { + "description": "validation of host names", + "schema": { + "format": "hostname" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid host name", + "data": "www.example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid punycoded IDN hostname", + "data": "xn--4gbwdl.xn--wgbh1c", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a host name starting with an illegal character", + "data": "-a-host-name-that-starts-with--", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a host name containing illegal characters", + "data": "not_a_valid_host_name", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a host name with a component too long", + "data": "a-vvvvvvvvvvvvvvvveeeeeeeeeeeeeeeerrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy-long-host-name-component", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "starts with hyphen", + "data": "-hostname", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ends with hyphen", + "data": "hostname-", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "starts with underscore", + "data": "_hostname", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ends with underscore", + "data": "hostname_", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "contains underscore", + "data": "host_name", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "exceeds maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "single label", + "data": "hostname", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label with hyphen", + "data": "host-name", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label with digits", + "data": "h0stn4me", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label ending with digit", + "data": "hostnam3", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/optional/format/ipv4.json b/encoding/jsonschema/testdata/external/tests/draft4/optional/format/ipv4.json new file mode 100644 index 000000000..1ef0f11f8 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/optional/format/ipv4.json @@ -0,0 +1,108 @@ +[ + { + "description": "validation of IP addresses", + "schema": { + "format": "ipv4" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IP address", + "data": "192.168.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an IP address with too many components", + "data": "127.0.0.0.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IP address with out-of-range values", + "data": "256.256.256.256", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IP address without 4 components", + "data": "127.0", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IP address as an integer", + "data": "0x7f000001", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IP address as an integer (decimal)", + "data": "2130706433", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid leading zeroes, as they are treated as octals", + "comment": "see https://sick.codes/universal-netmask-npm-package-used-by-270000-projects-vulnerable-to-octal-input-data-server-side-request-forgery-remote-file-inclusion-local-file-inclusion-and-more-cve-2021-28918/", + "data": "087.10.0.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "value without leading zero is valid", + "data": "87.10.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '২' (a Bengali 2)", + "data": "1২7.0.0.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "netmask is not a part of ipv4 address", + "data": "192.168.1.0/24", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/optional/format/ipv6.json b/encoding/jsonschema/testdata/external/tests/draft4/optional/format/ipv6.json new file mode 100644 index 000000000..0c8edf677 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/optional/format/ipv6.json @@ -0,0 +1,251 @@ +[ + { + "description": "validation of IPv6 addresses", + "schema": { + "format": "ipv6" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IPv6 address", + "data": "::1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an IPv6 address with out-of-range values", + "data": "12345::", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "trailing 4 hex symbols is valid", + "data": "::abef", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "trailing 5 hex symbols is invalid", + "data": "::abcef", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IPv6 address with too many components", + "data": "1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IPv6 address containing illegal characters", + "data": "::laptop", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no digits is valid", + "data": "::", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "leading colons is valid", + "data": "::42:ff:1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "trailing colons is valid", + "data": "d6::", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "missing leading octet is invalid", + "data": ":2:3:4:5:6:7:8", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "missing trailing octet is invalid", + "data": "1:2:3:4:5:6:7:", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "missing leading octet with omitted octets later", + "data": ":2:3:4::8", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "single set of double colons in the middle is valid", + "data": "1:d6::42", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "two sets of double colons is invalid", + "data": "1::d6::42", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "mixed format with the ipv4 section as decimal octets", + "data": "1::d6:192.168.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mixed format with double colons between the sections", + "data": "1:2::192.168.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mixed format with ipv4 section with octet out of range", + "data": "1::2:192.168.256.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "mixed format with ipv4 section with a hex octet", + "data": "1::2:192.168.ff.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "mixed format with leading double colons (ipv4-mapped ipv6 address)", + "data": "::ffff:192.168.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "triple colons is invalid", + "data": "1:2:3:4:5:::8", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "8 octets", + "data": "1:2:3:4:5:6:7:8", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "insufficient octets without double colons", + "data": "1:2:3:4:5:6:7", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no colons is invalid", + "data": "1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ipv4 is not ipv6", + "data": "127.0.0.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ipv4 segment must have 4 octets", + "data": "1:2:3:4:1.2.3", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "leading whitespace is invalid", + "data": " ::1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "trailing whitespace is invalid", + "data": "::1 ", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "netmask is not a part of ipv6 address", + "data": "fe80::/64", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "zone id is not a part of ipv6 address", + "data": "fe80::a%eth1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a long valid ipv6", + "data": "1000:1000:1000:1000:1000:1000:255.255.255.255", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a long invalid ipv6, below length limit, first", + "data": "100:100:100:100:100:100:255.255.255.255.255", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a long invalid ipv6, below length limit, second", + "data": "100:100:100:100:100:100:100:255.255.255.255", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4)", + "data": "1:2:3:4:5:6:7:৪", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4) in the IPv4 portion", + "data": "1:2::192.16৪.0.1", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/optional/format/unknown.json b/encoding/jsonschema/testdata/external/tests/draft4/optional/format/unknown.json new file mode 100644 index 000000000..97a7ae39e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/optional/format/unknown.json @@ -0,0 +1,53 @@ +[ + { + "description": "unknown format", + "schema": { + "format": "unknown" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "unknown formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore strings", + "data": "string", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/optional/format/uri.json b/encoding/jsonschema/testdata/external/tests/draft4/optional/format/uri.json new file mode 100644 index 000000000..9dfe867c4 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/optional/format/uri.json @@ -0,0 +1,167 @@ +[ + { + "description": "validation of URIs", + "schema": { + "format": "uri" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with anchor tag", + "data": "http://foo.bar/?baz=qux#quux", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with anchor tag and parentheses", + "data": "http://foo.com/blah_(wikipedia)_blah#cite-1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with URL-encoded stuff", + "data": "http://foo.bar/?q=Test%20URL-encoded%20stuff", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid puny-coded URL ", + "data": "http://xn--nw2a.xn--j6w193g/", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with many special characters", + "data": "http://-.~_!$\u0026'()*+,;=:%40:80%2f::::::@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL based on IPv4", + "data": "http://223.255.255.254", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with ftp scheme", + "data": "ftp://ftp.is.co.za/rfc/rfc1808.txt", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL for a simple text file", + "data": "http://www.ietf.org/rfc/rfc2396.txt", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL ", + "data": "ldap://[2001:db8::7]/c=GB?objectClass?one", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid mailto URI", + "data": "mailto:John.Doe@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid newsgroup URI", + "data": "news:comp.infosystems.www.servers.unix", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid tel URI", + "data": "tel:+1-816-555-1212", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URN", + "data": "urn:oasis:names:specification:docbook:dtd:xml:4.1.2", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid protocol-relative URI Reference", + "data": "//foo.bar/?baz=qux#quux", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid relative URI Reference", + "data": "/abc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI", + "data": "\\\\WINDOWS\\fileshare", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI though valid URI reference", + "data": "abc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI with spaces", + "data": "http:// shouldfail.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI with spaces and missing scheme", + "data": ":// should fail", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI with comma in scheme", + "data": "bar,baz:foo", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/optional/id.json b/encoding/jsonschema/testdata/external/tests/draft4/optional/id.json new file mode 100644 index 000000000..a84e77806 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/optional/id.json @@ -0,0 +1,60 @@ +[ + { + "description": "id inside an enum is not a real identifier", + "comment": "the implementation must not be confused by an id buried in the enum", + "schema": { + "definitions": { + "id_in_enum": { + "enum": [ + { + "id": "https://localhost:1234/my_identifier.json", + "type": "null" + } + ] + }, + "real_id_in_schema": { + "id": "https://localhost:1234/my_identifier.json", + "type": "string" + }, + "zzz_id_in_const": { + "const": { + "id": "https://localhost:1234/my_identifier.json", + "type": "null" + } + } + }, + "anyOf": [ + { + "$ref": "#/definitions/id_in_enum" + }, + { + "$ref": "https://localhost:1234/my_identifier.json" + } + ] + }, + "skip": "extract error: constraint \"const\" is not supported in JSON schema version http://json-schema.org/draft-04/schema#", + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "id": "https://localhost:1234/my_identifier.json", + "type": "null" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "match $ref to id", + "data": "a string to match #/definitions/id_in_enum", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "no match on enum or $ref to id", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/optional/non-bmp-regex.json b/encoding/jsonschema/testdata/external/tests/draft4/optional/non-bmp-regex.json new file mode 100644 index 000000000..3ea9d0e2e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/optional/non-bmp-regex.json @@ -0,0 +1,94 @@ +[ + { + "description": "Proper UTF-16 surrogate pair handling: pattern", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { + "pattern": "^🐲*$" + }, + "tests": [ + { + "description": "matches empty", + "data": "", + "valid": true + }, + { + "description": "matches single", + "data": "🐲", + "valid": true + }, + { + "description": "matches two", + "data": "🐲🐲", + "valid": true + }, + { + "description": "doesn't match one", + "data": "🐉", + "valid": false + }, + { + "description": "doesn't match two", + "data": "🐉🐉", + "valid": false + }, + { + "description": "doesn't match one ASCII", + "data": "D", + "valid": false + }, + { + "description": "doesn't match two ASCII", + "data": "DD", + "valid": false + } + ] + }, + { + "description": "Proper UTF-16 surrogate pair handling: patternProperties", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { + "patternProperties": { + "^🐲*$": { + "type": "integer" + } + } + }, + "tests": [ + { + "description": "matches empty", + "data": { + "": 1 + }, + "valid": true + }, + { + "description": "matches single", + "data": { + "🐲": 1 + }, + "valid": true + }, + { + "description": "matches two", + "data": { + "🐲🐲": 1 + }, + "valid": true + }, + { + "description": "doesn't match one", + "data": { + "🐲": "hello" + }, + "valid": false + }, + { + "description": "doesn't match two", + "data": { + "🐲🐲": "hello" + }, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/optional/zeroTerminatedFloats.json b/encoding/jsonschema/testdata/external/tests/draft4/optional/zeroTerminatedFloats.json new file mode 100644 index 000000000..0772afe8c --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/optional/zeroTerminatedFloats.json @@ -0,0 +1,15 @@ +[ + { + "description": "some languages do not distinguish between different types of numeric value", + "schema": { + "type": "integer" + }, + "tests": [ + { + "description": "a float is not an integer even without fractional part", + "data": 1.0, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/pattern.json b/encoding/jsonschema/testdata/external/tests/draft4/pattern.json new file mode 100644 index 000000000..b2d1ee318 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/pattern.json @@ -0,0 +1,63 @@ +[ + { + "description": "pattern validation", + "schema": { + "pattern": "^a*$" + }, + "tests": [ + { + "description": "a matching pattern is valid", + "data": "aaa", + "valid": true + }, + { + "description": "a non-matching pattern is invalid", + "data": "abc", + "valid": false + }, + { + "description": "ignores booleans", + "data": true, + "valid": true + }, + { + "description": "ignores integers", + "data": 123, + "valid": true + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true + }, + { + "description": "ignores objects", + "data": {}, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores null", + "data": null, + "valid": true + } + ] + }, + { + "description": "pattern is not anchored", + "schema": { + "pattern": "a+" + }, + "tests": [ + { + "description": "matches a substring", + "data": "xxaayy", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/patternProperties.json b/encoding/jsonschema/testdata/external/tests/draft4/patternProperties.json new file mode 100644 index 000000000..ba141f603 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/patternProperties.json @@ -0,0 +1,181 @@ +[ + { + "description": "patternProperties validates properties matching a regex", + "schema": { + "patternProperties": { + "f.*o": { + "type": "integer" + } + } + }, + "tests": [ + { + "description": "a single valid match is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "multiple valid matches is valid", + "data": { + "foo": 1, + "foooooo": 2 + }, + "valid": true + }, + { + "description": "a single invalid match is invalid", + "data": { + "foo": "bar", + "fooooo": 2 + }, + "valid": false + }, + { + "description": "multiple invalid matches is invalid", + "data": { + "foo": "bar", + "foooooo": "baz" + }, + "valid": false + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", + "data": "", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "multiple simultaneous patternProperties are validated", + "schema": { + "patternProperties": { + "a*": { + "type": "integer" + }, + "aaa*": { + "maximum": 20 + } + } + }, + "tests": [ + { + "description": "a single valid match is valid", + "data": { + "a": 21 + }, + "valid": true + }, + { + "description": "a simultaneous match is valid", + "data": { + "aaaa": 18 + }, + "valid": true + }, + { + "description": "multiple matches is valid", + "data": { + "a": 21, + "aaaa": 18 + }, + "valid": true + }, + { + "description": "an invalid due to one is invalid", + "data": { + "a": "bar" + }, + "valid": false + }, + { + "description": "an invalid due to the other is invalid", + "data": { + "aaaa": 31 + }, + "valid": false + }, + { + "description": "an invalid due to both is invalid", + "data": { + "aaa": "foo", + "aaaa": 31 + }, + "valid": false + } + ] + }, + { + "description": "regexes are not anchored by default and are case sensitive", + "schema": { + "patternProperties": { + "[0-9]{2,}": { + "type": "boolean" + }, + "X_": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "non recognized members are ignored", + "data": { + "answer 1": "42" + }, + "valid": true + }, + { + "description": "recognized members are accounted for", + "data": { + "a31b": null + }, + "valid": false + }, + { + "description": "regexes are case sensitive", + "data": { + "a_x_3": 3 + }, + "valid": true + }, + { + "description": "regexes are case sensitive, 2", + "data": { + "a_X_3": 3 + }, + "valid": false + } + ] + }, + { + "description": "patternProperties with null valued instance properties", + "schema": { + "patternProperties": { + "^.*bar$": { + "type": "null" + } + } + }, + "tests": [ + { + "description": "allows null values", + "data": { + "foobar": null + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/properties.json b/encoding/jsonschema/testdata/external/tests/draft4/properties.json new file mode 100644 index 000000000..02049574c --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/properties.json @@ -0,0 +1,294 @@ +[ + { + "description": "object properties validation", + "schema": { + "properties": { + "foo": { + "type": "integer" + }, + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "both properties present and valid is valid", + "data": { + "foo": 1, + "bar": "baz" + }, + "valid": true + }, + { + "description": "one property invalid is invalid", + "data": { + "foo": 1, + "bar": {} + }, + "valid": false + }, + { + "description": "both properties invalid is invalid", + "data": { + "foo": [], + "bar": {} + }, + "valid": false + }, + { + "description": "doesn't invalidate other properties", + "data": { + "quux": [] + }, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "properties, patternProperties, additionalProperties interaction", + "schema": { + "properties": { + "foo": { + "type": "array", + "maxItems": 3 + }, + "bar": { + "type": "array" + } + }, + "patternProperties": { + "f.o": { + "minItems": 2 + } + }, + "additionalProperties": { + "type": "integer" + } + }, + "tests": [ + { + "description": "property validates property", + "data": { + "foo": [ + 1, + 2 + ] + }, + "valid": true + }, + { + "description": "property invalidates property", + "data": { + "foo": [ + 1, + 2, + 3, + 4 + ] + }, + "valid": false + }, + { + "description": "patternProperty invalidates property", + "data": { + "foo": [] + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "patternProperty validates nonproperty", + "data": { + "fxo": [ + 1, + 2 + ] + }, + "valid": true + }, + { + "description": "patternProperty invalidates nonproperty", + "data": { + "fxo": [] + }, + "valid": false + }, + { + "description": "additionalProperty ignores property", + "data": { + "bar": [] + }, + "valid": true + }, + { + "description": "additionalProperty validates others", + "data": { + "quux": 3 + }, + "valid": true + }, + { + "description": "additionalProperty invalidates others", + "data": { + "quux": "foo" + }, + "valid": false + } + ] + }, + { + "description": "properties with escaped characters", + "schema": { + "properties": { + "foo\nbar": { + "type": "number" + }, + "foo\"bar": { + "type": "number" + }, + "foo\\bar": { + "type": "number" + }, + "foo\rbar": { + "type": "number" + }, + "foo\tbar": { + "type": "number" + }, + "foo\fbar": { + "type": "number" + } + } + }, + "tests": [ + { + "description": "object with all numbers is valid", + "data": { + "foo\nbar": 1, + "foo\"bar": 1, + "foo\\bar": 1, + "foo\rbar": 1, + "foo\tbar": 1, + "foo\fbar": 1 + }, + "valid": true + }, + { + "description": "object with strings is invalid", + "data": { + "foo\nbar": "1", + "foo\"bar": "1", + "foo\\bar": "1", + "foo\rbar": "1", + "foo\tbar": "1", + "foo\fbar": "1" + }, + "valid": false + } + ] + }, + { + "description": "properties with null valued instance properties", + "schema": { + "properties": { + "foo": { + "type": "null" + } + } + }, + "tests": [ + { + "description": "allows null values", + "data": { + "foo": null + }, + "valid": true + } + ] + }, + { + "description": "properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { + "properties": { + "__proto__": { + "type": "number" + }, + "toString": { + "properties": { + "length": { + "type": "string" + } + } + }, + "constructor": { + "type": "number" + } + } + }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": true + }, + { + "description": "__proto__ not valid", + "data": { + "__proto__": "foo" + }, + "valid": false + }, + { + "description": "toString not valid", + "data": { + "toString": { + "length": 37 + } + }, + "valid": false + }, + { + "description": "constructor not valid", + "data": { + "constructor": { + "length": 37 + } + }, + "valid": false + }, + { + "description": "all present and valid", + "data": { + "__proto__": 12, + "toString": { + "length": "foo" + }, + "constructor": 37 + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/ref.json b/encoding/jsonschema/testdata/external/tests/draft4/ref.json new file mode 100644 index 000000000..20b760fb6 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/ref.json @@ -0,0 +1,765 @@ +[ + { + "description": "root pointer ref", + "schema": { + "properties": { + "foo": { + "$ref": "#" + } + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "match", + "data": { + "foo": false + }, + "valid": true + }, + { + "description": "recursive match", + "data": { + "foo": { + "foo": false + } + }, + "valid": true + }, + { + "description": "mismatch", + "data": { + "bar": false + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "recursive mismatch", + "data": { + "foo": { + "bar": false + } + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "relative pointer ref to object", + "schema": { + "properties": { + "foo": { + "type": "integer" + }, + "bar": { + "$ref": "#/properties/foo" + } + } + }, + "skip": "extract error: cannot compile resulting schema: bar: reference \"foo\" not found:\n generated.cue:4:10\n", + "tests": [ + { + "description": "match", + "data": { + "bar": 3 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": { + "bar": true + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "relative pointer ref to array", + "schema": { + "items": [ + { + "type": "integer" + }, + { + "$ref": "#/items/0" + } + ] + }, + "skip": "extract error: referring to field \"items\" not yet supported", + "tests": [ + { + "description": "match array", + "data": [ + 1, + 2 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch array", + "data": [ + 1, + "foo" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "escaped pointer ref", + "schema": { + "definitions": { + "tilde~field": { + "type": "integer" + }, + "slash/field": { + "type": "integer" + }, + "percent%field": { + "type": "integer" + } + }, + "properties": { + "tilde": { + "$ref": "#/definitions/tilde~0field" + }, + "slash": { + "$ref": "#/definitions/slash~1field" + }, + "percent": { + "$ref": "#/definitions/percent%25field" + } + } + }, + "tests": [ + { + "description": "slash invalid", + "data": { + "slash": "aoeu" + }, + "valid": false + }, + { + "description": "tilde invalid", + "data": { + "tilde": "aoeu" + }, + "valid": false + }, + { + "description": "percent invalid", + "data": { + "percent": "aoeu" + }, + "valid": false + }, + { + "description": "slash valid", + "data": { + "slash": 123 + }, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values [...] and {slash:123} (mismatched types list and struct):\n generated.cue:2:33\n instance.json:1:1\nconflicting values bool and {slash:123} (mismatched types bool and struct):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and {slash:123} (mismatched types null and struct):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and {slash:123} (mismatched types number and struct):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and {slash:123} (mismatched types string and struct):\n generated.cue:2:24\n instance.json:1:1\nslash: undefined field: \"slash~1field\":\n generated.cue:4:14\n" + }, + { + "description": "tilde valid", + "data": { + "tilde": 123 + }, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values [...] and {tilde:123} (mismatched types list and struct):\n generated.cue:2:33\n instance.json:1:1\nconflicting values bool and {tilde:123} (mismatched types bool and struct):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and {tilde:123} (mismatched types null and struct):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and {tilde:123} (mismatched types number and struct):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and {tilde:123} (mismatched types string and struct):\n generated.cue:2:24\n instance.json:1:1\ntilde: undefined field: \"tilde~0field\":\n generated.cue:3:14\n" + }, + { + "description": "percent valid", + "data": { + "percent": 123 + }, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values [...] and {percent:123} (mismatched types list and struct):\n generated.cue:2:33\n instance.json:1:1\nconflicting values bool and {percent:123} (mismatched types bool and struct):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and {percent:123} (mismatched types null and struct):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and {percent:123} (mismatched types number and struct):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and {percent:123} (mismatched types string and struct):\n generated.cue:2:24\n instance.json:1:1\npercent: undefined field: \"percent%25field\":\n generated.cue:5:14\n" + } + ] + }, + { + "description": "nested refs", + "schema": { + "definitions": { + "a": { + "type": "integer" + }, + "b": { + "$ref": "#/definitions/a" + }, + "c": { + "$ref": "#/definitions/b" + } + }, + "allOf": [ + { + "$ref": "#/definitions/c" + } + ] + }, + "tests": [ + { + "description": "nested ref valid", + "data": 5, + "valid": true + }, + { + "description": "nested ref invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "ref overrides any sibling keywords", + "schema": { + "definitions": { + "reffed": { + "type": "array" + } + }, + "properties": { + "foo": { + "$ref": "#/definitions/reffed", + "maxItems": 2 + } + } + }, + "tests": [ + { + "description": "ref valid", + "data": { + "foo": [] + }, + "valid": true + }, + { + "description": "ref valid, maxItems ignored", + "data": { + "foo": [ + 1, + 2, + 3 + ] + }, + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [...] and {foo:[1,2,3]} (mismatched types list and struct):\n generated.cue:3:33\n instance.json:1:1\nconflicting values bool and {foo:[1,2,3]} (mismatched types bool and struct):\n generated.cue:3:8\n instance.json:1:1\nconflicting values null and {foo:[1,2,3]} (mismatched types null and struct):\n generated.cue:3:1\n instance.json:1:1\nconflicting values number and {foo:[1,2,3]} (mismatched types number and struct):\n generated.cue:3:15\n instance.json:1:1\nconflicting values string and {foo:[1,2,3]} (mismatched types string and struct):\n generated.cue:3:24\n instance.json:1:1\n" + }, + { + "description": "ref invalid", + "data": { + "foo": "string" + }, + "valid": false + } + ] + }, + { + "description": "$ref prevents a sibling id from changing the base uri", + "schema": { + "id": "http://localhost:1234/sibling_id/base/", + "definitions": { + "foo": { + "id": "http://localhost:1234/sibling_id/foo.json", + "type": "string" + }, + "base_foo": { + "$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json", + "id": "foo.json", + "type": "number" + } + }, + "allOf": [ + { + "$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not http://localhost:1234/sibling_id/foo.json", + "id": "http://localhost:1234/sibling_id/", + "$ref": "foo.json" + } + ] + }, + "skip": "extract error: constraint \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-04/schema# (and 1 more errors)", + "tests": [ + { + "description": "$ref resolves to /definitions/base_foo, data does not validate", + "data": "a", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "$ref resolves to /definitions/base_foo, data validates", + "data": 1, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "remote ref, containing refs itself", + "schema": { + "$ref": "http://json-schema.org/draft-04/schema#" + }, + "skip": "extract error: cannot compile resulting schema: package \"json-schema.org/draft-04/schema\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "remote ref valid", + "data": { + "minLength": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "remote ref invalid", + "data": { + "minLength": -1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "property named $ref that is not a reference", + "schema": { + "properties": { + "$ref": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": { + "$ref": "a" + }, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": { + "$ref": 2 + }, + "valid": false + } + ] + }, + { + "description": "property named $ref, containing an actual $ref", + "schema": { + "properties": { + "$ref": { + "$ref": "#/definitions/is-string" + } + }, + "definitions": { + "is-string": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": { + "$ref": "a" + }, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": { + "$ref": 2 + }, + "valid": false + } + ] + }, + { + "description": "Recursive references between schemas", + "schema": { + "id": "http://localhost:1234/tree", + "description": "tree of nodes", + "type": "object", + "properties": { + "meta": { + "type": "string" + }, + "nodes": { + "type": "array", + "items": { + "$ref": "node" + } + } + }, + "required": [ + "meta", + "nodes" + ], + "definitions": { + "node": { + "id": "http://localhost:1234/node", + "description": "node", + "type": "object", + "properties": { + "value": { + "type": "number" + }, + "subtree": { + "$ref": "tree" + } + }, + "required": [ + "value" + ] + } + } + }, + "skip": "extract error: cannot compile resulting schema: builtin package \"localhost:1234/node\" undefined:\n generated.cue:1:8\n_schema.nodes: reference \"node\" not found:\n generated.cue:8:14\n", + "tests": [ + { + "description": "valid tree", + "data": { + "meta": "root", + "nodes": [ + { + "value": 1, + "subtree": { + "meta": "child", + "nodes": [ + { + "value": 1.1 + }, + { + "value": 1.2 + } + ] + } + }, + { + "value": 2, + "subtree": { + "meta": "child", + "nodes": [ + { + "value": 2.1 + }, + { + "value": 2.2 + } + ] + } + } + ] + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid tree", + "data": { + "meta": "root", + "nodes": [ + { + "value": 1, + "subtree": { + "meta": "child", + "nodes": [ + { + "value": "string is invalid" + }, + { + "value": 1.2 + } + ] + } + }, + { + "value": 2, + "subtree": { + "meta": "child", + "nodes": [ + { + "value": 2.1 + }, + { + "value": 2.2 + } + ] + } + } + ] + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "refs with quote", + "schema": { + "properties": { + "foo\"bar": { + "$ref": "#/definitions/foo%22bar" + } + }, + "definitions": { + "foo\"bar": { + "type": "number" + } + } + }, + "tests": [ + { + "description": "object with numbers is valid", + "data": { + "foo\"bar": 1 + }, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values [...] and {\"foo\\\"bar\":1} (mismatched types list and struct):\n generated.cue:2:33\n instance.json:1:1\nconflicting values bool and {\"foo\\\"bar\":1} (mismatched types bool and struct):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and {\"foo\\\"bar\":1} (mismatched types null and struct):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and {\"foo\\\"bar\":1} (mismatched types number and struct):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and {\"foo\\\"bar\":1} (mismatched types string and struct):\n generated.cue:2:24\n instance.json:1:1\n\"foo\\\"bar\": undefined field: \"foo%22bar\":\n generated.cue:3:17\n" + }, + { + "description": "object with strings is invalid", + "data": { + "foo\"bar": "1" + }, + "valid": false + } + ] + }, + { + "description": "Location-independent identifier", + "schema": { + "allOf": [ + { + "$ref": "#foo" + } + ], + "definitions": { + "A": { + "id": "#foo", + "type": "integer" + } + } + }, + "skip": "extract error: $id URI may not contain a fragment (and 1 more errors)", + "tests": [ + { + "description": "match", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "Location-independent identifier with base URI change in subschema", + "schema": { + "id": "http://localhost:1234/root", + "allOf": [ + { + "$ref": "http://localhost:1234/nested.json#foo" + } + ], + "definitions": { + "A": { + "id": "nested.json", + "definitions": { + "B": { + "id": "#foo", + "type": "integer" + } + } + } + } + }, + "skip": "extract error: $id URI may not contain a fragment (and 1 more errors)", + "tests": [ + { + "description": "match", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "naive replacement of $ref with its destination is not correct", + "schema": { + "definitions": { + "a_string": { + "type": "string" + } + }, + "enum": [ + { + "$ref": "#/definitions/a_string" + } + ] + }, + "tests": [ + { + "description": "do not evaluate the $ref inside the enum, matching any string", + "data": "this is a string", + "valid": false + }, + { + "description": "match the enum exactly", + "data": { + "$ref": "#/definitions/a_string" + }, + "valid": true + } + ] + }, + { + "description": "id must be resolved against nearest parent, not just immediate parent", + "schema": { + "id": "http://example.com/a.json", + "definitions": { + "x": { + "id": "http://example.com/b/c.json", + "not": { + "definitions": { + "y": { + "id": "d.json", + "type": "number" + } + } + } + } + }, + "allOf": [ + { + "$ref": "http://example.com/b/d.json" + } + ] + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "id with file URI still resolves pointers - *nix", + "schema": { + "id": "file:///folder/file.json", + "definitions": { + "foo": { + "type": "number" + } + }, + "allOf": [ + { + "$ref": "#/definitions/foo" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "id with file URI still resolves pointers - windows", + "schema": { + "id": "file:///c:/folder/file.json", + "definitions": { + "foo": { + "type": "number" + } + }, + "allOf": [ + { + "$ref": "#/definitions/foo" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "empty tokens in $ref json-pointer", + "schema": { + "definitions": { + "": { + "definitions": { + "": { + "type": "number" + } + } + } + }, + "allOf": [ + { + "$ref": "#/definitions//definitions/" + } + ] + }, + "skip": "extract error: cannot refer to definitions section: must refer to one of its elements", + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/refRemote.json b/encoding/jsonschema/testdata/external/tests/draft4/refRemote.json new file mode 100644 index 000000000..d51c37340 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/refRemote.json @@ -0,0 +1,254 @@ +[ + { + "description": "remote ref", + "schema": { + "$ref": "http://localhost:1234/integer.json" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/integer.json:integer\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "remote ref valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "remote ref invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "fragment within remote ref", + "schema": { + "$ref": "http://localhost:1234/subSchemas.json#/definitions/integer" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/subSchemas.json:subSchemas\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "remote fragment valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "remote fragment invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ref within remote ref", + "schema": { + "$ref": "http://localhost:1234/subSchemas.json#/definitions/refToInteger" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/subSchemas.json:subSchemas\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "ref within ref valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ref within ref invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "base URI change", + "schema": { + "id": "http://localhost:1234/", + "items": { + "id": "baseUriChange/", + "items": { + "$ref": "folderInteger.json" + } + } + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/baseUriChange/folderInteger.json:folderInteger\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "base URI change ref valid", + "data": [ + [ + 1 + ] + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "base URI change ref invalid", + "data": [ + [ + "a" + ] + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "base URI change - change folder", + "schema": { + "id": "http://localhost:1234/scope_change_defs1.json", + "type": "object", + "properties": { + "list": { + "$ref": "#/definitions/baz" + } + }, + "definitions": { + "baz": { + "id": "baseUriChangeFolder/", + "type": "array", + "items": { + "$ref": "folderInteger.json" + } + } + } + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/baseUriChangeFolder/folderInteger.json:folderInteger\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is valid", + "data": { + "list": [ + 1 + ] + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": { + "list": [ + "a" + ] + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "base URI change - change folder in subschema", + "schema": { + "id": "http://localhost:1234/scope_change_defs2.json", + "type": "object", + "properties": { + "list": { + "$ref": "#/definitions/baz/definitions/bar" + } + }, + "definitions": { + "baz": { + "id": "baseUriChangeFolderInSubschema/", + "definitions": { + "bar": { + "type": "array", + "items": { + "$ref": "folderInteger.json" + } + } + } + } + } + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/baseUriChangeFolderInSubschema/folderInteger.json:folderInteger\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is valid", + "data": { + "list": [ + 1 + ] + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": { + "list": [ + "a" + ] + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "root ref in remote ref", + "schema": { + "id": "http://localhost:1234/object", + "type": "object", + "properties": { + "name": { + "$ref": "name.json#/definitions/orNull" + } + } + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/name.json:name\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "string is valid", + "data": { + "name": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "null is valid", + "data": { + "name": null + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "object is invalid", + "data": { + "name": { + "name": null + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "Location-independent identifier in remote ref", + "schema": { + "$ref": "http://localhost:1234/locationIndependentIdentifierDraft4.json#/definitions/refToInteger" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/locationIndependentIdentifierDraft4.json:locationIndependentIdentifierDraft4\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "integer is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/required.json b/encoding/jsonschema/testdata/external/tests/draft4/required.json new file mode 100644 index 000000000..69d6ce928 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/required.json @@ -0,0 +1,165 @@ +[ + { + "description": "required validation", + "schema": { + "properties": { + "foo": {}, + "bar": {} + }, + "required": [ + "foo" + ] + }, + "tests": [ + { + "description": "present required property is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "non-present required property is invalid", + "data": { + "bar": 1 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", + "data": "", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "required default validation", + "schema": { + "properties": { + "foo": {} + } + }, + "tests": [ + { + "description": "not required by default", + "data": {}, + "valid": true + } + ] + }, + { + "description": "required with escaped characters", + "schema": { + "required": [ + "foo\nbar", + "foo\"bar", + "foo\\bar", + "foo\rbar", + "foo\tbar", + "foo\fbar" + ] + }, + "tests": [ + { + "description": "object with all properties present is valid", + "data": { + "foo\nbar": 1, + "foo\"bar": 1, + "foo\\bar": 1, + "foo\rbar": 1, + "foo\tbar": 1, + "foo\fbar": 1 + }, + "valid": true + }, + { + "description": "object with some properties missing is invalid", + "data": { + "foo\nbar": "1", + "foo\"bar": "1" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "required properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { + "required": [ + "__proto__", + "toString", + "constructor" + ] + }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "__proto__ present", + "data": { + "__proto__": "foo" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "toString present", + "data": { + "toString": { + "length": 37 + } + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "constructor present", + "data": { + "constructor": { + "length": 37 + } + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "all present", + "data": { + "__proto__": 12, + "toString": { + "length": "foo" + }, + "constructor": 37 + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/type.json b/encoding/jsonschema/testdata/external/tests/draft4/type.json new file mode 100644 index 000000000..3e1010a32 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/type.json @@ -0,0 +1,509 @@ +[ + { + "description": "integer type matches integers", + "schema": { + "type": "integer" + }, + "tests": [ + { + "description": "an integer is an integer", + "data": 1, + "valid": true + }, + { + "description": "a float is not an integer", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an integer", + "data": "foo", + "valid": false + }, + { + "description": "a string is still not an integer, even if it looks like one", + "data": "1", + "valid": false + }, + { + "description": "an object is not an integer", + "data": {}, + "valid": false + }, + { + "description": "an array is not an integer", + "data": [], + "valid": false + }, + { + "description": "a boolean is not an integer", + "data": true, + "valid": false + }, + { + "description": "null is not an integer", + "data": null, + "valid": false + } + ] + }, + { + "description": "number type matches numbers", + "schema": { + "type": "number" + }, + "tests": [ + { + "description": "an integer is a number", + "data": 1, + "valid": true + }, + { + "description": "a float with zero fractional part is a number", + "data": 1.0, + "valid": true + }, + { + "description": "a float is a number", + "data": 1.1, + "valid": true + }, + { + "description": "a string is not a number", + "data": "foo", + "valid": false + }, + { + "description": "a string is still not a number, even if it looks like one", + "data": "1", + "valid": false + }, + { + "description": "an object is not a number", + "data": {}, + "valid": false + }, + { + "description": "an array is not a number", + "data": [], + "valid": false + }, + { + "description": "a boolean is not a number", + "data": true, + "valid": false + }, + { + "description": "null is not a number", + "data": null, + "valid": false + } + ] + }, + { + "description": "string type matches strings", + "schema": { + "type": "string" + }, + "tests": [ + { + "description": "1 is not a string", + "data": 1, + "valid": false + }, + { + "description": "a float is not a string", + "data": 1.1, + "valid": false + }, + { + "description": "a string is a string", + "data": "foo", + "valid": true + }, + { + "description": "a string is still a string, even if it looks like a number", + "data": "1", + "valid": true + }, + { + "description": "an empty string is still a string", + "data": "", + "valid": true + }, + { + "description": "an object is not a string", + "data": {}, + "valid": false + }, + { + "description": "an array is not a string", + "data": [], + "valid": false + }, + { + "description": "a boolean is not a string", + "data": true, + "valid": false + }, + { + "description": "null is not a string", + "data": null, + "valid": false + } + ] + }, + { + "description": "object type matches objects", + "schema": { + "type": "object" + }, + "tests": [ + { + "description": "an integer is not an object", + "data": 1, + "valid": false + }, + { + "description": "a float is not an object", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an object", + "data": "foo", + "valid": false + }, + { + "description": "an object is an object", + "data": {}, + "valid": true + }, + { + "description": "an array is not an object", + "data": [], + "valid": false + }, + { + "description": "a boolean is not an object", + "data": true, + "valid": false + }, + { + "description": "null is not an object", + "data": null, + "valid": false + } + ] + }, + { + "description": "array type matches arrays", + "schema": { + "type": "array" + }, + "tests": [ + { + "description": "an integer is not an array", + "data": 1, + "valid": false + }, + { + "description": "a float is not an array", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an array", + "data": "foo", + "valid": false + }, + { + "description": "an object is not an array", + "data": {}, + "valid": false + }, + { + "description": "an array is an array", + "data": [], + "valid": true + }, + { + "description": "a boolean is not an array", + "data": true, + "valid": false + }, + { + "description": "null is not an array", + "data": null, + "valid": false + } + ] + }, + { + "description": "boolean type matches booleans", + "schema": { + "type": "boolean" + }, + "tests": [ + { + "description": "an integer is not a boolean", + "data": 1, + "valid": false + }, + { + "description": "zero is not a boolean", + "data": 0, + "valid": false + }, + { + "description": "a float is not a boolean", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not a boolean", + "data": "foo", + "valid": false + }, + { + "description": "an empty string is not a boolean", + "data": "", + "valid": false + }, + { + "description": "an object is not a boolean", + "data": {}, + "valid": false + }, + { + "description": "an array is not a boolean", + "data": [], + "valid": false + }, + { + "description": "true is a boolean", + "data": true, + "valid": true + }, + { + "description": "false is a boolean", + "data": false, + "valid": true + }, + { + "description": "null is not a boolean", + "data": null, + "valid": false + } + ] + }, + { + "description": "null type matches only the null object", + "schema": { + "type": "null" + }, + "tests": [ + { + "description": "an integer is not null", + "data": 1, + "valid": false + }, + { + "description": "a float is not null", + "data": 1.1, + "valid": false + }, + { + "description": "zero is not null", + "data": 0, + "valid": false + }, + { + "description": "a string is not null", + "data": "foo", + "valid": false + }, + { + "description": "an empty string is not null", + "data": "", + "valid": false + }, + { + "description": "an object is not null", + "data": {}, + "valid": false + }, + { + "description": "an array is not null", + "data": [], + "valid": false + }, + { + "description": "true is not null", + "data": true, + "valid": false + }, + { + "description": "false is not null", + "data": false, + "valid": false + }, + { + "description": "null is null", + "data": null, + "valid": true + } + ] + }, + { + "description": "multiple types can be specified in an array", + "schema": { + "type": [ + "integer", + "string" + ] + }, + "tests": [ + { + "description": "an integer is valid", + "data": 1, + "valid": true + }, + { + "description": "a string is valid", + "data": "foo", + "valid": true + }, + { + "description": "a float is invalid", + "data": 1.1, + "valid": false + }, + { + "description": "an object is invalid", + "data": {}, + "valid": false + }, + { + "description": "an array is invalid", + "data": [], + "valid": false + }, + { + "description": "a boolean is invalid", + "data": true, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + } + ] + }, + { + "description": "type as array with one item", + "schema": { + "type": [ + "string" + ] + }, + "tests": [ + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "type: array or object", + "schema": { + "type": [ + "array", + "object" + ] + }, + "tests": [ + { + "description": "array is valid", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "object is valid", + "data": { + "foo": 123 + }, + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + } + ] + }, + { + "description": "type: array, object or null", + "schema": { + "type": [ + "array", + "object", + "null" + ] + }, + "tests": [ + { + "description": "array is valid", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "object is valid", + "data": { + "foo": 123 + }, + "valid": true + }, + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft4/uniqueItems.json b/encoding/jsonschema/testdata/external/tests/draft4/uniqueItems.json new file mode 100644 index 000000000..329125d52 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft4/uniqueItems.json @@ -0,0 +1,832 @@ +[ + { + "description": "uniqueItems validation", + "schema": { + "uniqueItems": true + }, + "tests": [ + { + "description": "unique array of integers is valid", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "non-unique array of integers is invalid", + "data": [ + 1, + 1 + ], + "valid": false + }, + { + "description": "non-unique array of more than two integers is invalid", + "data": [ + 1, + 2, + 1 + ], + "valid": false + }, + { + "description": "numbers are unique if mathematically unequal", + "data": [ + 1.0, + 1.00, + 1 + ], + "valid": false, + "skip": "unexpected success" + }, + { + "description": "false is not equal to zero", + "data": [ + 0, + false + ], + "valid": true + }, + { + "description": "true is not equal to one", + "data": [ + 1, + true + ], + "valid": true + }, + { + "description": "unique array of strings is valid", + "data": [ + "foo", + "bar", + "baz" + ], + "valid": true + }, + { + "description": "non-unique array of strings is invalid", + "data": [ + "foo", + "bar", + "foo" + ], + "valid": false + }, + { + "description": "unique array of objects is valid", + "data": [ + { + "foo": "bar" + }, + { + "foo": "baz" + } + ], + "valid": true + }, + { + "description": "non-unique array of objects is invalid", + "data": [ + { + "foo": "bar" + }, + { + "foo": "bar" + } + ], + "valid": false + }, + { + "description": "property order of array of objects is ignored", + "data": [ + { + "foo": "bar", + "bar": "foo" + }, + { + "bar": "foo", + "foo": "bar" + } + ], + "valid": false, + "skip": "unexpected success" + }, + { + "description": "unique array of nested objects is valid", + "data": [ + { + "foo": { + "bar": { + "baz": true + } + } + }, + { + "foo": { + "bar": { + "baz": false + } + } + } + ], + "valid": true + }, + { + "description": "non-unique array of nested objects is invalid", + "data": [ + { + "foo": { + "bar": { + "baz": true + } + } + }, + { + "foo": { + "bar": { + "baz": true + } + } + } + ], + "valid": false + }, + { + "description": "unique array of arrays is valid", + "data": [ + [ + "foo" + ], + [ + "bar" + ] + ], + "valid": true + }, + { + "description": "non-unique array of arrays is invalid", + "data": [ + [ + "foo" + ], + [ + "foo" + ] + ], + "valid": false + }, + { + "description": "non-unique array of more than two arrays is invalid", + "data": [ + [ + "foo" + ], + [ + "bar" + ], + [ + "foo" + ] + ], + "valid": false + }, + { + "description": "1 and true are unique", + "data": [ + 1, + true + ], + "valid": true + }, + { + "description": "0 and false are unique", + "data": [ + 0, + false + ], + "valid": true + }, + { + "description": "[1] and [true] are unique", + "data": [ + [ + 1 + ], + [ + true + ] + ], + "valid": true + }, + { + "description": "[0] and [false] are unique", + "data": [ + [ + 0 + ], + [ + false + ] + ], + "valid": true + }, + { + "description": "nested [1] and [true] are unique", + "data": [ + [ + [ + 1 + ], + "foo" + ], + [ + [ + true + ], + "foo" + ] + ], + "valid": true + }, + { + "description": "nested [0] and [false] are unique", + "data": [ + [ + [ + 0 + ], + "foo" + ], + [ + [ + false + ], + "foo" + ] + ], + "valid": true + }, + { + "description": "unique heterogeneous types are valid", + "data": [ + {}, + [ + 1 + ], + true, + null, + 1, + "{}" + ], + "valid": true + }, + { + "description": "non-unique heterogeneous types are invalid", + "data": [ + {}, + [ + 1 + ], + true, + null, + {}, + 1 + ], + "valid": false + }, + { + "description": "different objects are unique", + "data": [ + { + "a": 1, + "b": 2 + }, + { + "a": 2, + "b": 1 + } + ], + "valid": true + }, + { + "description": "objects are non-unique despite key order", + "data": [ + { + "a": 1, + "b": 2 + }, + { + "b": 2, + "a": 1 + } + ], + "valid": false, + "skip": "unexpected success" + }, + { + "description": "{\"a\": false} and {\"a\": 0} are unique", + "data": [ + { + "a": false + }, + { + "a": 0 + } + ], + "valid": true + }, + { + "description": "{\"a\": true} and {\"a\": 1} are unique", + "data": [ + { + "a": true + }, + { + "a": 1 + } + ], + "valid": true + } + ] + }, + { + "description": "uniqueItems with an array of items", + "schema": { + "items": [ + { + "type": "boolean" + }, + { + "type": "boolean" + } + ], + "uniqueItems": true + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [ + false, + true + ], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [ + true, + false + ], + "valid": true + }, + { + "description": "[false, false] from items array is not valid", + "data": [ + false, + false + ], + "valid": false + }, + { + "description": "[true, true] from items array is not valid", + "data": [ + true, + true + ], + "valid": false + }, + { + "description": "unique array extended from [false, true] is valid", + "data": [ + false, + true, + "foo", + "bar" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [false,true,\"foo\",\"bar\"] and {...} (mismatched types list and struct):\n generated.cue:3:1\n generated.cue:3:69\n instance.json:1:1\nconflicting values bool and [false,true,\"foo\",\"bar\"] (mismatched types bool and list):\n generated.cue:3:8\n instance.json:1:1\nconflicting values null and [false,true,\"foo\",\"bar\"] (mismatched types null and list):\n generated.cue:3:1\n instance.json:1:1\nconflicting values number and [false,true,\"foo\",\"bar\"] (mismatched types number and list):\n generated.cue:3:15\n instance.json:1:1\nconflicting values string and [false,true,\"foo\",\"bar\"] (mismatched types string and list):\n generated.cue:3:24\n instance.json:1:1\n" + }, + { + "description": "unique array extended from [true, false] is valid", + "data": [ + true, + false, + "foo", + "bar" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [true,false,\"foo\",\"bar\"] and {...} (mismatched types list and struct):\n generated.cue:3:1\n generated.cue:3:69\n instance.json:1:1\nconflicting values bool and [true,false,\"foo\",\"bar\"] (mismatched types bool and list):\n generated.cue:3:8\n instance.json:1:1\nconflicting values null and [true,false,\"foo\",\"bar\"] (mismatched types null and list):\n generated.cue:3:1\n instance.json:1:1\nconflicting values number and [true,false,\"foo\",\"bar\"] (mismatched types number and list):\n generated.cue:3:15\n instance.json:1:1\nconflicting values string and [true,false,\"foo\",\"bar\"] (mismatched types string and list):\n generated.cue:3:24\n instance.json:1:1\n" + }, + { + "description": "non-unique array extended from [false, true] is not valid", + "data": [ + false, + true, + "foo", + "foo" + ], + "valid": false + }, + { + "description": "non-unique array extended from [true, false] is not valid", + "data": [ + true, + false, + "foo", + "foo" + ], + "valid": false + } + ] + }, + { + "description": "uniqueItems with an array of items and additionalItems=false", + "schema": { + "items": [ + { + "type": "boolean" + }, + { + "type": "boolean" + } + ], + "uniqueItems": true, + "additionalItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [ + false, + true + ], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [ + true, + false + ], + "valid": true + }, + { + "description": "[false, false] from items array is not valid", + "data": [ + false, + false + ], + "valid": false + }, + { + "description": "[true, true] from items array is not valid", + "data": [ + true, + true + ], + "valid": false + }, + { + "description": "extra items are invalid even if unique", + "data": [ + false, + true, + null + ], + "valid": false + } + ] + }, + { + "description": "uniqueItems=false validation", + "schema": { + "uniqueItems": false + }, + "tests": [ + { + "description": "unique array of integers is valid", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "non-unique array of integers is valid", + "data": [ + 1, + 1 + ], + "valid": true + }, + { + "description": "numbers are unique if mathematically unequal", + "data": [ + 1.0, + 1.00, + 1 + ], + "valid": true + }, + { + "description": "false is not equal to zero", + "data": [ + 0, + false + ], + "valid": true + }, + { + "description": "true is not equal to one", + "data": [ + 1, + true + ], + "valid": true + }, + { + "description": "unique array of objects is valid", + "data": [ + { + "foo": "bar" + }, + { + "foo": "baz" + } + ], + "valid": true + }, + { + "description": "non-unique array of objects is valid", + "data": [ + { + "foo": "bar" + }, + { + "foo": "bar" + } + ], + "valid": true + }, + { + "description": "unique array of nested objects is valid", + "data": [ + { + "foo": { + "bar": { + "baz": true + } + } + }, + { + "foo": { + "bar": { + "baz": false + } + } + } + ], + "valid": true + }, + { + "description": "non-unique array of nested objects is valid", + "data": [ + { + "foo": { + "bar": { + "baz": true + } + } + }, + { + "foo": { + "bar": { + "baz": true + } + } + } + ], + "valid": true + }, + { + "description": "unique array of arrays is valid", + "data": [ + [ + "foo" + ], + [ + "bar" + ] + ], + "valid": true + }, + { + "description": "non-unique array of arrays is valid", + "data": [ + [ + "foo" + ], + [ + "foo" + ] + ], + "valid": true + }, + { + "description": "1 and true are unique", + "data": [ + 1, + true + ], + "valid": true + }, + { + "description": "0 and false are unique", + "data": [ + 0, + false + ], + "valid": true + }, + { + "description": "unique heterogeneous types are valid", + "data": [ + {}, + [ + 1 + ], + true, + null, + 1 + ], + "valid": true + }, + { + "description": "non-unique heterogeneous types are valid", + "data": [ + {}, + [ + 1 + ], + true, + null, + {}, + 1 + ], + "valid": true + } + ] + }, + { + "description": "uniqueItems=false with an array of items", + "schema": { + "items": [ + { + "type": "boolean" + }, + { + "type": "boolean" + } + ], + "uniqueItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [ + false, + true + ], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [ + true, + false + ], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [ + false, + false + ], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [ + true, + true + ], + "valid": true + }, + { + "description": "unique array extended from [false, true] is valid", + "data": [ + false, + true, + "foo", + "bar" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [false,true,\"foo\",\"bar\"] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:48\n instance.json:1:1\nconflicting values bool and [false,true,\"foo\",\"bar\"] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [false,true,\"foo\",\"bar\"] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [false,true,\"foo\",\"bar\"] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [false,true,\"foo\",\"bar\"] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "unique array extended from [true, false] is valid", + "data": [ + true, + false, + "foo", + "bar" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [true,false,\"foo\",\"bar\"] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:48\n instance.json:1:1\nconflicting values bool and [true,false,\"foo\",\"bar\"] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [true,false,\"foo\",\"bar\"] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [true,false,\"foo\",\"bar\"] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [true,false,\"foo\",\"bar\"] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "non-unique array extended from [false, true] is valid", + "data": [ + false, + true, + "foo", + "foo" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [false,true,\"foo\",\"foo\"] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:48\n instance.json:1:1\nconflicting values bool and [false,true,\"foo\",\"foo\"] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [false,true,\"foo\",\"foo\"] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [false,true,\"foo\",\"foo\"] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [false,true,\"foo\",\"foo\"] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "non-unique array extended from [true, false] is valid", + "data": [ + true, + false, + "foo", + "foo" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [true,false,\"foo\",\"foo\"] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:48\n instance.json:1:1\nconflicting values bool and [true,false,\"foo\",\"foo\"] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [true,false,\"foo\",\"foo\"] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [true,false,\"foo\",\"foo\"] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [true,false,\"foo\",\"foo\"] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + } + ] + }, + { + "description": "uniqueItems=false with an array of items and additionalItems=false", + "schema": { + "items": [ + { + "type": "boolean" + }, + { + "type": "boolean" + } + ], + "uniqueItems": false, + "additionalItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [ + false, + true + ], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [ + true, + false + ], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [ + false, + false + ], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [ + true, + true + ], + "valid": true + }, + { + "description": "extra items are invalid even if unique", + "data": [ + false, + true, + null + ], + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/additionalItems.json b/encoding/jsonschema/testdata/external/tests/draft6/additionalItems.json new file mode 100644 index 000000000..c910883ab --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/additionalItems.json @@ -0,0 +1,328 @@ +[ + { + "description": "additionalItems as schema", + "schema": { + "items": [ + {} + ], + "additionalItems": { + "type": "integer" + } + }, + "tests": [ + { + "description": "additional items match schema", + "data": [ + null, + 2, + 3, + 4 + ], + "valid": true + }, + { + "description": "additional items do not match schema", + "data": [ + null, + 2, + 3, + "foo" + ], + "valid": false + } + ] + }, + { + "description": "when items is schema, additionalItems does nothing", + "schema": { + "items": { + "type": "integer" + }, + "additionalItems": { + "type": "string" + } + }, + "tests": [ + { + "description": "valid with a array of type integers", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "invalid with a array of mixed types", + "data": [ + 1, + "2", + "3" + ], + "valid": false + } + ] + }, + { + "description": "when items is schema, boolean additionalItems does nothing", + "schema": { + "items": {}, + "additionalItems": false + }, + "tests": [ + { + "description": "all items match schema", + "data": [ + 1, + 2, + 3, + 4, + 5 + ], + "valid": true + } + ] + }, + { + "description": "array of items with no additionalItems permitted", + "schema": { + "items": [ + {}, + {}, + {} + ], + "additionalItems": false + }, + "tests": [ + { + "description": "empty array", + "data": [], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:45\n instance.json:1:1\nconflicting values bool and [] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "fewer number of items present (1)", + "data": [ + 1 + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:45\n instance.json:1:1\nconflicting values bool and [1] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "fewer number of items present (2)", + "data": [ + 1, + 2 + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1,2] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:45\n instance.json:1:1\nconflicting values bool and [1,2] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,2] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,2] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,2] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "equal number of items present", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "additional items are not permitted", + "data": [ + 1, + 2, + 3, + 4 + ], + "valid": false + } + ] + }, + { + "description": "additionalItems as false without items", + "schema": { + "additionalItems": false + }, + "tests": [ + { + "description": "items defaults to empty schema so everything is valid", + "data": [ + 1, + 2, + 3, + 4, + 5 + ], + "valid": true + }, + { + "description": "ignores non-arrays", + "data": { + "foo": "bar" + }, + "valid": true + } + ] + }, + { + "description": "additionalItems are allowed by default", + "schema": { + "items": [ + { + "type": "integer" + } + ] + }, + "tests": [ + { + "description": "only the first item is validated", + "data": [ + 1, + "foo", + false + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1,\"foo\",false] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:41\n instance.json:1:1\nconflicting values bool and [1,\"foo\",false] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,\"foo\",false] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,\"foo\",false] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,\"foo\",false] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + } + ] + }, + { + "description": "additionalItems does not look in applicators, valid case", + "schema": { + "allOf": [ + { + "items": [ + { + "type": "integer" + } + ] + } + ], + "additionalItems": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "items defined in allOf are not examined", + "data": [ + 1, + null + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1,null] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:41\n instance.json:1:1\nconflicting values bool and [1,null] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,null] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,null] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,null] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + } + ] + }, + { + "description": "additionalItems does not look in applicators, invalid case", + "schema": { + "allOf": [ + { + "items": [ + { + "type": "integer" + }, + { + "type": "string" + } + ] + } + ], + "items": [ + { + "type": "integer" + } + ], + "additionalItems": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "items defined in allOf are not examined", + "data": [ + 1, + "hello" + ], + "valid": false + } + ] + }, + { + "description": "items validation adjusts the starting index for additionalItems", + "schema": { + "items": [ + { + "type": "string" + } + ], + "additionalItems": { + "type": "integer" + } + }, + "tests": [ + { + "description": "valid items", + "data": [ + "x", + 2, + 3 + ], + "valid": true + }, + { + "description": "wrong type of second item", + "data": [ + "x", + "y" + ], + "valid": false + } + ] + }, + { + "description": "additionalItems with heterogeneous array", + "schema": { + "items": [ + {} + ], + "additionalItems": false + }, + "tests": [ + { + "description": "heterogeneous invalid instance", + "data": [ + "foo", + "bar", + 37 + ], + "valid": false + }, + { + "description": "valid instance", + "data": [ + null + ], + "valid": true + } + ] + }, + { + "description": "additionalItems with null instance elements", + "schema": { + "additionalItems": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ + null + ], + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/additionalProperties.json b/encoding/jsonschema/testdata/external/tests/draft6/additionalProperties.json new file mode 100644 index 000000000..dfc0faecb --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/additionalProperties.json @@ -0,0 +1,212 @@ +[ + { + "description": "additionalProperties being false does not allow other properties", + "schema": { + "properties": { + "foo": {}, + "bar": {} + }, + "patternProperties": { + "^v": {} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "no additional properties is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "an additional property is invalid", + "data": { + "foo": 1, + "bar": 2, + "quux": "boom" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ignores arrays", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobarbaz", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "patternProperties are not additional properties", + "data": { + "foo": 1, + "vroom": 2 + }, + "valid": true + } + ] + }, + { + "description": "non-ASCII pattern with additionalProperties", + "schema": { + "patternProperties": { + "^á": {} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "matching the pattern is valid", + "data": { + "ármányos": 2 + }, + "valid": true + }, + { + "description": "not matching the pattern is invalid", + "data": { + "élmény": 2 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "additionalProperties with schema", + "schema": { + "properties": { + "foo": {}, + "bar": {} + }, + "additionalProperties": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "no additional properties is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "an additional valid property is valid", + "data": { + "foo": 1, + "bar": 2, + "quux": true + }, + "valid": true + }, + { + "description": "an additional invalid property is invalid", + "data": { + "foo": 1, + "bar": 2, + "quux": 12 + }, + "valid": false + } + ] + }, + { + "description": "additionalProperties can exist by itself", + "schema": { + "additionalProperties": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "an additional valid property is valid", + "data": { + "foo": true + }, + "valid": true + }, + { + "description": "an additional invalid property is invalid", + "data": { + "foo": 1 + }, + "valid": false + } + ] + }, + { + "description": "additionalProperties are allowed by default", + "schema": { + "properties": { + "foo": {}, + "bar": {} + } + }, + "tests": [ + { + "description": "additional properties are allowed", + "data": { + "foo": 1, + "bar": 2, + "quux": true + }, + "valid": true + } + ] + }, + { + "description": "additionalProperties does not look in applicators", + "schema": { + "allOf": [ + { + "properties": { + "foo": {} + } + } + ], + "additionalProperties": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "properties defined in allOf are not examined", + "data": { + "foo": 1, + "bar": true + }, + "valid": false + } + ] + }, + { + "description": "additionalProperties with null valued instance properties", + "schema": { + "additionalProperties": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null values", + "data": { + "foo": null + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/allOf.json b/encoding/jsonschema/testdata/external/tests/draft6/allOf.json new file mode 100644 index 000000000..fd03f07b0 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/allOf.json @@ -0,0 +1,384 @@ +[ + { + "description": "allOf", + "schema": { + "allOf": [ + { + "properties": { + "bar": { + "type": "integer" + } + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + } + ] + }, + "tests": [ + { + "description": "allOf", + "data": { + "foo": "baz", + "bar": 2 + }, + "valid": true + }, + { + "description": "mismatch second", + "data": { + "foo": "baz" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "mismatch first", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "wrong type", + "data": { + "foo": "baz", + "bar": "quux" + }, + "valid": false + } + ] + }, + { + "description": "allOf with base schema", + "schema": { + "properties": { + "bar": { + "type": "integer" + } + }, + "required": [ + "bar" + ], + "allOf": [ + { + "properties": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + }, + { + "properties": { + "baz": { + "type": "null" + } + }, + "required": [ + "baz" + ] + } + ] + }, + "tests": [ + { + "description": "valid", + "data": { + "foo": "quux", + "bar": 2, + "baz": null + }, + "valid": true + }, + { + "description": "mismatch base schema", + "data": { + "foo": "quux", + "baz": null + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "mismatch first allOf", + "data": { + "bar": 2, + "baz": null + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "mismatch second allOf", + "data": { + "foo": "quux", + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "mismatch both", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "allOf simple types", + "schema": { + "allOf": [ + { + "maximum": 30 + }, + { + "minimum": 20 + } + ] + }, + "tests": [ + { + "description": "valid", + "data": 25, + "valid": true + }, + { + "description": "mismatch one", + "data": 35, + "valid": false + } + ] + }, + { + "description": "allOf with boolean schemas, all true", + "schema": { + "allOf": [ + true, + true + ] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "allOf with boolean schemas, some false", + "schema": { + "allOf": [ + true, + false + ] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "allOf with boolean schemas, all false", + "schema": { + "allOf": [ + false, + false + ] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "allOf with one empty schema", + "schema": { + "allOf": [ + {} + ] + }, + "tests": [ + { + "description": "any data is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "allOf with two empty schemas", + "schema": { + "allOf": [ + {}, + {} + ] + }, + "tests": [ + { + "description": "any data is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "allOf with the first empty schema", + "schema": { + "allOf": [ + {}, + { + "type": "number" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "allOf with the last empty schema", + "schema": { + "allOf": [ + { + "type": "number" + }, + {} + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "nested allOf, to check validation semantics", + "schema": { + "allOf": [ + { + "allOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "allOf combined with anyOf, oneOf", + "schema": { + "allOf": [ + { + "multipleOf": 2 + } + ], + "anyOf": [ + { + "multipleOf": 3 + } + ], + "oneOf": [ + { + "multipleOf": 5 + } + ] + }, + "tests": [ + { + "description": "allOf: false, anyOf: false, oneOf: false", + "data": 1, + "valid": false + }, + { + "description": "allOf: false, anyOf: false, oneOf: true", + "data": 5, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: false", + "data": 3, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: true", + "data": 15, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: false", + "data": 2, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: true", + "data": 10, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: false", + "data": 6, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: true", + "data": 30, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/anyOf.json b/encoding/jsonschema/testdata/external/tests/draft6/anyOf.json new file mode 100644 index 000000000..22ee3f38d --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/anyOf.json @@ -0,0 +1,226 @@ +[ + { + "description": "anyOf", + "schema": { + "anyOf": [ + { + "type": "integer" + }, + { + "minimum": 2 + } + ] + }, + "tests": [ + { + "description": "first anyOf valid", + "data": 1, + "valid": true + }, + { + "description": "second anyOf valid", + "data": 2.5, + "valid": true + }, + { + "description": "both anyOf valid", + "data": 3, + "valid": true + }, + { + "description": "neither anyOf valid", + "data": 1.5, + "valid": false + } + ] + }, + { + "description": "anyOf with base schema", + "schema": { + "type": "string", + "anyOf": [ + { + "maxLength": 2 + }, + { + "minLength": 4 + } + ] + }, + "tests": [ + { + "description": "mismatch base schema", + "data": 3, + "valid": false + }, + { + "description": "one anyOf valid", + "data": "foobar", + "valid": true + }, + { + "description": "both anyOf invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "anyOf with boolean schemas, all true", + "schema": { + "anyOf": [ + true, + true + ] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "anyOf with boolean schemas, some true", + "schema": { + "anyOf": [ + true, + false + ] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "anyOf with boolean schemas, all false", + "schema": { + "anyOf": [ + false, + false + ] + }, + "skip": "extract error: cannot compile resulting schema: 2 errors in empty disjunction:\nexplicit error (_|_ literal) in source:\n generated.cue:2:1\nexplicit error (_|_ literal) in source:\n generated.cue:2:7\n", + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "anyOf complex types", + "schema": { + "anyOf": [ + { + "properties": { + "bar": { + "type": "integer" + } + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + } + ] + }, + "tests": [ + { + "description": "first anyOf valid (complex)", + "data": { + "bar": 2 + }, + "valid": true + }, + { + "description": "second anyOf valid (complex)", + "data": { + "foo": "baz" + }, + "valid": true + }, + { + "description": "both anyOf valid (complex)", + "data": { + "foo": "baz", + "bar": 2 + }, + "valid": true + }, + { + "description": "neither anyOf valid (complex)", + "data": { + "foo": 2, + "bar": "quux" + }, + "valid": false + } + ] + }, + { + "description": "anyOf with one empty schema", + "schema": { + "anyOf": [ + { + "type": "number" + }, + {} + ] + }, + "tests": [ + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "number is valid", + "data": 123, + "valid": true + } + ] + }, + { + "description": "nested anyOf, to check validation semantics", + "schema": { + "anyOf": [ + { + "anyOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/boolean_schema.json b/encoding/jsonschema/testdata/external/tests/draft6/boolean_schema.json new file mode 100644 index 000000000..dd0e5677f --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/boolean_schema.json @@ -0,0 +1,122 @@ +[ + { + "description": "boolean schema 'true'", + "schema": true, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "boolean true is valid", + "data": true, + "valid": true + }, + { + "description": "boolean false is valid", + "data": false, + "valid": true + }, + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "object is valid", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + }, + { + "description": "array is valid", + "data": [ + "foo" + ], + "valid": true + }, + { + "description": "empty array is valid", + "data": [], + "valid": true + } + ] + }, + { + "description": "boolean schema 'false'", + "schema": false, + "skip": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n generated.cue:2:1\n", + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "null is invalid", + "data": null, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "object is invalid", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "array is invalid", + "data": [ + "foo" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/const.json b/encoding/jsonschema/testdata/external/tests/draft6/const.json new file mode 100644 index 000000000..c677c7e5a --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/const.json @@ -0,0 +1,437 @@ +[ + { + "description": "const validation", + "schema": { + "const": 2 + }, + "tests": [ + { + "description": "same value is valid", + "data": 2, + "valid": true + }, + { + "description": "another value is invalid", + "data": 5, + "valid": false + }, + { + "description": "another type is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "const with object", + "schema": { + "const": { + "foo": "bar", + "baz": "bax" + } + }, + "tests": [ + { + "description": "same object is valid", + "data": { + "foo": "bar", + "baz": "bax" + }, + "valid": true + }, + { + "description": "same object with different property order is valid", + "data": { + "baz": "bax", + "foo": "bar" + }, + "valid": true + }, + { + "description": "another object is invalid", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "another type is invalid", + "data": [ + 1, + 2 + ], + "valid": false + } + ] + }, + { + "description": "const with array", + "schema": { + "const": [ + { + "foo": "bar" + } + ] + }, + "tests": [ + { + "description": "same array is valid", + "data": [ + { + "foo": "bar" + } + ], + "valid": true + }, + { + "description": "another array item is invalid", + "data": [ + 2 + ], + "valid": false + }, + { + "description": "array with additional items is invalid", + "data": [ + 1, + 2, + 3 + ], + "valid": false + } + ] + }, + { + "description": "const with null", + "schema": { + "const": null + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "not null is invalid", + "data": 0, + "valid": false + } + ] + }, + { + "description": "const with false does not match 0", + "schema": { + "const": false + }, + "tests": [ + { + "description": "false is valid", + "data": false, + "valid": true + }, + { + "description": "integer zero is invalid", + "data": 0, + "valid": false + }, + { + "description": "float zero is invalid", + "data": 0.0, + "valid": false + } + ] + }, + { + "description": "const with true does not match 1", + "schema": { + "const": true + }, + "tests": [ + { + "description": "true is valid", + "data": true, + "valid": true + }, + { + "description": "integer one is invalid", + "data": 1, + "valid": false + }, + { + "description": "float one is invalid", + "data": 1.0, + "valid": false + } + ] + }, + { + "description": "const with [false] does not match [0]", + "schema": { + "const": [ + false + ] + }, + "tests": [ + { + "description": "[false] is valid", + "data": [ + false + ], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [ + 0 + ], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [ + 0.0 + ], + "valid": false + } + ] + }, + { + "description": "const with [true] does not match [1]", + "schema": { + "const": [ + true + ] + }, + "tests": [ + { + "description": "[true] is valid", + "data": [ + true + ], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [ + 1 + ], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [ + 1.0 + ], + "valid": false + } + ] + }, + { + "description": "const with {\"a\": false} does not match {\"a\": 0}", + "schema": { + "const": { + "a": false + } + }, + "tests": [ + { + "description": "{\"a\": false} is valid", + "data": { + "a": false + }, + "valid": true + }, + { + "description": "{\"a\": 0} is invalid", + "data": { + "a": 0 + }, + "valid": false + }, + { + "description": "{\"a\": 0.0} is invalid", + "data": { + "a": 0.0 + }, + "valid": false + } + ] + }, + { + "description": "const with {\"a\": true} does not match {\"a\": 1}", + "schema": { + "const": { + "a": true + } + }, + "tests": [ + { + "description": "{\"a\": true} is valid", + "data": { + "a": true + }, + "valid": true + }, + { + "description": "{\"a\": 1} is invalid", + "data": { + "a": 1 + }, + "valid": false + }, + { + "description": "{\"a\": 1.0} is invalid", + "data": { + "a": 1.0 + }, + "valid": false + } + ] + }, + { + "description": "const with 0 does not match other zero-like types", + "schema": { + "const": 0 + }, + "tests": [ + { + "description": "false is invalid", + "data": false, + "valid": false + }, + { + "description": "integer zero is valid", + "data": 0, + "valid": true + }, + { + "description": "float zero is valid", + "data": 0.0, + "valid": true, + "skip": "conflicting values 0.0 and 0 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + }, + { + "description": "empty string is invalid", + "data": "", + "valid": false + } + ] + }, + { + "description": "const with 1 does not match true", + "schema": { + "const": 1 + }, + "tests": [ + { + "description": "true is invalid", + "data": true, + "valid": false + }, + { + "description": "integer one is valid", + "data": 1, + "valid": true + }, + { + "description": "float one is valid", + "data": 1.0, + "valid": true, + "skip": "conflicting values 1.0 and 1 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + } + ] + }, + { + "description": "const with -2.0 matches integer and float types", + "schema": { + "const": -2.0 + }, + "tests": [ + { + "description": "integer -2 is valid", + "data": -2, + "valid": true, + "skip": "conflicting values -2 and -2.0 (mismatched types int and float):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "integer 2 is invalid", + "data": 2, + "valid": false + }, + { + "description": "float -2.0 is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float 2.0 is invalid", + "data": 2.0, + "valid": false + }, + { + "description": "float -2.00001 is invalid", + "data": -2.00001, + "valid": false + } + ] + }, + { + "description": "float and integers are equal up to 64-bit representation limits", + "schema": { + "const": 9007199254740992 + }, + "tests": [ + { + "description": "integer is valid", + "data": 9007199254740992, + "valid": true + }, + { + "description": "integer minus one is invalid", + "data": 9007199254740991, + "valid": false + }, + { + "description": "float is valid", + "data": 9007199254740992.0, + "valid": true, + "skip": "conflicting values 9007199254740992.0 and 9007199254740992 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "float minus one is invalid", + "data": 9007199254740991.0, + "valid": false + } + ] + }, + { + "description": "nul characters in strings", + "schema": { + "const": "hello\u0000there" + }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/contains.json b/encoding/jsonschema/testdata/external/tests/draft6/contains.json new file mode 100644 index 000000000..86d962dde --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/contains.json @@ -0,0 +1,207 @@ +[ + { + "description": "contains keyword validation", + "schema": { + "contains": { + "minimum": 5 + } + }, + "tests": [ + { + "description": "array with item matching schema (5) is valid", + "data": [ + 3, + 4, + 5 + ], + "valid": true + }, + { + "description": "array with item matching schema (6) is valid", + "data": [ + 3, + 4, + 6 + ], + "valid": true + }, + { + "description": "array with two items matching schema (5, 6) is valid", + "data": [ + 3, + 4, + 5, + 6 + ], + "valid": true + }, + { + "description": "array without items matching schema is invalid", + "data": [ + 2, + 3, + 4 + ], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + }, + { + "description": "not array is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "contains keyword with const keyword", + "schema": { + "contains": { + "const": 5 + } + }, + "tests": [ + { + "description": "array with item 5 is valid", + "data": [ + 3, + 4, + 5 + ], + "valid": true + }, + { + "description": "array with two items 5 is valid", + "data": [ + 3, + 4, + 5, + 5 + ], + "valid": true + }, + { + "description": "array without item 5 is invalid", + "data": [ + 1, + 2, + 3, + 4 + ], + "valid": false + } + ] + }, + { + "description": "contains keyword with boolean schema true", + "schema": { + "contains": true + }, + "tests": [ + { + "description": "any non-empty array is valid", + "data": [ + "foo" + ], + "valid": true + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + } + ] + }, + { + "description": "contains keyword with boolean schema false", + "schema": { + "contains": false + }, + "tests": [ + { + "description": "any non-empty array is invalid", + "data": [ + "foo" + ], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + }, + { + "description": "non-arrays are valid", + "data": "contains does not apply to strings", + "valid": true + } + ] + }, + { + "description": "items + contains", + "schema": { + "items": { + "multipleOf": 2 + }, + "contains": { + "multipleOf": 3 + } + }, + "tests": [ + { + "description": "matches items, does not match contains", + "data": [ + 2, + 4, + 8 + ], + "valid": false + }, + { + "description": "does not match items, matches contains", + "data": [ + 3, + 6, + 9 + ], + "valid": false + }, + { + "description": "matches both items and contains", + "data": [ + 6, + 12 + ], + "valid": true + }, + { + "description": "matches neither items nor contains", + "data": [ + 1, + 5 + ], + "valid": false + } + ] + }, + { + "description": "contains with null instance elements", + "schema": { + "contains": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null items", + "data": [ + null + ], + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/default.json b/encoding/jsonschema/testdata/external/tests/draft6/default.json new file mode 100644 index 000000000..587423d4a --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/default.json @@ -0,0 +1,88 @@ +[ + { + "description": "invalid type for default", + "schema": { + "properties": { + "foo": { + "type": "integer", + "default": [] + } + } + }, + "tests": [ + { + "description": "valid when property is specified", + "data": { + "foo": 13 + }, + "valid": true + }, + { + "description": "still valid when the invalid default is used", + "data": {}, + "valid": true + } + ] + }, + { + "description": "invalid string value for default", + "schema": { + "properties": { + "bar": { + "type": "string", + "minLength": 4, + "default": "bad" + } + } + }, + "tests": [ + { + "description": "valid when property is specified", + "data": { + "bar": "good" + }, + "valid": true + }, + { + "description": "still valid when the invalid default is used", + "data": {}, + "valid": true + } + ] + }, + { + "description": "the default keyword does not do anything if the property is missing", + "schema": { + "type": "object", + "properties": { + "alpha": { + "type": "number", + "maximum": 3, + "default": 5 + } + } + }, + "tests": [ + { + "description": "an explicit property value is checked against maximum (passing)", + "data": { + "alpha": 1 + }, + "valid": true + }, + { + "description": "an explicit property value is checked against maximum (failing)", + "data": { + "alpha": 5 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "missing properties are not filled in with the default", + "data": {}, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/definitions.json b/encoding/jsonschema/testdata/external/tests/draft6/definitions.json new file mode 100644 index 000000000..51772155e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/definitions.json @@ -0,0 +1,35 @@ +[ + { + "description": "validate definition against metaschema", + "schema": { + "$ref": "http://json-schema.org/draft-06/schema#" + }, + "skip": "extract error: cannot compile resulting schema: package \"json-schema.org/draft-06/schema\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "valid definition schema", + "data": { + "definitions": { + "foo": { + "type": "integer" + } + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid definition schema", + "data": { + "definitions": { + "foo": { + "type": 1 + } + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/dependencies.json b/encoding/jsonschema/testdata/external/tests/draft6/dependencies.json new file mode 100644 index 000000000..f61780a8b --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/dependencies.json @@ -0,0 +1,380 @@ +[ + { + "description": "dependencies", + "schema": { + "dependencies": { + "bar": [ + "foo" + ] + } + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependant", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "with dependency", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "missing dependency", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ignores arrays", + "data": [ + "bar" + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "dependencies with empty array", + "schema": { + "dependencies": { + "bar": [] + } + }, + "tests": [ + { + "description": "empty object", + "data": {}, + "valid": true + }, + { + "description": "object with one property", + "data": { + "bar": 2 + }, + "valid": true + }, + { + "description": "non-object is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "multiple dependencies", + "schema": { + "dependencies": { + "quux": [ + "foo", + "bar" + ] + } + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependants", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "with dependencies", + "data": { + "foo": 1, + "bar": 2, + "quux": 3 + }, + "valid": true + }, + { + "description": "missing dependency", + "data": { + "foo": 1, + "quux": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "missing other dependency", + "data": { + "bar": 1, + "quux": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "missing both dependencies", + "data": { + "quux": 1 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "multiple dependencies subschema", + "schema": { + "dependencies": { + "bar": { + "properties": { + "foo": { + "type": "integer" + }, + "bar": { + "type": "integer" + } + } + } + } + }, + "tests": [ + { + "description": "valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "no dependency", + "data": { + "foo": "quux" + }, + "valid": true + }, + { + "description": "wrong type", + "data": { + "foo": "quux", + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "wrong type other", + "data": { + "foo": 2, + "bar": "quux" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "wrong type both", + "data": { + "foo": "quux", + "bar": "quux" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "dependencies with boolean subschemas", + "schema": { + "dependencies": { + "foo": true, + "bar": false + } + }, + "tests": [ + { + "description": "object with property having schema true is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "object with property having schema false is invalid", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "object with both properties is invalid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "dependencies": { + "foo\nbar": [ + "foo\rbar" + ], + "foo\tbar": { + "minProperties": 4 + }, + "foo'bar": { + "required": [ + "foo\"bar" + ] + }, + "foo\"bar": [ + "foo'bar" + ] + } + }, + "tests": [ + { + "description": "valid object 1", + "data": { + "foo\nbar": 1, + "foo\rbar": 2 + }, + "valid": true + }, + { + "description": "valid object 2", + "data": { + "foo\tbar": 1, + "a": 2, + "b": 3, + "c": 4 + }, + "valid": true + }, + { + "description": "valid object 3", + "data": { + "foo'bar": 1, + "foo\"bar": 2 + }, + "valid": true + }, + { + "description": "invalid object 1", + "data": { + "foo\nbar": 1, + "foo": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "invalid object 2", + "data": { + "foo\tbar": 1, + "a": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "invalid object 3", + "data": { + "foo'bar": 1 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "invalid object 4", + "data": { + "foo\"bar": 2 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "dependent subschema incompatible with root", + "schema": { + "properties": { + "foo": {} + }, + "dependencies": { + "foo": { + "properties": { + "bar": {} + }, + "additionalProperties": false + } + } + }, + "tests": [ + { + "description": "matches root", + "data": { + "foo": 1 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "matches dependency", + "data": { + "bar": 1 + }, + "valid": true + }, + { + "description": "matches both", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "no dependency", + "data": { + "baz": 1 + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/enum.json b/encoding/jsonschema/testdata/external/tests/draft6/enum.json new file mode 100644 index 000000000..3158bea80 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/enum.json @@ -0,0 +1,449 @@ +[ + { + "description": "simple enum validation", + "schema": { + "enum": [ + 1, + 2, + 3 + ] + }, + "tests": [ + { + "description": "one of the enum is valid", + "data": 1, + "valid": true + }, + { + "description": "something else is invalid", + "data": 4, + "valid": false + } + ] + }, + { + "description": "heterogeneous enum validation", + "schema": { + "enum": [ + 6, + "foo", + [], + true, + { + "foo": 12 + } + ] + }, + "tests": [ + { + "description": "one of the enum is valid", + "data": [], + "valid": true + }, + { + "description": "something else is invalid", + "data": null, + "valid": false + }, + { + "description": "objects are deep compared", + "data": { + "foo": false + }, + "valid": false + }, + { + "description": "valid object matches", + "data": { + "foo": 12 + }, + "valid": true + }, + { + "description": "extra properties in object is invalid", + "data": { + "foo": 12, + "boo": 42 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "heterogeneous enum-with-null validation", + "schema": { + "enum": [ + 6, + null + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "number is valid", + "data": 6, + "valid": true + }, + { + "description": "something else is invalid", + "data": "test", + "valid": false + } + ] + }, + { + "description": "enums in properties", + "schema": { + "type": "object", + "properties": { + "foo": { + "enum": [ + "foo" + ] + }, + "bar": { + "enum": [ + "bar" + ] + } + }, + "required": [ + "bar" + ] + }, + "tests": [ + { + "description": "both properties are valid", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "wrong foo value", + "data": { + "foo": "foot", + "bar": "bar" + }, + "valid": false + }, + { + "description": "wrong bar value", + "data": { + "foo": "foo", + "bar": "bart" + }, + "valid": false + }, + { + "description": "missing optional property is valid", + "data": { + "bar": "bar" + }, + "valid": true + }, + { + "description": "missing required property is invalid", + "data": { + "foo": "foo" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "missing all properties is invalid", + "data": {}, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "enum with escaped characters", + "schema": { + "enum": [ + "foo\nbar", + "foo\rbar" + ] + }, + "tests": [ + { + "description": "member 1 is valid", + "data": "foo\nbar", + "valid": true + }, + { + "description": "member 2 is valid", + "data": "foo\rbar", + "valid": true + }, + { + "description": "another string is invalid", + "data": "abc", + "valid": false + } + ] + }, + { + "description": "enum with false does not match 0", + "schema": { + "enum": [ + false + ] + }, + "tests": [ + { + "description": "false is valid", + "data": false, + "valid": true + }, + { + "description": "integer zero is invalid", + "data": 0, + "valid": false + }, + { + "description": "float zero is invalid", + "data": 0.0, + "valid": false + } + ] + }, + { + "description": "enum with [false] does not match [0]", + "schema": { + "enum": [ + [ + false + ] + ] + }, + "tests": [ + { + "description": "[false] is valid", + "data": [ + false + ], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [ + 0 + ], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [ + 0.0 + ], + "valid": false + } + ] + }, + { + "description": "enum with true does not match 1", + "schema": { + "enum": [ + true + ] + }, + "tests": [ + { + "description": "true is valid", + "data": true, + "valid": true + }, + { + "description": "integer one is invalid", + "data": 1, + "valid": false + }, + { + "description": "float one is invalid", + "data": 1.0, + "valid": false + } + ] + }, + { + "description": "enum with [true] does not match [1]", + "schema": { + "enum": [ + [ + true + ] + ] + }, + "tests": [ + { + "description": "[true] is valid", + "data": [ + true + ], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [ + 1 + ], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [ + 1.0 + ], + "valid": false + } + ] + }, + { + "description": "enum with 0 does not match false", + "schema": { + "enum": [ + 0 + ] + }, + "tests": [ + { + "description": "false is invalid", + "data": false, + "valid": false + }, + { + "description": "integer zero is valid", + "data": 0, + "valid": true + }, + { + "description": "float zero is valid", + "data": 0.0, + "valid": true, + "skip": "conflicting values 0.0 and 0 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + } + ] + }, + { + "description": "enum with [0] does not match [false]", + "schema": { + "enum": [ + [ + 0 + ] + ] + }, + "tests": [ + { + "description": "[false] is invalid", + "data": [ + false + ], + "valid": false + }, + { + "description": "[0] is valid", + "data": [ + 0 + ], + "valid": true + }, + { + "description": "[0.0] is valid", + "data": [ + 0.0 + ], + "valid": true, + "skip": "0: conflicting values 0.0 and 0 (mismatched types float and int):\n generated.cue:2:1\n generated.cue:2:2\n instance.json:1:2\n" + } + ] + }, + { + "description": "enum with 1 does not match true", + "schema": { + "enum": [ + 1 + ] + }, + "tests": [ + { + "description": "true is invalid", + "data": true, + "valid": false + }, + { + "description": "integer one is valid", + "data": 1, + "valid": true + }, + { + "description": "float one is valid", + "data": 1.0, + "valid": true, + "skip": "conflicting values 1.0 and 1 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + } + ] + }, + { + "description": "enum with [1] does not match [true]", + "schema": { + "enum": [ + [ + 1 + ] + ] + }, + "tests": [ + { + "description": "[true] is invalid", + "data": [ + true + ], + "valid": false + }, + { + "description": "[1] is valid", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "[1.0] is valid", + "data": [ + 1.0 + ], + "valid": true, + "skip": "0: conflicting values 1.0 and 1 (mismatched types float and int):\n generated.cue:2:1\n generated.cue:2:2\n instance.json:1:2\n" + } + ] + }, + { + "description": "nul characters in strings", + "schema": { + "enum": [ + "hello\u0000there" + ] + }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/exclusiveMaximum.json b/encoding/jsonschema/testdata/external/tests/draft6/exclusiveMaximum.json new file mode 100644 index 000000000..5039e8321 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/exclusiveMaximum.json @@ -0,0 +1,30 @@ +[ + { + "description": "exclusiveMaximum validation", + "schema": { + "exclusiveMaximum": 3.0 + }, + "tests": [ + { + "description": "below the exclusiveMaximum is valid", + "data": 2.2, + "valid": true + }, + { + "description": "boundary point is invalid", + "data": 3.0, + "valid": false + }, + { + "description": "above the exclusiveMaximum is invalid", + "data": 3.5, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/exclusiveMinimum.json b/encoding/jsonschema/testdata/external/tests/draft6/exclusiveMinimum.json new file mode 100644 index 000000000..cb87ce2fc --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/exclusiveMinimum.json @@ -0,0 +1,30 @@ +[ + { + "description": "exclusiveMinimum validation", + "schema": { + "exclusiveMinimum": 1.1 + }, + "tests": [ + { + "description": "above the exclusiveMinimum is valid", + "data": 1.2, + "valid": true + }, + { + "description": "boundary point is invalid", + "data": 1.1, + "valid": false + }, + { + "description": "below the exclusiveMinimum is invalid", + "data": 0.6, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/format.json b/encoding/jsonschema/testdata/external/tests/draft6/format.json new file mode 100644 index 000000000..39b8e1c55 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/format.json @@ -0,0 +1,407 @@ +[ + { + "description": "email format", + "schema": { + "format": "email" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ipv4 format", + "schema": { + "format": "ipv4" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ipv6 format", + "schema": { + "format": "ipv6" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "hostname format", + "schema": { + "format": "hostname" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "date-time format", + "schema": { + "format": "date-time" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "json-pointer format", + "schema": { + "format": "json-pointer" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "uri format", + "schema": { + "format": "uri" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "uri-reference format", + "schema": { + "format": "uri-reference" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "uri-template format", + "schema": { + "format": "uri-template" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/infinite-loop-detection.json b/encoding/jsonschema/testdata/external/tests/draft6/infinite-loop-detection.json new file mode 100644 index 000000000..fe96bb563 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/infinite-loop-detection.json @@ -0,0 +1,42 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "definitions": { + "int": { + "type": "integer" + } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/definitions/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/definitions/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "failing case", + "data": { + "foo": "a string" + }, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/items.json b/encoding/jsonschema/testdata/external/tests/draft6/items.json new file mode 100644 index 000000000..7c45a9562 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/items.json @@ -0,0 +1,555 @@ +[ + { + "description": "a schema given for items", + "schema": { + "items": { + "type": "integer" + } + }, + "tests": [ + { + "description": "valid items", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "wrong type of items", + "data": [ + 1, + "x" + ], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "JavaScript pseudo-array is valid", + "data": { + "0": "invalid", + "length": 1 + }, + "valid": true + } + ] + }, + { + "description": "an array of schemas for items", + "schema": { + "items": [ + { + "type": "integer" + }, + { + "type": "string" + } + ] + }, + "tests": [ + { + "description": "correct types", + "data": [ + 1, + "foo" + ], + "valid": true + }, + { + "description": "wrong types", + "data": [ + "foo", + 1 + ], + "valid": false + }, + { + "description": "incomplete array of items", + "data": [ + 1 + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:49\n instance.json:1:1\nconflicting values bool and [1] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "array with additional items", + "data": [ + 1, + "foo", + true + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1,\"foo\",true] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:49\n instance.json:1:1\nconflicting values bool and [1,\"foo\",true] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,\"foo\",true] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,\"foo\",true] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,\"foo\",true] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "empty array", + "data": [], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:49\n instance.json:1:1\nconflicting values bool and [] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "JavaScript pseudo-array is valid", + "data": { + "0": "invalid", + "1": "valid", + "length": 2 + }, + "valid": true + } + ] + }, + { + "description": "items with boolean schema (true)", + "schema": { + "items": true + }, + "skip": "extract error: value of \"items\" must be an object or array", + "tests": [ + { + "description": "any array is valid", + "data": [ + 1, + "foo", + true + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "empty array is valid", + "data": [], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "items with boolean schema (false)", + "schema": { + "items": false + }, + "skip": "extract error: value of \"items\" must be an object or array", + "tests": [ + { + "description": "any non-empty array is invalid", + "data": [ + 1, + "foo", + true + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty array is valid", + "data": [], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "items with boolean schemas", + "schema": { + "items": [ + true, + false + ] + }, + "tests": [ + { + "description": "array with one item is valid", + "data": [ + 1 + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:44\n instance.json:1:1\nconflicting values bool and [1] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "array with two items is invalid", + "data": [ + 1, + "foo" + ], + "valid": false + }, + { + "description": "empty array is valid", + "data": [], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:44\n instance.json:1:1\nconflicting values bool and [] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + } + ] + }, + { + "description": "items and subitems", + "schema": { + "definitions": { + "item": { + "type": "array", + "additionalItems": false, + "items": [ + { + "$ref": "#/definitions/sub-item" + }, + { + "$ref": "#/definitions/sub-item" + } + ] + }, + "sub-item": { + "type": "object", + "required": [ + "foo" + ] + } + }, + "type": "array", + "additionalItems": false, + "items": [ + { + "$ref": "#/definitions/item" + }, + { + "$ref": "#/definitions/item" + }, + { + "$ref": "#/definitions/item" + } + ] + }, + "tests": [ + { + "description": "valid items", + "data": [ + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": true + }, + { + "description": "too many items", + "data": [ + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": false + }, + { + "description": "too many sub-items", + "data": [ + [ + { + "foo": null + }, + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": false + }, + { + "description": "wrong item", + "data": [ + { + "foo": null + }, + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": false + }, + { + "description": "wrong sub-item", + "data": [ + [ + {}, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": false, + "skip": "unexpected success" + }, + { + "description": "fewer items is valid", + "data": [ + [ + { + "foo": null + } + ], + [ + { + "foo": null + } + ] + ], + "valid": true, + "skip": "incompatible list lengths (2 and 3)\n" + } + ] + }, + { + "description": "nested items", + "schema": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "number" + } + } + } + } + }, + "tests": [ + { + "description": "valid nested array", + "data": [ + [ + [ + [ + 1 + ] + ], + [ + [ + 2 + ], + [ + 3 + ] + ] + ], + [ + [ + [ + 4 + ], + [ + 5 + ], + [ + 6 + ] + ] + ] + ], + "valid": true + }, + { + "description": "nested array with invalid type", + "data": [ + [ + [ + [ + "1" + ] + ], + [ + [ + 2 + ], + [ + 3 + ] + ] + ], + [ + [ + [ + 4 + ], + [ + 5 + ], + [ + 6 + ] + ] + ] + ], + "valid": false + }, + { + "description": "not deep enough", + "data": [ + [ + [ + 1 + ], + [ + 2 + ], + [ + 3 + ] + ], + [ + [ + 4 + ], + [ + 5 + ], + [ + 6 + ] + ] + ], + "valid": false + } + ] + }, + { + "description": "single-form items with null instance elements", + "schema": { + "items": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ + null + ], + "valid": true + } + ] + }, + { + "description": "array-form items with null instance elements", + "schema": { + "items": [ + { + "type": "null" + } + ] + }, + "tests": [ + { + "description": "allows null elements", + "data": [ + null + ], + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/maxItems.json b/encoding/jsonschema/testdata/external/tests/draft6/maxItems.json new file mode 100644 index 000000000..cb304e672 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/maxItems.json @@ -0,0 +1,66 @@ +[ + { + "description": "maxItems validation", + "schema": { + "maxItems": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "exact length is valid", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "too long is invalid", + "data": [ + 1, + 2, + 3 + ], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": "foobar", + "valid": true + } + ] + }, + { + "description": "maxItems validation with a decimal", + "schema": { + "maxItems": 2.0 + }, + "skip": "extract error: invalid uint", + "tests": [ + { + "description": "shorter is valid", + "data": [ + 1 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too long is invalid", + "data": [ + 1, + 2, + 3 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/maxLength.json b/encoding/jsonschema/testdata/external/tests/draft6/maxLength.json new file mode 100644 index 000000000..357b57159 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/maxLength.json @@ -0,0 +1,54 @@ +[ + { + "description": "maxLength validation", + "schema": { + "maxLength": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true + }, + { + "description": "exact length is valid", + "data": "fo", + "valid": true + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + }, + { + "description": "two graphemes is long enough", + "data": "💩💩", + "valid": true + } + ] + }, + { + "description": "maxLength validation with a decimal", + "schema": { + "maxLength": 2.0 + }, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values \"f\" and [...] (mismatched types string and list):\n generated.cue:3:1\n generated.cue:3:48\n instance.json:1:1\nconflicting values \"f\" and bool (mismatched types string and bool):\n generated.cue:3:1\n generated.cue:3:8\n instance.json:1:1\nconflicting values \"f\" and null (mismatched types string and null):\n generated.cue:3:1\n instance.json:1:1\nconflicting values \"f\" and number (mismatched types string and number):\n generated.cue:3:1\n generated.cue:3:15\n instance.json:1:1\nconflicting values \"f\" and {...} (mismatched types string and struct):\n generated.cue:3:1\n generated.cue:3:56\n instance.json:1:1\ncannot use 2.0 (type float) as int in argument 2 to strings.MaxRunes:\n generated.cue:3:41\n" + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/maxProperties.json b/encoding/jsonschema/testdata/external/tests/draft6/maxProperties.json new file mode 100644 index 000000000..f6b8aba8b --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/maxProperties.json @@ -0,0 +1,100 @@ +[ + { + "description": "maxProperties validation", + "schema": { + "maxProperties": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "exact length is valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "too long is invalid", + "data": { + "foo": 1, + "bar": 2, + "baz": 3 + }, + "valid": false + }, + { + "description": "ignores arrays", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "maxProperties validation with a decimal", + "schema": { + "maxProperties": 2.0 + }, + "skip": "extract error: invalid uint", + "tests": [ + { + "description": "shorter is valid", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too long is invalid", + "data": { + "foo": 1, + "bar": 2, + "baz": 3 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "maxProperties = 0 means the object is empty", + "schema": { + "maxProperties": 0 + }, + "tests": [ + { + "description": "no properties is valid", + "data": {}, + "valid": true + }, + { + "description": "one property is invalid", + "data": { + "foo": 1 + }, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/maximum.json b/encoding/jsonschema/testdata/external/tests/draft6/maximum.json new file mode 100644 index 000000000..c1b0fe5cb --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/maximum.json @@ -0,0 +1,58 @@ +[ + { + "description": "maximum validation", + "schema": { + "maximum": 3.0 + }, + "tests": [ + { + "description": "below the maximum is valid", + "data": 2.6, + "valid": true + }, + { + "description": "boundary point is valid", + "data": 3.0, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 3.5, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + }, + { + "description": "maximum validation with unsigned integer", + "schema": { + "maximum": 300 + }, + "tests": [ + { + "description": "below the maximum is invalid", + "data": 299.97, + "valid": true + }, + { + "description": "boundary point integer is valid", + "data": 300, + "valid": true + }, + { + "description": "boundary point float is valid", + "data": 300.00, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 300.5, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/minItems.json b/encoding/jsonschema/testdata/external/tests/draft6/minItems.json new file mode 100644 index 000000000..7264e5c61 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/minItems.json @@ -0,0 +1,59 @@ +[ + { + "description": "minItems validation", + "schema": { + "minItems": 1 + }, + "tests": [ + { + "description": "longer is valid", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "exact length is valid", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "too short is invalid", + "data": [], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": "", + "valid": true + } + ] + }, + { + "description": "minItems validation with a decimal", + "schema": { + "minItems": 1.0 + }, + "skip": "extract error: invalid uint", + "tests": [ + { + "description": "longer is valid", + "data": [ + 1, + 2 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too short is invalid", + "data": [], + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/minLength.json b/encoding/jsonschema/testdata/external/tests/draft6/minLength.json new file mode 100644 index 000000000..57f561be4 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/minLength.json @@ -0,0 +1,54 @@ +[ + { + "description": "minLength validation", + "schema": { + "minLength": 2 + }, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true + }, + { + "description": "exact length is valid", + "data": "fo", + "valid": true + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + }, + { + "description": "ignores non-strings", + "data": 1, + "valid": true + }, + { + "description": "one grapheme is not long enough", + "data": "💩", + "valid": false + } + ] + }, + { + "description": "minLength validation with a decimal", + "schema": { + "minLength": 2.0 + }, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values \"foo\" and [...] (mismatched types string and list):\n generated.cue:3:1\n generated.cue:3:48\n instance.json:1:1\nconflicting values \"foo\" and bool (mismatched types string and bool):\n generated.cue:3:1\n generated.cue:3:8\n instance.json:1:1\nconflicting values \"foo\" and null (mismatched types string and null):\n generated.cue:3:1\n instance.json:1:1\nconflicting values \"foo\" and number (mismatched types string and number):\n generated.cue:3:1\n generated.cue:3:15\n instance.json:1:1\nconflicting values \"foo\" and {...} (mismatched types string and struct):\n generated.cue:3:1\n generated.cue:3:56\n instance.json:1:1\ncannot use 2.0 (type float) as int in argument 2 to strings.MinRunes:\n generated.cue:3:41\n" + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/minProperties.json b/encoding/jsonschema/testdata/external/tests/draft6/minProperties.json new file mode 100644 index 000000000..070c35488 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/minProperties.json @@ -0,0 +1,76 @@ +[ + { + "description": "minProperties validation", + "schema": { + "minProperties": 1 + }, + "skip": "extract error: unsupported constraint \"minProperties\"", + "tests": [ + { + "description": "longer is valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "exact length is valid", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ignores arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores strings", + "data": "", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "minProperties validation with a decimal", + "schema": { + "minProperties": 1.0 + }, + "skip": "extract error: unsupported constraint \"minProperties\"", + "tests": [ + { + "description": "longer is valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/minimum.json b/encoding/jsonschema/testdata/external/tests/draft6/minimum.json new file mode 100644 index 000000000..8c1194093 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/minimum.json @@ -0,0 +1,73 @@ +[ + { + "description": "minimum validation", + "schema": { + "minimum": 1.1 + }, + "tests": [ + { + "description": "above the minimum is valid", + "data": 2.6, + "valid": true + }, + { + "description": "boundary point is valid", + "data": 1.1, + "valid": true + }, + { + "description": "below the minimum is invalid", + "data": 0.6, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + }, + { + "description": "minimum validation with signed integer", + "schema": { + "minimum": -2 + }, + "tests": [ + { + "description": "negative above the minimum is valid", + "data": -1, + "valid": true + }, + { + "description": "positive above the minimum is valid", + "data": 0, + "valid": true + }, + { + "description": "boundary point is valid", + "data": -2, + "valid": true + }, + { + "description": "boundary point with float is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float below the minimum is invalid", + "data": -2.0001, + "valid": false + }, + { + "description": "int below the minimum is invalid", + "data": -3, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/multipleOf.json b/encoding/jsonschema/testdata/external/tests/draft6/multipleOf.json new file mode 100644 index 000000000..bfd82eda5 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/multipleOf.json @@ -0,0 +1,94 @@ +[ + { + "description": "by int", + "schema": { + "multipleOf": 2 + }, + "tests": [ + { + "description": "int by int", + "data": 10, + "valid": true + }, + { + "description": "int by int fail", + "data": 7, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "by number", + "schema": { + "multipleOf": 1.5 + }, + "tests": [ + { + "description": "zero is multiple of anything", + "data": 0, + "valid": true + }, + { + "description": "4.5 is multiple of 1.5", + "data": 4.5, + "valid": true + }, + { + "description": "35 is not multiple of 1.5", + "data": 35, + "valid": false + } + ] + }, + { + "description": "by small number", + "schema": { + "multipleOf": 0.0001 + }, + "tests": [ + { + "description": "0.0075 is multiple of 0.0001", + "data": 0.0075, + "valid": true + }, + { + "description": "0.00751 is not multiple of 0.0001", + "data": 0.00751, + "valid": false + } + ] + }, + { + "description": "float division = inf", + "schema": { + "type": "integer", + "multipleOf": 0.123456789 + }, + "tests": [ + { + "description": "always invalid, but naive implementations may raise an overflow error", + "data": 1E+308, + "valid": false + } + ] + }, + { + "description": "small multiple of large integer", + "schema": { + "type": "integer", + "multipleOf": 1E-8 + }, + "tests": [ + { + "description": "any integer is a multiple of 1e-8", + "data": 12391239123, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/not.json b/encoding/jsonschema/testdata/external/tests/draft6/not.json new file mode 100644 index 000000000..8a575db2e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/not.json @@ -0,0 +1,344 @@ +[ + { + "description": "not", + "schema": { + "not": { + "type": "integer" + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "allowed", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "disallowed", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "not multiple types", + "schema": { + "not": { + "type": [ + "integer", + "boolean" + ] + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "other mismatch", + "data": true, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "not more complex schema", + "schema": { + "not": { + "type": "object", + "properties": { + "foo": { + "type": "string" + } + } + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "match", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "other match", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "forbidden property", + "schema": { + "properties": { + "foo": { + "not": {} + } + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "property present", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "property absent", + "data": { + "bar": 1, + "baz": 2 + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "forbid everything with empty schema", + "schema": { + "not": {} + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "null is invalid", + "data": null, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "object is invalid", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "array is invalid", + "data": [ + "foo" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "forbid everything with boolean schema true", + "schema": { + "not": true + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "null is invalid", + "data": null, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "object is invalid", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "array is invalid", + "data": [ + "foo" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "allow everything with boolean schema false", + "schema": { + "not": false + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string is valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "boolean true is valid", + "data": true, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "boolean false is valid", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "null is valid", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "object is valid", + "data": { + "foo": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "array is valid", + "data": [ + "foo" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "empty array is valid", + "data": [], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "double negation", + "schema": { + "not": { + "not": {} + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/oneOf.json b/encoding/jsonschema/testdata/external/tests/draft6/oneOf.json new file mode 100644 index 000000000..a76dae91b --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/oneOf.json @@ -0,0 +1,364 @@ +[ + { + "description": "oneOf", + "schema": { + "oneOf": [ + { + "type": "integer" + }, + { + "minimum": 2 + } + ] + }, + "tests": [ + { + "description": "first oneOf valid", + "data": 1, + "valid": true + }, + { + "description": "second oneOf valid", + "data": 2.5, + "valid": true + }, + { + "description": "both oneOf valid", + "data": 3, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "neither oneOf valid", + "data": 1.5, + "valid": false + } + ] + }, + { + "description": "oneOf with base schema", + "schema": { + "type": "string", + "oneOf": [ + { + "minLength": 2 + }, + { + "maxLength": 4 + } + ] + }, + "tests": [ + { + "description": "mismatch base schema", + "data": 3, + "valid": false + }, + { + "description": "one oneOf valid", + "data": "foobar", + "valid": true + }, + { + "description": "both oneOf valid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with boolean schemas, all true", + "schema": { + "oneOf": [ + true, + true, + true + ] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with boolean schemas, one true", + "schema": { + "oneOf": [ + true, + false, + false + ] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "oneOf with boolean schemas, more than one true", + "schema": { + "oneOf": [ + true, + true, + false + ] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with boolean schemas, all false", + "schema": { + "oneOf": [ + false, + false, + false + ] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf complex types", + "schema": { + "oneOf": [ + { + "properties": { + "bar": { + "type": "integer" + } + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + } + ] + }, + "tests": [ + { + "description": "first oneOf valid (complex)", + "data": { + "bar": 2 + }, + "valid": true + }, + { + "description": "second oneOf valid (complex)", + "data": { + "foo": "baz" + }, + "valid": true + }, + { + "description": "both oneOf valid (complex)", + "data": { + "foo": "baz", + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "neither oneOf valid (complex)", + "data": { + "foo": 2, + "bar": "quux" + }, + "valid": false + } + ] + }, + { + "description": "oneOf with empty schema", + "schema": { + "oneOf": [ + { + "type": "number" + }, + {} + ] + }, + "tests": [ + { + "description": "one valid - valid", + "data": "foo", + "valid": true + }, + { + "description": "both valid - invalid", + "data": 123, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with required", + "schema": { + "type": "object", + "oneOf": [ + { + "required": [ + "foo", + "bar" + ] + }, + { + "required": [ + "foo", + "baz" + ] + } + ] + }, + "tests": [ + { + "description": "both invalid - invalid", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "first valid - valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "second valid - valid", + "data": { + "foo": 1, + "baz": 3 + }, + "valid": true + }, + { + "description": "both valid - invalid", + "data": { + "foo": 1, + "bar": 2, + "baz": 3 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with missing optional property", + "schema": { + "oneOf": [ + { + "properties": { + "bar": true, + "baz": true + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "foo": true + }, + "required": [ + "foo" + ] + } + ] + }, + "tests": [ + { + "description": "first oneOf valid", + "data": { + "bar": 8 + }, + "valid": true + }, + { + "description": "second oneOf valid", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "both oneOf valid", + "data": { + "foo": "foo", + "bar": 8 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "neither oneOf valid", + "data": { + "baz": "quux" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "nested oneOf, to check validation semantics", + "schema": { + "oneOf": [ + { + "oneOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/optional/bignum.json b/encoding/jsonschema/testdata/external/tests/draft6/optional/bignum.json new file mode 100644 index 000000000..2310db3d6 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/optional/bignum.json @@ -0,0 +1,103 @@ +[ + { + "description": "integer", + "schema": { + "type": "integer" + }, + "tests": [ + { + "description": "a bignum is an integer", + "data": 12345678910111213141516171819202122232425262728293031, + "valid": true + }, + { + "description": "a negative bignum is an integer", + "data": -12345678910111213141516171819202122232425262728293031, + "valid": true + } + ] + }, + { + "description": "number", + "schema": { + "type": "number" + }, + "tests": [ + { + "description": "a bignum is a number", + "data": 98249283749234923498293171823948729348710298301928331, + "valid": true + }, + { + "description": "a negative bignum is a number", + "data": -98249283749234923498293171823948729348710298301928331, + "valid": true + } + ] + }, + { + "description": "string", + "schema": { + "type": "string" + }, + "tests": [ + { + "description": "a bignum is not a string", + "data": 98249283749234923498293171823948729348710298301928331, + "valid": false + } + ] + }, + { + "description": "maximum integer comparison", + "schema": { + "maximum": 18446744073709551615 + }, + "tests": [ + { + "description": "comparison works for high numbers", + "data": 18446744073709551600, + "valid": true + } + ] + }, + { + "description": "float comparison with high precision", + "schema": { + "exclusiveMaximum": 972783798187987123879878123.18878137 + }, + "tests": [ + { + "description": "comparison works for high numbers", + "data": 972783798187987123879878123.188781371, + "valid": false + } + ] + }, + { + "description": "minimum integer comparison", + "schema": { + "minimum": -18446744073709551615 + }, + "tests": [ + { + "description": "comparison works for very negative numbers", + "data": -18446744073709551600, + "valid": true + } + ] + }, + { + "description": "float comparison with high precision on negative numbers", + "schema": { + "exclusiveMinimum": -972783798187987123879878123.18878137 + }, + "tests": [ + { + "description": "comparison works for very negative numbers", + "data": -972783798187987123879878123.188781371, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/optional/ecmascript-regex.json b/encoding/jsonschema/testdata/external/tests/draft6/optional/ecmascript-regex.json new file mode 100644 index 000000000..95600268d --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/optional/ecmascript-regex.json @@ -0,0 +1,630 @@ +[ + { + "description": "ECMA 262 regex $ does not match trailing newline", + "schema": { + "type": "string", + "pattern": "^abc$" + }, + "tests": [ + { + "description": "matches in Python, but not in ECMA 262", + "data": "abc\\n", + "valid": false + }, + { + "description": "matches", + "data": "abc", + "valid": true + } + ] + }, + { + "description": "ECMA 262 regex converts \\t to horizontal tab", + "schema": { + "type": "string", + "pattern": "^\\t$" + }, + "tests": [ + { + "description": "does not match", + "data": "\\t", + "valid": false + }, + { + "description": "matches", + "data": "\t", + "valid": true + } + ] + }, + { + "description": "ECMA 262 regex escapes control codes with \\c and upper letter", + "schema": { + "type": "string", + "pattern": "^\\cC$" + }, + "skip": "extract error: unsupported regexp: error parsing regexp: invalid escape sequence: `\\c`", + "tests": [ + { + "description": "does not match", + "data": "\\cC", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "matches", + "data": "\u0003", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ECMA 262 regex escapes control codes with \\c and lower letter", + "schema": { + "type": "string", + "pattern": "^\\cc$" + }, + "skip": "extract error: unsupported regexp: error parsing regexp: invalid escape sequence: `\\c`", + "tests": [ + { + "description": "does not match", + "data": "\\cc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "matches", + "data": "\u0003", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ECMA 262 \\d matches ascii digits only", + "schema": { + "type": "string", + "pattern": "^\\d$" + }, + "tests": [ + { + "description": "ASCII zero matches", + "data": "0", + "valid": true + }, + { + "description": "NKO DIGIT ZERO does not match (unlike e.g. Python)", + "data": "߀", + "valid": false + }, + { + "description": "NKO DIGIT ZERO (as \\u escape) does not match", + "data": "߀", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\D matches everything but ascii digits", + "schema": { + "type": "string", + "pattern": "^\\D$" + }, + "tests": [ + { + "description": "ASCII zero does not match", + "data": "0", + "valid": false + }, + { + "description": "NKO DIGIT ZERO matches (unlike e.g. Python)", + "data": "߀", + "valid": true + }, + { + "description": "NKO DIGIT ZERO (as \\u escape) matches", + "data": "߀", + "valid": true + } + ] + }, + { + "description": "ECMA 262 \\w matches ascii letters only", + "schema": { + "type": "string", + "pattern": "^\\w$" + }, + "tests": [ + { + "description": "ASCII 'a' matches", + "data": "a", + "valid": true + }, + { + "description": "latin-1 e-acute does not match (unlike e.g. Python)", + "data": "é", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\W matches everything but ascii letters", + "schema": { + "type": "string", + "pattern": "^\\W$" + }, + "tests": [ + { + "description": "ASCII 'a' does not match", + "data": "a", + "valid": false + }, + { + "description": "latin-1 e-acute matches (unlike e.g. Python)", + "data": "é", + "valid": true + } + ] + }, + { + "description": "ECMA 262 \\s matches whitespace", + "schema": { + "type": "string", + "pattern": "^\\s$" + }, + "tests": [ + { + "description": "ASCII space matches", + "data": " ", + "valid": true + }, + { + "description": "Character tabulation matches", + "data": "\t", + "valid": true + }, + { + "description": "Line tabulation matches", + "data": "\u000b", + "valid": true, + "skip": "invalid value \"\\v\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "Form feed matches", + "data": "\f", + "valid": true + }, + { + "description": "latin-1 non-breaking-space matches", + "data": " ", + "valid": true, + "skip": "invalid value \"\\u00a0\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "zero-width whitespace matches", + "data": "\ufeff", + "valid": true, + "skip": "invalid value \"\\ufeff\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "line feed matches (line terminator)", + "data": "\n", + "valid": true + }, + { + "description": "paragraph separator matches (line terminator)", + "data": "\u2029", + "valid": true, + "skip": "invalid value \"\\u2029\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "EM SPACE matches (Space_Separator)", + "data": " ", + "valid": true, + "skip": "invalid value \"\\u2003\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "Non-whitespace control does not match", + "data": "\u0001", + "valid": false + }, + { + "description": "Non-whitespace does not match", + "data": "–", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\S matches everything but whitespace", + "schema": { + "type": "string", + "pattern": "^\\S$" + }, + "tests": [ + { + "description": "ASCII space does not match", + "data": " ", + "valid": false + }, + { + "description": "Character tabulation does not match", + "data": "\t", + "valid": false + }, + { + "description": "Line tabulation does not match", + "data": "\u000b", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "Form feed does not match", + "data": "\f", + "valid": false + }, + { + "description": "latin-1 non-breaking-space does not match", + "data": " ", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "zero-width whitespace does not match", + "data": "\ufeff", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "line feed does not match (line terminator)", + "data": "\n", + "valid": false + }, + { + "description": "paragraph separator does not match (line terminator)", + "data": "\u2029", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "EM SPACE does not match (Space_Separator)", + "data": " ", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "Non-whitespace control matches", + "data": "\u0001", + "valid": true + }, + { + "description": "Non-whitespace matches", + "data": "–", + "valid": true + } + ] + }, + { + "description": "patterns always use unicode semantics with pattern", + "schema": { + "pattern": "\\p{Letter}cole" + }, + "skip": "extract error: unsupported regexp: error parsing regexp: invalid character class range: `\\p{Letter}`", + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ÉTAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ÉCOLE, L'ÉGLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ÉTAIT SUR LA PATINOIRE.", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "\\w in patterns matches [A-Za-z0-9_], not unicode letters", + "schema": { + "pattern": "\\wcole" + }, + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": false + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ÉTAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ÉCOLE, L'ÉGLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ÉTAIT SUR LA PATINOIRE.", + "valid": false + } + ] + }, + { + "description": "pattern with ASCII ranges", + "schema": { + "pattern": "[a-z]cole" + }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": false + }, + { + "description": "ascii characters match", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + } + ] + }, + { + "description": "\\d in pattern matches [0-9], not unicode digits", + "schema": { + "pattern": "^\\d+$" + }, + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "৪২", + "valid": false + } + ] + }, + { + "description": "pattern with non-ASCII digits", + "schema": { + "pattern": "^\\p{digit}+$" + }, + "skip": "extract error: unsupported regexp: error parsing regexp: invalid character class range: `\\p{digit}`", + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "৪২", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "patterns always use unicode semantics with patternProperties", + "schema": { + "type": "object", + "patternProperties": { + "\\p{Letter}cole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { + "l'ecole": "pas de vraie vie" + }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": true + }, + { + "description": "unicode character in hex format in string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": true + }, + { + "description": "unicode matching is case-sensitive", + "data": { + "L'ÉCOLE": "PAS DE VRAIE VIE" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "\\w in patternProperties matches [A-Za-z0-9_], not unicode letters", + "schema": { + "type": "object", + "patternProperties": { + "\\wcole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { + "l'ecole": "pas de vraie vie" + }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "unicode character in hex format in string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "unicode matching is case-sensitive", + "data": { + "L'ÉCOLE": "PAS DE VRAIE VIE" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "patternProperties with ASCII ranges", + "schema": { + "type": "object", + "patternProperties": { + "[a-z]cole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "unicode character in hex format in string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ascii characters match", + "data": { + "l'ecole": "pas de vraie vie" + }, + "valid": true + } + ] + }, + { + "description": "\\d in patternProperties matches [0-9], not unicode digits", + "schema": { + "type": "object", + "patternProperties": { + "^\\d+$": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { + "42": "life, the universe, and everything" + }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { + "-%#": "spending the year dead for tax reasons" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { + "৪২": "khajit has wares if you have coin" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "patternProperties with non-ASCII digits", + "schema": { + "type": "object", + "patternProperties": { + "^\\p{digit}+$": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { + "42": "life, the universe, and everything" + }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { + "-%#": "spending the year dead for tax reasons" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { + "৪২": "khajit has wares if you have coin" + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/optional/float-overflow.json b/encoding/jsonschema/testdata/external/tests/draft6/optional/float-overflow.json new file mode 100644 index 000000000..ab966fd5e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/optional/float-overflow.json @@ -0,0 +1,17 @@ +[ + { + "description": "all integers are multiples of 0.5, if overflow is handled", + "schema": { + "type": "integer", + "multipleOf": 0.5 + }, + "tests": [ + { + "description": "valid if optional overflow handling is implemented", + "data": 1E+308, + "valid": true, + "skip": "conflicting values 1E+308 and int (mismatched types float and int):\n generated.cue:3:1\n instance.json:1:1\n" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/optional/format/date-time.json b/encoding/jsonschema/testdata/external/tests/draft6/optional/format/date-time.json new file mode 100644 index 000000000..970385b11 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/optional/format/date-time.json @@ -0,0 +1,161 @@ +[ + { + "description": "validation of date-time strings", + "schema": { + "format": "date-time" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time string", + "data": "1963-06-19T08:30:06.283185Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time string without second fraction", + "data": "1963-06-19T08:30:06Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time string with plus offset", + "data": "1937-01-01T12:00:27.87+00:20", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time string with minus offset", + "data": "1990-12-31T15:59:50.123-08:00", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time with a leap second, UTC", + "data": "1998-12-31T23:59:60Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time with a leap second, with minus offset", + "data": "1998-12-31T15:59:60.123-08:00", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid date-time past leap second, UTC", + "data": "1998-12-31T23:59:61Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid date-time with leap second on a wrong minute, UTC", + "data": "1998-12-31T23:58:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid date-time with leap second on a wrong hour, UTC", + "data": "1998-12-31T22:59:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid day in date-time string", + "data": "1990-02-31T15:59:59.123-08:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid offset in date-time string", + "data": "1990-12-31T15:59:59-24:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid closing Z after time-zone offset", + "data": "1963-06-19T08:30:06.28123+01:00Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid date-time string", + "data": "06/19/1963 08:30:06 PST", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "case-insensitive T and Z", + "data": "1963-06-19t08:30:06.283185z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "2013-350T01:01:01", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-padded month dates", + "data": "1963-6-19T08:30:06.283185Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-padded day dates", + "data": "1963-06-1T08:30:06.283185Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4) in date portion", + "data": "1963-06-1৪T00:00:00Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4) in time portion", + "data": "1963-06-11T0৪:00:00Z", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/optional/format/email.json b/encoding/jsonschema/testdata/external/tests/draft6/optional/format/email.json new file mode 100644 index 000000000..3d9734d2f --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/optional/format/email.json @@ -0,0 +1,101 @@ +[ + { + "description": "validation of e-mail addresses", + "schema": { + "format": "email" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid e-mail address", + "data": "joe.bloggs@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid e-mail address", + "data": "2962", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "tilde in local part is valid", + "data": "te~st@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "tilde before local part is valid", + "data": "~test@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "tilde after local part is valid", + "data": "test~@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "dot before local part is not valid", + "data": ".test@example.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "dot after local part is not valid", + "data": "test.@example.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "two separated dots inside local part are valid", + "data": "te.s.t@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "two subsequent dots inside local part are not valid", + "data": "te..st@example.com", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/optional/format/hostname.json b/encoding/jsonschema/testdata/external/tests/draft6/optional/format/hostname.json new file mode 100644 index 000000000..848785f52 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/optional/format/hostname.json @@ -0,0 +1,143 @@ +[ + { + "description": "validation of host names", + "schema": { + "format": "hostname" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid host name", + "data": "www.example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid punycoded IDN hostname", + "data": "xn--4gbwdl.xn--wgbh1c", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a host name starting with an illegal character", + "data": "-a-host-name-that-starts-with--", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a host name containing illegal characters", + "data": "not_a_valid_host_name", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a host name with a component too long", + "data": "a-vvvvvvvvvvvvvvvveeeeeeeeeeeeeeeerrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy-long-host-name-component", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "starts with hyphen", + "data": "-hostname", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ends with hyphen", + "data": "hostname-", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "starts with underscore", + "data": "_hostname", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ends with underscore", + "data": "hostname_", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "contains underscore", + "data": "host_name", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "exceeds maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "single label", + "data": "hostname", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label with hyphen", + "data": "host-name", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label with digits", + "data": "h0stn4me", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label ending with digit", + "data": "hostnam3", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/optional/format/ipv4.json b/encoding/jsonschema/testdata/external/tests/draft6/optional/format/ipv4.json new file mode 100644 index 000000000..1ef0f11f8 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/optional/format/ipv4.json @@ -0,0 +1,108 @@ +[ + { + "description": "validation of IP addresses", + "schema": { + "format": "ipv4" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IP address", + "data": "192.168.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an IP address with too many components", + "data": "127.0.0.0.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IP address with out-of-range values", + "data": "256.256.256.256", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IP address without 4 components", + "data": "127.0", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IP address as an integer", + "data": "0x7f000001", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IP address as an integer (decimal)", + "data": "2130706433", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid leading zeroes, as they are treated as octals", + "comment": "see https://sick.codes/universal-netmask-npm-package-used-by-270000-projects-vulnerable-to-octal-input-data-server-side-request-forgery-remote-file-inclusion-local-file-inclusion-and-more-cve-2021-28918/", + "data": "087.10.0.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "value without leading zero is valid", + "data": "87.10.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '২' (a Bengali 2)", + "data": "1২7.0.0.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "netmask is not a part of ipv4 address", + "data": "192.168.1.0/24", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/optional/format/ipv6.json b/encoding/jsonschema/testdata/external/tests/draft6/optional/format/ipv6.json new file mode 100644 index 000000000..0c8edf677 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/optional/format/ipv6.json @@ -0,0 +1,251 @@ +[ + { + "description": "validation of IPv6 addresses", + "schema": { + "format": "ipv6" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IPv6 address", + "data": "::1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an IPv6 address with out-of-range values", + "data": "12345::", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "trailing 4 hex symbols is valid", + "data": "::abef", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "trailing 5 hex symbols is invalid", + "data": "::abcef", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IPv6 address with too many components", + "data": "1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IPv6 address containing illegal characters", + "data": "::laptop", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no digits is valid", + "data": "::", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "leading colons is valid", + "data": "::42:ff:1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "trailing colons is valid", + "data": "d6::", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "missing leading octet is invalid", + "data": ":2:3:4:5:6:7:8", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "missing trailing octet is invalid", + "data": "1:2:3:4:5:6:7:", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "missing leading octet with omitted octets later", + "data": ":2:3:4::8", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "single set of double colons in the middle is valid", + "data": "1:d6::42", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "two sets of double colons is invalid", + "data": "1::d6::42", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "mixed format with the ipv4 section as decimal octets", + "data": "1::d6:192.168.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mixed format with double colons between the sections", + "data": "1:2::192.168.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mixed format with ipv4 section with octet out of range", + "data": "1::2:192.168.256.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "mixed format with ipv4 section with a hex octet", + "data": "1::2:192.168.ff.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "mixed format with leading double colons (ipv4-mapped ipv6 address)", + "data": "::ffff:192.168.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "triple colons is invalid", + "data": "1:2:3:4:5:::8", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "8 octets", + "data": "1:2:3:4:5:6:7:8", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "insufficient octets without double colons", + "data": "1:2:3:4:5:6:7", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no colons is invalid", + "data": "1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ipv4 is not ipv6", + "data": "127.0.0.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ipv4 segment must have 4 octets", + "data": "1:2:3:4:1.2.3", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "leading whitespace is invalid", + "data": " ::1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "trailing whitespace is invalid", + "data": "::1 ", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "netmask is not a part of ipv6 address", + "data": "fe80::/64", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "zone id is not a part of ipv6 address", + "data": "fe80::a%eth1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a long valid ipv6", + "data": "1000:1000:1000:1000:1000:1000:255.255.255.255", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a long invalid ipv6, below length limit, first", + "data": "100:100:100:100:100:100:255.255.255.255.255", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a long invalid ipv6, below length limit, second", + "data": "100:100:100:100:100:100:100:255.255.255.255", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4)", + "data": "1:2:3:4:5:6:7:৪", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4) in the IPv4 portion", + "data": "1:2::192.16৪.0.1", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/optional/format/json-pointer.json b/encoding/jsonschema/testdata/external/tests/draft6/optional/format/json-pointer.json new file mode 100644 index 000000000..5d36bee42 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/optional/format/json-pointer.json @@ -0,0 +1,239 @@ +[ + { + "description": "validation of JSON-pointers (JSON String Representation)", + "schema": { + "format": "json-pointer" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid JSON-pointer", + "data": "/foo/bar~0/baz~1/%a", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (~ not escaped)", + "data": "/foo/bar~", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer with empty segment", + "data": "/foo//bar", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer with the last empty segment", + "data": "/foo/bar/", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #1", + "data": "", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #2", + "data": "/foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #3", + "data": "/foo/0", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #4", + "data": "/", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #5", + "data": "/a~1b", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #6", + "data": "/c%d", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #7", + "data": "/e^f", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #8", + "data": "/g|h", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #9", + "data": "/i\\j", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #10", + "data": "/k\"l", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #11", + "data": "/ ", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #12", + "data": "/m~0n", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer used adding to the last array position", + "data": "/foo/-", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer (- used as object member name)", + "data": "/foo/-/bar", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer (multiple escaped characters)", + "data": "/~1~0~0~1~1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer (escaped with fraction part) #1", + "data": "/~1.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer (escaped with fraction part) #2", + "data": "/~0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #1", + "data": "#", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #2", + "data": "#/", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #3", + "data": "#a", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (some escaped, but not all) #1", + "data": "/~0~", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (some escaped, but not all) #2", + "data": "/~0/~", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (wrong escape character) #1", + "data": "/~2", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (wrong escape character) #2", + "data": "/~-1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (multiple characters not escaped)", + "data": "/~~", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #1", + "data": "a", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #2", + "data": "0", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #3", + "data": "a/a", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/optional/format/unknown.json b/encoding/jsonschema/testdata/external/tests/draft6/optional/format/unknown.json new file mode 100644 index 000000000..97a7ae39e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/optional/format/unknown.json @@ -0,0 +1,53 @@ +[ + { + "description": "unknown format", + "schema": { + "format": "unknown" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "unknown formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore strings", + "data": "string", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/optional/format/uri-reference.json b/encoding/jsonschema/testdata/external/tests/draft6/optional/format/uri-reference.json new file mode 100644 index 000000000..5cf42d3b2 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/optional/format/uri-reference.json @@ -0,0 +1,89 @@ +[ + { + "description": "validation of URI References", + "schema": { + "format": "uri-reference" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URI", + "data": "http://foo.bar/?baz=qux#quux", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid protocol-relative URI Reference", + "data": "//foo.bar/?baz=qux#quux", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid relative URI Reference", + "data": "/abc", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI Reference", + "data": "\\\\WINDOWS\\fileshare", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid URI Reference", + "data": "abc", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URI fragment", + "data": "#fragment", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI fragment", + "data": "#frag\\ment", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/optional/format/uri-template.json b/encoding/jsonschema/testdata/external/tests/draft6/optional/format/uri-template.json new file mode 100644 index 000000000..6d96910b3 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/optional/format/uri-template.json @@ -0,0 +1,71 @@ +[ + { + "description": "format: uri-template", + "schema": { + "format": "uri-template" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid uri-template", + "data": "http://example.com/dictionary/{term:1}/{term}", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid uri-template", + "data": "http://example.com/dictionary/{term:1}/{term", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid uri-template without variables", + "data": "http://example.com/dictionary", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid relative uri-template", + "data": "dictionary/{term:1}/{term}", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/optional/format/uri.json b/encoding/jsonschema/testdata/external/tests/draft6/optional/format/uri.json new file mode 100644 index 000000000..9dfe867c4 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/optional/format/uri.json @@ -0,0 +1,167 @@ +[ + { + "description": "validation of URIs", + "schema": { + "format": "uri" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with anchor tag", + "data": "http://foo.bar/?baz=qux#quux", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with anchor tag and parentheses", + "data": "http://foo.com/blah_(wikipedia)_blah#cite-1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with URL-encoded stuff", + "data": "http://foo.bar/?q=Test%20URL-encoded%20stuff", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid puny-coded URL ", + "data": "http://xn--nw2a.xn--j6w193g/", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with many special characters", + "data": "http://-.~_!$\u0026'()*+,;=:%40:80%2f::::::@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL based on IPv4", + "data": "http://223.255.255.254", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with ftp scheme", + "data": "ftp://ftp.is.co.za/rfc/rfc1808.txt", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL for a simple text file", + "data": "http://www.ietf.org/rfc/rfc2396.txt", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL ", + "data": "ldap://[2001:db8::7]/c=GB?objectClass?one", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid mailto URI", + "data": "mailto:John.Doe@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid newsgroup URI", + "data": "news:comp.infosystems.www.servers.unix", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid tel URI", + "data": "tel:+1-816-555-1212", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URN", + "data": "urn:oasis:names:specification:docbook:dtd:xml:4.1.2", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid protocol-relative URI Reference", + "data": "//foo.bar/?baz=qux#quux", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid relative URI Reference", + "data": "/abc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI", + "data": "\\\\WINDOWS\\fileshare", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI though valid URI reference", + "data": "abc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI with spaces", + "data": "http:// shouldfail.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI with spaces and missing scheme", + "data": ":// should fail", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI with comma in scheme", + "data": "bar,baz:foo", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/optional/id.json b/encoding/jsonschema/testdata/external/tests/draft6/optional/id.json new file mode 100644 index 000000000..b54e2b249 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/optional/id.json @@ -0,0 +1,148 @@ +[ + { + "description": "id inside an enum is not a real identifier", + "comment": "the implementation must not be confused by an id buried in the enum", + "schema": { + "definitions": { + "id_in_enum": { + "enum": [ + { + "$id": "https://localhost:1234/id/my_identifier.json", + "type": "null" + } + ] + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/id/my_identifier.json", + "type": "string" + }, + "zzz_id_in_const": { + "const": { + "$id": "https://localhost:1234/id/my_identifier.json", + "type": "null" + } + } + }, + "anyOf": [ + { + "$ref": "#/definitions/id_in_enum" + }, + { + "$ref": "https://localhost:1234/id/my_identifier.json" + } + ] + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/id/my_identifier.json:my_identifier\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "$id": "https://localhost:1234/id/my_identifier.json", + "type": "null" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "match $ref to id", + "data": "a string to match #/definitions/id_in_enum", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "no match on enum or $ref to id", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "non-schema object containing a plain-name $id property", + "schema": { + "definitions": { + "const_not_anchor": { + "const": { + "$id": "#not_a_real_anchor" + } + } + }, + "oneOf": [ + { + "const": "skip not_a_real_anchor" + }, + { + "allOf": [ + { + "not": { + "const": "skip not_a_real_anchor" + } + }, + { + "$ref": "#/definitions/const_not_anchor" + } + ] + } + ] + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_anchor", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "const at const_not_anchor does not match", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "non-schema object containing an $id property", + "schema": { + "definitions": { + "const_not_id": { + "const": { + "$id": "not_a_real_id" + } + } + }, + "oneOf": [ + { + "const": "skip not_a_real_id" + }, + { + "allOf": [ + { + "not": { + "const": "skip not_a_real_id" + } + }, + { + "$ref": "#/definitions/const_not_id" + } + ] + } + ] + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_id", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "const at const_not_id does not match", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/optional/non-bmp-regex.json b/encoding/jsonschema/testdata/external/tests/draft6/optional/non-bmp-regex.json new file mode 100644 index 000000000..3ea9d0e2e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/optional/non-bmp-regex.json @@ -0,0 +1,94 @@ +[ + { + "description": "Proper UTF-16 surrogate pair handling: pattern", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { + "pattern": "^🐲*$" + }, + "tests": [ + { + "description": "matches empty", + "data": "", + "valid": true + }, + { + "description": "matches single", + "data": "🐲", + "valid": true + }, + { + "description": "matches two", + "data": "🐲🐲", + "valid": true + }, + { + "description": "doesn't match one", + "data": "🐉", + "valid": false + }, + { + "description": "doesn't match two", + "data": "🐉🐉", + "valid": false + }, + { + "description": "doesn't match one ASCII", + "data": "D", + "valid": false + }, + { + "description": "doesn't match two ASCII", + "data": "DD", + "valid": false + } + ] + }, + { + "description": "Proper UTF-16 surrogate pair handling: patternProperties", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { + "patternProperties": { + "^🐲*$": { + "type": "integer" + } + } + }, + "tests": [ + { + "description": "matches empty", + "data": { + "": 1 + }, + "valid": true + }, + { + "description": "matches single", + "data": { + "🐲": 1 + }, + "valid": true + }, + { + "description": "matches two", + "data": { + "🐲🐲": 1 + }, + "valid": true + }, + { + "description": "doesn't match one", + "data": { + "🐲": "hello" + }, + "valid": false + }, + { + "description": "doesn't match two", + "data": { + "🐲🐲": "hello" + }, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/optional/unknownKeyword.json b/encoding/jsonschema/testdata/external/tests/draft6/optional/unknownKeyword.json new file mode 100644 index 000000000..e36a2a3e1 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/optional/unknownKeyword.json @@ -0,0 +1,66 @@ +[ + { + "description": "$id inside an unknown keyword is not a real identifier", + "comment": "the implementation must not be confused by an $id in locations we do not know how to parse", + "schema": { + "definitions": { + "id_in_unknown0": { + "not": { + "array_of_schemas": [ + { + "$id": "https://localhost:1234/unknownKeyword/my_identifier.json", + "type": "null" + } + ] + } + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/unknownKeyword/my_identifier.json", + "type": "string" + }, + "id_in_unknown1": { + "not": { + "object_of_schemas": { + "foo": { + "$id": "https://localhost:1234/unknownKeyword/my_identifier.json", + "type": "integer" + } + } + } + } + }, + "anyOf": [ + { + "$ref": "#/definitions/id_in_unknown0" + }, + { + "$ref": "#/definitions/id_in_unknown1" + }, + { + "$ref": "https://localhost:1234/unknownKeyword/my_identifier.json" + } + ] + }, + "skip": "extract error: unsupported constraint \"not\" (and 1 more errors)", + "tests": [ + { + "description": "type matches second anyOf, which has a real schema in it", + "data": "a string", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "type matches non-schema in first anyOf", + "data": null, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "type matches non-schema in third anyOf", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/pattern.json b/encoding/jsonschema/testdata/external/tests/draft6/pattern.json new file mode 100644 index 000000000..b2d1ee318 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/pattern.json @@ -0,0 +1,63 @@ +[ + { + "description": "pattern validation", + "schema": { + "pattern": "^a*$" + }, + "tests": [ + { + "description": "a matching pattern is valid", + "data": "aaa", + "valid": true + }, + { + "description": "a non-matching pattern is invalid", + "data": "abc", + "valid": false + }, + { + "description": "ignores booleans", + "data": true, + "valid": true + }, + { + "description": "ignores integers", + "data": 123, + "valid": true + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true + }, + { + "description": "ignores objects", + "data": {}, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores null", + "data": null, + "valid": true + } + ] + }, + { + "description": "pattern is not anchored", + "schema": { + "pattern": "a+" + }, + "tests": [ + { + "description": "matches a substring", + "data": "xxaayy", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/patternProperties.json b/encoding/jsonschema/testdata/external/tests/draft6/patternProperties.json new file mode 100644 index 000000000..eafb1a7a5 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/patternProperties.json @@ -0,0 +1,228 @@ +[ + { + "description": "patternProperties validates properties matching a regex", + "schema": { + "patternProperties": { + "f.*o": { + "type": "integer" + } + } + }, + "tests": [ + { + "description": "a single valid match is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "multiple valid matches is valid", + "data": { + "foo": 1, + "foooooo": 2 + }, + "valid": true + }, + { + "description": "a single invalid match is invalid", + "data": { + "foo": "bar", + "fooooo": 2 + }, + "valid": false + }, + { + "description": "multiple invalid matches is invalid", + "data": { + "foo": "bar", + "foooooo": "baz" + }, + "valid": false + }, + { + "description": "ignores arrays", + "data": [ + "foo" + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foo", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "multiple simultaneous patternProperties are validated", + "schema": { + "patternProperties": { + "a*": { + "type": "integer" + }, + "aaa*": { + "maximum": 20 + } + } + }, + "tests": [ + { + "description": "a single valid match is valid", + "data": { + "a": 21 + }, + "valid": true + }, + { + "description": "a simultaneous match is valid", + "data": { + "aaaa": 18 + }, + "valid": true + }, + { + "description": "multiple matches is valid", + "data": { + "a": 21, + "aaaa": 18 + }, + "valid": true + }, + { + "description": "an invalid due to one is invalid", + "data": { + "a": "bar" + }, + "valid": false + }, + { + "description": "an invalid due to the other is invalid", + "data": { + "aaaa": 31 + }, + "valid": false + }, + { + "description": "an invalid due to both is invalid", + "data": { + "aaa": "foo", + "aaaa": 31 + }, + "valid": false + } + ] + }, + { + "description": "regexes are not anchored by default and are case sensitive", + "schema": { + "patternProperties": { + "[0-9]{2,}": { + "type": "boolean" + }, + "X_": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "non recognized members are ignored", + "data": { + "answer 1": "42" + }, + "valid": true + }, + { + "description": "recognized members are accounted for", + "data": { + "a31b": null + }, + "valid": false + }, + { + "description": "regexes are case sensitive", + "data": { + "a_x_3": 3 + }, + "valid": true + }, + { + "description": "regexes are case sensitive, 2", + "data": { + "a_X_3": 3 + }, + "valid": false + } + ] + }, + { + "description": "patternProperties with boolean schemas", + "schema": { + "patternProperties": { + "f.*": true, + "b.*": false + } + }, + "tests": [ + { + "description": "object with property matching schema true is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "object with property matching schema false is invalid", + "data": { + "bar": 2 + }, + "valid": false + }, + { + "description": "object with both properties is invalid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false + }, + { + "description": "object with a property matching both true and false is invalid", + "data": { + "foobar": 1 + }, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "patternProperties with null valued instance properties", + "schema": { + "patternProperties": { + "^.*bar$": { + "type": "null" + } + } + }, + "tests": [ + { + "description": "allows null values", + "data": { + "foobar": null + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/properties.json b/encoding/jsonschema/testdata/external/tests/draft6/properties.json new file mode 100644 index 000000000..7c1c86dbb --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/properties.json @@ -0,0 +1,332 @@ +[ + { + "description": "object properties validation", + "schema": { + "properties": { + "foo": { + "type": "integer" + }, + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "both properties present and valid is valid", + "data": { + "foo": 1, + "bar": "baz" + }, + "valid": true + }, + { + "description": "one property invalid is invalid", + "data": { + "foo": 1, + "bar": {} + }, + "valid": false + }, + { + "description": "both properties invalid is invalid", + "data": { + "foo": [], + "bar": {} + }, + "valid": false + }, + { + "description": "doesn't invalidate other properties", + "data": { + "quux": [] + }, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "properties, patternProperties, additionalProperties interaction", + "schema": { + "properties": { + "foo": { + "type": "array", + "maxItems": 3 + }, + "bar": { + "type": "array" + } + }, + "patternProperties": { + "f.o": { + "minItems": 2 + } + }, + "additionalProperties": { + "type": "integer" + } + }, + "tests": [ + { + "description": "property validates property", + "data": { + "foo": [ + 1, + 2 + ] + }, + "valid": true + }, + { + "description": "property invalidates property", + "data": { + "foo": [ + 1, + 2, + 3, + 4 + ] + }, + "valid": false + }, + { + "description": "patternProperty invalidates property", + "data": { + "foo": [] + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "patternProperty validates nonproperty", + "data": { + "fxo": [ + 1, + 2 + ] + }, + "valid": true + }, + { + "description": "patternProperty invalidates nonproperty", + "data": { + "fxo": [] + }, + "valid": false + }, + { + "description": "additionalProperty ignores property", + "data": { + "bar": [] + }, + "valid": true + }, + { + "description": "additionalProperty validates others", + "data": { + "quux": 3 + }, + "valid": true + }, + { + "description": "additionalProperty invalidates others", + "data": { + "quux": "foo" + }, + "valid": false + } + ] + }, + { + "description": "properties with boolean schema", + "schema": { + "properties": { + "foo": true, + "bar": false + } + }, + "tests": [ + { + "description": "no property present is valid", + "data": {}, + "valid": true + }, + { + "description": "only 'true' property present is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "only 'false' property present is invalid", + "data": { + "bar": 2 + }, + "valid": false + }, + { + "description": "both properties present is invalid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false + } + ] + }, + { + "description": "properties with escaped characters", + "schema": { + "properties": { + "foo\nbar": { + "type": "number" + }, + "foo\"bar": { + "type": "number" + }, + "foo\\bar": { + "type": "number" + }, + "foo\rbar": { + "type": "number" + }, + "foo\tbar": { + "type": "number" + }, + "foo\fbar": { + "type": "number" + } + } + }, + "tests": [ + { + "description": "object with all numbers is valid", + "data": { + "foo\nbar": 1, + "foo\"bar": 1, + "foo\\bar": 1, + "foo\rbar": 1, + "foo\tbar": 1, + "foo\fbar": 1 + }, + "valid": true + }, + { + "description": "object with strings is invalid", + "data": { + "foo\nbar": "1", + "foo\"bar": "1", + "foo\\bar": "1", + "foo\rbar": "1", + "foo\tbar": "1", + "foo\fbar": "1" + }, + "valid": false + } + ] + }, + { + "description": "properties with null valued instance properties", + "schema": { + "properties": { + "foo": { + "type": "null" + } + } + }, + "tests": [ + { + "description": "allows null values", + "data": { + "foo": null + }, + "valid": true + } + ] + }, + { + "description": "properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { + "properties": { + "__proto__": { + "type": "number" + }, + "toString": { + "properties": { + "length": { + "type": "string" + } + } + }, + "constructor": { + "type": "number" + } + } + }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": true + }, + { + "description": "__proto__ not valid", + "data": { + "__proto__": "foo" + }, + "valid": false + }, + { + "description": "toString not valid", + "data": { + "toString": { + "length": 37 + } + }, + "valid": false + }, + { + "description": "constructor not valid", + "data": { + "constructor": { + "length": 37 + } + }, + "valid": false + }, + { + "description": "all present and valid", + "data": { + "__proto__": 12, + "toString": { + "length": "foo" + }, + "constructor": 37 + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/propertyNames.json b/encoding/jsonschema/testdata/external/tests/draft6/propertyNames.json new file mode 100644 index 000000000..da1f470dd --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/propertyNames.json @@ -0,0 +1,132 @@ +[ + { + "description": "propertyNames validation", + "schema": { + "propertyNames": { + "maxLength": 3 + } + }, + "skip": "extract error: cannot compile resulting schema: reference \"strings\" in label expression refers to field against which it would be matched:\n generated.cue:4:3\n", + "tests": [ + { + "description": "all property names valid", + "data": { + "f": {}, + "foo": {} + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "some property names invalid", + "data": { + "foo": {}, + "foobar": {} + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "object without properties is valid", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores arrays", + "data": [ + 1, + 2, + 3, + 4 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "propertyNames validation with pattern", + "schema": { + "propertyNames": { + "pattern": "^a+$" + } + }, + "tests": [ + { + "description": "matching property names valid", + "data": { + "a": {}, + "aa": {}, + "aaa": {} + }, + "valid": true + }, + { + "description": "non-matching property name is invalid", + "data": { + "aaA": {} + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "object without properties is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "propertyNames with boolean schema true", + "schema": { + "propertyNames": true + }, + "tests": [ + { + "description": "object with any properties is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "propertyNames with boolean schema false", + "schema": { + "propertyNames": false + }, + "tests": [ + { + "description": "object with any properties is invalid", + "data": { + "foo": 1 + }, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/ref.json b/encoding/jsonschema/testdata/external/tests/draft6/ref.json new file mode 100644 index 000000000..57a558db4 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/ref.json @@ -0,0 +1,1220 @@ +[ + { + "description": "root pointer ref", + "schema": { + "properties": { + "foo": { + "$ref": "#" + } + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "match", + "data": { + "foo": false + }, + "valid": true + }, + { + "description": "recursive match", + "data": { + "foo": { + "foo": false + } + }, + "valid": true + }, + { + "description": "mismatch", + "data": { + "bar": false + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "recursive mismatch", + "data": { + "foo": { + "bar": false + } + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "relative pointer ref to object", + "schema": { + "properties": { + "foo": { + "type": "integer" + }, + "bar": { + "$ref": "#/properties/foo" + } + } + }, + "skip": "extract error: cannot compile resulting schema: bar: reference \"foo\" not found:\n generated.cue:4:10\n", + "tests": [ + { + "description": "match", + "data": { + "bar": 3 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": { + "bar": true + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "relative pointer ref to array", + "schema": { + "items": [ + { + "type": "integer" + }, + { + "$ref": "#/items/0" + } + ] + }, + "skip": "extract error: referring to field \"items\" not yet supported", + "tests": [ + { + "description": "match array", + "data": [ + 1, + 2 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch array", + "data": [ + 1, + "foo" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "escaped pointer ref", + "schema": { + "definitions": { + "tilde~field": { + "type": "integer" + }, + "slash/field": { + "type": "integer" + }, + "percent%field": { + "type": "integer" + } + }, + "properties": { + "tilde": { + "$ref": "#/definitions/tilde~0field" + }, + "slash": { + "$ref": "#/definitions/slash~1field" + }, + "percent": { + "$ref": "#/definitions/percent%25field" + } + } + }, + "tests": [ + { + "description": "slash invalid", + "data": { + "slash": "aoeu" + }, + "valid": false + }, + { + "description": "tilde invalid", + "data": { + "tilde": "aoeu" + }, + "valid": false + }, + { + "description": "percent invalid", + "data": { + "percent": "aoeu" + }, + "valid": false + }, + { + "description": "slash valid", + "data": { + "slash": 123 + }, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values [...] and {slash:123} (mismatched types list and struct):\n generated.cue:2:33\n instance.json:1:1\nconflicting values bool and {slash:123} (mismatched types bool and struct):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and {slash:123} (mismatched types null and struct):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and {slash:123} (mismatched types number and struct):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and {slash:123} (mismatched types string and struct):\n generated.cue:2:24\n instance.json:1:1\nslash: undefined field: \"slash~1field\":\n generated.cue:4:14\n" + }, + { + "description": "tilde valid", + "data": { + "tilde": 123 + }, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values [...] and {tilde:123} (mismatched types list and struct):\n generated.cue:2:33\n instance.json:1:1\nconflicting values bool and {tilde:123} (mismatched types bool and struct):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and {tilde:123} (mismatched types null and struct):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and {tilde:123} (mismatched types number and struct):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and {tilde:123} (mismatched types string and struct):\n generated.cue:2:24\n instance.json:1:1\ntilde: undefined field: \"tilde~0field\":\n generated.cue:3:14\n" + }, + { + "description": "percent valid", + "data": { + "percent": 123 + }, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values [...] and {percent:123} (mismatched types list and struct):\n generated.cue:2:33\n instance.json:1:1\nconflicting values bool and {percent:123} (mismatched types bool and struct):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and {percent:123} (mismatched types null and struct):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and {percent:123} (mismatched types number and struct):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and {percent:123} (mismatched types string and struct):\n generated.cue:2:24\n instance.json:1:1\npercent: undefined field: \"percent%25field\":\n generated.cue:5:14\n" + } + ] + }, + { + "description": "nested refs", + "schema": { + "definitions": { + "a": { + "type": "integer" + }, + "b": { + "$ref": "#/definitions/a" + }, + "c": { + "$ref": "#/definitions/b" + } + }, + "allOf": [ + { + "$ref": "#/definitions/c" + } + ] + }, + "tests": [ + { + "description": "nested ref valid", + "data": 5, + "valid": true + }, + { + "description": "nested ref invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "ref overrides any sibling keywords", + "schema": { + "definitions": { + "reffed": { + "type": "array" + } + }, + "properties": { + "foo": { + "$ref": "#/definitions/reffed", + "maxItems": 2 + } + } + }, + "tests": [ + { + "description": "ref valid", + "data": { + "foo": [] + }, + "valid": true + }, + { + "description": "ref valid, maxItems ignored", + "data": { + "foo": [ + 1, + 2, + 3 + ] + }, + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [...] and {foo:[1,2,3]} (mismatched types list and struct):\n generated.cue:3:33\n instance.json:1:1\nconflicting values bool and {foo:[1,2,3]} (mismatched types bool and struct):\n generated.cue:3:8\n instance.json:1:1\nconflicting values null and {foo:[1,2,3]} (mismatched types null and struct):\n generated.cue:3:1\n instance.json:1:1\nconflicting values number and {foo:[1,2,3]} (mismatched types number and struct):\n generated.cue:3:15\n instance.json:1:1\nconflicting values string and {foo:[1,2,3]} (mismatched types string and struct):\n generated.cue:3:24\n instance.json:1:1\n" + }, + { + "description": "ref invalid", + "data": { + "foo": "string" + }, + "valid": false + } + ] + }, + { + "description": "$ref prevents a sibling $id from changing the base uri", + "schema": { + "$id": "http://localhost:1234/sibling_id/base/", + "definitions": { + "foo": { + "$id": "http://localhost:1234/sibling_id/foo.json", + "type": "string" + }, + "base_foo": { + "$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json", + "$id": "foo.json", + "type": "number" + } + }, + "allOf": [ + { + "$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not http://localhost:1234/sibling_id/foo.json", + "$id": "http://localhost:1234/sibling_id/", + "$ref": "foo.json" + } + ] + }, + "skip": "extract error: constraint \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema# (and 1 more errors)", + "tests": [ + { + "description": "$ref resolves to /definitions/base_foo, data does not validate", + "data": "a", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "$ref resolves to /definitions/base_foo, data validates", + "data": 1, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "remote ref, containing refs itself", + "schema": { + "$ref": "http://json-schema.org/draft-06/schema#" + }, + "skip": "extract error: cannot compile resulting schema: package \"json-schema.org/draft-06/schema\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "remote ref valid", + "data": { + "minLength": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "remote ref invalid", + "data": { + "minLength": -1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "property named $ref that is not a reference", + "schema": { + "properties": { + "$ref": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": { + "$ref": "a" + }, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": { + "$ref": 2 + }, + "valid": false + } + ] + }, + { + "description": "property named $ref, containing an actual $ref", + "schema": { + "properties": { + "$ref": { + "$ref": "#/definitions/is-string" + } + }, + "definitions": { + "is-string": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": { + "$ref": "a" + }, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": { + "$ref": 2 + }, + "valid": false + } + ] + }, + { + "description": "$ref to boolean schema true", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/bool" + } + ], + "definitions": { + "bool": true + } + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "$ref to boolean schema false", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/bool" + } + ], + "definitions": { + "bool": false + } + }, + "skip": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n generated.cue:4:8\n", + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "Recursive references between schemas", + "schema": { + "$id": "http://localhost:1234/tree", + "description": "tree of nodes", + "type": "object", + "properties": { + "meta": { + "type": "string" + }, + "nodes": { + "type": "array", + "items": { + "$ref": "node" + } + } + }, + "required": [ + "meta", + "nodes" + ], + "definitions": { + "node": { + "$id": "http://localhost:1234/node", + "description": "node", + "type": "object", + "properties": { + "value": { + "type": "number" + }, + "subtree": { + "$ref": "tree" + } + }, + "required": [ + "value" + ] + } + } + }, + "skip": "extract error: cannot compile resulting schema: builtin package \"localhost:1234/node\" undefined:\n generated.cue:1:8\n_schema.nodes: reference \"node\" not found:\n generated.cue:8:14\n", + "tests": [ + { + "description": "valid tree", + "data": { + "meta": "root", + "nodes": [ + { + "value": 1, + "subtree": { + "meta": "child", + "nodes": [ + { + "value": 1.1 + }, + { + "value": 1.2 + } + ] + } + }, + { + "value": 2, + "subtree": { + "meta": "child", + "nodes": [ + { + "value": 2.1 + }, + { + "value": 2.2 + } + ] + } + } + ] + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid tree", + "data": { + "meta": "root", + "nodes": [ + { + "value": 1, + "subtree": { + "meta": "child", + "nodes": [ + { + "value": "string is invalid" + }, + { + "value": 1.2 + } + ] + } + }, + { + "value": 2, + "subtree": { + "meta": "child", + "nodes": [ + { + "value": 2.1 + }, + { + "value": 2.2 + } + ] + } + } + ] + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "refs with quote", + "schema": { + "properties": { + "foo\"bar": { + "$ref": "#/definitions/foo%22bar" + } + }, + "definitions": { + "foo\"bar": { + "type": "number" + } + } + }, + "tests": [ + { + "description": "object with numbers is valid", + "data": { + "foo\"bar": 1 + }, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values [...] and {\"foo\\\"bar\":1} (mismatched types list and struct):\n generated.cue:2:33\n instance.json:1:1\nconflicting values bool and {\"foo\\\"bar\":1} (mismatched types bool and struct):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and {\"foo\\\"bar\":1} (mismatched types null and struct):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and {\"foo\\\"bar\":1} (mismatched types number and struct):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and {\"foo\\\"bar\":1} (mismatched types string and struct):\n generated.cue:2:24\n instance.json:1:1\n\"foo\\\"bar\": undefined field: \"foo%22bar\":\n generated.cue:3:17\n" + }, + { + "description": "object with strings is invalid", + "data": { + "foo\"bar": "1" + }, + "valid": false + } + ] + }, + { + "description": "Location-independent identifier", + "schema": { + "allOf": [ + { + "$ref": "#foo" + } + ], + "definitions": { + "A": { + "$id": "#foo", + "type": "integer" + } + } + }, + "skip": "extract error: $id URI may not contain a fragment (and 1 more errors)", + "tests": [ + { + "description": "match", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "Reference an anchor with a non-relative URI", + "schema": { + "$id": "https://example.com/schema-with-anchor", + "allOf": [ + { + "$ref": "https://example.com/schema-with-anchor#foo" + } + ], + "definitions": { + "A": { + "$id": "#foo", + "type": "integer" + } + } + }, + "skip": "extract error: $id URI may not contain a fragment (and 1 more errors)", + "tests": [ + { + "description": "match", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "Location-independent identifier with base URI change in subschema", + "schema": { + "$id": "http://localhost:1234/root", + "allOf": [ + { + "$ref": "http://localhost:1234/nested.json#foo" + } + ], + "definitions": { + "A": { + "$id": "nested.json", + "definitions": { + "B": { + "$id": "#foo", + "type": "integer" + } + } + } + } + }, + "skip": "extract error: $id URI may not contain a fragment (and 1 more errors)", + "tests": [ + { + "description": "match", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "naive replacement of $ref with its destination is not correct", + "schema": { + "definitions": { + "a_string": { + "type": "string" + } + }, + "enum": [ + { + "$ref": "#/definitions/a_string" + } + ] + }, + "tests": [ + { + "description": "do not evaluate the $ref inside the enum, matching any string", + "data": "this is a string", + "valid": false + }, + { + "description": "do not evaluate the $ref inside the enum, definition exact match", + "data": { + "type": "string" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "match the enum exactly", + "data": { + "$ref": "#/definitions/a_string" + }, + "valid": true + } + ] + }, + { + "description": "refs with relative uris and defs", + "schema": { + "$id": "http://example.com/schema-relative-uri-defs1.json", + "properties": { + "foo": { + "$id": "schema-relative-uri-defs2.json", + "definitions": { + "inner": { + "properties": { + "bar": { + "type": "string" + } + } + } + }, + "allOf": [ + { + "$ref": "#/definitions/inner" + } + ] + } + }, + "allOf": [ + { + "$ref": "schema-relative-uri-defs2.json" + } + ] + }, + "skip": "extract error: cannot compile resulting schema: package \"example.com/schema-relative-uri-defs2.json:schema\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "invalid on inner field", + "data": { + "foo": { + "bar": 1 + }, + "bar": "a" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid on outer field", + "data": { + "foo": { + "bar": "a" + }, + "bar": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid on both fields", + "data": { + "foo": { + "bar": "a" + }, + "bar": "a" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "relative refs with absolute uris and defs", + "schema": { + "$id": "http://example.com/schema-refs-absolute-uris-defs1.json", + "properties": { + "foo": { + "$id": "http://example.com/schema-refs-absolute-uris-defs2.json", + "definitions": { + "inner": { + "properties": { + "bar": { + "type": "string" + } + } + } + }, + "allOf": [ + { + "$ref": "#/definitions/inner" + } + ] + } + }, + "allOf": [ + { + "$ref": "schema-refs-absolute-uris-defs2.json" + } + ] + }, + "skip": "extract error: cannot compile resulting schema: package \"example.com/schema-refs-absolute-uris-defs2.json:schema\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "invalid on inner field", + "data": { + "foo": { + "bar": 1 + }, + "bar": "a" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid on outer field", + "data": { + "foo": { + "bar": "a" + }, + "bar": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid on both fields", + "data": { + "foo": { + "bar": "a" + }, + "bar": "a" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "simple URN base URI with $ref via the URN", + "schema": { + "$comment": "URIs do not have to have HTTP(s) schemes", + "$id": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed", + "minimum": 30, + "properties": { + "foo": { + "$ref": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed" + } + } + }, + "skip": "extract error: constraint \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#", + "tests": [ + { + "description": "valid under the URN IDed schema", + "data": { + "foo": 37 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid under the URN IDed schema", + "data": { + "foo": 12 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "simple URN base URI with JSON pointer", + "schema": { + "$comment": "URIs do not have to have HTTP(s) schemes", + "$id": "urn:uuid:deadbeef-1234-00ff-ff00-4321feebdaed", + "properties": { + "foo": { + "$ref": "#/definitions/bar" + } + }, + "definitions": { + "bar": { + "type": "string" + } + } + }, + "skip": "extract error: constraint \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#", + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "URN base URI with NSS", + "schema": { + "$comment": "RFC 8141 §2.2", + "$id": "urn:example:1/406/47452/2", + "properties": { + "foo": { + "$ref": "#/definitions/bar" + } + }, + "definitions": { + "bar": { + "type": "string" + } + } + }, + "skip": "extract error: constraint \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#", + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "URN base URI with r-component", + "schema": { + "$comment": "RFC 8141 §2.3.1", + "$id": "urn:example:foo-bar-baz-qux?+CCResolve:cc=uk", + "properties": { + "foo": { + "$ref": "#/definitions/bar" + } + }, + "definitions": { + "bar": { + "type": "string" + } + } + }, + "skip": "extract error: constraint \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#", + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "URN base URI with q-component", + "schema": { + "$comment": "RFC 8141 §2.3.2", + "$id": "urn:example:weather?=op=map\u0026lat=39.56\u0026lon=-104.85\u0026datetime=1969-07-21T02:56:15Z", + "properties": { + "foo": { + "$ref": "#/definitions/bar" + } + }, + "definitions": { + "bar": { + "type": "string" + } + } + }, + "skip": "extract error: constraint \"$comment\" is not supported in JSON schema version http://json-schema.org/draft-06/schema#", + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "URN base URI with URN and JSON pointer ref", + "schema": { + "$id": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed", + "properties": { + "foo": { + "$ref": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed#/definitions/bar" + } + }, + "definitions": { + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false + } + ] + }, + { + "description": "URN base URI with URN and anchor ref", + "schema": { + "$id": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed", + "properties": { + "foo": { + "$ref": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed#something" + } + }, + "definitions": { + "bar": { + "$id": "#something", + "type": "string" + } + } + }, + "skip": "extract error: anchors (something) not supported (and 1 more errors)", + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ref with absolute-path-reference", + "schema": { + "$id": "http://example.com/ref/absref.json", + "definitions": { + "a": { + "$id": "http://example.com/ref/absref/foobar.json", + "type": "number" + }, + "b": { + "$id": "http://example.com/absref/foobar.json", + "type": "string" + } + }, + "allOf": [ + { + "$ref": "/absref/foobar.json" + } + ] + }, + "skip": "extract error: cannot compile resulting schema: package \"example.com/absref/foobar.json:foobar\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "a string is valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an integer is invalid", + "data": 12, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$id with file URI still resolves pointers - *nix", + "schema": { + "$id": "file:///folder/file.json", + "definitions": { + "foo": { + "type": "number" + } + }, + "allOf": [ + { + "$ref": "#/definitions/foo" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "$id with file URI still resolves pointers - windows", + "schema": { + "$id": "file:///c:/folder/file.json", + "definitions": { + "foo": { + "type": "number" + } + }, + "allOf": [ + { + "$ref": "#/definitions/foo" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "empty tokens in $ref json-pointer", + "schema": { + "definitions": { + "": { + "definitions": { + "": { + "type": "number" + } + } + } + }, + "allOf": [ + { + "$ref": "#/definitions//definitions/" + } + ] + }, + "skip": "extract error: cannot refer to definitions section: must refer to one of its elements", + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/refRemote.json b/encoding/jsonschema/testdata/external/tests/draft6/refRemote.json new file mode 100644 index 000000000..a55382c77 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/refRemote.json @@ -0,0 +1,339 @@ +[ + { + "description": "remote ref", + "schema": { + "$ref": "http://localhost:1234/integer.json" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/integer.json:integer\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "remote ref valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "remote ref invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "fragment within remote ref", + "schema": { + "$ref": "http://localhost:1234/subSchemas.json#/definitions/integer" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/subSchemas.json:subSchemas\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "remote fragment valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "remote fragment invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ref within remote ref", + "schema": { + "$ref": "http://localhost:1234/subSchemas.json#/definitions/refToInteger" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/subSchemas.json:subSchemas\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "ref within ref valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ref within ref invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "base URI change", + "schema": { + "$id": "http://localhost:1234/", + "items": { + "$id": "baseUriChange/", + "items": { + "$ref": "folderInteger.json" + } + } + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/baseUriChange/folderInteger.json:folderInteger\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "base URI change ref valid", + "data": [ + [ + 1 + ] + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "base URI change ref invalid", + "data": [ + [ + "a" + ] + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "base URI change - change folder", + "schema": { + "$id": "http://localhost:1234/scope_change_defs1.json", + "type": "object", + "properties": { + "list": { + "$ref": "#/definitions/baz" + } + }, + "definitions": { + "baz": { + "$id": "baseUriChangeFolder/", + "type": "array", + "items": { + "$ref": "folderInteger.json" + } + } + } + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/baseUriChangeFolder/folderInteger.json:folderInteger\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is valid", + "data": { + "list": [ + 1 + ] + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": { + "list": [ + "a" + ] + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "base URI change - change folder in subschema", + "schema": { + "$id": "http://localhost:1234/scope_change_defs2.json", + "type": "object", + "properties": { + "list": { + "$ref": "#/definitions/baz/definitions/bar" + } + }, + "definitions": { + "baz": { + "$id": "baseUriChangeFolderInSubschema/", + "definitions": { + "bar": { + "type": "array", + "items": { + "$ref": "folderInteger.json" + } + } + } + } + } + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/baseUriChangeFolderInSubschema/folderInteger.json:folderInteger\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is valid", + "data": { + "list": [ + 1 + ] + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": { + "list": [ + "a" + ] + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "root ref in remote ref", + "schema": { + "$id": "http://localhost:1234/object", + "type": "object", + "properties": { + "name": { + "$ref": "name.json#/definitions/orNull" + } + } + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/name.json:name\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "string is valid", + "data": { + "name": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "null is valid", + "data": { + "name": null + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "object is invalid", + "data": { + "name": { + "name": null + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "remote ref with ref to definitions", + "schema": { + "$id": "http://localhost:1234/schema-remote-ref-ref-defs1.json", + "allOf": [ + { + "$ref": "ref-and-definitions.json" + } + ] + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/ref-and-definitions.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "invalid", + "data": { + "bar": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid", + "data": { + "bar": "a" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "Location-independent identifier in remote ref", + "schema": { + "$ref": "http://localhost:1234/locationIndependentIdentifierPre2019.json#/definitions/refToInteger" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/locationIndependentIdentifierPre2019.json:locationIndependentIdentifierPre2019\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "integer is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "retrieved nested refs resolve relative to their URI not $id", + "schema": { + "$id": "http://localhost:1234/some-id", + "properties": { + "name": { + "$ref": "nested/foo-ref-string.json" + } + } + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/nested/foo-ref-string.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is invalid", + "data": { + "name": { + "foo": 1 + } + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is valid", + "data": { + "name": { + "foo": "a" + } + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$ref to $ref finds location-independent $id", + "schema": { + "$ref": "http://localhost:1234/draft6/detached-ref.json#/definitions/foo" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft6/detached-ref.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/required.json b/encoding/jsonschema/testdata/external/tests/draft6/required.json new file mode 100644 index 000000000..5b1eb6ad6 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/required.json @@ -0,0 +1,181 @@ +[ + { + "description": "required validation", + "schema": { + "properties": { + "foo": {}, + "bar": {} + }, + "required": [ + "foo" + ] + }, + "tests": [ + { + "description": "present required property is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "non-present required property is invalid", + "data": { + "bar": 1 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", + "data": "", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "required default validation", + "schema": { + "properties": { + "foo": {} + } + }, + "tests": [ + { + "description": "not required by default", + "data": {}, + "valid": true + } + ] + }, + { + "description": "required with empty array", + "schema": { + "properties": { + "foo": {} + }, + "required": [] + }, + "tests": [ + { + "description": "property not required", + "data": {}, + "valid": true + } + ] + }, + { + "description": "required with escaped characters", + "schema": { + "required": [ + "foo\nbar", + "foo\"bar", + "foo\\bar", + "foo\rbar", + "foo\tbar", + "foo\fbar" + ] + }, + "tests": [ + { + "description": "object with all properties present is valid", + "data": { + "foo\nbar": 1, + "foo\"bar": 1, + "foo\\bar": 1, + "foo\rbar": 1, + "foo\tbar": 1, + "foo\fbar": 1 + }, + "valid": true + }, + { + "description": "object with some properties missing is invalid", + "data": { + "foo\nbar": "1", + "foo\"bar": "1" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "required properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { + "required": [ + "__proto__", + "toString", + "constructor" + ] + }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "__proto__ present", + "data": { + "__proto__": "foo" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "toString present", + "data": { + "toString": { + "length": 37 + } + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "constructor present", + "data": { + "constructor": { + "length": 37 + } + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "all present", + "data": { + "__proto__": 12, + "toString": { + "length": "foo" + }, + "constructor": 37 + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/type.json b/encoding/jsonschema/testdata/external/tests/draft6/type.json new file mode 100644 index 000000000..55f71cdcc --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/type.json @@ -0,0 +1,515 @@ +[ + { + "description": "integer type matches integers", + "schema": { + "type": "integer" + }, + "tests": [ + { + "description": "an integer is an integer", + "data": 1, + "valid": true + }, + { + "description": "a float with zero fractional part is an integer", + "data": 1.0, + "valid": true, + "skip": "conflicting values 1.0 and int (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "a float is not an integer", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an integer", + "data": "foo", + "valid": false + }, + { + "description": "a string is still not an integer, even if it looks like one", + "data": "1", + "valid": false + }, + { + "description": "an object is not an integer", + "data": {}, + "valid": false + }, + { + "description": "an array is not an integer", + "data": [], + "valid": false + }, + { + "description": "a boolean is not an integer", + "data": true, + "valid": false + }, + { + "description": "null is not an integer", + "data": null, + "valid": false + } + ] + }, + { + "description": "number type matches numbers", + "schema": { + "type": "number" + }, + "tests": [ + { + "description": "an integer is a number", + "data": 1, + "valid": true + }, + { + "description": "a float with zero fractional part is a number (and an integer)", + "data": 1.0, + "valid": true + }, + { + "description": "a float is a number", + "data": 1.1, + "valid": true + }, + { + "description": "a string is not a number", + "data": "foo", + "valid": false + }, + { + "description": "a string is still not a number, even if it looks like one", + "data": "1", + "valid": false + }, + { + "description": "an object is not a number", + "data": {}, + "valid": false + }, + { + "description": "an array is not a number", + "data": [], + "valid": false + }, + { + "description": "a boolean is not a number", + "data": true, + "valid": false + }, + { + "description": "null is not a number", + "data": null, + "valid": false + } + ] + }, + { + "description": "string type matches strings", + "schema": { + "type": "string" + }, + "tests": [ + { + "description": "1 is not a string", + "data": 1, + "valid": false + }, + { + "description": "a float is not a string", + "data": 1.1, + "valid": false + }, + { + "description": "a string is a string", + "data": "foo", + "valid": true + }, + { + "description": "a string is still a string, even if it looks like a number", + "data": "1", + "valid": true + }, + { + "description": "an empty string is still a string", + "data": "", + "valid": true + }, + { + "description": "an object is not a string", + "data": {}, + "valid": false + }, + { + "description": "an array is not a string", + "data": [], + "valid": false + }, + { + "description": "a boolean is not a string", + "data": true, + "valid": false + }, + { + "description": "null is not a string", + "data": null, + "valid": false + } + ] + }, + { + "description": "object type matches objects", + "schema": { + "type": "object" + }, + "tests": [ + { + "description": "an integer is not an object", + "data": 1, + "valid": false + }, + { + "description": "a float is not an object", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an object", + "data": "foo", + "valid": false + }, + { + "description": "an object is an object", + "data": {}, + "valid": true + }, + { + "description": "an array is not an object", + "data": [], + "valid": false + }, + { + "description": "a boolean is not an object", + "data": true, + "valid": false + }, + { + "description": "null is not an object", + "data": null, + "valid": false + } + ] + }, + { + "description": "array type matches arrays", + "schema": { + "type": "array" + }, + "tests": [ + { + "description": "an integer is not an array", + "data": 1, + "valid": false + }, + { + "description": "a float is not an array", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an array", + "data": "foo", + "valid": false + }, + { + "description": "an object is not an array", + "data": {}, + "valid": false + }, + { + "description": "an array is an array", + "data": [], + "valid": true + }, + { + "description": "a boolean is not an array", + "data": true, + "valid": false + }, + { + "description": "null is not an array", + "data": null, + "valid": false + } + ] + }, + { + "description": "boolean type matches booleans", + "schema": { + "type": "boolean" + }, + "tests": [ + { + "description": "an integer is not a boolean", + "data": 1, + "valid": false + }, + { + "description": "zero is not a boolean", + "data": 0, + "valid": false + }, + { + "description": "a float is not a boolean", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not a boolean", + "data": "foo", + "valid": false + }, + { + "description": "an empty string is not a boolean", + "data": "", + "valid": false + }, + { + "description": "an object is not a boolean", + "data": {}, + "valid": false + }, + { + "description": "an array is not a boolean", + "data": [], + "valid": false + }, + { + "description": "true is a boolean", + "data": true, + "valid": true + }, + { + "description": "false is a boolean", + "data": false, + "valid": true + }, + { + "description": "null is not a boolean", + "data": null, + "valid": false + } + ] + }, + { + "description": "null type matches only the null object", + "schema": { + "type": "null" + }, + "tests": [ + { + "description": "an integer is not null", + "data": 1, + "valid": false + }, + { + "description": "a float is not null", + "data": 1.1, + "valid": false + }, + { + "description": "zero is not null", + "data": 0, + "valid": false + }, + { + "description": "a string is not null", + "data": "foo", + "valid": false + }, + { + "description": "an empty string is not null", + "data": "", + "valid": false + }, + { + "description": "an object is not null", + "data": {}, + "valid": false + }, + { + "description": "an array is not null", + "data": [], + "valid": false + }, + { + "description": "true is not null", + "data": true, + "valid": false + }, + { + "description": "false is not null", + "data": false, + "valid": false + }, + { + "description": "null is null", + "data": null, + "valid": true + } + ] + }, + { + "description": "multiple types can be specified in an array", + "schema": { + "type": [ + "integer", + "string" + ] + }, + "tests": [ + { + "description": "an integer is valid", + "data": 1, + "valid": true + }, + { + "description": "a string is valid", + "data": "foo", + "valid": true + }, + { + "description": "a float is invalid", + "data": 1.1, + "valid": false + }, + { + "description": "an object is invalid", + "data": {}, + "valid": false + }, + { + "description": "an array is invalid", + "data": [], + "valid": false + }, + { + "description": "a boolean is invalid", + "data": true, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + } + ] + }, + { + "description": "type as array with one item", + "schema": { + "type": [ + "string" + ] + }, + "tests": [ + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "type: array or object", + "schema": { + "type": [ + "array", + "object" + ] + }, + "tests": [ + { + "description": "array is valid", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "object is valid", + "data": { + "foo": 123 + }, + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + } + ] + }, + { + "description": "type: array, object or null", + "schema": { + "type": [ + "array", + "object", + "null" + ] + }, + "tests": [ + { + "description": "array is valid", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "object is valid", + "data": { + "foo": 123 + }, + "valid": true + }, + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft6/uniqueItems.json b/encoding/jsonschema/testdata/external/tests/draft6/uniqueItems.json new file mode 100644 index 000000000..329125d52 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft6/uniqueItems.json @@ -0,0 +1,832 @@ +[ + { + "description": "uniqueItems validation", + "schema": { + "uniqueItems": true + }, + "tests": [ + { + "description": "unique array of integers is valid", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "non-unique array of integers is invalid", + "data": [ + 1, + 1 + ], + "valid": false + }, + { + "description": "non-unique array of more than two integers is invalid", + "data": [ + 1, + 2, + 1 + ], + "valid": false + }, + { + "description": "numbers are unique if mathematically unequal", + "data": [ + 1.0, + 1.00, + 1 + ], + "valid": false, + "skip": "unexpected success" + }, + { + "description": "false is not equal to zero", + "data": [ + 0, + false + ], + "valid": true + }, + { + "description": "true is not equal to one", + "data": [ + 1, + true + ], + "valid": true + }, + { + "description": "unique array of strings is valid", + "data": [ + "foo", + "bar", + "baz" + ], + "valid": true + }, + { + "description": "non-unique array of strings is invalid", + "data": [ + "foo", + "bar", + "foo" + ], + "valid": false + }, + { + "description": "unique array of objects is valid", + "data": [ + { + "foo": "bar" + }, + { + "foo": "baz" + } + ], + "valid": true + }, + { + "description": "non-unique array of objects is invalid", + "data": [ + { + "foo": "bar" + }, + { + "foo": "bar" + } + ], + "valid": false + }, + { + "description": "property order of array of objects is ignored", + "data": [ + { + "foo": "bar", + "bar": "foo" + }, + { + "bar": "foo", + "foo": "bar" + } + ], + "valid": false, + "skip": "unexpected success" + }, + { + "description": "unique array of nested objects is valid", + "data": [ + { + "foo": { + "bar": { + "baz": true + } + } + }, + { + "foo": { + "bar": { + "baz": false + } + } + } + ], + "valid": true + }, + { + "description": "non-unique array of nested objects is invalid", + "data": [ + { + "foo": { + "bar": { + "baz": true + } + } + }, + { + "foo": { + "bar": { + "baz": true + } + } + } + ], + "valid": false + }, + { + "description": "unique array of arrays is valid", + "data": [ + [ + "foo" + ], + [ + "bar" + ] + ], + "valid": true + }, + { + "description": "non-unique array of arrays is invalid", + "data": [ + [ + "foo" + ], + [ + "foo" + ] + ], + "valid": false + }, + { + "description": "non-unique array of more than two arrays is invalid", + "data": [ + [ + "foo" + ], + [ + "bar" + ], + [ + "foo" + ] + ], + "valid": false + }, + { + "description": "1 and true are unique", + "data": [ + 1, + true + ], + "valid": true + }, + { + "description": "0 and false are unique", + "data": [ + 0, + false + ], + "valid": true + }, + { + "description": "[1] and [true] are unique", + "data": [ + [ + 1 + ], + [ + true + ] + ], + "valid": true + }, + { + "description": "[0] and [false] are unique", + "data": [ + [ + 0 + ], + [ + false + ] + ], + "valid": true + }, + { + "description": "nested [1] and [true] are unique", + "data": [ + [ + [ + 1 + ], + "foo" + ], + [ + [ + true + ], + "foo" + ] + ], + "valid": true + }, + { + "description": "nested [0] and [false] are unique", + "data": [ + [ + [ + 0 + ], + "foo" + ], + [ + [ + false + ], + "foo" + ] + ], + "valid": true + }, + { + "description": "unique heterogeneous types are valid", + "data": [ + {}, + [ + 1 + ], + true, + null, + 1, + "{}" + ], + "valid": true + }, + { + "description": "non-unique heterogeneous types are invalid", + "data": [ + {}, + [ + 1 + ], + true, + null, + {}, + 1 + ], + "valid": false + }, + { + "description": "different objects are unique", + "data": [ + { + "a": 1, + "b": 2 + }, + { + "a": 2, + "b": 1 + } + ], + "valid": true + }, + { + "description": "objects are non-unique despite key order", + "data": [ + { + "a": 1, + "b": 2 + }, + { + "b": 2, + "a": 1 + } + ], + "valid": false, + "skip": "unexpected success" + }, + { + "description": "{\"a\": false} and {\"a\": 0} are unique", + "data": [ + { + "a": false + }, + { + "a": 0 + } + ], + "valid": true + }, + { + "description": "{\"a\": true} and {\"a\": 1} are unique", + "data": [ + { + "a": true + }, + { + "a": 1 + } + ], + "valid": true + } + ] + }, + { + "description": "uniqueItems with an array of items", + "schema": { + "items": [ + { + "type": "boolean" + }, + { + "type": "boolean" + } + ], + "uniqueItems": true + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [ + false, + true + ], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [ + true, + false + ], + "valid": true + }, + { + "description": "[false, false] from items array is not valid", + "data": [ + false, + false + ], + "valid": false + }, + { + "description": "[true, true] from items array is not valid", + "data": [ + true, + true + ], + "valid": false + }, + { + "description": "unique array extended from [false, true] is valid", + "data": [ + false, + true, + "foo", + "bar" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [false,true,\"foo\",\"bar\"] and {...} (mismatched types list and struct):\n generated.cue:3:1\n generated.cue:3:69\n instance.json:1:1\nconflicting values bool and [false,true,\"foo\",\"bar\"] (mismatched types bool and list):\n generated.cue:3:8\n instance.json:1:1\nconflicting values null and [false,true,\"foo\",\"bar\"] (mismatched types null and list):\n generated.cue:3:1\n instance.json:1:1\nconflicting values number and [false,true,\"foo\",\"bar\"] (mismatched types number and list):\n generated.cue:3:15\n instance.json:1:1\nconflicting values string and [false,true,\"foo\",\"bar\"] (mismatched types string and list):\n generated.cue:3:24\n instance.json:1:1\n" + }, + { + "description": "unique array extended from [true, false] is valid", + "data": [ + true, + false, + "foo", + "bar" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [true,false,\"foo\",\"bar\"] and {...} (mismatched types list and struct):\n generated.cue:3:1\n generated.cue:3:69\n instance.json:1:1\nconflicting values bool and [true,false,\"foo\",\"bar\"] (mismatched types bool and list):\n generated.cue:3:8\n instance.json:1:1\nconflicting values null and [true,false,\"foo\",\"bar\"] (mismatched types null and list):\n generated.cue:3:1\n instance.json:1:1\nconflicting values number and [true,false,\"foo\",\"bar\"] (mismatched types number and list):\n generated.cue:3:15\n instance.json:1:1\nconflicting values string and [true,false,\"foo\",\"bar\"] (mismatched types string and list):\n generated.cue:3:24\n instance.json:1:1\n" + }, + { + "description": "non-unique array extended from [false, true] is not valid", + "data": [ + false, + true, + "foo", + "foo" + ], + "valid": false + }, + { + "description": "non-unique array extended from [true, false] is not valid", + "data": [ + true, + false, + "foo", + "foo" + ], + "valid": false + } + ] + }, + { + "description": "uniqueItems with an array of items and additionalItems=false", + "schema": { + "items": [ + { + "type": "boolean" + }, + { + "type": "boolean" + } + ], + "uniqueItems": true, + "additionalItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [ + false, + true + ], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [ + true, + false + ], + "valid": true + }, + { + "description": "[false, false] from items array is not valid", + "data": [ + false, + false + ], + "valid": false + }, + { + "description": "[true, true] from items array is not valid", + "data": [ + true, + true + ], + "valid": false + }, + { + "description": "extra items are invalid even if unique", + "data": [ + false, + true, + null + ], + "valid": false + } + ] + }, + { + "description": "uniqueItems=false validation", + "schema": { + "uniqueItems": false + }, + "tests": [ + { + "description": "unique array of integers is valid", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "non-unique array of integers is valid", + "data": [ + 1, + 1 + ], + "valid": true + }, + { + "description": "numbers are unique if mathematically unequal", + "data": [ + 1.0, + 1.00, + 1 + ], + "valid": true + }, + { + "description": "false is not equal to zero", + "data": [ + 0, + false + ], + "valid": true + }, + { + "description": "true is not equal to one", + "data": [ + 1, + true + ], + "valid": true + }, + { + "description": "unique array of objects is valid", + "data": [ + { + "foo": "bar" + }, + { + "foo": "baz" + } + ], + "valid": true + }, + { + "description": "non-unique array of objects is valid", + "data": [ + { + "foo": "bar" + }, + { + "foo": "bar" + } + ], + "valid": true + }, + { + "description": "unique array of nested objects is valid", + "data": [ + { + "foo": { + "bar": { + "baz": true + } + } + }, + { + "foo": { + "bar": { + "baz": false + } + } + } + ], + "valid": true + }, + { + "description": "non-unique array of nested objects is valid", + "data": [ + { + "foo": { + "bar": { + "baz": true + } + } + }, + { + "foo": { + "bar": { + "baz": true + } + } + } + ], + "valid": true + }, + { + "description": "unique array of arrays is valid", + "data": [ + [ + "foo" + ], + [ + "bar" + ] + ], + "valid": true + }, + { + "description": "non-unique array of arrays is valid", + "data": [ + [ + "foo" + ], + [ + "foo" + ] + ], + "valid": true + }, + { + "description": "1 and true are unique", + "data": [ + 1, + true + ], + "valid": true + }, + { + "description": "0 and false are unique", + "data": [ + 0, + false + ], + "valid": true + }, + { + "description": "unique heterogeneous types are valid", + "data": [ + {}, + [ + 1 + ], + true, + null, + 1 + ], + "valid": true + }, + { + "description": "non-unique heterogeneous types are valid", + "data": [ + {}, + [ + 1 + ], + true, + null, + {}, + 1 + ], + "valid": true + } + ] + }, + { + "description": "uniqueItems=false with an array of items", + "schema": { + "items": [ + { + "type": "boolean" + }, + { + "type": "boolean" + } + ], + "uniqueItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [ + false, + true + ], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [ + true, + false + ], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [ + false, + false + ], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [ + true, + true + ], + "valid": true + }, + { + "description": "unique array extended from [false, true] is valid", + "data": [ + false, + true, + "foo", + "bar" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [false,true,\"foo\",\"bar\"] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:48\n instance.json:1:1\nconflicting values bool and [false,true,\"foo\",\"bar\"] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [false,true,\"foo\",\"bar\"] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [false,true,\"foo\",\"bar\"] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [false,true,\"foo\",\"bar\"] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "unique array extended from [true, false] is valid", + "data": [ + true, + false, + "foo", + "bar" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [true,false,\"foo\",\"bar\"] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:48\n instance.json:1:1\nconflicting values bool and [true,false,\"foo\",\"bar\"] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [true,false,\"foo\",\"bar\"] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [true,false,\"foo\",\"bar\"] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [true,false,\"foo\",\"bar\"] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "non-unique array extended from [false, true] is valid", + "data": [ + false, + true, + "foo", + "foo" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [false,true,\"foo\",\"foo\"] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:48\n instance.json:1:1\nconflicting values bool and [false,true,\"foo\",\"foo\"] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [false,true,\"foo\",\"foo\"] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [false,true,\"foo\",\"foo\"] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [false,true,\"foo\",\"foo\"] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "non-unique array extended from [true, false] is valid", + "data": [ + true, + false, + "foo", + "foo" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [true,false,\"foo\",\"foo\"] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:48\n instance.json:1:1\nconflicting values bool and [true,false,\"foo\",\"foo\"] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [true,false,\"foo\",\"foo\"] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [true,false,\"foo\",\"foo\"] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [true,false,\"foo\",\"foo\"] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + } + ] + }, + { + "description": "uniqueItems=false with an array of items and additionalItems=false", + "schema": { + "items": [ + { + "type": "boolean" + }, + { + "type": "boolean" + } + ], + "uniqueItems": false, + "additionalItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [ + false, + true + ], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [ + true, + false + ], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [ + false, + false + ], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [ + true, + true + ], + "valid": true + }, + { + "description": "extra items are invalid even if unique", + "data": [ + false, + true, + null + ], + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/additionalItems.json b/encoding/jsonschema/testdata/external/tests/draft7/additionalItems.json new file mode 100644 index 000000000..c910883ab --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/additionalItems.json @@ -0,0 +1,328 @@ +[ + { + "description": "additionalItems as schema", + "schema": { + "items": [ + {} + ], + "additionalItems": { + "type": "integer" + } + }, + "tests": [ + { + "description": "additional items match schema", + "data": [ + null, + 2, + 3, + 4 + ], + "valid": true + }, + { + "description": "additional items do not match schema", + "data": [ + null, + 2, + 3, + "foo" + ], + "valid": false + } + ] + }, + { + "description": "when items is schema, additionalItems does nothing", + "schema": { + "items": { + "type": "integer" + }, + "additionalItems": { + "type": "string" + } + }, + "tests": [ + { + "description": "valid with a array of type integers", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "invalid with a array of mixed types", + "data": [ + 1, + "2", + "3" + ], + "valid": false + } + ] + }, + { + "description": "when items is schema, boolean additionalItems does nothing", + "schema": { + "items": {}, + "additionalItems": false + }, + "tests": [ + { + "description": "all items match schema", + "data": [ + 1, + 2, + 3, + 4, + 5 + ], + "valid": true + } + ] + }, + { + "description": "array of items with no additionalItems permitted", + "schema": { + "items": [ + {}, + {}, + {} + ], + "additionalItems": false + }, + "tests": [ + { + "description": "empty array", + "data": [], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:45\n instance.json:1:1\nconflicting values bool and [] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "fewer number of items present (1)", + "data": [ + 1 + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:45\n instance.json:1:1\nconflicting values bool and [1] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "fewer number of items present (2)", + "data": [ + 1, + 2 + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1,2] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:45\n instance.json:1:1\nconflicting values bool and [1,2] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,2] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,2] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,2] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "equal number of items present", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "additional items are not permitted", + "data": [ + 1, + 2, + 3, + 4 + ], + "valid": false + } + ] + }, + { + "description": "additionalItems as false without items", + "schema": { + "additionalItems": false + }, + "tests": [ + { + "description": "items defaults to empty schema so everything is valid", + "data": [ + 1, + 2, + 3, + 4, + 5 + ], + "valid": true + }, + { + "description": "ignores non-arrays", + "data": { + "foo": "bar" + }, + "valid": true + } + ] + }, + { + "description": "additionalItems are allowed by default", + "schema": { + "items": [ + { + "type": "integer" + } + ] + }, + "tests": [ + { + "description": "only the first item is validated", + "data": [ + 1, + "foo", + false + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1,\"foo\",false] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:41\n instance.json:1:1\nconflicting values bool and [1,\"foo\",false] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,\"foo\",false] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,\"foo\",false] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,\"foo\",false] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + } + ] + }, + { + "description": "additionalItems does not look in applicators, valid case", + "schema": { + "allOf": [ + { + "items": [ + { + "type": "integer" + } + ] + } + ], + "additionalItems": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "items defined in allOf are not examined", + "data": [ + 1, + null + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1,null] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:41\n instance.json:1:1\nconflicting values bool and [1,null] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,null] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,null] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,null] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + } + ] + }, + { + "description": "additionalItems does not look in applicators, invalid case", + "schema": { + "allOf": [ + { + "items": [ + { + "type": "integer" + }, + { + "type": "string" + } + ] + } + ], + "items": [ + { + "type": "integer" + } + ], + "additionalItems": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "items defined in allOf are not examined", + "data": [ + 1, + "hello" + ], + "valid": false + } + ] + }, + { + "description": "items validation adjusts the starting index for additionalItems", + "schema": { + "items": [ + { + "type": "string" + } + ], + "additionalItems": { + "type": "integer" + } + }, + "tests": [ + { + "description": "valid items", + "data": [ + "x", + 2, + 3 + ], + "valid": true + }, + { + "description": "wrong type of second item", + "data": [ + "x", + "y" + ], + "valid": false + } + ] + }, + { + "description": "additionalItems with heterogeneous array", + "schema": { + "items": [ + {} + ], + "additionalItems": false + }, + "tests": [ + { + "description": "heterogeneous invalid instance", + "data": [ + "foo", + "bar", + 37 + ], + "valid": false + }, + { + "description": "valid instance", + "data": [ + null + ], + "valid": true + } + ] + }, + { + "description": "additionalItems with null instance elements", + "schema": { + "additionalItems": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ + null + ], + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/additionalProperties.json b/encoding/jsonschema/testdata/external/tests/draft7/additionalProperties.json new file mode 100644 index 000000000..dfc0faecb --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/additionalProperties.json @@ -0,0 +1,212 @@ +[ + { + "description": "additionalProperties being false does not allow other properties", + "schema": { + "properties": { + "foo": {}, + "bar": {} + }, + "patternProperties": { + "^v": {} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "no additional properties is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "an additional property is invalid", + "data": { + "foo": 1, + "bar": 2, + "quux": "boom" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ignores arrays", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobarbaz", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "patternProperties are not additional properties", + "data": { + "foo": 1, + "vroom": 2 + }, + "valid": true + } + ] + }, + { + "description": "non-ASCII pattern with additionalProperties", + "schema": { + "patternProperties": { + "^á": {} + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "matching the pattern is valid", + "data": { + "ármányos": 2 + }, + "valid": true + }, + { + "description": "not matching the pattern is invalid", + "data": { + "élmény": 2 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "additionalProperties with schema", + "schema": { + "properties": { + "foo": {}, + "bar": {} + }, + "additionalProperties": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "no additional properties is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "an additional valid property is valid", + "data": { + "foo": 1, + "bar": 2, + "quux": true + }, + "valid": true + }, + { + "description": "an additional invalid property is invalid", + "data": { + "foo": 1, + "bar": 2, + "quux": 12 + }, + "valid": false + } + ] + }, + { + "description": "additionalProperties can exist by itself", + "schema": { + "additionalProperties": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "an additional valid property is valid", + "data": { + "foo": true + }, + "valid": true + }, + { + "description": "an additional invalid property is invalid", + "data": { + "foo": 1 + }, + "valid": false + } + ] + }, + { + "description": "additionalProperties are allowed by default", + "schema": { + "properties": { + "foo": {}, + "bar": {} + } + }, + "tests": [ + { + "description": "additional properties are allowed", + "data": { + "foo": 1, + "bar": 2, + "quux": true + }, + "valid": true + } + ] + }, + { + "description": "additionalProperties does not look in applicators", + "schema": { + "allOf": [ + { + "properties": { + "foo": {} + } + } + ], + "additionalProperties": { + "type": "boolean" + } + }, + "tests": [ + { + "description": "properties defined in allOf are not examined", + "data": { + "foo": 1, + "bar": true + }, + "valid": false + } + ] + }, + { + "description": "additionalProperties with null valued instance properties", + "schema": { + "additionalProperties": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null values", + "data": { + "foo": null + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/allOf.json b/encoding/jsonschema/testdata/external/tests/draft7/allOf.json new file mode 100644 index 000000000..fd03f07b0 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/allOf.json @@ -0,0 +1,384 @@ +[ + { + "description": "allOf", + "schema": { + "allOf": [ + { + "properties": { + "bar": { + "type": "integer" + } + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + } + ] + }, + "tests": [ + { + "description": "allOf", + "data": { + "foo": "baz", + "bar": 2 + }, + "valid": true + }, + { + "description": "mismatch second", + "data": { + "foo": "baz" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "mismatch first", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "wrong type", + "data": { + "foo": "baz", + "bar": "quux" + }, + "valid": false + } + ] + }, + { + "description": "allOf with base schema", + "schema": { + "properties": { + "bar": { + "type": "integer" + } + }, + "required": [ + "bar" + ], + "allOf": [ + { + "properties": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + }, + { + "properties": { + "baz": { + "type": "null" + } + }, + "required": [ + "baz" + ] + } + ] + }, + "tests": [ + { + "description": "valid", + "data": { + "foo": "quux", + "bar": 2, + "baz": null + }, + "valid": true + }, + { + "description": "mismatch base schema", + "data": { + "foo": "quux", + "baz": null + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "mismatch first allOf", + "data": { + "bar": 2, + "baz": null + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "mismatch second allOf", + "data": { + "foo": "quux", + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "mismatch both", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "allOf simple types", + "schema": { + "allOf": [ + { + "maximum": 30 + }, + { + "minimum": 20 + } + ] + }, + "tests": [ + { + "description": "valid", + "data": 25, + "valid": true + }, + { + "description": "mismatch one", + "data": 35, + "valid": false + } + ] + }, + { + "description": "allOf with boolean schemas, all true", + "schema": { + "allOf": [ + true, + true + ] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "allOf with boolean schemas, some false", + "schema": { + "allOf": [ + true, + false + ] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "allOf with boolean schemas, all false", + "schema": { + "allOf": [ + false, + false + ] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "allOf with one empty schema", + "schema": { + "allOf": [ + {} + ] + }, + "tests": [ + { + "description": "any data is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "allOf with two empty schemas", + "schema": { + "allOf": [ + {}, + {} + ] + }, + "tests": [ + { + "description": "any data is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "allOf with the first empty schema", + "schema": { + "allOf": [ + {}, + { + "type": "number" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "allOf with the last empty schema", + "schema": { + "allOf": [ + { + "type": "number" + }, + {} + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "nested allOf, to check validation semantics", + "schema": { + "allOf": [ + { + "allOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "allOf combined with anyOf, oneOf", + "schema": { + "allOf": [ + { + "multipleOf": 2 + } + ], + "anyOf": [ + { + "multipleOf": 3 + } + ], + "oneOf": [ + { + "multipleOf": 5 + } + ] + }, + "tests": [ + { + "description": "allOf: false, anyOf: false, oneOf: false", + "data": 1, + "valid": false + }, + { + "description": "allOf: false, anyOf: false, oneOf: true", + "data": 5, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: false", + "data": 3, + "valid": false + }, + { + "description": "allOf: false, anyOf: true, oneOf: true", + "data": 15, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: false", + "data": 2, + "valid": false + }, + { + "description": "allOf: true, anyOf: false, oneOf: true", + "data": 10, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: false", + "data": 6, + "valid": false + }, + { + "description": "allOf: true, anyOf: true, oneOf: true", + "data": 30, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/anyOf.json b/encoding/jsonschema/testdata/external/tests/draft7/anyOf.json new file mode 100644 index 000000000..22ee3f38d --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/anyOf.json @@ -0,0 +1,226 @@ +[ + { + "description": "anyOf", + "schema": { + "anyOf": [ + { + "type": "integer" + }, + { + "minimum": 2 + } + ] + }, + "tests": [ + { + "description": "first anyOf valid", + "data": 1, + "valid": true + }, + { + "description": "second anyOf valid", + "data": 2.5, + "valid": true + }, + { + "description": "both anyOf valid", + "data": 3, + "valid": true + }, + { + "description": "neither anyOf valid", + "data": 1.5, + "valid": false + } + ] + }, + { + "description": "anyOf with base schema", + "schema": { + "type": "string", + "anyOf": [ + { + "maxLength": 2 + }, + { + "minLength": 4 + } + ] + }, + "tests": [ + { + "description": "mismatch base schema", + "data": 3, + "valid": false + }, + { + "description": "one anyOf valid", + "data": "foobar", + "valid": true + }, + { + "description": "both anyOf invalid", + "data": "foo", + "valid": false + } + ] + }, + { + "description": "anyOf with boolean schemas, all true", + "schema": { + "anyOf": [ + true, + true + ] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "anyOf with boolean schemas, some true", + "schema": { + "anyOf": [ + true, + false + ] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "anyOf with boolean schemas, all false", + "schema": { + "anyOf": [ + false, + false + ] + }, + "skip": "extract error: cannot compile resulting schema: 2 errors in empty disjunction:\nexplicit error (_|_ literal) in source:\n generated.cue:2:1\nexplicit error (_|_ literal) in source:\n generated.cue:2:7\n", + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "anyOf complex types", + "schema": { + "anyOf": [ + { + "properties": { + "bar": { + "type": "integer" + } + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + } + ] + }, + "tests": [ + { + "description": "first anyOf valid (complex)", + "data": { + "bar": 2 + }, + "valid": true + }, + { + "description": "second anyOf valid (complex)", + "data": { + "foo": "baz" + }, + "valid": true + }, + { + "description": "both anyOf valid (complex)", + "data": { + "foo": "baz", + "bar": 2 + }, + "valid": true + }, + { + "description": "neither anyOf valid (complex)", + "data": { + "foo": 2, + "bar": "quux" + }, + "valid": false + } + ] + }, + { + "description": "anyOf with one empty schema", + "schema": { + "anyOf": [ + { + "type": "number" + }, + {} + ] + }, + "tests": [ + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "number is valid", + "data": 123, + "valid": true + } + ] + }, + { + "description": "nested anyOf, to check validation semantics", + "schema": { + "anyOf": [ + { + "anyOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/boolean_schema.json b/encoding/jsonschema/testdata/external/tests/draft7/boolean_schema.json new file mode 100644 index 000000000..dd0e5677f --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/boolean_schema.json @@ -0,0 +1,122 @@ +[ + { + "description": "boolean schema 'true'", + "schema": true, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "boolean true is valid", + "data": true, + "valid": true + }, + { + "description": "boolean false is valid", + "data": false, + "valid": true + }, + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "object is valid", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + }, + { + "description": "array is valid", + "data": [ + "foo" + ], + "valid": true + }, + { + "description": "empty array is valid", + "data": [], + "valid": true + } + ] + }, + { + "description": "boolean schema 'false'", + "schema": false, + "skip": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n generated.cue:2:1\n", + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "null is invalid", + "data": null, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "object is invalid", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "array is invalid", + "data": [ + "foo" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/const.json b/encoding/jsonschema/testdata/external/tests/draft7/const.json new file mode 100644 index 000000000..c677c7e5a --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/const.json @@ -0,0 +1,437 @@ +[ + { + "description": "const validation", + "schema": { + "const": 2 + }, + "tests": [ + { + "description": "same value is valid", + "data": 2, + "valid": true + }, + { + "description": "another value is invalid", + "data": 5, + "valid": false + }, + { + "description": "another type is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "const with object", + "schema": { + "const": { + "foo": "bar", + "baz": "bax" + } + }, + "tests": [ + { + "description": "same object is valid", + "data": { + "foo": "bar", + "baz": "bax" + }, + "valid": true + }, + { + "description": "same object with different property order is valid", + "data": { + "baz": "bax", + "foo": "bar" + }, + "valid": true + }, + { + "description": "another object is invalid", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "another type is invalid", + "data": [ + 1, + 2 + ], + "valid": false + } + ] + }, + { + "description": "const with array", + "schema": { + "const": [ + { + "foo": "bar" + } + ] + }, + "tests": [ + { + "description": "same array is valid", + "data": [ + { + "foo": "bar" + } + ], + "valid": true + }, + { + "description": "another array item is invalid", + "data": [ + 2 + ], + "valid": false + }, + { + "description": "array with additional items is invalid", + "data": [ + 1, + 2, + 3 + ], + "valid": false + } + ] + }, + { + "description": "const with null", + "schema": { + "const": null + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "not null is invalid", + "data": 0, + "valid": false + } + ] + }, + { + "description": "const with false does not match 0", + "schema": { + "const": false + }, + "tests": [ + { + "description": "false is valid", + "data": false, + "valid": true + }, + { + "description": "integer zero is invalid", + "data": 0, + "valid": false + }, + { + "description": "float zero is invalid", + "data": 0.0, + "valid": false + } + ] + }, + { + "description": "const with true does not match 1", + "schema": { + "const": true + }, + "tests": [ + { + "description": "true is valid", + "data": true, + "valid": true + }, + { + "description": "integer one is invalid", + "data": 1, + "valid": false + }, + { + "description": "float one is invalid", + "data": 1.0, + "valid": false + } + ] + }, + { + "description": "const with [false] does not match [0]", + "schema": { + "const": [ + false + ] + }, + "tests": [ + { + "description": "[false] is valid", + "data": [ + false + ], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [ + 0 + ], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [ + 0.0 + ], + "valid": false + } + ] + }, + { + "description": "const with [true] does not match [1]", + "schema": { + "const": [ + true + ] + }, + "tests": [ + { + "description": "[true] is valid", + "data": [ + true + ], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [ + 1 + ], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [ + 1.0 + ], + "valid": false + } + ] + }, + { + "description": "const with {\"a\": false} does not match {\"a\": 0}", + "schema": { + "const": { + "a": false + } + }, + "tests": [ + { + "description": "{\"a\": false} is valid", + "data": { + "a": false + }, + "valid": true + }, + { + "description": "{\"a\": 0} is invalid", + "data": { + "a": 0 + }, + "valid": false + }, + { + "description": "{\"a\": 0.0} is invalid", + "data": { + "a": 0.0 + }, + "valid": false + } + ] + }, + { + "description": "const with {\"a\": true} does not match {\"a\": 1}", + "schema": { + "const": { + "a": true + } + }, + "tests": [ + { + "description": "{\"a\": true} is valid", + "data": { + "a": true + }, + "valid": true + }, + { + "description": "{\"a\": 1} is invalid", + "data": { + "a": 1 + }, + "valid": false + }, + { + "description": "{\"a\": 1.0} is invalid", + "data": { + "a": 1.0 + }, + "valid": false + } + ] + }, + { + "description": "const with 0 does not match other zero-like types", + "schema": { + "const": 0 + }, + "tests": [ + { + "description": "false is invalid", + "data": false, + "valid": false + }, + { + "description": "integer zero is valid", + "data": 0, + "valid": true + }, + { + "description": "float zero is valid", + "data": 0.0, + "valid": true, + "skip": "conflicting values 0.0 and 0 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + }, + { + "description": "empty string is invalid", + "data": "", + "valid": false + } + ] + }, + { + "description": "const with 1 does not match true", + "schema": { + "const": 1 + }, + "tests": [ + { + "description": "true is invalid", + "data": true, + "valid": false + }, + { + "description": "integer one is valid", + "data": 1, + "valid": true + }, + { + "description": "float one is valid", + "data": 1.0, + "valid": true, + "skip": "conflicting values 1.0 and 1 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + } + ] + }, + { + "description": "const with -2.0 matches integer and float types", + "schema": { + "const": -2.0 + }, + "tests": [ + { + "description": "integer -2 is valid", + "data": -2, + "valid": true, + "skip": "conflicting values -2 and -2.0 (mismatched types int and float):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "integer 2 is invalid", + "data": 2, + "valid": false + }, + { + "description": "float -2.0 is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float 2.0 is invalid", + "data": 2.0, + "valid": false + }, + { + "description": "float -2.00001 is invalid", + "data": -2.00001, + "valid": false + } + ] + }, + { + "description": "float and integers are equal up to 64-bit representation limits", + "schema": { + "const": 9007199254740992 + }, + "tests": [ + { + "description": "integer is valid", + "data": 9007199254740992, + "valid": true + }, + { + "description": "integer minus one is invalid", + "data": 9007199254740991, + "valid": false + }, + { + "description": "float is valid", + "data": 9007199254740992.0, + "valid": true, + "skip": "conflicting values 9007199254740992.0 and 9007199254740992 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "float minus one is invalid", + "data": 9007199254740991.0, + "valid": false + } + ] + }, + { + "description": "nul characters in strings", + "schema": { + "const": "hello\u0000there" + }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/contains.json b/encoding/jsonschema/testdata/external/tests/draft7/contains.json new file mode 100644 index 000000000..4082cfd7e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/contains.json @@ -0,0 +1,233 @@ +[ + { + "description": "contains keyword validation", + "schema": { + "contains": { + "minimum": 5 + } + }, + "tests": [ + { + "description": "array with item matching schema (5) is valid", + "data": [ + 3, + 4, + 5 + ], + "valid": true + }, + { + "description": "array with item matching schema (6) is valid", + "data": [ + 3, + 4, + 6 + ], + "valid": true + }, + { + "description": "array with two items matching schema (5, 6) is valid", + "data": [ + 3, + 4, + 5, + 6 + ], + "valid": true + }, + { + "description": "array without items matching schema is invalid", + "data": [ + 2, + 3, + 4 + ], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + }, + { + "description": "not array is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "contains keyword with const keyword", + "schema": { + "contains": { + "const": 5 + } + }, + "tests": [ + { + "description": "array with item 5 is valid", + "data": [ + 3, + 4, + 5 + ], + "valid": true + }, + { + "description": "array with two items 5 is valid", + "data": [ + 3, + 4, + 5, + 5 + ], + "valid": true + }, + { + "description": "array without item 5 is invalid", + "data": [ + 1, + 2, + 3, + 4 + ], + "valid": false + } + ] + }, + { + "description": "contains keyword with boolean schema true", + "schema": { + "contains": true + }, + "tests": [ + { + "description": "any non-empty array is valid", + "data": [ + "foo" + ], + "valid": true + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + } + ] + }, + { + "description": "contains keyword with boolean schema false", + "schema": { + "contains": false + }, + "tests": [ + { + "description": "any non-empty array is invalid", + "data": [ + "foo" + ], + "valid": false + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false + }, + { + "description": "non-arrays are valid", + "data": "contains does not apply to strings", + "valid": true + } + ] + }, + { + "description": "items + contains", + "schema": { + "items": { + "multipleOf": 2 + }, + "contains": { + "multipleOf": 3 + } + }, + "tests": [ + { + "description": "matches items, does not match contains", + "data": [ + 2, + 4, + 8 + ], + "valid": false + }, + { + "description": "does not match items, matches contains", + "data": [ + 3, + 6, + 9 + ], + "valid": false + }, + { + "description": "matches both items and contains", + "data": [ + 6, + 12 + ], + "valid": true + }, + { + "description": "matches neither items nor contains", + "data": [ + 1, + 5 + ], + "valid": false + } + ] + }, + { + "description": "contains with false if subschema", + "schema": { + "contains": { + "if": false, + "else": true + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 1 more errors)", + "tests": [ + { + "description": "any non-empty array is valid", + "data": [ + "foo" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "contains with null instance elements", + "schema": { + "contains": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null items", + "data": [ + null + ], + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/default.json b/encoding/jsonschema/testdata/external/tests/draft7/default.json new file mode 100644 index 000000000..587423d4a --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/default.json @@ -0,0 +1,88 @@ +[ + { + "description": "invalid type for default", + "schema": { + "properties": { + "foo": { + "type": "integer", + "default": [] + } + } + }, + "tests": [ + { + "description": "valid when property is specified", + "data": { + "foo": 13 + }, + "valid": true + }, + { + "description": "still valid when the invalid default is used", + "data": {}, + "valid": true + } + ] + }, + { + "description": "invalid string value for default", + "schema": { + "properties": { + "bar": { + "type": "string", + "minLength": 4, + "default": "bad" + } + } + }, + "tests": [ + { + "description": "valid when property is specified", + "data": { + "bar": "good" + }, + "valid": true + }, + { + "description": "still valid when the invalid default is used", + "data": {}, + "valid": true + } + ] + }, + { + "description": "the default keyword does not do anything if the property is missing", + "schema": { + "type": "object", + "properties": { + "alpha": { + "type": "number", + "maximum": 3, + "default": 5 + } + } + }, + "tests": [ + { + "description": "an explicit property value is checked against maximum (passing)", + "data": { + "alpha": 1 + }, + "valid": true + }, + { + "description": "an explicit property value is checked against maximum (failing)", + "data": { + "alpha": 5 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "missing properties are not filled in with the default", + "data": {}, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/definitions.json b/encoding/jsonschema/testdata/external/tests/draft7/definitions.json new file mode 100644 index 000000000..a2943f74d --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/definitions.json @@ -0,0 +1,35 @@ +[ + { + "description": "validate definition against metaschema", + "schema": { + "$ref": "http://json-schema.org/draft-07/schema#" + }, + "skip": "extract error: cannot compile resulting schema: package \"json-schema.org/draft-07/schema\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "valid definition schema", + "data": { + "definitions": { + "foo": { + "type": "integer" + } + } + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid definition schema", + "data": { + "definitions": { + "foo": { + "type": 1 + } + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/dependencies.json b/encoding/jsonschema/testdata/external/tests/draft7/dependencies.json new file mode 100644 index 000000000..f61780a8b --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/dependencies.json @@ -0,0 +1,380 @@ +[ + { + "description": "dependencies", + "schema": { + "dependencies": { + "bar": [ + "foo" + ] + } + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependant", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "with dependency", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "missing dependency", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ignores arrays", + "data": [ + "bar" + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "dependencies with empty array", + "schema": { + "dependencies": { + "bar": [] + } + }, + "tests": [ + { + "description": "empty object", + "data": {}, + "valid": true + }, + { + "description": "object with one property", + "data": { + "bar": 2 + }, + "valid": true + }, + { + "description": "non-object is valid", + "data": 1, + "valid": true + } + ] + }, + { + "description": "multiple dependencies", + "schema": { + "dependencies": { + "quux": [ + "foo", + "bar" + ] + } + }, + "tests": [ + { + "description": "neither", + "data": {}, + "valid": true + }, + { + "description": "nondependants", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "with dependencies", + "data": { + "foo": 1, + "bar": 2, + "quux": 3 + }, + "valid": true + }, + { + "description": "missing dependency", + "data": { + "foo": 1, + "quux": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "missing other dependency", + "data": { + "bar": 1, + "quux": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "missing both dependencies", + "data": { + "quux": 1 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "multiple dependencies subschema", + "schema": { + "dependencies": { + "bar": { + "properties": { + "foo": { + "type": "integer" + }, + "bar": { + "type": "integer" + } + } + } + } + }, + "tests": [ + { + "description": "valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "no dependency", + "data": { + "foo": "quux" + }, + "valid": true + }, + { + "description": "wrong type", + "data": { + "foo": "quux", + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "wrong type other", + "data": { + "foo": 2, + "bar": "quux" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "wrong type both", + "data": { + "foo": "quux", + "bar": "quux" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "dependencies with boolean subschemas", + "schema": { + "dependencies": { + "foo": true, + "bar": false + } + }, + "tests": [ + { + "description": "object with property having schema true is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "object with property having schema false is invalid", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "object with both properties is invalid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "dependencies with escaped characters", + "schema": { + "dependencies": { + "foo\nbar": [ + "foo\rbar" + ], + "foo\tbar": { + "minProperties": 4 + }, + "foo'bar": { + "required": [ + "foo\"bar" + ] + }, + "foo\"bar": [ + "foo'bar" + ] + } + }, + "tests": [ + { + "description": "valid object 1", + "data": { + "foo\nbar": 1, + "foo\rbar": 2 + }, + "valid": true + }, + { + "description": "valid object 2", + "data": { + "foo\tbar": 1, + "a": 2, + "b": 3, + "c": 4 + }, + "valid": true + }, + { + "description": "valid object 3", + "data": { + "foo'bar": 1, + "foo\"bar": 2 + }, + "valid": true + }, + { + "description": "invalid object 1", + "data": { + "foo\nbar": 1, + "foo": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "invalid object 2", + "data": { + "foo\tbar": 1, + "a": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "invalid object 3", + "data": { + "foo'bar": 1 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "invalid object 4", + "data": { + "foo\"bar": 2 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "dependent subschema incompatible with root", + "schema": { + "properties": { + "foo": {} + }, + "dependencies": { + "foo": { + "properties": { + "bar": {} + }, + "additionalProperties": false + } + } + }, + "tests": [ + { + "description": "matches root", + "data": { + "foo": 1 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "matches dependency", + "data": { + "bar": 1 + }, + "valid": true + }, + { + "description": "matches both", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "no dependency", + "data": { + "baz": 1 + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/enum.json b/encoding/jsonschema/testdata/external/tests/draft7/enum.json new file mode 100644 index 000000000..3158bea80 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/enum.json @@ -0,0 +1,449 @@ +[ + { + "description": "simple enum validation", + "schema": { + "enum": [ + 1, + 2, + 3 + ] + }, + "tests": [ + { + "description": "one of the enum is valid", + "data": 1, + "valid": true + }, + { + "description": "something else is invalid", + "data": 4, + "valid": false + } + ] + }, + { + "description": "heterogeneous enum validation", + "schema": { + "enum": [ + 6, + "foo", + [], + true, + { + "foo": 12 + } + ] + }, + "tests": [ + { + "description": "one of the enum is valid", + "data": [], + "valid": true + }, + { + "description": "something else is invalid", + "data": null, + "valid": false + }, + { + "description": "objects are deep compared", + "data": { + "foo": false + }, + "valid": false + }, + { + "description": "valid object matches", + "data": { + "foo": 12 + }, + "valid": true + }, + { + "description": "extra properties in object is invalid", + "data": { + "foo": 12, + "boo": 42 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "heterogeneous enum-with-null validation", + "schema": { + "enum": [ + 6, + null + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "number is valid", + "data": 6, + "valid": true + }, + { + "description": "something else is invalid", + "data": "test", + "valid": false + } + ] + }, + { + "description": "enums in properties", + "schema": { + "type": "object", + "properties": { + "foo": { + "enum": [ + "foo" + ] + }, + "bar": { + "enum": [ + "bar" + ] + } + }, + "required": [ + "bar" + ] + }, + "tests": [ + { + "description": "both properties are valid", + "data": { + "foo": "foo", + "bar": "bar" + }, + "valid": true + }, + { + "description": "wrong foo value", + "data": { + "foo": "foot", + "bar": "bar" + }, + "valid": false + }, + { + "description": "wrong bar value", + "data": { + "foo": "foo", + "bar": "bart" + }, + "valid": false + }, + { + "description": "missing optional property is valid", + "data": { + "bar": "bar" + }, + "valid": true + }, + { + "description": "missing required property is invalid", + "data": { + "foo": "foo" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "missing all properties is invalid", + "data": {}, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "enum with escaped characters", + "schema": { + "enum": [ + "foo\nbar", + "foo\rbar" + ] + }, + "tests": [ + { + "description": "member 1 is valid", + "data": "foo\nbar", + "valid": true + }, + { + "description": "member 2 is valid", + "data": "foo\rbar", + "valid": true + }, + { + "description": "another string is invalid", + "data": "abc", + "valid": false + } + ] + }, + { + "description": "enum with false does not match 0", + "schema": { + "enum": [ + false + ] + }, + "tests": [ + { + "description": "false is valid", + "data": false, + "valid": true + }, + { + "description": "integer zero is invalid", + "data": 0, + "valid": false + }, + { + "description": "float zero is invalid", + "data": 0.0, + "valid": false + } + ] + }, + { + "description": "enum with [false] does not match [0]", + "schema": { + "enum": [ + [ + false + ] + ] + }, + "tests": [ + { + "description": "[false] is valid", + "data": [ + false + ], + "valid": true + }, + { + "description": "[0] is invalid", + "data": [ + 0 + ], + "valid": false + }, + { + "description": "[0.0] is invalid", + "data": [ + 0.0 + ], + "valid": false + } + ] + }, + { + "description": "enum with true does not match 1", + "schema": { + "enum": [ + true + ] + }, + "tests": [ + { + "description": "true is valid", + "data": true, + "valid": true + }, + { + "description": "integer one is invalid", + "data": 1, + "valid": false + }, + { + "description": "float one is invalid", + "data": 1.0, + "valid": false + } + ] + }, + { + "description": "enum with [true] does not match [1]", + "schema": { + "enum": [ + [ + true + ] + ] + }, + "tests": [ + { + "description": "[true] is valid", + "data": [ + true + ], + "valid": true + }, + { + "description": "[1] is invalid", + "data": [ + 1 + ], + "valid": false + }, + { + "description": "[1.0] is invalid", + "data": [ + 1.0 + ], + "valid": false + } + ] + }, + { + "description": "enum with 0 does not match false", + "schema": { + "enum": [ + 0 + ] + }, + "tests": [ + { + "description": "false is invalid", + "data": false, + "valid": false + }, + { + "description": "integer zero is valid", + "data": 0, + "valid": true + }, + { + "description": "float zero is valid", + "data": 0.0, + "valid": true, + "skip": "conflicting values 0.0 and 0 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + } + ] + }, + { + "description": "enum with [0] does not match [false]", + "schema": { + "enum": [ + [ + 0 + ] + ] + }, + "tests": [ + { + "description": "[false] is invalid", + "data": [ + false + ], + "valid": false + }, + { + "description": "[0] is valid", + "data": [ + 0 + ], + "valid": true + }, + { + "description": "[0.0] is valid", + "data": [ + 0.0 + ], + "valid": true, + "skip": "0: conflicting values 0.0 and 0 (mismatched types float and int):\n generated.cue:2:1\n generated.cue:2:2\n instance.json:1:2\n" + } + ] + }, + { + "description": "enum with 1 does not match true", + "schema": { + "enum": [ + 1 + ] + }, + "tests": [ + { + "description": "true is invalid", + "data": true, + "valid": false + }, + { + "description": "integer one is valid", + "data": 1, + "valid": true + }, + { + "description": "float one is valid", + "data": 1.0, + "valid": true, + "skip": "conflicting values 1.0 and 1 (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + } + ] + }, + { + "description": "enum with [1] does not match [true]", + "schema": { + "enum": [ + [ + 1 + ] + ] + }, + "tests": [ + { + "description": "[true] is invalid", + "data": [ + true + ], + "valid": false + }, + { + "description": "[1] is valid", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "[1.0] is valid", + "data": [ + 1.0 + ], + "valid": true, + "skip": "0: conflicting values 1.0 and 1 (mismatched types float and int):\n generated.cue:2:1\n generated.cue:2:2\n instance.json:1:2\n" + } + ] + }, + { + "description": "nul characters in strings", + "schema": { + "enum": [ + "hello\u0000there" + ] + }, + "tests": [ + { + "description": "match string with nul", + "data": "hello\u0000there", + "valid": true + }, + { + "description": "do not match string lacking nul", + "data": "hellothere", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/exclusiveMaximum.json b/encoding/jsonschema/testdata/external/tests/draft7/exclusiveMaximum.json new file mode 100644 index 000000000..5039e8321 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/exclusiveMaximum.json @@ -0,0 +1,30 @@ +[ + { + "description": "exclusiveMaximum validation", + "schema": { + "exclusiveMaximum": 3.0 + }, + "tests": [ + { + "description": "below the exclusiveMaximum is valid", + "data": 2.2, + "valid": true + }, + { + "description": "boundary point is invalid", + "data": 3.0, + "valid": false + }, + { + "description": "above the exclusiveMaximum is invalid", + "data": 3.5, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/exclusiveMinimum.json b/encoding/jsonschema/testdata/external/tests/draft7/exclusiveMinimum.json new file mode 100644 index 000000000..cb87ce2fc --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/exclusiveMinimum.json @@ -0,0 +1,30 @@ +[ + { + "description": "exclusiveMinimum validation", + "schema": { + "exclusiveMinimum": 1.1 + }, + "tests": [ + { + "description": "above the exclusiveMinimum is valid", + "data": 1.2, + "valid": true + }, + { + "description": "boundary point is invalid", + "data": 1.1, + "valid": false + }, + { + "description": "below the exclusiveMinimum is invalid", + "data": 0.6, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/format.json b/encoding/jsonschema/testdata/external/tests/draft7/format.json new file mode 100644 index 000000000..ff46bbbee --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/format.json @@ -0,0 +1,767 @@ +[ + { + "description": "email format", + "schema": { + "format": "email" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "idn-email format", + "schema": { + "format": "idn-email" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "regex format", + "schema": { + "format": "regex" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ipv4 format", + "schema": { + "format": "ipv4" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ipv6 format", + "schema": { + "format": "ipv6" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "idn-hostname format", + "schema": { + "format": "idn-hostname" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "hostname format", + "schema": { + "format": "hostname" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "date format", + "schema": { + "format": "date" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "date-time format", + "schema": { + "format": "date-time" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "time format", + "schema": { + "format": "time" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "json-pointer format", + "schema": { + "format": "json-pointer" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "relative-json-pointer format", + "schema": { + "format": "relative-json-pointer" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "iri format", + "schema": { + "format": "iri" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "iri-reference format", + "schema": { + "format": "iri-reference" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "uri format", + "schema": { + "format": "uri" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "uri-reference format", + "schema": { + "format": "uri-reference" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "uri-template format", + "schema": { + "format": "uri-template" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/if-then-else.json b/encoding/jsonschema/testdata/external/tests/draft7/if-then-else.json new file mode 100644 index 000000000..890945211 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/if-then-else.json @@ -0,0 +1,308 @@ +[ + { + "description": "ignore if without then or else", + "schema": { + "if": { + "const": 0 + } + }, + "skip": "extract error: unsupported constraint \"if\"", + "tests": [ + { + "description": "valid when valid against lone if", + "data": 0, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid when invalid against lone if", + "data": "hello", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ignore then without if", + "schema": { + "then": { + "const": 0 + } + }, + "skip": "extract error: unsupported constraint \"then\"", + "tests": [ + { + "description": "valid when valid against lone then", + "data": 0, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid when invalid against lone then", + "data": "hello", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ignore else without if", + "schema": { + "else": { + "const": 0 + } + }, + "skip": "extract error: unsupported constraint \"else\"", + "tests": [ + { + "description": "valid when valid against lone else", + "data": 0, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid when invalid against lone else", + "data": "hello", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "if and then without else", + "schema": { + "if": { + "exclusiveMaximum": 0 + }, + "then": { + "minimum": -10 + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 1 more errors)", + "tests": [ + { + "description": "valid through then", + "data": -1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid through then", + "data": -100, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid when if test fails", + "data": 3, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "if and else without then", + "schema": { + "if": { + "exclusiveMaximum": 0 + }, + "else": { + "multipleOf": 2 + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 1 more errors)", + "tests": [ + { + "description": "valid when if test passes", + "data": -1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid through else", + "data": 4, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid through else", + "data": 3, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "validate against correct branch, then vs else", + "schema": { + "if": { + "exclusiveMaximum": 0 + }, + "then": { + "minimum": -10 + }, + "else": { + "multipleOf": 2 + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 2 more errors)", + "tests": [ + { + "description": "valid through then", + "data": -1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid through then", + "data": -100, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid through else", + "data": 4, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid through else", + "data": 3, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "non-interference across combined schemas", + "schema": { + "allOf": [ + { + "if": { + "exclusiveMaximum": 0 + } + }, + { + "then": { + "minimum": -10 + } + }, + { + "else": { + "multipleOf": 2 + } + } + ] + }, + "skip": "extract error: unsupported constraint \"if\" (and 2 more errors)", + "tests": [ + { + "description": "valid, but would have been invalid through then", + "data": -100, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid, but would have been invalid through else", + "data": 3, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "if with boolean schema true", + "schema": { + "if": true, + "then": { + "const": "then" + }, + "else": { + "const": "else" + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 2 more errors)", + "tests": [ + { + "description": "boolean schema true in if always chooses the then path (valid)", + "data": "then", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "boolean schema true in if always chooses the then path (invalid)", + "data": "else", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "if with boolean schema false", + "schema": { + "if": false, + "then": { + "const": "then" + }, + "else": { + "const": "else" + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 2 more errors)", + "tests": [ + { + "description": "boolean schema false in if always chooses the else path (invalid)", + "data": "then", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean schema false in if always chooses the else path (valid)", + "data": "else", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "if appears at the end when serialized (keyword processing sequence)", + "schema": { + "then": { + "const": "yes" + }, + "else": { + "const": "other" + }, + "if": { + "maxLength": 4 + } + }, + "skip": "extract error: unsupported constraint \"then\" (and 2 more errors)", + "tests": [ + { + "description": "yes redirects to then and passes", + "data": "yes", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "other redirects to else and passes", + "data": "other", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "no redirects to then and fails", + "data": "no", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid redirects to else and fails", + "data": "invalid", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/infinite-loop-detection.json b/encoding/jsonschema/testdata/external/tests/draft7/infinite-loop-detection.json new file mode 100644 index 000000000..fe96bb563 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/infinite-loop-detection.json @@ -0,0 +1,42 @@ +[ + { + "description": "evaluating the same schema location against the same data location twice is not a sign of an infinite loop", + "schema": { + "definitions": { + "int": { + "type": "integer" + } + }, + "allOf": [ + { + "properties": { + "foo": { + "$ref": "#/definitions/int" + } + } + }, + { + "additionalProperties": { + "$ref": "#/definitions/int" + } + } + ] + }, + "tests": [ + { + "description": "passing case", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "failing case", + "data": { + "foo": "a string" + }, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/items.json b/encoding/jsonschema/testdata/external/tests/draft7/items.json new file mode 100644 index 000000000..7c45a9562 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/items.json @@ -0,0 +1,555 @@ +[ + { + "description": "a schema given for items", + "schema": { + "items": { + "type": "integer" + } + }, + "tests": [ + { + "description": "valid items", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "wrong type of items", + "data": [ + 1, + "x" + ], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "JavaScript pseudo-array is valid", + "data": { + "0": "invalid", + "length": 1 + }, + "valid": true + } + ] + }, + { + "description": "an array of schemas for items", + "schema": { + "items": [ + { + "type": "integer" + }, + { + "type": "string" + } + ] + }, + "tests": [ + { + "description": "correct types", + "data": [ + 1, + "foo" + ], + "valid": true + }, + { + "description": "wrong types", + "data": [ + "foo", + 1 + ], + "valid": false + }, + { + "description": "incomplete array of items", + "data": [ + 1 + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:49\n instance.json:1:1\nconflicting values bool and [1] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "array with additional items", + "data": [ + 1, + "foo", + true + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1,\"foo\",true] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:49\n instance.json:1:1\nconflicting values bool and [1,\"foo\",true] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1,\"foo\",true] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1,\"foo\",true] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1,\"foo\",true] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "empty array", + "data": [], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:49\n instance.json:1:1\nconflicting values bool and [] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "JavaScript pseudo-array is valid", + "data": { + "0": "invalid", + "1": "valid", + "length": 2 + }, + "valid": true + } + ] + }, + { + "description": "items with boolean schema (true)", + "schema": { + "items": true + }, + "skip": "extract error: value of \"items\" must be an object or array", + "tests": [ + { + "description": "any array is valid", + "data": [ + 1, + "foo", + true + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "empty array is valid", + "data": [], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "items with boolean schema (false)", + "schema": { + "items": false + }, + "skip": "extract error: value of \"items\" must be an object or array", + "tests": [ + { + "description": "any non-empty array is invalid", + "data": [ + 1, + "foo", + true + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty array is valid", + "data": [], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "items with boolean schemas", + "schema": { + "items": [ + true, + false + ] + }, + "tests": [ + { + "description": "array with one item is valid", + "data": [ + 1 + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [1] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:44\n instance.json:1:1\nconflicting values bool and [1] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [1] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [1] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [1] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "array with two items is invalid", + "data": [ + 1, + "foo" + ], + "valid": false + }, + { + "description": "empty array is valid", + "data": [], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:44\n instance.json:1:1\nconflicting values bool and [] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + } + ] + }, + { + "description": "items and subitems", + "schema": { + "definitions": { + "item": { + "type": "array", + "additionalItems": false, + "items": [ + { + "$ref": "#/definitions/sub-item" + }, + { + "$ref": "#/definitions/sub-item" + } + ] + }, + "sub-item": { + "type": "object", + "required": [ + "foo" + ] + } + }, + "type": "array", + "additionalItems": false, + "items": [ + { + "$ref": "#/definitions/item" + }, + { + "$ref": "#/definitions/item" + }, + { + "$ref": "#/definitions/item" + } + ] + }, + "tests": [ + { + "description": "valid items", + "data": [ + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": true + }, + { + "description": "too many items", + "data": [ + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": false + }, + { + "description": "too many sub-items", + "data": [ + [ + { + "foo": null + }, + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": false + }, + { + "description": "wrong item", + "data": [ + { + "foo": null + }, + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": false + }, + { + "description": "wrong sub-item", + "data": [ + [ + {}, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ], + [ + { + "foo": null + }, + { + "foo": null + } + ] + ], + "valid": false, + "skip": "unexpected success" + }, + { + "description": "fewer items is valid", + "data": [ + [ + { + "foo": null + } + ], + [ + { + "foo": null + } + ] + ], + "valid": true, + "skip": "incompatible list lengths (2 and 3)\n" + } + ] + }, + { + "description": "nested items", + "schema": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "number" + } + } + } + } + }, + "tests": [ + { + "description": "valid nested array", + "data": [ + [ + [ + [ + 1 + ] + ], + [ + [ + 2 + ], + [ + 3 + ] + ] + ], + [ + [ + [ + 4 + ], + [ + 5 + ], + [ + 6 + ] + ] + ] + ], + "valid": true + }, + { + "description": "nested array with invalid type", + "data": [ + [ + [ + [ + "1" + ] + ], + [ + [ + 2 + ], + [ + 3 + ] + ] + ], + [ + [ + [ + 4 + ], + [ + 5 + ], + [ + 6 + ] + ] + ] + ], + "valid": false + }, + { + "description": "not deep enough", + "data": [ + [ + [ + 1 + ], + [ + 2 + ], + [ + 3 + ] + ], + [ + [ + 4 + ], + [ + 5 + ], + [ + 6 + ] + ] + ], + "valid": false + } + ] + }, + { + "description": "single-form items with null instance elements", + "schema": { + "items": { + "type": "null" + } + }, + "tests": [ + { + "description": "allows null elements", + "data": [ + null + ], + "valid": true + } + ] + }, + { + "description": "array-form items with null instance elements", + "schema": { + "items": [ + { + "type": "null" + } + ] + }, + "tests": [ + { + "description": "allows null elements", + "data": [ + null + ], + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/maxItems.json b/encoding/jsonschema/testdata/external/tests/draft7/maxItems.json new file mode 100644 index 000000000..cb304e672 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/maxItems.json @@ -0,0 +1,66 @@ +[ + { + "description": "maxItems validation", + "schema": { + "maxItems": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "exact length is valid", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "too long is invalid", + "data": [ + 1, + 2, + 3 + ], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": "foobar", + "valid": true + } + ] + }, + { + "description": "maxItems validation with a decimal", + "schema": { + "maxItems": 2.0 + }, + "skip": "extract error: invalid uint", + "tests": [ + { + "description": "shorter is valid", + "data": [ + 1 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too long is invalid", + "data": [ + 1, + 2, + 3 + ], + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/maxLength.json b/encoding/jsonschema/testdata/external/tests/draft7/maxLength.json new file mode 100644 index 000000000..357b57159 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/maxLength.json @@ -0,0 +1,54 @@ +[ + { + "description": "maxLength validation", + "schema": { + "maxLength": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true + }, + { + "description": "exact length is valid", + "data": "fo", + "valid": true + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + }, + { + "description": "two graphemes is long enough", + "data": "💩💩", + "valid": true + } + ] + }, + { + "description": "maxLength validation with a decimal", + "schema": { + "maxLength": 2.0 + }, + "tests": [ + { + "description": "shorter is valid", + "data": "f", + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values \"f\" and [...] (mismatched types string and list):\n generated.cue:3:1\n generated.cue:3:48\n instance.json:1:1\nconflicting values \"f\" and bool (mismatched types string and bool):\n generated.cue:3:1\n generated.cue:3:8\n instance.json:1:1\nconflicting values \"f\" and null (mismatched types string and null):\n generated.cue:3:1\n instance.json:1:1\nconflicting values \"f\" and number (mismatched types string and number):\n generated.cue:3:1\n generated.cue:3:15\n instance.json:1:1\nconflicting values \"f\" and {...} (mismatched types string and struct):\n generated.cue:3:1\n generated.cue:3:56\n instance.json:1:1\ncannot use 2.0 (type float) as int in argument 2 to strings.MaxRunes:\n generated.cue:3:41\n" + }, + { + "description": "too long is invalid", + "data": "foo", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/maxProperties.json b/encoding/jsonschema/testdata/external/tests/draft7/maxProperties.json new file mode 100644 index 000000000..f6b8aba8b --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/maxProperties.json @@ -0,0 +1,100 @@ +[ + { + "description": "maxProperties validation", + "schema": { + "maxProperties": 2 + }, + "tests": [ + { + "description": "shorter is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "exact length is valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "too long is invalid", + "data": { + "foo": 1, + "bar": 2, + "baz": 3 + }, + "valid": false + }, + { + "description": "ignores arrays", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "maxProperties validation with a decimal", + "schema": { + "maxProperties": 2.0 + }, + "skip": "extract error: invalid uint", + "tests": [ + { + "description": "shorter is valid", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too long is invalid", + "data": { + "foo": 1, + "bar": 2, + "baz": 3 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "maxProperties = 0 means the object is empty", + "schema": { + "maxProperties": 0 + }, + "tests": [ + { + "description": "no properties is valid", + "data": {}, + "valid": true + }, + { + "description": "one property is invalid", + "data": { + "foo": 1 + }, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/maximum.json b/encoding/jsonschema/testdata/external/tests/draft7/maximum.json new file mode 100644 index 000000000..c1b0fe5cb --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/maximum.json @@ -0,0 +1,58 @@ +[ + { + "description": "maximum validation", + "schema": { + "maximum": 3.0 + }, + "tests": [ + { + "description": "below the maximum is valid", + "data": 2.6, + "valid": true + }, + { + "description": "boundary point is valid", + "data": 3.0, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 3.5, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + }, + { + "description": "maximum validation with unsigned integer", + "schema": { + "maximum": 300 + }, + "tests": [ + { + "description": "below the maximum is invalid", + "data": 299.97, + "valid": true + }, + { + "description": "boundary point integer is valid", + "data": 300, + "valid": true + }, + { + "description": "boundary point float is valid", + "data": 300.00, + "valid": true + }, + { + "description": "above the maximum is invalid", + "data": 300.5, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/minItems.json b/encoding/jsonschema/testdata/external/tests/draft7/minItems.json new file mode 100644 index 000000000..7264e5c61 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/minItems.json @@ -0,0 +1,59 @@ +[ + { + "description": "minItems validation", + "schema": { + "minItems": 1 + }, + "tests": [ + { + "description": "longer is valid", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "exact length is valid", + "data": [ + 1 + ], + "valid": true + }, + { + "description": "too short is invalid", + "data": [], + "valid": false + }, + { + "description": "ignores non-arrays", + "data": "", + "valid": true + } + ] + }, + { + "description": "minItems validation with a decimal", + "schema": { + "minItems": 1.0 + }, + "skip": "extract error: invalid uint", + "tests": [ + { + "description": "longer is valid", + "data": [ + 1, + 2 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too short is invalid", + "data": [], + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/minLength.json b/encoding/jsonschema/testdata/external/tests/draft7/minLength.json new file mode 100644 index 000000000..57f561be4 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/minLength.json @@ -0,0 +1,54 @@ +[ + { + "description": "minLength validation", + "schema": { + "minLength": 2 + }, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true + }, + { + "description": "exact length is valid", + "data": "fo", + "valid": true + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + }, + { + "description": "ignores non-strings", + "data": 1, + "valid": true + }, + { + "description": "one grapheme is not long enough", + "data": "💩", + "valid": false + } + ] + }, + { + "description": "minLength validation with a decimal", + "schema": { + "minLength": 2.0 + }, + "tests": [ + { + "description": "longer is valid", + "data": "foo", + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values \"foo\" and [...] (mismatched types string and list):\n generated.cue:3:1\n generated.cue:3:48\n instance.json:1:1\nconflicting values \"foo\" and bool (mismatched types string and bool):\n generated.cue:3:1\n generated.cue:3:8\n instance.json:1:1\nconflicting values \"foo\" and null (mismatched types string and null):\n generated.cue:3:1\n instance.json:1:1\nconflicting values \"foo\" and number (mismatched types string and number):\n generated.cue:3:1\n generated.cue:3:15\n instance.json:1:1\nconflicting values \"foo\" and {...} (mismatched types string and struct):\n generated.cue:3:1\n generated.cue:3:56\n instance.json:1:1\ncannot use 2.0 (type float) as int in argument 2 to strings.MinRunes:\n generated.cue:3:41\n" + }, + { + "description": "too short is invalid", + "data": "f", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/minProperties.json b/encoding/jsonschema/testdata/external/tests/draft7/minProperties.json new file mode 100644 index 000000000..070c35488 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/minProperties.json @@ -0,0 +1,76 @@ +[ + { + "description": "minProperties validation", + "schema": { + "minProperties": 1 + }, + "skip": "extract error: unsupported constraint \"minProperties\"", + "tests": [ + { + "description": "longer is valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "exact length is valid", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ignores arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores strings", + "data": "", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "minProperties validation with a decimal", + "schema": { + "minProperties": 1.0 + }, + "skip": "extract error: unsupported constraint \"minProperties\"", + "tests": [ + { + "description": "longer is valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "too short is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/minimum.json b/encoding/jsonschema/testdata/external/tests/draft7/minimum.json new file mode 100644 index 000000000..8c1194093 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/minimum.json @@ -0,0 +1,73 @@ +[ + { + "description": "minimum validation", + "schema": { + "minimum": 1.1 + }, + "tests": [ + { + "description": "above the minimum is valid", + "data": 2.6, + "valid": true + }, + { + "description": "boundary point is valid", + "data": 1.1, + "valid": true + }, + { + "description": "below the minimum is invalid", + "data": 0.6, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + }, + { + "description": "minimum validation with signed integer", + "schema": { + "minimum": -2 + }, + "tests": [ + { + "description": "negative above the minimum is valid", + "data": -1, + "valid": true + }, + { + "description": "positive above the minimum is valid", + "data": 0, + "valid": true + }, + { + "description": "boundary point is valid", + "data": -2, + "valid": true + }, + { + "description": "boundary point with float is valid", + "data": -2.0, + "valid": true + }, + { + "description": "float below the minimum is invalid", + "data": -2.0001, + "valid": false + }, + { + "description": "int below the minimum is invalid", + "data": -3, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "x", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/multipleOf.json b/encoding/jsonschema/testdata/external/tests/draft7/multipleOf.json new file mode 100644 index 000000000..bfd82eda5 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/multipleOf.json @@ -0,0 +1,94 @@ +[ + { + "description": "by int", + "schema": { + "multipleOf": 2 + }, + "tests": [ + { + "description": "int by int", + "data": 10, + "valid": true + }, + { + "description": "int by int fail", + "data": 7, + "valid": false + }, + { + "description": "ignores non-numbers", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "by number", + "schema": { + "multipleOf": 1.5 + }, + "tests": [ + { + "description": "zero is multiple of anything", + "data": 0, + "valid": true + }, + { + "description": "4.5 is multiple of 1.5", + "data": 4.5, + "valid": true + }, + { + "description": "35 is not multiple of 1.5", + "data": 35, + "valid": false + } + ] + }, + { + "description": "by small number", + "schema": { + "multipleOf": 0.0001 + }, + "tests": [ + { + "description": "0.0075 is multiple of 0.0001", + "data": 0.0075, + "valid": true + }, + { + "description": "0.00751 is not multiple of 0.0001", + "data": 0.00751, + "valid": false + } + ] + }, + { + "description": "float division = inf", + "schema": { + "type": "integer", + "multipleOf": 0.123456789 + }, + "tests": [ + { + "description": "always invalid, but naive implementations may raise an overflow error", + "data": 1E+308, + "valid": false + } + ] + }, + { + "description": "small multiple of large integer", + "schema": { + "type": "integer", + "multipleOf": 1E-8 + }, + "tests": [ + { + "description": "any integer is a multiple of 1e-8", + "data": 12391239123, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/not.json b/encoding/jsonschema/testdata/external/tests/draft7/not.json new file mode 100644 index 000000000..8a575db2e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/not.json @@ -0,0 +1,344 @@ +[ + { + "description": "not", + "schema": { + "not": { + "type": "integer" + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "allowed", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "disallowed", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "not multiple types", + "schema": { + "not": { + "type": [ + "integer", + "boolean" + ] + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "other mismatch", + "data": true, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "not more complex schema", + "schema": { + "not": { + "type": "object", + "properties": { + "foo": { + "type": "string" + } + } + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "match", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "other match", + "data": { + "foo": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "forbidden property", + "schema": { + "properties": { + "foo": { + "not": {} + } + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "property present", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "property absent", + "data": { + "bar": 1, + "baz": 2 + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "forbid everything with empty schema", + "schema": { + "not": {} + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "null is invalid", + "data": null, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "object is invalid", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "array is invalid", + "data": [ + "foo" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "forbid everything with boolean schema true", + "schema": { + "not": true + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "number is invalid", + "data": 1, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean true is invalid", + "data": true, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "boolean false is invalid", + "data": false, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "null is invalid", + "data": null, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "object is invalid", + "data": { + "foo": "bar" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty object is invalid", + "data": {}, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "array is invalid", + "data": [ + "foo" + ], + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty array is invalid", + "data": [], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "allow everything with boolean schema false", + "schema": { + "not": false + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string is valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "boolean true is valid", + "data": true, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "boolean false is valid", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "null is valid", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "object is valid", + "data": { + "foo": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "array is valid", + "data": [ + "foo" + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "empty array is valid", + "data": [], + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "double negation", + "schema": { + "not": { + "not": {} + } + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/oneOf.json b/encoding/jsonschema/testdata/external/tests/draft7/oneOf.json new file mode 100644 index 000000000..a76dae91b --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/oneOf.json @@ -0,0 +1,364 @@ +[ + { + "description": "oneOf", + "schema": { + "oneOf": [ + { + "type": "integer" + }, + { + "minimum": 2 + } + ] + }, + "tests": [ + { + "description": "first oneOf valid", + "data": 1, + "valid": true + }, + { + "description": "second oneOf valid", + "data": 2.5, + "valid": true + }, + { + "description": "both oneOf valid", + "data": 3, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "neither oneOf valid", + "data": 1.5, + "valid": false + } + ] + }, + { + "description": "oneOf with base schema", + "schema": { + "type": "string", + "oneOf": [ + { + "minLength": 2 + }, + { + "maxLength": 4 + } + ] + }, + "tests": [ + { + "description": "mismatch base schema", + "data": 3, + "valid": false + }, + { + "description": "one oneOf valid", + "data": "foobar", + "valid": true + }, + { + "description": "both oneOf valid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with boolean schemas, all true", + "schema": { + "oneOf": [ + true, + true, + true + ] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with boolean schemas, one true", + "schema": { + "oneOf": [ + true, + false, + false + ] + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "oneOf with boolean schemas, more than one true", + "schema": { + "oneOf": [ + true, + true, + false + ] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with boolean schemas, all false", + "schema": { + "oneOf": [ + false, + false, + false + ] + }, + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf complex types", + "schema": { + "oneOf": [ + { + "properties": { + "bar": { + "type": "integer" + } + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + } + ] + }, + "tests": [ + { + "description": "first oneOf valid (complex)", + "data": { + "bar": 2 + }, + "valid": true + }, + { + "description": "second oneOf valid (complex)", + "data": { + "foo": "baz" + }, + "valid": true + }, + { + "description": "both oneOf valid (complex)", + "data": { + "foo": "baz", + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "neither oneOf valid (complex)", + "data": { + "foo": 2, + "bar": "quux" + }, + "valid": false + } + ] + }, + { + "description": "oneOf with empty schema", + "schema": { + "oneOf": [ + { + "type": "number" + }, + {} + ] + }, + "tests": [ + { + "description": "one valid - valid", + "data": "foo", + "valid": true + }, + { + "description": "both valid - invalid", + "data": 123, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with required", + "schema": { + "type": "object", + "oneOf": [ + { + "required": [ + "foo", + "bar" + ] + }, + { + "required": [ + "foo", + "baz" + ] + } + ] + }, + "tests": [ + { + "description": "both invalid - invalid", + "data": { + "bar": 2 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "first valid - valid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": true + }, + { + "description": "second valid - valid", + "data": { + "foo": 1, + "baz": 3 + }, + "valid": true + }, + { + "description": "both valid - invalid", + "data": { + "foo": 1, + "bar": 2, + "baz": 3 + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "oneOf with missing optional property", + "schema": { + "oneOf": [ + { + "properties": { + "bar": true, + "baz": true + }, + "required": [ + "bar" + ] + }, + { + "properties": { + "foo": true + }, + "required": [ + "foo" + ] + } + ] + }, + "tests": [ + { + "description": "first oneOf valid", + "data": { + "bar": 8 + }, + "valid": true + }, + { + "description": "second oneOf valid", + "data": { + "foo": "foo" + }, + "valid": true + }, + { + "description": "both oneOf valid", + "data": { + "foo": "foo", + "bar": 8 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "neither oneOf valid", + "data": { + "baz": "quux" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "nested oneOf, to check validation semantics", + "schema": { + "oneOf": [ + { + "oneOf": [ + { + "type": "null" + } + ] + } + ] + }, + "tests": [ + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "anything non-null is invalid", + "data": 123, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/bignum.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/bignum.json new file mode 100644 index 000000000..2310db3d6 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/bignum.json @@ -0,0 +1,103 @@ +[ + { + "description": "integer", + "schema": { + "type": "integer" + }, + "tests": [ + { + "description": "a bignum is an integer", + "data": 12345678910111213141516171819202122232425262728293031, + "valid": true + }, + { + "description": "a negative bignum is an integer", + "data": -12345678910111213141516171819202122232425262728293031, + "valid": true + } + ] + }, + { + "description": "number", + "schema": { + "type": "number" + }, + "tests": [ + { + "description": "a bignum is a number", + "data": 98249283749234923498293171823948729348710298301928331, + "valid": true + }, + { + "description": "a negative bignum is a number", + "data": -98249283749234923498293171823948729348710298301928331, + "valid": true + } + ] + }, + { + "description": "string", + "schema": { + "type": "string" + }, + "tests": [ + { + "description": "a bignum is not a string", + "data": 98249283749234923498293171823948729348710298301928331, + "valid": false + } + ] + }, + { + "description": "maximum integer comparison", + "schema": { + "maximum": 18446744073709551615 + }, + "tests": [ + { + "description": "comparison works for high numbers", + "data": 18446744073709551600, + "valid": true + } + ] + }, + { + "description": "float comparison with high precision", + "schema": { + "exclusiveMaximum": 972783798187987123879878123.18878137 + }, + "tests": [ + { + "description": "comparison works for high numbers", + "data": 972783798187987123879878123.188781371, + "valid": false + } + ] + }, + { + "description": "minimum integer comparison", + "schema": { + "minimum": -18446744073709551615 + }, + "tests": [ + { + "description": "comparison works for very negative numbers", + "data": -18446744073709551600, + "valid": true + } + ] + }, + { + "description": "float comparison with high precision on negative numbers", + "schema": { + "exclusiveMinimum": -972783798187987123879878123.18878137 + }, + "tests": [ + { + "description": "comparison works for very negative numbers", + "data": -972783798187987123879878123.188781371, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/content.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/content.json new file mode 100644 index 000000000..604eec6f5 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/content.json @@ -0,0 +1,81 @@ +[ + { + "description": "validation of string-encoded content based on media type", + "schema": { + "contentMediaType": "application/json" + }, + "tests": [ + { + "description": "a valid JSON document", + "data": "{\"foo\": \"bar\"}", + "valid": true + }, + { + "description": "an invalid JSON document", + "data": "{:}", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + }, + { + "description": "validation of binary string-encoding", + "schema": { + "contentEncoding": "base64" + }, + "tests": [ + { + "description": "a valid base64 string", + "data": "eyJmb28iOiAiYmFyIn0K", + "valid": true + }, + { + "description": "an invalid base64 string (% is not a valid character)", + "data": "eyJmb28iOi%iYmFyIn0K", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + }, + { + "description": "validation of binary-encoded media type documents", + "schema": { + "contentMediaType": "application/json", + "contentEncoding": "base64" + }, + "tests": [ + { + "description": "a valid base64-encoded JSON document", + "data": "eyJmb28iOiAiYmFyIn0K", + "valid": true + }, + { + "description": "a validly-encoded invalid JSON document", + "data": "ezp9Cg==", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "an invalid base64 string that is valid JSON", + "data": "{}", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ignores non-strings", + "data": 100, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/cross-draft.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/cross-draft.json new file mode 100644 index 000000000..cac4c4827 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/cross-draft.json @@ -0,0 +1,39 @@ +[ + { + "description": "refs to future drafts are processed as future drafts", + "schema": { + "type": "object", + "allOf": [ + { + "properties": { + "foo": true + } + }, + { + "$ref": "http://localhost:1234/draft2019-09/dependentRequired.json" + } + ] + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft2019-09/dependentRequired.json:dependentRequired\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "missing bar is invalid", + "comment": "if the implementation is not processing the $ref as a 2019-09 schema, this test will fail", + "data": { + "foo": "any value" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "present bar is valid", + "data": { + "foo": "any value", + "bar": "also any value" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/ecmascript-regex.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/ecmascript-regex.json new file mode 100644 index 000000000..95600268d --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/ecmascript-regex.json @@ -0,0 +1,630 @@ +[ + { + "description": "ECMA 262 regex $ does not match trailing newline", + "schema": { + "type": "string", + "pattern": "^abc$" + }, + "tests": [ + { + "description": "matches in Python, but not in ECMA 262", + "data": "abc\\n", + "valid": false + }, + { + "description": "matches", + "data": "abc", + "valid": true + } + ] + }, + { + "description": "ECMA 262 regex converts \\t to horizontal tab", + "schema": { + "type": "string", + "pattern": "^\\t$" + }, + "tests": [ + { + "description": "does not match", + "data": "\\t", + "valid": false + }, + { + "description": "matches", + "data": "\t", + "valid": true + } + ] + }, + { + "description": "ECMA 262 regex escapes control codes with \\c and upper letter", + "schema": { + "type": "string", + "pattern": "^\\cC$" + }, + "skip": "extract error: unsupported regexp: error parsing regexp: invalid escape sequence: `\\c`", + "tests": [ + { + "description": "does not match", + "data": "\\cC", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "matches", + "data": "\u0003", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ECMA 262 regex escapes control codes with \\c and lower letter", + "schema": { + "type": "string", + "pattern": "^\\cc$" + }, + "skip": "extract error: unsupported regexp: error parsing regexp: invalid escape sequence: `\\c`", + "tests": [ + { + "description": "does not match", + "data": "\\cc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "matches", + "data": "\u0003", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ECMA 262 \\d matches ascii digits only", + "schema": { + "type": "string", + "pattern": "^\\d$" + }, + "tests": [ + { + "description": "ASCII zero matches", + "data": "0", + "valid": true + }, + { + "description": "NKO DIGIT ZERO does not match (unlike e.g. Python)", + "data": "߀", + "valid": false + }, + { + "description": "NKO DIGIT ZERO (as \\u escape) does not match", + "data": "߀", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\D matches everything but ascii digits", + "schema": { + "type": "string", + "pattern": "^\\D$" + }, + "tests": [ + { + "description": "ASCII zero does not match", + "data": "0", + "valid": false + }, + { + "description": "NKO DIGIT ZERO matches (unlike e.g. Python)", + "data": "߀", + "valid": true + }, + { + "description": "NKO DIGIT ZERO (as \\u escape) matches", + "data": "߀", + "valid": true + } + ] + }, + { + "description": "ECMA 262 \\w matches ascii letters only", + "schema": { + "type": "string", + "pattern": "^\\w$" + }, + "tests": [ + { + "description": "ASCII 'a' matches", + "data": "a", + "valid": true + }, + { + "description": "latin-1 e-acute does not match (unlike e.g. Python)", + "data": "é", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\W matches everything but ascii letters", + "schema": { + "type": "string", + "pattern": "^\\W$" + }, + "tests": [ + { + "description": "ASCII 'a' does not match", + "data": "a", + "valid": false + }, + { + "description": "latin-1 e-acute matches (unlike e.g. Python)", + "data": "é", + "valid": true + } + ] + }, + { + "description": "ECMA 262 \\s matches whitespace", + "schema": { + "type": "string", + "pattern": "^\\s$" + }, + "tests": [ + { + "description": "ASCII space matches", + "data": " ", + "valid": true + }, + { + "description": "Character tabulation matches", + "data": "\t", + "valid": true + }, + { + "description": "Line tabulation matches", + "data": "\u000b", + "valid": true, + "skip": "invalid value \"\\v\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "Form feed matches", + "data": "\f", + "valid": true + }, + { + "description": "latin-1 non-breaking-space matches", + "data": " ", + "valid": true, + "skip": "invalid value \"\\u00a0\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "zero-width whitespace matches", + "data": "\ufeff", + "valid": true, + "skip": "invalid value \"\\ufeff\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "line feed matches (line terminator)", + "data": "\n", + "valid": true + }, + { + "description": "paragraph separator matches (line terminator)", + "data": "\u2029", + "valid": true, + "skip": "invalid value \"\\u2029\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "EM SPACE matches (Space_Separator)", + "data": " ", + "valid": true, + "skip": "invalid value \"\\u2003\" (out of bound =~\"^\\\\s$\"):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "Non-whitespace control does not match", + "data": "\u0001", + "valid": false + }, + { + "description": "Non-whitespace does not match", + "data": "–", + "valid": false + } + ] + }, + { + "description": "ECMA 262 \\S matches everything but whitespace", + "schema": { + "type": "string", + "pattern": "^\\S$" + }, + "tests": [ + { + "description": "ASCII space does not match", + "data": " ", + "valid": false + }, + { + "description": "Character tabulation does not match", + "data": "\t", + "valid": false + }, + { + "description": "Line tabulation does not match", + "data": "\u000b", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "Form feed does not match", + "data": "\f", + "valid": false + }, + { + "description": "latin-1 non-breaking-space does not match", + "data": " ", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "zero-width whitespace does not match", + "data": "\ufeff", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "line feed does not match (line terminator)", + "data": "\n", + "valid": false + }, + { + "description": "paragraph separator does not match (line terminator)", + "data": "\u2029", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "EM SPACE does not match (Space_Separator)", + "data": " ", + "valid": false, + "skip": "unexpected success" + }, + { + "description": "Non-whitespace control matches", + "data": "\u0001", + "valid": true + }, + { + "description": "Non-whitespace matches", + "data": "–", + "valid": true + } + ] + }, + { + "description": "patterns always use unicode semantics with pattern", + "schema": { + "pattern": "\\p{Letter}cole" + }, + "skip": "extract error: unsupported regexp: error parsing regexp: invalid character class range: `\\p{Letter}`", + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ÉTAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ÉCOLE, L'ÉGLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ÉTAIT SUR LA PATINOIRE.", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "\\w in patterns matches [A-Za-z0-9_], not unicode letters", + "schema": { + "pattern": "\\wcole" + }, + "tests": [ + { + "description": "ascii character in json string", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": false + }, + { + "description": "unicode matching is case-sensitive", + "data": "LES HIVERS DE MON ENFANCE ÉTAIENT DES SAISONS LONGUES, LONGUES. NOUS VIVIONS EN TROIS LIEUX: L'ÉCOLE, L'ÉGLISE ET LA PATINOIRE; MAIS LA VRAIE VIE ÉTAIT SUR LA PATINOIRE.", + "valid": false + } + ] + }, + { + "description": "pattern with ASCII ranges", + "schema": { + "pattern": "[a-z]cole" + }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": false + }, + { + "description": "unicode character in hex format in string", + "data": "Les hivers de mon enfance étaient des saisons longues, longues. Nous vivions en trois lieux: l'école, l'église et la patinoire; mais la vraie vie était sur la patinoire.", + "valid": false + }, + { + "description": "ascii characters match", + "data": "Les hivers de mon enfance etaient des saisons longues, longues. Nous vivions en trois lieux: l'ecole, l'eglise et la patinoire; mais la vraie vie etait sur la patinoire.", + "valid": true + } + ] + }, + { + "description": "\\d in pattern matches [0-9], not unicode digits", + "schema": { + "pattern": "^\\d+$" + }, + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "৪২", + "valid": false + } + ] + }, + { + "description": "pattern with non-ASCII digits", + "schema": { + "pattern": "^\\p{digit}+$" + }, + "skip": "extract error: unsupported regexp: error parsing regexp: invalid character class range: `\\p{digit}`", + "tests": [ + { + "description": "ascii digits", + "data": "42", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ascii non-digits", + "data": "-%#", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": "৪২", + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "patterns always use unicode semantics with patternProperties", + "schema": { + "type": "object", + "patternProperties": { + "\\p{Letter}cole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { + "l'ecole": "pas de vraie vie" + }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": true + }, + { + "description": "unicode character in hex format in string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": true + }, + { + "description": "unicode matching is case-sensitive", + "data": { + "L'ÉCOLE": "PAS DE VRAIE VIE" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "\\w in patternProperties matches [A-Za-z0-9_], not unicode letters", + "schema": { + "type": "object", + "patternProperties": { + "\\wcole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii character in json string", + "data": { + "l'ecole": "pas de vraie vie" + }, + "valid": true + }, + { + "description": "literal unicode character in json string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "unicode character in hex format in string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "unicode matching is case-sensitive", + "data": { + "L'ÉCOLE": "PAS DE VRAIE VIE" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "patternProperties with ASCII ranges", + "schema": { + "type": "object", + "patternProperties": { + "[a-z]cole": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "literal unicode character in json string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "unicode character in hex format in string", + "data": { + "l'école": "pas de vraie vie" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ascii characters match", + "data": { + "l'ecole": "pas de vraie vie" + }, + "valid": true + } + ] + }, + { + "description": "\\d in patternProperties matches [0-9], not unicode digits", + "schema": { + "type": "object", + "patternProperties": { + "^\\d+$": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { + "42": "life, the universe, and everything" + }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { + "-%#": "spending the year dead for tax reasons" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { + "৪২": "khajit has wares if you have coin" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "patternProperties with non-ASCII digits", + "schema": { + "type": "object", + "patternProperties": { + "^\\p{digit}+$": true + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "ascii digits", + "data": { + "42": "life, the universe, and everything" + }, + "valid": true + }, + { + "description": "ascii non-digits", + "data": { + "-%#": "spending the year dead for tax reasons" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "non-ascii digits (BENGALI DIGIT FOUR, BENGALI DIGIT TWO)", + "data": { + "৪২": "khajit has wares if you have coin" + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/float-overflow.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/float-overflow.json new file mode 100644 index 000000000..ab966fd5e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/float-overflow.json @@ -0,0 +1,17 @@ +[ + { + "description": "all integers are multiples of 0.5, if overflow is handled", + "schema": { + "type": "integer", + "multipleOf": 0.5 + }, + "tests": [ + { + "description": "valid if optional overflow handling is implemented", + "data": 1E+308, + "valid": true, + "skip": "conflicting values 1E+308 and int (mismatched types float and int):\n generated.cue:3:1\n instance.json:1:1\n" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/format/date-time.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/date-time.json new file mode 100644 index 000000000..970385b11 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/date-time.json @@ -0,0 +1,161 @@ +[ + { + "description": "validation of date-time strings", + "schema": { + "format": "date-time" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time string", + "data": "1963-06-19T08:30:06.283185Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time string without second fraction", + "data": "1963-06-19T08:30:06Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time string with plus offset", + "data": "1937-01-01T12:00:27.87+00:20", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time string with minus offset", + "data": "1990-12-31T15:59:50.123-08:00", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time with a leap second, UTC", + "data": "1998-12-31T23:59:60Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date-time with a leap second, with minus offset", + "data": "1998-12-31T15:59:60.123-08:00", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid date-time past leap second, UTC", + "data": "1998-12-31T23:59:61Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid date-time with leap second on a wrong minute, UTC", + "data": "1998-12-31T23:58:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid date-time with leap second on a wrong hour, UTC", + "data": "1998-12-31T22:59:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid day in date-time string", + "data": "1990-02-31T15:59:59.123-08:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid offset in date-time string", + "data": "1990-12-31T15:59:59-24:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid closing Z after time-zone offset", + "data": "1963-06-19T08:30:06.28123+01:00Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid date-time string", + "data": "06/19/1963 08:30:06 PST", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "case-insensitive T and Z", + "data": "1963-06-19t08:30:06.283185z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "2013-350T01:01:01", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-padded month dates", + "data": "1963-6-19T08:30:06.283185Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-padded day dates", + "data": "1963-06-1T08:30:06.283185Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4) in date portion", + "data": "1963-06-1৪T00:00:00Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4) in time portion", + "data": "1963-06-11T0৪:00:00Z", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/format/date.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/date.json new file mode 100644 index 000000000..f8a7eecf5 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/date.json @@ -0,0 +1,293 @@ +[ + { + "description": "validation of date strings", + "schema": { + "format": "date" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date string", + "data": "1963-06-19", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in January", + "data": "2020-01-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in January", + "data": "2020-01-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 28 days in February (normal)", + "data": "2021-02-28", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 29 days in February (normal)", + "data": "2021-02-29", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 29 days in February (leap)", + "data": "2020-02-29", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 30 days in February (leap)", + "data": "2020-02-30", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in March", + "data": "2020-03-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in March", + "data": "2020-03-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 30 days in April", + "data": "2020-04-30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 31 days in April", + "data": "2020-04-31", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in May", + "data": "2020-05-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in May", + "data": "2020-05-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 30 days in June", + "data": "2020-06-30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 31 days in June", + "data": "2020-06-31", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in July", + "data": "2020-07-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in July", + "data": "2020-07-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in August", + "data": "2020-08-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in August", + "data": "2020-08-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 30 days in September", + "data": "2020-09-30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 31 days in September", + "data": "2020-09-31", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in October", + "data": "2020-10-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in October", + "data": "2020-10-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 30 days in November", + "data": "2020-11-30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 31 days in November", + "data": "2020-11-31", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid date string with 31 days in December", + "data": "2020-12-31", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with 32 days in December", + "data": "2020-12-32", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a invalid date string with invalid month", + "data": "2020-13-01", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid date string", + "data": "06/19/1963", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "2013-350", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "non-padded month dates are not valid", + "data": "1998-1-20", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "non-padded day dates are not valid", + "data": "1998-01-1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid month", + "data": "1998-13-01", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid month-day combination", + "data": "1998-04-31", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "2021 is not a leap year", + "data": "2021-02-29", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "2020 is a leap year", + "data": "2020-02-29", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4)", + "data": "1963-06-1৪", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ISO8601 / non-RFC3339: YYYYMMDD without dashes (2023-03-28)", + "data": "20230328", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ISO8601 / non-RFC3339: week number implicit day of week (2023-01-02)", + "data": "2023-W01", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ISO8601 / non-RFC3339: week number with day of week (2023-03-28)", + "data": "2023-W13-2", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ISO8601 / non-RFC3339: week number rollover to next year (2023-01-01)", + "data": "2022W527", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/format/email.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/email.json new file mode 100644 index 000000000..3d9734d2f --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/email.json @@ -0,0 +1,101 @@ +[ + { + "description": "validation of e-mail addresses", + "schema": { + "format": "email" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid e-mail address", + "data": "joe.bloggs@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid e-mail address", + "data": "2962", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "tilde in local part is valid", + "data": "te~st@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "tilde before local part is valid", + "data": "~test@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "tilde after local part is valid", + "data": "test~@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "dot before local part is not valid", + "data": ".test@example.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "dot after local part is not valid", + "data": "test.@example.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "two separated dots inside local part are valid", + "data": "te.s.t@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "two subsequent dots inside local part are not valid", + "data": "te..st@example.com", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/format/hostname.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/hostname.json new file mode 100644 index 000000000..848785f52 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/hostname.json @@ -0,0 +1,143 @@ +[ + { + "description": "validation of host names", + "schema": { + "format": "hostname" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid host name", + "data": "www.example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid punycoded IDN hostname", + "data": "xn--4gbwdl.xn--wgbh1c", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a host name starting with an illegal character", + "data": "-a-host-name-that-starts-with--", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a host name containing illegal characters", + "data": "not_a_valid_host_name", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a host name with a component too long", + "data": "a-vvvvvvvvvvvvvvvveeeeeeeeeeeeeeeerrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy-long-host-name-component", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "starts with hyphen", + "data": "-hostname", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ends with hyphen", + "data": "hostname-", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "starts with underscore", + "data": "_hostname", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ends with underscore", + "data": "hostname_", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "contains underscore", + "data": "host_name", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "exceeds maximum label length", + "data": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "single label", + "data": "hostname", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label with hyphen", + "data": "host-name", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label with digits", + "data": "h0stn4me", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label ending with digit", + "data": "hostnam3", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/format/idn-email.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/idn-email.json new file mode 100644 index 000000000..7f1a47069 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/idn-email.json @@ -0,0 +1,71 @@ +[ + { + "description": "validation of an internationalized e-mail addresses", + "schema": { + "format": "idn-email" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid idn e-mail (example@example.test in Hangul)", + "data": "실례@실례.테스트", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid idn e-mail address", + "data": "2962", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid e-mail address", + "data": "joe.bloggs@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid e-mail address", + "data": "2962", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/format/idn-hostname.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/idn-hostname.json new file mode 100644 index 000000000..6d642eb9f --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/idn-hostname.json @@ -0,0 +1,382 @@ +[ + { + "description": "validation of internationalized host names", + "schema": { + "format": "idn-hostname" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid host name (example.test in Hangul)", + "data": "실례.테스트", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "illegal first char U+302E Hangul single dot tone mark", + "data": "〮실례.테스트", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "contains illegal char U+302E Hangul single dot tone mark", + "data": "실〮례.테스트", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a host name with a component too long", + "data": "실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실실례례테스트례례례례례례례례례례례례례례례례례테스트례례례례례례례례례례례례례례례례례례례테스트례례례례례례례례례례례례테스트례례실례.테스트", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid label, correct Punycode", + "comment": "https://tools.ietf.org/html/rfc5890#section-2.3.2.1 https://tools.ietf.org/html/rfc5891#section-4.4 https://tools.ietf.org/html/rfc3492#section-7.1", + "data": "-\u003e $1.00 \u003c--", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid Chinese Punycode", + "comment": "https://tools.ietf.org/html/rfc5890#section-2.3.2.1 https://tools.ietf.org/html/rfc5891#section-4.4", + "data": "xn--ihqwcrb4cv8a8dqg056pqjye", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid Punycode", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.4 https://tools.ietf.org/html/rfc5890#section-2.3.2.1", + "data": "xn--X", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "U-label contains \"--\" in the 3rd and 4th position", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1 https://tools.ietf.org/html/rfc5890#section-2.3.2.1", + "data": "XN--aa---o47jg78q", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "U-label starts with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "-hello", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "U-label ends with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "hello-", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "U-label starts and ends with a dash", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.1", + "data": "-hello-", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Begins with a Spacing Combining Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "ःhello", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Begins with a Nonspacing Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "̀hello", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Begins with an Enclosing Mark", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.2", + "data": "҈hello", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Exceptions that are PVALID, left-to-right chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "ßς་〇", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Exceptions that are PVALID, right-to-left chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "۽۾", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Exceptions that are DISALLOWED, right-to-left chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6", + "data": "ـߺ", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Exceptions that are DISALLOWED, left-to-right chars", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.2 https://tools.ietf.org/html/rfc5892#section-2.6 Note: The two combining marks (U+302E and U+302F) are in the middle and not at the start", + "data": "〱〲〳〴〵〮〯〻", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "MIDDLE DOT with no preceding 'l'", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "a·l", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "MIDDLE DOT with nothing preceding", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "·l", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "MIDDLE DOT with no following 'l'", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l·a", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "MIDDLE DOT with nothing following", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l·", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "MIDDLE DOT with surrounding 'l's", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.3", + "data": "l·l", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Greek KERAIA not followed by Greek", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "α͵S", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Greek KERAIA not followed by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "α͵", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Greek KERAIA followed by Greek", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.4", + "data": "α͵β", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Hebrew GERESH not preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "A׳ב", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Hebrew GERESH not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "׳ב", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Hebrew GERESH preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.5", + "data": "א׳ב", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Hebrew GERSHAYIM not preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "A״ב", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Hebrew GERSHAYIM not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "״ב", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Hebrew GERSHAYIM preceded by Hebrew", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.6", + "data": "א״ב", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "KATAKANA MIDDLE DOT with no Hiragana, Katakana, or Han", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "def・abc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "KATAKANA MIDDLE DOT with no other characters", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "・", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "KATAKANA MIDDLE DOT with Hiragana", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "・ぁ", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "KATAKANA MIDDLE DOT with Katakana", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "・ァ", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "KATAKANA MIDDLE DOT with Han", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.7", + "data": "・丈", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Arabic-Indic digits mixed with Extended Arabic-Indic digits", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8", + "data": "ب٠۰", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "Arabic-Indic digits not mixed with Extended Arabic-Indic digits", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.8", + "data": "ب٠ب", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "Extended Arabic-Indic digits not mixed with Arabic-Indic digits", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.9", + "data": "۰0", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ZERO WIDTH JOINER not preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "क‍ष", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ZERO WIDTH JOINER not preceded by anything", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "‍ष", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ZERO WIDTH JOINER preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.2 https://www.unicode.org/review/pr-37.pdf", + "data": "क्‍ष", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ZERO WIDTH NON-JOINER preceded by Virama", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1", + "data": "क्‌ष", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ZERO WIDTH NON-JOINER not preceded by Virama but matches regexp", + "comment": "https://tools.ietf.org/html/rfc5891#section-4.2.3.3 https://tools.ietf.org/html/rfc5892#appendix-A.1 https://www.w3.org/TR/alreq/#h_disjoining_enforcement", + "data": "بي‌بي", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label", + "data": "hostname", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label with hyphen", + "data": "host-name", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label with digits", + "data": "h0stn4me", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "single label ending with digit", + "data": "hostnam3", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/format/ipv4.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/ipv4.json new file mode 100644 index 000000000..1ef0f11f8 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/ipv4.json @@ -0,0 +1,108 @@ +[ + { + "description": "validation of IP addresses", + "schema": { + "format": "ipv4" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IP address", + "data": "192.168.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an IP address with too many components", + "data": "127.0.0.0.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IP address with out-of-range values", + "data": "256.256.256.256", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IP address without 4 components", + "data": "127.0", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IP address as an integer", + "data": "0x7f000001", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IP address as an integer (decimal)", + "data": "2130706433", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid leading zeroes, as they are treated as octals", + "comment": "see https://sick.codes/universal-netmask-npm-package-used-by-270000-projects-vulnerable-to-octal-input-data-server-side-request-forgery-remote-file-inclusion-local-file-inclusion-and-more-cve-2021-28918/", + "data": "087.10.0.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "value without leading zero is valid", + "data": "87.10.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '২' (a Bengali 2)", + "data": "1২7.0.0.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "netmask is not a part of ipv4 address", + "data": "192.168.1.0/24", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/format/ipv6.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/ipv6.json new file mode 100644 index 000000000..0c8edf677 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/ipv6.json @@ -0,0 +1,251 @@ +[ + { + "description": "validation of IPv6 addresses", + "schema": { + "format": "ipv6" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IPv6 address", + "data": "::1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an IPv6 address with out-of-range values", + "data": "12345::", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "trailing 4 hex symbols is valid", + "data": "::abef", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "trailing 5 hex symbols is invalid", + "data": "::abcef", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IPv6 address with too many components", + "data": "1:1:1:1:1:1:1:1:1:1:1:1:1:1:1:1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an IPv6 address containing illegal characters", + "data": "::laptop", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no digits is valid", + "data": "::", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "leading colons is valid", + "data": "::42:ff:1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "trailing colons is valid", + "data": "d6::", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "missing leading octet is invalid", + "data": ":2:3:4:5:6:7:8", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "missing trailing octet is invalid", + "data": "1:2:3:4:5:6:7:", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "missing leading octet with omitted octets later", + "data": ":2:3:4::8", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "single set of double colons in the middle is valid", + "data": "1:d6::42", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "two sets of double colons is invalid", + "data": "1::d6::42", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "mixed format with the ipv4 section as decimal octets", + "data": "1::d6:192.168.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mixed format with double colons between the sections", + "data": "1:2::192.168.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mixed format with ipv4 section with octet out of range", + "data": "1::2:192.168.256.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "mixed format with ipv4 section with a hex octet", + "data": "1::2:192.168.ff.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "mixed format with leading double colons (ipv4-mapped ipv6 address)", + "data": "::ffff:192.168.0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "triple colons is invalid", + "data": "1:2:3:4:5:::8", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "8 octets", + "data": "1:2:3:4:5:6:7:8", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "insufficient octets without double colons", + "data": "1:2:3:4:5:6:7", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no colons is invalid", + "data": "1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ipv4 is not ipv6", + "data": "127.0.0.1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "ipv4 segment must have 4 octets", + "data": "1:2:3:4:1.2.3", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "leading whitespace is invalid", + "data": " ::1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "trailing whitespace is invalid", + "data": "::1 ", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "netmask is not a part of ipv6 address", + "data": "fe80::/64", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "zone id is not a part of ipv6 address", + "data": "fe80::a%eth1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a long valid ipv6", + "data": "1000:1000:1000:1000:1000:1000:255.255.255.255", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a long invalid ipv6, below length limit, first", + "data": "100:100:100:100:100:100:255.255.255.255.255", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a long invalid ipv6, below length limit, second", + "data": "100:100:100:100:100:100:100:255.255.255.255", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4)", + "data": "1:2:3:4:5:6:7:৪", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '৪' (a Bengali 4) in the IPv4 portion", + "data": "1:2::192.16৪.0.1", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/format/iri-reference.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/iri-reference.json new file mode 100644 index 000000000..4ec8e0904 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/iri-reference.json @@ -0,0 +1,89 @@ +[ + { + "description": "validation of IRI References", + "schema": { + "format": "iri-reference" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI", + "data": "http://ƒøø.ßår/?∂éœ=πîx#πîüx", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid protocol-relative IRI Reference", + "data": "//ƒøø.ßår/?∂éœ=πîx#πîüx", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid relative IRI Reference", + "data": "/âππ", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid IRI Reference", + "data": "\\\\WINDOWS\\filëßåré", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI Reference", + "data": "âππ", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI fragment", + "data": "#ƒrägmênt", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid IRI fragment", + "data": "#ƒräg\\mênt", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/format/iri.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/iri.json new file mode 100644 index 000000000..5cbed507d --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/iri.json @@ -0,0 +1,101 @@ +[ + { + "description": "validation of IRIs", + "schema": { + "format": "iri" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI with anchor tag", + "data": "http://ƒøø.ßår/?∂éœ=πîx#πîüx", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI with anchor tag and parentheses", + "data": "http://ƒøø.com/blah_(wîkïpédiå)_blah#ßité-1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI with URL-encoded stuff", + "data": "http://ƒøø.ßår/?q=Test%20URL-encoded%20stuff", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI with many special characters", + "data": "http://-.~_!$\u0026'()*+,;=:%40:80%2f::::::@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid IRI based on IPv6", + "data": "http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid IRI based on IPv6", + "data": "http://2001:0db8:85a3:0000:0000:8a2e:0370:7334", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid relative IRI Reference", + "data": "/abc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid IRI", + "data": "\\\\WINDOWS\\filëßåré", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid IRI though valid IRI reference", + "data": "âππ", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/format/json-pointer.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/json-pointer.json new file mode 100644 index 000000000..5d36bee42 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/json-pointer.json @@ -0,0 +1,239 @@ +[ + { + "description": "validation of JSON-pointers (JSON String Representation)", + "schema": { + "format": "json-pointer" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid JSON-pointer", + "data": "/foo/bar~0/baz~1/%a", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (~ not escaped)", + "data": "/foo/bar~", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer with empty segment", + "data": "/foo//bar", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer with the last empty segment", + "data": "/foo/bar/", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #1", + "data": "", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #2", + "data": "/foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #3", + "data": "/foo/0", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #4", + "data": "/", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #5", + "data": "/a~1b", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #6", + "data": "/c%d", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #7", + "data": "/e^f", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #8", + "data": "/g|h", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #9", + "data": "/i\\j", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #10", + "data": "/k\"l", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #11", + "data": "/ ", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #12", + "data": "/m~0n", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer used adding to the last array position", + "data": "/foo/-", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer (- used as object member name)", + "data": "/foo/-/bar", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer (multiple escaped characters)", + "data": "/~1~0~0~1~1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer (escaped with fraction part) #1", + "data": "/~1.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid JSON-pointer (escaped with fraction part) #2", + "data": "/~0.1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #1", + "data": "#", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #2", + "data": "#/", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #3", + "data": "#a", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (some escaped, but not all) #1", + "data": "/~0~", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (some escaped, but not all) #2", + "data": "/~0/~", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (wrong escape character) #1", + "data": "/~2", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (wrong escape character) #2", + "data": "/~-1", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (multiple characters not escaped)", + "data": "/~~", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #1", + "data": "a", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #2", + "data": "0", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #3", + "data": "a/a", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/format/regex.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/regex.json new file mode 100644 index 000000000..3269e24f3 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/regex.json @@ -0,0 +1,59 @@ +[ + { + "description": "validation of regular expressions", + "schema": { + "format": "regex" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid regular expression", + "data": "([abc])+\\s+$", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a regular expression with unclosed parens is invalid", + "data": "^(abc]", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/format/relative-json-pointer.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/relative-json-pointer.json new file mode 100644 index 000000000..73194f41f --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/relative-json-pointer.json @@ -0,0 +1,119 @@ +[ + { + "description": "validation of Relative JSON Pointers (RJP)", + "schema": { + "format": "relative-json-pointer" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid upwards RJP", + "data": "1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid downwards RJP", + "data": "0/foo/bar", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid up and then down RJP, with array index", + "data": "2/0/baz/1/zip", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid RJP taking the member or index name", + "data": "0#", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid RJP that is a valid JSON Pointer", + "data": "/foo/bar", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "negative prefix", + "data": "-1/foo/bar", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "explicit positive prefix", + "data": "+1/foo/bar", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "## is not a valid json-pointer", + "data": "0##", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "zero cannot be followed by other digits, plus json-pointer", + "data": "01/a", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "zero cannot be followed by other digits, plus octothorpe", + "data": "01#", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "empty string", + "data": "", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "multi-digit integer prefix", + "data": "120/foo/bar", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/format/time.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/time.json new file mode 100644 index 000000000..5a7196a64 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/time.json @@ -0,0 +1,281 @@ +[ + { + "description": "validation of time strings", + "schema": { + "format": "time" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid time string", + "data": "08:30:06Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid time string with extra leading zeros", + "data": "008:030:006Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid time string with no leading zero for single digit", + "data": "8:3:6Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "hour, minute, second must be two digits", + "data": "8:0030:6Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid time string with leap second, Zulu", + "data": "23:59:60Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, Zulu (wrong hour)", + "data": "22:59:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, Zulu (wrong minute)", + "data": "23:58:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid leap second, zero time-offset", + "data": "23:59:60+00:00", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, zero time-offset (wrong hour)", + "data": "22:59:60+00:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, zero time-offset (wrong minute)", + "data": "23:58:60+00:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid leap second, positive time-offset", + "data": "01:29:60+01:30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid leap second, large positive time-offset", + "data": "23:29:60+23:30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, positive time-offset (wrong hour)", + "data": "23:59:60+01:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, positive time-offset (wrong minute)", + "data": "23:59:60+00:30", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid leap second, negative time-offset", + "data": "15:59:60-08:00", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "valid leap second, large negative time-offset", + "data": "00:29:60-23:30", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, negative time-offset (wrong hour)", + "data": "23:59:60-01:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid leap second, negative time-offset (wrong minute)", + "data": "23:59:60-00:30", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid time string with second fraction", + "data": "23:20:50.52Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid time string with precise second fraction", + "data": "08:30:06.283185Z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid time string with plus offset", + "data": "08:30:06+00:20", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid time string with minus offset", + "data": "08:30:06-08:00", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "hour, minute in time-offset must be two digits", + "data": "08:30:06-8:000", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid time string with case-insensitive Z", + "data": "08:30:06z", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid hour", + "data": "24:00:00Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid minute", + "data": "00:60:00Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid second", + "data": "00:00:61Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid leap second (wrong hour)", + "data": "22:59:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid leap second (wrong minute)", + "data": "23:58:60Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid time numoffset hour", + "data": "01:02:03+24:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid time numoffset minute", + "data": "01:02:03+00:60", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid time string with invalid time with both Z and numoffset", + "data": "01:02:03Z+00:30", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid offset indicator", + "data": "08:30:06 PST", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "only RFC3339 not all of ISO 8601 are valid", + "data": "01:01:01,1111", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no time offset", + "data": "12:00:00", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "no time offset with second fraction", + "data": "12:00:00.52", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid non-ASCII '২' (a Bengali 2)", + "data": "1২:00:00Z", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "offset not starting with plus or minus", + "data": "08:30:06#00:20", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "contains letters", + "data": "ab:cd:ef", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/format/unknown.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/unknown.json new file mode 100644 index 000000000..97a7ae39e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/unknown.json @@ -0,0 +1,53 @@ +[ + { + "description": "unknown format", + "schema": { + "format": "unknown" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "unknown formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "unknown formats ignore strings", + "data": "string", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/format/uri-reference.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/uri-reference.json new file mode 100644 index 000000000..5cf42d3b2 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/uri-reference.json @@ -0,0 +1,89 @@ +[ + { + "description": "validation of URI References", + "schema": { + "format": "uri-reference" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URI", + "data": "http://foo.bar/?baz=qux#quux", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid protocol-relative URI Reference", + "data": "//foo.bar/?baz=qux#quux", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid relative URI Reference", + "data": "/abc", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI Reference", + "data": "\\\\WINDOWS\\fileshare", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid URI Reference", + "data": "abc", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URI fragment", + "data": "#fragment", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI fragment", + "data": "#frag\\ment", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/format/uri-template.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/uri-template.json new file mode 100644 index 000000000..6d96910b3 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/uri-template.json @@ -0,0 +1,71 @@ +[ + { + "description": "format: uri-template", + "schema": { + "format": "uri-template" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid uri-template", + "data": "http://example.com/dictionary/{term:1}/{term}", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid uri-template", + "data": "http://example.com/dictionary/{term:1}/{term", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "a valid uri-template without variables", + "data": "http://example.com/dictionary", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid relative uri-template", + "data": "dictionary/{term:1}/{term}", + "valid": true, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/format/uri.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/uri.json new file mode 100644 index 000000000..9dfe867c4 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/format/uri.json @@ -0,0 +1,167 @@ +[ + { + "description": "validation of URIs", + "schema": { + "format": "uri" + }, + "skip": "extract error: unsupported constraint \"format\"", + "tests": [ + { + "description": "all string formats ignore integers", + "data": 12, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore floats", + "data": 13.7, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore objects", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore arrays", + "data": [], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore booleans", + "data": false, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "all string formats ignore nulls", + "data": null, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with anchor tag", + "data": "http://foo.bar/?baz=qux#quux", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with anchor tag and parentheses", + "data": "http://foo.com/blah_(wikipedia)_blah#cite-1", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with URL-encoded stuff", + "data": "http://foo.bar/?q=Test%20URL-encoded%20stuff", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid puny-coded URL ", + "data": "http://xn--nw2a.xn--j6w193g/", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with many special characters", + "data": "http://-.~_!$\u0026'()*+,;=:%40:80%2f::::::@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL based on IPv4", + "data": "http://223.255.255.254", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL with ftp scheme", + "data": "ftp://ftp.is.co.za/rfc/rfc1808.txt", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL for a simple text file", + "data": "http://www.ietf.org/rfc/rfc2396.txt", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URL ", + "data": "ldap://[2001:db8::7]/c=GB?objectClass?one", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid mailto URI", + "data": "mailto:John.Doe@example.com", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid newsgroup URI", + "data": "news:comp.infosystems.www.servers.unix", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid tel URI", + "data": "tel:+1-816-555-1212", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a valid URN", + "data": "urn:oasis:names:specification:docbook:dtd:xml:4.1.2", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an invalid protocol-relative URI Reference", + "data": "//foo.bar/?baz=qux#quux", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid relative URI Reference", + "data": "/abc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI", + "data": "\\\\WINDOWS\\fileshare", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI though valid URI reference", + "data": "abc", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI with spaces", + "data": "http:// shouldfail.com", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI with spaces and missing scheme", + "data": ":// should fail", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an invalid URI with comma in scheme", + "data": "bar,baz:foo", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/id.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/id.json new file mode 100644 index 000000000..b06c4ddf3 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/id.json @@ -0,0 +1,128 @@ +[ + { + "description": "id inside an enum is not a real identifier", + "comment": "the implementation must not be confused by an id buried in the enum", + "schema": { + "definitions": { + "id_in_enum": { + "enum": [ + { + "$id": "https://localhost:1234/id/my_identifier.json", + "type": "null" + } + ] + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/id/my_identifier.json", + "type": "string" + }, + "zzz_id_in_const": { + "const": { + "$id": "https://localhost:1234/id/my_identifier.json", + "type": "null" + } + } + }, + "anyOf": [ + { + "$ref": "#/definitions/id_in_enum" + }, + { + "$ref": "https://localhost:1234/id/my_identifier.json" + } + ] + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/id/my_identifier.json:my_identifier\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "exact match to enum, and type matches", + "data": { + "$id": "https://localhost:1234/id/my_identifier.json", + "type": "null" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "match $ref to id", + "data": "a string to match #/definitions/id_in_enum", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "no match on enum or $ref to id", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "non-schema object containing a plain-name $id property", + "schema": { + "definitions": { + "const_not_anchor": { + "const": { + "$id": "#not_a_real_anchor" + } + } + }, + "if": { + "const": "skip not_a_real_anchor" + }, + "then": true, + "else": { + "$ref": "#/definitions/const_not_anchor" + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 2 more errors)", + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_anchor", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "const at const_not_anchor does not match", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "non-schema object containing an $id property", + "schema": { + "definitions": { + "const_not_id": { + "const": { + "$id": "not_a_real_id" + } + } + }, + "if": { + "const": "skip not_a_real_id" + }, + "then": true, + "else": { + "$ref": "#/definitions/const_not_id" + } + }, + "skip": "extract error: unsupported constraint \"if\" (and 2 more errors)", + "tests": [ + { + "description": "skip traversing definition for a valid result", + "data": "skip not_a_real_id", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "const at const_not_id does not match", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/non-bmp-regex.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/non-bmp-regex.json new file mode 100644 index 000000000..3ea9d0e2e --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/non-bmp-regex.json @@ -0,0 +1,94 @@ +[ + { + "description": "Proper UTF-16 surrogate pair handling: pattern", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { + "pattern": "^🐲*$" + }, + "tests": [ + { + "description": "matches empty", + "data": "", + "valid": true + }, + { + "description": "matches single", + "data": "🐲", + "valid": true + }, + { + "description": "matches two", + "data": "🐲🐲", + "valid": true + }, + { + "description": "doesn't match one", + "data": "🐉", + "valid": false + }, + { + "description": "doesn't match two", + "data": "🐉🐉", + "valid": false + }, + { + "description": "doesn't match one ASCII", + "data": "D", + "valid": false + }, + { + "description": "doesn't match two ASCII", + "data": "DD", + "valid": false + } + ] + }, + { + "description": "Proper UTF-16 surrogate pair handling: patternProperties", + "comment": "Optional because .Net doesn't correctly handle 32-bit Unicode characters", + "schema": { + "patternProperties": { + "^🐲*$": { + "type": "integer" + } + } + }, + "tests": [ + { + "description": "matches empty", + "data": { + "": 1 + }, + "valid": true + }, + { + "description": "matches single", + "data": { + "🐲": 1 + }, + "valid": true + }, + { + "description": "matches two", + "data": { + "🐲🐲": 1 + }, + "valid": true + }, + { + "description": "doesn't match one", + "data": { + "🐲": "hello" + }, + "valid": false + }, + { + "description": "doesn't match two", + "data": { + "🐲🐲": "hello" + }, + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/optional/unknownKeyword.json b/encoding/jsonschema/testdata/external/tests/draft7/optional/unknownKeyword.json new file mode 100644 index 000000000..e36a2a3e1 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/optional/unknownKeyword.json @@ -0,0 +1,66 @@ +[ + { + "description": "$id inside an unknown keyword is not a real identifier", + "comment": "the implementation must not be confused by an $id in locations we do not know how to parse", + "schema": { + "definitions": { + "id_in_unknown0": { + "not": { + "array_of_schemas": [ + { + "$id": "https://localhost:1234/unknownKeyword/my_identifier.json", + "type": "null" + } + ] + } + }, + "real_id_in_schema": { + "$id": "https://localhost:1234/unknownKeyword/my_identifier.json", + "type": "string" + }, + "id_in_unknown1": { + "not": { + "object_of_schemas": { + "foo": { + "$id": "https://localhost:1234/unknownKeyword/my_identifier.json", + "type": "integer" + } + } + } + } + }, + "anyOf": [ + { + "$ref": "#/definitions/id_in_unknown0" + }, + { + "$ref": "#/definitions/id_in_unknown1" + }, + { + "$ref": "https://localhost:1234/unknownKeyword/my_identifier.json" + } + ] + }, + "skip": "extract error: unsupported constraint \"not\" (and 1 more errors)", + "tests": [ + { + "description": "type matches second anyOf, which has a real schema in it", + "data": "a string", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "type matches non-schema in first anyOf", + "data": null, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "type matches non-schema in third anyOf", + "data": 1, + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/pattern.json b/encoding/jsonschema/testdata/external/tests/draft7/pattern.json new file mode 100644 index 000000000..b2d1ee318 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/pattern.json @@ -0,0 +1,63 @@ +[ + { + "description": "pattern validation", + "schema": { + "pattern": "^a*$" + }, + "tests": [ + { + "description": "a matching pattern is valid", + "data": "aaa", + "valid": true + }, + { + "description": "a non-matching pattern is invalid", + "data": "abc", + "valid": false + }, + { + "description": "ignores booleans", + "data": true, + "valid": true + }, + { + "description": "ignores integers", + "data": 123, + "valid": true + }, + { + "description": "ignores floats", + "data": 1.0, + "valid": true + }, + { + "description": "ignores objects", + "data": {}, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores null", + "data": null, + "valid": true + } + ] + }, + { + "description": "pattern is not anchored", + "schema": { + "pattern": "a+" + }, + "tests": [ + { + "description": "matches a substring", + "data": "xxaayy", + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/patternProperties.json b/encoding/jsonschema/testdata/external/tests/draft7/patternProperties.json new file mode 100644 index 000000000..eafb1a7a5 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/patternProperties.json @@ -0,0 +1,228 @@ +[ + { + "description": "patternProperties validates properties matching a regex", + "schema": { + "patternProperties": { + "f.*o": { + "type": "integer" + } + } + }, + "tests": [ + { + "description": "a single valid match is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "multiple valid matches is valid", + "data": { + "foo": 1, + "foooooo": 2 + }, + "valid": true + }, + { + "description": "a single invalid match is invalid", + "data": { + "foo": "bar", + "fooooo": 2 + }, + "valid": false + }, + { + "description": "multiple invalid matches is invalid", + "data": { + "foo": "bar", + "foooooo": "baz" + }, + "valid": false + }, + { + "description": "ignores arrays", + "data": [ + "foo" + ], + "valid": true + }, + { + "description": "ignores strings", + "data": "foo", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "multiple simultaneous patternProperties are validated", + "schema": { + "patternProperties": { + "a*": { + "type": "integer" + }, + "aaa*": { + "maximum": 20 + } + } + }, + "tests": [ + { + "description": "a single valid match is valid", + "data": { + "a": 21 + }, + "valid": true + }, + { + "description": "a simultaneous match is valid", + "data": { + "aaaa": 18 + }, + "valid": true + }, + { + "description": "multiple matches is valid", + "data": { + "a": 21, + "aaaa": 18 + }, + "valid": true + }, + { + "description": "an invalid due to one is invalid", + "data": { + "a": "bar" + }, + "valid": false + }, + { + "description": "an invalid due to the other is invalid", + "data": { + "aaaa": 31 + }, + "valid": false + }, + { + "description": "an invalid due to both is invalid", + "data": { + "aaa": "foo", + "aaaa": 31 + }, + "valid": false + } + ] + }, + { + "description": "regexes are not anchored by default and are case sensitive", + "schema": { + "patternProperties": { + "[0-9]{2,}": { + "type": "boolean" + }, + "X_": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "non recognized members are ignored", + "data": { + "answer 1": "42" + }, + "valid": true + }, + { + "description": "recognized members are accounted for", + "data": { + "a31b": null + }, + "valid": false + }, + { + "description": "regexes are case sensitive", + "data": { + "a_x_3": 3 + }, + "valid": true + }, + { + "description": "regexes are case sensitive, 2", + "data": { + "a_X_3": 3 + }, + "valid": false + } + ] + }, + { + "description": "patternProperties with boolean schemas", + "schema": { + "patternProperties": { + "f.*": true, + "b.*": false + } + }, + "tests": [ + { + "description": "object with property matching schema true is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "object with property matching schema false is invalid", + "data": { + "bar": 2 + }, + "valid": false + }, + { + "description": "object with both properties is invalid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false + }, + { + "description": "object with a property matching both true and false is invalid", + "data": { + "foobar": 1 + }, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "patternProperties with null valued instance properties", + "schema": { + "patternProperties": { + "^.*bar$": { + "type": "null" + } + } + }, + "tests": [ + { + "description": "allows null values", + "data": { + "foobar": null + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/properties.json b/encoding/jsonschema/testdata/external/tests/draft7/properties.json new file mode 100644 index 000000000..7c1c86dbb --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/properties.json @@ -0,0 +1,332 @@ +[ + { + "description": "object properties validation", + "schema": { + "properties": { + "foo": { + "type": "integer" + }, + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "both properties present and valid is valid", + "data": { + "foo": 1, + "bar": "baz" + }, + "valid": true + }, + { + "description": "one property invalid is invalid", + "data": { + "foo": 1, + "bar": {} + }, + "valid": false + }, + { + "description": "both properties invalid is invalid", + "data": { + "foo": [], + "bar": {} + }, + "valid": false + }, + { + "description": "doesn't invalidate other properties", + "data": { + "quux": [] + }, + "valid": true + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "properties, patternProperties, additionalProperties interaction", + "schema": { + "properties": { + "foo": { + "type": "array", + "maxItems": 3 + }, + "bar": { + "type": "array" + } + }, + "patternProperties": { + "f.o": { + "minItems": 2 + } + }, + "additionalProperties": { + "type": "integer" + } + }, + "tests": [ + { + "description": "property validates property", + "data": { + "foo": [ + 1, + 2 + ] + }, + "valid": true + }, + { + "description": "property invalidates property", + "data": { + "foo": [ + 1, + 2, + 3, + 4 + ] + }, + "valid": false + }, + { + "description": "patternProperty invalidates property", + "data": { + "foo": [] + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "patternProperty validates nonproperty", + "data": { + "fxo": [ + 1, + 2 + ] + }, + "valid": true + }, + { + "description": "patternProperty invalidates nonproperty", + "data": { + "fxo": [] + }, + "valid": false + }, + { + "description": "additionalProperty ignores property", + "data": { + "bar": [] + }, + "valid": true + }, + { + "description": "additionalProperty validates others", + "data": { + "quux": 3 + }, + "valid": true + }, + { + "description": "additionalProperty invalidates others", + "data": { + "quux": "foo" + }, + "valid": false + } + ] + }, + { + "description": "properties with boolean schema", + "schema": { + "properties": { + "foo": true, + "bar": false + } + }, + "tests": [ + { + "description": "no property present is valid", + "data": {}, + "valid": true + }, + { + "description": "only 'true' property present is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "only 'false' property present is invalid", + "data": { + "bar": 2 + }, + "valid": false + }, + { + "description": "both properties present is invalid", + "data": { + "foo": 1, + "bar": 2 + }, + "valid": false + } + ] + }, + { + "description": "properties with escaped characters", + "schema": { + "properties": { + "foo\nbar": { + "type": "number" + }, + "foo\"bar": { + "type": "number" + }, + "foo\\bar": { + "type": "number" + }, + "foo\rbar": { + "type": "number" + }, + "foo\tbar": { + "type": "number" + }, + "foo\fbar": { + "type": "number" + } + } + }, + "tests": [ + { + "description": "object with all numbers is valid", + "data": { + "foo\nbar": 1, + "foo\"bar": 1, + "foo\\bar": 1, + "foo\rbar": 1, + "foo\tbar": 1, + "foo\fbar": 1 + }, + "valid": true + }, + { + "description": "object with strings is invalid", + "data": { + "foo\nbar": "1", + "foo\"bar": "1", + "foo\\bar": "1", + "foo\rbar": "1", + "foo\tbar": "1", + "foo\fbar": "1" + }, + "valid": false + } + ] + }, + { + "description": "properties with null valued instance properties", + "schema": { + "properties": { + "foo": { + "type": "null" + } + } + }, + "tests": [ + { + "description": "allows null values", + "data": { + "foo": null + }, + "valid": true + } + ] + }, + { + "description": "properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { + "properties": { + "__proto__": { + "type": "number" + }, + "toString": { + "properties": { + "length": { + "type": "string" + } + } + }, + "constructor": { + "type": "number" + } + } + }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": true + }, + { + "description": "__proto__ not valid", + "data": { + "__proto__": "foo" + }, + "valid": false + }, + { + "description": "toString not valid", + "data": { + "toString": { + "length": 37 + } + }, + "valid": false + }, + { + "description": "constructor not valid", + "data": { + "constructor": { + "length": 37 + } + }, + "valid": false + }, + { + "description": "all present and valid", + "data": { + "__proto__": 12, + "toString": { + "length": "foo" + }, + "constructor": 37 + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/propertyNames.json b/encoding/jsonschema/testdata/external/tests/draft7/propertyNames.json new file mode 100644 index 000000000..da1f470dd --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/propertyNames.json @@ -0,0 +1,132 @@ +[ + { + "description": "propertyNames validation", + "schema": { + "propertyNames": { + "maxLength": 3 + } + }, + "skip": "extract error: cannot compile resulting schema: reference \"strings\" in label expression refers to field against which it would be matched:\n generated.cue:4:3\n", + "tests": [ + { + "description": "all property names valid", + "data": { + "f": {}, + "foo": {} + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "some property names invalid", + "data": { + "foo": {}, + "foobar": {} + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "object without properties is valid", + "data": {}, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores arrays", + "data": [ + 1, + 2, + 3, + 4 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "propertyNames validation with pattern", + "schema": { + "propertyNames": { + "pattern": "^a+$" + } + }, + "tests": [ + { + "description": "matching property names valid", + "data": { + "a": {}, + "aa": {}, + "aaa": {} + }, + "valid": true + }, + { + "description": "non-matching property name is invalid", + "data": { + "aaA": {} + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "object without properties is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "propertyNames with boolean schema true", + "schema": { + "propertyNames": true + }, + "tests": [ + { + "description": "object with any properties is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + }, + { + "description": "propertyNames with boolean schema false", + "schema": { + "propertyNames": false + }, + "tests": [ + { + "description": "object with any properties is invalid", + "data": { + "foo": 1 + }, + "valid": false + }, + { + "description": "empty object is valid", + "data": {}, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/ref.json b/encoding/jsonschema/testdata/external/tests/draft7/ref.json new file mode 100644 index 000000000..e89ec6603 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/ref.json @@ -0,0 +1,1337 @@ +[ + { + "description": "root pointer ref", + "schema": { + "properties": { + "foo": { + "$ref": "#" + } + }, + "additionalProperties": false + }, + "tests": [ + { + "description": "match", + "data": { + "foo": false + }, + "valid": true + }, + { + "description": "recursive match", + "data": { + "foo": { + "foo": false + } + }, + "valid": true + }, + { + "description": "mismatch", + "data": { + "bar": false + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "recursive mismatch", + "data": { + "foo": { + "bar": false + } + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "relative pointer ref to object", + "schema": { + "properties": { + "foo": { + "type": "integer" + }, + "bar": { + "$ref": "#/properties/foo" + } + } + }, + "skip": "extract error: cannot compile resulting schema: bar: reference \"foo\" not found:\n generated.cue:4:10\n", + "tests": [ + { + "description": "match", + "data": { + "bar": 3 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": { + "bar": true + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "relative pointer ref to array", + "schema": { + "items": [ + { + "type": "integer" + }, + { + "$ref": "#/items/0" + } + ] + }, + "skip": "extract error: referring to field \"items\" not yet supported", + "tests": [ + { + "description": "match array", + "data": [ + 1, + 2 + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch array", + "data": [ + 1, + "foo" + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "escaped pointer ref", + "schema": { + "definitions": { + "tilde~field": { + "type": "integer" + }, + "slash/field": { + "type": "integer" + }, + "percent%field": { + "type": "integer" + } + }, + "properties": { + "tilde": { + "$ref": "#/definitions/tilde~0field" + }, + "slash": { + "$ref": "#/definitions/slash~1field" + }, + "percent": { + "$ref": "#/definitions/percent%25field" + } + } + }, + "tests": [ + { + "description": "slash invalid", + "data": { + "slash": "aoeu" + }, + "valid": false + }, + { + "description": "tilde invalid", + "data": { + "tilde": "aoeu" + }, + "valid": false + }, + { + "description": "percent invalid", + "data": { + "percent": "aoeu" + }, + "valid": false + }, + { + "description": "slash valid", + "data": { + "slash": 123 + }, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values [...] and {slash:123} (mismatched types list and struct):\n generated.cue:2:33\n instance.json:1:1\nconflicting values bool and {slash:123} (mismatched types bool and struct):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and {slash:123} (mismatched types null and struct):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and {slash:123} (mismatched types number and struct):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and {slash:123} (mismatched types string and struct):\n generated.cue:2:24\n instance.json:1:1\nslash: undefined field: \"slash~1field\":\n generated.cue:4:14\n" + }, + { + "description": "tilde valid", + "data": { + "tilde": 123 + }, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values [...] and {tilde:123} (mismatched types list and struct):\n generated.cue:2:33\n instance.json:1:1\nconflicting values bool and {tilde:123} (mismatched types bool and struct):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and {tilde:123} (mismatched types null and struct):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and {tilde:123} (mismatched types number and struct):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and {tilde:123} (mismatched types string and struct):\n generated.cue:2:24\n instance.json:1:1\ntilde: undefined field: \"tilde~0field\":\n generated.cue:3:14\n" + }, + { + "description": "percent valid", + "data": { + "percent": 123 + }, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values [...] and {percent:123} (mismatched types list and struct):\n generated.cue:2:33\n instance.json:1:1\nconflicting values bool and {percent:123} (mismatched types bool and struct):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and {percent:123} (mismatched types null and struct):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and {percent:123} (mismatched types number and struct):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and {percent:123} (mismatched types string and struct):\n generated.cue:2:24\n instance.json:1:1\npercent: undefined field: \"percent%25field\":\n generated.cue:5:14\n" + } + ] + }, + { + "description": "nested refs", + "schema": { + "definitions": { + "a": { + "type": "integer" + }, + "b": { + "$ref": "#/definitions/a" + }, + "c": { + "$ref": "#/definitions/b" + } + }, + "allOf": [ + { + "$ref": "#/definitions/c" + } + ] + }, + "tests": [ + { + "description": "nested ref valid", + "data": 5, + "valid": true + }, + { + "description": "nested ref invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "ref overrides any sibling keywords", + "schema": { + "definitions": { + "reffed": { + "type": "array" + } + }, + "properties": { + "foo": { + "$ref": "#/definitions/reffed", + "maxItems": 2 + } + } + }, + "tests": [ + { + "description": "ref valid", + "data": { + "foo": [] + }, + "valid": true + }, + { + "description": "ref valid, maxItems ignored", + "data": { + "foo": [ + 1, + 2, + 3 + ] + }, + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [...] and {foo:[1,2,3]} (mismatched types list and struct):\n generated.cue:3:33\n instance.json:1:1\nconflicting values bool and {foo:[1,2,3]} (mismatched types bool and struct):\n generated.cue:3:8\n instance.json:1:1\nconflicting values null and {foo:[1,2,3]} (mismatched types null and struct):\n generated.cue:3:1\n instance.json:1:1\nconflicting values number and {foo:[1,2,3]} (mismatched types number and struct):\n generated.cue:3:15\n instance.json:1:1\nconflicting values string and {foo:[1,2,3]} (mismatched types string and struct):\n generated.cue:3:24\n instance.json:1:1\n" + }, + { + "description": "ref invalid", + "data": { + "foo": "string" + }, + "valid": false + } + ] + }, + { + "description": "$ref prevents a sibling $id from changing the base uri", + "schema": { + "$id": "http://localhost:1234/sibling_id/base/", + "definitions": { + "foo": { + "$id": "http://localhost:1234/sibling_id/foo.json", + "type": "string" + }, + "base_foo": { + "$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json", + "$id": "foo.json", + "type": "number" + } + }, + "allOf": [ + { + "$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not http://localhost:1234/sibling_id/foo.json", + "$id": "http://localhost:1234/sibling_id/", + "$ref": "foo.json" + } + ] + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/sibling_id/foo.json:foo\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "$ref resolves to /definitions/base_foo, data does not validate", + "data": "a", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "$ref resolves to /definitions/base_foo, data validates", + "data": 1, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "remote ref, containing refs itself", + "schema": { + "$ref": "http://json-schema.org/draft-07/schema#" + }, + "skip": "extract error: cannot compile resulting schema: package \"json-schema.org/draft-07/schema\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "remote ref valid", + "data": { + "minLength": 1 + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "remote ref invalid", + "data": { + "minLength": -1 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "property named $ref that is not a reference", + "schema": { + "properties": { + "$ref": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": { + "$ref": "a" + }, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": { + "$ref": 2 + }, + "valid": false + } + ] + }, + { + "description": "property named $ref, containing an actual $ref", + "schema": { + "properties": { + "$ref": { + "$ref": "#/definitions/is-string" + } + }, + "definitions": { + "is-string": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "property named $ref valid", + "data": { + "$ref": "a" + }, + "valid": true + }, + { + "description": "property named $ref invalid", + "data": { + "$ref": 2 + }, + "valid": false + } + ] + }, + { + "description": "$ref to boolean schema true", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/bool" + } + ], + "definitions": { + "bool": true + } + }, + "tests": [ + { + "description": "any value is valid", + "data": "foo", + "valid": true + } + ] + }, + { + "description": "$ref to boolean schema false", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/bool" + } + ], + "definitions": { + "bool": false + } + }, + "skip": "extract error: cannot compile resulting schema: explicit error (_|_ literal) in source:\n generated.cue:4:8\n", + "tests": [ + { + "description": "any value is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "Recursive references between schemas", + "schema": { + "$id": "http://localhost:1234/tree", + "description": "tree of nodes", + "type": "object", + "properties": { + "meta": { + "type": "string" + }, + "nodes": { + "type": "array", + "items": { + "$ref": "node" + } + } + }, + "required": [ + "meta", + "nodes" + ], + "definitions": { + "node": { + "$id": "http://localhost:1234/node", + "description": "node", + "type": "object", + "properties": { + "value": { + "type": "number" + }, + "subtree": { + "$ref": "tree" + } + }, + "required": [ + "value" + ] + } + } + }, + "skip": "extract error: cannot compile resulting schema: builtin package \"localhost:1234/node\" undefined:\n generated.cue:1:8\n_schema.nodes: reference \"node\" not found:\n generated.cue:8:14\n", + "tests": [ + { + "description": "valid tree", + "data": { + "meta": "root", + "nodes": [ + { + "value": 1, + "subtree": { + "meta": "child", + "nodes": [ + { + "value": 1.1 + }, + { + "value": 1.2 + } + ] + } + }, + { + "value": 2, + "subtree": { + "meta": "child", + "nodes": [ + { + "value": 2.1 + }, + { + "value": 2.2 + } + ] + } + } + ] + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "invalid tree", + "data": { + "meta": "root", + "nodes": [ + { + "value": 1, + "subtree": { + "meta": "child", + "nodes": [ + { + "value": "string is invalid" + }, + { + "value": 1.2 + } + ] + } + }, + { + "value": 2, + "subtree": { + "meta": "child", + "nodes": [ + { + "value": 2.1 + }, + { + "value": 2.2 + } + ] + } + } + ] + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "refs with quote", + "schema": { + "properties": { + "foo\"bar": { + "$ref": "#/definitions/foo%22bar" + } + }, + "definitions": { + "foo\"bar": { + "type": "number" + } + } + }, + "tests": [ + { + "description": "object with numbers is valid", + "data": { + "foo\"bar": 1 + }, + "valid": true, + "skip": "6 errors in empty disjunction:\nconflicting values [...] and {\"foo\\\"bar\":1} (mismatched types list and struct):\n generated.cue:2:33\n instance.json:1:1\nconflicting values bool and {\"foo\\\"bar\":1} (mismatched types bool and struct):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and {\"foo\\\"bar\":1} (mismatched types null and struct):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and {\"foo\\\"bar\":1} (mismatched types number and struct):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and {\"foo\\\"bar\":1} (mismatched types string and struct):\n generated.cue:2:24\n instance.json:1:1\n\"foo\\\"bar\": undefined field: \"foo%22bar\":\n generated.cue:3:17\n" + }, + { + "description": "object with strings is invalid", + "data": { + "foo\"bar": "1" + }, + "valid": false + } + ] + }, + { + "description": "Location-independent identifier", + "schema": { + "allOf": [ + { + "$ref": "#foo" + } + ], + "definitions": { + "A": { + "$id": "#foo", + "type": "integer" + } + } + }, + "skip": "extract error: $id URI may not contain a fragment (and 1 more errors)", + "tests": [ + { + "description": "match", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "Reference an anchor with a non-relative URI", + "schema": { + "$id": "https://example.com/schema-with-anchor", + "allOf": [ + { + "$ref": "https://example.com/schema-with-anchor#foo" + } + ], + "definitions": { + "A": { + "$id": "#foo", + "type": "integer" + } + } + }, + "skip": "extract error: $id URI may not contain a fragment (and 1 more errors)", + "tests": [ + { + "description": "match", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "Location-independent identifier with base URI change in subschema", + "schema": { + "$id": "http://localhost:1234/root", + "allOf": [ + { + "$ref": "http://localhost:1234/nested.json#foo" + } + ], + "definitions": { + "A": { + "$id": "nested.json", + "definitions": { + "B": { + "$id": "#foo", + "type": "integer" + } + } + } + } + }, + "skip": "extract error: $id URI may not contain a fragment (and 1 more errors)", + "tests": [ + { + "description": "match", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "mismatch", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "naive replacement of $ref with its destination is not correct", + "schema": { + "definitions": { + "a_string": { + "type": "string" + } + }, + "enum": [ + { + "$ref": "#/definitions/a_string" + } + ] + }, + "tests": [ + { + "description": "do not evaluate the $ref inside the enum, matching any string", + "data": "this is a string", + "valid": false + }, + { + "description": "do not evaluate the $ref inside the enum, definition exact match", + "data": { + "type": "string" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "match the enum exactly", + "data": { + "$ref": "#/definitions/a_string" + }, + "valid": true + } + ] + }, + { + "description": "refs with relative uris and defs", + "schema": { + "$id": "http://example.com/schema-relative-uri-defs1.json", + "properties": { + "foo": { + "$id": "schema-relative-uri-defs2.json", + "definitions": { + "inner": { + "properties": { + "bar": { + "type": "string" + } + } + } + }, + "allOf": [ + { + "$ref": "#/definitions/inner" + } + ] + } + }, + "allOf": [ + { + "$ref": "schema-relative-uri-defs2.json" + } + ] + }, + "skip": "extract error: cannot compile resulting schema: package \"example.com/schema-relative-uri-defs2.json:schema\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "invalid on inner field", + "data": { + "foo": { + "bar": 1 + }, + "bar": "a" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid on outer field", + "data": { + "foo": { + "bar": "a" + }, + "bar": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid on both fields", + "data": { + "foo": { + "bar": "a" + }, + "bar": "a" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "relative refs with absolute uris and defs", + "schema": { + "$id": "http://example.com/schema-refs-absolute-uris-defs1.json", + "properties": { + "foo": { + "$id": "http://example.com/schema-refs-absolute-uris-defs2.json", + "definitions": { + "inner": { + "properties": { + "bar": { + "type": "string" + } + } + } + }, + "allOf": [ + { + "$ref": "#/definitions/inner" + } + ] + } + }, + "allOf": [ + { + "$ref": "schema-refs-absolute-uris-defs2.json" + } + ] + }, + "skip": "extract error: cannot compile resulting schema: package \"example.com/schema-refs-absolute-uris-defs2.json:schema\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "invalid on inner field", + "data": { + "foo": { + "bar": 1 + }, + "bar": "a" + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "invalid on outer field", + "data": { + "foo": { + "bar": "a" + }, + "bar": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid on both fields", + "data": { + "foo": { + "bar": "a" + }, + "bar": "a" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$id must be resolved against nearest parent, not just immediate parent", + "schema": { + "$id": "http://example.com/a.json", + "definitions": { + "x": { + "$id": "http://example.com/b/c.json", + "not": { + "definitions": { + "y": { + "$id": "d.json", + "type": "number" + } + } + } + } + }, + "allOf": [ + { + "$ref": "http://example.com/b/d.json" + } + ] + }, + "skip": "extract error: unsupported constraint \"not\"", + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "simple URN base URI with $ref via the URN", + "schema": { + "$comment": "URIs do not have to have HTTP(s) schemes", + "$id": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed", + "minimum": 30, + "properties": { + "foo": { + "$ref": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed" + } + } + }, + "tests": [ + { + "description": "valid under the URN IDed schema", + "data": { + "foo": 37 + }, + "valid": true + }, + { + "description": "invalid under the URN IDed schema", + "data": { + "foo": 12 + }, + "valid": false + } + ] + }, + { + "description": "simple URN base URI with JSON pointer", + "schema": { + "$comment": "URIs do not have to have HTTP(s) schemes", + "$id": "urn:uuid:deadbeef-1234-00ff-ff00-4321feebdaed", + "properties": { + "foo": { + "$ref": "#/definitions/bar" + } + }, + "definitions": { + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false + } + ] + }, + { + "description": "URN base URI with NSS", + "schema": { + "$comment": "RFC 8141 §2.2", + "$id": "urn:example:1/406/47452/2", + "properties": { + "foo": { + "$ref": "#/definitions/bar" + } + }, + "definitions": { + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false + } + ] + }, + { + "description": "URN base URI with r-component", + "schema": { + "$comment": "RFC 8141 §2.3.1", + "$id": "urn:example:foo-bar-baz-qux?+CCResolve:cc=uk", + "properties": { + "foo": { + "$ref": "#/definitions/bar" + } + }, + "definitions": { + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false + } + ] + }, + { + "description": "URN base URI with q-component", + "schema": { + "$comment": "RFC 8141 §2.3.2", + "$id": "urn:example:weather?=op=map\u0026lat=39.56\u0026lon=-104.85\u0026datetime=1969-07-21T02:56:15Z", + "properties": { + "foo": { + "$ref": "#/definitions/bar" + } + }, + "definitions": { + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false + } + ] + }, + { + "description": "URN base URI with URN and JSON pointer ref", + "schema": { + "$id": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed", + "properties": { + "foo": { + "$ref": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed#/definitions/bar" + } + }, + "definitions": { + "bar": { + "type": "string" + } + } + }, + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false + } + ] + }, + { + "description": "URN base URI with URN and anchor ref", + "schema": { + "$id": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed", + "properties": { + "foo": { + "$ref": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed#something" + } + }, + "definitions": { + "bar": { + "$id": "#something", + "type": "string" + } + } + }, + "skip": "extract error: anchors (something) not supported (and 1 more errors)", + "tests": [ + { + "description": "a string is valid", + "data": { + "foo": "bar" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "a non-string is invalid", + "data": { + "foo": 12 + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ref to if", + "schema": { + "allOf": [ + { + "$ref": "http://example.com/ref/if" + }, + { + "if": { + "$id": "http://example.com/ref/if", + "type": "integer" + } + } + ] + }, + "skip": "extract error: unsupported constraint \"if\"", + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ref to then", + "schema": { + "allOf": [ + { + "$ref": "http://example.com/ref/then" + }, + { + "then": { + "$id": "http://example.com/ref/then", + "type": "integer" + } + } + ] + }, + "skip": "extract error: unsupported constraint \"then\"", + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ref to else", + "schema": { + "allOf": [ + { + "$ref": "http://example.com/ref/else" + }, + { + "else": { + "$id": "http://example.com/ref/else", + "type": "integer" + } + } + ] + }, + "skip": "extract error: unsupported constraint \"else\"", + "tests": [ + { + "description": "a non-integer is invalid due to the $ref", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "an integer is valid", + "data": 12, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ref with absolute-path-reference", + "schema": { + "$id": "http://example.com/ref/absref.json", + "definitions": { + "a": { + "$id": "http://example.com/ref/absref/foobar.json", + "type": "number" + }, + "b": { + "$id": "http://example.com/absref/foobar.json", + "type": "string" + } + }, + "allOf": [ + { + "$ref": "/absref/foobar.json" + } + ] + }, + "skip": "extract error: cannot compile resulting schema: package \"example.com/absref/foobar.json:foobar\" imported but not defined in :\n generated.cue:1:8\n", + "tests": [ + { + "description": "a string is valid", + "data": "foo", + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "an integer is invalid", + "data": 12, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$id with file URI still resolves pointers - *nix", + "schema": { + "$id": "file:///folder/file.json", + "definitions": { + "foo": { + "type": "number" + } + }, + "allOf": [ + { + "$ref": "#/definitions/foo" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "$id with file URI still resolves pointers - windows", + "schema": { + "$id": "file:///c:/folder/file.json", + "definitions": { + "foo": { + "type": "number" + } + }, + "allOf": [ + { + "$ref": "#/definitions/foo" + } + ] + }, + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false + } + ] + }, + { + "description": "empty tokens in $ref json-pointer", + "schema": { + "definitions": { + "": { + "definitions": { + "": { + "type": "number" + } + } + } + }, + "allOf": [ + { + "$ref": "#/definitions//definitions/" + } + ] + }, + "skip": "extract error: cannot refer to definitions section: must refer to one of its elements", + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/refRemote.json b/encoding/jsonschema/testdata/external/tests/draft7/refRemote.json new file mode 100644 index 000000000..50160bb82 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/refRemote.json @@ -0,0 +1,339 @@ +[ + { + "description": "remote ref", + "schema": { + "$ref": "http://localhost:1234/integer.json" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/integer.json:integer\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "remote ref valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "remote ref invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "fragment within remote ref", + "schema": { + "$ref": "http://localhost:1234/subSchemas.json#/definitions/integer" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/subSchemas.json:subSchemas\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "remote fragment valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "remote fragment invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "ref within remote ref", + "schema": { + "$ref": "http://localhost:1234/subSchemas.json#/definitions/refToInteger" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/subSchemas.json:subSchemas\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "ref within ref valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "ref within ref invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "base URI change", + "schema": { + "$id": "http://localhost:1234/", + "items": { + "$id": "baseUriChange/", + "items": { + "$ref": "folderInteger.json" + } + } + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/baseUriChange/folderInteger.json:folderInteger\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "base URI change ref valid", + "data": [ + [ + 1 + ] + ], + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "base URI change ref invalid", + "data": [ + [ + "a" + ] + ], + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "base URI change - change folder", + "schema": { + "$id": "http://localhost:1234/scope_change_defs1.json", + "type": "object", + "properties": { + "list": { + "$ref": "#/definitions/baz" + } + }, + "definitions": { + "baz": { + "$id": "baseUriChangeFolder/", + "type": "array", + "items": { + "$ref": "folderInteger.json" + } + } + } + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/baseUriChangeFolder/folderInteger.json:folderInteger\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is valid", + "data": { + "list": [ + 1 + ] + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": { + "list": [ + "a" + ] + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "base URI change - change folder in subschema", + "schema": { + "$id": "http://localhost:1234/scope_change_defs2.json", + "type": "object", + "properties": { + "list": { + "$ref": "#/definitions/baz/definitions/bar" + } + }, + "definitions": { + "baz": { + "$id": "baseUriChangeFolderInSubschema/", + "definitions": { + "bar": { + "type": "array", + "items": { + "$ref": "folderInteger.json" + } + } + } + } + } + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/baseUriChangeFolderInSubschema/folderInteger.json:folderInteger\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is valid", + "data": { + "list": [ + 1 + ] + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": { + "list": [ + "a" + ] + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "root ref in remote ref", + "schema": { + "$id": "http://localhost:1234/object", + "type": "object", + "properties": { + "name": { + "$ref": "name.json#/definitions/orNull" + } + } + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/name.json:name\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "string is valid", + "data": { + "name": "foo" + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "null is valid", + "data": { + "name": null + }, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "object is invalid", + "data": { + "name": { + "name": null + } + }, + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "remote ref with ref to definitions", + "schema": { + "$id": "http://localhost:1234/schema-remote-ref-ref-defs1.json", + "allOf": [ + { + "$ref": "ref-and-definitions.json" + } + ] + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/ref-and-definitions.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "invalid", + "data": { + "bar": 1 + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "valid", + "data": { + "bar": "a" + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "Location-independent identifier in remote ref", + "schema": { + "$ref": "http://localhost:1234/locationIndependentIdentifierPre2019.json#/definitions/refToInteger" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/locationIndependentIdentifierPre2019.json:locationIndependentIdentifierPre2019\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "integer is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false, + "skip": "could not compile schema" + } + ] + }, + { + "description": "retrieved nested refs resolve relative to their URI not $id", + "schema": { + "$id": "http://localhost:1234/some-id", + "properties": { + "name": { + "$ref": "nested/foo-ref-string.json" + } + } + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/nested/foo-ref-string.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is invalid", + "data": { + "name": { + "foo": 1 + } + }, + "valid": false, + "skip": "could not compile schema" + }, + { + "description": "string is valid", + "data": { + "name": { + "foo": "a" + } + }, + "valid": true, + "skip": "could not compile schema" + } + ] + }, + { + "description": "$ref to $ref finds location-independent $id", + "schema": { + "$ref": "http://localhost:1234/draft7/detached-ref.json#/definitions/foo" + }, + "skip": "extract error: cannot compile resulting schema: invalid import path: \"localhost:1234/draft7/detached-ref.json:schema\":\n generated.cue:1:8\n", + "tests": [ + { + "description": "number is valid", + "data": 1, + "valid": true, + "skip": "could not compile schema" + }, + { + "description": "non-number is invalid", + "data": "a", + "valid": false, + "skip": "could not compile schema" + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/required.json b/encoding/jsonschema/testdata/external/tests/draft7/required.json new file mode 100644 index 000000000..5b1eb6ad6 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/required.json @@ -0,0 +1,181 @@ +[ + { + "description": "required validation", + "schema": { + "properties": { + "foo": {}, + "bar": {} + }, + "required": [ + "foo" + ] + }, + "tests": [ + { + "description": "present required property is valid", + "data": { + "foo": 1 + }, + "valid": true + }, + { + "description": "non-present required property is invalid", + "data": { + "bar": 1 + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", + "data": "", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + } + ] + }, + { + "description": "required default validation", + "schema": { + "properties": { + "foo": {} + } + }, + "tests": [ + { + "description": "not required by default", + "data": {}, + "valid": true + } + ] + }, + { + "description": "required with empty array", + "schema": { + "properties": { + "foo": {} + }, + "required": [] + }, + "tests": [ + { + "description": "property not required", + "data": {}, + "valid": true + } + ] + }, + { + "description": "required with escaped characters", + "schema": { + "required": [ + "foo\nbar", + "foo\"bar", + "foo\\bar", + "foo\rbar", + "foo\tbar", + "foo\fbar" + ] + }, + "tests": [ + { + "description": "object with all properties present is valid", + "data": { + "foo\nbar": 1, + "foo\"bar": 1, + "foo\\bar": 1, + "foo\rbar": 1, + "foo\tbar": 1, + "foo\fbar": 1 + }, + "valid": true + }, + { + "description": "object with some properties missing is invalid", + "data": { + "foo\nbar": "1", + "foo\"bar": "1" + }, + "valid": false, + "skip": "unexpected success" + } + ] + }, + { + "description": "required properties whose names are Javascript object property names", + "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.", + "schema": { + "required": [ + "__proto__", + "toString", + "constructor" + ] + }, + "tests": [ + { + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { + "description": "none of the properties mentioned", + "data": {}, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "__proto__ present", + "data": { + "__proto__": "foo" + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "toString present", + "data": { + "toString": { + "length": 37 + } + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "constructor present", + "data": { + "constructor": { + "length": 37 + } + }, + "valid": false, + "skip": "unexpected success" + }, + { + "description": "all present", + "data": { + "__proto__": 12, + "toString": { + "length": "foo" + }, + "constructor": 37 + }, + "valid": true + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/type.json b/encoding/jsonschema/testdata/external/tests/draft7/type.json new file mode 100644 index 000000000..55f71cdcc --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/type.json @@ -0,0 +1,515 @@ +[ + { + "description": "integer type matches integers", + "schema": { + "type": "integer" + }, + "tests": [ + { + "description": "an integer is an integer", + "data": 1, + "valid": true + }, + { + "description": "a float with zero fractional part is an integer", + "data": 1.0, + "valid": true, + "skip": "conflicting values 1.0 and int (mismatched types float and int):\n generated.cue:2:1\n instance.json:1:1\n" + }, + { + "description": "a float is not an integer", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an integer", + "data": "foo", + "valid": false + }, + { + "description": "a string is still not an integer, even if it looks like one", + "data": "1", + "valid": false + }, + { + "description": "an object is not an integer", + "data": {}, + "valid": false + }, + { + "description": "an array is not an integer", + "data": [], + "valid": false + }, + { + "description": "a boolean is not an integer", + "data": true, + "valid": false + }, + { + "description": "null is not an integer", + "data": null, + "valid": false + } + ] + }, + { + "description": "number type matches numbers", + "schema": { + "type": "number" + }, + "tests": [ + { + "description": "an integer is a number", + "data": 1, + "valid": true + }, + { + "description": "a float with zero fractional part is a number (and an integer)", + "data": 1.0, + "valid": true + }, + { + "description": "a float is a number", + "data": 1.1, + "valid": true + }, + { + "description": "a string is not a number", + "data": "foo", + "valid": false + }, + { + "description": "a string is still not a number, even if it looks like one", + "data": "1", + "valid": false + }, + { + "description": "an object is not a number", + "data": {}, + "valid": false + }, + { + "description": "an array is not a number", + "data": [], + "valid": false + }, + { + "description": "a boolean is not a number", + "data": true, + "valid": false + }, + { + "description": "null is not a number", + "data": null, + "valid": false + } + ] + }, + { + "description": "string type matches strings", + "schema": { + "type": "string" + }, + "tests": [ + { + "description": "1 is not a string", + "data": 1, + "valid": false + }, + { + "description": "a float is not a string", + "data": 1.1, + "valid": false + }, + { + "description": "a string is a string", + "data": "foo", + "valid": true + }, + { + "description": "a string is still a string, even if it looks like a number", + "data": "1", + "valid": true + }, + { + "description": "an empty string is still a string", + "data": "", + "valid": true + }, + { + "description": "an object is not a string", + "data": {}, + "valid": false + }, + { + "description": "an array is not a string", + "data": [], + "valid": false + }, + { + "description": "a boolean is not a string", + "data": true, + "valid": false + }, + { + "description": "null is not a string", + "data": null, + "valid": false + } + ] + }, + { + "description": "object type matches objects", + "schema": { + "type": "object" + }, + "tests": [ + { + "description": "an integer is not an object", + "data": 1, + "valid": false + }, + { + "description": "a float is not an object", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an object", + "data": "foo", + "valid": false + }, + { + "description": "an object is an object", + "data": {}, + "valid": true + }, + { + "description": "an array is not an object", + "data": [], + "valid": false + }, + { + "description": "a boolean is not an object", + "data": true, + "valid": false + }, + { + "description": "null is not an object", + "data": null, + "valid": false + } + ] + }, + { + "description": "array type matches arrays", + "schema": { + "type": "array" + }, + "tests": [ + { + "description": "an integer is not an array", + "data": 1, + "valid": false + }, + { + "description": "a float is not an array", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not an array", + "data": "foo", + "valid": false + }, + { + "description": "an object is not an array", + "data": {}, + "valid": false + }, + { + "description": "an array is an array", + "data": [], + "valid": true + }, + { + "description": "a boolean is not an array", + "data": true, + "valid": false + }, + { + "description": "null is not an array", + "data": null, + "valid": false + } + ] + }, + { + "description": "boolean type matches booleans", + "schema": { + "type": "boolean" + }, + "tests": [ + { + "description": "an integer is not a boolean", + "data": 1, + "valid": false + }, + { + "description": "zero is not a boolean", + "data": 0, + "valid": false + }, + { + "description": "a float is not a boolean", + "data": 1.1, + "valid": false + }, + { + "description": "a string is not a boolean", + "data": "foo", + "valid": false + }, + { + "description": "an empty string is not a boolean", + "data": "", + "valid": false + }, + { + "description": "an object is not a boolean", + "data": {}, + "valid": false + }, + { + "description": "an array is not a boolean", + "data": [], + "valid": false + }, + { + "description": "true is a boolean", + "data": true, + "valid": true + }, + { + "description": "false is a boolean", + "data": false, + "valid": true + }, + { + "description": "null is not a boolean", + "data": null, + "valid": false + } + ] + }, + { + "description": "null type matches only the null object", + "schema": { + "type": "null" + }, + "tests": [ + { + "description": "an integer is not null", + "data": 1, + "valid": false + }, + { + "description": "a float is not null", + "data": 1.1, + "valid": false + }, + { + "description": "zero is not null", + "data": 0, + "valid": false + }, + { + "description": "a string is not null", + "data": "foo", + "valid": false + }, + { + "description": "an empty string is not null", + "data": "", + "valid": false + }, + { + "description": "an object is not null", + "data": {}, + "valid": false + }, + { + "description": "an array is not null", + "data": [], + "valid": false + }, + { + "description": "true is not null", + "data": true, + "valid": false + }, + { + "description": "false is not null", + "data": false, + "valid": false + }, + { + "description": "null is null", + "data": null, + "valid": true + } + ] + }, + { + "description": "multiple types can be specified in an array", + "schema": { + "type": [ + "integer", + "string" + ] + }, + "tests": [ + { + "description": "an integer is valid", + "data": 1, + "valid": true + }, + { + "description": "a string is valid", + "data": "foo", + "valid": true + }, + { + "description": "a float is invalid", + "data": 1.1, + "valid": false + }, + { + "description": "an object is invalid", + "data": {}, + "valid": false + }, + { + "description": "an array is invalid", + "data": [], + "valid": false + }, + { + "description": "a boolean is invalid", + "data": true, + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + } + ] + }, + { + "description": "type as array with one item", + "schema": { + "type": [ + "string" + ] + }, + "tests": [ + { + "description": "string is valid", + "data": "foo", + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + } + ] + }, + { + "description": "type: array or object", + "schema": { + "type": [ + "array", + "object" + ] + }, + "tests": [ + { + "description": "array is valid", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "object is valid", + "data": { + "foo": 123 + }, + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + }, + { + "description": "null is invalid", + "data": null, + "valid": false + } + ] + }, + { + "description": "type: array, object or null", + "schema": { + "type": [ + "array", + "object", + "null" + ] + }, + "tests": [ + { + "description": "array is valid", + "data": [ + 1, + 2, + 3 + ], + "valid": true + }, + { + "description": "object is valid", + "data": { + "foo": 123 + }, + "valid": true + }, + { + "description": "null is valid", + "data": null, + "valid": true + }, + { + "description": "number is invalid", + "data": 123, + "valid": false + }, + { + "description": "string is invalid", + "data": "foo", + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/testdata/external/tests/draft7/uniqueItems.json b/encoding/jsonschema/testdata/external/tests/draft7/uniqueItems.json new file mode 100644 index 000000000..329125d52 --- /dev/null +++ b/encoding/jsonschema/testdata/external/tests/draft7/uniqueItems.json @@ -0,0 +1,832 @@ +[ + { + "description": "uniqueItems validation", + "schema": { + "uniqueItems": true + }, + "tests": [ + { + "description": "unique array of integers is valid", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "non-unique array of integers is invalid", + "data": [ + 1, + 1 + ], + "valid": false + }, + { + "description": "non-unique array of more than two integers is invalid", + "data": [ + 1, + 2, + 1 + ], + "valid": false + }, + { + "description": "numbers are unique if mathematically unequal", + "data": [ + 1.0, + 1.00, + 1 + ], + "valid": false, + "skip": "unexpected success" + }, + { + "description": "false is not equal to zero", + "data": [ + 0, + false + ], + "valid": true + }, + { + "description": "true is not equal to one", + "data": [ + 1, + true + ], + "valid": true + }, + { + "description": "unique array of strings is valid", + "data": [ + "foo", + "bar", + "baz" + ], + "valid": true + }, + { + "description": "non-unique array of strings is invalid", + "data": [ + "foo", + "bar", + "foo" + ], + "valid": false + }, + { + "description": "unique array of objects is valid", + "data": [ + { + "foo": "bar" + }, + { + "foo": "baz" + } + ], + "valid": true + }, + { + "description": "non-unique array of objects is invalid", + "data": [ + { + "foo": "bar" + }, + { + "foo": "bar" + } + ], + "valid": false + }, + { + "description": "property order of array of objects is ignored", + "data": [ + { + "foo": "bar", + "bar": "foo" + }, + { + "bar": "foo", + "foo": "bar" + } + ], + "valid": false, + "skip": "unexpected success" + }, + { + "description": "unique array of nested objects is valid", + "data": [ + { + "foo": { + "bar": { + "baz": true + } + } + }, + { + "foo": { + "bar": { + "baz": false + } + } + } + ], + "valid": true + }, + { + "description": "non-unique array of nested objects is invalid", + "data": [ + { + "foo": { + "bar": { + "baz": true + } + } + }, + { + "foo": { + "bar": { + "baz": true + } + } + } + ], + "valid": false + }, + { + "description": "unique array of arrays is valid", + "data": [ + [ + "foo" + ], + [ + "bar" + ] + ], + "valid": true + }, + { + "description": "non-unique array of arrays is invalid", + "data": [ + [ + "foo" + ], + [ + "foo" + ] + ], + "valid": false + }, + { + "description": "non-unique array of more than two arrays is invalid", + "data": [ + [ + "foo" + ], + [ + "bar" + ], + [ + "foo" + ] + ], + "valid": false + }, + { + "description": "1 and true are unique", + "data": [ + 1, + true + ], + "valid": true + }, + { + "description": "0 and false are unique", + "data": [ + 0, + false + ], + "valid": true + }, + { + "description": "[1] and [true] are unique", + "data": [ + [ + 1 + ], + [ + true + ] + ], + "valid": true + }, + { + "description": "[0] and [false] are unique", + "data": [ + [ + 0 + ], + [ + false + ] + ], + "valid": true + }, + { + "description": "nested [1] and [true] are unique", + "data": [ + [ + [ + 1 + ], + "foo" + ], + [ + [ + true + ], + "foo" + ] + ], + "valid": true + }, + { + "description": "nested [0] and [false] are unique", + "data": [ + [ + [ + 0 + ], + "foo" + ], + [ + [ + false + ], + "foo" + ] + ], + "valid": true + }, + { + "description": "unique heterogeneous types are valid", + "data": [ + {}, + [ + 1 + ], + true, + null, + 1, + "{}" + ], + "valid": true + }, + { + "description": "non-unique heterogeneous types are invalid", + "data": [ + {}, + [ + 1 + ], + true, + null, + {}, + 1 + ], + "valid": false + }, + { + "description": "different objects are unique", + "data": [ + { + "a": 1, + "b": 2 + }, + { + "a": 2, + "b": 1 + } + ], + "valid": true + }, + { + "description": "objects are non-unique despite key order", + "data": [ + { + "a": 1, + "b": 2 + }, + { + "b": 2, + "a": 1 + } + ], + "valid": false, + "skip": "unexpected success" + }, + { + "description": "{\"a\": false} and {\"a\": 0} are unique", + "data": [ + { + "a": false + }, + { + "a": 0 + } + ], + "valid": true + }, + { + "description": "{\"a\": true} and {\"a\": 1} are unique", + "data": [ + { + "a": true + }, + { + "a": 1 + } + ], + "valid": true + } + ] + }, + { + "description": "uniqueItems with an array of items", + "schema": { + "items": [ + { + "type": "boolean" + }, + { + "type": "boolean" + } + ], + "uniqueItems": true + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [ + false, + true + ], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [ + true, + false + ], + "valid": true + }, + { + "description": "[false, false] from items array is not valid", + "data": [ + false, + false + ], + "valid": false + }, + { + "description": "[true, true] from items array is not valid", + "data": [ + true, + true + ], + "valid": false + }, + { + "description": "unique array extended from [false, true] is valid", + "data": [ + false, + true, + "foo", + "bar" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [false,true,\"foo\",\"bar\"] and {...} (mismatched types list and struct):\n generated.cue:3:1\n generated.cue:3:69\n instance.json:1:1\nconflicting values bool and [false,true,\"foo\",\"bar\"] (mismatched types bool and list):\n generated.cue:3:8\n instance.json:1:1\nconflicting values null and [false,true,\"foo\",\"bar\"] (mismatched types null and list):\n generated.cue:3:1\n instance.json:1:1\nconflicting values number and [false,true,\"foo\",\"bar\"] (mismatched types number and list):\n generated.cue:3:15\n instance.json:1:1\nconflicting values string and [false,true,\"foo\",\"bar\"] (mismatched types string and list):\n generated.cue:3:24\n instance.json:1:1\n" + }, + { + "description": "unique array extended from [true, false] is valid", + "data": [ + true, + false, + "foo", + "bar" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [true,false,\"foo\",\"bar\"] and {...} (mismatched types list and struct):\n generated.cue:3:1\n generated.cue:3:69\n instance.json:1:1\nconflicting values bool and [true,false,\"foo\",\"bar\"] (mismatched types bool and list):\n generated.cue:3:8\n instance.json:1:1\nconflicting values null and [true,false,\"foo\",\"bar\"] (mismatched types null and list):\n generated.cue:3:1\n instance.json:1:1\nconflicting values number and [true,false,\"foo\",\"bar\"] (mismatched types number and list):\n generated.cue:3:15\n instance.json:1:1\nconflicting values string and [true,false,\"foo\",\"bar\"] (mismatched types string and list):\n generated.cue:3:24\n instance.json:1:1\n" + }, + { + "description": "non-unique array extended from [false, true] is not valid", + "data": [ + false, + true, + "foo", + "foo" + ], + "valid": false + }, + { + "description": "non-unique array extended from [true, false] is not valid", + "data": [ + true, + false, + "foo", + "foo" + ], + "valid": false + } + ] + }, + { + "description": "uniqueItems with an array of items and additionalItems=false", + "schema": { + "items": [ + { + "type": "boolean" + }, + { + "type": "boolean" + } + ], + "uniqueItems": true, + "additionalItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [ + false, + true + ], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [ + true, + false + ], + "valid": true + }, + { + "description": "[false, false] from items array is not valid", + "data": [ + false, + false + ], + "valid": false + }, + { + "description": "[true, true] from items array is not valid", + "data": [ + true, + true + ], + "valid": false + }, + { + "description": "extra items are invalid even if unique", + "data": [ + false, + true, + null + ], + "valid": false + } + ] + }, + { + "description": "uniqueItems=false validation", + "schema": { + "uniqueItems": false + }, + "tests": [ + { + "description": "unique array of integers is valid", + "data": [ + 1, + 2 + ], + "valid": true + }, + { + "description": "non-unique array of integers is valid", + "data": [ + 1, + 1 + ], + "valid": true + }, + { + "description": "numbers are unique if mathematically unequal", + "data": [ + 1.0, + 1.00, + 1 + ], + "valid": true + }, + { + "description": "false is not equal to zero", + "data": [ + 0, + false + ], + "valid": true + }, + { + "description": "true is not equal to one", + "data": [ + 1, + true + ], + "valid": true + }, + { + "description": "unique array of objects is valid", + "data": [ + { + "foo": "bar" + }, + { + "foo": "baz" + } + ], + "valid": true + }, + { + "description": "non-unique array of objects is valid", + "data": [ + { + "foo": "bar" + }, + { + "foo": "bar" + } + ], + "valid": true + }, + { + "description": "unique array of nested objects is valid", + "data": [ + { + "foo": { + "bar": { + "baz": true + } + } + }, + { + "foo": { + "bar": { + "baz": false + } + } + } + ], + "valid": true + }, + { + "description": "non-unique array of nested objects is valid", + "data": [ + { + "foo": { + "bar": { + "baz": true + } + } + }, + { + "foo": { + "bar": { + "baz": true + } + } + } + ], + "valid": true + }, + { + "description": "unique array of arrays is valid", + "data": [ + [ + "foo" + ], + [ + "bar" + ] + ], + "valid": true + }, + { + "description": "non-unique array of arrays is valid", + "data": [ + [ + "foo" + ], + [ + "foo" + ] + ], + "valid": true + }, + { + "description": "1 and true are unique", + "data": [ + 1, + true + ], + "valid": true + }, + { + "description": "0 and false are unique", + "data": [ + 0, + false + ], + "valid": true + }, + { + "description": "unique heterogeneous types are valid", + "data": [ + {}, + [ + 1 + ], + true, + null, + 1 + ], + "valid": true + }, + { + "description": "non-unique heterogeneous types are valid", + "data": [ + {}, + [ + 1 + ], + true, + null, + {}, + 1 + ], + "valid": true + } + ] + }, + { + "description": "uniqueItems=false with an array of items", + "schema": { + "items": [ + { + "type": "boolean" + }, + { + "type": "boolean" + } + ], + "uniqueItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [ + false, + true + ], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [ + true, + false + ], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [ + false, + false + ], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [ + true, + true + ], + "valid": true + }, + { + "description": "unique array extended from [false, true] is valid", + "data": [ + false, + true, + "foo", + "bar" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [false,true,\"foo\",\"bar\"] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:48\n instance.json:1:1\nconflicting values bool and [false,true,\"foo\",\"bar\"] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [false,true,\"foo\",\"bar\"] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [false,true,\"foo\",\"bar\"] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [false,true,\"foo\",\"bar\"] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "unique array extended from [true, false] is valid", + "data": [ + true, + false, + "foo", + "bar" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [true,false,\"foo\",\"bar\"] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:48\n instance.json:1:1\nconflicting values bool and [true,false,\"foo\",\"bar\"] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [true,false,\"foo\",\"bar\"] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [true,false,\"foo\",\"bar\"] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [true,false,\"foo\",\"bar\"] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "non-unique array extended from [false, true] is valid", + "data": [ + false, + true, + "foo", + "foo" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [false,true,\"foo\",\"foo\"] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:48\n instance.json:1:1\nconflicting values bool and [false,true,\"foo\",\"foo\"] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [false,true,\"foo\",\"foo\"] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [false,true,\"foo\",\"foo\"] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [false,true,\"foo\",\"foo\"] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + }, + { + "description": "non-unique array extended from [true, false] is valid", + "data": [ + true, + false, + "foo", + "foo" + ], + "valid": true, + "skip": "5 errors in empty disjunction:\nconflicting values [true,false,\"foo\",\"foo\"] and {...} (mismatched types list and struct):\n generated.cue:2:1\n generated.cue:2:48\n instance.json:1:1\nconflicting values bool and [true,false,\"foo\",\"foo\"] (mismatched types bool and list):\n generated.cue:2:8\n instance.json:1:1\nconflicting values null and [true,false,\"foo\",\"foo\"] (mismatched types null and list):\n generated.cue:2:1\n instance.json:1:1\nconflicting values number and [true,false,\"foo\",\"foo\"] (mismatched types number and list):\n generated.cue:2:15\n instance.json:1:1\nconflicting values string and [true,false,\"foo\",\"foo\"] (mismatched types string and list):\n generated.cue:2:24\n instance.json:1:1\n" + } + ] + }, + { + "description": "uniqueItems=false with an array of items and additionalItems=false", + "schema": { + "items": [ + { + "type": "boolean" + }, + { + "type": "boolean" + } + ], + "uniqueItems": false, + "additionalItems": false + }, + "tests": [ + { + "description": "[false, true] from items array is valid", + "data": [ + false, + true + ], + "valid": true + }, + { + "description": "[true, false] from items array is valid", + "data": [ + true, + false + ], + "valid": true + }, + { + "description": "[false, false] from items array is valid", + "data": [ + false, + false + ], + "valid": true + }, + { + "description": "[true, true] from items array is valid", + "data": [ + true, + true + ], + "valid": true + }, + { + "description": "extra items are invalid even if unique", + "data": [ + false, + true, + null + ], + "valid": false + } + ] + } +] diff --git a/encoding/jsonschema/teststats.go b/encoding/jsonschema/teststats.go new file mode 100644 index 000000000..570236e70 --- /dev/null +++ b/encoding/jsonschema/teststats.go @@ -0,0 +1,96 @@ +//go:build ignore + +// This command prints a summary of which external tests are passing and failing. +package main + +import ( + "flag" + "fmt" + "log" + "path" + "sort" + + "cuelang.org/go/encoding/jsonschema/internal/externaltest" +) + +var list = flag.Bool("list", false, "list all failed tests") + +func main() { + tests, err := externaltest.ReadTestDir("testdata/external") + if err != nil { + log.Fatal(err) + } + flag.Parse() + if *list { + listFailures(tests) + } else { + showStats(tests) + } +} + +func showStats(tests map[string][]*externaltest.Schema) { + schemaOK := 0 + schemaTot := 0 + testOK := 0 + testTot := 0 + schemaOKTestOK := 0 + schemaOKTestTot := 0 + for _, schemas := range tests { + for _, schema := range schemas { + schemaTot++ + if schema.Skip == "" { + schemaOK++ + } + for _, test := range schema.Tests { + testTot++ + if test.Skip == "" { + testOK++ + } + if schema.Skip == "" { + schemaOKTestTot++ + if test.Skip == "" { + schemaOKTestOK++ + } + } + } + } + } + fmt.Printf("schema extract (pass / total): %d / %d = %.1f%%\n", schemaOK, schemaTot, percent(schemaOK, schemaTot)) + fmt.Printf("tests (pass / total): %d / %d = %.1f%%\n", testOK, testTot, percent(testOK, testTot)) + fmt.Printf("tests on extracted schemas (pass / total): %d / %d = %.1f%%\n", schemaOKTestOK, schemaOKTestTot, percent(schemaOKTestOK, schemaOKTestTot)) +} + +func listFailures(tests map[string][]*externaltest.Schema) { + for _, filename := range sortedKeys(tests) { + schemas := tests[filename] + filename = path.Join("testdata/external", filename) + for _, schema := range schemas { + if schema.Skip != "" { + fmt.Printf("%s: schema fail (%s)\n", filename, schema.Description) + continue + } + for _, test := range schema.Tests { + if test.Skip != "" { + reason := "fail" + if !test.Valid { + reason = "unexpected success" + } + fmt.Printf("%s: %s (%s; %s)\n", filename, reason, schema.Description, test.Description) + } + } + } + } +} + +func percent(a, b int) float64 { + return (float64(a) / float64(b)) * 100.0 +} + +func sortedKeys[T any](m map[string]T) []string { + ks := make([]string, 0, len(m)) + for k := range m { + ks = append(ks, k) + } + sort.Strings(ks) + return ks +} diff --git a/encoding/jsonschema/vendor-external b/encoding/jsonschema/vendor-external new file mode 100755 index 000000000..1ab5a620f --- /dev/null +++ b/encoding/jsonschema/vendor-external @@ -0,0 +1,17 @@ +#!/bin/sh + +set -e + +# main as of Sun May 19 19:01:03 2024 +0300 +COMMIT=9fc880bfb6d8ccd093bc82431f17d13681ffae8e + +# This script pulls in the external JSON Schema tests. + +# First check that the tests pass as is. +go test + +# Then fetch the new tests. +go run vendor_external.go -- $COMMIT + +# Then update the test results. +CUE_UPDATE=1 go test diff --git a/encoding/jsonschema/vendor_external.go b/encoding/jsonschema/vendor_external.go new file mode 100644 index 000000000..5ebee7c17 --- /dev/null +++ b/encoding/jsonschema/vendor_external.go @@ -0,0 +1,95 @@ +//go:build ignore + +package main + +import ( + "flag" + "fmt" + "io/fs" + "log" + "os" + "os/exec" + "path" + "path/filepath" + "strings" +) + +const ( + testRepo = "git@github.com:json-schema-org/JSON-Schema-Test-Suite" + testDir = "testdata/external/tests" +) + +func main() { + flag.Usage = func() { + fmt.Fprintf(os.Stderr, "usage: vendor-external commit\n") + os.Exit(2) + } + flag.Parse() + if flag.NArg() != 1 { + flag.Usage() + } + if err := doVendor(flag.Arg(0)); err != nil { + log.Fatal(err) + } +} + +func doVendor(commit string) error { + tmpDir, err := os.MkdirTemp("", "") + if err != nil { + return err + } + defer os.RemoveAll(tmpDir) + logf("cloning %s", testRepo) + if err := runCmd(tmpDir, "git", "clone", "-q", testRepo, "."); err != nil { + return err + } + logf("checking out commit %s", commit) + if err := runCmd(tmpDir, "git", "checkout", "-q", commit); err != nil { + return err + } + logf("copying files to %s", testDir) + if err := os.RemoveAll(testDir); err != nil { + return err + } + fsys := os.DirFS(filepath.Join(tmpDir, "tests")) + err = fs.WalkDir(fsys, ".", func(filename string, d fs.DirEntry, err error) error { + if err != nil { + return err + } + // Exclude draft-next (too new) and draft3 (too old). + if d.IsDir() && (filename == "draft-next" || filename == "draft3") { + return fs.SkipDir + } + // Exclude symlinks and directories + if !d.Type().IsRegular() { + return nil + } + if !strings.HasSuffix(filename, ".json") { + return nil + } + if err := os.MkdirAll(filepath.Join(testDir, path.Dir(filename)), 0o777); err != nil { + return err + } + data, err := fs.ReadFile(fsys, filename) + if err != nil { + return err + } + if err := os.WriteFile(filepath.Join(testDir, filename), data, 0o666); err != nil { + return err + } + return nil + }) + return err +} + +func runCmd(dir string, name string, args ...string) error { + c := exec.Command(name, args...) + c.Dir = dir + c.Stdout = os.Stdout + c.Stderr = os.Stderr + return c.Run() +} + +func logf(f string, a ...any) { + fmt.Fprintf(os.Stderr, "%s\n", fmt.Sprintf(f, a...)) +}