@@ -764,7 +764,7 @@ const compileSchema = (schema, root, opts, scope, basePathRoot = '') => {
764
764
errorIf ( safeand ( present ( item ) , condition ) , errorArgs )
765
765
}
766
766
} else if ( isSchemaish ( deps ) && dependencies !== 'dependentRequired' ) {
767
- uncertain ( dependencies )
767
+ uncertain ( dependencies ) // TODO: we don't always need this, remove when no uncertainity?
768
768
fun . if ( item . checked ? true : present ( item ) , ( ) => {
769
769
const delta = rule ( current , deps , subPath ( dependencies , key ) , dyn )
770
770
evaluateDelta ( orDelta ( { } , delta ) )
@@ -776,6 +776,27 @@ const compileSchema = (schema, root, opts, scope, basePathRoot = '') => {
776
776
} )
777
777
}
778
778
779
+ handle ( 'propertyDependencies' , [ 'object' ] , ( propertyDependencies ) => {
780
+ for ( const [ key , variants ] of Object . entries ( propertyDependencies ) ) {
781
+ enforce ( isPlainObject ( variants ) , 'propertyDependencies must be an object' )
782
+ uncertain ( 'propertyDependencies' ) // TODO: we don't always need this, remove when no uncertainity?
783
+ const item = currPropImm ( key , checked ( key ) )
784
+ // NOTE: would it be useful to also check if it's a string?
785
+ fun . if ( item . checked ? true : present ( item ) , ( ) => {
786
+ for ( const [ val , deps ] of Object . entries ( variants ) ) {
787
+ enforce ( isSchemaish ( deps ) , 'propertyDependencies must contain schemas' )
788
+ fun . if ( compare ( buildName ( item ) , val ) , ( ) => {
789
+ // TODO: we already know that we have an object here, optimize?
790
+ const delta = rule ( current , deps , subPath ( 'propertyDependencies' , key , val ) , dyn )
791
+ evaluateDelta ( orDelta ( { } , delta ) )
792
+ evaluateDeltaDynamic ( delta )
793
+ } )
794
+ }
795
+ } )
796
+ }
797
+ return null
798
+ } )
799
+
779
800
handle ( 'properties' , [ 'object' ] , ( properties ) => {
780
801
for ( const p of Object . keys ( properties ) ) {
781
802
if ( constProp === p ) continue // checked in discriminator, avoid double-check
@@ -1181,8 +1202,9 @@ const compileSchema = (schema, root, opts, scope, basePathRoot = '') => {
1181
1202
const logicalOp = [ 'not' , 'if' , 'then' , 'else' ] . includes ( schemaPath [ schemaPath . length - 1 ] )
1182
1203
const branchOp = [ 'oneOf' , 'anyOf' , 'allOf' ] . includes ( schemaPath [ schemaPath . length - 2 ] )
1183
1204
const depOp = [ 'dependencies' , 'dependentSchemas' ] . includes ( schemaPath [ schemaPath . length - 2 ] )
1205
+ const propDepOp = [ 'propertyDependencies' ] . includes ( schemaPath [ schemaPath . length - 3 ] )
1184
1206
// Coherence check, unreachable, double-check that we came from expected path
1185
- enforce ( logicalOp || branchOp || depOp , 'Unexpected' )
1207
+ enforce ( logicalOp || branchOp || depOp || propDepOp , 'Unexpected logical path ' )
1186
1208
} else if ( ! schemaPath . includes ( 'not' ) ) {
1187
1209
// 'not' does not mark anything as evaluated (unlike even if/then/else), so it's safe to exclude from these
1188
1210
// checks, as we are sure that everything will be checked without it. It can be viewed as a pure add-on.
0 commit comments