...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package jsonschema
18
19 import "gopkg.in/yaml.v3"
20
21
22
23
24
25 type Schema struct {
26 Schema *string
27 ID *string
28 Ref *string
29
30
31
32 MultipleOf *SchemaNumber
33 Maximum *SchemaNumber
34 ExclusiveMaximum *bool
35 Minimum *SchemaNumber
36 ExclusiveMinimum *bool
37
38
39 MaxLength *int64
40 MinLength *int64
41 Pattern *string
42
43
44 AdditionalItems *SchemaOrBoolean
45 Items *SchemaOrSchemaArray
46 MaxItems *int64
47 MinItems *int64
48 UniqueItems *bool
49
50
51 MaxProperties *int64
52 MinProperties *int64
53 Required *[]string
54 AdditionalProperties *SchemaOrBoolean
55 Properties *[]*NamedSchema
56 PatternProperties *[]*NamedSchema
57 Dependencies *[]*NamedSchemaOrStringArray
58
59
60 Enumeration *[]SchemaEnumValue
61 Type *StringOrStringArray
62 AllOf *[]*Schema
63 AnyOf *[]*Schema
64 OneOf *[]*Schema
65 Not *Schema
66 Definitions *[]*NamedSchema
67
68
69 Title *string
70 Description *string
71 Default *yaml.Node
72
73
74 Format *string
75 }
76
77
78
79
80
81
82 type SchemaNumber struct {
83 Integer *int64
84 Float *float64
85 }
86
87
88 func NewSchemaNumberWithInteger(i int64) *SchemaNumber {
89 result := &SchemaNumber{}
90 result.Integer = &i
91 return result
92 }
93
94
95 func NewSchemaNumberWithFloat(f float64) *SchemaNumber {
96 result := &SchemaNumber{}
97 result.Float = &f
98 return result
99 }
100
101
102 type SchemaOrBoolean struct {
103 Schema *Schema
104 Boolean *bool
105 }
106
107
108 func NewSchemaOrBooleanWithSchema(s *Schema) *SchemaOrBoolean {
109 result := &SchemaOrBoolean{}
110 result.Schema = s
111 return result
112 }
113
114
115 func NewSchemaOrBooleanWithBoolean(b bool) *SchemaOrBoolean {
116 result := &SchemaOrBoolean{}
117 result.Boolean = &b
118 return result
119 }
120
121
122
123 type StringOrStringArray struct {
124 String *string
125 StringArray *[]string
126 }
127
128
129 func NewStringOrStringArrayWithString(s string) *StringOrStringArray {
130 result := &StringOrStringArray{}
131 result.String = &s
132 return result
133 }
134
135
136 func NewStringOrStringArrayWithStringArray(a []string) *StringOrStringArray {
137 result := &StringOrStringArray{}
138 result.StringArray = &a
139 return result
140 }
141
142
143
144 type SchemaOrStringArray struct {
145 Schema *Schema
146 StringArray *[]string
147 }
148
149
150
151 type SchemaOrSchemaArray struct {
152 Schema *Schema
153 SchemaArray *[]*Schema
154 }
155
156
157 func NewSchemaOrSchemaArrayWithSchema(s *Schema) *SchemaOrSchemaArray {
158 result := &SchemaOrSchemaArray{}
159 result.Schema = s
160 return result
161 }
162
163
164 func NewSchemaOrSchemaArrayWithSchemaArray(a []*Schema) *SchemaOrSchemaArray {
165 result := &SchemaOrSchemaArray{}
166 result.SchemaArray = &a
167 return result
168 }
169
170
171
172 type SchemaEnumValue struct {
173 String *string
174 Bool *bool
175 }
176
177
178
179 type NamedSchema struct {
180 Name string
181 Value *Schema
182 }
183
184
185 func NewNamedSchema(name string, value *Schema) *NamedSchema {
186 return &NamedSchema{Name: name, Value: value}
187 }
188
189
190
191 type NamedSchemaOrStringArray struct {
192 Name string
193 Value *SchemaOrStringArray
194 }
195
196
197
198 func namedSchemaArrayElementWithName(array *[]*NamedSchema, name string) *Schema {
199 if array == nil {
200 return nil
201 }
202 for _, pair := range *array {
203 if pair.Name == name {
204 return pair.Value
205 }
206 }
207 return nil
208 }
209
210
211 func (s *Schema) PropertyWithName(name string) *Schema {
212 return namedSchemaArrayElementWithName(s.Properties, name)
213 }
214
215
216 func (s *Schema) PatternPropertyWithName(name string) *Schema {
217 return namedSchemaArrayElementWithName(s.PatternProperties, name)
218 }
219
220
221 func (s *Schema) DefinitionWithName(name string) *Schema {
222 return namedSchemaArrayElementWithName(s.Definitions, name)
223 }
224
225
226 func (s *Schema) AddProperty(name string, property *Schema) {
227 *s.Properties = append(*s.Properties, NewNamedSchema(name, property))
228 }
229
View as plain text