forked from qri-io/jsonschema
-
Notifications
You must be signed in to change notification settings - Fork 0
/
draft2019_09_keywords.go
111 lines (95 loc) · 3.69 KB
/
draft2019_09_keywords.go
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package jsonschema
// LoadDraft2019_09 loads the keywords for schema validation
// based on draft2019_09
// this is also the default keyword set loaded automatically
// if no other is loaded
func LoadDraft2019_09() {
r, release := getGlobalKeywordRegistry()
defer release()
r.LoadDraft2019_09()
}
// DefaultIfEmpty populates the KeywordRegistry with the 2019_09
// jsonschema draft specification only if the registry is empty.
func (r *KeywordRegistry) DefaultIfEmpty() {
if !r.IsRegistryLoaded() {
r.LoadDraft2019_09()
}
}
// LoadDraft2019_09 loads the keywords for schema validation
// based on draft2019_09
// this is also the default keyword set loaded automatically
// if no other is loaded
func (r *KeywordRegistry) LoadDraft2019_09() {
// core keywords
r.RegisterKeyword("$schema", NewSchemaURI)
r.RegisterKeyword("$id", NewID)
r.RegisterKeyword("description", NewDescription)
r.RegisterKeyword("title", NewTitle)
r.RegisterKeyword("$comment", NewComment)
r.RegisterKeyword("examples", NewExamples)
r.RegisterKeyword("readOnly", NewReadOnly)
r.RegisterKeyword("writeOnly", NewWriteOnly)
r.RegisterKeyword("$ref", NewRef)
r.RegisterKeyword("$recursiveRef", NewRecursiveRef)
r.RegisterKeyword("$anchor", NewAnchor)
r.RegisterKeyword("$recursiveAnchor", NewRecursiveAnchor)
r.RegisterKeyword("$defs", NewDefs)
r.RegisterKeyword("default", NewDefault)
r.SetKeywordOrder("$ref", 0)
r.SetKeywordOrder("$recursiveRef", 0)
// standard keywords
r.RegisterKeyword("type", NewType)
r.RegisterKeyword("enum", NewEnum)
r.RegisterKeyword("const", NewConst)
// numeric keywords
r.RegisterKeyword("multipleOf", NewMultipleOf)
r.RegisterKeyword("maximum", NewMaximum)
r.RegisterKeyword("exclusiveMaximum", NewExclusiveMaximum)
r.RegisterKeyword("minimum", NewMinimum)
r.RegisterKeyword("exclusiveMinimum", NewExclusiveMinimum)
// string keywords
r.RegisterKeyword("maxLength", NewMaxLength)
r.RegisterKeyword("minLength", NewMinLength)
r.RegisterKeyword("pattern", NewPattern)
// boolean keywords
r.RegisterKeyword("allOf", NewAllOf)
r.RegisterKeyword("anyOf", NewAnyOf)
r.RegisterKeyword("oneOf", NewOneOf)
r.RegisterKeyword("not", NewNot)
// object keywords
r.RegisterKeyword("properties", NewProperties)
r.RegisterKeyword("patternProperties", NewPatternProperties)
r.RegisterKeyword("additionalProperties", NewAdditionalProperties)
r.RegisterKeyword("required", NewRequired)
r.RegisterKeyword("propertyNames", NewPropertyNames)
r.RegisterKeyword("maxProperties", NewMaxProperties)
r.RegisterKeyword("minProperties", NewMinProperties)
r.RegisterKeyword("dependentSchemas", NewDependentSchemas)
r.RegisterKeyword("dependentRequired", NewDependentRequired)
r.RegisterKeyword("unevaluatedProperties", NewUnevaluatedProperties)
r.SetKeywordOrder("properties", 2)
r.SetKeywordOrder("additionalProperties", 3)
r.SetKeywordOrder("unevaluatedProperties", 4)
// array keywords
r.RegisterKeyword("items", NewItems)
r.RegisterKeyword("additionalItems", NewAdditionalItems)
r.RegisterKeyword("maxItems", NewMaxItems)
r.RegisterKeyword("minItems", NewMinItems)
r.RegisterKeyword("uniqueItems", NewUniqueItems)
r.RegisterKeyword("contains", NewContains)
r.RegisterKeyword("maxContains", NewMaxContains)
r.RegisterKeyword("minContains", NewMinContains)
r.RegisterKeyword("unevaluatedItems", NewUnevaluatedItems)
r.SetKeywordOrder("maxContains", 2)
r.SetKeywordOrder("minContains", 2)
r.SetKeywordOrder("additionalItems", 3)
r.SetKeywordOrder("unevaluatedItems", 4)
// conditional keywords
r.RegisterKeyword("if", NewIf)
r.RegisterKeyword("then", NewThen)
r.RegisterKeyword("else", NewElse)
r.SetKeywordOrder("then", 2)
r.SetKeywordOrder("else", 2)
//optional formats
r.RegisterKeyword("format", NewFormat)
}