[ { "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": {}, "valid": true }, { "description": "object with some properties missing is invalid", "data": {}, "valid": false } ] }, { "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": "none of the properties mentioned", "data": {}, "valid": false }, { "description": "__proto__ present", "data": {}, "valid": false }, { "description": "toString present", "data": {}, "valid": false }, { "description": "constructor present", "data": {}, "valid": false }, { "description": "all present", "data": {}, "valid": true } ] }, { "description": "basic required property validation", "enums": [], "types": [], "puncs": [ { "name": "basic_validation_test", "public": false, "schemas": [ { "$id": "basic_validation_test.request", "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "integer", "minimum": 0 } }, "required": [ "name", "age" ] } ] } ], "tests": [ { "description": "missing all required fields", "data": {}, "valid": false, "expect_errors": [ { "code": "REQUIRED_FIELD_MISSING", "path": "/name" }, { "code": "REQUIRED_FIELD_MISSING", "path": "/age" } ] }, { "description": "missing some required fields", "data": {}, "valid": false, "expect_errors": [ { "code": "REQUIRED_FIELD_MISSING", "path": "/age" } ] } ] }, { "description": "required property merging across inheritance", "enums": [], "puncs": [], "types": [ { "name": "entity", "schemas": [ { "$id": "entity", "type": "object", "properties": { "id": { "type": "string", "format": "uuid" }, "type": { "type": "string" }, "created_by": { "type": "string", "format": "uuid" } }, "required": [ "id", "type", "created_by" ] } ] }, { "name": "user", "schemas": [ { "$id": "user", "base": "entity", "$ref": "entity", "properties": { "password": { "type": "string", "minLength": 8 } }, "if": { "properties": { "type": { "const": "user" } } }, "then": { "required": [ "password" ] } } ] }, { "name": "person", "schemas": [ { "$id": "person", "base": "user", "$ref": "user", "properties": { "first_name": { "type": "string", "minLength": 1 }, "last_name": { "type": "string", "minLength": 1 } }, "if": { "properties": { "type": { "const": "person" } } }, "then": { "required": [ "first_name", "last_name" ] } } ] } ], "tests": [ { "description": "missing all required fields across inheritance chain", "schema_id": "person", "data": {}, "valid": false, "expect_errors": [ { "code": "REQUIRED_FIELD_MISSING", "path": "/id" }, { "code": "REQUIRED_FIELD_MISSING", "path": "/created_by" }, { "code": "REQUIRED_FIELD_MISSING", "path": "/first_name" }, { "code": "REQUIRED_FIELD_MISSING", "path": "/last_name" } ] }, { "description": "conditional requirements through inheritance", "schema_id": "person", "data": {}, "valid": false, "expect_errors": [ { "code": "REQUIRED_FIELD_MISSING", "path": "/first_name" }, { "code": "REQUIRED_FIELD_MISSING", "path": "/last_name" } ] } ] } ]