From cbcb56c3c4bc97d2c61efef90e024d5d88717365 Mon Sep 17 00:00:00 2001 From: Thomas <34217413+thommann@users.noreply.github.com> Date: Fri, 4 Jul 2025 11:00:06 +0200 Subject: [PATCH] fix(jambo): Fix allOf constraints (#1) * Fix incorrect min/max length handling in allOf type parser and update tests accordingly * Fix schema converter test to correct allOf handling --- jambo/parser/allof_type_parser.py | 4 ++-- tests/parser/test_allof_type_parser.py | 8 ++++---- tests/test_schema_converter.py | 7 +++++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/jambo/parser/allof_type_parser.py b/jambo/parser/allof_type_parser.py index 3180ae3..709365e 100644 --- a/jambo/parser/allof_type_parser.py +++ b/jambo/parser/allof_type_parser.py @@ -74,10 +74,10 @@ class AllOfTypeParser(GenericTypeParser): return old_value + new_value if prop_name in ("maxLength", "maximum", "exclusiveMaximum"): - return old_value if old_value > new_value else new_value + return old_value if old_value < new_value else new_value if prop_name in ("minLength", "minimum", "exclusiveMinimum"): - return old_value if old_value < new_value else new_value + return old_value if old_value > new_value else new_value if prop_name == "properties": for key, value in new_value.items(): diff --git a/tests/parser/test_allof_type_parser.py b/tests/parser/test_allof_type_parser.py index 2ae4bc2..290c636 100644 --- a/tests/parser/test_allof_type_parser.py +++ b/tests/parser/test_allof_type_parser.py @@ -117,8 +117,8 @@ class TestAllOfTypeParser(TestCase): ) self.assertEqual(type_parsing, str) - self.assertEqual(type_validator["max_length"], 11) - self.assertEqual(type_validator["min_length"], 1) + self.assertEqual(type_validator["max_length"], 4) + self.assertEqual(type_validator["min_length"], 2) def test_all_of_type_parser_in_fields(self): """ @@ -138,8 +138,8 @@ class TestAllOfTypeParser(TestCase): ) self.assertEqual(type_parsing, str) - self.assertEqual(type_validator["max_length"], 11) - self.assertEqual(type_validator["min_length"], 1) + self.assertEqual(type_validator["max_length"], 4) + self.assertEqual(type_validator["min_length"], 2) def test_invalid_all_of(self): """ diff --git a/tests/test_schema_converter.py b/tests/test_schema_converter.py index fbba3c9..d25ae9a 100644 --- a/tests/test_schema_converter.py +++ b/tests/test_schema_converter.py @@ -358,10 +358,13 @@ class TestSchemaConverter(TestCase): Model = SchemaConverter.build(schema) obj = Model( - name="J", + name="John", ) - self.assertEqual(obj.name, "J") + self.assertEqual(obj.name, "John") + + with self.assertRaises(ValueError): + Model(name="J") with self.assertRaises(ValueError): Model(name="John Invalid")