@@ -80,20 +80,19 @@ const errorHandlers = [
80
80
instanceLocation : Instance . uri ( instance ) ,
81
81
schemaLocation : schemaLocation
82
82
} ) ;
83
- } else if ( alternatives . length === 1 ) {
83
+ } else if ( alternatives . length === 1 ) { // case 2 when only one type match
84
84
return getErrors ( alternatives [ 0 ] , instance ) ;
85
+ } else if ( instance . type === "object" ) {
86
+ let targetAlternativeIndex = - 1 ;
87
+ for ( const alternative of alternatives ) {
88
+ targetAlternativeIndex ++ ;
89
+ for ( const instanceLocation in alternative ) {
90
+ if ( instanceLocation !== "#" ) {
91
+ return getErrors ( alternatives [ targetAlternativeIndex ] , instance ) ;
92
+ }
93
+ }
94
+ }
85
95
}
86
-
87
- // const anyOfSchema = await getSchema(schemaLocation);
88
- // const numberOfAlternatives = Schema.length(anyOfSchema);
89
- // Instance.typeOf(instance);
90
- // const instance = Instance.fromJs(instance)
91
- // if(numberOfAlternatives == )
92
- // errors.push({
93
- // message: `The instance should be at least ${Schema.value(keyword)} characters`,
94
- // instanceLocation: Instance.uri(instance),
95
- // schemaLocation: schemaLocation
96
- // });
97
96
}
98
97
}
99
98
@@ -470,6 +469,7 @@ const errorHandlers = [
470
469
471
470
return errors ;
472
471
} ,
472
+
473
473
async ( normalizedErrors , instance ) => {
474
474
/** @type ErrorObject[] */
475
475
const errors = [ ] ;
@@ -488,31 +488,50 @@ const errorHandlers = [
488
488
}
489
489
490
490
return errors ;
491
- }
492
- ] ;
491
+ } ,
493
492
494
- /** @type (value: Json) => "null" | "boolean" | "number" | "string" | "array" | "object" | "undefined" */
495
- const jsonTypeOf = ( value ) => {
496
- const jsType = typeof value ;
497
-
498
- switch ( jsType ) {
499
- case "number" :
500
- case "string" :
501
- case "boolean" :
502
- case "undefined" :
503
- return jsType ;
504
- case "object" :
505
- if ( Array . isArray ( value ) ) {
506
- return "array" ;
507
- } else if ( value === null ) {
508
- return "null" ;
509
- } else if ( Object . getPrototypeOf ( value ) === Object . prototype ) {
510
- return "object" ;
493
+ // eslint-disable-next-line @typescript-eslint/require-await
494
+ async ( normalizedErrors , instance ) => {
495
+ /** @type ErrorObject[] */
496
+ const errors = [ ] ;
497
+
498
+ if ( normalizedErrors [ "https://json-schema.org/keyword/contains" ] ) {
499
+ for ( const schemaLocation in normalizedErrors [ "https://json-schema.org/keyword/contains" ] ) {
500
+ // const keyword = await getSchema(schemaLocation);
501
+ errors . push ( {
502
+ message : `TODO - contains` ,
503
+ instanceLocation : Instance . uri ( instance ) ,
504
+ schemaLocation : schemaLocation
505
+ } ) ;
511
506
}
512
- default : {
513
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
514
- const type = jsType === "object" ? Object . getPrototypeOf ( value ) . constructor . name ?? "anonymous" : jsType ;
515
- throw Error ( `Not a JSON compatible type: ${ type } ` ) ;
516
507
}
508
+
509
+ return errors ;
517
510
}
518
- } ;
511
+ ] ;
512
+
513
+ // /** @type (value: Json) => "null" | "boolean" | "number" | "string" | "array" | "object" | "undefined" */
514
+ // const jsonTypeOf = (value) => {
515
+ // const jsType = typeof value;
516
+
517
+ // switch (jsType) {
518
+ // case "number":
519
+ // case "string":
520
+ // case "boolean":
521
+ // case "undefined":
522
+ // return jsType;
523
+ // case "object":
524
+ // if (Array.isArray(value)) {
525
+ // return "array";
526
+ // } else if (value === null) {
527
+ // return "null";
528
+ // } else if (Object.getPrototypeOf(value) === Object.prototype) {
529
+ // return "object";
530
+ // }
531
+ // default: {
532
+ // // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
533
+ // const type = jsType === "object" ? Object.getPrototypeOf(value).constructor.name ?? "anonymous" : jsType;
534
+ // throw Error(`Not a JSON compatible type: ${type}`);
535
+ // }
536
+ // }
537
+ // };
0 commit comments