Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19700,11 +19700,12 @@ components:
- id
type: object
DeploymentRulesOptions:
description: Options for deployment rule response representing either faulty
deployment detection or monitor options.
oneOf:
anyOf:
- $ref: '#/components/schemas/DeploymentRuleOptionsFaultyDeploymentDetection'
- $ref: '#/components/schemas/DeploymentRuleOptionsMonitor'
description: Options for deployment rule response representing either faulty
deployment detection or monitor options. The actual type is determined by
the parent's 'type' field.
DetachCaseRequest:
description: Request for detaching security findings from their case.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type CreateDeploymentRuleParamsDataAttributes struct {
DryRun *bool `json:"dry_run,omitempty"`
// The name of the deployment rule.
Name string `json:"name"`
// Options for deployment rule response representing either faulty deployment detection or monitor options.
// Options for deployment rule response representing either faulty deployment detection or monitor options. The actual type is determined by the parent's 'type' field.
Options DeploymentRulesOptions `json:"options"`
// The type of the deployment rule (faulty_deployment_detection or monitor).
Type string `json:"type"`
Expand Down Expand Up @@ -191,14 +191,23 @@ func (o *CreateDeploymentRuleParamsDataAttributes) UnmarshalJSON(bytes []byte) (
} else {
return err
}

hasInvalidField := false
o.DryRun = all.DryRun
o.Name = *all.Name
if all.Options.UnparsedObject != nil && o.UnparsedObject == nil {
hasInvalidField = true
}
o.Options = *all.Options
o.Type = *all.Type

if len(additionalProperties) > 0 {
o.AdditionalProperties = additionalProperties
}

if hasInvalidField {
return datadog.Unmarshal(bytes, &o.UnparsedObject)
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type DeploymentRuleResponseDataAttributes struct {
GateId string `json:"gate_id"`
// The name of the deployment rule.
Name string `json:"name"`
// Options for deployment rule response representing either faulty deployment detection or monitor options.
// Options for deployment rule response representing either faulty deployment detection or monitor options. The actual type is determined by the parent's 'type' field.
Options DeploymentRulesOptions `json:"options"`
// The type of the deployment rule.
Type DeploymentRuleResponseDataAttributesType `json:"type"`
Expand Down Expand Up @@ -364,6 +364,9 @@ func (o *DeploymentRuleResponseDataAttributes) UnmarshalJSON(bytes []byte) (err
o.DryRun = *all.DryRun
o.GateId = *all.GateId
o.Name = *all.Name
if all.Options.UnparsedObject != nil && o.UnparsedObject == nil {
hasInvalidField = true
}
o.Options = *all.Options
if !all.Type.IsValid() {
hasInvalidField = true
Expand Down
112 changes: 37 additions & 75 deletions api/datadogV2/model_deployment_rules_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,98 +8,60 @@ import (
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
)

// DeploymentRulesOptions - Options for deployment rule response representing either faulty deployment detection or monitor options.
// DeploymentRulesOptions Options for deployment rule response representing either faulty deployment detection or monitor options. The actual type is determined by the parent's 'type' field.
type DeploymentRulesOptions struct {
DeploymentRuleOptionsFaultyDeploymentDetection *DeploymentRuleOptionsFaultyDeploymentDetection
DeploymentRuleOptionsMonitor *DeploymentRuleOptionsMonitor

// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
UnparsedObject interface{}
UnparsedObject map[string]interface{} `json:"-"`
AdditionalProperties map[string]interface{} `json:"-"`
}

// DeploymentRuleOptionsFaultyDeploymentDetectionAsDeploymentRulesOptions is a convenience function that returns DeploymentRuleOptionsFaultyDeploymentDetection wrapped in DeploymentRulesOptions.
func DeploymentRuleOptionsFaultyDeploymentDetectionAsDeploymentRulesOptions(v *DeploymentRuleOptionsFaultyDeploymentDetection) DeploymentRulesOptions {
return DeploymentRulesOptions{DeploymentRuleOptionsFaultyDeploymentDetection: v}
// NewDeploymentRulesOptions instantiates a new DeploymentRulesOptions 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 NewDeploymentRulesOptions() *DeploymentRulesOptions {
this := DeploymentRulesOptions{}
return &this
}

// DeploymentRuleOptionsMonitorAsDeploymentRulesOptions is a convenience function that returns DeploymentRuleOptionsMonitor wrapped in DeploymentRulesOptions.
func DeploymentRuleOptionsMonitorAsDeploymentRulesOptions(v *DeploymentRuleOptionsMonitor) DeploymentRulesOptions {
return DeploymentRulesOptions{DeploymentRuleOptionsMonitor: v}
// NewDeploymentRulesOptionsWithDefaults instantiates a new DeploymentRulesOptions 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 NewDeploymentRulesOptionsWithDefaults() *DeploymentRulesOptions {
this := DeploymentRulesOptions{}
return &this
}

// UnmarshalJSON turns data into one of the pointers in the struct.
func (obj *DeploymentRulesOptions) UnmarshalJSON(data []byte) error {
var err error
match := 0
// try to unmarshal data into DeploymentRuleOptionsFaultyDeploymentDetection
err = datadog.Unmarshal(data, &obj.DeploymentRuleOptionsFaultyDeploymentDetection)
if err == nil {
if obj.DeploymentRuleOptionsFaultyDeploymentDetection != nil && obj.DeploymentRuleOptionsFaultyDeploymentDetection.UnparsedObject == nil {
jsonDeploymentRuleOptionsFaultyDeploymentDetection, _ := datadog.Marshal(obj.DeploymentRuleOptionsFaultyDeploymentDetection)
if string(jsonDeploymentRuleOptionsFaultyDeploymentDetection) == "{}" && string(data) != "{}" { // empty struct
obj.DeploymentRuleOptionsFaultyDeploymentDetection = nil
} else {
match++
}
} else {
obj.DeploymentRuleOptionsFaultyDeploymentDetection = nil
}
} else {
obj.DeploymentRuleOptionsFaultyDeploymentDetection = nil
}

// try to unmarshal data into DeploymentRuleOptionsMonitor
err = datadog.Unmarshal(data, &obj.DeploymentRuleOptionsMonitor)
if err == nil {
if obj.DeploymentRuleOptionsMonitor != nil && obj.DeploymentRuleOptionsMonitor.UnparsedObject == nil {
jsonDeploymentRuleOptionsMonitor, _ := datadog.Marshal(obj.DeploymentRuleOptionsMonitor)
if string(jsonDeploymentRuleOptionsMonitor) == "{}" { // empty struct
obj.DeploymentRuleOptionsMonitor = nil
} else {
match++
}
} else {
obj.DeploymentRuleOptionsMonitor = nil
}
} else {
obj.DeploymentRuleOptionsMonitor = nil
// MarshalJSON serializes the struct using spec logic.
func (o DeploymentRulesOptions) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.UnparsedObject != nil {
return datadog.Marshal(o.UnparsedObject)
}

if match != 1 { // more than 1 match
// reset to nil
obj.DeploymentRuleOptionsFaultyDeploymentDetection = nil
obj.DeploymentRuleOptionsMonitor = nil
return datadog.Unmarshal(data, &obj.UnparsedObject)
for key, value := range o.AdditionalProperties {
toSerialize[key] = value
}
return nil // exactly one match
return datadog.Marshal(toSerialize)
}

// MarshalJSON turns data from the first non-nil pointers in the struct to JSON.
func (obj DeploymentRulesOptions) MarshalJSON() ([]byte, error) {
if obj.DeploymentRuleOptionsFaultyDeploymentDetection != nil {
return datadog.Marshal(&obj.DeploymentRuleOptionsFaultyDeploymentDetection)
}

if obj.DeploymentRuleOptionsMonitor != nil {
return datadog.Marshal(&obj.DeploymentRuleOptionsMonitor)
}

if obj.UnparsedObject != nil {
return datadog.Marshal(obj.UnparsedObject)
// UnmarshalJSON deserializes the given payload.
func (o *DeploymentRulesOptions) UnmarshalJSON(bytes []byte) (err error) {
all := struct {
}{}
if err = datadog.Unmarshal(bytes, &all); err != nil {
return datadog.Unmarshal(bytes, &o.UnparsedObject)
}
return nil, nil // no data in oneOf schemas
}

// GetActualInstance returns the actual instance.
func (obj *DeploymentRulesOptions) GetActualInstance() interface{} {
if obj.DeploymentRuleOptionsFaultyDeploymentDetection != nil {
return obj.DeploymentRuleOptionsFaultyDeploymentDetection
additionalProperties := make(map[string]interface{})
if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil {
datadog.DeleteKeys(additionalProperties, &[]string{})
} else {
return err
}

if obj.DeploymentRuleOptionsMonitor != nil {
return obj.DeploymentRuleOptionsMonitor
if len(additionalProperties) > 0 {
o.AdditionalProperties = additionalProperties
}

// all schemas are nil
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type UpdateDeploymentRuleParamsDataAttributes struct {
DryRun bool `json:"dry_run"`
// The name of the deployment rule.
Name string `json:"name"`
// Options for deployment rule response representing either faulty deployment detection or monitor options.
// Options for deployment rule response representing either faulty deployment detection or monitor options. The actual type is determined by the parent's 'type' field.
Options DeploymentRulesOptions `json:"options"`
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
UnparsedObject map[string]interface{} `json:"-"`
Expand Down Expand Up @@ -153,13 +153,22 @@ func (o *UpdateDeploymentRuleParamsDataAttributes) UnmarshalJSON(bytes []byte) (
} else {
return err
}

hasInvalidField := false
o.DryRun = *all.DryRun
o.Name = *all.Name
if all.Options.UnparsedObject != nil && o.UnparsedObject == nil {
hasInvalidField = true
}
o.Options = *all.Options

if len(additionalProperties) > 0 {
o.AdditionalProperties = additionalProperties
}

if hasInvalidField {
return datadog.Unmarshal(bytes, &o.UnparsedObject)
}

return nil
}
11 changes: 4 additions & 7 deletions examples/v2/deployment-gates/CreateDeploymentRule.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ func main() {
body := datadogV2.CreateDeploymentRuleParams{
Data: &datadogV2.CreateDeploymentRuleParamsData{
Attributes: datadogV2.CreateDeploymentRuleParamsDataAttributes{
DryRun: datadog.PtrBool(false),
Name: "My deployment rule",
Options: datadogV2.DeploymentRulesOptions{
DeploymentRuleOptionsFaultyDeploymentDetection: &datadogV2.DeploymentRuleOptionsFaultyDeploymentDetection{
ExcludedResources: []string{},
}},
Type: "faulty_deployment_detection",
DryRun: datadog.PtrBool(false),
Name: "My deployment rule",
Options: datadogV2.DeploymentRulesOptions{},
Type: "faulty_deployment_detection",
},
Type: datadogV2.DEPLOYMENTRULEDATATYPE_DEPLOYMENT_RULE,
},
Expand Down
9 changes: 3 additions & 6 deletions examples/v2/deployment-gates/UpdateDeploymentRule.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ func main() {
body := datadogV2.UpdateDeploymentRuleParams{
Data: datadogV2.UpdateDeploymentRuleParamsData{
Attributes: datadogV2.UpdateDeploymentRuleParamsDataAttributes{
DryRun: false,
Name: "Updated deployment rule",
Options: datadogV2.DeploymentRulesOptions{
DeploymentRuleOptionsFaultyDeploymentDetection: &datadogV2.DeploymentRuleOptionsFaultyDeploymentDetection{
ExcludedResources: []string{},
}},
DryRun: false,
Name: "Updated deployment rule",
Options: datadogV2.DeploymentRulesOptions{},
},
Type: datadogV2.DEPLOYMENTRULEDATATYPE_DEPLOYMENT_RULE,
},
Expand Down
6 changes: 3 additions & 3 deletions tests/scenarios/features/v2/deployment_gates.feature
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Feature: Deployment Gates
Given operation "CreateDeploymentRule" enabled
And new "CreateDeploymentRule" request
And request contains "gate_id" parameter from "REPLACE.ME"
And body with value {"data": {"attributes": {"dry_run": false, "name": "My deployment rule", "options": {"duration": 3600, "excluded_resources": ["resource1", "resource2"]}, "type": "faulty_deployment_detection"}, "type": "deployment_rule"}}
And body with value {"data": {"attributes": {"dry_run": false, "name": "My deployment rule", "type": "faulty_deployment_detection"}, "type": "deployment_rule"}}
When the request is sent
Then the response status is 400 Bad request.

Expand Down Expand Up @@ -279,7 +279,7 @@ Feature: Deployment Gates
And new "UpdateDeploymentRule" request
And request contains "gate_id" parameter from "REPLACE.ME"
And request contains "id" parameter from "REPLACE.ME"
And body with value {"data": {"attributes": {"dry_run": false, "name": "Updated deployment rule", "options": {"duration": 3600, "excluded_resources": ["resource1", "resource2"]}}, "type": "deployment_rule"}}
And body with value {"data": {"attributes": {"dry_run": false, "name": "Updated deployment rule"}, "type": "deployment_rule"}}
When the request is sent
Then the response status is 400 Bad request.

Expand All @@ -289,7 +289,7 @@ Feature: Deployment Gates
And new "UpdateDeploymentRule" request
And request contains "gate_id" parameter from "REPLACE.ME"
And request contains "id" parameter from "REPLACE.ME"
And body with value {"data": {"attributes": {"dry_run": false, "name": "Updated deployment rule", "options": {"duration": 3600, "excluded_resources": ["resource1", "resource2"]}}, "type": "deployment_rule"}}
And body with value {"data": {"attributes": {"dry_run": false, "name": "Updated deployment rule"}, "type": "deployment_rule"}}
When the request is sent
Then the response status is 404 Deployment rule not found.

Expand Down