@@ -44,11 +44,23 @@ def is_double(instance: object) -> bool:
4444 return isinstance (instance , float )
4545
4646
47- def is_binary (instance : object ) -> bool :
48- if not isinstance (instance , (str , bytes )):
49- return True
50- if isinstance (instance , str ):
47+ def is_binary_strict (instance : object ) -> bool :
48+ # Strict: only accepts base64-encoded strings, not raw bytes
49+ if isinstance (instance , bytes ):
5150 return False
51+ if isinstance (instance , str ):
52+ try :
53+ b64decode (instance )
54+ return True
55+ except Exception :
56+ return False
57+ return True
58+
59+
60+ def is_binary_pragmatic (instance : object ) -> bool :
61+ # Pragmatic: accepts bytes (common in Python) or base64-encoded strings
62+ if isinstance (instance , (str , bytes )):
63+ return True
5264 return True
5365
5466
@@ -72,10 +84,21 @@ def is_password(instance: object) -> bool:
7284oas30_format_checker .checks ("int64" )(is_int64 )
7385oas30_format_checker .checks ("float" )(is_float )
7486oas30_format_checker .checks ("double" )(is_double )
75- oas30_format_checker .checks ("binary" )(is_binary )
87+ oas30_format_checker .checks ("binary" )(is_binary_pragmatic )
7688oas30_format_checker .checks ("byte" , (binascii .Error , TypeError ))(is_byte )
7789oas30_format_checker .checks ("password" )(is_password )
7890
91+ oas30_strict_format_checker = FormatChecker ()
92+ oas30_strict_format_checker .checks ("int32" )(is_int32 )
93+ oas30_strict_format_checker .checks ("int64" )(is_int64 )
94+ oas30_strict_format_checker .checks ("float" )(is_float )
95+ oas30_strict_format_checker .checks ("double" )(is_double )
96+ oas30_strict_format_checker .checks ("binary" )(is_binary_strict )
97+ oas30_strict_format_checker .checks ("byte" , (binascii .Error , TypeError ))(
98+ is_byte
99+ )
100+ oas30_strict_format_checker .checks ("password" )(is_password )
101+
79102oas31_format_checker = FormatChecker ()
80103oas31_format_checker .checks ("int32" )(is_int32 )
81104oas31_format_checker .checks ("int64" )(is_int64 )
0 commit comments