Merge pull request #61 from HideyoshiNakazone/fix/object-invalid-required
fix: fixes invalid subobject required
This commit was merged in pull request #61.
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user