Line data Source code
1 : // Copyright 2026 The Authors
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // https://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : /// A single JSON Schema validation failure.
16 : ///
17 : /// [path] is the dot-notation path to the field that failed (e.g. `'address.city'`,
18 : /// `'tags[0]'`). An empty string means the violation is at the root document
19 : /// level (e.g. a `required` field is missing from the top-level map).
20 : ///
21 : /// [message] is a human-readable description of the constraint that was
22 : /// violated, suitable for display in error messages and logs.
23 : final class SchemaViolation {
24 : /// Creates a [SchemaViolation] at [path] with [message].
25 5 : const SchemaViolation({required this.path, required this.message});
26 :
27 : /// Dot-notation path to the offending field, or `''` for root-level violations.
28 : final String path;
29 :
30 : /// Human-readable description of the violated constraint.
31 : final String message;
32 :
33 1 : @override
34 6 : String toString() => path.isEmpty ? message : '$path: $message';
35 :
36 1 : @override
37 : bool operator ==(Object other) =>
38 1 : other is SchemaViolation &&
39 3 : other.path == path &&
40 3 : other.message == message;
41 :
42 1 : @override
43 3 : int get hashCode => Object.hash(path, message);
44 : }
|