feat: Add binary and file-path string format support

Add support for two additional JSON Schema string formats:
- 'binary' -> bytes (for base64-encoded binary data)
- 'file-path' -> FilePath (for filesystem paths)
This commit is contained in:
Joel Barmettler
2026-01-21 15:48:16 +01:00
parent a75ad61a21
commit 1da93a4d25
2 changed files with 29 additions and 2 deletions

View File

@@ -2,7 +2,7 @@ from jambo.exceptions import InvalidSchemaException
from jambo.parser._type_parser import GenericTypeParser
from jambo.types.type_parser_options import TypeParserOptions
from pydantic import AnyUrl, EmailStr, TypeAdapter, ValidationError
from pydantic import AnyUrl, EmailStr, FilePath, TypeAdapter, ValidationError
from typing_extensions import Unpack
from datetime import date, datetime, time, timedelta
@@ -38,6 +38,9 @@ class StringTypeParser(GenericTypeParser):
"uri": AnyUrl,
# "iri" # Not supported by pydantic and currently not supported by jambo
"uuid": UUID,
# Additional formats
"binary": bytes,
"file-path": FilePath,
}
format_pattern_mapping = {

View File

@@ -1,7 +1,7 @@
from jambo.exceptions import InvalidSchemaException
from jambo.parser import StringTypeParser
from pydantic import AnyUrl, EmailStr
from pydantic import AnyUrl, EmailStr, FilePath
from datetime import date, datetime, time, timedelta, timezone
from ipaddress import IPv4Address, IPv6Address, ip_address
@@ -319,3 +319,27 @@ class TestStringTypeParser(TestCase):
timedelta(seconds=0.5),
],
)
def test_string_parser_with_binary_format(self):
parser = StringTypeParser()
properties = {
"type": "string",
"format": "binary",
}
type_parsing, type_validator = parser.from_properties("placeholder", properties)
self.assertEqual(type_parsing, bytes)
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)