@@ -548,19 +548,14 @@ function buildArray (context, location) {
548
548
549
549
if ( Array . isArray ( itemsSchema ) ) {
550
550
for ( let i = 0 ; i < itemsSchema . length ; i ++ ) {
551
- const item = itemsSchema [ i ]
552
551
const tmpRes = buildValue ( context , itemsLocation . getPropertyLocation ( i ) , `obj[${ i } ]` )
553
552
functionCode += `
554
553
if (${ i } < arrayLength) {
555
- if (${ buildArrayTypeCondition ( item . type , `[${ i } ]` ) } ) {
556
- let json = ''
557
- ${ tmpRes }
558
- jsonOutput += json
559
- if (${ i } < arrayLength - 1) {
560
- jsonOutput += ','
561
- }
562
- } else {
563
- throw new Error(\`Item at ${ i } does not match schema definition.\`)
554
+ let json = ''
555
+ ${ tmpRes }
556
+ jsonOutput += json
557
+ if (${ i } < arrayLength - 1) {
558
+ jsonOutput += ','
564
559
}
565
560
}
566
561
`
@@ -596,49 +591,6 @@ function buildArray (context, location) {
596
591
return functionName
597
592
}
598
593
599
- function buildArrayTypeCondition ( type , accessor ) {
600
- let condition
601
- switch ( type ) {
602
- case 'null' :
603
- condition = `obj${ accessor } === null`
604
- break
605
- case 'string' :
606
- condition = `typeof obj${ accessor } === 'string' ||
607
- obj${ accessor } === null ||
608
- obj${ accessor } instanceof Date ||
609
- obj${ accessor } instanceof RegExp ||
610
- (
611
- typeof obj${ accessor } === "object" &&
612
- typeof obj${ accessor } .toString === "function" &&
613
- obj${ accessor } .toString !== Object.prototype.toString
614
- )`
615
- break
616
- case 'integer' :
617
- condition = `Number.isInteger(obj${ accessor } )`
618
- break
619
- case 'number' :
620
- condition = `Number.isFinite(obj${ accessor } )`
621
- break
622
- case 'boolean' :
623
- condition = `typeof obj${ accessor } === 'boolean'`
624
- break
625
- case 'object' :
626
- condition = `obj${ accessor } && typeof obj${ accessor } === 'object' && obj${ accessor } .constructor === Object`
627
- break
628
- case 'array' :
629
- condition = `Array.isArray(obj${ accessor } )`
630
- break
631
- default :
632
- if ( Array . isArray ( type ) ) {
633
- const conditions = type . map ( ( subType ) => {
634
- return buildArrayTypeCondition ( subType , accessor )
635
- } )
636
- condition = `(${ conditions . join ( ' || ' ) } )`
637
- }
638
- }
639
- return condition
640
- }
641
-
642
594
function generateFuncName ( context ) {
643
595
return 'anonymous' + context . functionsCounter ++
644
596
}
0 commit comments