Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python/semantic_kernel/schema/kernel_json_schema_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
dict: "object",
set: "array",
tuple: "array",
type(None): "null",
"int": "integer",
"str": "string",
"bool": "boolean",
Expand All @@ -28,6 +29,8 @@
"tuple": "array",
"object": "object",
"array": "array",
"None": "null",
"NoneType": "null",
}


Expand Down
21 changes: 21 additions & 0 deletions python/tests/unit/schema/test_schema_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,27 @@ def test_build_optional():
assert schema == {"type": ["integer", "null"]}


def test_get_json_schema_none_type():
# NoneType maps to the JSON Schema "null" type, not "object".
assert KernelJsonSchemaBuilder.get_json_schema(type(None)) == {"type": "null"}


def test_build_none_type():
assert KernelJsonSchemaBuilder.build(type(None)) == {"type": "null"}


def test_build_union_with_none():
# A union of more than two members that includes None must represent the
# None member as {"type": "null"}, not {"type": "object"}.
schema = KernelJsonSchemaBuilder.build(Union[int, str, None])
assert schema == {"anyOf": [{"type": "integer"}, {"type": "string"}, {"type": "null"}]}


def test_build_from_type_name_none():
assert KernelJsonSchemaBuilder.build_from_type_name("None") == {"type": "null"}
assert KernelJsonSchemaBuilder.build_from_type_name("NoneType") == {"type": "null"}


def test_build_model_schema_for_many_types():
schema = KernelJsonSchemaBuilder.build(MockModel)
expected = """
Expand Down
Loading