Removes OneOf due to complexity and niche use case

After further analysis, the functionality was deemed too complex to implement for such a niche use case and will therefore be removed from the implementation backlog
This commit is contained in:
2025-04-17 16:06:55 -03:00
parent dc350aaa8b
commit 5fdb4fa724
4 changed files with 54 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
# Exports generic type parser # Exports generic type parser
from ._type_parser import GenericTypeParser as GenericTypeParser from ._type_parser import GenericTypeParser as GenericTypeParser
from .allof_type_parser import AllOfTypeParser as AllOfTypeParser from .allof_type_parser import AllOfTypeParser as AllOfTypeParser
from .anyof_type_parser import AnyOfTypeParser as AnyOfTypeParser
from .array_type_parser import ArrayTypeParser as ArrayTypeParser from .array_type_parser import ArrayTypeParser as ArrayTypeParser
from .boolean_type_parser import BooleanTypeParser as BooleanTypeParser from .boolean_type_parser import BooleanTypeParser as BooleanTypeParser
from .float_type_parser import FloatTypeParser as FloatTypeParser from .float_type_parser import FloatTypeParser as FloatTypeParser

View File

@@ -0,0 +1,28 @@
from jambo.parser._type_parser import GenericTypeParser
from typing import Union
class AnyOfTypeParser(GenericTypeParser):
mapped_type = Union
json_schema_type = "anyOf"
@staticmethod
def from_properties(name, properties):
if "anyOf" not in properties:
raise ValueError(f"Invalid JSON Schema: {properties}")
if not isinstance(properties["anyOf"], list):
raise ValueError(f"Invalid JSON Schema: {properties['anyOf']}")
subProperties = properties["anyOf"]
types = [
GenericTypeParser.get_impl(subProperty["type"]).from_properties(
name, subProperty
)
for subProperty in subProperties
]
return Union[*(t for t, v in types)], {}

View File

@@ -84,8 +84,6 @@ class SchemaConverter:
_field_type = "anyOf" _field_type = "anyOf"
case {"allOf": _}: case {"allOf": _}:
_field_type = "allOf" _field_type = "allOf"
case {"oneOf": _}:
_field_type = "oneOf"
case {"type": _}: case {"type": _}:
_field_type = properties["type"] _field_type = properties["type"]
case _: case _:

View File

@@ -0,0 +1,25 @@
from jambo.parser.anyof_type_parser import AnyOfTypeParser
from typing import Union, get_args, get_origin
from unittest import TestCase
class TestAnyOfTypeParser(TestCase):
def test_any_of_string_or_int(self):
"""
Tests the AnyOfTypeParser with a string or int type.
"""
properties = {
"anyOf": [
{"type": "string"},
{"type": "integer"},
],
}
type_parsing, _ = AnyOfTypeParser.from_properties("placeholder", properties)
# check union type has string and int
self.assertEqual(get_origin(type_parsing), Union)
self.assertIn(str, get_args(type_parsing))
self.assertIn(int, get_args(type_parsing))