@@ -77,12 +77,33 @@ def _show_validation_error(
77
77
if err .context :
78
78
best_match = jsonschema .exceptions .best_match (err .context )
79
79
self ._echo ("Underlying errors caused this." , indent = 2 )
80
+ self ._echo ("" )
80
81
self ._echo ("Best Match:" , indent = 2 )
81
82
self ._echo (self ._format_validation_error_message (best_match ), indent = 4 )
83
+
84
+ best_deep_match = find_best_deep_match (err )
85
+ if best_deep_match != best_match :
86
+ self ._echo ("Best Deep Match:" , indent = 2 )
87
+ self ._echo (
88
+ self ._format_validation_error_message (best_deep_match ), indent = 4
89
+ )
90
+
82
91
if self .verbosity > 1 :
83
92
self ._echo ("All Errors:" , indent = 2 )
84
93
for e in iter_validation_error (err ):
85
94
self ._echo (self ._format_validation_error_message (e ), indent = 4 )
95
+ else :
96
+ num_other_errors = len (list (iter_validation_error (err ))) - 1
97
+ if best_deep_match != best_match :
98
+ num_other_errors -= 1
99
+ if num_other_errors > 0 :
100
+ self ._echo ("" )
101
+ self ._echo (
102
+ f"{ click .style (str (num_other_errors ), fg = 'yellow' )} other "
103
+ "errors were produced. "
104
+ "Use '--verbose' to see all errors." ,
105
+ indent = 2 ,
106
+ )
86
107
87
108
def _show_parse_error (self , filename : str , err : ParseError ) -> None :
88
109
if self .verbosity < 2 :
@@ -139,10 +160,17 @@ def _dump_error_map(
139
160
}
140
161
if err .context :
141
162
best_match = jsonschema .exceptions .best_match (err .context )
163
+ best_deep_match = find_best_deep_match (err )
142
164
item ["best_match" ] = {
143
165
"path" : best_match .json_path ,
144
166
"message" : best_match .message ,
145
167
}
168
+ item ["best_deep_match" ] = {
169
+ "path" : best_deep_match .json_path ,
170
+ "message" : best_deep_match .message ,
171
+ }
172
+ num_sub_errors = len (list (iter_validation_error (err ))) - 1
173
+ item ["num_sub_errors" ] = num_sub_errors
146
174
if self .verbosity > 1 :
147
175
item ["sub_errors" ] = [
148
176
{"path" : suberr .json_path , "message" : suberr .message }
@@ -176,3 +204,18 @@ def report_errors(self, result: CheckResult) -> None:
176
204
"text" : TextReporter ,
177
205
"json" : JsonReporter ,
178
206
}
207
+
208
+
209
+ def _deep_match_relevance (error : jsonschema .ValidationError ) -> tuple [bool | int , ...]:
210
+ validator = error .validator
211
+ return (
212
+ validator not in ("anyOf" , "oneOf" ),
213
+ len (error .absolute_path ),
214
+ - len (error .path ),
215
+ )
216
+
217
+
218
+ def find_best_deep_match (
219
+ errors : jsonschema .ValidationError ,
220
+ ) -> jsonschema .ValidationError :
221
+ return max (iter_validation_error (errors ), key = _deep_match_relevance )
0 commit comments