diff --git a/.apigentools-info b/.apigentools-info index 7e8040cecd2..719a8310c4c 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.6", - "regenerated": "2024-09-06 21:00:03.088699", - "spec_repo_commit": "3dff532a" + "regenerated": "2024-09-09 16:24:01.726594", + "spec_repo_commit": "82038586" }, "v2": { "apigentools_version": "1.6.6", - "regenerated": "2024-09-06 21:00:03.109592", - "spec_repo_commit": "3dff532a" + "regenerated": "2024-09-09 16:24:01.746218", + "spec_repo_commit": "82038586" } } } \ No newline at end of file diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index 7e7134461fa..07ab96c114c 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -16740,6 +16740,212 @@ components: $ref: '#/components/schemas/LogQueryDefinition' sort: $ref: '#/components/schemas/WidgetSortBy' + text_formats: + description: List of text formats for columns produced by tags. + items: + $ref: '#/components/schemas/TableWidgetTextFormat' + type: array + type: object + TableWidgetTextFormat: + description: Text format rules for a tag-based column within a table widget. + example: + - match: + type: is + value: fruit + replace: + type: all + with: vegetable + - match: + type: is + value: cake + palette: white_on_green + items: + $ref: '#/components/schemas/TableWidgetTextFormatRule' + minItems: 1 + type: array + TableWidgetTextFormatCustomPaletteType: + description: Custom color-on-color palette. + enum: + - custom_bg + example: custom_bg + type: string + x-enum-varnames: + - CUSTOM_BG + TableWidgetTextFormatMatch: + description: Match rule for the table widget text format. + example: + type: is + value: fruit + properties: + type: + $ref: '#/components/schemas/TableWidgetTextFormatMatchType' + value: + description: Table Widget Match String. + example: Match Value + type: string + required: + - type + - value + type: object + TableWidgetTextFormatMatchType: + description: Match or compare option. + enum: + - is + - is_not + - contains + - does_not_contain + - starts_with + - ends_with + example: is + type: string + x-enum-varnames: + - IS + - IS_NOT + - CONTAINS + - DOES_NOT_CONTAIN + - STARTS_WITH + - ENDS_WITH + TableWidgetTextFormatPalette: + default: white_on_green + description: Color-on-color palette to highlight replaced text. + enum: + - white_on_red + - white_on_yellow + - white_on_green + - black_on_light_red + - black_on_light_yellow + - black_on_light_green + - red_on_white + - yellow_on_white + type: string + x-enum-varnames: + - WHITE_ON_RED + - WHITE_ON_YELLOW + - WHITE_ON_GREEN + - BLACK_ON_LIGHT_RED + - BLACK_ON_LIGHT_YELLOW + - BLACK_ON_LIGHT_GREEN + - RED_ON_WHITE + - YELLOW_ON_WHITE + TableWidgetTextFormatReplace: + description: Replace rule for the table widget text format. + example: + type: all + with: vegetable + oneOf: + - $ref: '#/components/schemas/TableWidgetTextFormatReplaceAll' + - $ref: '#/components/schemas/TableWidgetTextFormatReplaceSubstring' + TableWidgetTextFormatReplaceAll: + description: Match All definition. + example: + type: all + with: vegetable + properties: + type: + $ref: '#/components/schemas/TableWidgetTextFormatReplaceAllType' + with: + description: Replace All type. + example: all + type: string + required: + - type + - with + type: object + TableWidgetTextFormatReplaceAllType: + description: Table widget text format replace all type. + enum: + - all + example: all + type: string + x-enum-varnames: + - ALL + TableWidgetTextFormatReplaceSubstring: + description: Match Sub-string definition. + example: + substring: fruit + type: substring + with: vegetable + properties: + substring: + description: Text that will be replaced. + example: string to replace + type: string + type: + $ref: '#/components/schemas/TableWidgetTextFormatReplaceSubstringType' + with: + description: Text that will replace original sub-string. + example: replacement + type: string + required: + - type + - with + - substring + type: object + TableWidgetTextFormatReplaceSubstringType: + description: Table widget text format replace sub-string type. + enum: + - substring + example: substring + type: string + x-enum-varnames: + - SUBSTRING + TableWidgetTextFormatRule: + description: Text format rule. + example: + match: + type: is + value: apple + replace: + type: all + with: vegetable + oneOf: + - $ref: '#/components/schemas/TableWidgetTextFormatRuleMain' + - $ref: '#/components/schemas/TableWidgetTextFormatRuleCustomPalette' + TableWidgetTextFormatRuleCustomPalette: + description: Text format rule with custom palette. + example: + custom_bg_color: '#111111' + match: + type: is + value: fruit + palette: custom_bg + replace: + type: all + with: vegetable + properties: + custom_bg_color: + description: Hex representation of the custom background color. + example: '#111111' + type: string + match: + $ref: '#/components/schemas/TableWidgetTextFormatMatch' + palette: + $ref: '#/components/schemas/TableWidgetTextFormatCustomPaletteType' + replace: + $ref: '#/components/schemas/TableWidgetTextFormatReplace' + required: + - match + - palette + - custom_bg_color + type: object + TableWidgetTextFormatRuleMain: + description: Text format rule with preset palettes. + example: + match: + type: is + value: apple + replace: + type: all + with: vegetable + properties: + match: + $ref: '#/components/schemas/TableWidgetTextFormatMatch' + palette: + $ref: '#/components/schemas/TableWidgetTextFormatPalette' + replace: + $ref: '#/components/schemas/TableWidgetTextFormatReplace' + required: + - match type: object TagToHosts: description: In this object, the key is the tag, the value is a list of host diff --git a/api/datadogV1/model_table_widget_request.go b/api/datadogV1/model_table_widget_request.go index 9bf29315748..85d5e77869c 100644 --- a/api/datadogV1/model_table_widget_request.go +++ b/api/datadogV1/model_table_widget_request.go @@ -50,6 +50,8 @@ type TableWidgetRequest struct { SecurityQuery *LogQueryDefinition `json:"security_query,omitempty"` // The controls for sorting the widget. Sort *WidgetSortBy `json:"sort,omitempty"` + // List of text formats for columns produced by tags. + TextFormats [][]TableWidgetTextFormatRule `json:"text_formats,omitempty"` // 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:"-"` @@ -632,6 +634,34 @@ func (o *TableWidgetRequest) SetSort(v WidgetSortBy) { o.Sort = &v } +// GetTextFormats returns the TextFormats field value if set, zero value otherwise. +func (o *TableWidgetRequest) GetTextFormats() [][]TableWidgetTextFormatRule { + if o == nil || o.TextFormats == nil { + var ret [][]TableWidgetTextFormatRule + return ret + } + return o.TextFormats +} + +// GetTextFormatsOk returns a tuple with the TextFormats field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *TableWidgetRequest) GetTextFormatsOk() (*[][]TableWidgetTextFormatRule, bool) { + if o == nil || o.TextFormats == nil { + return nil, false + } + return &o.TextFormats, true +} + +// HasTextFormats returns a boolean if a field has been set. +func (o *TableWidgetRequest) HasTextFormats() bool { + return o != nil && o.TextFormats != nil +} + +// SetTextFormats gets a reference to the given [][]TableWidgetTextFormatRule and assigns it to the TextFormats field. +func (o *TableWidgetRequest) SetTextFormats(v [][]TableWidgetTextFormatRule) { + o.TextFormats = v +} + // MarshalJSON serializes the struct using spec logic. func (o TableWidgetRequest) MarshalJSON() ([]byte, error) { toSerialize := map[string]interface{}{} @@ -698,6 +728,9 @@ func (o TableWidgetRequest) MarshalJSON() ([]byte, error) { if o.Sort != nil { toSerialize["sort"] = o.Sort } + if o.TextFormats != nil { + toSerialize["text_formats"] = o.TextFormats + } for key, value := range o.AdditionalProperties { toSerialize[key] = value @@ -728,13 +761,14 @@ func (o *TableWidgetRequest) UnmarshalJSON(bytes []byte) (err error) { RumQuery *LogQueryDefinition `json:"rum_query,omitempty"` SecurityQuery *LogQueryDefinition `json:"security_query,omitempty"` Sort *WidgetSortBy `json:"sort,omitempty"` + TextFormats [][]TableWidgetTextFormatRule `json:"text_formats,omitempty"` }{} if err = datadog.Unmarshal(bytes, &all); err != nil { return datadog.Unmarshal(bytes, &o.UnparsedObject) } additionalProperties := make(map[string]interface{}) if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { - datadog.DeleteKeys(additionalProperties, &[]string{"aggregator", "alias", "apm_query", "apm_stats_query", "cell_display_mode", "conditional_formats", "event_query", "formulas", "limit", "log_query", "network_query", "order", "process_query", "profile_metrics_query", "q", "queries", "response_format", "rum_query", "security_query", "sort"}) + datadog.DeleteKeys(additionalProperties, &[]string{"aggregator", "alias", "apm_query", "apm_stats_query", "cell_display_mode", "conditional_formats", "event_query", "formulas", "limit", "log_query", "network_query", "order", "process_query", "profile_metrics_query", "q", "queries", "response_format", "rum_query", "security_query", "sort", "text_formats"}) } else { return err } @@ -802,6 +836,7 @@ func (o *TableWidgetRequest) UnmarshalJSON(bytes []byte) (err error) { hasInvalidField = true } o.Sort = all.Sort + o.TextFormats = all.TextFormats if len(additionalProperties) > 0 { o.AdditionalProperties = additionalProperties diff --git a/api/datadogV1/model_table_widget_text_format_custom_palette_type.go b/api/datadogV1/model_table_widget_text_format_custom_palette_type.go new file mode 100644 index 00000000000..8ebbf342f21 --- /dev/null +++ b/api/datadogV1/model_table_widget_text_format_custom_palette_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" +) + +// TableWidgetTextFormatCustomPaletteType Custom color-on-color palette. +type TableWidgetTextFormatCustomPaletteType string + +// List of TableWidgetTextFormatCustomPaletteType. +const ( + TABLEWIDGETTEXTFORMATCUSTOMPALETTETYPE_CUSTOM_BG TableWidgetTextFormatCustomPaletteType = "custom_bg" +) + +var allowedTableWidgetTextFormatCustomPaletteTypeEnumValues = []TableWidgetTextFormatCustomPaletteType{ + TABLEWIDGETTEXTFORMATCUSTOMPALETTETYPE_CUSTOM_BG, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *TableWidgetTextFormatCustomPaletteType) GetAllowedValues() []TableWidgetTextFormatCustomPaletteType { + return allowedTableWidgetTextFormatCustomPaletteTypeEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *TableWidgetTextFormatCustomPaletteType) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = TableWidgetTextFormatCustomPaletteType(value) + return nil +} + +// NewTableWidgetTextFormatCustomPaletteTypeFromValue returns a pointer to a valid TableWidgetTextFormatCustomPaletteType +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewTableWidgetTextFormatCustomPaletteTypeFromValue(v string) (*TableWidgetTextFormatCustomPaletteType, error) { + ev := TableWidgetTextFormatCustomPaletteType(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for TableWidgetTextFormatCustomPaletteType: valid values are %v", v, allowedTableWidgetTextFormatCustomPaletteTypeEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v TableWidgetTextFormatCustomPaletteType) IsValid() bool { + for _, existing := range allowedTableWidgetTextFormatCustomPaletteTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to TableWidgetTextFormatCustomPaletteType value. +func (v TableWidgetTextFormatCustomPaletteType) Ptr() *TableWidgetTextFormatCustomPaletteType { + return &v +} diff --git a/api/datadogV1/model_table_widget_text_format_match.go b/api/datadogV1/model_table_widget_text_format_match.go new file mode 100644 index 00000000000..2cce790a1b6 --- /dev/null +++ b/api/datadogV1/model_table_widget_text_format_match.go @@ -0,0 +1,143 @@ +// 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" +) + +// TableWidgetTextFormatMatch Match rule for the table widget text format. +type TableWidgetTextFormatMatch struct { + // Match or compare option. + Type TableWidgetTextFormatMatchType `json:"type"` + // Table Widget Match String. + Value string `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:"-"` +} + +// NewTableWidgetTextFormatMatch instantiates a new TableWidgetTextFormatMatch 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 NewTableWidgetTextFormatMatch(typeVar TableWidgetTextFormatMatchType, value string) *TableWidgetTextFormatMatch { + this := TableWidgetTextFormatMatch{} + this.Type = typeVar + this.Value = value + return &this +} + +// NewTableWidgetTextFormatMatchWithDefaults instantiates a new TableWidgetTextFormatMatch 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 NewTableWidgetTextFormatMatchWithDefaults() *TableWidgetTextFormatMatch { + this := TableWidgetTextFormatMatch{} + return &this +} + +// GetType returns the Type field value. +func (o *TableWidgetTextFormatMatch) GetType() TableWidgetTextFormatMatchType { + if o == nil { + var ret TableWidgetTextFormatMatchType + 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 *TableWidgetTextFormatMatch) GetTypeOk() (*TableWidgetTextFormatMatchType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value. +func (o *TableWidgetTextFormatMatch) SetType(v TableWidgetTextFormatMatchType) { + o.Type = v +} + +// GetValue returns the Value field value. +func (o *TableWidgetTextFormatMatch) GetValue() string { + if o == nil { + var ret string + 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 *TableWidgetTextFormatMatch) GetValueOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Value, true +} + +// SetValue sets field value. +func (o *TableWidgetTextFormatMatch) SetValue(v string) { + o.Value = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o TableWidgetTextFormatMatch) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["type"] = o.Type + toSerialize["value"] = o.Value + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *TableWidgetTextFormatMatch) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Type *TableWidgetTextFormatMatchType `json:"type"` + Value *string `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.Value == nil { + return fmt.Errorf("required field value missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"type", "value"}) + } else { + return err + } + + hasInvalidField := false + if !all.Type.IsValid() { + hasInvalidField = true + } else { + o.Type = *all.Type + } + 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_table_widget_text_format_match_type.go b/api/datadogV1/model_table_widget_text_format_match_type.go new file mode 100644 index 00000000000..1d6b2ca7ef9 --- /dev/null +++ b/api/datadogV1/model_table_widget_text_format_match_type.go @@ -0,0 +1,74 @@ +// 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" +) + +// TableWidgetTextFormatMatchType Match or compare option. +type TableWidgetTextFormatMatchType string + +// List of TableWidgetTextFormatMatchType. +const ( + TABLEWIDGETTEXTFORMATMATCHTYPE_IS TableWidgetTextFormatMatchType = "is" + TABLEWIDGETTEXTFORMATMATCHTYPE_IS_NOT TableWidgetTextFormatMatchType = "is_not" + TABLEWIDGETTEXTFORMATMATCHTYPE_CONTAINS TableWidgetTextFormatMatchType = "contains" + TABLEWIDGETTEXTFORMATMATCHTYPE_DOES_NOT_CONTAIN TableWidgetTextFormatMatchType = "does_not_contain" + TABLEWIDGETTEXTFORMATMATCHTYPE_STARTS_WITH TableWidgetTextFormatMatchType = "starts_with" + TABLEWIDGETTEXTFORMATMATCHTYPE_ENDS_WITH TableWidgetTextFormatMatchType = "ends_with" +) + +var allowedTableWidgetTextFormatMatchTypeEnumValues = []TableWidgetTextFormatMatchType{ + TABLEWIDGETTEXTFORMATMATCHTYPE_IS, + TABLEWIDGETTEXTFORMATMATCHTYPE_IS_NOT, + TABLEWIDGETTEXTFORMATMATCHTYPE_CONTAINS, + TABLEWIDGETTEXTFORMATMATCHTYPE_DOES_NOT_CONTAIN, + TABLEWIDGETTEXTFORMATMATCHTYPE_STARTS_WITH, + TABLEWIDGETTEXTFORMATMATCHTYPE_ENDS_WITH, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *TableWidgetTextFormatMatchType) GetAllowedValues() []TableWidgetTextFormatMatchType { + return allowedTableWidgetTextFormatMatchTypeEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *TableWidgetTextFormatMatchType) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = TableWidgetTextFormatMatchType(value) + return nil +} + +// NewTableWidgetTextFormatMatchTypeFromValue returns a pointer to a valid TableWidgetTextFormatMatchType +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewTableWidgetTextFormatMatchTypeFromValue(v string) (*TableWidgetTextFormatMatchType, error) { + ev := TableWidgetTextFormatMatchType(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for TableWidgetTextFormatMatchType: valid values are %v", v, allowedTableWidgetTextFormatMatchTypeEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v TableWidgetTextFormatMatchType) IsValid() bool { + for _, existing := range allowedTableWidgetTextFormatMatchTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to TableWidgetTextFormatMatchType value. +func (v TableWidgetTextFormatMatchType) Ptr() *TableWidgetTextFormatMatchType { + return &v +} diff --git a/api/datadogV1/model_table_widget_text_format_palette.go b/api/datadogV1/model_table_widget_text_format_palette.go new file mode 100644 index 00000000000..28380d82d78 --- /dev/null +++ b/api/datadogV1/model_table_widget_text_format_palette.go @@ -0,0 +1,78 @@ +// 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" +) + +// TableWidgetTextFormatPalette Color-on-color palette to highlight replaced text. +type TableWidgetTextFormatPalette string + +// List of TableWidgetTextFormatPalette. +const ( + TABLEWIDGETTEXTFORMATPALETTE_WHITE_ON_RED TableWidgetTextFormatPalette = "white_on_red" + TABLEWIDGETTEXTFORMATPALETTE_WHITE_ON_YELLOW TableWidgetTextFormatPalette = "white_on_yellow" + TABLEWIDGETTEXTFORMATPALETTE_WHITE_ON_GREEN TableWidgetTextFormatPalette = "white_on_green" + TABLEWIDGETTEXTFORMATPALETTE_BLACK_ON_LIGHT_RED TableWidgetTextFormatPalette = "black_on_light_red" + TABLEWIDGETTEXTFORMATPALETTE_BLACK_ON_LIGHT_YELLOW TableWidgetTextFormatPalette = "black_on_light_yellow" + TABLEWIDGETTEXTFORMATPALETTE_BLACK_ON_LIGHT_GREEN TableWidgetTextFormatPalette = "black_on_light_green" + TABLEWIDGETTEXTFORMATPALETTE_RED_ON_WHITE TableWidgetTextFormatPalette = "red_on_white" + TABLEWIDGETTEXTFORMATPALETTE_YELLOW_ON_WHITE TableWidgetTextFormatPalette = "yellow_on_white" +) + +var allowedTableWidgetTextFormatPaletteEnumValues = []TableWidgetTextFormatPalette{ + TABLEWIDGETTEXTFORMATPALETTE_WHITE_ON_RED, + TABLEWIDGETTEXTFORMATPALETTE_WHITE_ON_YELLOW, + TABLEWIDGETTEXTFORMATPALETTE_WHITE_ON_GREEN, + TABLEWIDGETTEXTFORMATPALETTE_BLACK_ON_LIGHT_RED, + TABLEWIDGETTEXTFORMATPALETTE_BLACK_ON_LIGHT_YELLOW, + TABLEWIDGETTEXTFORMATPALETTE_BLACK_ON_LIGHT_GREEN, + TABLEWIDGETTEXTFORMATPALETTE_RED_ON_WHITE, + TABLEWIDGETTEXTFORMATPALETTE_YELLOW_ON_WHITE, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *TableWidgetTextFormatPalette) GetAllowedValues() []TableWidgetTextFormatPalette { + return allowedTableWidgetTextFormatPaletteEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *TableWidgetTextFormatPalette) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = TableWidgetTextFormatPalette(value) + return nil +} + +// NewTableWidgetTextFormatPaletteFromValue returns a pointer to a valid TableWidgetTextFormatPalette +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewTableWidgetTextFormatPaletteFromValue(v string) (*TableWidgetTextFormatPalette, error) { + ev := TableWidgetTextFormatPalette(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for TableWidgetTextFormatPalette: valid values are %v", v, allowedTableWidgetTextFormatPaletteEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v TableWidgetTextFormatPalette) IsValid() bool { + for _, existing := range allowedTableWidgetTextFormatPaletteEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to TableWidgetTextFormatPalette value. +func (v TableWidgetTextFormatPalette) Ptr() *TableWidgetTextFormatPalette { + return &v +} diff --git a/api/datadogV1/model_table_widget_text_format_replace.go b/api/datadogV1/model_table_widget_text_format_replace.go new file mode 100644 index 00000000000..60742ebf625 --- /dev/null +++ b/api/datadogV1/model_table_widget_text_format_replace.go @@ -0,0 +1,105 @@ +// 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" +) + +// TableWidgetTextFormatReplace - Replace rule for the table widget text format. +type TableWidgetTextFormatReplace struct { + TableWidgetTextFormatReplaceAll *TableWidgetTextFormatReplaceAll + TableWidgetTextFormatReplaceSubstring *TableWidgetTextFormatReplaceSubstring + + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject interface{} +} + +// TableWidgetTextFormatReplaceAllAsTableWidgetTextFormatReplace is a convenience function that returns TableWidgetTextFormatReplaceAll wrapped in TableWidgetTextFormatReplace. +func TableWidgetTextFormatReplaceAllAsTableWidgetTextFormatReplace(v *TableWidgetTextFormatReplaceAll) TableWidgetTextFormatReplace { + return TableWidgetTextFormatReplace{TableWidgetTextFormatReplaceAll: v} +} + +// TableWidgetTextFormatReplaceSubstringAsTableWidgetTextFormatReplace is a convenience function that returns TableWidgetTextFormatReplaceSubstring wrapped in TableWidgetTextFormatReplace. +func TableWidgetTextFormatReplaceSubstringAsTableWidgetTextFormatReplace(v *TableWidgetTextFormatReplaceSubstring) TableWidgetTextFormatReplace { + return TableWidgetTextFormatReplace{TableWidgetTextFormatReplaceSubstring: v} +} + +// UnmarshalJSON turns data into one of the pointers in the struct. +func (obj *TableWidgetTextFormatReplace) UnmarshalJSON(data []byte) error { + var err error + match := 0 + // try to unmarshal data into TableWidgetTextFormatReplaceAll + err = datadog.Unmarshal(data, &obj.TableWidgetTextFormatReplaceAll) + if err == nil { + if obj.TableWidgetTextFormatReplaceAll != nil && obj.TableWidgetTextFormatReplaceAll.UnparsedObject == nil { + jsonTableWidgetTextFormatReplaceAll, _ := datadog.Marshal(obj.TableWidgetTextFormatReplaceAll) + if string(jsonTableWidgetTextFormatReplaceAll) == "{}" { // empty struct + obj.TableWidgetTextFormatReplaceAll = nil + } else { + match++ + } + } else { + obj.TableWidgetTextFormatReplaceAll = nil + } + } else { + obj.TableWidgetTextFormatReplaceAll = nil + } + + // try to unmarshal data into TableWidgetTextFormatReplaceSubstring + err = datadog.Unmarshal(data, &obj.TableWidgetTextFormatReplaceSubstring) + if err == nil { + if obj.TableWidgetTextFormatReplaceSubstring != nil && obj.TableWidgetTextFormatReplaceSubstring.UnparsedObject == nil { + jsonTableWidgetTextFormatReplaceSubstring, _ := datadog.Marshal(obj.TableWidgetTextFormatReplaceSubstring) + if string(jsonTableWidgetTextFormatReplaceSubstring) == "{}" { // empty struct + obj.TableWidgetTextFormatReplaceSubstring = nil + } else { + match++ + } + } else { + obj.TableWidgetTextFormatReplaceSubstring = nil + } + } else { + obj.TableWidgetTextFormatReplaceSubstring = nil + } + + if match != 1 { // more than 1 match + // reset to nil + obj.TableWidgetTextFormatReplaceAll = nil + obj.TableWidgetTextFormatReplaceSubstring = nil + return datadog.Unmarshal(data, &obj.UnparsedObject) + } + return nil // exactly one match +} + +// MarshalJSON turns data from the first non-nil pointers in the struct to JSON. +func (obj TableWidgetTextFormatReplace) MarshalJSON() ([]byte, error) { + if obj.TableWidgetTextFormatReplaceAll != nil { + return datadog.Marshal(&obj.TableWidgetTextFormatReplaceAll) + } + + if obj.TableWidgetTextFormatReplaceSubstring != nil { + return datadog.Marshal(&obj.TableWidgetTextFormatReplaceSubstring) + } + + if obj.UnparsedObject != nil { + return datadog.Marshal(obj.UnparsedObject) + } + return nil, nil // no data in oneOf schemas +} + +// GetActualInstance returns the actual instance. +func (obj *TableWidgetTextFormatReplace) GetActualInstance() interface{} { + if obj.TableWidgetTextFormatReplaceAll != nil { + return obj.TableWidgetTextFormatReplaceAll + } + + if obj.TableWidgetTextFormatReplaceSubstring != nil { + return obj.TableWidgetTextFormatReplaceSubstring + } + + // all schemas are nil + return nil +} diff --git a/api/datadogV1/model_table_widget_text_format_replace_all.go b/api/datadogV1/model_table_widget_text_format_replace_all.go new file mode 100644 index 00000000000..91d07434417 --- /dev/null +++ b/api/datadogV1/model_table_widget_text_format_replace_all.go @@ -0,0 +1,143 @@ +// 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" +) + +// TableWidgetTextFormatReplaceAll Match All definition. +type TableWidgetTextFormatReplaceAll struct { + // Table widget text format replace all type. + Type TableWidgetTextFormatReplaceAllType `json:"type"` + // Replace All type. + With string `json:"with"` + // 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:"-"` +} + +// NewTableWidgetTextFormatReplaceAll instantiates a new TableWidgetTextFormatReplaceAll 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 NewTableWidgetTextFormatReplaceAll(typeVar TableWidgetTextFormatReplaceAllType, with string) *TableWidgetTextFormatReplaceAll { + this := TableWidgetTextFormatReplaceAll{} + this.Type = typeVar + this.With = with + return &this +} + +// NewTableWidgetTextFormatReplaceAllWithDefaults instantiates a new TableWidgetTextFormatReplaceAll 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 NewTableWidgetTextFormatReplaceAllWithDefaults() *TableWidgetTextFormatReplaceAll { + this := TableWidgetTextFormatReplaceAll{} + return &this +} + +// GetType returns the Type field value. +func (o *TableWidgetTextFormatReplaceAll) GetType() TableWidgetTextFormatReplaceAllType { + if o == nil { + var ret TableWidgetTextFormatReplaceAllType + 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 *TableWidgetTextFormatReplaceAll) GetTypeOk() (*TableWidgetTextFormatReplaceAllType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value. +func (o *TableWidgetTextFormatReplaceAll) SetType(v TableWidgetTextFormatReplaceAllType) { + o.Type = v +} + +// GetWith returns the With field value. +func (o *TableWidgetTextFormatReplaceAll) GetWith() string { + if o == nil { + var ret string + return ret + } + return o.With +} + +// GetWithOk returns a tuple with the With field value +// and a boolean to check if the value has been set. +func (o *TableWidgetTextFormatReplaceAll) GetWithOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.With, true +} + +// SetWith sets field value. +func (o *TableWidgetTextFormatReplaceAll) SetWith(v string) { + o.With = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o TableWidgetTextFormatReplaceAll) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["type"] = o.Type + toSerialize["with"] = o.With + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *TableWidgetTextFormatReplaceAll) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Type *TableWidgetTextFormatReplaceAllType `json:"type"` + With *string `json:"with"` + }{} + 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.With == nil { + return fmt.Errorf("required field with missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"type", "with"}) + } else { + return err + } + + hasInvalidField := false + if !all.Type.IsValid() { + hasInvalidField = true + } else { + o.Type = *all.Type + } + o.With = *all.With + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV1/model_table_widget_text_format_replace_all_type.go b/api/datadogV1/model_table_widget_text_format_replace_all_type.go new file mode 100644 index 00000000000..59e00d97ea6 --- /dev/null +++ b/api/datadogV1/model_table_widget_text_format_replace_all_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" +) + +// TableWidgetTextFormatReplaceAllType Table widget text format replace all type. +type TableWidgetTextFormatReplaceAllType string + +// List of TableWidgetTextFormatReplaceAllType. +const ( + TABLEWIDGETTEXTFORMATREPLACEALLTYPE_ALL TableWidgetTextFormatReplaceAllType = "all" +) + +var allowedTableWidgetTextFormatReplaceAllTypeEnumValues = []TableWidgetTextFormatReplaceAllType{ + TABLEWIDGETTEXTFORMATREPLACEALLTYPE_ALL, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *TableWidgetTextFormatReplaceAllType) GetAllowedValues() []TableWidgetTextFormatReplaceAllType { + return allowedTableWidgetTextFormatReplaceAllTypeEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *TableWidgetTextFormatReplaceAllType) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = TableWidgetTextFormatReplaceAllType(value) + return nil +} + +// NewTableWidgetTextFormatReplaceAllTypeFromValue returns a pointer to a valid TableWidgetTextFormatReplaceAllType +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewTableWidgetTextFormatReplaceAllTypeFromValue(v string) (*TableWidgetTextFormatReplaceAllType, error) { + ev := TableWidgetTextFormatReplaceAllType(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for TableWidgetTextFormatReplaceAllType: valid values are %v", v, allowedTableWidgetTextFormatReplaceAllTypeEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v TableWidgetTextFormatReplaceAllType) IsValid() bool { + for _, existing := range allowedTableWidgetTextFormatReplaceAllTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to TableWidgetTextFormatReplaceAllType value. +func (v TableWidgetTextFormatReplaceAllType) Ptr() *TableWidgetTextFormatReplaceAllType { + return &v +} diff --git a/api/datadogV1/model_table_widget_text_format_replace_substring.go b/api/datadogV1/model_table_widget_text_format_replace_substring.go new file mode 100644 index 00000000000..b70d9e40fb9 --- /dev/null +++ b/api/datadogV1/model_table_widget_text_format_replace_substring.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" +) + +// TableWidgetTextFormatReplaceSubstring Match Sub-string definition. +type TableWidgetTextFormatReplaceSubstring struct { + // Text that will be replaced. + Substring string `json:"substring"` + // Table widget text format replace sub-string type. + Type TableWidgetTextFormatReplaceSubstringType `json:"type"` + // Text that will replace original sub-string. + With string `json:"with"` + // 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:"-"` +} + +// NewTableWidgetTextFormatReplaceSubstring instantiates a new TableWidgetTextFormatReplaceSubstring 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 NewTableWidgetTextFormatReplaceSubstring(substring string, typeVar TableWidgetTextFormatReplaceSubstringType, with string) *TableWidgetTextFormatReplaceSubstring { + this := TableWidgetTextFormatReplaceSubstring{} + this.Substring = substring + this.Type = typeVar + this.With = with + return &this +} + +// NewTableWidgetTextFormatReplaceSubstringWithDefaults instantiates a new TableWidgetTextFormatReplaceSubstring 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 NewTableWidgetTextFormatReplaceSubstringWithDefaults() *TableWidgetTextFormatReplaceSubstring { + this := TableWidgetTextFormatReplaceSubstring{} + return &this +} + +// GetSubstring returns the Substring field value. +func (o *TableWidgetTextFormatReplaceSubstring) GetSubstring() string { + if o == nil { + var ret string + return ret + } + return o.Substring +} + +// GetSubstringOk returns a tuple with the Substring field value +// and a boolean to check if the value has been set. +func (o *TableWidgetTextFormatReplaceSubstring) GetSubstringOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Substring, true +} + +// SetSubstring sets field value. +func (o *TableWidgetTextFormatReplaceSubstring) SetSubstring(v string) { + o.Substring = v +} + +// GetType returns the Type field value. +func (o *TableWidgetTextFormatReplaceSubstring) GetType() TableWidgetTextFormatReplaceSubstringType { + if o == nil { + var ret TableWidgetTextFormatReplaceSubstringType + 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 *TableWidgetTextFormatReplaceSubstring) GetTypeOk() (*TableWidgetTextFormatReplaceSubstringType, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value. +func (o *TableWidgetTextFormatReplaceSubstring) SetType(v TableWidgetTextFormatReplaceSubstringType) { + o.Type = v +} + +// GetWith returns the With field value. +func (o *TableWidgetTextFormatReplaceSubstring) GetWith() string { + if o == nil { + var ret string + return ret + } + return o.With +} + +// GetWithOk returns a tuple with the With field value +// and a boolean to check if the value has been set. +func (o *TableWidgetTextFormatReplaceSubstring) GetWithOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.With, true +} + +// SetWith sets field value. +func (o *TableWidgetTextFormatReplaceSubstring) SetWith(v string) { + o.With = v +} + +// MarshalJSON serializes the struct using spec logic. +func (o TableWidgetTextFormatReplaceSubstring) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["substring"] = o.Substring + toSerialize["type"] = o.Type + toSerialize["with"] = o.With + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *TableWidgetTextFormatReplaceSubstring) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Substring *string `json:"substring"` + Type *TableWidgetTextFormatReplaceSubstringType `json:"type"` + With *string `json:"with"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Substring == nil { + return fmt.Errorf("required field substring missing") + } + if all.Type == nil { + return fmt.Errorf("required field type missing") + } + if all.With == nil { + return fmt.Errorf("required field with missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"substring", "type", "with"}) + } else { + return err + } + + hasInvalidField := false + o.Substring = *all.Substring + if !all.Type.IsValid() { + hasInvalidField = true + } else { + o.Type = *all.Type + } + o.With = *all.With + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV1/model_table_widget_text_format_replace_substring_type.go b/api/datadogV1/model_table_widget_text_format_replace_substring_type.go new file mode 100644 index 00000000000..270f314d444 --- /dev/null +++ b/api/datadogV1/model_table_widget_text_format_replace_substring_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" +) + +// TableWidgetTextFormatReplaceSubstringType Table widget text format replace sub-string type. +type TableWidgetTextFormatReplaceSubstringType string + +// List of TableWidgetTextFormatReplaceSubstringType. +const ( + TABLEWIDGETTEXTFORMATREPLACESUBSTRINGTYPE_SUBSTRING TableWidgetTextFormatReplaceSubstringType = "substring" +) + +var allowedTableWidgetTextFormatReplaceSubstringTypeEnumValues = []TableWidgetTextFormatReplaceSubstringType{ + TABLEWIDGETTEXTFORMATREPLACESUBSTRINGTYPE_SUBSTRING, +} + +// GetAllowedValues reeturns the list of possible values. +func (v *TableWidgetTextFormatReplaceSubstringType) GetAllowedValues() []TableWidgetTextFormatReplaceSubstringType { + return allowedTableWidgetTextFormatReplaceSubstringTypeEnumValues +} + +// UnmarshalJSON deserializes the given payload. +func (v *TableWidgetTextFormatReplaceSubstringType) UnmarshalJSON(src []byte) error { + var value string + err := datadog.Unmarshal(src, &value) + if err != nil { + return err + } + *v = TableWidgetTextFormatReplaceSubstringType(value) + return nil +} + +// NewTableWidgetTextFormatReplaceSubstringTypeFromValue returns a pointer to a valid TableWidgetTextFormatReplaceSubstringType +// for the value passed as argument, or an error if the value passed is not allowed by the enum. +func NewTableWidgetTextFormatReplaceSubstringTypeFromValue(v string) (*TableWidgetTextFormatReplaceSubstringType, error) { + ev := TableWidgetTextFormatReplaceSubstringType(v) + if ev.IsValid() { + return &ev, nil + } + return nil, fmt.Errorf("invalid value '%v' for TableWidgetTextFormatReplaceSubstringType: valid values are %v", v, allowedTableWidgetTextFormatReplaceSubstringTypeEnumValues) +} + +// IsValid return true if the value is valid for the enum, false otherwise. +func (v TableWidgetTextFormatReplaceSubstringType) IsValid() bool { + for _, existing := range allowedTableWidgetTextFormatReplaceSubstringTypeEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to TableWidgetTextFormatReplaceSubstringType value. +func (v TableWidgetTextFormatReplaceSubstringType) Ptr() *TableWidgetTextFormatReplaceSubstringType { + return &v +} diff --git a/api/datadogV1/model_table_widget_text_format_rule.go b/api/datadogV1/model_table_widget_text_format_rule.go new file mode 100644 index 00000000000..4d4fd9d72f5 --- /dev/null +++ b/api/datadogV1/model_table_widget_text_format_rule.go @@ -0,0 +1,105 @@ +// 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" +) + +// TableWidgetTextFormatRule - Text format rule. +type TableWidgetTextFormatRule struct { + TableWidgetTextFormatRuleMain *TableWidgetTextFormatRuleMain + TableWidgetTextFormatRuleCustomPalette *TableWidgetTextFormatRuleCustomPalette + + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct + UnparsedObject interface{} +} + +// TableWidgetTextFormatRuleMainAsTableWidgetTextFormatRule is a convenience function that returns TableWidgetTextFormatRuleMain wrapped in TableWidgetTextFormatRule. +func TableWidgetTextFormatRuleMainAsTableWidgetTextFormatRule(v *TableWidgetTextFormatRuleMain) TableWidgetTextFormatRule { + return TableWidgetTextFormatRule{TableWidgetTextFormatRuleMain: v} +} + +// TableWidgetTextFormatRuleCustomPaletteAsTableWidgetTextFormatRule is a convenience function that returns TableWidgetTextFormatRuleCustomPalette wrapped in TableWidgetTextFormatRule. +func TableWidgetTextFormatRuleCustomPaletteAsTableWidgetTextFormatRule(v *TableWidgetTextFormatRuleCustomPalette) TableWidgetTextFormatRule { + return TableWidgetTextFormatRule{TableWidgetTextFormatRuleCustomPalette: v} +} + +// UnmarshalJSON turns data into one of the pointers in the struct. +func (obj *TableWidgetTextFormatRule) UnmarshalJSON(data []byte) error { + var err error + match := 0 + // try to unmarshal data into TableWidgetTextFormatRuleMain + err = datadog.Unmarshal(data, &obj.TableWidgetTextFormatRuleMain) + if err == nil { + if obj.TableWidgetTextFormatRuleMain != nil && obj.TableWidgetTextFormatRuleMain.UnparsedObject == nil { + jsonTableWidgetTextFormatRuleMain, _ := datadog.Marshal(obj.TableWidgetTextFormatRuleMain) + if string(jsonTableWidgetTextFormatRuleMain) == "{}" { // empty struct + obj.TableWidgetTextFormatRuleMain = nil + } else { + match++ + } + } else { + obj.TableWidgetTextFormatRuleMain = nil + } + } else { + obj.TableWidgetTextFormatRuleMain = nil + } + + // try to unmarshal data into TableWidgetTextFormatRuleCustomPalette + err = datadog.Unmarshal(data, &obj.TableWidgetTextFormatRuleCustomPalette) + if err == nil { + if obj.TableWidgetTextFormatRuleCustomPalette != nil && obj.TableWidgetTextFormatRuleCustomPalette.UnparsedObject == nil { + jsonTableWidgetTextFormatRuleCustomPalette, _ := datadog.Marshal(obj.TableWidgetTextFormatRuleCustomPalette) + if string(jsonTableWidgetTextFormatRuleCustomPalette) == "{}" { // empty struct + obj.TableWidgetTextFormatRuleCustomPalette = nil + } else { + match++ + } + } else { + obj.TableWidgetTextFormatRuleCustomPalette = nil + } + } else { + obj.TableWidgetTextFormatRuleCustomPalette = nil + } + + if match != 1 { // more than 1 match + // reset to nil + obj.TableWidgetTextFormatRuleMain = nil + obj.TableWidgetTextFormatRuleCustomPalette = nil + return datadog.Unmarshal(data, &obj.UnparsedObject) + } + return nil // exactly one match +} + +// MarshalJSON turns data from the first non-nil pointers in the struct to JSON. +func (obj TableWidgetTextFormatRule) MarshalJSON() ([]byte, error) { + if obj.TableWidgetTextFormatRuleMain != nil { + return datadog.Marshal(&obj.TableWidgetTextFormatRuleMain) + } + + if obj.TableWidgetTextFormatRuleCustomPalette != nil { + return datadog.Marshal(&obj.TableWidgetTextFormatRuleCustomPalette) + } + + if obj.UnparsedObject != nil { + return datadog.Marshal(obj.UnparsedObject) + } + return nil, nil // no data in oneOf schemas +} + +// GetActualInstance returns the actual instance. +func (obj *TableWidgetTextFormatRule) GetActualInstance() interface{} { + if obj.TableWidgetTextFormatRuleMain != nil { + return obj.TableWidgetTextFormatRuleMain + } + + if obj.TableWidgetTextFormatRuleCustomPalette != nil { + return obj.TableWidgetTextFormatRuleCustomPalette + } + + // all schemas are nil + return nil +} diff --git a/api/datadogV1/model_table_widget_text_format_rule_custom_palette.go b/api/datadogV1/model_table_widget_text_format_rule_custom_palette.go new file mode 100644 index 00000000000..aad408df344 --- /dev/null +++ b/api/datadogV1/model_table_widget_text_format_rule_custom_palette.go @@ -0,0 +1,213 @@ +// 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" +) + +// TableWidgetTextFormatRuleCustomPalette Text format rule with custom palette. +type TableWidgetTextFormatRuleCustomPalette struct { + // Hex representation of the custom background color. + CustomBgColor string `json:"custom_bg_color"` + // Match rule for the table widget text format. + Match TableWidgetTextFormatMatch `json:"match"` + // Custom color-on-color palette. + Palette TableWidgetTextFormatCustomPaletteType `json:"palette"` + // Replace rule for the table widget text format. + Replace *TableWidgetTextFormatReplace `json:"replace,omitempty"` + // 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:"-"` +} + +// NewTableWidgetTextFormatRuleCustomPalette instantiates a new TableWidgetTextFormatRuleCustomPalette 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 NewTableWidgetTextFormatRuleCustomPalette(customBgColor string, match TableWidgetTextFormatMatch, palette TableWidgetTextFormatCustomPaletteType) *TableWidgetTextFormatRuleCustomPalette { + this := TableWidgetTextFormatRuleCustomPalette{} + this.CustomBgColor = customBgColor + this.Match = match + this.Palette = palette + return &this +} + +// NewTableWidgetTextFormatRuleCustomPaletteWithDefaults instantiates a new TableWidgetTextFormatRuleCustomPalette 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 NewTableWidgetTextFormatRuleCustomPaletteWithDefaults() *TableWidgetTextFormatRuleCustomPalette { + this := TableWidgetTextFormatRuleCustomPalette{} + return &this +} + +// GetCustomBgColor returns the CustomBgColor field value. +func (o *TableWidgetTextFormatRuleCustomPalette) GetCustomBgColor() string { + if o == nil { + var ret string + return ret + } + return o.CustomBgColor +} + +// GetCustomBgColorOk returns a tuple with the CustomBgColor field value +// and a boolean to check if the value has been set. +func (o *TableWidgetTextFormatRuleCustomPalette) GetCustomBgColorOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.CustomBgColor, true +} + +// SetCustomBgColor sets field value. +func (o *TableWidgetTextFormatRuleCustomPalette) SetCustomBgColor(v string) { + o.CustomBgColor = v +} + +// GetMatch returns the Match field value. +func (o *TableWidgetTextFormatRuleCustomPalette) GetMatch() TableWidgetTextFormatMatch { + if o == nil { + var ret TableWidgetTextFormatMatch + return ret + } + return o.Match +} + +// GetMatchOk returns a tuple with the Match field value +// and a boolean to check if the value has been set. +func (o *TableWidgetTextFormatRuleCustomPalette) GetMatchOk() (*TableWidgetTextFormatMatch, bool) { + if o == nil { + return nil, false + } + return &o.Match, true +} + +// SetMatch sets field value. +func (o *TableWidgetTextFormatRuleCustomPalette) SetMatch(v TableWidgetTextFormatMatch) { + o.Match = v +} + +// GetPalette returns the Palette field value. +func (o *TableWidgetTextFormatRuleCustomPalette) GetPalette() TableWidgetTextFormatCustomPaletteType { + if o == nil { + var ret TableWidgetTextFormatCustomPaletteType + return ret + } + return o.Palette +} + +// GetPaletteOk returns a tuple with the Palette field value +// and a boolean to check if the value has been set. +func (o *TableWidgetTextFormatRuleCustomPalette) GetPaletteOk() (*TableWidgetTextFormatCustomPaletteType, bool) { + if o == nil { + return nil, false + } + return &o.Palette, true +} + +// SetPalette sets field value. +func (o *TableWidgetTextFormatRuleCustomPalette) SetPalette(v TableWidgetTextFormatCustomPaletteType) { + o.Palette = v +} + +// GetReplace returns the Replace field value if set, zero value otherwise. +func (o *TableWidgetTextFormatRuleCustomPalette) GetReplace() TableWidgetTextFormatReplace { + if o == nil || o.Replace == nil { + var ret TableWidgetTextFormatReplace + return ret + } + return *o.Replace +} + +// GetReplaceOk returns a tuple with the Replace field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *TableWidgetTextFormatRuleCustomPalette) GetReplaceOk() (*TableWidgetTextFormatReplace, bool) { + if o == nil || o.Replace == nil { + return nil, false + } + return o.Replace, true +} + +// HasReplace returns a boolean if a field has been set. +func (o *TableWidgetTextFormatRuleCustomPalette) HasReplace() bool { + return o != nil && o.Replace != nil +} + +// SetReplace gets a reference to the given TableWidgetTextFormatReplace and assigns it to the Replace field. +func (o *TableWidgetTextFormatRuleCustomPalette) SetReplace(v TableWidgetTextFormatReplace) { + o.Replace = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o TableWidgetTextFormatRuleCustomPalette) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["custom_bg_color"] = o.CustomBgColor + toSerialize["match"] = o.Match + toSerialize["palette"] = o.Palette + if o.Replace != nil { + toSerialize["replace"] = o.Replace + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *TableWidgetTextFormatRuleCustomPalette) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + CustomBgColor *string `json:"custom_bg_color"` + Match *TableWidgetTextFormatMatch `json:"match"` + Palette *TableWidgetTextFormatCustomPaletteType `json:"palette"` + Replace *TableWidgetTextFormatReplace `json:"replace,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.CustomBgColor == nil { + return fmt.Errorf("required field custom_bg_color missing") + } + if all.Match == nil { + return fmt.Errorf("required field match missing") + } + if all.Palette == nil { + return fmt.Errorf("required field palette missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"custom_bg_color", "match", "palette", "replace"}) + } else { + return err + } + + hasInvalidField := false + o.CustomBgColor = *all.CustomBgColor + if all.Match.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Match = *all.Match + if !all.Palette.IsValid() { + hasInvalidField = true + } else { + o.Palette = *all.Palette + } + o.Replace = all.Replace + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/api/datadogV1/model_table_widget_text_format_rule_main.go b/api/datadogV1/model_table_widget_text_format_rule_main.go new file mode 100644 index 00000000000..36c2435240b --- /dev/null +++ b/api/datadogV1/model_table_widget_text_format_rule_main.go @@ -0,0 +1,188 @@ +// 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" +) + +// TableWidgetTextFormatRuleMain Text format rule with preset palettes. +type TableWidgetTextFormatRuleMain struct { + // Match rule for the table widget text format. + Match TableWidgetTextFormatMatch `json:"match"` + // Color-on-color palette to highlight replaced text. + Palette *TableWidgetTextFormatPalette `json:"palette,omitempty"` + // Replace rule for the table widget text format. + Replace *TableWidgetTextFormatReplace `json:"replace,omitempty"` + // 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:"-"` +} + +// NewTableWidgetTextFormatRuleMain instantiates a new TableWidgetTextFormatRuleMain 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 NewTableWidgetTextFormatRuleMain(match TableWidgetTextFormatMatch) *TableWidgetTextFormatRuleMain { + this := TableWidgetTextFormatRuleMain{} + this.Match = match + var palette TableWidgetTextFormatPalette = TABLEWIDGETTEXTFORMATPALETTE_WHITE_ON_GREEN + this.Palette = &palette + return &this +} + +// NewTableWidgetTextFormatRuleMainWithDefaults instantiates a new TableWidgetTextFormatRuleMain 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 NewTableWidgetTextFormatRuleMainWithDefaults() *TableWidgetTextFormatRuleMain { + this := TableWidgetTextFormatRuleMain{} + var palette TableWidgetTextFormatPalette = TABLEWIDGETTEXTFORMATPALETTE_WHITE_ON_GREEN + this.Palette = &palette + return &this +} + +// GetMatch returns the Match field value. +func (o *TableWidgetTextFormatRuleMain) GetMatch() TableWidgetTextFormatMatch { + if o == nil { + var ret TableWidgetTextFormatMatch + return ret + } + return o.Match +} + +// GetMatchOk returns a tuple with the Match field value +// and a boolean to check if the value has been set. +func (o *TableWidgetTextFormatRuleMain) GetMatchOk() (*TableWidgetTextFormatMatch, bool) { + if o == nil { + return nil, false + } + return &o.Match, true +} + +// SetMatch sets field value. +func (o *TableWidgetTextFormatRuleMain) SetMatch(v TableWidgetTextFormatMatch) { + o.Match = v +} + +// GetPalette returns the Palette field value if set, zero value otherwise. +func (o *TableWidgetTextFormatRuleMain) GetPalette() TableWidgetTextFormatPalette { + if o == nil || o.Palette == nil { + var ret TableWidgetTextFormatPalette + return ret + } + return *o.Palette +} + +// GetPaletteOk returns a tuple with the Palette field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *TableWidgetTextFormatRuleMain) GetPaletteOk() (*TableWidgetTextFormatPalette, bool) { + if o == nil || o.Palette == nil { + return nil, false + } + return o.Palette, true +} + +// HasPalette returns a boolean if a field has been set. +func (o *TableWidgetTextFormatRuleMain) HasPalette() bool { + return o != nil && o.Palette != nil +} + +// SetPalette gets a reference to the given TableWidgetTextFormatPalette and assigns it to the Palette field. +func (o *TableWidgetTextFormatRuleMain) SetPalette(v TableWidgetTextFormatPalette) { + o.Palette = &v +} + +// GetReplace returns the Replace field value if set, zero value otherwise. +func (o *TableWidgetTextFormatRuleMain) GetReplace() TableWidgetTextFormatReplace { + if o == nil || o.Replace == nil { + var ret TableWidgetTextFormatReplace + return ret + } + return *o.Replace +} + +// GetReplaceOk returns a tuple with the Replace field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *TableWidgetTextFormatRuleMain) GetReplaceOk() (*TableWidgetTextFormatReplace, bool) { + if o == nil || o.Replace == nil { + return nil, false + } + return o.Replace, true +} + +// HasReplace returns a boolean if a field has been set. +func (o *TableWidgetTextFormatRuleMain) HasReplace() bool { + return o != nil && o.Replace != nil +} + +// SetReplace gets a reference to the given TableWidgetTextFormatReplace and assigns it to the Replace field. +func (o *TableWidgetTextFormatRuleMain) SetReplace(v TableWidgetTextFormatReplace) { + o.Replace = &v +} + +// MarshalJSON serializes the struct using spec logic. +func (o TableWidgetTextFormatRuleMain) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.UnparsedObject != nil { + return datadog.Marshal(o.UnparsedObject) + } + toSerialize["match"] = o.Match + if o.Palette != nil { + toSerialize["palette"] = o.Palette + } + if o.Replace != nil { + toSerialize["replace"] = o.Replace + } + + for key, value := range o.AdditionalProperties { + toSerialize[key] = value + } + return datadog.Marshal(toSerialize) +} + +// UnmarshalJSON deserializes the given payload. +func (o *TableWidgetTextFormatRuleMain) UnmarshalJSON(bytes []byte) (err error) { + all := struct { + Match *TableWidgetTextFormatMatch `json:"match"` + Palette *TableWidgetTextFormatPalette `json:"palette,omitempty"` + Replace *TableWidgetTextFormatReplace `json:"replace,omitempty"` + }{} + if err = datadog.Unmarshal(bytes, &all); err != nil { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + if all.Match == nil { + return fmt.Errorf("required field match missing") + } + additionalProperties := make(map[string]interface{}) + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { + datadog.DeleteKeys(additionalProperties, &[]string{"match", "palette", "replace"}) + } else { + return err + } + + hasInvalidField := false + if all.Match.UnparsedObject != nil && o.UnparsedObject == nil { + hasInvalidField = true + } + o.Match = *all.Match + if all.Palette != nil && !all.Palette.IsValid() { + hasInvalidField = true + } else { + o.Palette = all.Palette + } + o.Replace = all.Replace + + if len(additionalProperties) > 0 { + o.AdditionalProperties = additionalProperties + } + + if hasInvalidField { + return datadog.Unmarshal(bytes, &o.UnparsedObject) + } + + return nil +} diff --git a/examples/v1/dashboards/CreateDashboard_794302680.go b/examples/v1/dashboards/CreateDashboard_794302680.go new file mode 100644 index 00000000000..75c111c11f0 --- /dev/null +++ b/examples/v1/dashboards/CreateDashboard_794302680.go @@ -0,0 +1,174 @@ +// Create a new dashboard with query_table widget and text formatting + +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-Dashboard", + Description: *datadog.NewNullableString(datadog.PtrString("")), + Widgets: []datadogV1.Widget{ + { + Definition: datadogV1.WidgetDefinition{ + TableWidgetDefinition: &datadogV1.TableWidgetDefinition{ + Title: datadog.PtrString(""), + TitleSize: datadog.PtrString("16"), + TitleAlign: datadogV1.WIDGETTEXTALIGN_LEFT.Ptr(), + Type: datadogV1.TABLEWIDGETDEFINITIONTYPE_QUERY_TABLE, + Requests: []datadogV1.TableWidgetRequest{ + { + Queries: []datadogV1.FormulaAndFunctionQueryDefinition{ + datadogV1.FormulaAndFunctionQueryDefinition{ + FormulaAndFunctionMetricQueryDefinition: &datadogV1.FormulaAndFunctionMetricQueryDefinition{ + Aggregator: datadogV1.FORMULAANDFUNCTIONMETRICAGGREGATION_AVG.Ptr(), + DataSource: datadogV1.FORMULAANDFUNCTIONMETRICDATASOURCE_METRICS, + Name: "query1", + Query: "avg:aws.stream.globalaccelerator.processed_bytes_in{*} by {aws_account,acceleratoripaddress}", + }}, + datadogV1.FormulaAndFunctionQueryDefinition{ + FormulaAndFunctionMetricQueryDefinition: &datadogV1.FormulaAndFunctionMetricQueryDefinition{ + Aggregator: datadogV1.FORMULAANDFUNCTIONMETRICAGGREGATION_AVG.Ptr(), + DataSource: datadogV1.FORMULAANDFUNCTIONMETRICDATASOURCE_METRICS, + Name: "query2", + Query: "avg:aws.stream.globalaccelerator.processed_bytes_out{*} by {aws_account,acceleratoripaddress}", + }}, + }, + ResponseFormat: datadogV1.FORMULAANDFUNCTIONRESPONSEFORMAT_SCALAR.Ptr(), + TextFormats: [][]datadogV1.TableWidgetTextFormatRule{ + { + datadogV1.TableWidgetTextFormatRule{ + TableWidgetTextFormatRuleMain: &datadogV1.TableWidgetTextFormatRuleMain{ + Match: datadogV1.TableWidgetTextFormatMatch{ + Type: datadogV1.TABLEWIDGETTEXTFORMATMATCHTYPE_IS, + Value: "fruit", + }, + Palette: datadogV1.TABLEWIDGETTEXTFORMATPALETTE_WHITE_ON_RED.Ptr(), + Replace: &datadogV1.TableWidgetTextFormatReplace{ + TableWidgetTextFormatReplaceAll: &datadogV1.TableWidgetTextFormatReplaceAll{ + Type: datadogV1.TABLEWIDGETTEXTFORMATREPLACEALLTYPE_ALL, + With: "vegetable", + }}, + }}, + datadogV1.TableWidgetTextFormatRule{ + TableWidgetTextFormatRuleCustomPalette: &datadogV1.TableWidgetTextFormatRuleCustomPalette{ + Match: datadogV1.TableWidgetTextFormatMatch{ + Type: datadogV1.TABLEWIDGETTEXTFORMATMATCHTYPE_IS, + Value: "animal", + }, + Palette: datadogV1.TABLEWIDGETTEXTFORMATCUSTOMPALETTETYPE_CUSTOM_BG, + CustomBgColor: "#c33c3c", + }}, + datadogV1.TableWidgetTextFormatRule{ + TableWidgetTextFormatRuleMain: &datadogV1.TableWidgetTextFormatRuleMain{ + Match: datadogV1.TableWidgetTextFormatMatch{ + Type: datadogV1.TABLEWIDGETTEXTFORMATMATCHTYPE_IS, + Value: "robot", + }, + Palette: datadogV1.TABLEWIDGETTEXTFORMATPALETTE_RED_ON_WHITE.Ptr(), + }}, + datadogV1.TableWidgetTextFormatRule{ + TableWidgetTextFormatRuleMain: &datadogV1.TableWidgetTextFormatRuleMain{ + Match: datadogV1.TableWidgetTextFormatMatch{ + Type: datadogV1.TABLEWIDGETTEXTFORMATMATCHTYPE_IS, + Value: "ai", + }, + Palette: datadogV1.TABLEWIDGETTEXTFORMATPALETTE_YELLOW_ON_WHITE.Ptr(), + }}, + }, + { + datadogV1.TableWidgetTextFormatRule{ + TableWidgetTextFormatRuleMain: &datadogV1.TableWidgetTextFormatRuleMain{ + Match: datadogV1.TableWidgetTextFormatMatch{ + Type: datadogV1.TABLEWIDGETTEXTFORMATMATCHTYPE_IS_NOT, + Value: "xyz", + }, + Palette: datadogV1.TABLEWIDGETTEXTFORMATPALETTE_WHITE_ON_YELLOW.Ptr(), + }}, + }, + { + datadogV1.TableWidgetTextFormatRule{ + TableWidgetTextFormatRuleMain: &datadogV1.TableWidgetTextFormatRuleMain{ + Match: datadogV1.TableWidgetTextFormatMatch{ + Type: datadogV1.TABLEWIDGETTEXTFORMATMATCHTYPE_CONTAINS, + Value: "test", + }, + Palette: datadogV1.TABLEWIDGETTEXTFORMATPALETTE_WHITE_ON_GREEN.Ptr(), + Replace: &datadogV1.TableWidgetTextFormatReplace{ + TableWidgetTextFormatReplaceAll: &datadogV1.TableWidgetTextFormatReplaceAll{ + Type: datadogV1.TABLEWIDGETTEXTFORMATREPLACEALLTYPE_ALL, + With: "vegetable", + }}, + }}, + }, + { + datadogV1.TableWidgetTextFormatRule{ + TableWidgetTextFormatRuleMain: &datadogV1.TableWidgetTextFormatRuleMain{ + Match: datadogV1.TableWidgetTextFormatMatch{ + Type: datadogV1.TABLEWIDGETTEXTFORMATMATCHTYPE_DOES_NOT_CONTAIN, + Value: "blah", + }, + Palette: datadogV1.TABLEWIDGETTEXTFORMATPALETTE_BLACK_ON_LIGHT_RED.Ptr(), + }}, + }, + { + datadogV1.TableWidgetTextFormatRule{ + TableWidgetTextFormatRuleMain: &datadogV1.TableWidgetTextFormatRuleMain{ + Match: datadogV1.TableWidgetTextFormatMatch{ + Type: datadogV1.TABLEWIDGETTEXTFORMATMATCHTYPE_STARTS_WITH, + Value: "abc", + }, + Palette: datadogV1.TABLEWIDGETTEXTFORMATPALETTE_BLACK_ON_LIGHT_YELLOW.Ptr(), + }}, + }, + { + datadogV1.TableWidgetTextFormatRule{ + TableWidgetTextFormatRuleMain: &datadogV1.TableWidgetTextFormatRuleMain{ + Match: datadogV1.TableWidgetTextFormatMatch{ + Type: datadogV1.TABLEWIDGETTEXTFORMATMATCHTYPE_ENDS_WITH, + Value: "xyz", + }, + Palette: datadogV1.TABLEWIDGETTEXTFORMATPALETTE_BLACK_ON_LIGHT_GREEN.Ptr(), + }}, + }, + }, + Formulas: []datadogV1.WidgetFormula{}, + }, + }, + HasSearchBar: datadogV1.TABLEWIDGETHASSEARCHBAR_NEVER.Ptr(), + }}, + Layout: &datadogV1.WidgetLayout{ + X: 0, + Y: 0, + Width: 4, + Height: 4, + }, + }, + }, + TemplateVariables: []datadogV1.DashboardTemplateVariable{}, + LayoutType: datadogV1.DASHBOARDLAYOUTTYPE_FREE, + IsReadOnly: datadog.PtrBool(false), + NotifyList: *datadog.NewNullableList(&[]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_query_table_widget_and_text_formatting.freeze b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Dashboards/Scenario_Create_a_new_dashboard_with_query_table_widget_and_text_formatting.freeze new file mode 100644 index 00000000000..51efecd8d94 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Dashboards/Scenario_Create_a_new_dashboard_with_query_table_widget_and_text_formatting.freeze @@ -0,0 +1 @@ +2024-09-06T23:18:00.781Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/TestScenarios/v1/Feature_Dashboards/Scenario_Create_a_new_dashboard_with_query_table_widget_and_text_formatting.yaml b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Dashboards/Scenario_Create_a_new_dashboard_with_query_table_widget_and_text_formatting.yaml new file mode 100644 index 00000000000..628b34b49a4 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Dashboards/Scenario_Create_a_new_dashboard_with_query_table_widget_and_text_formatting.yaml @@ -0,0 +1,45 @@ +interactions: +- request: + body: | + {"description":"","is_read_only":false,"layout_type":"free","notify_list":[],"template_variables":[],"title":"Test-Create_a_new_dashboard_with_query_table_widget_and_text_formatting-1725664680","widgets":[{"definition":{"has_search_bar":"never","requests":[{"formulas":[],"queries":[{"aggregator":"avg","data_source":"metrics","name":"query1","query":"avg:aws.stream.globalaccelerator.processed_bytes_in{*} by {aws_account,acceleratoripaddress}"},{"aggregator":"avg","data_source":"metrics","name":"query2","query":"avg:aws.stream.globalaccelerator.processed_bytes_out{*} by {aws_account,acceleratoripaddress}"}],"response_format":"scalar","text_formats":[[{"match":{"type":"is","value":"fruit"},"palette":"white_on_red","replace":{"type":"all","with":"vegetable"}},{"custom_bg_color":"#c33c3c","match":{"type":"is","value":"animal"},"palette":"custom_bg"},{"match":{"type":"is","value":"robot"},"palette":"red_on_white"},{"match":{"type":"is","value":"ai"},"palette":"yellow_on_white"}],[{"match":{"type":"is_not","value":"xyz"},"palette":"white_on_yellow"}],[{"match":{"type":"contains","value":"test"},"palette":"white_on_green","replace":{"type":"all","with":"vegetable"}}],[{"match":{"type":"does_not_contain","value":"blah"},"palette":"black_on_light_red"}],[{"match":{"type":"starts_with","value":"abc"},"palette":"black_on_light_yellow"}],[{"match":{"type":"ends_with","value":"xyz"},"palette":"black_on_light_green"}]]}],"title":"","title_align":"left","title_size":"16","type":"query_table"},"layout":{"height":4,"width":4,"x":0,"y":0}}]} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + id: 0 + method: POST + url: https://api.datadoghq.com/api/v1/dashboard + response: + body: '{"id":"e5e-3v7-f8f","title":"Test-Create_a_new_dashboard_with_query_table_widget_and_text_formatting-1725664680","description":"","author_handle":"frog@datadoghq.com","author_name":null,"layout_type":"free","url":"/dashboard/e5e-3v7-f8f/test-createanewdashboardwithquerytablewidgetandtextformatting-1725664680","is_read_only":false,"template_variables":[],"widgets":[{"definition":{"has_search_bar":"never","requests":[{"formulas":[],"queries":[{"aggregator":"avg","data_source":"metrics","name":"query1","query":"avg:aws.stream.globalaccelerator.processed_bytes_in{*} + by {aws_account,acceleratoripaddress}"},{"aggregator":"avg","data_source":"metrics","name":"query2","query":"avg:aws.stream.globalaccelerator.processed_bytes_out{*} + by {aws_account,acceleratoripaddress}"}],"response_format":"scalar","text_formats":[[{"match":{"type":"is","value":"fruit"},"palette":"white_on_red","replace":{"type":"all","with":"vegetable"}},{"custom_bg_color":"#c33c3c","match":{"type":"is","value":"animal"},"palette":"custom_bg"},{"match":{"type":"is","value":"robot"},"palette":"red_on_white"},{"match":{"type":"is","value":"ai"},"palette":"yellow_on_white"}],[{"match":{"type":"is_not","value":"xyz"},"palette":"white_on_yellow"}],[{"match":{"type":"contains","value":"test"},"palette":"white_on_green","replace":{"type":"all","with":"vegetable"}}],[{"match":{"type":"does_not_contain","value":"blah"},"palette":"black_on_light_red"}],[{"match":{"type":"starts_with","value":"abc"},"palette":"black_on_light_yellow"}],[{"match":{"type":"ends_with","value":"xyz"},"palette":"black_on_light_green"}]]}],"title":"","title_align":"left","title_size":"16","type":"query_table"},"layout":{"height":4,"width":4,"x":0,"y":0},"id":3812902574450452}],"notify_list":[],"created_at":"2024-09-06T23:18:01.030313+00:00","modified_at":"2024-09-06T23:18:01.030313+00:00","restricted_roles":[]} + + ' + code: 200 + duration: 0ms + headers: + Content-Type: + - application/json + status: 200 OK +- request: + body: '' + form: {} + headers: + Accept: + - application/json + id: 1 + method: DELETE + url: https://api.datadoghq.com/api/v1/dashboard/e5e-3v7-f8f + response: + body: '{"deleted_dashboard_id":"e5e-3v7-f8f"} + + ' + code: 200 + duration: 0ms + headers: + Content-Type: + - application/json + status: 200 OK +version: 2 diff --git a/tests/scenarios/features/v1/dashboards.feature b/tests/scenarios/features/v1/dashboards.feature index 27f714940da..e46818a8e95 100644 --- a/tests/scenarios/features/v1/dashboards.feature +++ b/tests/scenarios/features/v1/dashboards.feature @@ -580,6 +580,21 @@ Feature: Dashboards And the response "widgets[0].definition.requests[0].sort.order_by[0].type" is equal to "formula" And the response "widgets[0].definition.requests[0].sort.order_by[0].index" is equal to 0 + @team:DataDog/dashboards-backend + Scenario: Create a new dashboard with query_table widget and text formatting + Given new "CreateDashboard" request + And body from file "dashboards_json_payload/query_table_widget_text_formatting.json" + When the request is sent + Then the response status is 200 OK + And the response "widgets[0].definition.type" is equal to "query_table" + And the response "widgets[0].definition.requests[0].text_formats[0][0].match.type" is equal to "is" + And the response "widgets[0].definition.requests[0].text_formats[0][0].match.value" is equal to "fruit" + And the response "widgets[0].definition.requests[0].text_formats[0][0].palette" is equal to "white_on_red" + And the response "widgets[0].definition.requests[0].text_formats[0][0].replace.type" is equal to "all" + And the response "widgets[0].definition.requests[0].text_formats[0][0].replace.with" is equal to "vegetable" + And the response "widgets[0].definition.requests[0].text_formats[0][1].palette" is equal to "custom_bg" + And the response "widgets[0].definition.requests[0].text_formats[0][1].custom_bg_color" is equal to "#c33c3c" + @team:DataDog/dashboards-backend Scenario: Create a new dashboard with query_value widget Given new "CreateDashboard" request diff --git a/tests/scenarios/features/v1/dashboards_json_payload/query_table_widget_text_formatting.json b/tests/scenarios/features/v1/dashboards_json_payload/query_table_widget_text_formatting.json new file mode 100644 index 00000000000..a4bdaba86bd --- /dev/null +++ b/tests/scenarios/features/v1/dashboards_json_payload/query_table_widget_text_formatting.json @@ -0,0 +1,132 @@ +{ + "title": "{{ unique }}", + "description": "", + "widgets": [ + { + "definition": { + "title": "", + "title_size": "16", + "title_align": "left", + "type": "query_table", + "requests": [ + { + "queries": [ + { + "aggregator": "avg", + "data_source": "metrics", + "name": "query1", + "query": "avg:aws.stream.globalaccelerator.processed_bytes_in{*} by {aws_account,acceleratoripaddress}" + }, + { + "aggregator": "avg", + "data_source": "metrics", + "name": "query2", + "query": "avg:aws.stream.globalaccelerator.processed_bytes_out{*} by {aws_account,acceleratoripaddress}" + } + ], + "response_format": "scalar", + "text_formats": [ + [ + { + "match": { + "type": "is", + "value": "fruit" + }, + "palette": "white_on_red", + "replace": { + "type": "all", + "with": "vegetable" + } + }, + { + "match": { + "type": "is", + "value": "animal" + }, + "palette": "custom_bg", + "custom_bg_color": "#c33c3c" + }, + { + "match": { + "type": "is", + "value": "robot" + }, + "palette": "red_on_white" + }, + { + "match": { + "type": "is", + "value": "ai" + }, + "palette": "yellow_on_white" + } + ], + [ + { + "match": { + "type": "is_not", + "value": "xyz" + }, + "palette": "white_on_yellow" + } + ], + [ + { + "match": { + "type": "contains", + "value": "test" + }, + "palette": "white_on_green", + "replace": { + "type": "all", + "with": "vegetable" + } + } + ], + [ + { + "match": { + "type": "does_not_contain", + "value": "blah" + }, + "palette": "black_on_light_red" + } + ], + [ + { + "match": { + "type": "starts_with", + "value": "abc" + }, + "palette": "black_on_light_yellow" + } + ], + [ + { + "match": { + "type": "ends_with", + "value": "xyz" + }, + "palette": "black_on_light_green" + } + ] + ], + "formulas": [ + ] + } + ], + "has_search_bar": "never" + }, + "layout": { + "x": 0, + "y": 0, + "width": 4, + "height": 4 + } + } + ], + "template_variables": [], + "layout_type": "free", + "is_read_only": false, + "notify_list": [] +}