|
| 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 | +// CreateMaintenanceRequestData |
| 14 | +type CreateMaintenanceRequestData struct { |
| 15 | + // The supported attributes for creating a maintenance. |
| 16 | + Attributes CreateMaintenanceRequestDataAttributes `json:"attributes"` |
| 17 | + // Maintenances resource type. |
| 18 | + Type PatchMaintenanceRequestDataType `json:"type"` |
| 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 | +// NewCreateMaintenanceRequestData instantiates a new CreateMaintenanceRequestData 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 NewCreateMaintenanceRequestData(attributes CreateMaintenanceRequestDataAttributes, typeVar PatchMaintenanceRequestDataType) *CreateMaintenanceRequestData { |
| 29 | + this := CreateMaintenanceRequestData{} |
| 30 | + this.Attributes = attributes |
| 31 | + this.Type = typeVar |
| 32 | + return &this |
| 33 | +} |
| 34 | + |
| 35 | +// NewCreateMaintenanceRequestDataWithDefaults instantiates a new CreateMaintenanceRequestData object. |
| 36 | +// This constructor will only assign default values to properties that have it defined, |
| 37 | +// but it doesn't guarantee that properties required by API are set. |
| 38 | +func NewCreateMaintenanceRequestDataWithDefaults() *CreateMaintenanceRequestData { |
| 39 | + this := CreateMaintenanceRequestData{} |
| 40 | + var typeVar PatchMaintenanceRequestDataType = PATCHMAINTENANCEREQUESTDATATYPE_MAINTENANCES |
| 41 | + this.Type = typeVar |
| 42 | + return &this |
| 43 | +} |
| 44 | + |
| 45 | +// GetAttributes returns the Attributes field value. |
| 46 | +func (o *CreateMaintenanceRequestData) GetAttributes() CreateMaintenanceRequestDataAttributes { |
| 47 | + if o == nil { |
| 48 | + var ret CreateMaintenanceRequestDataAttributes |
| 49 | + return ret |
| 50 | + } |
| 51 | + return o.Attributes |
| 52 | +} |
| 53 | + |
| 54 | +// GetAttributesOk returns a tuple with the Attributes field value |
| 55 | +// and a boolean to check if the value has been set. |
| 56 | +func (o *CreateMaintenanceRequestData) GetAttributesOk() (*CreateMaintenanceRequestDataAttributes, bool) { |
| 57 | + if o == nil { |
| 58 | + return nil, false |
| 59 | + } |
| 60 | + return &o.Attributes, true |
| 61 | +} |
| 62 | + |
| 63 | +// SetAttributes sets field value. |
| 64 | +func (o *CreateMaintenanceRequestData) SetAttributes(v CreateMaintenanceRequestDataAttributes) { |
| 65 | + o.Attributes = v |
| 66 | +} |
| 67 | + |
| 68 | +// GetType returns the Type field value. |
| 69 | +func (o *CreateMaintenanceRequestData) GetType() PatchMaintenanceRequestDataType { |
| 70 | + if o == nil { |
| 71 | + var ret PatchMaintenanceRequestDataType |
| 72 | + return ret |
| 73 | + } |
| 74 | + return o.Type |
| 75 | +} |
| 76 | + |
| 77 | +// GetTypeOk returns a tuple with the Type field value |
| 78 | +// and a boolean to check if the value has been set. |
| 79 | +func (o *CreateMaintenanceRequestData) GetTypeOk() (*PatchMaintenanceRequestDataType, bool) { |
| 80 | + if o == nil { |
| 81 | + return nil, false |
| 82 | + } |
| 83 | + return &o.Type, true |
| 84 | +} |
| 85 | + |
| 86 | +// SetType sets field value. |
| 87 | +func (o *CreateMaintenanceRequestData) SetType(v PatchMaintenanceRequestDataType) { |
| 88 | + o.Type = v |
| 89 | +} |
| 90 | + |
| 91 | +// MarshalJSON serializes the struct using spec logic. |
| 92 | +func (o CreateMaintenanceRequestData) MarshalJSON() ([]byte, error) { |
| 93 | + toSerialize := map[string]interface{}{} |
| 94 | + if o.UnparsedObject != nil { |
| 95 | + return datadog.Marshal(o.UnparsedObject) |
| 96 | + } |
| 97 | + toSerialize["attributes"] = o.Attributes |
| 98 | + toSerialize["type"] = o.Type |
| 99 | + |
| 100 | + for key, value := range o.AdditionalProperties { |
| 101 | + toSerialize[key] = value |
| 102 | + } |
| 103 | + return datadog.Marshal(toSerialize) |
| 104 | +} |
| 105 | + |
| 106 | +// UnmarshalJSON deserializes the given payload. |
| 107 | +func (o *CreateMaintenanceRequestData) UnmarshalJSON(bytes []byte) (err error) { |
| 108 | + all := struct { |
| 109 | + Attributes *CreateMaintenanceRequestDataAttributes `json:"attributes"` |
| 110 | + Type *PatchMaintenanceRequestDataType `json:"type"` |
| 111 | + }{} |
| 112 | + if err = datadog.Unmarshal(bytes, &all); err != nil { |
| 113 | + return datadog.Unmarshal(bytes, &o.UnparsedObject) |
| 114 | + } |
| 115 | + if all.Attributes == nil { |
| 116 | + return fmt.Errorf("required field attributes missing") |
| 117 | + } |
| 118 | + if all.Type == nil { |
| 119 | + return fmt.Errorf("required field type missing") |
| 120 | + } |
| 121 | + additionalProperties := make(map[string]interface{}) |
| 122 | + if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil { |
| 123 | + datadog.DeleteKeys(additionalProperties, &[]string{"attributes", "type"}) |
| 124 | + } else { |
| 125 | + return err |
| 126 | + } |
| 127 | + |
| 128 | + hasInvalidField := false |
| 129 | + if all.Attributes.UnparsedObject != nil && o.UnparsedObject == nil { |
| 130 | + hasInvalidField = true |
| 131 | + } |
| 132 | + o.Attributes = *all.Attributes |
| 133 | + if !all.Type.IsValid() { |
| 134 | + hasInvalidField = true |
| 135 | + } else { |
| 136 | + o.Type = *all.Type |
| 137 | + } |
| 138 | + |
| 139 | + if len(additionalProperties) > 0 { |
| 140 | + o.AdditionalProperties = additionalProperties |
| 141 | + } |
| 142 | + |
| 143 | + if hasInvalidField { |
| 144 | + return datadog.Unmarshal(bytes, &o.UnparsedObject) |
| 145 | + } |
| 146 | + |
| 147 | + return nil |
| 148 | +} |
0 commit comments