Skip to content

Commit 3d86fa6

Browse files
committed
remove some duplicated error messages that add a lot of clutter but no value
1 parent aec5766 commit 3d86fa6

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

bin/php-openapi

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,34 @@ switch ($command) {
137137
}
138138
if (!$validator->isValid()) {
139139
print_formatted("\BOpenAPI v3.0 schema violations:\C\n", STDERR);
140-
foreach ($validator->getErrors() as $error) {
140+
$errors = $validator->getErrors();
141+
foreach ($errors as $error) {
142+
// hide some errors triggered by other errors further down the path
143+
if (strpos($error['message'], 'The property $ref is required') !== false && substr($error['property'], -4, 4) === '$ref') {
144+
$hasErrorInPath = false;
145+
foreach ($errors as $suberror) {
146+
if ($suberror['property'] !== $error['property'] && strpos($suberror['property'], substr($error['property'], 0, -4)) === 0) {
147+
$hasErrorInPath = true;
148+
break;
149+
}
150+
}
151+
if ($hasErrorInPath) {
152+
continue;
153+
}
154+
}
155+
if (strpos($error['message'], 'Failed to match exactly one schema') !== false) {
156+
$hasErrorInPath = false;
157+
foreach ($errors as $suberror) {
158+
if (strpos($suberror['property'], $error['property'] . '.') === 0) {
159+
$hasErrorInPath = true;
160+
break;
161+
}
162+
}
163+
if ($hasErrorInPath) {
164+
continue;
165+
}
166+
}
167+
141168
print_formatted(sprintf("- [\Y%s\C] %s\n", escape_formatted($error['property']), escape_formatted($error['message'])), STDERR);
142169
}
143170
}
@@ -306,7 +333,7 @@ function print_formatted($string, $stream) {
306333
fwrite($stream, strtr($string, [
307334
'\\Y' => "\033[33m", // yellow
308335
'\\G' => "\033[32m", // green
309-
'\\R' => "\033[31m", // green
336+
'\\R' => "\033[31m", // red
310337
'\\B' => "\033[1m", // bold
311338
'\\C' => "\033[0m", // clear
312339
'\\\\' => '\\',

0 commit comments

Comments
 (0)