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

@@ -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)