fix(jambo): Add support for file-path format in StringTypeParser (#7)

This commit is contained in:
Thomas
2025-07-07 17:31:33 +02:00
committed by GitHub
parent 45018eadd1
commit 053279ba95
2 changed files with 16 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
from jambo.parser._type_parser import GenericTypeParser
from jambo.types.type_parser_options import TypeParserOptions
from pydantic import EmailStr, HttpUrl, IPvAnyAddress
from pydantic import EmailStr, HttpUrl, IPvAnyAddress, FilePath
from typing_extensions import Unpack
from datetime import date, datetime, time
@@ -28,6 +28,7 @@ class StringTypeParser(GenericTypeParser):
"time": time,
"date-time": datetime,
"binary": bytes,
"file-path": FilePath, # Added file-path format
}
format_pattern_mapping = {
@@ -56,4 +57,4 @@ class StringTypeParser(GenericTypeParser):
mapped_properties["json_schema_extra"] = {}
mapped_properties["json_schema_extra"]["format"] = format_type
return mapped_type, mapped_properties
return mapped_type, mapped_properties

View File

@@ -1,6 +1,6 @@
from jambo.parser import StringTypeParser
from pydantic import EmailStr, HttpUrl, IPvAnyAddress
from pydantic import EmailStr, HttpUrl, IPvAnyAddress, FilePath
from datetime import date, datetime, time
from unittest import TestCase
@@ -159,6 +159,18 @@ class TestStringTypeParser(TestCase):
type_validator["pattern"], parser.format_pattern_mapping[format_type]
)
def test_string_parser_with_file_path_format(self):
parser = StringTypeParser()
properties = {
"type": "string",
"format": "file-path",
}
type_parsing, type_validator = parser.from_properties("placeholder", properties)
self.assertEqual(type_parsing, FilePath)
def test_string_parser_with_unsupported_format(self):
parser = StringTypeParser()