From acbb13fe5fad5e7bfa10c37fee01b55d7c4cbc8d Mon Sep 17 00:00:00 2001 From: Denis Blanchette Date: Mon, 24 Feb 2025 10:37:26 -0500 Subject: [PATCH] fix: [JSON Schema] Type "null" should be string --- schema/__init__.py | 4 ++-- test_schema.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/schema/__init__.py b/schema/__init__.py index 346e367..6340c14 100644 --- a/schema/__init__.py +++ b/schema/__init__.py @@ -701,7 +701,7 @@ def _to_schema(s: Any, ignore_extra_keys: bool) -> Schema: if len(or_values) == 1: or_value = or_values[0] if or_value is None: - return_schema["type"] = None + return_schema["type"] = "null" else: return_schema["const"] = _to_json_type(or_value) return return_schema @@ -736,7 +736,7 @@ def _to_schema(s: Any, ignore_extra_keys: bool) -> Schema: return_schema["allOf"] = all_of_values elif flavor == COMPARABLE: if s is None: - return_schema["type"] = None + return_schema["type"] = "null" else: return_schema["const"] = _to_json_type(s) elif flavor == VALIDATOR and type(s) == Regex: diff --git a/test_schema.py b/test_schema.py index a129aed..8e01c71 100644 --- a/test_schema.py +++ b/test_schema.py @@ -1146,7 +1146,7 @@ def test_json_schema_const_is_none(): assert s.json_schema("my-id") == { "$schema": "http://json-schema.org/draft-07/schema#", "$id": "my-id", - "properties": {"test": {"type": None}}, + "properties": {"test": {"type": "null"}}, "required": ["test"], "additionalProperties": False, "type": "object", @@ -1413,7 +1413,7 @@ def test_json_schema_dict_type(): } -def test_regex_json_schema(): +def test_json_schema_title_and_description(): s = Schema( { Literal(