Skip to content

Commit 8ffdb8c

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add subtest for synthetics multistep tests (#3555)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 58a8639 commit 8ffdb8c

9 files changed

Lines changed: 798 additions & 2 deletions

.generator/schemas/v1/openapi.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14766,6 +14766,61 @@ components:
1476614766
oneOf:
1476714767
- $ref: '#/components/schemas/SyntheticsAPITestStep'
1476814768
- $ref: '#/components/schemas/SyntheticsAPIWaitStep'
14769+
- $ref: '#/components/schemas/SyntheticsAPISubtestStep'
14770+
SyntheticsAPISubtestStep:
14771+
description: The subtest step used in a Synthetics multi-step API test.
14772+
properties:
14773+
allowFailure:
14774+
description: Determines whether or not to continue with test if this step
14775+
fails.
14776+
type: boolean
14777+
alwaysExecute:
14778+
description: A boolean set to always execute this step even if the previous
14779+
step failed or was skipped.
14780+
type: boolean
14781+
exitIfSucceed:
14782+
description: Determines whether or not to exit the test if the step succeeds.
14783+
type: boolean
14784+
extractedValuesFromScript:
14785+
description: Generate variables using JavaScript.
14786+
type: string
14787+
id:
14788+
description: ID of the step.
14789+
example: abc-def-123
14790+
readOnly: true
14791+
type: string
14792+
isCritical:
14793+
description: 'Determines whether or not to consider the entire test as failed
14794+
if this step fails.
14795+
14796+
Can be used only if `allowFailure` is `true`.'
14797+
type: boolean
14798+
name:
14799+
description: The name of the step.
14800+
example: Example step name
14801+
type: string
14802+
retry:
14803+
$ref: '#/components/schemas/SyntheticsTestOptionsRetry'
14804+
subtestPublicId:
14805+
description: Public ID of the test to be played as part of a `playSubTest`
14806+
step type.
14807+
example: ''
14808+
type: string
14809+
subtype:
14810+
$ref: '#/components/schemas/SyntheticsAPISubtestStepSubtype'
14811+
required:
14812+
- name
14813+
- subtype
14814+
- subtestPublicId
14815+
type: object
14816+
SyntheticsAPISubtestStepSubtype:
14817+
description: The subtype of the Synthetic multi-step API subtest step.
14818+
enum:
14819+
- playSubTest
14820+
example: playSubTest
14821+
type: string
14822+
x-enum-varnames:
14823+
- PLAY_SUB_TEST
1476914824
SyntheticsAPITest:
1477014825
description: Object containing details about a Synthetic API test.
1477114826
properties:

api/datadogV1/model_synthetics_api_step.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import (
1010

1111
// SyntheticsAPIStep - The steps used in a Synthetic multi-step API test.
1212
type SyntheticsAPIStep struct {
13-
SyntheticsAPITestStep *SyntheticsAPITestStep
14-
SyntheticsAPIWaitStep *SyntheticsAPIWaitStep
13+
SyntheticsAPITestStep *SyntheticsAPITestStep
14+
SyntheticsAPIWaitStep *SyntheticsAPIWaitStep
15+
SyntheticsAPISubtestStep *SyntheticsAPISubtestStep
1516

1617
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
1718
UnparsedObject interface{}
@@ -27,6 +28,11 @@ func SyntheticsAPIWaitStepAsSyntheticsAPIStep(v *SyntheticsAPIWaitStep) Syntheti
2728
return SyntheticsAPIStep{SyntheticsAPIWaitStep: v}
2829
}
2930

31+
// SyntheticsAPISubtestStepAsSyntheticsAPIStep is a convenience function that returns SyntheticsAPISubtestStep wrapped in SyntheticsAPIStep.
32+
func SyntheticsAPISubtestStepAsSyntheticsAPIStep(v *SyntheticsAPISubtestStep) SyntheticsAPIStep {
33+
return SyntheticsAPIStep{SyntheticsAPISubtestStep: v}
34+
}
35+
3036
// UnmarshalJSON turns data into one of the pointers in the struct.
3137
func (obj *SyntheticsAPIStep) UnmarshalJSON(data []byte) error {
3238
var err error
@@ -65,10 +71,28 @@ func (obj *SyntheticsAPIStep) UnmarshalJSON(data []byte) error {
6571
obj.SyntheticsAPIWaitStep = nil
6672
}
6773

74+
// try to unmarshal data into SyntheticsAPISubtestStep
75+
err = datadog.Unmarshal(data, &obj.SyntheticsAPISubtestStep)
76+
if err == nil {
77+
if obj.SyntheticsAPISubtestStep != nil && obj.SyntheticsAPISubtestStep.UnparsedObject == nil {
78+
jsonSyntheticsAPISubtestStep, _ := datadog.Marshal(obj.SyntheticsAPISubtestStep)
79+
if string(jsonSyntheticsAPISubtestStep) == "{}" { // empty struct
80+
obj.SyntheticsAPISubtestStep = nil
81+
} else {
82+
match++
83+
}
84+
} else {
85+
obj.SyntheticsAPISubtestStep = nil
86+
}
87+
} else {
88+
obj.SyntheticsAPISubtestStep = nil
89+
}
90+
6891
if match != 1 { // more than 1 match
6992
// reset to nil
7093
obj.SyntheticsAPITestStep = nil
7194
obj.SyntheticsAPIWaitStep = nil
95+
obj.SyntheticsAPISubtestStep = nil
7296
return datadog.Unmarshal(data, &obj.UnparsedObject)
7397
}
7498
return nil // exactly one match
@@ -84,6 +108,10 @@ func (obj SyntheticsAPIStep) MarshalJSON() ([]byte, error) {
84108
return datadog.Marshal(&obj.SyntheticsAPIWaitStep)
85109
}
86110

111+
if obj.SyntheticsAPISubtestStep != nil {
112+
return datadog.Marshal(&obj.SyntheticsAPISubtestStep)
113+
}
114+
87115
if obj.UnparsedObject != nil {
88116
return datadog.Marshal(obj.UnparsedObject)
89117
}
@@ -100,6 +128,10 @@ func (obj *SyntheticsAPIStep) GetActualInstance() interface{} {
100128
return obj.SyntheticsAPIWaitStep
101129
}
102130

131+
if obj.SyntheticsAPISubtestStep != nil {
132+
return obj.SyntheticsAPISubtestStep
133+
}
134+
103135
// all schemas are nil
104136
return nil
105137
}

0 commit comments

Comments
 (0)