diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index e922a2a26ab..a6d35cbd212 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -1443,6 +1443,8 @@ components: format: date-time readOnly: true type: string + default_timeframe: + $ref: "#/components/schemas/DashboardDefaultTimeframeSetting" description: description: Description of the dashboard. nullable: true @@ -1557,6 +1559,18 @@ components: required: - data type: object + DashboardDefaultTimeframeSetting: + description: The default timeframe applied when opening the dashboard. Set to `null` to clear the dashboard's default timeframe. + discriminator: + mapping: + fixed: "#/components/schemas/DashboardFixedTimeframe" + live: "#/components/schemas/DashboardLiveTimeframe" + propertyName: type + nullable: true + oneOf: + - $ref: "#/components/schemas/DashboardLiveTimeframe" + - $ref: "#/components/schemas/DashboardFixedTimeframe" + type: object DashboardDeleteResponse: description: Response from the delete dashboard call. properties: @@ -1564,6 +1578,36 @@ components: description: ID of the deleted dashboard. type: string type: object + DashboardFixedTimeframe: + description: A fixed dashboard timeframe. + properties: + from: + description: Start time in milliseconds since epoch. + example: 1712080128000 + format: int64 + minimum: 0 + type: integer + to: + description: End time in milliseconds since epoch. + example: 1712083128000 + format: int64 + minimum: 0 + type: integer + type: + $ref: "#/components/schemas/DashboardFixedTimeframeType" + required: + - type + - from + - to + type: object + DashboardFixedTimeframeType: + description: Type of fixed timeframe. + enum: + - fixed + example: fixed + type: string + x-enum-varnames: + - FIXED DashboardGlobalTime: description: Object containing the live span selection for the dashboard. properties: @@ -1672,6 +1716,32 @@ components: $ref: "#/components/schemas/DashboardList" type: array type: object + DashboardLiveTimeframe: + description: A live dashboard timeframe. + properties: + type: + $ref: "#/components/schemas/DashboardLiveTimeframeType" + unit: + $ref: "#/components/schemas/WidgetLiveSpanUnit" + value: + description: Value of the live timeframe span. + example: 4 + format: int64 + minimum: 1 + type: integer + required: + - type + - value + - unit + type: object + DashboardLiveTimeframeType: + description: Type of live timeframe. + enum: + - live + example: live + type: string + x-enum-varnames: + - LIVE DashboardReflowType: description: |- Reflow type for a **new dashboard layout** dashboard. Set this only when layout type is 'ordered'. diff --git a/api/datadogV1/model_dashboard.go b/api/datadogV1/model_dashboard.go index aa98b9e5fd2..36c95dc83d4 100644 --- a/api/datadogV1/model_dashboard.go +++ b/api/datadogV1/model_dashboard.go @@ -20,6 +20,8 @@ type Dashboard struct { AuthorName datadog.NullableString `json:"author_name,omitempty"` // Creation date of the dashboard. CreatedAt *time.Time `json:"created_at,omitempty"` + // The default timeframe applied when opening the dashboard. Set to `null` to clear the dashboard's default timeframe. + DefaultTimeframe NullableDashboardDefaultTimeframeSetting `json:"default_timeframe,omitempty"` // Description of the dashboard. Description datadog.NullableString `json:"description,omitempty"` // ID of the dashboard. @@ -175,6 +177,45 @@ func (o *Dashboard) SetCreatedAt(v time.Time) { o.CreatedAt = &v } +// GetDefaultTimeframe returns the DefaultTimeframe field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *Dashboard) GetDefaultTimeframe() DashboardDefaultTimeframeSetting { + if o == nil || o.DefaultTimeframe.Get() == nil { + var ret DashboardDefaultTimeframeSetting + return ret + } + return *o.DefaultTimeframe.Get() +} + +// GetDefaultTimeframeOk returns a tuple with the DefaultTimeframe field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned. +func (o *Dashboard) GetDefaultTimeframeOk() (*DashboardDefaultTimeframeSetting, bool) { + if o == nil { + return nil, false + } + return o.DefaultTimeframe.Get(), o.DefaultTimeframe.IsSet() +} + +// HasDefaultTimeframe returns a boolean if a field has been set. +func (o *Dashboard) HasDefaultTimeframe() bool { + return o != nil && o.DefaultTimeframe.IsSet() +} + +// SetDefaultTimeframe gets a reference to the given NullableDashboardDefaultTimeframeSetting and assigns it to the DefaultTimeframe field. +func (o *Dashboard) SetDefaultTimeframe(v DashboardDefaultTimeframeSetting) { + o.DefaultTimeframe.Set(&v) +} + +// SetDefaultTimeframeNil sets the value for DefaultTimeframe to be an explicit nil. +func (o *Dashboard) SetDefaultTimeframeNil() { + o.DefaultTimeframe.Set(nil) +} + +// UnsetDefaultTimeframe ensures that no value is present for DefaultTimeframe, not even an explicit nil. +func (o *Dashboard) UnsetDefaultTimeframe() { + o.DefaultTimeframe.Unset() +} + // GetDescription returns the Description field value if set, zero value otherwise (both if not set or set to explicit null). func (o *Dashboard) GetDescription() string { if o == nil || o.Description.Get() == nil { @@ -638,6 +679,9 @@ func (o Dashboard) MarshalJSON() ([]byte, error) { toSerialize["created_at"] = o.CreatedAt.Format("2006-01-02T15:04:05.000Z07:00") } } + if o.DefaultTimeframe.IsSet() { + toSerialize["default_timeframe"] = o.DefaultTimeframe.Get() + } if o.Description.IsSet() { toSerialize["description"] = o.Description.Get() } @@ -691,24 +735,25 @@ func (o Dashboard) MarshalJSON() ([]byte, error) { // UnmarshalJSON deserializes the given payload. func (o *Dashboard) UnmarshalJSON(bytes []byte) (err error) { all := struct { - AuthorHandle *string `json:"author_handle,omitempty"` - AuthorName datadog.NullableString `json:"author_name,omitempty"` - CreatedAt *time.Time `json:"created_at,omitempty"` - Description datadog.NullableString `json:"description,omitempty"` - Id *string `json:"id,omitempty"` - IsReadOnly *bool `json:"is_read_only,omitempty"` - LayoutType *DashboardLayoutType `json:"layout_type"` - ModifiedAt *time.Time `json:"modified_at,omitempty"` - NotifyList datadog.NullableList[string] `json:"notify_list,omitempty"` - ReflowType *DashboardReflowType `json:"reflow_type,omitempty"` - RestrictedRoles []string `json:"restricted_roles,omitempty"` - Tabs []DashboardTab `json:"tabs,omitempty"` - Tags datadog.NullableList[string] `json:"tags,omitempty"` - TemplateVariablePresets []DashboardTemplateVariablePreset `json:"template_variable_presets,omitempty"` - TemplateVariables []DashboardTemplateVariable `json:"template_variables,omitempty"` - Title *string `json:"title"` - Url *string `json:"url,omitempty"` - Widgets *[]Widget `json:"widgets"` + AuthorHandle *string `json:"author_handle,omitempty"` + AuthorName datadog.NullableString `json:"author_name,omitempty"` + CreatedAt *time.Time `json:"created_at,omitempty"` + DefaultTimeframe NullableDashboardDefaultTimeframeSetting `json:"default_timeframe,omitempty"` + Description datadog.NullableString `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + IsReadOnly *bool `json:"is_read_only,omitempty"` + LayoutType *DashboardLayoutType `json:"layout_type"` + ModifiedAt *time.Time `json:"modified_at,omitempty"` + NotifyList datadog.NullableList[string] `json:"notify_list,omitempty"` + ReflowType *DashboardReflowType `json:"reflow_type,omitempty"` + RestrictedRoles []string `json:"restricted_roles,omitempty"` + Tabs []DashboardTab `json:"tabs,omitempty"` + Tags datadog.NullableList[string] `json:"tags,omitempty"` + TemplateVariablePresets []DashboardTemplateVariablePreset `json:"template_variable_presets,omitempty"` + TemplateVariables []DashboardTemplateVariable `json:"template_variables,omitempty"` + Title *string `json:"title"` + Url *string `json:"url,omitempty"` + Widgets *[]Widget `json:"widgets"` }{} if err = datadog.Unmarshal(bytes, &all); err != nil { return datadog.Unmarshal(bytes, &o.UnparsedObject) @@ -724,7 +769,7 @@ func (o *Dashboard) UnmarshalJSON(bytes []byte) (err error) { } additionalProperties := make(map[string]interface{}) if err = datadog.UnmarshalUseNumber(bytes, &additionalProperties); err == nil { - datadog.DeleteKeys(additionalProperties, &[]string{"author_handle", "author_name", "created_at", "description", "id", "is_read_only", "layout_type", "modified_at", "notify_list", "reflow_type", "restricted_roles", "tabs", "tags", "template_variable_presets", "template_variables", "title", "url", "widgets"}) + datadog.DeleteKeys(additionalProperties, &[]string{"author_handle", "author_name", "created_at", "default_timeframe", "description", "id", "is_read_only", "layout_type", "modified_at", "notify_list", "reflow_type", "restricted_roles", "tabs", "tags", "template_variable_presets", "template_variables", "title", "url", "widgets"}) } else { return err } @@ -733,6 +778,7 @@ func (o *Dashboard) UnmarshalJSON(bytes []byte) (err error) { o.AuthorHandle = all.AuthorHandle o.AuthorName = all.AuthorName o.CreatedAt = all.CreatedAt + o.DefaultTimeframe = all.DefaultTimeframe o.Description = all.Description o.Id = all.Id o.IsReadOnly = all.IsReadOnly diff --git a/api/datadogV1/model_dashboard_default_timeframe_setting.go b/api/datadogV1/model_dashboard_default_timeframe_setting.go new file mode 100644 index 00000000000..a5776f6edfe --- /dev/null +++ b/api/datadogV1/model_dashboard_default_timeframe_setting.go @@ -0,0 +1,113 @@ +// 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" +) + +// DashboardDefaultTimeframeSetting - The default timeframe applied when opening the dashboard. Set to `null` to clear the dashboard's default timeframe. +type DashboardDefaultTimeframeSetting struct { + DashboardLiveTimeframe *DashboardLiveTimeframe + DashboardFixedTimeframe *DashboardFixedTimeframe + + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject interface{} +} + +// DashboardLiveTimeframeAsDashboardDefaultTimeframeSetting is a convenience function that returns DashboardLiveTimeframe wrapped in DashboardDefaultTimeframeSetting. +func DashboardLiveTimeframeAsDashboardDefaultTimeframeSetting(v *DashboardLiveTimeframe) DashboardDefaultTimeframeSetting { + return DashboardDefaultTimeframeSetting{DashboardLiveTimeframe: v} +} + +// DashboardFixedTimeframeAsDashboardDefaultTimeframeSetting is a convenience function that returns DashboardFixedTimeframe wrapped in DashboardDefaultTimeframeSetting. +func DashboardFixedTimeframeAsDashboardDefaultTimeframeSetting(v *DashboardFixedTimeframe) DashboardDefaultTimeframeSetting { + return DashboardDefaultTimeframeSetting{DashboardFixedTimeframe: v} +} + +// UnmarshalJSON turns data into one of the pointers in the struct. +func (obj *DashboardDefaultTimeframeSetting) UnmarshalJSON(data []byte) error { + var err error +} + +// MarshalJSON turns data from the first non-nil pointers in the struct to JSON. +func (obj DashboardDefaultTimeframeSetting) MarshalJSON() ([]byte, error) { + if obj.DashboardLiveTimeframe != nil { + return datadog.Marshal(&obj.DashboardLiveTimeframe) + } + + if obj.DashboardFixedTimeframe != nil { + return datadog.Marshal(&obj.DashboardFixedTimeframe) + } + + if obj.UnparsedObject != nil { + return datadog.Marshal(obj.UnparsedObject) + } + return nil, nil // no data in oneOf schemas +} + +// GetActualInstance returns the actual instance. +func (obj *DashboardDefaultTimeframeSetting) GetActualInstance() interface{} { + if obj.DashboardLiveTimeframe != nil { + return obj.DashboardLiveTimeframe + } + + if obj.DashboardFixedTimeframe != nil { + return obj.DashboardFixedTimeframe + } + + // all schemas are nil + return nil +} + +// NullableDashboardDefaultTimeframeSetting handles when a null is used for DashboardDefaultTimeframeSetting. +type NullableDashboardDefaultTimeframeSetting struct { + value *DashboardDefaultTimeframeSetting + isSet bool +} + +// Get returns the associated value. +func (v NullableDashboardDefaultTimeframeSetting) Get() *DashboardDefaultTimeframeSetting { + return v.value +} + +// Set changes the value and indicates it's been called. +func (v *NullableDashboardDefaultTimeframeSetting) Set(val *DashboardDefaultTimeframeSetting) { + v.value = val + v.isSet = true +} + +// IsSet returns whether Set has been called. +func (v NullableDashboardDefaultTimeframeSetting) IsSet() bool { + return v.isSet +} + +// Unset sets the value to nil and resets the set flag/ +func (v *NullableDashboardDefaultTimeframeSetting) Unset() { + v.value = nil + v.isSet = false +} + +// NewNullableDashboardDefaultTimeframeSetting initializes the struct as if Set has been called. +func NewNullableDashboardDefaultTimeframeSetting(val *DashboardDefaultTimeframeSetting) *NullableDashboardDefaultTimeframeSetting { + return &NullableDashboardDefaultTimeframeSetting{value: val, isSet: true} +} + +// MarshalJSON serializes the associated value. +func (v NullableDashboardDefaultTimeframeSetting) MarshalJSON() ([]byte, error) { + return datadog.Marshal(v.value) +} + +// UnmarshalJSON deserializes the payload and sets the flag as if Set has been called. +func (v *NullableDashboardDefaultTimeframeSetting) UnmarshalJSON(src []byte) error { + v.isSet = true + + // this object is nullable so check if the payload is null or empty string + if string(src) == "" || string(src) == "{}" { + return nil + } + + return datadog.Unmarshal(src, &v.value) +} diff --git a/api/datadogV1/model_dashboard_fixed_timeframe.go b/api/datadogV1/model_dashboard_fixed_timeframe.go new file mode 100644 index 00000000000..c9ddefd304f --- /dev/null +++ b/api/datadogV1/model_dashboard_fixed_timeframe.go @@ -0,0 +1,175 @@ +// 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 ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// DashboardFixedTimeframe A fixed dashboard timeframe. +type DashboardFixedTimeframe struct { + // Start time in milliseconds since epoch. + From int64 `json:"from"` + // End time in milliseconds since epoch. + To int64 `json:"to"` + // Type of fixed timeframe. + Type DashboardFixedTimeframeType `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{} `json:"-"` +} + +// NewDashboardFixedTimeframe instantiates a new DashboardFixedTimeframe 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 NewDashboardFixedTimeframe(from int64, to int64, typeVar DashboardFixedTimeframeType) *DashboardFixedTimeframe { + this := DashboardFixedTimeframe{} + this.From = from + this.To = to + this.Type = typeVar + return &this +} + +// NewDashboardFixedTimeframeWithDefaults instantiates a new DashboardFixedTimeframe 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 NewDashboardFixedTimeframeWithDefaults() *DashboardFixedTimeframe { + this := DashboardFixedTimeframe{} + return &this +} + +// GetFrom returns the From field value. +func (o *DashboardFixedTimeframe) GetFrom() int64 { + if o == nil { + var ret int64 + return ret + } + return o.From +} + +// GetFromOk returns a tuple with the From field value +// and a boolean to check if the value has been set. +func (o *DashboardFixedTimeframe) GetFromOk() (*int64, bool) { + if o == nil { + return nil, false + } + return &o.From, true +} + +// SetFrom sets field value. +func (o *DashboardFixedTimeframe) SetFrom(v int64) { + o.From = v +} + +// GetTo returns the To field value. +func (o *DashboardFixedTimeframe) GetTo() int64 { + if o == nil { + var ret int64 + return ret + } + return o.To +} + +// GetToOk returns a tuple with the To field value +// and a boolean to check if the value has been set. +func (o *DashboardFixedTimeframe) GetToOk() (*int64, bool) { + if o == nil { + return nil, false + } + return &o.To, true +} + +// SetTo sets field value. +func (o *DashboardFixedTimeframe) SetTo(v int64) { + o.To = v +} + +// GetType returns the Type field value. +func (o *DashboardFixedTimeframe) GetType() DashboardFixedTimeframeType { + if o == nil { + var ret DashboardFixedTimeframeType + 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 *DashboardFixedTimeframe) GetTypeOk() (*DashboardFixedTimeframeType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value. +func (o *DashboardFixedTimeframe) SetType(v DashboardFixedTimeframeType) { + o.Type = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o DashboardFixedTimeframe) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["from"] = o.From + toSerialize["to"] = o.To + toSerialize["type"] = o.Type + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *DashboardFixedTimeframe) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + From *int64 `json:"from"` + To *int64 `json:"to"` + Type *DashboardFixedTimeframeType `json:"type"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.From == nil { + return fmt.Errorf("required field from missing") + } + if all.To == nil { + return fmt.Errorf("required field to missing") + } + if all.Type == nil { + return fmt.Errorf("required field type missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.UnmarshalUseNumber(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"from", "to", "type"}) + } else { + return err + } + + hasInvalidField := false + o.From = *all.From + o.To = *all.To + if !all.Type.IsValid() { + hasInvalidField = true + } else { + o.Type = *all.Type + } + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV1/model_dashboard_fixed_timeframe_type.go b/api/datadogV1/model_dashboard_fixed_timeframe_type.go new file mode 100644 index 00000000000..2a3e3286370 --- /dev/null +++ b/api/datadogV1/model_dashboard_fixed_timeframe_type.go @@ -0,0 +1,64 @@ +// 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 ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// DashboardFixedTimeframeType Type of fixed timeframe. +type DashboardFixedTimeframeType string + +// List of DashboardFixedTimeframeType. +const ( + DASHBOARDFIXEDTIMEFRAMETYPE_FIXED DashboardFixedTimeframeType = "fixed" +) + +var allowedDashboardFixedTimeframeTypeEnumValues = []DashboardFixedTimeframeType{ + DASHBOARDFIXEDTIMEFRAMETYPE_FIXED, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *DashboardFixedTimeframeType) GetAllowedValues() []DashboardFixedTimeframeType { + return allowedDashboardFixedTimeframeTypeEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *DashboardFixedTimeframeType) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = DashboardFixedTimeframeType(value) + return nil +} + +// NewDashboardFixedTimeframeTypeFromValue returns a pointer to a valid DashboardFixedTimeframeType +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewDashboardFixedTimeframeTypeFromValue(v string) (*DashboardFixedTimeframeType, error) { + ev := DashboardFixedTimeframeType(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for DashboardFixedTimeframeType: valid values are %v", v, allowedDashboardFixedTimeframeTypeEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v DashboardFixedTimeframeType) IsValid() bool { + for _, existing := range allowedDashboardFixedTimeframeTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to DashboardFixedTimeframeType value. +func (v DashboardFixedTimeframeType) Ptr() *DashboardFixedTimeframeType { + return &v +} diff --git a/api/datadogV1/model_dashboard_live_timeframe.go b/api/datadogV1/model_dashboard_live_timeframe.go new file mode 100644 index 00000000000..9a5dffcc12a --- /dev/null +++ b/api/datadogV1/model_dashboard_live_timeframe.go @@ -0,0 +1,179 @@ +// 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 ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// DashboardLiveTimeframe A live dashboard timeframe. +type DashboardLiveTimeframe struct { + // Type of live timeframe. + Type DashboardLiveTimeframeType `json:"type"` + // Unit of the time span. + Unit WidgetLiveSpanUnit `json:"unit"` + // Value of the live timeframe span. + Value int64 `json:"value"` + // 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{} `json:"-"` +} + +// NewDashboardLiveTimeframe instantiates a new DashboardLiveTimeframe 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 NewDashboardLiveTimeframe(typeVar DashboardLiveTimeframeType, unit WidgetLiveSpanUnit, value int64) *DashboardLiveTimeframe { + this := DashboardLiveTimeframe{} + this.Type = typeVar + this.Unit = unit + this.Value = value + return &this +} + +// NewDashboardLiveTimeframeWithDefaults instantiates a new DashboardLiveTimeframe 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 NewDashboardLiveTimeframeWithDefaults() *DashboardLiveTimeframe { + this := DashboardLiveTimeframe{} + return &this +} + +// GetType returns the Type field value. +func (o *DashboardLiveTimeframe) GetType() DashboardLiveTimeframeType { + if o == nil { + var ret DashboardLiveTimeframeType + 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 *DashboardLiveTimeframe) GetTypeOk() (*DashboardLiveTimeframeType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value. +func (o *DashboardLiveTimeframe) SetType(v DashboardLiveTimeframeType) { + o.Type = v +} + +// GetUnit returns the Unit field value. +func (o *DashboardLiveTimeframe) GetUnit() WidgetLiveSpanUnit { + if o == nil { + var ret WidgetLiveSpanUnit + return ret + } + return o.Unit +} + +// GetUnitOk returns a tuple with the Unit field value +// and a boolean to check if the value has been set. +func (o *DashboardLiveTimeframe) GetUnitOk() (*WidgetLiveSpanUnit, bool) { + if o == nil { + return nil, false + } + return &o.Unit, true +} + +// SetUnit sets field value. +func (o *DashboardLiveTimeframe) SetUnit(v WidgetLiveSpanUnit) { + o.Unit = v +} + +// GetValue returns the Value field value. +func (o *DashboardLiveTimeframe) GetValue() int64 { + if o == nil { + var ret int64 + return ret + } + return o.Value +} + +// GetValueOk returns a tuple with the Value field value +// and a boolean to check if the value has been set. +func (o *DashboardLiveTimeframe) GetValueOk() (*int64, bool) { + if o == nil { + return nil, false + } + return &o.Value, true +} + +// SetValue sets field value. +func (o *DashboardLiveTimeframe) SetValue(v int64) { + o.Value = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o DashboardLiveTimeframe) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["type"] = o.Type + toSerialize["unit"] = o.Unit + toSerialize["value"] = o.Value + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *DashboardLiveTimeframe) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Type *DashboardLiveTimeframeType `json:"type"` + Unit *WidgetLiveSpanUnit `json:"unit"` + Value *int64 `json:"value"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Type == nil { + return fmt.Errorf("required field type missing") + } + if all.Unit == nil { + return fmt.Errorf("required field unit missing") + } + if all.Value == nil { + return fmt.Errorf("required field value missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.UnmarshalUseNumber(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"type", "unit", "value"}) + } else { + return err + } + + hasInvalidField := false + if !all.Type.IsValid() { + hasInvalidField = true + } else { + o.Type = *all.Type + } + if !all.Unit.IsValid() { + hasInvalidField = true + } else { + o.Unit = *all.Unit + } + o.Value = *all.Value + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV1/model_dashboard_live_timeframe_type.go b/api/datadogV1/model_dashboard_live_timeframe_type.go new file mode 100644 index 00000000000..14676b86cbb --- /dev/null +++ b/api/datadogV1/model_dashboard_live_timeframe_type.go @@ -0,0 +1,64 @@ +// 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 ( + "fmt" + + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" +) + +// DashboardLiveTimeframeType Type of live timeframe. +type DashboardLiveTimeframeType string + +// List of DashboardLiveTimeframeType. +const ( + DASHBOARDLIVETIMEFRAMETYPE_LIVE DashboardLiveTimeframeType = "live" +) + +var allowedDashboardLiveTimeframeTypeEnumValues = []DashboardLiveTimeframeType{ + DASHBOARDLIVETIMEFRAMETYPE_LIVE, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *DashboardLiveTimeframeType) GetAllowedValues() []DashboardLiveTimeframeType { + return allowedDashboardLiveTimeframeTypeEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *DashboardLiveTimeframeType) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = DashboardLiveTimeframeType(value) + return nil +} + +// NewDashboardLiveTimeframeTypeFromValue returns a pointer to a valid DashboardLiveTimeframeType +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewDashboardLiveTimeframeTypeFromValue(v string) (*DashboardLiveTimeframeType, error) { + ev := DashboardLiveTimeframeType(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for DashboardLiveTimeframeType: valid values are %v", v, allowedDashboardLiveTimeframeTypeEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v DashboardLiveTimeframeType) IsValid() bool { + for _, existing := range allowedDashboardLiveTimeframeTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to DashboardLiveTimeframeType value. +func (v DashboardLiveTimeframeType) Ptr() *DashboardLiveTimeframeType { + return &v +} diff --git a/tests/scenarios/features/v1/dashboards.feature b/tests/scenarios/features/v1/dashboards.feature index 932dc22b0b3..2fb06cd716e 100644 --- a/tests/scenarios/features/v1/dashboards.feature +++ b/tests/scenarios/features/v1/dashboards.feature @@ -90,7 +90,7 @@ Feature: Dashboards @generated @skip @team:DataDog/dashboards-backend Scenario: Create a new dashboard returns "Bad Request" response Given new "CreateDashboard" request - And body with value {"description": null, "is_read_only": false, "layout_type": "ordered", "notify_list": [], "reflow_type": "auto", "restricted_roles": [], "tabs": [{"id": "", "name": "L", "widget_ids": [0]}], "tags": [], "template_variable_presets": [{"template_variables": [{"values": []}]}], "template_variables": [{"available_values": ["my-host", "host1", "host2"], "default": "my-host", "defaults": ["my-host-1", "my-host-2"], "name": "host1", "prefix": "host", "type": "group"}], "title": "", "widgets": [{"definition": {"requests": {"fill": {"q": "avg:system.cpu.user{*}"}}, "type": "hostmap"}}]} + And body with value {"default_timeframe": {"type": "live", "unit": "minute", "value": 4}, "description": null, "is_read_only": false, "layout_type": "ordered", "notify_list": [], "reflow_type": "auto", "restricted_roles": [], "tabs": [{"id": "", "name": "L", "widget_ids": [0]}], "tags": [], "template_variable_presets": [{"template_variables": [{"values": []}]}], "template_variables": [{"available_values": ["my-host", "host1", "host2"], "default": "my-host", "defaults": ["my-host-1", "my-host-2"], "name": "host1", "prefix": "host", "type": "group"}], "title": "", "widgets": [{"definition": {"requests": {"fill": {"q": "avg:system.cpu.user{*}"}}, "type": "hostmap"}}]} When the request is sent Then the response status is 400 Bad Request @@ -1463,7 +1463,7 @@ Feature: Dashboards Scenario: Update a dashboard returns "Bad Request" response Given new "UpdateDashboard" request And request contains "dashboard_id" parameter from "REPLACE.ME" - And body with value {"description": null, "is_read_only": false, "layout_type": "ordered", "notify_list": [], "reflow_type": "auto", "restricted_roles": [], "tabs": [{"id": "", "name": "L", "widget_ids": [0]}], "tags": [], "template_variable_presets": [{"template_variables": [{"values": []}]}], "template_variables": [{"available_values": ["my-host", "host1", "host2"], "default": "my-host", "defaults": ["my-host-1", "my-host-2"], "name": "host1", "prefix": "host", "type": "group"}], "title": "", "widgets": [{"definition": {"requests": {"fill": {"q": "avg:system.cpu.user{*}"}}, "type": "hostmap"}}]} + And body with value {"default_timeframe": {"type": "live", "unit": "minute", "value": 4}, "description": null, "is_read_only": false, "layout_type": "ordered", "notify_list": [], "reflow_type": "auto", "restricted_roles": [], "tabs": [{"id": "", "name": "L", "widget_ids": [0]}], "tags": [], "template_variable_presets": [{"template_variables": [{"values": []}]}], "template_variables": [{"available_values": ["my-host", "host1", "host2"], "default": "my-host", "defaults": ["my-host-1", "my-host-2"], "name": "host1", "prefix": "host", "type": "group"}], "title": "", "widgets": [{"definition": {"requests": {"fill": {"q": "avg:system.cpu.user{*}"}}, "type": "hostmap"}}]} When the request is sent Then the response status is 400 Bad Request @@ -1471,7 +1471,7 @@ Feature: Dashboards Scenario: Update a dashboard returns "Item Not Found" response Given new "UpdateDashboard" request And request contains "dashboard_id" parameter from "REPLACE.ME" - And body with value {"description": null, "is_read_only": false, "layout_type": "ordered", "notify_list": [], "reflow_type": "auto", "restricted_roles": [], "tabs": [{"id": "", "name": "L", "widget_ids": [0]}], "tags": [], "template_variable_presets": [{"template_variables": [{"values": []}]}], "template_variables": [{"available_values": ["my-host", "host1", "host2"], "default": "my-host", "defaults": ["my-host-1", "my-host-2"], "name": "host1", "prefix": "host", "type": "group"}], "title": "", "widgets": [{"definition": {"requests": {"fill": {"q": "avg:system.cpu.user{*}"}}, "type": "hostmap"}}]} + And body with value {"default_timeframe": {"type": "live", "unit": "minute", "value": 4}, "description": null, "is_read_only": false, "layout_type": "ordered", "notify_list": [], "reflow_type": "auto", "restricted_roles": [], "tabs": [{"id": "", "name": "L", "widget_ids": [0]}], "tags": [], "template_variable_presets": [{"template_variables": [{"values": []}]}], "template_variables": [{"available_values": ["my-host", "host1", "host2"], "default": "my-host", "defaults": ["my-host-1", "my-host-2"], "name": "host1", "prefix": "host", "type": "group"}], "title": "", "widgets": [{"definition": {"requests": {"fill": {"q": "avg:system.cpu.user{*}"}}, "type": "hostmap"}}]} When the request is sent Then the response status is 404 Item Not Found