From fed844a8de4031756b937673fd840c16f2547e36 Mon Sep 17 00:00:00 2001 From: Matthew Adams Date: Tue, 10 Feb 2026 08:32:23 +0000 Subject: [PATCH 1/2] Added tests for the interaction of default and required. --- tests/draft2019-09/default.json | 26 ++++++++++++++++++++++++++ tests/draft2020-12/default.json | 26 ++++++++++++++++++++++++++ tests/draft3/default.json | 25 +++++++++++++++++++++++++ tests/draft4/default.json | 25 +++++++++++++++++++++++++ tests/draft6/default.json | 25 +++++++++++++++++++++++++ tests/draft7/default.json | 25 +++++++++++++++++++++++++ 6 files changed, 152 insertions(+) diff --git a/tests/draft2019-09/default.json b/tests/draft2019-09/default.json index 95eba5a79..f2cdf50af 100644 --- a/tests/draft2019-09/default.json +++ b/tests/draft2019-09/default.json @@ -78,5 +78,31 @@ "valid": true } ] + }, + { + "description": "the default keyword does not interact with required", + "schema": { + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "alpha": { + "type": "number", + "default": 5 + } + }, + "required": ["alpha"] + }, + "tests": [ + { + "description": "An explicit property passes required", + "data": { "alpha": 1 }, + "valid": true + }, + { + "description": "missing properties are not filled in with the default by required", + "data": {}, + "valid": false + } + ] } ] diff --git a/tests/draft2020-12/default.json b/tests/draft2020-12/default.json index ceb3ae271..2c07f8e82 100644 --- a/tests/draft2020-12/default.json +++ b/tests/draft2020-12/default.json @@ -78,5 +78,31 @@ "valid": true } ] + }, + { + "description": "the default keyword does not interact with required", + "schema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "alpha": { + "type": "number", + "default": 5 + } + }, + "required": ["alpha"] + }, + "tests": [ + { + "description": "An explicit property passes required", + "data": { "alpha": 1 }, + "valid": true + }, + { + "description": "missing properties are not filled in with the default by required", + "data": {}, + "valid": false + } + ] } ] diff --git a/tests/draft3/default.json b/tests/draft3/default.json index 289a9b66c..1d6ab1770 100644 --- a/tests/draft3/default.json +++ b/tests/draft3/default.json @@ -75,5 +75,30 @@ "valid": true } ] + }, + { + "description": "the default keyword does not interact with required", + "schema": { + "type": "object", + "properties": { + "alpha": { + "type": "number", + "default": 5 + } + }, + "required": ["alpha"] + }, + "tests": [ + { + "description": "An explicit property passes required", + "data": { "alpha": 1 }, + "valid": true + }, + { + "description": "missing properties are not filled in with the default by required", + "data": {}, + "valid": false + } + ] } ] diff --git a/tests/draft4/default.json b/tests/draft4/default.json index 289a9b66c..1d6ab1770 100644 --- a/tests/draft4/default.json +++ b/tests/draft4/default.json @@ -75,5 +75,30 @@ "valid": true } ] + }, + { + "description": "the default keyword does not interact with required", + "schema": { + "type": "object", + "properties": { + "alpha": { + "type": "number", + "default": 5 + } + }, + "required": ["alpha"] + }, + "tests": [ + { + "description": "An explicit property passes required", + "data": { "alpha": 1 }, + "valid": true + }, + { + "description": "missing properties are not filled in with the default by required", + "data": {}, + "valid": false + } + ] } ] diff --git a/tests/draft6/default.json b/tests/draft6/default.json index 289a9b66c..1d6ab1770 100644 --- a/tests/draft6/default.json +++ b/tests/draft6/default.json @@ -75,5 +75,30 @@ "valid": true } ] + }, + { + "description": "the default keyword does not interact with required", + "schema": { + "type": "object", + "properties": { + "alpha": { + "type": "number", + "default": 5 + } + }, + "required": ["alpha"] + }, + "tests": [ + { + "description": "An explicit property passes required", + "data": { "alpha": 1 }, + "valid": true + }, + { + "description": "missing properties are not filled in with the default by required", + "data": {}, + "valid": false + } + ] } ] diff --git a/tests/draft7/default.json b/tests/draft7/default.json index 289a9b66c..1d6ab1770 100644 --- a/tests/draft7/default.json +++ b/tests/draft7/default.json @@ -75,5 +75,30 @@ "valid": true } ] + }, + { + "description": "the default keyword does not interact with required", + "schema": { + "type": "object", + "properties": { + "alpha": { + "type": "number", + "default": 5 + } + }, + "required": ["alpha"] + }, + "tests": [ + { + "description": "An explicit property passes required", + "data": { "alpha": 1 }, + "valid": true + }, + { + "description": "missing properties are not filled in with the default by required", + "data": {}, + "valid": false + } + ] } ] From 81568fc9f3458986f69db6e505aa3728ff214d96 Mon Sep 17 00:00:00 2001 From: Matthew Adams Date: Tue, 10 Feb 2026 08:42:44 +0000 Subject: [PATCH 2/2] Removed incorrect draft 3 test --- tests/draft3/default.json | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/tests/draft3/default.json b/tests/draft3/default.json index 1d6ab1770..289a9b66c 100644 --- a/tests/draft3/default.json +++ b/tests/draft3/default.json @@ -75,30 +75,5 @@ "valid": true } ] - }, - { - "description": "the default keyword does not interact with required", - "schema": { - "type": "object", - "properties": { - "alpha": { - "type": "number", - "default": 5 - } - }, - "required": ["alpha"] - }, - "tests": [ - { - "description": "An explicit property passes required", - "data": { "alpha": 1 }, - "valid": true - }, - { - "description": "missing properties are not filled in with the default by required", - "data": {}, - "valid": false - } - ] } ]