From 49c5692490056ea8297a7ebd94aba2d5747dd80e Mon Sep 17 00:00:00 2001 From: "ci.datadog-api-spec" Date: Wed, 21 Sep 2022 15:05:30 +0000 Subject: [PATCH] Regenerate client from commit 6d52d28b of spec repo --- .apigentools-info | 8 +- .generator/schemas/v1/openapi.yaml | 70 +++++ .../model_slo_list_widget_definition.go | 271 ++++++++++++++++++ .../model_slo_list_widget_definition_type.go | 107 +++++++ api/datadogV1/model_slo_list_widget_query.go | 146 ++++++++++ .../model_slo_list_widget_request.go | 151 ++++++++++ .../model_slo_list_widget_request_type.go | 107 +++++++ api/datadogV1/model_widget_definition.go | 32 +++ .../dashboards/CreateDashboard_1423904722.go | 62 ++++ ..._new_dashboard_with_slo_list_widget.freeze | 1 + ..._a_new_dashboard_with_slo_list_widget.yaml | 81 ++++++ .../scenarios/features/v1/dashboards.feature | 11 + .../slo_list_widget.json | 32 +++ 13 files changed, 1075 insertions(+), 4 deletions(-) create mode 100644 api/datadogV1/model_slo_list_widget_definition.go create mode 100644 api/datadogV1/model_slo_list_widget_definition_type.go create mode 100644 api/datadogV1/model_slo_list_widget_query.go create mode 100644 api/datadogV1/model_slo_list_widget_request.go create mode 100644 api/datadogV1/model_slo_list_widget_request_type.go create mode 100644 examples/v1/dashboards/CreateDashboard_1423904722.go create mode 100644 tests/scenarios/cassettes/TestScenarios/v1/Feature_Dashboards/Scenario_Create_a_new_dashboard_with_slo_list_widget.freeze create mode 100644 tests/scenarios/cassettes/TestScenarios/v1/Feature_Dashboards/Scenario_Create_a_new_dashboard_with_slo_list_widget.yaml create mode 100644 tests/scenarios/features/v1/dashboards_json_payload/slo_list_widget.json diff --git a/.apigentools-info b/.apigentools-info index f48e381c22c..f267f0cdef0 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.4", - "regenerated": "2022-09-16 13:42:49.599994", - "spec_repo_commit": "acc0b78b" + "regenerated": "2022-09-21 15:04:02.814313", + "spec_repo_commit": "6d52d28b" }, "v2": { "apigentools_version": "1.6.4", - "regenerated": "2022-09-16 13:42:49.615641", - "spec_repo_commit": "acc0b78b" + "regenerated": "2022-09-21 15:04:02.834084", + "spec_repo_commit": "6d52d28b" } } } \ No newline at end of file diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index 2990ab08c55..3dec55959c7 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -9262,6 +9262,75 @@ components: format: int64 type: integer type: object + SLOListWidgetDefinition: + description: Use the SLO List widget to track your SLOs (Service Level Objectives) + on screenboards. + properties: + requests: + description: Array of one request object to display in the widget. + items: + $ref: '#/components/schemas/SLOListWidgetRequest' + maxItems: 1 + minItems: 1 + type: array + title: + description: Title of the widget. + type: string + title_align: + $ref: '#/components/schemas/WidgetTextAlign' + title_size: + description: Size of the title. + type: string + type: + $ref: '#/components/schemas/SLOListWidgetDefinitionType' + required: + - type + - requests + type: object + SLOListWidgetDefinitionType: + default: slo_list + description: Type of the SLO List widget. + enum: + - slo_list + example: slo_list + type: string + x-enum-varnames: + - SLO_LIST + SLOListWidgetQuery: + description: Updated SLO List widget. + properties: + limit: + default: 100 + description: Maximum number of results to display in the table. + format: int64 + maximum: 100 + minimum: 1 + type: integer + query_string: + description: Widget query. + example: env:prod AND service:my-app + type: string + required: + - query_string + type: object + SLOListWidgetRequest: + description: Updated SLO List widget. + properties: + query: + $ref: '#/components/schemas/SLOListWidgetQuery' + request_type: + $ref: '#/components/schemas/SLOListWidgetRequestType' + required: + - query + - request_type + type: object + SLOListWidgetRequestType: + description: Widget request type. + enum: + - slo_list + type: string + x-enum-varnames: + - SLO_LIST SLOOverallStatuses: description: Overall status of the SLO by timeframes. properties: @@ -17340,6 +17409,7 @@ components: - $ref: '#/components/schemas/QueryValueWidgetDefinition' - $ref: '#/components/schemas/ScatterPlotWidgetDefinition' - $ref: '#/components/schemas/SLOWidgetDefinition' + - $ref: '#/components/schemas/SLOListWidgetDefinition' - $ref: '#/components/schemas/ServiceMapWidgetDefinition' - $ref: '#/components/schemas/ServiceSummaryWidgetDefinition' - $ref: '#/components/schemas/SunburstWidgetDefinition' diff --git a/api/datadogV1/model_slo_list_widget_definition.go b/api/datadogV1/model_slo_list_widget_definition.go new file mode 100644 index 00000000000..f39da62a72d --- /dev/null +++ b/api/datadogV1/model_slo_list_widget_definition.go @@ -0,0 +1,271 @@ +// 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 ( + "encoding/json" + "fmt" +) + +// SLOListWidgetDefinition Use the SLO List widget to track your SLOs (Service Level Objectives) on screenboards. +type SLOListWidgetDefinition struct { + // Array of one request object to display in the widget. + Requests []SLOListWidgetRequest `json:"requests"` + // Title of the widget. + Title *string `json:"title,omitempty"` + // How to align the text on the widget. + TitleAlign *WidgetTextAlign `json:"title_align,omitempty"` + // Size of the title. + TitleSize *string `json:"title_size,omitempty"` + // Type of the SLO List widget. + Type SLOListWidgetDefinitionType `json:"type"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:-` + AdditionalProperties map[string]interface{} +} + +// NewSLOListWidgetDefinition instantiates a new SLOListWidgetDefinition object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewSLOListWidgetDefinition(requests []SLOListWidgetRequest, typeVar SLOListWidgetDefinitionType) *SLOListWidgetDefinition { + this := SLOListWidgetDefinition{} + this.Requests = requests + this.Type = typeVar + return &this +} + +// NewSLOListWidgetDefinitionWithDefaults instantiates a new SLOListWidgetDefinition object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewSLOListWidgetDefinitionWithDefaults() *SLOListWidgetDefinition { + this := SLOListWidgetDefinition{} + var typeVar SLOListWidgetDefinitionType = SLOLISTWIDGETDEFINITIONTYPE_SLO_LIST + this.Type = typeVar + return &this +} + +// GetRequests returns the Requests field value. +func (o *SLOListWidgetDefinition) GetRequests() []SLOListWidgetRequest { + if o == nil { + var ret []SLOListWidgetRequest + return ret + } + return o.Requests +} + +// GetRequestsOk returns a tuple with the Requests field value +// and a boolean to check if the value has been set. +func (o *SLOListWidgetDefinition) GetRequestsOk() (*[]SLOListWidgetRequest, bool) { + if o == nil { + return nil, false + } + return &o.Requests, true +} + +// SetRequests sets field value. +func (o *SLOListWidgetDefinition) SetRequests(v []SLOListWidgetRequest) { + o.Requests = v +} + +// GetTitle returns the Title field value if set, zero value otherwise. +func (o *SLOListWidgetDefinition) GetTitle() string { + if o == nil || o.Title == nil { + var ret string + return ret + } + return *o.Title +} + +// GetTitleOk returns a tuple with the Title field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SLOListWidgetDefinition) GetTitleOk() (*string, bool) { + if o == nil || o.Title == nil { + return nil, false + } + return o.Title, true +} + +// HasTitle returns a boolean if a field has been set. +func (o *SLOListWidgetDefinition) HasTitle() bool { + if o != nil && o.Title != nil { + return true + } + + return false +} + +// SetTitle gets a reference to the given string and assigns it to the Title field. +func (o *SLOListWidgetDefinition) SetTitle(v string) { + o.Title = &v +} + +// GetTitleAlign returns the TitleAlign field value if set, zero value otherwise. +func (o *SLOListWidgetDefinition) GetTitleAlign() WidgetTextAlign { + if o == nil || o.TitleAlign == nil { + var ret WidgetTextAlign + return ret + } + return *o.TitleAlign +} + +// GetTitleAlignOk returns a tuple with the TitleAlign field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SLOListWidgetDefinition) GetTitleAlignOk() (*WidgetTextAlign, bool) { + if o == nil || o.TitleAlign == nil { + return nil, false + } + return o.TitleAlign, true +} + +// HasTitleAlign returns a boolean if a field has been set. +func (o *SLOListWidgetDefinition) HasTitleAlign() bool { + if o != nil && o.TitleAlign != nil { + return true + } + + return false +} + +// SetTitleAlign gets a reference to the given WidgetTextAlign and assigns it to the TitleAlign field. +func (o *SLOListWidgetDefinition) SetTitleAlign(v WidgetTextAlign) { + o.TitleAlign = &v +} + +// GetTitleSize returns the TitleSize field value if set, zero value otherwise. +func (o *SLOListWidgetDefinition) GetTitleSize() string { + if o == nil || o.TitleSize == nil { + var ret string + return ret + } + return *o.TitleSize +} + +// GetTitleSizeOk returns a tuple with the TitleSize field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SLOListWidgetDefinition) GetTitleSizeOk() (*string, bool) { + if o == nil || o.TitleSize == nil { + return nil, false + } + return o.TitleSize, true +} + +// HasTitleSize returns a boolean if a field has been set. +func (o *SLOListWidgetDefinition) HasTitleSize() bool { + if o != nil && o.TitleSize != nil { + return true + } + + return false +} + +// SetTitleSize gets a reference to the given string and assigns it to the TitleSize field. +func (o *SLOListWidgetDefinition) SetTitleSize(v string) { + o.TitleSize = &v +} + +// GetType returns the Type field value. +func (o *SLOListWidgetDefinition) GetType() SLOListWidgetDefinitionType { + if o == nil { + var ret SLOListWidgetDefinitionType + return ret + } + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *SLOListWidgetDefinition) GetTypeOk() (*SLOListWidgetDefinitionType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value. +func (o *SLOListWidgetDefinition) SetType(v SLOListWidgetDefinitionType) { + o.Type = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o SLOListWidgetDefinition) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return json.Marshal(o.UnparsedObject) + } + toSerialize["requests"] = o.Requests + if o.Title != nil { + toSerialize["title"] = o.Title + } + if o.TitleAlign != nil { + toSerialize["title_align"] = o.TitleAlign + } + if o.TitleSize != nil { + toSerialize["title_size"] = o.TitleSize + } + toSerialize["type"] = o.Type + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return json.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *SLOListWidgetDefinition) UnmarshalJSON(bytes []byte) (err error) { + raw := map[string]interface{}{} + required := struct { + Requests *[]SLOListWidgetRequest `json:"requests"` + Type *SLOListWidgetDefinitionType `json:"type"` + }{} + all := struct { + Requests []SLOListWidgetRequest `json:"requests"` + Title *string `json:"title,omitempty"` + TitleAlign *WidgetTextAlign `json:"title_align,omitempty"` + TitleSize *string `json:"title_size,omitempty"` + Type SLOListWidgetDefinitionType `json:"type"` + }{} + err = json.Unmarshal(bytes, &required) + if err != nil { + return err + } + if required.Requests == nil { + return fmt.Errorf("Required field requests missing") + } + if required.Type == nil { + return fmt.Errorf("Required field type missing") + } + err = json.Unmarshal(bytes, &all) + if err != nil { + err = json.Unmarshal(bytes, &raw) + if err != nil { + return err + } + o.UnparsedObject = raw + return nil + } + if v := all.TitleAlign; v != nil && !v.IsValid() { + err = json.Unmarshal(bytes, &raw) + if err != nil { + return err + } + o.UnparsedObject = raw + return nil + } + if v := all.Type; !v.IsValid() { + err = json.Unmarshal(bytes, &raw) + if err != nil { + return err + } + o.UnparsedObject = raw + return nil + } + o.Requests = all.Requests + o.Title = all.Title + o.TitleAlign = all.TitleAlign + o.TitleSize = all.TitleSize + o.Type = all.Type + return nil +} diff --git a/api/datadogV1/model_slo_list_widget_definition_type.go b/api/datadogV1/model_slo_list_widget_definition_type.go new file mode 100644 index 00000000000..8e337c00031 --- /dev/null +++ b/api/datadogV1/model_slo_list_widget_definition_type.go @@ -0,0 +1,107 @@ +// 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 ( + "encoding/json" + "fmt" +) + +// SLOListWidgetDefinitionType Type of the SLO List widget. +type SLOListWidgetDefinitionType string + +// List of SLOListWidgetDefinitionType. +const ( + SLOLISTWIDGETDEFINITIONTYPE_SLO_LIST SLOListWidgetDefinitionType = "slo_list" +) + +var allowedSLOListWidgetDefinitionTypeEnumValues = []SLOListWidgetDefinitionType{ + SLOLISTWIDGETDEFINITIONTYPE_SLO_LIST, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *SLOListWidgetDefinitionType) GetAllowedValues() []SLOListWidgetDefinitionType { + return allowedSLOListWidgetDefinitionTypeEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *SLOListWidgetDefinitionType) UnmarshalJSON(src []byte) error { + var value string + err := json.Unmarshal(src, &value) + if err != nil { + return err + } + *v = SLOListWidgetDefinitionType(value) + return nil +} + +// NewSLOListWidgetDefinitionTypeFromValue returns a pointer to a valid SLOListWidgetDefinitionType +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewSLOListWidgetDefinitionTypeFromValue(v string) (*SLOListWidgetDefinitionType, error) { + ev := SLOListWidgetDefinitionType(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for SLOListWidgetDefinitionType: valid values are %v", v, allowedSLOListWidgetDefinitionTypeEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v SLOListWidgetDefinitionType) IsValid() bool { + for _, existing := range allowedSLOListWidgetDefinitionTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to SLOListWidgetDefinitionType value. +func (v SLOListWidgetDefinitionType) Ptr() *SLOListWidgetDefinitionType { + return &v +} + +// NullableSLOListWidgetDefinitionType handles when a null is used for SLOListWidgetDefinitionType. +type NullableSLOListWidgetDefinitionType struct { + value *SLOListWidgetDefinitionType + isSet bool +} + +// Get returns the associated value. +func (v NullableSLOListWidgetDefinitionType) Get() *SLOListWidgetDefinitionType { + return v.value +} + +// Set changes the value and indicates it's been called. +func (v *NullableSLOListWidgetDefinitionType) Set(val *SLOListWidgetDefinitionType) { + v.value = val + v.isSet = true +} + +// IsSet returns whether Set has been called. +func (v NullableSLOListWidgetDefinitionType) IsSet() bool { + return v.isSet +} + +// Unset sets the value to nil and resets the set flag. +func (v *NullableSLOListWidgetDefinitionType) Unset() { + v.value = nil + v.isSet = false +} + +// NewNullableSLOListWidgetDefinitionType initializes the struct as if Set has been called. +func NewNullableSLOListWidgetDefinitionType(val *SLOListWidgetDefinitionType) *NullableSLOListWidgetDefinitionType { + return &NullableSLOListWidgetDefinitionType{value: val, isSet: true} +} + +// MarshalJSON serializes the associated value. +func (v NullableSLOListWidgetDefinitionType) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +// UnmarshalJSON deserializes the payload and sets the flag as if Set has been called. +func (v *NullableSLOListWidgetDefinitionType) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/api/datadogV1/model_slo_list_widget_query.go b/api/datadogV1/model_slo_list_widget_query.go new file mode 100644 index 00000000000..3187dd349f0 --- /dev/null +++ b/api/datadogV1/model_slo_list_widget_query.go @@ -0,0 +1,146 @@ +// 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 ( + "encoding/json" + "fmt" +) + +// SLOListWidgetQuery Updated SLO List widget. +type SLOListWidgetQuery struct { + // Maximum number of results to display in the table. + Limit *int64 `json:"limit,omitempty"` + // Widget query. + QueryString string `json:"query_string"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:-` + AdditionalProperties map[string]interface{} +} + +// NewSLOListWidgetQuery instantiates a new SLOListWidgetQuery object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewSLOListWidgetQuery(queryString string) *SLOListWidgetQuery { + this := SLOListWidgetQuery{} + var limit int64 = 100 + this.Limit = &limit + this.QueryString = queryString + return &this +} + +// NewSLOListWidgetQueryWithDefaults instantiates a new SLOListWidgetQuery object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewSLOListWidgetQueryWithDefaults() *SLOListWidgetQuery { + this := SLOListWidgetQuery{} + var limit int64 = 100 + this.Limit = &limit + return &this +} + +// GetLimit returns the Limit field value if set, zero value otherwise. +func (o *SLOListWidgetQuery) GetLimit() int64 { + if o == nil || o.Limit == nil { + var ret int64 + return ret + } + return *o.Limit +} + +// GetLimitOk returns a tuple with the Limit field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SLOListWidgetQuery) GetLimitOk() (*int64, bool) { + if o == nil || o.Limit == nil { + return nil, false + } + return o.Limit, true +} + +// HasLimit returns a boolean if a field has been set. +func (o *SLOListWidgetQuery) HasLimit() bool { + if o != nil && o.Limit != nil { + return true + } + + return false +} + +// SetLimit gets a reference to the given int64 and assigns it to the Limit field. +func (o *SLOListWidgetQuery) SetLimit(v int64) { + o.Limit = &v +} + +// GetQueryString returns the QueryString field value. +func (o *SLOListWidgetQuery) GetQueryString() string { + if o == nil { + var ret string + return ret + } + return o.QueryString +} + +// GetQueryStringOk returns a tuple with the QueryString field value +// and a boolean to check if the value has been set. +func (o *SLOListWidgetQuery) GetQueryStringOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.QueryString, true +} + +// SetQueryString sets field value. +func (o *SLOListWidgetQuery) SetQueryString(v string) { + o.QueryString = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o SLOListWidgetQuery) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return json.Marshal(o.UnparsedObject) + } + if o.Limit != nil { + toSerialize["limit"] = o.Limit + } + toSerialize["query_string"] = o.QueryString + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return json.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *SLOListWidgetQuery) UnmarshalJSON(bytes []byte) (err error) { + raw := map[string]interface{}{} + required := struct { + QueryString *string `json:"query_string"` + }{} + all := struct { + Limit *int64 `json:"limit,omitempty"` + QueryString string `json:"query_string"` + }{} + err = json.Unmarshal(bytes, &required) + if err != nil { + return err + } + if required.QueryString == nil { + return fmt.Errorf("Required field query_string missing") + } + err = json.Unmarshal(bytes, &all) + if err != nil { + err = json.Unmarshal(bytes, &raw) + if err != nil { + return err + } + o.UnparsedObject = raw + return nil + } + o.Limit = all.Limit + o.QueryString = all.QueryString + return nil +} diff --git a/api/datadogV1/model_slo_list_widget_request.go b/api/datadogV1/model_slo_list_widget_request.go new file mode 100644 index 00000000000..1d398c0907a --- /dev/null +++ b/api/datadogV1/model_slo_list_widget_request.go @@ -0,0 +1,151 @@ +// 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 ( + "encoding/json" + "fmt" +) + +// SLOListWidgetRequest Updated SLO List widget. +type SLOListWidgetRequest struct { + // Updated SLO List widget. + Query SLOListWidgetQuery `json:"query"` + // Widget request type. + RequestType SLOListWidgetRequestType `json:"request_type"` + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject map[string]interface{} `json:-` + AdditionalProperties map[string]interface{} +} + +// NewSLOListWidgetRequest instantiates a new SLOListWidgetRequest object. +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed. +func NewSLOListWidgetRequest(query SLOListWidgetQuery, requestType SLOListWidgetRequestType) *SLOListWidgetRequest { + this := SLOListWidgetRequest{} + this.Query = query + this.RequestType = requestType + return &this +} + +// NewSLOListWidgetRequestWithDefaults instantiates a new SLOListWidgetRequest object. +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set. +func NewSLOListWidgetRequestWithDefaults() *SLOListWidgetRequest { + this := SLOListWidgetRequest{} + return &this +} + +// GetQuery returns the Query field value. +func (o *SLOListWidgetRequest) GetQuery() SLOListWidgetQuery { + if o == nil { + var ret SLOListWidgetQuery + return ret + } + return o.Query +} + +// GetQueryOk returns a tuple with the Query field value +// and a boolean to check if the value has been set. +func (o *SLOListWidgetRequest) GetQueryOk() (*SLOListWidgetQuery, bool) { + if o == nil { + return nil, false + } + return &o.Query, true +} + +// SetQuery sets field value. +func (o *SLOListWidgetRequest) SetQuery(v SLOListWidgetQuery) { + o.Query = v +} + +// GetRequestType returns the RequestType field value. +func (o *SLOListWidgetRequest) GetRequestType() SLOListWidgetRequestType { + if o == nil { + var ret SLOListWidgetRequestType + return ret + } + return o.RequestType +} + +// GetRequestTypeOk returns a tuple with the RequestType field value +// and a boolean to check if the value has been set. +func (o *SLOListWidgetRequest) GetRequestTypeOk() (*SLOListWidgetRequestType, bool) { + if o == nil { + return nil, false + } + return &o.RequestType, true +} + +// SetRequestType sets field value. +func (o *SLOListWidgetRequest) SetRequestType(v SLOListWidgetRequestType) { + o.RequestType = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o SLOListWidgetRequest) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return json.Marshal(o.UnparsedObject) + } + toSerialize["query"] = o.Query + toSerialize["request_type"] = o.RequestType + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return json.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *SLOListWidgetRequest) UnmarshalJSON(bytes []byte) (err error) { + raw := map[string]interface{}{} + required := struct { + Query *SLOListWidgetQuery `json:"query"` + RequestType *SLOListWidgetRequestType `json:"request_type"` + }{} + all := struct { + Query SLOListWidgetQuery `json:"query"` + RequestType SLOListWidgetRequestType `json:"request_type"` + }{} + err = json.Unmarshal(bytes, &required) + if err != nil { + return err + } + if required.Query == nil { + return fmt.Errorf("Required field query missing") + } + if required.RequestType == nil { + return fmt.Errorf("Required field request_type missing") + } + err = json.Unmarshal(bytes, &all) + if err != nil { + err = json.Unmarshal(bytes, &raw) + if err != nil { + return err + } + o.UnparsedObject = raw + return nil + } + if v := all.RequestType; !v.IsValid() { + err = json.Unmarshal(bytes, &raw) + if err != nil { + return err + } + o.UnparsedObject = raw + return nil + } + if all.Query.UnparsedObject != nil && o.UnparsedObject == nil { + err = json.Unmarshal(bytes, &raw) + if err != nil { + return err + } + o.UnparsedObject = raw + } + o.Query = all.Query + o.RequestType = all.RequestType + return nil +} diff --git a/api/datadogV1/model_slo_list_widget_request_type.go b/api/datadogV1/model_slo_list_widget_request_type.go new file mode 100644 index 00000000000..4a93ebf405b --- /dev/null +++ b/api/datadogV1/model_slo_list_widget_request_type.go @@ -0,0 +1,107 @@ +// 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 ( + "encoding/json" + "fmt" +) + +// SLOListWidgetRequestType Widget request type. +type SLOListWidgetRequestType string + +// List of SLOListWidgetRequestType. +const ( + SLOLISTWIDGETREQUESTTYPE_SLO_LIST SLOListWidgetRequestType = "slo_list" +) + +var allowedSLOListWidgetRequestTypeEnumValues = []SLOListWidgetRequestType{ + SLOLISTWIDGETREQUESTTYPE_SLO_LIST, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *SLOListWidgetRequestType) GetAllowedValues() []SLOListWidgetRequestType { + return allowedSLOListWidgetRequestTypeEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *SLOListWidgetRequestType) UnmarshalJSON(src []byte) error { + var value string + err := json.Unmarshal(src, &value) + if err != nil { + return err + } + *v = SLOListWidgetRequestType(value) + return nil +} + +// NewSLOListWidgetRequestTypeFromValue returns a pointer to a valid SLOListWidgetRequestType +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewSLOListWidgetRequestTypeFromValue(v string) (*SLOListWidgetRequestType, error) { + ev := SLOListWidgetRequestType(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for SLOListWidgetRequestType: valid values are %v", v, allowedSLOListWidgetRequestTypeEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v SLOListWidgetRequestType) IsValid() bool { + for _, existing := range allowedSLOListWidgetRequestTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to SLOListWidgetRequestType value. +func (v SLOListWidgetRequestType) Ptr() *SLOListWidgetRequestType { + return &v +} + +// NullableSLOListWidgetRequestType handles when a null is used for SLOListWidgetRequestType. +type NullableSLOListWidgetRequestType struct { + value *SLOListWidgetRequestType + isSet bool +} + +// Get returns the associated value. +func (v NullableSLOListWidgetRequestType) Get() *SLOListWidgetRequestType { + return v.value +} + +// Set changes the value and indicates it's been called. +func (v *NullableSLOListWidgetRequestType) Set(val *SLOListWidgetRequestType) { + v.value = val + v.isSet = true +} + +// IsSet returns whether Set has been called. +func (v NullableSLOListWidgetRequestType) IsSet() bool { + return v.isSet +} + +// Unset sets the value to nil and resets the set flag. +func (v *NullableSLOListWidgetRequestType) Unset() { + v.value = nil + v.isSet = false +} + +// NewNullableSLOListWidgetRequestType initializes the struct as if Set has been called. +func NewNullableSLOListWidgetRequestType(val *SLOListWidgetRequestType) *NullableSLOListWidgetRequestType { + return &NullableSLOListWidgetRequestType{value: val, isSet: true} +} + +// MarshalJSON serializes the associated value. +func (v NullableSLOListWidgetRequestType) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +// UnmarshalJSON deserializes the payload and sets the flag as if Set has been called. +func (v *NullableSLOListWidgetRequestType) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/api/datadogV1/model_widget_definition.go b/api/datadogV1/model_widget_definition.go index 416032fe5a8..ee38742ba1f 100644 --- a/api/datadogV1/model_widget_definition.go +++ b/api/datadogV1/model_widget_definition.go @@ -30,6 +30,7 @@ type WidgetDefinition struct { QueryValueWidgetDefinition *QueryValueWidgetDefinition ScatterPlotWidgetDefinition *ScatterPlotWidgetDefinition SLOWidgetDefinition *SLOWidgetDefinition + SLOListWidgetDefinition *SLOListWidgetDefinition ServiceMapWidgetDefinition *ServiceMapWidgetDefinition ServiceSummaryWidgetDefinition *ServiceSummaryWidgetDefinition SunburstWidgetDefinition *SunburstWidgetDefinition @@ -145,6 +146,11 @@ func SLOWidgetDefinitionAsWidgetDefinition(v *SLOWidgetDefinition) WidgetDefinit return WidgetDefinition{SLOWidgetDefinition: v} } +// SLOListWidgetDefinitionAsWidgetDefinition is a convenience function that returns SLOListWidgetDefinition wrapped in WidgetDefinition. +func SLOListWidgetDefinitionAsWidgetDefinition(v *SLOListWidgetDefinition) WidgetDefinition { + return WidgetDefinition{SLOListWidgetDefinition: v} +} + // ServiceMapWidgetDefinitionAsWidgetDefinition is a convenience function that returns ServiceMapWidgetDefinition wrapped in WidgetDefinition. func ServiceMapWidgetDefinitionAsWidgetDefinition(v *ServiceMapWidgetDefinition) WidgetDefinition { return WidgetDefinition{ServiceMapWidgetDefinition: v} @@ -539,6 +545,23 @@ func (obj *WidgetDefinition) UnmarshalJSON(data []byte) error { obj.SLOWidgetDefinition = nil } + // try to unmarshal data into SLOListWidgetDefinition + err = json.Unmarshal(data, &obj.SLOListWidgetDefinition) + if err == nil { + if obj.SLOListWidgetDefinition != nil && obj.SLOListWidgetDefinition.UnparsedObject == nil { + jsonSLOListWidgetDefinition, _ := json.Marshal(obj.SLOListWidgetDefinition) + if string(jsonSLOListWidgetDefinition) == "{}" { // empty struct + obj.SLOListWidgetDefinition = nil + } else { + match++ + } + } else { + obj.SLOListWidgetDefinition = nil + } + } else { + obj.SLOListWidgetDefinition = nil + } + // try to unmarshal data into ServiceMapWidgetDefinition err = json.Unmarshal(data, &obj.ServiceMapWidgetDefinition) if err == nil { @@ -731,6 +754,7 @@ func (obj *WidgetDefinition) UnmarshalJSON(data []byte) error { obj.QueryValueWidgetDefinition = nil obj.ScatterPlotWidgetDefinition = nil obj.SLOWidgetDefinition = nil + obj.SLOListWidgetDefinition = nil obj.ServiceMapWidgetDefinition = nil obj.ServiceSummaryWidgetDefinition = nil obj.SunburstWidgetDefinition = nil @@ -828,6 +852,10 @@ func (obj WidgetDefinition) MarshalJSON() ([]byte, error) { return json.Marshal(&obj.SLOWidgetDefinition) } + if obj.SLOListWidgetDefinition != nil { + return json.Marshal(&obj.SLOListWidgetDefinition) + } + if obj.ServiceMapWidgetDefinition != nil { return json.Marshal(&obj.ServiceMapWidgetDefinition) } @@ -956,6 +984,10 @@ func (obj *WidgetDefinition) GetActualInstance() interface{} { return obj.SLOWidgetDefinition } + if obj.SLOListWidgetDefinition != nil { + return obj.SLOListWidgetDefinition + } + if obj.ServiceMapWidgetDefinition != nil { return obj.ServiceMapWidgetDefinition } diff --git a/examples/v1/dashboards/CreateDashboard_1423904722.go b/examples/v1/dashboards/CreateDashboard_1423904722.go new file mode 100644 index 00000000000..c31a052900d --- /dev/null +++ b/examples/v1/dashboards/CreateDashboard_1423904722.go @@ -0,0 +1,62 @@ +// Create a new dashboard with slo list widget + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV1" +) + +func main() { + body := datadogV1.Dashboard{ + Title: "Example-Create_a_new_dashboard_with_slo_list_widget", + Description: *datadog.NewNullableString(datadog.PtrString("")), + Widgets: []datadogV1.Widget{ + { + Layout: &datadogV1.WidgetLayout{ + X: 0, + Y: 0, + Width: 60, + Height: 21, + }, + Definition: datadogV1.WidgetDefinition{ + SLOListWidgetDefinition: &datadogV1.SLOListWidgetDefinition{ + TitleSize: datadog.PtrString("16"), + TitleAlign: datadogV1.WIDGETTEXTALIGN_LEFT.Ptr(), + Type: datadogV1.SLOLISTWIDGETDEFINITIONTYPE_SLO_LIST, + Requests: []datadogV1.SLOListWidgetRequest{ + { + Query: datadogV1.SLOListWidgetQuery{ + QueryString: "env:prod AND service:my-app", + Limit: datadog.PtrInt64(75), + }, + RequestType: datadogV1.SLOLISTWIDGETREQUESTTYPE_SLO_LIST, + }, + }, + }}, + }, + }, + TemplateVariables: []datadogV1.DashboardTemplateVariable{}, + LayoutType: datadogV1.DASHBOARDLAYOUTTYPE_FREE, + IsReadOnly: datadog.PtrBool(false), + NotifyList: []string{}, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + api := datadogV1.NewDashboardsApi(apiClient) + resp, r, err := api.CreateDashboard(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent) +} diff --git a/tests/scenarios/cassettes/TestScenarios/v1/Feature_Dashboards/Scenario_Create_a_new_dashboard_with_slo_list_widget.freeze b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Dashboards/Scenario_Create_a_new_dashboard_with_slo_list_widget.freeze new file mode 100644 index 00000000000..3175b16b31e --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Dashboards/Scenario_Create_a_new_dashboard_with_slo_list_widget.freeze @@ -0,0 +1 @@ +2022-09-21T14:58:35.783Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/TestScenarios/v1/Feature_Dashboards/Scenario_Create_a_new_dashboard_with_slo_list_widget.yaml b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Dashboards/Scenario_Create_a_new_dashboard_with_slo_list_widget.yaml new file mode 100644 index 00000000000..db96ae48c33 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Dashboards/Scenario_Create_a_new_dashboard_with_slo_list_widget.yaml @@ -0,0 +1,81 @@ +interactions: +- request: + body: | + {"name":"Test-Create_a_new_dashboard_with_slo_list_widget-1663772315","query":{"denominator":"sum:httpservice.hits{!code:3xx}.as_count()","numerator":"sum:httpservice.hits{code:2xx}.as_count()"},"thresholds":[{"target":95,"timeframe":"7d","warning":98}],"type":"metric"} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + method: POST + url: https://api.datadoghq.com/api/v1/slo + response: + body: '{"data":[{"description":"","monitor_tags":[],"creator":{"handle":"frog@datadoghq.com","name":null,"email":"frog@datadoghq.com"},"thresholds":[{"warning":98.0,"warning_display":"98.","target":95.0,"target_display":"95.","timeframe":"7d"}],"type_id":1,"query":{"denominator":"sum:httpservice.hits{!code:3xx}.as_count()","numerator":"sum:httpservice.hits{code:2xx}.as_count()"},"id":"7f88381afe5f5c1e987664e7057253fd","name":"Test-Create_a_new_dashboard_with_slo_list_widget-1663772315","created_at":1663772316,"tags":[],"modified_at":1663772316,"type":"metric"}],"error":null} + + ' + code: 200 + duration: '' + headers: + Content-Type: + - application/json + status: 200 OK +- request: + body: | + {"description":"","is_read_only":false,"layout_type":"free","notify_list":[],"template_variables":[],"title":"Test-Create_a_new_dashboard_with_slo_list_widget-1663772315","widgets":[{"definition":{"requests":[{"query":{"limit":75,"query_string":"env:prod AND service:my-app"},"request_type":"slo_list"}],"title_align":"left","title_size":"16","type":"slo_list"},"layout":{"height":21,"width":60,"x":0,"y":0}}]} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + method: POST + url: https://api.datadoghq.com/api/v1/dashboard + response: + body: '{"notify_list":[],"description":"","restricted_roles":[],"author_name":null,"template_variables":[],"is_read_only":false,"id":"xf3-y64-ib5","title":"Test-Create_a_new_dashboard_with_slo_list_widget-1663772315","url":"/dashboard/xf3-y64-ib5/test-createanewdashboardwithslolistwidget-1663772315","created_at":"2022-09-21T14:58:36.648616+00:00","modified_at":"2022-09-21T14:58:36.648616+00:00","author_handle":"frog@datadoghq.com","widgets":[{"definition":{"type":"slo_list","requests":[{"query":{"query_string":"env:prod + AND service:my-app","limit":75},"request_type":"slo_list"}],"title_align":"left","title_size":"16"},"layout":{"y":0,"width":60,"x":0,"height":21},"id":434825034616209}],"layout_type":"free"} + + ' + code: 200 + duration: '' + headers: + Content-Type: + - application/json + status: 200 OK +- request: + body: '' + form: {} + headers: + Accept: + - application/json + method: DELETE + url: https://api.datadoghq.com/api/v1/dashboard/xf3-y64-ib5 + response: + body: '{"deleted_dashboard_id":"xf3-y64-ib5"} + + ' + code: 200 + duration: '' + headers: + Content-Type: + - application/json + status: 200 OK +- request: + body: '' + form: {} + headers: + Accept: + - application/json + method: DELETE + url: https://api.datadoghq.com/api/v1/slo/7f88381afe5f5c1e987664e7057253fd + response: + body: '{"data":["7f88381afe5f5c1e987664e7057253fd"],"error":null} + + ' + code: 200 + duration: '' + headers: + Content-Type: + - application/json + status: 200 OK +version: 1 diff --git a/tests/scenarios/features/v1/dashboards.feature b/tests/scenarios/features/v1/dashboards.feature index cdb446a2b9c..f26ae03b86c 100644 --- a/tests/scenarios/features/v1/dashboards.feature +++ b/tests/scenarios/features/v1/dashboards.feature @@ -390,6 +390,17 @@ Feature: Dashboards And the response "widgets[0].definition.type" is equal to "servicemap" And the response "widgets[0].definition.filters" is equal to ["env:none","environment:*"] + @team:DataDog/dashboards + Scenario: Create a new dashboard with slo list widget + Given there is a valid "slo" in the system + And new "CreateDashboard" request + And body from file "dashboards_json_payload/slo_list_widget.json" + When the request is sent + Then the response status is 200 OK + And the response "widgets[0].definition.type" is equal to "slo_list" + And the response "widgets[0].definition.requests[0].query.query_string" is equal to "env:prod AND service:my-app" + And the response "widgets[0].definition.requests[0].query.limit" is equal to 75 + @team:DataDog/dashboards Scenario: Create a new dashboard with slo widget Given there is a valid "slo" in the system diff --git a/tests/scenarios/features/v1/dashboards_json_payload/slo_list_widget.json b/tests/scenarios/features/v1/dashboards_json_payload/slo_list_widget.json new file mode 100644 index 00000000000..74b5916587f --- /dev/null +++ b/tests/scenarios/features/v1/dashboards_json_payload/slo_list_widget.json @@ -0,0 +1,32 @@ +{ + "title": "{{ unique }}", + "description": "", + "widgets": [ + { + "layout": { + "x": 0, + "y": 0, + "width": 60, + "height": 21 + }, + "definition": { + "title_size": "16", + "title_align": "left", + "type": "slo_list", + "requests": [ + { + "query": { + "query_string": "env:prod AND service:my-app", + "limit": 75 + }, + "request_type": "slo_list" + } + ] + } + } + ], + "template_variables": [], + "layout_type": "free", + "is_read_only": false, + "notify_list": [] +}