-
Notifications
You must be signed in to change notification settings - Fork 0
/
array.go
78 lines (63 loc) · 1.73 KB
/
array.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
package polyschema
func checkArray(parent, child JsonSchema) TypesIdentity {
var identity TypesIdentity
identity = TypesEqual
// maxItems
if parent.MaxItems != nil && child.MaxItems != nil && *parent.MaxItems != *child.MaxItems {
return TypesNotEqual
}
if parent.MaxItems == nil && child.MaxItems != nil {
identity = TypesSubtype
}
// minItems
if parent.MinItems != nil && child.MinItems != nil && *parent.MinItems != *child.MinItems {
return TypesNotEqual
}
if parent.MinItems == nil && child.MinItems != nil {
identity = TypesSubtype
}
// items
if parent.Items != nil && child.Items != nil {
switch Subtype(*parent.Items, *child.Items) {
case TypesNotEqual:
return TypesNotEqual
case TypesSubtype:
identity = TypesSubtype
}
}
if parent.Items == nil && child.Items != nil {
identity = TypesSubtype
}
// contains
if parent.Contains != nil && child.Contains != nil {
switch Subtype(*parent.Contains, *child.Contains) {
case TypesNotEqual:
return TypesNotEqual
case TypesSubtype:
identity = TypesSubtype
}
}
if parent.Contains == nil && child.Contains != nil {
identity = TypesSubtype
}
// additionalItems
if parent.AdditionalItems != nil && child.AdditionalItems != nil {
switch Subtype(*parent.AdditionalItems, *child.AdditionalItems) {
case TypesNotEqual:
return TypesNotEqual
case TypesSubtype:
identity = TypesSubtype
}
}
if parent.AdditionalItems == nil && child.AdditionalItems != nil {
identity = TypesSubtype
}
// uniqueItems
if parent.UniqueItems != nil && child.UniqueItems != nil && *parent.UniqueItems != *child.UniqueItems {
return TypesNotEqual
}
if parent.UniqueItems == nil && child.UniqueItems != nil {
identity = TypesSubtype
}
return identity
}