@@ -12,8 +12,34 @@ const type = async (normalizedErrors, instance, localization) => {
1212 const errors = [ ] ;
1313
1414 if ( normalizedErrors [ "https://json-schema.org/keyword/type" ] ) {
15+ let allowedTypes = new Set ( [ "null" , "boolean" , "number" , "string" , "array" , "object" , "integer" ] ) ;
16+ const failedTypeLocations = [ ] ;
17+
1518 for ( const schemaLocation in normalizedErrors [ "https://json-schema.org/keyword/type" ] ) {
16- if ( ! normalizedErrors [ "https://json-schema.org/keyword/type" ] [ schemaLocation ] ) {
19+ const isValid = normalizedErrors [ "https://json-schema.org/keyword/type" ] [ schemaLocation ] ;
20+ if ( ! isValid ) {
21+ failedTypeLocations . push ( schemaLocation ) ;
22+ }
23+
24+ const keyword = await getSchema ( schemaLocation ) ;
25+ /** @type {string|string[] } */
26+ const value = Schema . value ( keyword ) ;
27+ const types = Array . isArray ( value ) ? value : [ value ] ;
28+ /** @type {Set<string> } */
29+ const keywordTypes = new Set ( types ) ;
30+ allowedTypes = allowedTypes . intersection ( keywordTypes ) ;
31+ }
32+
33+ if ( allowedTypes . size === 0 ) {
34+ if ( failedTypeLocations . length > 0 ) {
35+ errors . push ( {
36+ message : localization . getConflictingTypeMessage ( ) ,
37+ instanceLocation : Instance . uri ( instance ) ,
38+ schemaLocation : failedTypeLocations [ 0 ]
39+ } ) ;
40+ }
41+ } else {
42+ for ( const schemaLocation of failedTypeLocations ) {
1743 const keyword = await getSchema ( schemaLocation ) ;
1844 errors . push ( {
1945 message : localization . getTypeErrorMessage ( Schema . value ( keyword ) , Instance . typeOf ( instance ) ) ,
0 commit comments