88from jsonschema .exceptions import best_match
99
1010from openapi_spec_validator import __version__
11+ from openapi_spec_validator import schemas
1112from openapi_spec_validator .readers import read_from_filename
1213from openapi_spec_validator .readers import read_from_stdin
1314from openapi_spec_validator .shortcuts import get_validator_cls
@@ -38,6 +39,7 @@ def print_validationerror(
3839 exc : ValidationError ,
3940 subschema_errors : str = "best-match" ,
4041 index : int | None = None ,
42+ supports_subschema_details : bool = True ,
4143) -> None :
4244 if index is None :
4345 print (f"{ filename } : Validation Error: { exc } " )
@@ -48,6 +50,13 @@ def print_validationerror(
4850 print (exc .cause )
4951 if not exc .context :
5052 return
53+ if not supports_subschema_details :
54+ print ("\n \n # Subschema details\n " )
55+ print (
56+ "Subschema error details are not available "
57+ "with jsonschema-rs backend."
58+ )
59+ return
5160 if subschema_errors == "all" :
5261 print ("\n \n # Due to one of those errors\n " )
5362 print ("\n \n \n " .join ("## " + str (e ) for e in exc .context ))
@@ -139,6 +148,10 @@ def main(args: Sequence[str] | None = None) -> None:
139148 if subschema_errors is None :
140149 subschema_errors = "best-match"
141150
151+ supports_subschema_details = (
152+ schemas .get_validator_backend () != "jsonschema-rs"
153+ )
154+
142155 for filename in args_parsed .file :
143156 # choose source
144157 reader = read_from_filename
@@ -181,6 +194,9 @@ def main(args: Sequence[str] | None = None) -> None:
181194 err ,
182195 subschema_errors ,
183196 index = idx ,
197+ supports_subschema_details = (
198+ supports_subschema_details
199+ ),
184200 )
185201 print (f"{ filename } : { len (errors )} validation errors found" )
186202 sys .exit (1 )
@@ -189,7 +205,12 @@ def main(args: Sequence[str] | None = None) -> None:
189205
190206 validate (spec , base_uri = base_uri , cls = validator_cls )
191207 except ValidationError as exc :
192- print_validationerror (filename , exc , subschema_errors )
208+ print_validationerror (
209+ filename ,
210+ exc ,
211+ subschema_errors ,
212+ supports_subschema_details = supports_subschema_details ,
213+ )
193214 sys .exit (1 )
194215 except Exception as exc :
195216 print_error (filename , exc )
0 commit comments