The validation module already implemented the composable-rule idiom under its own names (Check/Issue/SubjectContext) and a value-type Validator with duplicated traversal machinery per layer. Renamed the core types to the canonical names (Validation/ValidationError/ValidationErrorCollection/ ValidationContext/BuiltinValidation/AnyValidation), converted Validator to a reference-type class with the two-tier default-rule split, and genericized it over both Subject and Document via a new Traversable protocol so the model and tagged layers share one walk engine instead of two copies. Wired the JSON-representability rule set into the same shape and closed the two missing pieces (unwrap combinator, JSON coverage/config-pin tests).
16 lines
989 B
Swift
16 lines
989 B
Swift
public extension PureYAML.Validation {
|
|
/// A tree node a `Validator` can walk. `Validator`'s traversal engine is shared by every layer
|
|
/// (validation-rules.md, principle 10); each `Traversable` conformance supplies only that layer's
|
|
/// own traversal shape: "each layer defines only its own document, its rules, and its traversal".
|
|
protocol Traversable: Validatable {
|
|
/// Extra values to offer to type-directed checks at this node, beyond the node itself (e.g. a
|
|
/// mapping's own type, or a mapping's key nodes). A `nil` path component offers at this node's
|
|
/// own path; a non-nil one offers at that child's path (e.g. a mapping key's location).
|
|
var extraOffers: [(component: Path.Component?, value: any Validatable)] { get }
|
|
|
|
/// This node's children to recurse into, each paired with the path component that reaches it
|
|
/// from this node.
|
|
var children: [(component: Path.Component, value: Self)] { get }
|
|
}
|
|
}
|