fix: fixes invalid subobject required

This commit is contained in:
2025-11-24 17:34:29 +00:00
committed by GitHub
parent e775b53f7d
commit 2da409e6df
2 changed files with 37 additions and 3 deletions

View File

@@ -23,9 +23,13 @@ class ObjectTypeParser(GenericTypeParser):
)
type_properties = self.mappings_properties_builder(properties, **kwargs)
if (default_value := type_properties.pop("default", None)) is not None:
type_properties["default_factory"] = lambda: type_parsing.model_validate(
default_value
if (
default_value := type_properties.pop("default", None)
) is not None or not kwargs.get("required", False):
type_properties["default_factory"] = (
lambda: type_parsing.model_validate(default_value)
if default_value is not None
else None
)
if (example_values := type_properties.pop("examples", None)) is not None:

View File

@@ -836,3 +836,33 @@ class TestSchemaConverter(TestCase):
second_type = get_args(arg2)[0]
self.assertNotEqual(first_type.__name__, second_type.__name__)
def test_object_invalid_require(self):
# https://github.com/HideyoshiNakazone/jambo/issues/60
object_ = SchemaConverter.build(
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "TEST",
"type": "object",
"required": ["title"],
"properties": {
"title": {
"type": "string",
"description": "The title of the object",
},
"description": {
"type": "object",
"properties": {
"summary": {
"type": "string",
},
"details": {
"type": "string",
},
},
},
},
}
)
self.assertFalse(object_.model_fields["description"].is_required()) # FAIL