|
| 1 | +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. |
| 2 | +// This product includes software developed at Datadog (https://www.datadoghq.com/). |
| 3 | +// Copyright 2019-Present Datadog, Inc. |
| 4 | + |
| 5 | +package datadogV2 |
| 6 | + |
| 7 | +import ( |
| 8 | + "fmt" |
| 9 | + |
| 10 | + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" |
| 11 | +) |
| 12 | + |
| 13 | +// CreateOrUpdateWidgetRequestAttributes Attributes for creating or updating a widget. |
| 14 | +type CreateOrUpdateWidgetRequestAttributes struct { |
| 15 | + // The definition of a widget, including its type and configuration. |
| 16 | + Definition WidgetDefinition `json:"definition"` |
| 17 | + // User-defined tags for organizing the widget. |
| 18 | + Tags datadog.NullableList[string] `json:"tags,omitempty"` |
| 19 | + // UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct |
| 20 | + UnparsedObject map[string]interface{} `json:"-"` |
| 21 | + AdditionalProperties map[string]interface{} `json:"-"` |
| 22 | +} |
| 23 | + |
| 24 | +// NewCreateOrUpdateWidgetRequestAttributes instantiates a new CreateOrUpdateWidgetRequestAttributes object. |
| 25 | +// This constructor will assign default values to properties that have it defined, |
| 26 | +// and makes sure properties required by API are set, but the set of arguments |
| 27 | +// will change when the set of required properties is changed. |
| 28 | +func NewCreateOrUpdateWidgetRequestAttributes(definition WidgetDefinition) *CreateOrUpdateWidgetRequestAttributes { |
| 29 | + this := CreateOrUpdateWidgetRequestAttributes{} |
| 30 | + this.Definition = definition |
| 31 | + return &this |
| 32 | +} |
| 33 | + |
| 34 | +// NewCreateOrUpdateWidgetRequestAttributesWithDefaults instantiates a new CreateOrUpdateWidgetRequestAttributes object. |
| 35 | +// This constructor will only assign default values to properties that have it defined, |
| 36 | +// but it doesn't guarantee that properties required by API are set. |
| 37 | +func NewCreateOrUpdateWidgetRequestAttributesWithDefaults() *CreateOrUpdateWidgetRequestAttributes { |
| 38 | + this := CreateOrUpdateWidgetRequestAttributes{} |
| 39 | + return &this |
| 40 | +} |
| 41 | + |
| 42 | +// GetDefinition returns the Definition field value. |
| 43 | +func (o *CreateOrUpdateWidgetRequestAttributes) GetDefinition() WidgetDefinition { |
| 44 | + if o == nil { |
| 45 | + var ret WidgetDefinition |
| 46 | + return ret |
| 47 | + } |
| 48 | + return o.Definition |
| 49 | +} |
| 50 | + |
| 51 | +// GetDefinitionOk returns a tuple with the Definition field value |
| 52 | +// and a boolean to check if the value has been set. |
| 53 | +func (o *CreateOrUpdateWidgetRequestAttributes) GetDefinitionOk() (*WidgetDefinition, bool) { |
| 54 | + if o == nil { |
| 55 | + return nil, false |
| 56 | + } |
| 57 | + return &o.Definition, true |
| 58 | +} |
| 59 | + |
| 60 | +// SetDefinition sets field value. |
| 61 | +func (o *CreateOrUpdateWidgetRequestAttributes) SetDefinition(v WidgetDefinition) { |
| 62 | + o.Definition = v |
| 63 | +} |
| 64 | + |
| 65 | +// GetTags returns the Tags field value if set, zero value otherwise (both if not set or set to explicit null). |
| 66 | +func (o *CreateOrUpdateWidgetRequestAttributes) GetTags() []string { |
| 67 | + if o == nil || o.Tags.Get() == nil { |
| 68 | + var ret []string |
| 69 | + return ret |
| 70 | + } |
| 71 | + return *o.Tags.Get() |
| 72 | +} |
| 73 | + |
| 74 | +// GetTagsOk returns a tuple with the Tags field value if set, nil otherwise |
| 75 | +// and a boolean to check if the value has been set. |
| 76 | +// NOTE: If the value is an explicit nil, `nil, true` will be returned. |
| 77 | +func (o *CreateOrUpdateWidgetRequestAttributes) GetTagsOk() (*[]string, bool) { |
| 78 | + if o == nil { |
| 79 | + return nil, false |
| 80 | + } |
| 81 | + return o.Tags.Get(), o.Tags.IsSet() |
| 82 | +} |
| 83 | + |
| 84 | +// HasTags returns a boolean if a field has been set. |
| 85 | +func (o *CreateOrUpdateWidgetRequestAttributes) HasTags() bool { |
| 86 | + return o != nil && o.Tags.IsSet() |
| 87 | +} |
| 88 | + |
| 89 | +// SetTags gets a reference to the given datadog.NullableList[string] and assigns it to the Tags field. |
| 90 | +func (o *CreateOrUpdateWidgetRequestAttributes) SetTags(v []string) { |
| 91 | + o.Tags.Set(&v) |
| 92 | +} |
| 93 | + |
| 94 | +// SetTagsNil sets the value for Tags to be an explicit nil. |
| 95 | +func (o *CreateOrUpdateWidgetRequestAttributes) SetTagsNil() { |
| 96 | + o.Tags.Set(nil) |
| 97 | +} |
| 98 | + |
| 99 | +// UnsetTags ensures that no value is present for Tags, not even an explicit nil. |
| 100 | +func (o *CreateOrUpdateWidgetRequestAttributes) UnsetTags() { |
| 101 | + o.Tags.Unset() |
| 102 | +} |
| 103 | + |
| 104 | +// MarshalJSON serializes the struct using spec logic. |
| 105 | +func (o CreateOrUpdateWidgetRequestAttributes) MarshalJSON() ([]byte, error) { |
| 106 | + toSerialize := map[string]interface{}{} |
| 107 | + if o.UnparsedObject != nil { |
| 108 | + return datadog.Marshal(o.UnparsedObject) |
| 109 | + } |
| 110 | + toSerialize["definition"] = o.Definition |
| 111 | + if o.Tags.IsSet() { |
| 112 | + toSerialize["tags"] = o.Tags.Get() |
| 113 | + } |
| 114 | + |
| 115 | + for key, value := range o.AdditionalProperties { |
| 116 | + toSerialize[key] = value |
| 117 | + } |
| 118 | + return datadog.Marshal(toSerialize) |
| 119 | +} |
| 120 | + |
| 121 | +// UnmarshalJSON deserializes the given payload. |
| 122 | +func (o *CreateOrUpdateWidgetRequestAttributes) UnmarshalJSON(bytes []byte) (err error) { |
| 123 | + all := struct { |
| 124 | + Definition *WidgetDefinition `json:"definition"` |
| 125 | + Tags datadog.NullableList[string] `json:"tags,omitempty"` |
| 126 | + }{} |
| 127 | + if err = datadog.Unmarshal(bytes, &all); err != nil { |
| 128 | + return datadog.Unmarshal(bytes, &o.UnparsedObject) |
| 129 | + } |
| 130 | + if all.Definition == nil { |
| 131 | + return fmt.Errorf("required field definition missing") |
| 132 | + } |
| 133 | + additionalProperties := make(map[string]interface{}) |
| 134 | + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { |
| 135 | + datadog.DeleteKeys(additionalProperties, &[]string{"definition", "tags"}) |
| 136 | + } else { |
| 137 | + return err |
| 138 | + } |
| 139 | + |
| 140 | + hasInvalidField := false |
| 141 | + if all.Definition.UnparsedObject != nil && o.UnparsedObject == nil { |
| 142 | + hasInvalidField = true |
| 143 | + } |
| 144 | + o.Definition = *all.Definition |
| 145 | + o.Tags = all.Tags |
| 146 | + |
| 147 | + if len(additionalProperties) > 0 { |
| 148 | + o.AdditionalProperties = additionalProperties |
| 149 | + } |
| 150 | + |
| 151 | + if hasInvalidField { |
| 152 | + return datadog.Unmarshal(bytes, &o.UnparsedObject) |
| 153 | + } |
| 154 | + |
| 155 | + return nil |
| 156 | +} |
0 commit comments