feat: format and linting pre-merge

This commit is contained in:
2025-11-26 10:54:42 -03:00
parent 40106e4765
commit 27e756dadf
4 changed files with 18 additions and 34 deletions

View File

@@ -73,13 +73,11 @@ class GenericTypeParser(ABC, Generic[T]):
:param kwargs: Additional options for type parsing.
:return: A tuple containing the type and its properties.
"""
parser = cls._get_impl(
cls._normalize_properties(properties)
)
parser = cls._get_impl(cls._normalize_properties(properties))
return parser().from_properties(name=name, properties=properties, **kwargs)
@staticmethod
def _normalize_properties(properties: JSONSchema) -> JSONSchema:
"""
@@ -87,21 +85,21 @@ class GenericTypeParser(ABC, Generic[T]):
:param properties: The properties to be normalized.
"""
type_value = properties.pop("type", None)
if isinstance(type_value, str):
properties["type"] = type_value
return properties
if isinstance(type_value, list) and len(type_value) == 0:
raise InvalidSchemaException(
"Invalid schema: 'type' list cannot be empty", invalid_field=str(properties)
"Invalid schema: 'type' list cannot be empty",
invalid_field=str(properties),
)
if isinstance(type_value, list) and len(type_value) == 1:
properties["type"] = type_value[0]
return properties
if isinstance(type_value, list):
properties["anyOf"] = [{"type": t} for t in type_value]
return properties

View File

@@ -1,4 +1,4 @@
from jambo.exceptions import InternalAssertionException, InvalidSchemaException, UnsupportedSchemaException
from jambo.exceptions import InvalidSchemaException, UnsupportedSchemaException
from jambo.parser import ObjectTypeParser, RefTypeParser
from jambo.types import JSONSchema, RefCacheDict
@@ -135,11 +135,12 @@ class SchemaConverter:
"""
if "$ref" in schema:
return "$ref"
type_value = schema.get("type")
if isinstance(type_value, list):
raise InvalidSchemaException(
"Invalid schema: 'type' cannot be a list at the top level", invalid_field=str(schema)
"Invalid schema: 'type' cannot be a list at the top level",
invalid_field=str(schema),
)
return type_value

View File

@@ -42,7 +42,7 @@ JSONSchema = TypedDict(
"description": str,
"default": JSONType,
"examples": List[JSONType],
"type": JSONSchemaType|List[JSONSchemaType],
"type": JSONSchemaType | List[JSONSchemaType],
"enum": List[JSONType],
"const": JSONType,
"properties": Dict[str, "JSONSchema"],