Skip to content

Commit be0a85f

Browse files
committed
feat: support dependentSchemas
1 parent 3d5cd2c commit be0a85f

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

Sources/Draft201909Validator.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class Draft201909Validator: Validator {
2121
"const": const,
2222
"format": format,
2323
"dependencies": dependencies,
24+
"dependentSchemas": dependentSchemas,
2425
"allOf": allOf,
2526
"oneOf": oneOf,
2627
"anyOf": anyOf,

Sources/Validators.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,23 @@ func dependentRequired(validator: Validator, dependentRequired: Any, instance: A
560560
}))
561561
}
562562

563+
func dependentSchemas(validator: Validator, dependentRequired: Any, instance: Any, schema: [String: Any]) -> ValidationResult {
564+
guard let instance = instance as? [String: Any] else {
565+
return .valid
566+
}
567+
568+
guard let dependentRequired = dependentRequired as? [String: Any] else {
569+
return .valid
570+
}
571+
572+
return flatten(dependentRequired.compactMap({ (key, subschema) -> ValidationResult? in
573+
if instance.keys.contains(key) {
574+
return validator.descend(instance: instance, subschema: subschema)
575+
}
576+
577+
return nil
578+
}))
579+
}
563580

564581
func propertyNames(validator: Validator, propertyNames: Any, instance: Any, schema: [String: Any]) -> ValidationResult {
565582
guard let instance = instance as? [String: Any] else {

Tests/JSONSchemaTests/JSONSchemaCases.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ class JSONSchemaCases: XCTestCase {
123123
"ref.json",
124124
"refRemote.json",
125125
"anchor.json",
126-
"dependentSchemas.json",
127126
"unevaluatedProperties.json",
128127
"unevaluatedItems.json",
129128

0 commit comments

Comments
 (0)