Skip to content

Make assertion target be int or string #2859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2025-05-20 07:21:26.115507",
"spec_repo_commit": "fec20f97"
"regenerated": "2025-05-23 12:48:19.641798",
"spec_repo_commit": "11a9dcb4"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2025-05-20 07:21:26.131253",
"spec_repo_commit": "fec20f97"
"regenerated": "2025-05-23 12:48:19.657459",
"spec_repo_commit": "11a9dcb4"
}
}
}
20 changes: 18 additions & 2 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14221,8 +14221,8 @@ components:
operator:
$ref: '#/components/schemas/SyntheticsAssertionBodyHashOperator'
target:
$ref: '#/components/schemas/SyntheticsAssertionTargetValue'
description: Value used by the operator.
example: 123456
type:
$ref: '#/components/schemas/SyntheticsAssertionBodyHashType'
required:
Expand Down Expand Up @@ -14278,6 +14278,7 @@ components:
description: The specific operator to use on the path.
type: string
targetValue:
$ref: '#/components/schemas/SyntheticsAssertionTargetValue'
description: The path target value to compare to.
type: object
SyntheticsAssertionJSONSchemaMetaSchema:
Expand Down Expand Up @@ -14385,8 +14386,8 @@ components:
description: The associated assertion property.
type: string
target:
$ref: '#/components/schemas/SyntheticsAssertionTargetValue'
description: Value used by the operator.
example: 123456
timingsScope:
$ref: '#/components/schemas/SyntheticsAssertionTimingsScope'
type:
Expand All @@ -14396,6 +14397,20 @@ components:
- operator
- target
type: object
SyntheticsAssertionTargetValue:
description: Value used by the operator in assertions. Can be either a number
or string.
oneOf:
- $ref: '#/components/schemas/SyntheticsAssertionTargetValueNumber'
- $ref: '#/components/schemas/SyntheticsAssertionTargetValueString'
SyntheticsAssertionTargetValueNumber:
description: Numeric value used by the operator in assertions.
format: double
type: number
SyntheticsAssertionTargetValueString:
description: String value used by the operator in assertions. Supports templated
variables.
type: string
SyntheticsAssertionTimingsScope:
description: Timings scope for response time assertions.
enum:
Expand Down Expand Up @@ -14480,6 +14495,7 @@ components:
description: The specific operator to use on the path.
type: string
targetValue:
$ref: '#/components/schemas/SyntheticsAssertionTargetValue'
description: The path target value to compare to.
xPath:
description: The X path to assert.
Expand Down
18 changes: 14 additions & 4 deletions .generator/src/generator/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,25 @@ def format_data_with_schema(
else:

def format_number(x):
if isinstance(x, bool):
if isinstance(x, bool | str):
raise TypeError(f"{x} is not supported type {schema}")
return str(x)

def format_double(x):
if isinstance(x, bool):
if isinstance(x, bool | str):
raise TypeError(f"{x} is not supported type {schema}")
return float(x)

def format_int(x):
if isinstance(x, bool | str):
raise TypeError(f"{x} is not supported type {schema}")
return str(x)

def format_int64(x):
if isinstance(x, bool | str):
raise TypeError(f"{x} is not supported type {schema}")
return str(x) + "L"

def format_string(x):
if isinstance(x, bool):
raise TypeError(f"{x} is not supported type {schema}")
Expand Down Expand Up @@ -425,8 +435,8 @@ def open_file(x):
return f"new File({format_string(x)})"

formatters = {
"int32": lambda x: str(int(x)),
"int64": lambda x: str(int(x)) + "L",
"int32": format_int,
"int64": format_int64,
"double": format_double,
"date-time": format_datetime,
"number": format_number,
Expand Down
3 changes: 2 additions & 1 deletion examples/v1/synthetics/CreateSyntheticsAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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.SyntheticsBrowserTestRumSettings;
import com.datadog.api.client.v1.model.SyntheticsTestCiOptions;
Expand Down Expand Up @@ -40,7 +41,7 @@ public static void main(String[] args) {
new SyntheticsAssertion(
new SyntheticsAssertionTarget()
.operator(SyntheticsAssertionOperator.LESS_THAN)
.target(1000)
.target(new SyntheticsAssertionTargetValue(1000.0))
.type(SyntheticsAssertionType.RESPONSE_TIME))))
.request(new SyntheticsTestRequest().method("GET").url("https://example.com")))
.locations(Collections.singletonList("aws:eu-west-3"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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.SyntheticsTestDetailsSubType;
import com.datadog.api.client.v1.model.SyntheticsTestOptions;
Expand All @@ -30,7 +31,7 @@ public static void main(String[] args) {
new SyntheticsAssertion(
new SyntheticsAssertionTarget()
.operator(SyntheticsAssertionOperator.IS_IN_MORE_DAYS_THAN)
.target(10)
.target(new SyntheticsAssertionTargetValue(10.0))
.type(SyntheticsAssertionType.CERTIFICATE))))
.request(
new SyntheticsTestRequest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.datadog.api.client.v1.model.SyntheticsAssertionJSONPathTargetTarget;
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.SyntheticsAssertionTimingsScope;
import com.datadog.api.client.v1.model.SyntheticsAssertionType;
import com.datadog.api.client.v1.model.SyntheticsAssertionXPathOperator;
Expand Down Expand Up @@ -52,12 +53,12 @@ public static void main(String[] args) {
new SyntheticsAssertionTarget()
.operator(SyntheticsAssertionOperator.IS)
.property("{{ PROPERTY }}")
.target("text/html")
.target(new SyntheticsAssertionTargetValue("text/html"))
.type(SyntheticsAssertionType.HEADER)),
new SyntheticsAssertion(
new SyntheticsAssertionTarget()
.operator(SyntheticsAssertionOperator.LESS_THAN)
.target(2000)
.target(new SyntheticsAssertionTargetValue(2000.0))
.type(SyntheticsAssertionType.RESPONSE_TIME)
.timingsScope(SyntheticsAssertionTimingsScope.WITHOUT_DNS)),
new SyntheticsAssertion(
Expand All @@ -68,15 +69,15 @@ public static void main(String[] args) {
new SyntheticsAssertionJSONPathTargetTarget()
.jsonPath("topKey")
.operator("isNot")
.targetValue("0"))
.targetValue(new SyntheticsAssertionTargetValue("0")))
.type(SyntheticsAssertionType.BODY)),
new SyntheticsAssertion(
new SyntheticsAssertionXPathTarget()
.operator(SyntheticsAssertionXPathOperator.VALIDATES_X_PATH)
.target(
new SyntheticsAssertionXPathTargetTarget()
.xPath("target-xpath")
.targetValue("0")
.targetValue(new SyntheticsAssertionTargetValue("0"))
.operator("contains"))
.type(SyntheticsAssertionType.BODY))))
.configVariables(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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.SyntheticsConfigVariable;
import com.datadog.api.client.v1.model.SyntheticsConfigVariableType;
Expand Down Expand Up @@ -59,7 +60,9 @@ public static void main(String[] args) {
new SyntheticsAssertionTarget()
.operator(SyntheticsAssertionOperator.IS)
.type(SyntheticsAssertionType.STATUS_CODE)
.target(200))))
.target(
new SyntheticsAssertionTargetValue(
200.0)))))
.exitIfSucceed(true)
.extractedValues(
Collections.singletonList(
Expand Down Expand Up @@ -106,7 +109,9 @@ public static void main(String[] args) {
new SyntheticsAssertionTarget()
.operator(SyntheticsAssertionOperator.LESS_THAN)
.type(SyntheticsAssertionType.RESPONSE_TIME)
.target(1000))))
.target(
new SyntheticsAssertionTargetValue(
1000.0)))))
.request(
new SyntheticsTestRequest()
.host("grpcbin.test.k6.io")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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.SyntheticsTestDetailsSubType;
import com.datadog.api.client.v1.model.SyntheticsTestOptions;
Expand All @@ -33,17 +34,17 @@ public static void main(String[] args) {
new SyntheticsAssertion(
new SyntheticsAssertionTarget()
.operator(SyntheticsAssertionOperator.IS)
.target(1)
.target(new SyntheticsAssertionTargetValue(1.0))
.type(SyntheticsAssertionType.GRPC_HEALTHCHECK_STATUS)),
new SyntheticsAssertion(
new SyntheticsAssertionTarget()
.operator(SyntheticsAssertionOperator.IS)
.target("proto target")
.target(new SyntheticsAssertionTargetValue("proto target"))
.type(SyntheticsAssertionType.GRPC_PROTO)),
new SyntheticsAssertion(
new SyntheticsAssertionTarget()
.operator(SyntheticsAssertionOperator.IS)
.target("123")
.target(new SyntheticsAssertionTargetValue("123"))
.property("property")
.type(SyntheticsAssertionType.GRPC_METADATA))))
.request(
Expand Down
13 changes: 7 additions & 6 deletions examples/v1/synthetics/CreateSyntheticsAPITest_1487281163.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.datadog.api.client.v1.model.SyntheticsAssertionJavascriptType;
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.SyntheticsAssertionTimingsScope;
import com.datadog.api.client.v1.model.SyntheticsAssertionType;
import com.datadog.api.client.v1.model.SyntheticsAssertionXPathOperator;
Expand Down Expand Up @@ -59,12 +60,12 @@ public static void main(String[] args) {
new SyntheticsAssertionTarget()
.operator(SyntheticsAssertionOperator.IS)
.property("{{ PROPERTY }}")
.target("text/html")
.target(new SyntheticsAssertionTargetValue("text/html"))
.type(SyntheticsAssertionType.HEADER)),
new SyntheticsAssertion(
new SyntheticsAssertionTarget()
.operator(SyntheticsAssertionOperator.LESS_THAN)
.target(2000)
.target(new SyntheticsAssertionTargetValue(2000.0))
.type(SyntheticsAssertionType.RESPONSE_TIME)
.timingsScope(SyntheticsAssertionTimingsScope.WITHOUT_DNS)),
new SyntheticsAssertion(
Expand All @@ -75,7 +76,7 @@ public static void main(String[] args) {
new SyntheticsAssertionJSONPathTargetTarget()
.jsonPath("topKey")
.operator("isNot")
.targetValue("0"))
.targetValue(new SyntheticsAssertionTargetValue("0")))
.type(SyntheticsAssertionType.BODY)),
new SyntheticsAssertion(
new SyntheticsAssertionJSONPathTarget()
Expand All @@ -86,7 +87,7 @@ public static void main(String[] args) {
.elementsOperator("atLeastOneElementMatches")
.jsonPath("topKey")
.operator("isNot")
.targetValue("0"))
.targetValue(new SyntheticsAssertionTargetValue("0")))
.type(SyntheticsAssertionType.BODY)),
new SyntheticsAssertion(
new SyntheticsAssertionJSONSchemaTarget()
Expand All @@ -107,13 +108,13 @@ public static void main(String[] args) {
.target(
new SyntheticsAssertionXPathTargetTarget()
.xPath("target-xpath")
.targetValue("0")
.targetValue(new SyntheticsAssertionTargetValue("0"))
.operator("contains"))
.type(SyntheticsAssertionType.BODY)),
new SyntheticsAssertion(
new SyntheticsAssertionBodyHashTarget()
.operator(SyntheticsAssertionBodyHashOperator.MD5)
.target("a")
.target(new SyntheticsAssertionTargetValue("a"))
.type(SyntheticsAssertionBodyHashType.BODY_HASH)),
new SyntheticsAssertion(
new SyntheticsAssertionJavascript()
Expand Down
Loading