|
5 | 5 | package datadogV1 |
6 | 6 |
|
7 | 7 | import ( |
8 | | - "fmt" |
9 | | - |
10 | 8 | "github.com/DataDog/datadog-api-client-go/v2/api/datadog" |
11 | 9 | ) |
12 | 10 |
|
13 | | -// SLOCountDefinition A count-based (metric) SLI specification, composed of three parts: the good events formula, the total events formula, |
14 | | -// and the underlying queries. |
| 11 | +// SLOCountDefinition - A count-based (metric) SLI specification, composed of three parts: the good events formula, |
| 12 | +// the bad or total events formula, and the underlying queries. |
| 13 | +// Exactly one of `total_events_formula` or `bad_events_formula` must be provided. |
15 | 14 | type SLOCountDefinition struct { |
16 | | - // A formula that specifies how to combine the results of multiple queries. |
17 | | - GoodEventsFormula SLOFormula `json:"good_events_formula"` |
18 | | - // |
19 | | - Queries []SLODataSourceQueryDefinition `json:"queries"` |
20 | | - // A formula that specifies how to combine the results of multiple queries. |
21 | | - TotalEventsFormula SLOFormula `json:"total_events_formula"` |
22 | | - // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct |
23 | | - UnparsedObject map[string]interface{} `json:"-"` |
24 | | - AdditionalProperties map[string]interface{} `json:"-"` |
25 | | -} |
| 15 | + SLOCountDefinitionWithTotalEventsFormula *SLOCountDefinitionWithTotalEventsFormula |
| 16 | + SLOCountDefinitionWithBadEventsFormula *SLOCountDefinitionWithBadEventsFormula |
26 | 17 |
|
27 | | -// NewSLOCountDefinition instantiates a new SLOCountDefinition object. |
28 | | -// This constructor will assign default values to properties that have it defined, |
29 | | -// and makes sure properties required by API are set, but the set of arguments |
30 | | -// will change when the set of required properties is changed. |
31 | | -func NewSLOCountDefinition(goodEventsFormula SLOFormula, queries []SLODataSourceQueryDefinition, totalEventsFormula SLOFormula) *SLOCountDefinition { |
32 | | - this := SLOCountDefinition{} |
33 | | - this.GoodEventsFormula = goodEventsFormula |
34 | | - this.Queries = queries |
35 | | - this.TotalEventsFormula = totalEventsFormula |
36 | | - return &this |
| 18 | + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct |
| 19 | + UnparsedObject interface{} |
37 | 20 | } |
38 | 21 |
|
39 | | -// NewSLOCountDefinitionWithDefaults instantiates a new SLOCountDefinition object. |
40 | | -// This constructor will only assign default values to properties that have it defined, |
41 | | -// but it doesn't guarantee that properties required by API are set. |
42 | | -func NewSLOCountDefinitionWithDefaults() *SLOCountDefinition { |
43 | | - this := SLOCountDefinition{} |
44 | | - return &this |
| 22 | +// SLOCountDefinitionWithTotalEventsFormulaAsSLOCountDefinition is a convenience function that returns SLOCountDefinitionWithTotalEventsFormula wrapped in SLOCountDefinition. |
| 23 | +func SLOCountDefinitionWithTotalEventsFormulaAsSLOCountDefinition(v *SLOCountDefinitionWithTotalEventsFormula) SLOCountDefinition { |
| 24 | + return SLOCountDefinition{SLOCountDefinitionWithTotalEventsFormula: v} |
45 | 25 | } |
46 | 26 |
|
47 | | -// GetGoodEventsFormula returns the GoodEventsFormula field value. |
48 | | -func (o *SLOCountDefinition) GetGoodEventsFormula() SLOFormula { |
49 | | - if o == nil { |
50 | | - var ret SLOFormula |
51 | | - return ret |
52 | | - } |
53 | | - return o.GoodEventsFormula |
| 27 | +// SLOCountDefinitionWithBadEventsFormulaAsSLOCountDefinition is a convenience function that returns SLOCountDefinitionWithBadEventsFormula wrapped in SLOCountDefinition. |
| 28 | +func SLOCountDefinitionWithBadEventsFormulaAsSLOCountDefinition(v *SLOCountDefinitionWithBadEventsFormula) SLOCountDefinition { |
| 29 | + return SLOCountDefinition{SLOCountDefinitionWithBadEventsFormula: v} |
54 | 30 | } |
55 | 31 |
|
56 | | -// GetGoodEventsFormulaOk returns a tuple with the GoodEventsFormula field value |
57 | | -// and a boolean to check if the value has been set. |
58 | | -func (o *SLOCountDefinition) GetGoodEventsFormulaOk() (*SLOFormula, bool) { |
59 | | - if o == nil { |
60 | | - return nil, false |
| 32 | +// UnmarshalJSON turns data into one of the pointers in the struct. |
| 33 | +func (obj *SLOCountDefinition) UnmarshalJSON(data []byte) error { |
| 34 | + var err error |
| 35 | + match := 0 |
| 36 | + // try to unmarshal data into SLOCountDefinitionWithTotalEventsFormula |
| 37 | + err = datadog.Unmarshal(data, &obj.SLOCountDefinitionWithTotalEventsFormula) |
| 38 | + if err == nil { |
| 39 | + if obj.SLOCountDefinitionWithTotalEventsFormula != nil && obj.SLOCountDefinitionWithTotalEventsFormula.UnparsedObject == nil { |
| 40 | + jsonSLOCountDefinitionWithTotalEventsFormula, _ := datadog.Marshal(obj.SLOCountDefinitionWithTotalEventsFormula) |
| 41 | + if string(jsonSLOCountDefinitionWithTotalEventsFormula) == "{}" { // empty struct |
| 42 | + obj.SLOCountDefinitionWithTotalEventsFormula = nil |
| 43 | + } else { |
| 44 | + match++ |
| 45 | + } |
| 46 | + } else { |
| 47 | + obj.SLOCountDefinitionWithTotalEventsFormula = nil |
| 48 | + } |
| 49 | + } else { |
| 50 | + obj.SLOCountDefinitionWithTotalEventsFormula = nil |
| 51 | + } |
| 52 | + |
| 53 | + // try to unmarshal data into SLOCountDefinitionWithBadEventsFormula |
| 54 | + err = datadog.Unmarshal(data, &obj.SLOCountDefinitionWithBadEventsFormula) |
| 55 | + if err == nil { |
| 56 | + if obj.SLOCountDefinitionWithBadEventsFormula != nil && obj.SLOCountDefinitionWithBadEventsFormula.UnparsedObject == nil { |
| 57 | + jsonSLOCountDefinitionWithBadEventsFormula, _ := datadog.Marshal(obj.SLOCountDefinitionWithBadEventsFormula) |
| 58 | + if string(jsonSLOCountDefinitionWithBadEventsFormula) == "{}" { // empty struct |
| 59 | + obj.SLOCountDefinitionWithBadEventsFormula = nil |
| 60 | + } else { |
| 61 | + match++ |
| 62 | + } |
| 63 | + } else { |
| 64 | + obj.SLOCountDefinitionWithBadEventsFormula = nil |
| 65 | + } |
| 66 | + } else { |
| 67 | + obj.SLOCountDefinitionWithBadEventsFormula = nil |
61 | 68 | } |
62 | | - return &o.GoodEventsFormula, true |
63 | | -} |
64 | 69 |
|
65 | | -// SetGoodEventsFormula sets field value. |
66 | | -func (o *SLOCountDefinition) SetGoodEventsFormula(v SLOFormula) { |
67 | | - o.GoodEventsFormula = v |
68 | | -} |
69 | | - |
70 | | -// GetQueries returns the Queries field value. |
71 | | -func (o *SLOCountDefinition) GetQueries() []SLODataSourceQueryDefinition { |
72 | | - if o == nil { |
73 | | - var ret []SLODataSourceQueryDefinition |
74 | | - return ret |
| 70 | + if match != 1 { // more than 1 match |
| 71 | + // reset to nil |
| 72 | + obj.SLOCountDefinitionWithTotalEventsFormula = nil |
| 73 | + obj.SLOCountDefinitionWithBadEventsFormula = nil |
| 74 | + return datadog.Unmarshal(data, &obj.UnparsedObject) |
75 | 75 | } |
76 | | - return o.Queries |
| 76 | + return nil // exactly one match |
77 | 77 | } |
78 | 78 |
|
79 | | -// GetQueriesOk returns a tuple with the Queries field value |
80 | | -// and a boolean to check if the value has been set. |
81 | | -func (o *SLOCountDefinition) GetQueriesOk() (*[]SLODataSourceQueryDefinition, bool) { |
82 | | - if o == nil { |
83 | | - return nil, false |
| 79 | +// MarshalJSON turns data from the first non-nil pointers in the struct to JSON. |
| 80 | +func (obj SLOCountDefinition) MarshalJSON() ([]byte, error) { |
| 81 | + if obj.SLOCountDefinitionWithTotalEventsFormula != nil { |
| 82 | + return datadog.Marshal(&obj.SLOCountDefinitionWithTotalEventsFormula) |
84 | 83 | } |
85 | | - return &o.Queries, true |
86 | | -} |
87 | | - |
88 | | -// SetQueries sets field value. |
89 | | -func (o *SLOCountDefinition) SetQueries(v []SLODataSourceQueryDefinition) { |
90 | | - o.Queries = v |
91 | | -} |
92 | 84 |
|
93 | | -// GetTotalEventsFormula returns the TotalEventsFormula field value. |
94 | | -func (o *SLOCountDefinition) GetTotalEventsFormula() SLOFormula { |
95 | | - if o == nil { |
96 | | - var ret SLOFormula |
97 | | - return ret |
| 85 | + if obj.SLOCountDefinitionWithBadEventsFormula != nil { |
| 86 | + return datadog.Marshal(&obj.SLOCountDefinitionWithBadEventsFormula) |
98 | 87 | } |
99 | | - return o.TotalEventsFormula |
100 | | -} |
101 | 88 |
|
102 | | -// GetTotalEventsFormulaOk returns a tuple with the TotalEventsFormula field value |
103 | | -// and a boolean to check if the value has been set. |
104 | | -func (o *SLOCountDefinition) GetTotalEventsFormulaOk() (*SLOFormula, bool) { |
105 | | - if o == nil { |
106 | | - return nil, false |
| 89 | + if obj.UnparsedObject != nil { |
| 90 | + return datadog.Marshal(obj.UnparsedObject) |
107 | 91 | } |
108 | | - return &o.TotalEventsFormula, true |
109 | | -} |
110 | | - |
111 | | -// SetTotalEventsFormula sets field value. |
112 | | -func (o *SLOCountDefinition) SetTotalEventsFormula(v SLOFormula) { |
113 | | - o.TotalEventsFormula = v |
| 92 | + return nil, nil // no data in oneOf schemas |
114 | 93 | } |
115 | 94 |
|
116 | | -// MarshalJSON serializes the struct using spec logic. |
117 | | -func (o SLOCountDefinition) MarshalJSON() ([]byte, error) { |
118 | | - toSerialize := map[string]interface{}{} |
119 | | - if o.UnparsedObject != nil { |
120 | | - return datadog.Marshal(o.UnparsedObject) |
121 | | - } |
122 | | - toSerialize["good_events_formula"] = o.GoodEventsFormula |
123 | | - toSerialize["queries"] = o.Queries |
124 | | - toSerialize["total_events_formula"] = o.TotalEventsFormula |
125 | | - |
126 | | - for key, value := range o.AdditionalProperties { |
127 | | - toSerialize[key] = value |
128 | | - } |
129 | | - return datadog.Marshal(toSerialize) |
130 | | -} |
131 | | - |
132 | | -// UnmarshalJSON deserializes the given payload. |
133 | | -func (o *SLOCountDefinition) UnmarshalJSON(bytes []byte) (err error) { |
134 | | - all := struct { |
135 | | - GoodEventsFormula *SLOFormula `json:"good_events_formula"` |
136 | | - Queries *[]SLODataSourceQueryDefinition `json:"queries"` |
137 | | - TotalEventsFormula *SLOFormula `json:"total_events_formula"` |
138 | | - }{} |
139 | | - if err = datadog.Unmarshal(bytes, &all); err != nil { |
140 | | - return datadog.Unmarshal(bytes, &o.UnparsedObject) |
141 | | - } |
142 | | - if all.GoodEventsFormula == nil { |
143 | | - return fmt.Errorf("required field good_events_formula missing") |
144 | | - } |
145 | | - if all.Queries == nil { |
146 | | - return fmt.Errorf("required field queries missing") |
147 | | - } |
148 | | - if all.TotalEventsFormula == nil { |
149 | | - return fmt.Errorf("required field total_events_formula missing") |
150 | | - } |
151 | | - additionalProperties := make(map[string]interface{}) |
152 | | - if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { |
153 | | - datadog.DeleteKeys(additionalProperties, &[]string{"good_events_formula", "queries", "total_events_formula"}) |
154 | | - } else { |
155 | | - return err |
156 | | - } |
157 | | - |
158 | | - hasInvalidField := false |
159 | | - if all.GoodEventsFormula.UnparsedObject != nil && o.UnparsedObject == nil { |
160 | | - hasInvalidField = true |
161 | | - } |
162 | | - o.GoodEventsFormula = *all.GoodEventsFormula |
163 | | - o.Queries = *all.Queries |
164 | | - if all.TotalEventsFormula.UnparsedObject != nil && o.UnparsedObject == nil { |
165 | | - hasInvalidField = true |
166 | | - } |
167 | | - o.TotalEventsFormula = *all.TotalEventsFormula |
168 | | - |
169 | | - if len(additionalProperties) > 0 { |
170 | | - o.AdditionalProperties = additionalProperties |
| 95 | +// GetActualInstance returns the actual instance. |
| 96 | +func (obj *SLOCountDefinition) GetActualInstance() interface{} { |
| 97 | + if obj.SLOCountDefinitionWithTotalEventsFormula != nil { |
| 98 | + return obj.SLOCountDefinitionWithTotalEventsFormula |
171 | 99 | } |
172 | 100 |
|
173 | | - if hasInvalidField { |
174 | | - return datadog.Unmarshal(bytes, &o.UnparsedObject) |
| 101 | + if obj.SLOCountDefinitionWithBadEventsFormula != nil { |
| 102 | + return obj.SLOCountDefinitionWithBadEventsFormula |
175 | 103 | } |
176 | 104 |
|
| 105 | + // all schemas are nil |
177 | 106 | return nil |
178 | 107 | } |
0 commit comments