/
model_behaviors.go
268 lines (223 loc) · 7.02 KB
/
model_behaviors.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
Edge Firewall API
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package edgefirewall
import (
"encoding/json"
"fmt"
)
// Behaviors - struct for Behaviors
type Behaviors struct {
NullArgumentBehavior *NullArgumentBehavior
SetCustomResponse *SetCustomResponse
SetRateLimitBehavior *SetRateLimitBehavior
SetWAFRuleSetAndWafModeBehavior *SetWAFRuleSetAndWafModeBehavior
SetWAFRuleSetBehavior *SetWAFRuleSetBehavior
SimpleArgumentBehavior *SimpleArgumentBehavior
}
// NullArgumentBehaviorAsBehaviors is a convenience function that returns NullArgumentBehavior wrapped in Behaviors
func NullArgumentBehaviorAsBehaviors(v *NullArgumentBehavior) Behaviors {
return Behaviors{
NullArgumentBehavior: v,
}
}
// SetCustomResponseAsBehaviors is a convenience function that returns SetCustomResponse wrapped in Behaviors
func SetCustomResponseAsBehaviors(v *SetCustomResponse) Behaviors {
return Behaviors{
SetCustomResponse: v,
}
}
// SetRateLimitBehaviorAsBehaviors is a convenience function that returns SetRateLimitBehavior wrapped in Behaviors
func SetRateLimitBehaviorAsBehaviors(v *SetRateLimitBehavior) Behaviors {
return Behaviors{
SetRateLimitBehavior: v,
}
}
// SetWAFRuleSetAndWafModeBehaviorAsBehaviors is a convenience function that returns SetWAFRuleSetAndWafModeBehavior wrapped in Behaviors
func SetWAFRuleSetAndWafModeBehaviorAsBehaviors(v *SetWAFRuleSetAndWafModeBehavior) Behaviors {
return Behaviors{
SetWAFRuleSetAndWafModeBehavior: v,
}
}
// SetWAFRuleSetBehaviorAsBehaviors is a convenience function that returns SetWAFRuleSetBehavior wrapped in Behaviors
func SetWAFRuleSetBehaviorAsBehaviors(v *SetWAFRuleSetBehavior) Behaviors {
return Behaviors{
SetWAFRuleSetBehavior: v,
}
}
// SimpleArgumentBehaviorAsBehaviors is a convenience function that returns SimpleArgumentBehavior wrapped in Behaviors
func SimpleArgumentBehaviorAsBehaviors(v *SimpleArgumentBehavior) Behaviors {
return Behaviors{
SimpleArgumentBehavior: v,
}
}
// Unmarshal JSON data into one of the pointers in the struct
func (dst *Behaviors) UnmarshalJSON(data []byte) error {
var err error
match := 0
// try to unmarshal data into NullArgumentBehavior
err = newStrictDecoder(data).Decode(&dst.NullArgumentBehavior)
if err == nil {
jsonNullArgumentBehavior, _ := json.Marshal(dst.NullArgumentBehavior)
if string(jsonNullArgumentBehavior) == "{}" { // empty struct
dst.NullArgumentBehavior = nil
} else {
match++
}
} else {
dst.NullArgumentBehavior = nil
}
// try to unmarshal data into SetCustomResponse
err = newStrictDecoder(data).Decode(&dst.SetCustomResponse)
if err == nil {
jsonSetCustomResponse, _ := json.Marshal(dst.SetCustomResponse)
if string(jsonSetCustomResponse) == "{}" { // empty struct
dst.SetCustomResponse = nil
} else {
match++
}
} else {
dst.SetCustomResponse = nil
}
// try to unmarshal data into SetRateLimitBehavior
err = newStrictDecoder(data).Decode(&dst.SetRateLimitBehavior)
if err == nil {
jsonSetRateLimitBehavior, _ := json.Marshal(dst.SetRateLimitBehavior)
if string(jsonSetRateLimitBehavior) == "{}" { // empty struct
dst.SetRateLimitBehavior = nil
} else {
match++
}
} else {
dst.SetRateLimitBehavior = nil
}
// try to unmarshal data into SetWAFRuleSetAndWafModeBehavior
err = newStrictDecoder(data).Decode(&dst.SetWAFRuleSetAndWafModeBehavior)
if err == nil {
jsonSetWAFRuleSetAndWafModeBehavior, _ := json.Marshal(dst.SetWAFRuleSetAndWafModeBehavior)
if string(jsonSetWAFRuleSetAndWafModeBehavior) == "{}" { // empty struct
dst.SetWAFRuleSetAndWafModeBehavior = nil
} else {
match++
}
} else {
dst.SetWAFRuleSetAndWafModeBehavior = nil
}
// try to unmarshal data into SetWAFRuleSetBehavior
err = newStrictDecoder(data).Decode(&dst.SetWAFRuleSetBehavior)
if err == nil {
jsonSetWAFRuleSetBehavior, _ := json.Marshal(dst.SetWAFRuleSetBehavior)
if string(jsonSetWAFRuleSetBehavior) == "{}" { // empty struct
dst.SetWAFRuleSetBehavior = nil
} else {
match++
}
} else {
dst.SetWAFRuleSetBehavior = nil
}
// try to unmarshal data into SimpleArgumentBehavior
err = newStrictDecoder(data).Decode(&dst.SimpleArgumentBehavior)
if err == nil {
jsonSimpleArgumentBehavior, _ := json.Marshal(dst.SimpleArgumentBehavior)
if string(jsonSimpleArgumentBehavior) == "{}" { // empty struct
dst.SimpleArgumentBehavior = nil
} else {
match++
}
} else {
dst.SimpleArgumentBehavior = nil
}
if match > 1 { // more than 1 match
// reset to nil
dst.NullArgumentBehavior = nil
dst.SetCustomResponse = nil
dst.SetRateLimitBehavior = nil
dst.SetWAFRuleSetAndWafModeBehavior = nil
dst.SetWAFRuleSetBehavior = nil
dst.SimpleArgumentBehavior = nil
return fmt.Errorf("data matches more than one schema in oneOf(Behaviors)")
} else if match == 1 {
return nil // exactly one match
} else { // no match
return fmt.Errorf("data failed to match schemas in oneOf(Behaviors)")
}
}
// Marshal data from the first non-nil pointers in the struct to JSON
func (src Behaviors) MarshalJSON() ([]byte, error) {
if src.NullArgumentBehavior != nil {
return json.Marshal(&src.NullArgumentBehavior)
}
if src.SetCustomResponse != nil {
return json.Marshal(&src.SetCustomResponse)
}
if src.SetRateLimitBehavior != nil {
return json.Marshal(&src.SetRateLimitBehavior)
}
if src.SetWAFRuleSetAndWafModeBehavior != nil {
return json.Marshal(&src.SetWAFRuleSetAndWafModeBehavior)
}
if src.SetWAFRuleSetBehavior != nil {
return json.Marshal(&src.SetWAFRuleSetBehavior)
}
if src.SimpleArgumentBehavior != nil {
return json.Marshal(&src.SimpleArgumentBehavior)
}
return nil, nil // no data in oneOf schemas
}
// Get the actual instance
func (obj *Behaviors) GetActualInstance() (interface{}) {
if obj == nil {
return nil
}
if obj.NullArgumentBehavior != nil {
return obj.NullArgumentBehavior
}
if obj.SetCustomResponse != nil {
return obj.SetCustomResponse
}
if obj.SetRateLimitBehavior != nil {
return obj.SetRateLimitBehavior
}
if obj.SetWAFRuleSetAndWafModeBehavior != nil {
return obj.SetWAFRuleSetAndWafModeBehavior
}
if obj.SetWAFRuleSetBehavior != nil {
return obj.SetWAFRuleSetBehavior
}
if obj.SimpleArgumentBehavior != nil {
return obj.SimpleArgumentBehavior
}
// all schemas are nil
return nil
}
type NullableBehaviors struct {
value *Behaviors
isSet bool
}
func (v NullableBehaviors) Get() *Behaviors {
return v.value
}
func (v *NullableBehaviors) Set(val *Behaviors) {
v.value = val
v.isSet = true
}
func (v NullableBehaviors) IsSet() bool {
return v.isSet
}
func (v *NullableBehaviors) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableBehaviors(val *Behaviors) *NullableBehaviors {
return &NullableBehaviors{value: val, isSet: true}
}
func (v NullableBehaviors) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableBehaviors) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}