1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use crate::definition::Type;
use crate::validator::DocumentPath;

use std::collections::HashSet;

use serde_json;

#[derive(Debug)]
pub enum Error {
    ParseError(serde_json::Error),
    InvalidRoot,
    MissingAttribute {
        path: DocumentPath,
        attr: String,
    },
    InvalidValue {
        path: DocumentPath,
        value: serde_json::Value,
    },
    ForbiddenType {
        path: DocumentPath,
        typ: Type,
    },
    UnrecognizedAttribute {
        path: DocumentPath,
        attr: String,
    },
    UnknownType {
        path: DocumentPath,
        typ: String,
    },
    DuplicatePointer {
        path: DocumentPath,
        ptr: String,
    },
    DuplicateId {
        path: DocumentPath,
        id: String,
    },
    DuplicateName {
        path: DocumentPath,
        name: String,
    },
    // TODO: Check duplicate attributes when building attributes, etc.
    DuplicateAttribute {
        path: DocumentPath,
        attr: String,
    },
    UndefinedId {
        path: DocumentPath,
        id: String,
    },
    UnresolvedPointers {
        target: String,
        sources: HashSet<String>,
    },
}

#[derive(Debug)]
pub enum ValidationError {
    UndefinedDefinition,
    Failure {
        rule: String,
        path: Vec<String>,
        message: String,
    },
}