Skip to content

Commit 05e8375

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add support to patch Synthetics test with partial data using JSON Patch (#1418)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent fb4640a commit 05e8375

File tree

14 files changed

+654
-6
lines changed

14 files changed

+654
-6
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.6",
7-
"regenerated": "2023-11-17 11:20:23.180572",
8-
"spec_repo_commit": "04139dfa"
7+
"regenerated": "2023-11-17 12:18:19.958601",
8+
"spec_repo_commit": "d2efeed9"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.6",
12-
"regenerated": "2023-11-17 11:20:23.195109",
13-
"spec_repo_commit": "04139dfa"
12+
"regenerated": "2023-11-17 12:18:19.974563",
13+
"spec_repo_commit": "d2efeed9"
1414
}
1515
}
1616
}

.generator/schemas/v1/openapi.yaml

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14705,6 +14705,55 @@ components:
1470514705
type:
1470614706
$ref: '#/components/schemas/SyntheticsGlobalVariableParseTestOptionsType'
1470714707
type: object
14708+
SyntheticsPatchTestBody:
14709+
description: Wrapper around an array of [JSON Patch](https://jsonpatch.com)
14710+
operations to perform on the test
14711+
properties:
14712+
data:
14713+
description: Array of [JSON Patch](https://jsonpatch.com) operations to
14714+
perform on the test
14715+
example:
14716+
- op: replace
14717+
path: /name
14718+
value: New test name
14719+
- op: remove
14720+
path: /config/assertions/0
14721+
items:
14722+
$ref: '#/components/schemas/SyntheticsPatchTestOperation'
14723+
type: array
14724+
type: object
14725+
SyntheticsPatchTestOperation:
14726+
description: A single [JSON Patch](https://jsonpatch.com) operation to perform
14727+
on the test
14728+
properties:
14729+
op:
14730+
$ref: '#/components/schemas/SyntheticsPatchTestOperationName'
14731+
path:
14732+
description: The path to the value to modify
14733+
example: /name
14734+
type: string
14735+
value:
14736+
description: A value to use in a [JSON Patch](https://jsonpatch.com) operation
14737+
example: New Test Name
14738+
type: object
14739+
SyntheticsPatchTestOperationName:
14740+
description: The operation to perform
14741+
enum:
14742+
- add
14743+
- remove
14744+
- replace
14745+
- move
14746+
- copy
14747+
- test
14748+
example: replace
14749+
type: string
14750+
x-enum-varnames:
14751+
- ADD
14752+
- REMOVE
14753+
- REPLACE
14754+
- MOVE
14755+
- COPY
14756+
- TEST
1470814757
SyntheticsPlayingTab:
1470914758
description: Navigate between different tabs for your browser test.
1471014759
enum:
@@ -29651,7 +29700,7 @@ paths:
2965129700
description: Edit the configuration of a Synthetic browser test.
2965229701
operationId: UpdateBrowserTest
2965329702
parameters:
29654-
- description: The public ID of the test to get details from.
29703+
- description: The public ID of the test to edit.
2965529704
in: path
2965629705
name: public_id
2965729706
required: true
@@ -29990,6 +30039,60 @@ paths:
2999030039
summary: Get a test configuration
2999130040
tags:
2999230041
- Synthetics
30042+
patch:
30043+
description: Patch the configuration of a Synthetic test with partial data.
30044+
operationId: PatchTest
30045+
parameters:
30046+
- description: The public ID of the test to patch.
30047+
in: path
30048+
name: public_id
30049+
required: true
30050+
schema:
30051+
type: string
30052+
requestBody:
30053+
content:
30054+
application/json:
30055+
schema:
30056+
$ref: '#/components/schemas/SyntheticsPatchTestBody'
30057+
description: '[JSON Patch](https://jsonpatch.com/) compliant list of operations'
30058+
required: true
30059+
responses:
30060+
'200':
30061+
content:
30062+
application/json:
30063+
schema:
30064+
$ref: '#/components/schemas/SyntheticsTestDetails'
30065+
description: OK
30066+
'400':
30067+
content:
30068+
application/json:
30069+
schema:
30070+
$ref: '#/components/schemas/APIErrorResponse'
30071+
description: '- JSON format is wrong
30072+
30073+
- Updating sub-type is forbidden'
30074+
'403':
30075+
content:
30076+
application/json:
30077+
schema:
30078+
$ref: '#/components/schemas/APIErrorResponse'
30079+
description: Forbidden
30080+
'404':
30081+
content:
30082+
application/json:
30083+
schema:
30084+
$ref: '#/components/schemas/APIErrorResponse'
30085+
description: '- Synthetic Monitoring is not activated for the user
30086+
30087+
- Test is not owned by the user
30088+
30089+
- Test can''t be found'
30090+
'429':
30091+
$ref: '#/components/responses/TooManyRequestsResponse'
30092+
summary: Patch a Synthetic test
30093+
tags:
30094+
- Synthetics
30095+
x-codegen-request-body-name: body
2999330096
/api/v1/synthetics/tests/{public_id}/results:
2999430097
get:
2999530098
description: Get the last 150 test results summaries for a given Synthetic API
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"2023-11-17T12:10:50.122Z"
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
{
2+
"log": {
3+
"_recordingName": "Synthetics/Patch a Synthetic test returns \"OK\" response",
4+
"creator": {
5+
"comment": "persister:fs",
6+
"name": "Polly.JS",
7+
"version": "6.0.5"
8+
},
9+
"entries": [
10+
{
11+
"_id": "38585d005d3037e31715bcd6e20bc309",
12+
"_order": 0,
13+
"cache": {},
14+
"request": {
15+
"bodySize": 1718,
16+
"cookies": [],
17+
"headers": [
18+
{
19+
"_fromType": "array",
20+
"name": "accept",
21+
"value": "application/json"
22+
},
23+
{
24+
"_fromType": "array",
25+
"name": "content-type",
26+
"value": "application/json"
27+
}
28+
],
29+
"headersSize": 579,
30+
"httpVersion": "HTTP/1.1",
31+
"method": "POST",
32+
"postData": {
33+
"mimeType": "application/json",
34+
"params": [],
35+
"text": "{\"config\":{\"assertions\":[{\"operator\":\"is\",\"property\":\"{{ PROPERTY }}\",\"target\":\"text/html\",\"type\":\"header\"},{\"operator\":\"lessThan\",\"target\":2000,\"timingsScope\":\"withoutDNS\",\"type\":\"responseTime\"},{\"operator\":\"validatesJSONPath\",\"target\":{\"jsonPath\":\"topKey\",\"operator\":\"isNot\",\"targetValue\":\"0\"},\"type\":\"body\"},{\"operator\":\"validatesXPath\",\"target\":{\"operator\":\"contains\",\"targetValue\":\"0\",\"xPath\":\"target-xpath\"},\"type\":\"body\"}],\"configVariables\":[{\"example\":\"content-type\",\"name\":\"PROPERTY\",\"pattern\":\"content-type\",\"type\":\"text\"}],\"request\":{\"basicAuth\":{\"accessTokenUrl\":\"https://datadog-token.com\",\"audience\":\"audience\",\"clientId\":\"client-id\",\"clientSecret\":\"client-secret\",\"resource\":\"resource\",\"scope\":\"yoyo\",\"tokenApiAuthentication\":\"header\",\"type\":\"oauth-client\"},\"certificate\":{\"cert\":{\"content\":\"cert-content\",\"filename\":\"cert-filename\",\"updatedAt\":\"2020-10-16T09:23:24.857Z\"},\"key\":{\"content\":\"key-content\",\"filename\":\"key-filename\",\"updatedAt\":\"2020-10-16T09:23:24.857Z\"}},\"headers\":{\"unique\":\"testpatchasynthetictestreturnsokresponse1700223050\"},\"method\":\"GET\",\"persistCookies\":true,\"proxy\":{\"headers\":{},\"url\":\"https://datadoghq.com\"},\"timeout\":10,\"url\":\"https://datadoghq.com\"}},\"locations\":[\"aws:us-east-2\"],\"message\":\"BDD test payload: synthetics_api_http_test_payload.json\",\"name\":\"Test-Patch_a_Synthetic_test_returns_OK_response-1700223050\",\"options\":{\"accept_self_signed\":false,\"allow_insecure\":true,\"follow_redirects\":true,\"httpVersion\":\"http2\",\"min_failure_duration\":10,\"min_location_failed\":1,\"monitor_name\":\"Test-Patch_a_Synthetic_test_returns_OK_response-1700223050\",\"monitor_priority\":5,\"retry\":{\"count\":3,\"interval\":10},\"tick_every\":60},\"subtype\":\"http\",\"tags\":[\"testing:api\"],\"type\":\"api\"}"
36+
},
37+
"queryString": [],
38+
"url": "https://api.datadoghq.com/api/v1/synthetics/tests/api"
39+
},
40+
"response": {
41+
"bodySize": 2039,
42+
"content": {
43+
"mimeType": "application/json",
44+
"size": 2039,
45+
"text": "{\"public_id\":\"imz-5ik-p8i\",\"name\":\"Test-Patch_a_Synthetic_test_returns_OK_response-1700223050\",\"status\":\"live\",\"type\":\"api\",\"tags\":[\"testing:api\"],\"created_at\":\"2023-11-17T12:10:50.727692+00:00\",\"modified_at\":\"2023-11-17T12:10:50.727692+00:00\",\"config\":{\"assertions\":[{\"operator\":\"is\",\"property\":\"{{ PROPERTY }}\",\"target\":\"text/html\",\"type\":\"header\"},{\"operator\":\"lessThan\",\"target\":2000,\"timingsScope\":\"withoutDNS\",\"type\":\"responseTime\"},{\"operator\":\"validatesJSONPath\",\"target\":{\"jsonPath\":\"topKey\",\"operator\":\"isNot\",\"targetValue\":\"0\"},\"type\":\"body\"},{\"operator\":\"validatesXPath\",\"target\":{\"operator\":\"contains\",\"targetValue\":\"0\",\"xPath\":\"target-xpath\"},\"type\":\"body\"}],\"configVariables\":[{\"example\":\"content-type\",\"name\":\"PROPERTY\",\"pattern\":\"content-type\",\"type\":\"text\"}],\"request\":{\"basicAuth\":{\"accessTokenUrl\":\"https://datadog-token.com\",\"audience\":\"audience\",\"clientId\":\"client-id\",\"clientSecret\":\"client-secret\",\"resource\":\"resource\",\"scope\":\"yoyo\",\"tokenApiAuthentication\":\"header\",\"type\":\"oauth-client\"},\"certificate\":{\"cert\":{\"filename\":\"cert-filename\",\"updatedAt\":\"2020-10-16T09:23:24.857Z\"},\"key\":{\"filename\":\"key-filename\",\"updatedAt\":\"2020-10-16T09:23:24.857Z\"}},\"headers\":{\"unique\":\"testpatchasynthetictestreturnsokresponse1700223050\"},\"method\":\"GET\",\"persistCookies\":true,\"proxy\":{\"headers\":{},\"url\":\"https://datadoghq.com\"},\"timeout\":10,\"url\":\"https://datadoghq.com\"}},\"message\":\"BDD test payload: synthetics_api_http_test_payload.json\",\"options\":{\"accept_self_signed\":false,\"allow_insecure\":true,\"follow_redirects\":true,\"httpVersion\":\"http2\",\"min_failure_duration\":10,\"min_location_failed\":1,\"monitor_name\":\"Test-Patch_a_Synthetic_test_returns_OK_response-1700223050\",\"monitor_priority\":5,\"retry\":{\"count\":3,\"interval\":10},\"tick_every\":60},\"locations\":[\"aws:us-east-2\"],\"subtype\":\"http\",\"created_by\":{\"name\":null,\"handle\":\"[email protected]\",\"email\":\"[email protected]\"},\"deleted_at\":null,\"monitor_id\":135003391,\"org_id\":321813,\"modified_by\":{\"name\":null,\"handle\":\"[email protected]\",\"email\":\"[email protected]\"}}"
46+
},
47+
"cookies": [],
48+
"headers": [
49+
{
50+
"name": "content-type",
51+
"value": "application/json"
52+
}
53+
],
54+
"headersSize": 663,
55+
"httpVersion": "HTTP/1.1",
56+
"redirectURL": "",
57+
"status": 200,
58+
"statusText": "OK"
59+
},
60+
"startedDateTime": "2023-11-17T12:10:50.131Z",
61+
"time": 699
62+
},
63+
{
64+
"_id": "c8c1020cca5d35b56408bf8512ee3811",
65+
"_order": 0,
66+
"cache": {},
67+
"request": {
68+
"bodySize": 112,
69+
"cookies": [],
70+
"headers": [
71+
{
72+
"_fromType": "array",
73+
"name": "accept",
74+
"value": "application/json"
75+
},
76+
{
77+
"_fromType": "array",
78+
"name": "content-type",
79+
"value": "application/json"
80+
}
81+
],
82+
"headersSize": 573,
83+
"httpVersion": "HTTP/1.1",
84+
"method": "PATCH",
85+
"postData": {
86+
"mimeType": "application/json",
87+
"params": [],
88+
"text": "{\"data\":[{\"op\":\"replace\",\"path\":\"/name\",\"value\":\"New test name\"},{\"op\":\"remove\",\"path\":\"/config/assertions/0\"}]}"
89+
},
90+
"queryString": [],
91+
"url": "https://api.datadoghq.com/api/v1/synthetics/tests/imz-5ik-p8i"
92+
},
93+
"response": {
94+
"bodySize": 1911,
95+
"content": {
96+
"mimeType": "application/json",
97+
"size": 1911,
98+
"text": "{\"public_id\":\"imz-5ik-p8i\",\"name\":\"New test name\",\"status\":\"live\",\"type\":\"api\",\"tags\":[\"testing:api\"],\"created_at\":\"2023-11-17T12:10:50.727692+00:00\",\"modified_at\":\"2023-11-17T12:10:51.334561+00:00\",\"config\":{\"assertions\":[{\"operator\":\"lessThan\",\"target\":2000,\"timingsScope\":\"withoutDNS\",\"type\":\"responseTime\"},{\"operator\":\"validatesJSONPath\",\"target\":{\"jsonPath\":\"topKey\",\"operator\":\"isNot\",\"targetValue\":\"0\"},\"type\":\"body\"},{\"operator\":\"validatesXPath\",\"target\":{\"operator\":\"contains\",\"targetValue\":\"0\",\"xPath\":\"target-xpath\"},\"type\":\"body\"}],\"configVariables\":[{\"example\":\"content-type\",\"name\":\"PROPERTY\",\"pattern\":\"content-type\",\"type\":\"text\"}],\"request\":{\"basicAuth\":{\"accessTokenUrl\":\"https://datadog-token.com\",\"audience\":\"audience\",\"clientId\":\"client-id\",\"clientSecret\":\"client-secret\",\"resource\":\"resource\",\"scope\":\"yoyo\",\"tokenApiAuthentication\":\"header\",\"type\":\"oauth-client\"},\"certificate\":{\"key\":{\"filename\":\"key-filename\",\"updatedAt\":\"2020-10-16T09:23:24.857Z\"},\"cert\":{\"filename\":\"cert-filename\",\"updatedAt\":\"2020-10-16T09:23:24.857Z\"}},\"headers\":{\"unique\":\"testpatchasynthetictestreturnsokresponse1700223050\"},\"method\":\"GET\",\"persistCookies\":true,\"proxy\":{\"headers\":{},\"url\":\"https://datadoghq.com\"},\"timeout\":10,\"url\":\"https://datadoghq.com\"}},\"message\":\"BDD test payload: synthetics_api_http_test_payload.json\",\"options\":{\"accept_self_signed\":false,\"allow_insecure\":true,\"follow_redirects\":true,\"httpVersion\":\"http2\",\"min_failure_duration\":10,\"min_location_failed\":1,\"monitor_name\":\"Test-Patch_a_Synthetic_test_returns_OK_response-1700223050\",\"monitor_priority\":5,\"retry\":{\"count\":3,\"interval\":10},\"tick_every\":60},\"locations\":[\"aws:us-east-2\"],\"subtype\":\"http\",\"created_by\":{\"name\":null,\"handle\":\"[email protected]\",\"email\":\"[email protected]\"},\"deleted_at\":null,\"monitor_id\":135003391,\"org_id\":321813,\"modified_by\":{\"name\":null,\"handle\":\"[email protected]\",\"email\":\"[email protected]\"}}"
99+
},
100+
"cookies": [],
101+
"headers": [
102+
{
103+
"name": "content-type",
104+
"value": "application/json"
105+
}
106+
],
107+
"headersSize": 656,
108+
"httpVersion": "HTTP/1.1",
109+
"redirectURL": "",
110+
"status": 200,
111+
"statusText": "OK"
112+
},
113+
"startedDateTime": "2023-11-17T12:10:50.836Z",
114+
"time": 1072
115+
},
116+
{
117+
"_id": "e9f4dd558e490e510465eee7904fce23",
118+
"_order": 0,
119+
"cache": {},
120+
"request": {
121+
"bodySize": 30,
122+
"cookies": [],
123+
"headers": [
124+
{
125+
"_fromType": "array",
126+
"name": "accept",
127+
"value": "application/json"
128+
},
129+
{
130+
"_fromType": "array",
131+
"name": "content-type",
132+
"value": "application/json"
133+
}
134+
],
135+
"headersSize": 568,
136+
"httpVersion": "HTTP/1.1",
137+
"method": "POST",
138+
"postData": {
139+
"mimeType": "application/json",
140+
"params": [],
141+
"text": "{\"public_ids\":[\"imz-5ik-p8i\"]}"
142+
},
143+
"queryString": [],
144+
"url": "https://api.datadoghq.com/api/v1/synthetics/tests/delete"
145+
},
146+
"response": {
147+
"bodySize": 96,
148+
"content": {
149+
"mimeType": "application/json",
150+
"size": 96,
151+
"text": "{\"deleted_tests\":[{\"public_id\":\"imz-5ik-p8i\",\"deleted_at\":\"2023-11-17T12:10:52.395192+00:00\"}]}\n"
152+
},
153+
"cookies": [],
154+
"headers": [
155+
{
156+
"name": "content-type",
157+
"value": "application/json"
158+
}
159+
],
160+
"headersSize": 661,
161+
"httpVersion": "HTTP/1.1",
162+
"redirectURL": "",
163+
"status": 200,
164+
"statusText": "OK"
165+
},
166+
"startedDateTime": "2023-11-17T12:10:51.915Z",
167+
"time": 1031
168+
}
169+
],
170+
"pages": [],
171+
"version": "1.2"
172+
}
173+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Patch a Synthetic test returns "OK" response
3+
*/
4+
5+
import { client, v1 } from "@datadog/datadog-api-client";
6+
7+
const configuration = client.createConfiguration();
8+
const apiInstance = new v1.SyntheticsApi(configuration);
9+
10+
// there is a valid "synthetics_api_test" in the system
11+
const SYNTHETICS_API_TEST_PUBLIC_ID = process.env
12+
.SYNTHETICS_API_TEST_PUBLIC_ID as string;
13+
14+
const params: v1.SyntheticsApiPatchTestRequest = {
15+
body: {
16+
data: [
17+
{
18+
op: "replace",
19+
path: "/name",
20+
value: "New test name",
21+
},
22+
{
23+
op: "remove",
24+
path: "/config/assertions/0",
25+
},
26+
],
27+
},
28+
publicId: SYNTHETICS_API_TEST_PUBLIC_ID,
29+
};
30+
31+
apiInstance
32+
.patchTest(params)
33+
.then((data: v1.SyntheticsTestDetails) => {
34+
console.log(
35+
"API called successfully. Returned data: " + JSON.stringify(data)
36+
);
37+
})
38+
.catch((error: any) => console.error(error));

features/support/scenarios_model_mapping.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,17 @@ export const ScenariosModelMappings: {[key: string]: {[key: string]: any}} = {
21172117
},
21182118
"operationResponseType": "SyntheticsTestDetails",
21192119
},
2120+
"v1.PatchTest": {
2121+
"publicId": {
2122+
"type": "string",
2123+
"format": "",
2124+
},
2125+
"body": {
2126+
"type": "SyntheticsPatchTestBody",
2127+
"format": "",
2128+
},
2129+
"operationResponseType": "SyntheticsTestDetails",
2130+
},
21202131
"v1.GetAPITestLatestResults": {
21212132
"publicId": {
21222133
"type": "string",

0 commit comments

Comments
 (0)