[ { "description": "object properties validation", "database": { "schemas": [ { "$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": {}, "valid": true }, { "description": "ignores arrays", "data": [], "valid": true }, { "description": "ignores other non-objects", "data": 12, "valid": true } ] }, { "description": "properties with boolean schema", "database": { "schemas": [ { "$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", "database": { "schemas": [ { "$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", "database": { "schemas": [ { "$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.", "database": { "schemas": [ { "$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 } ] }, { "description": "extensible: true allows extra properties", "database": { "schemas": [ { "$schema": "https://json-schema.org/draft/2020-12/schema", "properties": { "foo": { "type": "integer" } }, "extensible": true } ] }, "tests": [ { "description": "extra property is valid", "data": { "foo": 1, "bar": "baz" }, "valid": true } ] }, { "description": "strict by default: extra properties invalid", "database": { "schemas": [ { "$schema": "https://json-schema.org/draft/2020-12/schema", "properties": { "foo": { "type": "string" } } } ] }, "tests": [ { "description": "extra property is invalid", "data": { "foo": "bar", "extra": 1 }, "valid": false } ] }, { "description": "inheritance: nested object inherits strictness from strict parent", "database": { "schemas": [ { "$schema": "https://json-schema.org/draft/2020-12/schema", "properties": { "nested": { "properties": { "foo": { "type": "string" } } } } } ] }, "tests": [ { "description": "nested extra property is invalid", "data": { "nested": { "foo": "bar", "extra": 1 } }, "valid": false } ] }, { "description": "override: nested object allows extra properties if extensible: true", "database": { "schemas": [ { "$schema": "https://json-schema.org/draft/2020-12/schema", "properties": { "nested": { "extensible": true, "properties": { "foo": { "type": "string" } } } } } ] }, "tests": [ { "description": "nested extra property is valid", "data": { "nested": { "foo": "bar", "extra": 1 } }, "valid": true } ] }, { "description": "inheritance: nested object inherits looseness from loose parent", "database": { "schemas": [ { "$schema": "https://json-schema.org/draft/2020-12/schema", "extensible": true, "properties": { "nested": { "properties": { "foo": { "type": "string" } } } } } ] }, "tests": [ { "description": "nested extra property is valid", "data": { "nested": { "foo": "bar", "extra": 1 } }, "valid": true } ] }, { "description": "override: nested object enforces strictness if extensible: false", "database": { "schemas": [ { "$schema": "https://json-schema.org/draft/2020-12/schema", "extensible": true, "properties": { "nested": { "extensible": false, "properties": { "foo": { "type": "string" } } } } } ] }, "tests": [ { "description": "nested extra property is invalid", "data": { "nested": { "foo": "bar", "extra": 1 } }, "valid": false } ] }, { "description": "arrays: inline items inherit strictness from strict parent", "database": { "schemas": [ { "$schema": "https://json-schema.org/draft/2020-12/schema", "properties": { "list": { "type": "array", "items": { "properties": { "foo": { "type": "string" } } } } } } ] }, "tests": [ { "description": "array item with extra property is invalid (strict parent)", "data": { "list": [ { "foo": "bar", "extra": 1 } ] }, "valid": false } ] }, { "description": "arrays: inline items inherit looseness from loose parent", "database": { "schemas": [ { "$schema": "https://json-schema.org/draft/2020-12/schema", "extensible": true, "properties": { "list": { "type": "array", "items": { "properties": { "foo": { "type": "string" } } } } } } ] }, "tests": [ { "description": "array item with extra property is valid (loose parent)", "data": { "list": [ { "foo": "bar", "extra": 1 } ] }, "valid": true } ] } ]