@@ -17,6 +17,7 @@ use MooX::HandlesVia;
17
17
use JSON::Schema::Draft201909::Annotation;
18
18
use JSON::Schema::Draft201909::Error;
19
19
use JSON::PP ();
20
+ use List::Util 1.50 ' head' ;
20
21
use namespace::clean;
21
22
22
23
use overload
@@ -70,35 +71,41 @@ sub format {
70
71
}
71
72
if ($style eq ' terse' ) {
72
73
# we can also drop errors for unevaluatedItems, unevaluatedProperties
73
- # when there is another (non-discarded) error at the same instance location (indicating that
74
- # "unevaluated" is actually "unsuccessfully evaluated").
75
- my %instance_locations ;
74
+ # when there is another (non-discarded) error at the same instance location or parent keyword
75
+ # location (indicating that "unevaluated" is actually "unsuccessfully evaluated").
76
+ my ( %instance_locations , %keyword_locations ) ;
76
77
77
78
my @errors = grep {
78
79
my ($keyword , $error ) = ($_ -> keyword, $_ -> error);
79
80
80
81
my $keep = 0+!!(
81
82
not $keyword
82
- or ($keyword =~ / ^unevaluated(?:Items|Properties)$ /
83
- and $error =~ / "$keyword " keyword present, but/ )
84
83
or (
85
- not grep $keyword eq $_ , qw( allOf anyOf if then else dependentSchemas propertyNames)
84
+ not grep $keyword eq $_ , qw( allOf anyOf if then else dependentSchemas contains propertyNames)
86
85
and ($keyword ne ' oneOf' or $error ne ' no subschemas are valid' )
87
- and ($keyword ne ' items' or $error eq ' item not permitted' )
86
+ and ($keyword ne ' items' # list form of items (prefixItems)
87
+ or $error eq ' item not permitted' and $_ -> keyword_location =~ m { /[0-9]+$} )
88
88
and ($keyword ne ' additionalItems' or $error eq ' additional item not permitted' )
89
- and ($keyword ne ' unevaluatedItems'
90
- or ($error eq ' additional item not permitted' and not $instance_locations {$_ -> instance_location}{$keyword }))
91
89
and (not grep $keyword eq $_ , qw( properties patternProperties)
92
90
or $error eq ' property not permitted' )
93
91
and ($keyword ne ' additionalProperties' or $error eq ' additional property not permitted' ))
94
- and ($keyword ne ' unevaluatedProperties'
95
- or ($error eq ' additional property not permitted' and not $instance_locations {$_ -> instance_location}{$keyword }))
96
92
);
97
93
98
- ++$instance_locations {$_ -> instance_location}-> {unevaluatedItems }
99
- if $keep and $keyword and grep $keyword eq $_ , qw( items additionalItems unevaluatedItems) ;
100
- ++$instance_locations {$_ -> instance_location}-> {unevaluatedProperties }
101
- if $keep and $keyword and grep $keyword eq $_ , qw( properties additionalProperties patternProperties unevaluatedProperties) ;
94
+ if ($keep and $keyword and $keyword =~ / ^unevaluated(?:Items|Properties)$ /
95
+ and $error !~ / "$keyword " keyword present, but/ ) {
96
+ my $parent_keyword_location = join (' /' , head(-1, split (' /' , $_ -> keyword_location)));
97
+ my $parent_instance_location = join (' /' , head(-1, split (' /' , $_ -> instance_location)));
98
+
99
+ $keep = (
100
+ (($keyword eq ' unevaluatedProperties' and $error eq ' additional property not permitted' )
101
+ or ($keyword eq ' unevaluatedItems' and $error eq ' additional item not permitted' ))
102
+ and not $instance_locations {$_ -> instance_location}
103
+ and not grep m / ^$parent_keyword_location / , keys %keyword_locations
104
+ );
105
+ }
106
+
107
+ ++$instance_locations {$_ -> instance_location} if $keep ;
108
+ ++$keyword_locations {$_ -> keyword_location} if $keep ;
102
109
103
110
$keep ;
104
111
}
0 commit comments