@@ -45,7 +45,7 @@ const anyOfErrorHandler = async (normalizedErrors, instance, localization) => {
4545 // No alternative matched the type/enum/const of the instance.
4646 if ( alternatives . length === 0 ) {
4747 /** @type Set<string> */
48- const expectedTypes = new Set ( ) ;
48+ let expectedTypes = new Set ( ) ;
4949
5050 /** @type Set<Json> */
5151 const expectedEnums = new Set ( ) ;
@@ -55,13 +55,19 @@ const anyOfErrorHandler = async (normalizedErrors, instance, localization) => {
5555 if ( instanceLocation === Instance . uri ( instance ) ) {
5656 let alternativeTypes = new Set ( [ "null" , "boolean" , "number" , "string" , "array" , "object" ] ) ;
5757 for ( const schemaLocation in alternative [ instanceLocation ] [ "https://json-schema.org/keyword/type" ] ) {
58- // TODO: Support type arrays
5958 const keyword = await getSchema ( schemaLocation ) ;
60- const expectedType = /** @type string */ ( Schema . value ( keyword ) ) ;
61- alternativeTypes = alternativeTypes . intersection ( new Set ( ( [ expectedType ] ) ) ) ;
59+ if ( Schema . typeOf ( keyword ) === "array" ) {
60+ const expectedTypes = /** @type string[] */ ( Schema . value ( keyword ) ) ;
61+ alternativeTypes = alternativeTypes . intersection ( new Set ( expectedTypes ) ) ;
62+ } else {
63+ const expectedType = /** @type string */ ( Schema . value ( keyword ) ) ;
64+ alternativeTypes = alternativeTypes . intersection ( new Set ( [ expectedType ] ) ) ;
65+ }
6266 }
63- if ( alternativeTypes . size === 1 ) {
64- expectedTypes . add ( [ ...alternativeTypes ] [ 0 ] ) ;
67+
68+ // The are 6 types. If all types are allowed, don't use expectedTypes
69+ if ( alternativeTypes . size !== 6 ) {
70+ expectedTypes = expectedTypes . union ( alternativeTypes ) ;
6571 }
6672
6773 for ( const schemaLocation in alternative [ instanceLocation ] [ "https://json-schema.org/keyword/enum" ] ) {
@@ -79,7 +85,6 @@ const anyOfErrorHandler = async (normalizedErrors, instance, localization) => {
7985 }
8086 }
8187 }
82-
8388 errors . push ( {
8489 message : localization . getEnumErrorMessage ( {
8590 allowedValues : [ ...expectedEnums ] ,
0 commit comments