feat: duration string parser #73

Merged
JCHacking merged 2 commits from string-duration into main 2025-12-06 19:53:27 +00:00
Showing only changes of commit 422cc2efe0 - Show all commits

View File

@@ -2,7 +2,7 @@ from jambo.exceptions import InvalidSchemaException
from jambo.parser._type_parser import GenericTypeParser from jambo.parser._type_parser import GenericTypeParser
from jambo.types.type_parser_options import TypeParserOptions from jambo.types.type_parser_options import TypeParserOptions
from pydantic import AnyUrl, EmailStr, TypeAdapter from pydantic import AnyUrl, EmailStr, TypeAdapter, ValidationError
from typing_extensions import Unpack from typing_extensions import Unpack
from datetime import date, datetime, time, timedelta from datetime import date, datetime, time, timedelta
@@ -62,11 +62,16 @@ class StringTypeParser(GenericTypeParser):
if format_type in self.format_pattern_mapping: if format_type in self.format_pattern_mapping:
mapped_properties["pattern"] = self.format_pattern_mapping[format_type] mapped_properties["pattern"] = self.format_pattern_mapping[format_type]
if "examples" in mapped_properties: try:
mapped_properties["examples"] = [ if "examples" in mapped_properties:
TypeAdapter(mapped_type).validate_python(example) mapped_properties["examples"] = [
for example in mapped_properties["examples"] TypeAdapter(mapped_type).validate_python(example)
] for example in mapped_properties["examples"]
]
except ValidationError as err:
raise InvalidSchemaException(
f"Invalid example type for field {name}."
) from err
if "json_schema_extra" not in mapped_properties: if "json_schema_extra" not in mapped_properties:
mapped_properties["json_schema_extra"] = {} mapped_properties["json_schema_extra"] = {}