-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcloning.go
130 lines (118 loc) · 3.08 KB
/
cloning.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package valix
func (v *Validator) Clone() *Validator {
return &Validator{
IgnoreUnknownProperties: v.IgnoreUnknownProperties,
Properties: v.Properties.Clone(),
Constraints: v.Constraints.Clone(),
AllowArray: v.AllowArray,
DisallowObject: v.DisallowObject,
AllowNullJson: v.AllowNullJson,
StopOnFirst: v.StopOnFirst,
UseNumber: v.UseNumber,
OrderedPropertyChecks: v.OrderedPropertyChecks,
WhenConditions: v.WhenConditions.Clone(),
ConditionalVariants: v.ConditionalVariants.Clone(),
OasInfo: cloneOasInfo(v.OasInfo),
}
}
func cloneValidator(src *Validator) *Validator {
if src == nil {
return nil
}
return src.Clone()
}
func (pv *PropertyValidator) Clone() *PropertyValidator {
return &PropertyValidator{
Type: pv.Type,
NotNull: pv.NotNull,
Mandatory: pv.Mandatory,
MandatoryWhen: pv.MandatoryWhen.Clone(),
Constraints: pv.Constraints.Clone(),
ObjectValidator: cloneValidator(pv.ObjectValidator),
Order: pv.Order,
WhenConditions: pv.WhenConditions.Clone(),
UnwantedConditions: pv.UnwantedConditions.Clone(),
RequiredWith: pv.RequiredWith.Clone(),
RequiredWithMessage: pv.RequiredWithMessage,
UnwantedWith: pv.UnwantedWith.Clone(),
UnwantedWithMessage: pv.UnwantedWithMessage,
OasInfo: cloneOasInfo(pv.OasInfo),
}
}
func (src Properties) Clone() Properties {
if src == nil {
return nil
}
result := Properties{}
for k, v := range src {
if v == nil {
result[k] = nil
} else {
result[k] = v.Clone()
}
}
return result
}
func (src ConditionalVariants) Clone() ConditionalVariants {
if src == nil {
return nil
}
result := make(ConditionalVariants, 0, len(src))
for _, v := range src {
result = append(result, cloneConditionalVariant(v))
}
return result
}
func cloneConditionalVariant(src *ConditionalVariant) *ConditionalVariant {
if src == nil {
return nil
}
return src.Clone()
}
func (src *ConditionalVariant) Clone() *ConditionalVariant {
return &ConditionalVariant{
WhenConditions: src.WhenConditions.Clone(),
Constraints: src.Constraints.Clone(),
Properties: src.Properties.Clone(),
ConditionalVariants: src.ConditionalVariants.Clone(),
}
}
func (src Conditions) Clone() Conditions {
if src == nil {
return nil
}
result := make(Conditions, len(src))
copy(result, src)
return result
}
func (src Constraints) Clone() Constraints {
if src == nil {
return nil
}
result := make(Constraints, len(src))
copy(result, src)
return result
}
func (src OthersExpr) Clone() OthersExpr {
if src == nil {
return nil
}
result := make(OthersExpr, len(src))
copy(result, src)
return result
}
func cloneOasInfo(src *OasInfo) *OasInfo {
if src == nil {
return nil
}
return src.Clone()
}
func (oas *OasInfo) Clone() *OasInfo {
return &OasInfo{
Description: oas.Description,
Title: oas.Title,
Format: oas.Format,
Example: oas.Example,
Deprecated: oas.Deprecated,
}
}