@@ -602,7 +602,8 @@ function validate(
602
602
originalSchema : JSONSchema ,
603
603
validationResult : ValidationResult ,
604
604
matchingSchemas : ISchemaCollector ,
605
- options : Options
605
+ options : Options ,
606
+ isAdditionalPropertiesCheck ?: boolean
606
607
// eslint-disable-next-line @typescript-eslint/no-explicit-any
607
608
) : any {
608
609
const { isKubernetes } = options ;
@@ -646,6 +647,18 @@ function validate(
646
647
return node . type === type || ( type === 'integer' && node . type === 'number' && node . isInteger ) ;
647
648
}
648
649
650
+ function matchesSchemaType ( schema : JSONSchema ) : boolean {
651
+ /* when schema type is object and it contains oneOf then needs to validate that particular types
652
+ reference issue 692
653
+ */
654
+ const type = Array . isArray ( schema . type ) ? undefined : schema . type ;
655
+ if ( type === 'object' && typeof schema . additionalProperties === 'object' && schema . additionalProperties . oneOf ) {
656
+ return true ;
657
+ } else if ( type ) {
658
+ return matchesType ( type ) ;
659
+ }
660
+ }
661
+
649
662
if ( Array . isArray ( schema . type ) ) {
650
663
if ( ! schema . type . some ( matchesType ) ) {
651
664
validationResult . problems . push ( {
@@ -659,7 +672,7 @@ function validate(
659
672
} ) ;
660
673
}
661
674
} else if ( schema . type ) {
662
- if ( ! matchesType ( schema . type ) ) {
675
+ if ( ! matchesSchemaType ( schema ) ) {
663
676
//get more specific name than just object
664
677
const schemaType = schema . type === 'object' ? getSchemaTypeName ( schema ) : schema . type ;
665
678
validationResult . problems . push ( {
@@ -678,6 +691,13 @@ function validate(
678
691
validate ( node , asSchema ( subSchemaRef ) , schema , validationResult , matchingSchemas , options ) ;
679
692
}
680
693
}
694
+ if ( schema . additionalProperties && typeof schema . additionalProperties === 'object' && schema . additionalProperties . oneOf ) {
695
+ const propertyValidationResult = new ValidationResult ( isKubernetes ) ;
696
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
697
+ validate ( node , < any > schema . additionalProperties , schema , propertyValidationResult , matchingSchemas , options , true ) ;
698
+ validationResult . mergePropertyMatch ( propertyValidationResult ) ;
699
+ validationResult . mergeEnumValues ( propertyValidationResult ) ;
700
+ }
681
701
const notSchema = asSchema ( schema . not ) ;
682
702
if ( notSchema ) {
683
703
const subValidationResult = new ValidationResult ( isKubernetes ) ;
@@ -727,7 +747,14 @@ function validate(
727
747
} else if ( isKubernetes ) {
728
748
bestMatch = alternativeComparison ( subValidationResult , bestMatch , subSchema , subMatchingSchemas ) ;
729
749
} else {
730
- bestMatch = genericComparison ( maxOneMatch , subValidationResult , bestMatch , subSchema , subMatchingSchemas ) ;
750
+ bestMatch = genericComparison (
751
+ maxOneMatch ,
752
+ subValidationResult ,
753
+ bestMatch ,
754
+ subSchema ,
755
+ subMatchingSchemas ,
756
+ isAdditionalPropertiesCheck
757
+ ) ;
731
758
}
732
759
}
733
760
@@ -1429,7 +1456,8 @@ function validate(
1429
1456
matchingSchemas : ISchemaCollector ;
1430
1457
} ,
1431
1458
subSchema ,
1432
- subMatchingSchemas
1459
+ subMatchingSchemas ,
1460
+ isAdditionalPropertiesCheck ?: boolean
1433
1461
) : {
1434
1462
schema : JSONSchema ;
1435
1463
validationResult : ValidationResult ;
@@ -1442,7 +1470,7 @@ function validate(
1442
1470
bestMatch . validationResult . propertiesValueMatches += subValidationResult . propertiesValueMatches ;
1443
1471
} else {
1444
1472
const compareResult = subValidationResult . compareGeneric ( bestMatch . validationResult ) ;
1445
- if ( compareResult > 0 ) {
1473
+ if ( compareResult > 0 || isAdditionalPropertiesCheck ) {
1446
1474
// our node is the best matching so far
1447
1475
bestMatch = {
1448
1476
schema : subSchema ,
0 commit comments