Skip to content

Commit 168ca42

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-specarchana-asokan
authored
Add FormulaAndFunctionEventQueryGroupByFields schema to support flat group_by form (DataDog#3750)
* Regenerate client from commit 4bfcbd9 of spec repo * Fix GroupBy type in dashboard tests for oneOf schema change Update manually maintained test code to use the new FormulaAndFunctionEventQueryGroupByConfig wrapper type instead of raw []FormulaAndFunctionEventQueryGroupBy slices. This matches the spec change in datadog-api-spec PR #5141. * Regenerate client from commit 6846005 of spec repo --------- Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com> Co-authored-by: Archana Asokan <archana.asokan@datadoghq.com>
1 parent 594940d commit 168ca42

58 files changed

Lines changed: 722 additions & 204 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.generator/schemas/v1/openapi.yaml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2962,10 +2962,7 @@ components:
29622962
data_source:
29632963
$ref: '#/components/schemas/FormulaAndFunctionEventsDataSource'
29642964
group_by:
2965-
description: Group by options.
2966-
items:
2967-
$ref: '#/components/schemas/FormulaAndFunctionEventQueryGroupBy'
2968-
type: array
2965+
$ref: '#/components/schemas/FormulaAndFunctionEventQueryGroupByConfig'
29692966
indexes:
29702967
description: An array of index names to query in the stream. Omit or use
29712968
`[]` to query all indexes at once.
@@ -3037,6 +3034,40 @@ components:
30373034
required:
30383035
- facet
30393036
type: object
3037+
FormulaAndFunctionEventQueryGroupByConfig:
3038+
description: Group by configuration for a formula and functions events query.
3039+
Accepts either a list of facet objects or a flat object that specifies a list
3040+
of facet fields.
3041+
oneOf:
3042+
- $ref: '#/components/schemas/FormulaAndFunctionEventQueryGroupByList'
3043+
- $ref: '#/components/schemas/FormulaAndFunctionEventQueryGroupByFields'
3044+
FormulaAndFunctionEventQueryGroupByFields:
3045+
description: Flat group by configuration using multiple event facet fields.
3046+
properties:
3047+
fields:
3048+
description: List of event facets to group by.
3049+
example:
3050+
- hostname
3051+
- service
3052+
items:
3053+
description: Event facet.
3054+
type: string
3055+
type: array
3056+
limit:
3057+
description: Number of groups to return.
3058+
example: 10
3059+
format: int64
3060+
type: integer
3061+
sort:
3062+
$ref: '#/components/schemas/FormulaAndFunctionEventQueryGroupBySort'
3063+
required:
3064+
- fields
3065+
type: object
3066+
FormulaAndFunctionEventQueryGroupByList:
3067+
description: List of objects used to group by.
3068+
items:
3069+
$ref: '#/components/schemas/FormulaAndFunctionEventQueryGroupBy'
3070+
type: array
30403071
FormulaAndFunctionEventQueryGroupBySort:
30413072
description: Options for sorting group by results.
30423073
properties:

api/datadogV1/model_formula_and_function_event_query_definition.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ type FormulaAndFunctionEventQueryDefinition struct {
1818
CrossOrgUuids []string `json:"cross_org_uuids,omitempty"`
1919
// Data source for event platform-based queries.
2020
DataSource FormulaAndFunctionEventsDataSource `json:"data_source"`
21-
// Group by options.
22-
GroupBy []FormulaAndFunctionEventQueryGroupBy `json:"group_by,omitempty"`
21+
// Group by configuration for a formula and functions events query. Accepts either a list of facet objects or a flat object that specifies a list of facet fields.
22+
GroupBy *FormulaAndFunctionEventQueryGroupByConfig `json:"group_by,omitempty"`
2323
// An array of index names to query in the stream. Omit or use `[]` to query all indexes at once.
2424
Indexes []string `json:"indexes,omitempty"`
2525
// Name of the query for use in formulas.
@@ -128,31 +128,31 @@ func (o *FormulaAndFunctionEventQueryDefinition) SetDataSource(v FormulaAndFunct
128128
}
129129

130130
// GetGroupBy returns the GroupBy field value if set, zero value otherwise.
131-
func (o *FormulaAndFunctionEventQueryDefinition) GetGroupBy() []FormulaAndFunctionEventQueryGroupBy {
131+
func (o *FormulaAndFunctionEventQueryDefinition) GetGroupBy() FormulaAndFunctionEventQueryGroupByConfig {
132132
if o == nil || o.GroupBy == nil {
133-
var ret []FormulaAndFunctionEventQueryGroupBy
133+
var ret FormulaAndFunctionEventQueryGroupByConfig
134134
return ret
135135
}
136-
return o.GroupBy
136+
return *o.GroupBy
137137
}
138138

139139
// GetGroupByOk returns a tuple with the GroupBy field value if set, nil otherwise
140140
// and a boolean to check if the value has been set.
141-
func (o *FormulaAndFunctionEventQueryDefinition) GetGroupByOk() (*[]FormulaAndFunctionEventQueryGroupBy, bool) {
141+
func (o *FormulaAndFunctionEventQueryDefinition) GetGroupByOk() (*FormulaAndFunctionEventQueryGroupByConfig, bool) {
142142
if o == nil || o.GroupBy == nil {
143143
return nil, false
144144
}
145-
return &o.GroupBy, true
145+
return o.GroupBy, true
146146
}
147147

148148
// HasGroupBy returns a boolean if a field has been set.
149149
func (o *FormulaAndFunctionEventQueryDefinition) HasGroupBy() bool {
150150
return o != nil && o.GroupBy != nil
151151
}
152152

153-
// SetGroupBy gets a reference to the given []FormulaAndFunctionEventQueryGroupBy and assigns it to the GroupBy field.
154-
func (o *FormulaAndFunctionEventQueryDefinition) SetGroupBy(v []FormulaAndFunctionEventQueryGroupBy) {
155-
o.GroupBy = v
153+
// SetGroupBy gets a reference to the given FormulaAndFunctionEventQueryGroupByConfig and assigns it to the GroupBy field.
154+
func (o *FormulaAndFunctionEventQueryDefinition) SetGroupBy(v FormulaAndFunctionEventQueryGroupByConfig) {
155+
o.GroupBy = &v
156156
}
157157

158158
// GetIndexes returns the Indexes field value if set, zero value otherwise.
@@ -299,7 +299,7 @@ func (o *FormulaAndFunctionEventQueryDefinition) UnmarshalJSON(bytes []byte) (er
299299
Compute *FormulaAndFunctionEventQueryDefinitionCompute `json:"compute"`
300300
CrossOrgUuids []string `json:"cross_org_uuids,omitempty"`
301301
DataSource *FormulaAndFunctionEventsDataSource `json:"data_source"`
302-
GroupBy []FormulaAndFunctionEventQueryGroupBy `json:"group_by,omitempty"`
302+
GroupBy *FormulaAndFunctionEventQueryGroupByConfig `json:"group_by,omitempty"`
303303
Indexes []string `json:"indexes,omitempty"`
304304
Name *string `json:"name"`
305305
Search *FormulaAndFunctionEventQueryDefinitionSearch `json:"search,omitempty"`
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
// Copyright 2019-Present Datadog, Inc.
4+
5+
package datadogV1
6+
7+
import (
8+
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
9+
)
10+
11+
// FormulaAndFunctionEventQueryGroupByConfig - Group by configuration for a formula and functions events query. Accepts either a list of facet objects or a flat object that specifies a list of facet fields.
12+
type FormulaAndFunctionEventQueryGroupByConfig struct {
13+
FormulaAndFunctionEventQueryGroupByList *[]FormulaAndFunctionEventQueryGroupBy
14+
FormulaAndFunctionEventQueryGroupByFields *FormulaAndFunctionEventQueryGroupByFields
15+
16+
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
17+
UnparsedObject interface{}
18+
}
19+
20+
// FormulaAndFunctionEventQueryGroupByListAsFormulaAndFunctionEventQueryGroupByConfig is a convenience function that returns []FormulaAndFunctionEventQueryGroupBy wrapped in FormulaAndFunctionEventQueryGroupByConfig.
21+
func FormulaAndFunctionEventQueryGroupByListAsFormulaAndFunctionEventQueryGroupByConfig(v *[]FormulaAndFunctionEventQueryGroupBy) FormulaAndFunctionEventQueryGroupByConfig {
22+
return FormulaAndFunctionEventQueryGroupByConfig{FormulaAndFunctionEventQueryGroupByList: v}
23+
}
24+
25+
// FormulaAndFunctionEventQueryGroupByFieldsAsFormulaAndFunctionEventQueryGroupByConfig is a convenience function that returns FormulaAndFunctionEventQueryGroupByFields wrapped in FormulaAndFunctionEventQueryGroupByConfig.
26+
func FormulaAndFunctionEventQueryGroupByFieldsAsFormulaAndFunctionEventQueryGroupByConfig(v *FormulaAndFunctionEventQueryGroupByFields) FormulaAndFunctionEventQueryGroupByConfig {
27+
return FormulaAndFunctionEventQueryGroupByConfig{FormulaAndFunctionEventQueryGroupByFields: v}
28+
}
29+
30+
// UnmarshalJSON turns data into one of the pointers in the struct.
31+
func (obj *FormulaAndFunctionEventQueryGroupByConfig) UnmarshalJSON(data []byte) error {
32+
var err error
33+
match := 0
34+
// try to unmarshal data into FormulaAndFunctionEventQueryGroupByList
35+
err = datadog.Unmarshal(data, &obj.FormulaAndFunctionEventQueryGroupByList)
36+
if err == nil {
37+
if obj.FormulaAndFunctionEventQueryGroupByList != nil {
38+
jsonFormulaAndFunctionEventQueryGroupByList, _ := datadog.Marshal(obj.FormulaAndFunctionEventQueryGroupByList)
39+
if string(jsonFormulaAndFunctionEventQueryGroupByList) == "{}" && string(data) != "{}" { // empty struct
40+
obj.FormulaAndFunctionEventQueryGroupByList = nil
41+
} else {
42+
match++
43+
}
44+
} else {
45+
obj.FormulaAndFunctionEventQueryGroupByList = nil
46+
}
47+
} else {
48+
obj.FormulaAndFunctionEventQueryGroupByList = nil
49+
}
50+
51+
// try to unmarshal data into FormulaAndFunctionEventQueryGroupByFields
52+
err = datadog.Unmarshal(data, &obj.FormulaAndFunctionEventQueryGroupByFields)
53+
if err == nil {
54+
if obj.FormulaAndFunctionEventQueryGroupByFields != nil && obj.FormulaAndFunctionEventQueryGroupByFields.UnparsedObject == nil {
55+
jsonFormulaAndFunctionEventQueryGroupByFields, _ := datadog.Marshal(obj.FormulaAndFunctionEventQueryGroupByFields)
56+
if string(jsonFormulaAndFunctionEventQueryGroupByFields) == "{}" { // empty struct
57+
obj.FormulaAndFunctionEventQueryGroupByFields = nil
58+
} else {
59+
match++
60+
}
61+
} else {
62+
obj.FormulaAndFunctionEventQueryGroupByFields = nil
63+
}
64+
} else {
65+
obj.FormulaAndFunctionEventQueryGroupByFields = nil
66+
}
67+
68+
if match != 1 { // more than 1 match
69+
// reset to nil
70+
obj.FormulaAndFunctionEventQueryGroupByList = nil
71+
obj.FormulaAndFunctionEventQueryGroupByFields = nil
72+
return datadog.Unmarshal(data, &obj.UnparsedObject)
73+
}
74+
return nil // exactly one match
75+
}
76+
77+
// MarshalJSON turns data from the first non-nil pointers in the struct to JSON.
78+
func (obj FormulaAndFunctionEventQueryGroupByConfig) MarshalJSON() ([]byte, error) {
79+
if obj.FormulaAndFunctionEventQueryGroupByList != nil {
80+
return datadog.Marshal(&obj.FormulaAndFunctionEventQueryGroupByList)
81+
}
82+
83+
if obj.FormulaAndFunctionEventQueryGroupByFields != nil {
84+
return datadog.Marshal(&obj.FormulaAndFunctionEventQueryGroupByFields)
85+
}
86+
87+
if obj.UnparsedObject != nil {
88+
return datadog.Marshal(obj.UnparsedObject)
89+
}
90+
return nil, nil // no data in oneOf schemas
91+
}
92+
93+
// GetActualInstance returns the actual instance.
94+
func (obj *FormulaAndFunctionEventQueryGroupByConfig) GetActualInstance() interface{} {
95+
if obj.FormulaAndFunctionEventQueryGroupByList != nil {
96+
return obj.FormulaAndFunctionEventQueryGroupByList
97+
}
98+
99+
if obj.FormulaAndFunctionEventQueryGroupByFields != nil {
100+
return obj.FormulaAndFunctionEventQueryGroupByFields
101+
}
102+
103+
// all schemas are nil
104+
return nil
105+
}
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
// Copyright 2019-Present Datadog, Inc.
4+
5+
package datadogV1
6+
7+
import (
8+
"fmt"
9+
10+
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
11+
)
12+
13+
// FormulaAndFunctionEventQueryGroupByFields Flat group by configuration using multiple event facet fields.
14+
type FormulaAndFunctionEventQueryGroupByFields struct {
15+
// List of event facets to group by.
16+
Fields []string `json:"fields"`
17+
// Number of groups to return.
18+
Limit *int64 `json:"limit,omitempty"`
19+
// Options for sorting group by results.
20+
Sort *FormulaAndFunctionEventQueryGroupBySort `json:"sort,omitempty"`
21+
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
22+
UnparsedObject map[string]interface{} `json:"-"`
23+
AdditionalProperties map[string]interface{} `json:"-"`
24+
}
25+
26+
// NewFormulaAndFunctionEventQueryGroupByFields instantiates a new FormulaAndFunctionEventQueryGroupByFields object.
27+
// This constructor will assign default values to properties that have it defined,
28+
// and makes sure properties required by API are set, but the set of arguments
29+
// will change when the set of required properties is changed.
30+
func NewFormulaAndFunctionEventQueryGroupByFields(fields []string) *FormulaAndFunctionEventQueryGroupByFields {
31+
this := FormulaAndFunctionEventQueryGroupByFields{}
32+
this.Fields = fields
33+
return &this
34+
}
35+
36+
// NewFormulaAndFunctionEventQueryGroupByFieldsWithDefaults instantiates a new FormulaAndFunctionEventQueryGroupByFields object.
37+
// This constructor will only assign default values to properties that have it defined,
38+
// but it doesn't guarantee that properties required by API are set.
39+
func NewFormulaAndFunctionEventQueryGroupByFieldsWithDefaults() *FormulaAndFunctionEventQueryGroupByFields {
40+
this := FormulaAndFunctionEventQueryGroupByFields{}
41+
return &this
42+
}
43+
44+
// GetFields returns the Fields field value.
45+
func (o *FormulaAndFunctionEventQueryGroupByFields) GetFields() []string {
46+
if o == nil {
47+
var ret []string
48+
return ret
49+
}
50+
return o.Fields
51+
}
52+
53+
// GetFieldsOk returns a tuple with the Fields field value
54+
// and a boolean to check if the value has been set.
55+
func (o *FormulaAndFunctionEventQueryGroupByFields) GetFieldsOk() (*[]string, bool) {
56+
if o == nil {
57+
return nil, false
58+
}
59+
return &o.Fields, true
60+
}
61+
62+
// SetFields sets field value.
63+
func (o *FormulaAndFunctionEventQueryGroupByFields) SetFields(v []string) {
64+
o.Fields = v
65+
}
66+
67+
// GetLimit returns the Limit field value if set, zero value otherwise.
68+
func (o *FormulaAndFunctionEventQueryGroupByFields) GetLimit() int64 {
69+
if o == nil || o.Limit == nil {
70+
var ret int64
71+
return ret
72+
}
73+
return *o.Limit
74+
}
75+
76+
// GetLimitOk returns a tuple with the Limit field value if set, nil otherwise
77+
// and a boolean to check if the value has been set.
78+
func (o *FormulaAndFunctionEventQueryGroupByFields) GetLimitOk() (*int64, bool) {
79+
if o == nil || o.Limit == nil {
80+
return nil, false
81+
}
82+
return o.Limit, true
83+
}
84+
85+
// HasLimit returns a boolean if a field has been set.
86+
func (o *FormulaAndFunctionEventQueryGroupByFields) HasLimit() bool {
87+
return o != nil && o.Limit != nil
88+
}
89+
90+
// SetLimit gets a reference to the given int64 and assigns it to the Limit field.
91+
func (o *FormulaAndFunctionEventQueryGroupByFields) SetLimit(v int64) {
92+
o.Limit = &v
93+
}
94+
95+
// GetSort returns the Sort field value if set, zero value otherwise.
96+
func (o *FormulaAndFunctionEventQueryGroupByFields) GetSort() FormulaAndFunctionEventQueryGroupBySort {
97+
if o == nil || o.Sort == nil {
98+
var ret FormulaAndFunctionEventQueryGroupBySort
99+
return ret
100+
}
101+
return *o.Sort
102+
}
103+
104+
// GetSortOk returns a tuple with the Sort field value if set, nil otherwise
105+
// and a boolean to check if the value has been set.
106+
func (o *FormulaAndFunctionEventQueryGroupByFields) GetSortOk() (*FormulaAndFunctionEventQueryGroupBySort, bool) {
107+
if o == nil || o.Sort == nil {
108+
return nil, false
109+
}
110+
return o.Sort, true
111+
}
112+
113+
// HasSort returns a boolean if a field has been set.
114+
func (o *FormulaAndFunctionEventQueryGroupByFields) HasSort() bool {
115+
return o != nil && o.Sort != nil
116+
}
117+
118+
// SetSort gets a reference to the given FormulaAndFunctionEventQueryGroupBySort and assigns it to the Sort field.
119+
func (o *FormulaAndFunctionEventQueryGroupByFields) SetSort(v FormulaAndFunctionEventQueryGroupBySort) {
120+
o.Sort = &v
121+
}
122+
123+
// MarshalJSON serializes the struct using spec logic.
124+
func (o FormulaAndFunctionEventQueryGroupByFields) MarshalJSON() ([]byte, error) {
125+
toSerialize := map[string]interface{}{}
126+
if o.UnparsedObject != nil {
127+
return datadog.Marshal(o.UnparsedObject)
128+
}
129+
toSerialize["fields"] = o.Fields
130+
if o.Limit != nil {
131+
toSerialize["limit"] = o.Limit
132+
}
133+
if o.Sort != nil {
134+
toSerialize["sort"] = o.Sort
135+
}
136+
137+
for key, value := range o.AdditionalProperties {
138+
toSerialize[key] = value
139+
}
140+
return datadog.Marshal(toSerialize)
141+
}
142+
143+
// UnmarshalJSON deserializes the given payload.
144+
func (o *FormulaAndFunctionEventQueryGroupByFields) UnmarshalJSON(bytes []byte) (err error) {
145+
all := struct {
146+
Fields *[]string `json:"fields"`
147+
Limit *int64 `json:"limit,omitempty"`
148+
Sort *FormulaAndFunctionEventQueryGroupBySort `json:"sort,omitempty"`
149+
}{}
150+
if err = datadog.Unmarshal(bytes, &all); err != nil {
151+
return datadog.Unmarshal(bytes, &o.UnparsedObject)
152+
}
153+
if all.Fields == nil {
154+
return fmt.Errorf("required field fields missing")
155+
}
156+
additionalProperties := make(map[string]interface{})
157+
if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil {
158+
datadog.DeleteKeys(additionalProperties, &[]string{"fields", "limit", "sort"})
159+
} else {
160+
return err
161+
}
162+
163+
hasInvalidField := false
164+
o.Fields = *all.Fields
165+
o.Limit = all.Limit
166+
if all.Sort != nil && all.Sort.UnparsedObject != nil && o.UnparsedObject == nil {
167+
hasInvalidField = true
168+
}
169+
o.Sort = all.Sort
170+
171+
if len(additionalProperties) > 0 {
172+
o.AdditionalProperties = additionalProperties
173+
}
174+
175+
if hasInvalidField {
176+
return datadog.Unmarshal(bytes, &o.UnparsedObject)
177+
}
178+
179+
return nil
180+
}

0 commit comments

Comments
 (0)