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
55 changes: 55 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14597,6 +14597,61 @@ components:
oneOf:
- $ref: '#/components/schemas/SyntheticsAPITestStep'
- $ref: '#/components/schemas/SyntheticsAPIWaitStep'
- $ref: '#/components/schemas/SyntheticsAPISubtestStep'
SyntheticsAPISubtestStep:
description: The subtest step used in a Synthetics multi-step API test.
properties:
allowFailure:
description: Determines whether or not to continue with test if this step
fails.
type: boolean
alwaysExecute:
description: A boolean set to always execute this step even if the previous
step failed or was skipped.
type: boolean
exitIfSucceed:
description: Determines whether or not to exit the test if the step succeeds.
type: boolean
extractedValuesFromScript:
description: Generate variables using JavaScript.
type: string
id:
description: ID of the step.
example: abc-def-123
readOnly: true
type: string
isCritical:
description: 'Determines whether or not to consider the entire test as failed
if this step fails.

Can be used only if `allowFailure` is `true`.'
type: boolean
name:
description: The name of the step.
example: Example step name
type: string
retry:
$ref: '#/components/schemas/SyntheticsTestOptionsRetry'
subtestPublicId:
description: Public ID of the test to be played as part of a `playSubTest`
step type.
example: ''
type: string
subtype:
$ref: '#/components/schemas/SyntheticsAPISubtestStepSubtype'
required:
- name
- subtype
- subtestPublicId
type: object
SyntheticsAPISubtestStepSubtype:
description: The subtype of the Synthetic multi-step API subtest step.
enum:
- playSubTest
example: playSubTest
type: string
x-enum-varnames:
- PLAY_SUB_TEST
SyntheticsAPITest:
description: Object containing details about a Synthetic API test.
properties:
Expand Down
86 changes: 86 additions & 0 deletions examples/v1/synthetics/CreateSyntheticsAPITest_2106135939.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Create a multistep test with subtest returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v1.api.SyntheticsApi;
import com.datadog.api.client.v1.model.SyntheticsAPIStep;
import com.datadog.api.client.v1.model.SyntheticsAPISubtestStep;
import com.datadog.api.client.v1.model.SyntheticsAPISubtestStepSubtype;
import com.datadog.api.client.v1.model.SyntheticsAPITest;
import com.datadog.api.client.v1.model.SyntheticsAPITestConfig;
import com.datadog.api.client.v1.model.SyntheticsAPITestStep;
import com.datadog.api.client.v1.model.SyntheticsAPITestStepSubtype;
import com.datadog.api.client.v1.model.SyntheticsAPITestType;
import com.datadog.api.client.v1.model.SyntheticsAssertion;
import com.datadog.api.client.v1.model.SyntheticsAssertionOperator;
import com.datadog.api.client.v1.model.SyntheticsAssertionTarget;
import com.datadog.api.client.v1.model.SyntheticsAssertionTargetValue;
import com.datadog.api.client.v1.model.SyntheticsAssertionType;
import com.datadog.api.client.v1.model.SyntheticsBasicAuth;
import com.datadog.api.client.v1.model.SyntheticsBasicAuthWeb;
import com.datadog.api.client.v1.model.SyntheticsTestDetailsSubType;
import com.datadog.api.client.v1.model.SyntheticsTestOptions;
import com.datadog.api.client.v1.model.SyntheticsTestRequest;
import java.util.Arrays;
import java.util.Collections;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
SyntheticsApi apiInstance = new SyntheticsApi(defaultClient);

// there is a valid "synthetics_api_test" in the system
String SYNTHETICS_API_TEST_PUBLIC_ID = System.getenv("SYNTHETICS_API_TEST_PUBLIC_ID");

SyntheticsAPITest body =
new SyntheticsAPITest()
.config(
new SyntheticsAPITestConfig()
.steps(
Arrays.asList(
new SyntheticsAPIStep(
new SyntheticsAPITestStep()
.assertions(
Collections.singletonList(
new SyntheticsAssertion(
new SyntheticsAssertionTarget()
.operator(SyntheticsAssertionOperator.IS)
.type(SyntheticsAssertionType.STATUS_CODE)
.target(
new SyntheticsAssertionTargetValue(
200.0)))))
.name("request is sent")
.request(
new SyntheticsTestRequest()
.url("https://httpbin.org/status/200")
.method("GET")
.basicAuth(
new SyntheticsBasicAuth(
new SyntheticsBasicAuthWeb()
.password("password")
.username("username"))))
.subtype(SyntheticsAPITestStepSubtype.HTTP)),
new SyntheticsAPIStep(
new SyntheticsAPISubtestStep()
.subtype(SyntheticsAPISubtestStepSubtype.PLAY_SUB_TEST)
.subtestPublicId(SYNTHETICS_API_TEST_PUBLIC_ID)
.name("subtest step")))))
.locations(Collections.singletonList("aws:us-east-2"))
.message("BDD test payload: synthetics_api_test_multi_step_with_subtest.json")
.name("Example-Synthetic")
.options(new SyntheticsTestOptions().tickEvery(60L))
.subtype(SyntheticsTestDetailsSubType.MULTI)
.type(SyntheticsAPITestType.API);

try {
SyntheticsAPITest result = apiInstance.createSyntheticsAPITest(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling SyntheticsApi#createSyntheticsAPITest");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,51 @@ public SyntheticsAPIStep deserialize(JsonParser jp, DeserializationContext ctxt)
log.log(Level.FINER, "Input data does not match schema 'SyntheticsAPIWaitStep'", e);
}

// deserialize SyntheticsAPISubtestStep
try {
boolean attemptParsing = true;
// ensure that we respect type coercion as set on the client ObjectMapper
if (SyntheticsAPISubtestStep.class.equals(Integer.class)
|| SyntheticsAPISubtestStep.class.equals(Long.class)
|| SyntheticsAPISubtestStep.class.equals(Float.class)
|| SyntheticsAPISubtestStep.class.equals(Double.class)
|| SyntheticsAPISubtestStep.class.equals(Boolean.class)
|| SyntheticsAPISubtestStep.class.equals(String.class)) {
attemptParsing = typeCoercion;
if (!attemptParsing) {
attemptParsing |=
((SyntheticsAPISubtestStep.class.equals(Integer.class)
|| SyntheticsAPISubtestStep.class.equals(Long.class))
&& token == JsonToken.VALUE_NUMBER_INT);
attemptParsing |=
((SyntheticsAPISubtestStep.class.equals(Float.class)
|| SyntheticsAPISubtestStep.class.equals(Double.class))
&& (token == JsonToken.VALUE_NUMBER_FLOAT
|| token == JsonToken.VALUE_NUMBER_INT));
attemptParsing |=
(SyntheticsAPISubtestStep.class.equals(Boolean.class)
&& (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE));
attemptParsing |=
(SyntheticsAPISubtestStep.class.equals(String.class)
&& token == JsonToken.VALUE_STRING);
}
}
if (attemptParsing) {
tmp = tree.traverse(jp.getCodec()).readValueAs(SyntheticsAPISubtestStep.class);
// TODO: there is no validation against JSON schema constraints
// (min, max, enum, pattern...), this does not perform a strict JSON
// validation, which means the 'match' count may be higher than it should be.
if (!((SyntheticsAPISubtestStep) tmp).unparsed) {
deserialized = tmp;
match++;
}
log.log(Level.FINER, "Input data matches schema 'SyntheticsAPISubtestStep'");
}
} catch (Exception e) {
// deserialization failed, continue
log.log(Level.FINER, "Input data does not match schema 'SyntheticsAPISubtestStep'", e);
}

SyntheticsAPIStep ret = new SyntheticsAPIStep();
if (match == 1) {
ret.setActualInstance(deserialized);
Expand Down Expand Up @@ -205,9 +250,15 @@ public SyntheticsAPIStep(SyntheticsAPIWaitStep o) {
setActualInstance(o);
}

public SyntheticsAPIStep(SyntheticsAPISubtestStep o) {
super("oneOf", Boolean.FALSE);
setActualInstance(o);
}

static {
schemas.put("SyntheticsAPITestStep", new GenericType<SyntheticsAPITestStep>() {});
schemas.put("SyntheticsAPIWaitStep", new GenericType<SyntheticsAPIWaitStep>() {});
schemas.put("SyntheticsAPISubtestStep", new GenericType<SyntheticsAPISubtestStep>() {});
JSON.registerDescendants(SyntheticsAPIStep.class, Collections.unmodifiableMap(schemas));
}

Expand All @@ -218,7 +269,8 @@ public Map<String, GenericType> getSchemas() {

/**
* Set the instance that matches the oneOf child schema, check the instance parameter is valid
* against the oneOf child schemas: SyntheticsAPITestStep, SyntheticsAPIWaitStep
* against the oneOf child schemas: SyntheticsAPITestStep, SyntheticsAPIWaitStep,
* SyntheticsAPISubtestStep
*
* <p>It could be an instance of the 'oneOf' schemas. The oneOf child schemas may themselves be a
* composed schema (allOf, anyOf, oneOf).
Expand All @@ -233,20 +285,26 @@ public void setActualInstance(Object instance) {
super.setActualInstance(instance);
return;
}
if (JSON.isInstanceOf(SyntheticsAPISubtestStep.class, instance, new HashSet<Class<?>>())) {
super.setActualInstance(instance);
return;
}

if (JSON.isInstanceOf(UnparsedObject.class, instance, new HashSet<Class<?>>())) {
super.setActualInstance(instance);
return;
}
throw new RuntimeException(
"Invalid instance type. Must be SyntheticsAPITestStep, SyntheticsAPIWaitStep");
"Invalid instance type. Must be SyntheticsAPITestStep, SyntheticsAPIWaitStep,"
+ " SyntheticsAPISubtestStep");
}

/**
* Get the actual instance, which can be the following: SyntheticsAPITestStep,
* SyntheticsAPIWaitStep
* SyntheticsAPIWaitStep, SyntheticsAPISubtestStep
*
* @return The actual instance (SyntheticsAPITestStep, SyntheticsAPIWaitStep)
* @return The actual instance (SyntheticsAPITestStep, SyntheticsAPIWaitStep,
* SyntheticsAPISubtestStep)
*/
@Override
public Object getActualInstance() {
Expand Down Expand Up @@ -274,4 +332,15 @@ public SyntheticsAPITestStep getSyntheticsAPITestStep() throws ClassCastExceptio
public SyntheticsAPIWaitStep getSyntheticsAPIWaitStep() throws ClassCastException {
return (SyntheticsAPIWaitStep) super.getActualInstance();
}

/**
* Get the actual instance of `SyntheticsAPISubtestStep`. If the actual instance is not
* `SyntheticsAPISubtestStep`, the ClassCastException will be thrown.
*
* @return The actual instance of `SyntheticsAPISubtestStep`
* @throws ClassCastException if the instance is not `SyntheticsAPISubtestStep`
*/
public SyntheticsAPISubtestStep getSyntheticsAPISubtestStep() throws ClassCastException {
return (SyntheticsAPISubtestStep) super.getActualInstance();
}
}
Loading
Loading