Skip to content

Commit 6a6ac2f

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

13 files changed

+482
-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:25.832617",
8-
"spec_repo_commit": "04139dfa"
7+
"regenerated": "2023-11-17 12:18:28.002474",
8+
"spec_repo_commit": "d2efeed9"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.6",
12-
"regenerated": "2023-11-17 11:20:25.855529",
13-
"spec_repo_commit": "04139dfa"
12+
"regenerated": "2023-11-17 12:18:28.020826",
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

docs/datadog_api_client.v1.model.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4292,6 +4292,27 @@ synthetics\_parsing\_options
42924292
:members:
42934293
:show-inheritance:
42944294

4295+
synthetics\_patch\_test\_body
4296+
-----------------------------
4297+
4298+
.. automodule:: datadog_api_client.v1.model.synthetics_patch_test_body
4299+
:members:
4300+
:show-inheritance:
4301+
4302+
synthetics\_patch\_test\_operation
4303+
----------------------------------
4304+
4305+
.. automodule:: datadog_api_client.v1.model.synthetics_patch_test_operation
4306+
:members:
4307+
:show-inheritance:
4308+
4309+
synthetics\_patch\_test\_operation\_name
4310+
----------------------------------------
4311+
4312+
.. automodule:: datadog_api_client.v1.model.synthetics_patch_test_operation_name
4313+
:members:
4314+
:show-inheritance:
4315+
42954316
synthetics\_playing\_tab
42964317
------------------------
42974318

examples/v1/synthetics/PatchTest.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Patch a Synthetic test returns "OK" response
3+
"""
4+
5+
from os import environ
6+
from datadog_api_client import ApiClient, Configuration
7+
from datadog_api_client.v1.api.synthetics_api import SyntheticsApi
8+
from datadog_api_client.v1.model.synthetics_patch_test_body import SyntheticsPatchTestBody
9+
from datadog_api_client.v1.model.synthetics_patch_test_operation import SyntheticsPatchTestOperation
10+
from datadog_api_client.v1.model.synthetics_patch_test_operation_name import SyntheticsPatchTestOperationName
11+
12+
# there is a valid "synthetics_api_test" in the system
13+
SYNTHETICS_API_TEST_PUBLIC_ID = environ["SYNTHETICS_API_TEST_PUBLIC_ID"]
14+
15+
body = SyntheticsPatchTestBody(
16+
data=[
17+
SyntheticsPatchTestOperation(
18+
op=SyntheticsPatchTestOperationName.REPLACE,
19+
path="/name",
20+
value="New test name",
21+
),
22+
SyntheticsPatchTestOperation(
23+
op=SyntheticsPatchTestOperationName.REMOVE,
24+
path="/config/assertions/0",
25+
),
26+
],
27+
)
28+
29+
configuration = Configuration()
30+
with ApiClient(configuration) as api_client:
31+
api_instance = SyntheticsApi(api_client)
32+
response = api_instance.patch_test(public_id=SYNTHETICS_API_TEST_PUBLIC_ID, body=body)
33+
34+
print(response)

src/datadog_api_client/v1/api/synthetics_api.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from datadog_api_client.v1.model.synthetics_trigger_ci_tests_response import SyntheticsTriggerCITestsResponse
3434
from datadog_api_client.v1.model.synthetics_trigger_body import SyntheticsTriggerBody
3535
from datadog_api_client.v1.model.synthetics_ci_test_body import SyntheticsCITestBody
36+
from datadog_api_client.v1.model.synthetics_patch_test_body import SyntheticsPatchTestBody
3637
from datadog_api_client.v1.model.synthetics_get_api_test_latest_results_response import (
3738
SyntheticsGetAPITestLatestResultsResponse,
3839
)
@@ -581,6 +582,32 @@ def __init__(self, api_client=None):
581582
api_client=api_client,
582583
)
583584

585+
self._patch_test_endpoint = _Endpoint(
586+
settings={
587+
"response_type": (SyntheticsTestDetails,),
588+
"auth": ["apiKeyAuth", "appKeyAuth"],
589+
"endpoint_path": "/api/v1/synthetics/tests/{public_id}",
590+
"operation_id": "patch_test",
591+
"http_method": "PATCH",
592+
"version": "v1",
593+
},
594+
params_map={
595+
"public_id": {
596+
"required": True,
597+
"openapi_types": (str,),
598+
"attribute": "public_id",
599+
"location": "path",
600+
},
601+
"body": {
602+
"required": True,
603+
"openapi_types": (SyntheticsPatchTestBody,),
604+
"location": "body",
605+
},
606+
},
607+
headers_map={"accept": ["application/json"], "content_type": ["application/json"]},
608+
api_client=api_client,
609+
)
610+
584611
self._trigger_ci_tests_endpoint = _Endpoint(
585612
settings={
586613
"response_type": (SyntheticsTriggerCITestsResponse,),
@@ -1187,6 +1214,28 @@ def list_tests_with_pagination(
11871214
}
11881215
return endpoint.call_with_http_info_paginated(pagination)
11891216

1217+
def patch_test(
1218+
self,
1219+
public_id: str,
1220+
body: SyntheticsPatchTestBody,
1221+
) -> SyntheticsTestDetails:
1222+
"""Patch a Synthetic test.
1223+
1224+
Patch the configuration of a Synthetic test with partial data.
1225+
1226+
:param public_id: The public ID of the test to patch.
1227+
:type public_id: str
1228+
:param body: `JSON Patch <https://jsonpatch.com/>`_ compliant list of operations
1229+
:type body: SyntheticsPatchTestBody
1230+
:rtype: SyntheticsTestDetails
1231+
"""
1232+
kwargs: Dict[str, Any] = {}
1233+
kwargs["public_id"] = public_id
1234+
1235+
kwargs["body"] = body
1236+
1237+
return self._patch_test_endpoint.call_with_http_info(**kwargs)
1238+
11901239
def trigger_ci_tests(
11911240
self,
11921241
body: SyntheticsCITestBody,
@@ -1252,7 +1301,7 @@ def update_browser_test(
12521301
12531302
Edit the configuration of a Synthetic browser test.
12541303
1255-
:param public_id: The public ID of the test to get details from.
1304+
:param public_id: The public ID of the test to edit.
12561305
:type public_id: str
12571306
:param body: New test details to be saved.
12581307
:type body: SyntheticsBrowserTest
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2+
# This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
# Copyright 2019-Present Datadog, Inc.
4+
from __future__ import annotations
5+
6+
from typing import List, Union, TYPE_CHECKING
7+
8+
from datadog_api_client.model_utils import (
9+
ModelNormal,
10+
cached_property,
11+
unset,
12+
UnsetType,
13+
)
14+
15+
16+
if TYPE_CHECKING:
17+
from datadog_api_client.v1.model.synthetics_patch_test_operation import SyntheticsPatchTestOperation
18+
19+
20+
class SyntheticsPatchTestBody(ModelNormal):
21+
@cached_property
22+
def openapi_types(_):
23+
from datadog_api_client.v1.model.synthetics_patch_test_operation import SyntheticsPatchTestOperation
24+
25+
return {
26+
"data": ([SyntheticsPatchTestOperation],),
27+
}
28+
29+
attribute_map = {
30+
"data": "data",
31+
}
32+
33+
def __init__(self_, data: Union[List[SyntheticsPatchTestOperation], UnsetType] = unset, **kwargs):
34+
"""
35+
Wrapper around an array of `JSON Patch <https://jsonpatch.com>`_ operations to perform on the test
36+
37+
:param data: Array of `JSON Patch <https://jsonpatch.com>`_ operations to perform on the test
38+
:type data: [SyntheticsPatchTestOperation], optional
39+
"""
40+
if data is not unset:
41+
kwargs["data"] = data
42+
super().__init__(kwargs)

0 commit comments

Comments
 (0)