@@ -28,19 +28,24 @@ const containsErrorHandler = async (normalizedErrors, instance, localization) =>
2828
2929 /** @type ContainsRange */
3030 const range = { } ;
31+ const parentLocation = pointerPop ( schemaLocation ) ;
3132
3233 for ( const minContainsLocation in normalizedErrors [ "https://json-schema.org/keyword/minContains" ] ) {
33- const minContainsNode = await getSchema ( minContainsLocation ) ;
34- const minContains = /** @type number */ ( Schema . value ( minContainsNode ) ) ;
35- range . minContains = Math . max ( range . minContains ?? - 1 , minContains ) ;
36- schemaLocations . push ( minContainsLocation ) ;
34+ if ( pointerPop ( minContainsLocation ) === parentLocation ) {
35+ const minContainsNode = await getSchema ( minContainsLocation ) ;
36+ range . minContains = /** @type number */ ( Schema . value ( minContainsNode ) ) ;
37+ schemaLocations . push ( minContainsLocation ) ;
38+ break ;
39+ }
3740 }
3841
3942 for ( const maxContainsLocation in normalizedErrors [ "https://json-schema.org/keyword/maxContains" ] ) {
40- const maxContainsNode = await getSchema ( maxContainsLocation ) ;
41- const maxContains = /** @type number */ ( Schema . value ( maxContainsNode ) ) ;
42- range . maxContains = Math . min ( range . maxContains ?? Number . MAX_VALUE , maxContains ) ;
43- schemaLocations . push ( maxContainsLocation ) ;
43+ if ( pointerPop ( maxContainsLocation ) === parentLocation ) {
44+ const maxContainsNode = await getSchema ( maxContainsLocation ) ;
45+ range . maxContains = /** @type number */ ( Schema . value ( maxContainsNode ) ) ;
46+ schemaLocations . push ( maxContainsLocation ) ;
47+ break ;
48+ }
4449 }
4550
4651 errors . push ( {
@@ -54,4 +59,7 @@ const containsErrorHandler = async (normalizedErrors, instance, localization) =>
5459 return errors ;
5560} ;
5661
62+ /** @type (pointer: string) => string */
63+ const pointerPop = ( pointer ) => pointer . replace ( / \/ [ ^ / ] + $ / , "" ) ;
64+
5765export default containsErrorHandler ;
0 commit comments