-
Notifications
You must be signed in to change notification settings - Fork 54
/
model_synthetics_assertion.go
170 lines (147 loc) · 6.4 KB
/
model_synthetics_assertion.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
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.
package datadogV1
import (
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
)
// SyntheticsAssertion - Object describing the assertions type, their associated operator,
// which property they apply, and upon which target.
type SyntheticsAssertion struct {
SyntheticsAssertionTarget *SyntheticsAssertionTarget
SyntheticsAssertionJSONPathTarget *SyntheticsAssertionJSONPathTarget
SyntheticsAssertionJSONSchemaTarget *SyntheticsAssertionJSONSchemaTarget
SyntheticsAssertionXPathTarget *SyntheticsAssertionXPathTarget
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
UnparsedObject interface{}
}
// SyntheticsAssertionTargetAsSyntheticsAssertion is a convenience function that returns SyntheticsAssertionTarget wrapped in SyntheticsAssertion.
func SyntheticsAssertionTargetAsSyntheticsAssertion(v *SyntheticsAssertionTarget) SyntheticsAssertion {
return SyntheticsAssertion{SyntheticsAssertionTarget: v}
}
// SyntheticsAssertionJSONPathTargetAsSyntheticsAssertion is a convenience function that returns SyntheticsAssertionJSONPathTarget wrapped in SyntheticsAssertion.
func SyntheticsAssertionJSONPathTargetAsSyntheticsAssertion(v *SyntheticsAssertionJSONPathTarget) SyntheticsAssertion {
return SyntheticsAssertion{SyntheticsAssertionJSONPathTarget: v}
}
// SyntheticsAssertionJSONSchemaTargetAsSyntheticsAssertion is a convenience function that returns SyntheticsAssertionJSONSchemaTarget wrapped in SyntheticsAssertion.
func SyntheticsAssertionJSONSchemaTargetAsSyntheticsAssertion(v *SyntheticsAssertionJSONSchemaTarget) SyntheticsAssertion {
return SyntheticsAssertion{SyntheticsAssertionJSONSchemaTarget: v}
}
// SyntheticsAssertionXPathTargetAsSyntheticsAssertion is a convenience function that returns SyntheticsAssertionXPathTarget wrapped in SyntheticsAssertion.
func SyntheticsAssertionXPathTargetAsSyntheticsAssertion(v *SyntheticsAssertionXPathTarget) SyntheticsAssertion {
return SyntheticsAssertion{SyntheticsAssertionXPathTarget: v}
}
// UnmarshalJSON turns data into one of the pointers in the struct.
func (obj *SyntheticsAssertion) UnmarshalJSON(data []byte) error {
var err error
match := 0
// try to unmarshal data into SyntheticsAssertionTarget
err = datadog.Unmarshal(data, &obj.SyntheticsAssertionTarget)
if err == nil {
if obj.SyntheticsAssertionTarget != nil && obj.SyntheticsAssertionTarget.UnparsedObject == nil {
jsonSyntheticsAssertionTarget, _ := datadog.Marshal(obj.SyntheticsAssertionTarget)
if string(jsonSyntheticsAssertionTarget) == "{}" { // empty struct
obj.SyntheticsAssertionTarget = nil
} else {
match++
}
} else {
obj.SyntheticsAssertionTarget = nil
}
} else {
obj.SyntheticsAssertionTarget = nil
}
// try to unmarshal data into SyntheticsAssertionJSONPathTarget
err = datadog.Unmarshal(data, &obj.SyntheticsAssertionJSONPathTarget)
if err == nil {
if obj.SyntheticsAssertionJSONPathTarget != nil && obj.SyntheticsAssertionJSONPathTarget.UnparsedObject == nil {
jsonSyntheticsAssertionJSONPathTarget, _ := datadog.Marshal(obj.SyntheticsAssertionJSONPathTarget)
if string(jsonSyntheticsAssertionJSONPathTarget) == "{}" { // empty struct
obj.SyntheticsAssertionJSONPathTarget = nil
} else {
match++
}
} else {
obj.SyntheticsAssertionJSONPathTarget = nil
}
} else {
obj.SyntheticsAssertionJSONPathTarget = nil
}
// try to unmarshal data into SyntheticsAssertionJSONSchemaTarget
err = datadog.Unmarshal(data, &obj.SyntheticsAssertionJSONSchemaTarget)
if err == nil {
if obj.SyntheticsAssertionJSONSchemaTarget != nil && obj.SyntheticsAssertionJSONSchemaTarget.UnparsedObject == nil {
jsonSyntheticsAssertionJSONSchemaTarget, _ := datadog.Marshal(obj.SyntheticsAssertionJSONSchemaTarget)
if string(jsonSyntheticsAssertionJSONSchemaTarget) == "{}" { // empty struct
obj.SyntheticsAssertionJSONSchemaTarget = nil
} else {
match++
}
} else {
obj.SyntheticsAssertionJSONSchemaTarget = nil
}
} else {
obj.SyntheticsAssertionJSONSchemaTarget = nil
}
// try to unmarshal data into SyntheticsAssertionXPathTarget
err = datadog.Unmarshal(data, &obj.SyntheticsAssertionXPathTarget)
if err == nil {
if obj.SyntheticsAssertionXPathTarget != nil && obj.SyntheticsAssertionXPathTarget.UnparsedObject == nil {
jsonSyntheticsAssertionXPathTarget, _ := datadog.Marshal(obj.SyntheticsAssertionXPathTarget)
if string(jsonSyntheticsAssertionXPathTarget) == "{}" { // empty struct
obj.SyntheticsAssertionXPathTarget = nil
} else {
match++
}
} else {
obj.SyntheticsAssertionXPathTarget = nil
}
} else {
obj.SyntheticsAssertionXPathTarget = nil
}
if match != 1 { // more than 1 match
// reset to nil
obj.SyntheticsAssertionTarget = nil
obj.SyntheticsAssertionJSONPathTarget = nil
obj.SyntheticsAssertionJSONSchemaTarget = nil
obj.SyntheticsAssertionXPathTarget = nil
return datadog.Unmarshal(data, &obj.UnparsedObject)
}
return nil // exactly one match
}
// MarshalJSON turns data from the first non-nil pointers in the struct to JSON.
func (obj SyntheticsAssertion) MarshalJSON() ([]byte, error) {
if obj.SyntheticsAssertionTarget != nil {
return datadog.Marshal(&obj.SyntheticsAssertionTarget)
}
if obj.SyntheticsAssertionJSONPathTarget != nil {
return datadog.Marshal(&obj.SyntheticsAssertionJSONPathTarget)
}
if obj.SyntheticsAssertionJSONSchemaTarget != nil {
return datadog.Marshal(&obj.SyntheticsAssertionJSONSchemaTarget)
}
if obj.SyntheticsAssertionXPathTarget != nil {
return datadog.Marshal(&obj.SyntheticsAssertionXPathTarget)
}
if obj.UnparsedObject != nil {
return datadog.Marshal(obj.UnparsedObject)
}
return nil, nil // no data in oneOf schemas
}
// GetActualInstance returns the actual instance.
func (obj *SyntheticsAssertion) GetActualInstance() interface{} {
if obj.SyntheticsAssertionTarget != nil {
return obj.SyntheticsAssertionTarget
}
if obj.SyntheticsAssertionJSONPathTarget != nil {
return obj.SyntheticsAssertionJSONPathTarget
}
if obj.SyntheticsAssertionJSONSchemaTarget != nil {
return obj.SyntheticsAssertionJSONSchemaTarget
}
if obj.SyntheticsAssertionXPathTarget != nil {
return obj.SyntheticsAssertionXPathTarget
}
// all schemas are nil
return nil
}