public extension PureYAML.Validation { /// The caseless namespace of built-in type-directed checks, referenceable by name. enum BuiltinValidation { /// Reports each duplicate key within a single mapping. The type-directed counterpart of the /// legacy `Rule.mappingKeysAreUnique`; fires on `Model.Mapping` values directly rather than /// switching on a `Model.Value`. public static var mappingKeysAreUnique: Validation { Validation(description: "Mapping keys are unique") { context in var seen = Set() var errors: [ValidationError] = [] for pair in context.subject.pairs where !seen.insert(pair.keyNode).inserted { errors.append(ValidationError( severity: .error, reason: "Duplicate mapping key '\(pair.keyNode.description)'", path: context.path.appending(pair.keyNode.pathComponent), )) } return errors } } } } extension PureYAML.Model.Key { /// The path component a duplicate-key error points at: a plain `.key` for a string key, a /// `.complexKey` for a sequence or mapping key (which has no string spelling). var pathComponent: PureYAML.Validation.Path.Component { switch self { case let .string(value): .key(value) case .mapping, .sequence: .complexKey(self) } } }