Skip to content
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

Add support to patch Synthetics test with partial data using JSON Patch #1767

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": "2023-11-17 11:20:25.832617",
"spec_repo_commit": "04139dfa"
"regenerated": "2023-11-17 12:18:28.002474",
"spec_repo_commit": "d2efeed9"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2023-11-17 11:20:25.855529",
"spec_repo_commit": "04139dfa"
"regenerated": "2023-11-17 12:18:28.020826",
"spec_repo_commit": "d2efeed9"
}
}
}
105 changes: 104 additions & 1 deletion .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14705,6 +14705,55 @@ components:
type:
$ref: '#/components/schemas/SyntheticsGlobalVariableParseTestOptionsType'
type: object
SyntheticsPatchTestBody:
description: Wrapper around an array of [JSON Patch](https://jsonpatch.com)
operations to perform on the test
properties:
data:
description: Array of [JSON Patch](https://jsonpatch.com) operations to
perform on the test
example:
- op: replace
path: /name
value: New test name
- op: remove
path: /config/assertions/0
items:
$ref: '#/components/schemas/SyntheticsPatchTestOperation'
type: array
type: object
SyntheticsPatchTestOperation:
description: A single [JSON Patch](https://jsonpatch.com) operation to perform
on the test
properties:
op:
$ref: '#/components/schemas/SyntheticsPatchTestOperationName'
path:
description: The path to the value to modify
example: /name
type: string
value:
description: A value to use in a [JSON Patch](https://jsonpatch.com) operation
example: New Test Name
type: object
SyntheticsPatchTestOperationName:
description: The operation to perform
enum:
- add
- remove
- replace
- move
- copy
- test
example: replace
type: string
x-enum-varnames:
- ADD
- REMOVE
- REPLACE
- MOVE
- COPY
- TEST
SyntheticsPlayingTab:
description: Navigate between different tabs for your browser test.
enum:
Expand Down Expand Up @@ -29651,7 +29700,7 @@ paths:
description: Edit the configuration of a Synthetic browser test.
operationId: UpdateBrowserTest
parameters:
- description: The public ID of the test to get details from.
- description: The public ID of the test to edit.
in: path
name: public_id
required: true
Expand Down Expand Up @@ -29990,6 +30039,60 @@ paths:
summary: Get a test configuration
tags:
- Synthetics
patch:
description: Patch the configuration of a Synthetic test with partial data.
operationId: PatchTest
parameters:
- description: The public ID of the test to patch.
in: path
name: public_id
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/SyntheticsPatchTestBody'
description: '[JSON Patch](https://jsonpatch.com/) compliant list of operations'
required: true
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/SyntheticsTestDetails'
description: OK
'400':
content:
application/json:
schema:
$ref: '#/components/schemas/APIErrorResponse'
description: '- JSON format is wrong

- Updating sub-type is forbidden'
'403':
content:
application/json:
schema:
$ref: '#/components/schemas/APIErrorResponse'
description: Forbidden
'404':
content:
application/json:
schema:
$ref: '#/components/schemas/APIErrorResponse'
description: '- Synthetic Monitoring is not activated for the user

- Test is not owned by the user

- Test can''t be found'
'429':
$ref: '#/components/responses/TooManyRequestsResponse'
summary: Patch a Synthetic test
tags:
- Synthetics
x-codegen-request-body-name: body
/api/v1/synthetics/tests/{public_id}/results:
get:
description: Get the last 150 test results summaries for a given Synthetic API
Expand Down
21 changes: 21 additions & 0 deletions docs/datadog_api_client.v1.model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4292,6 +4292,27 @@ synthetics\_parsing\_options
:members:
:show-inheritance:

synthetics\_patch\_test\_body
-----------------------------

.. automodule:: datadog_api_client.v1.model.synthetics_patch_test_body
:members:
:show-inheritance:

synthetics\_patch\_test\_operation
----------------------------------

.. automodule:: datadog_api_client.v1.model.synthetics_patch_test_operation
:members:
:show-inheritance:

synthetics\_patch\_test\_operation\_name
----------------------------------------

.. automodule:: datadog_api_client.v1.model.synthetics_patch_test_operation_name
:members:
:show-inheritance:

synthetics\_playing\_tab
------------------------

Expand Down
34 changes: 34 additions & 0 deletions examples/v1/synthetics/PatchTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Patch a Synthetic test returns "OK" response
"""

from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v1.api.synthetics_api import SyntheticsApi
from datadog_api_client.v1.model.synthetics_patch_test_body import SyntheticsPatchTestBody
from datadog_api_client.v1.model.synthetics_patch_test_operation import SyntheticsPatchTestOperation
from datadog_api_client.v1.model.synthetics_patch_test_operation_name import SyntheticsPatchTestOperationName

# there is a valid "synthetics_api_test" in the system
SYNTHETICS_API_TEST_PUBLIC_ID = environ["SYNTHETICS_API_TEST_PUBLIC_ID"]

body = SyntheticsPatchTestBody(
data=[
SyntheticsPatchTestOperation(
op=SyntheticsPatchTestOperationName.REPLACE,
path="/name",
value="New test name",
),
SyntheticsPatchTestOperation(
op=SyntheticsPatchTestOperationName.REMOVE,
path="/config/assertions/0",
),
],
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
api_instance = SyntheticsApi(api_client)
response = api_instance.patch_test(public_id=SYNTHETICS_API_TEST_PUBLIC_ID, body=body)

print(response)
51 changes: 50 additions & 1 deletion src/datadog_api_client/v1/api/synthetics_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from datadog_api_client.v1.model.synthetics_trigger_ci_tests_response import SyntheticsTriggerCITestsResponse
from datadog_api_client.v1.model.synthetics_trigger_body import SyntheticsTriggerBody
from datadog_api_client.v1.model.synthetics_ci_test_body import SyntheticsCITestBody
from datadog_api_client.v1.model.synthetics_patch_test_body import SyntheticsPatchTestBody
from datadog_api_client.v1.model.synthetics_get_api_test_latest_results_response import (
SyntheticsGetAPITestLatestResultsResponse,
)
Expand Down Expand Up @@ -581,6 +582,32 @@ def __init__(self, api_client=None):
api_client=api_client,
)

self._patch_test_endpoint = _Endpoint(
settings={
"response_type": (SyntheticsTestDetails,),
"auth": ["apiKeyAuth", "appKeyAuth"],
"endpoint_path": "/api/v1/synthetics/tests/{public_id}",
"operation_id": "patch_test",
"http_method": "PATCH",
"version": "v1",
},
params_map={
"public_id": {
"required": True,
"openapi_types": (str,),
"attribute": "public_id",
"location": "path",
},
"body": {
"required": True,
"openapi_types": (SyntheticsPatchTestBody,),
"location": "body",
},
},
headers_map={"accept": ["application/json"], "content_type": ["application/json"]},
api_client=api_client,
)

self._trigger_ci_tests_endpoint = _Endpoint(
settings={
"response_type": (SyntheticsTriggerCITestsResponse,),
Expand Down Expand Up @@ -1187,6 +1214,28 @@ def list_tests_with_pagination(
}
return endpoint.call_with_http_info_paginated(pagination)

def patch_test(
self,
public_id: str,
body: SyntheticsPatchTestBody,
) -> SyntheticsTestDetails:
"""Patch a Synthetic test.

Patch the configuration of a Synthetic test with partial data.

:param public_id: The public ID of the test to patch.
:type public_id: str
:param body: `JSON Patch <https://jsonpatch.com/>`_ compliant list of operations
:type body: SyntheticsPatchTestBody
:rtype: SyntheticsTestDetails
"""
kwargs: Dict[str, Any] = {}
kwargs["public_id"] = public_id

kwargs["body"] = body

return self._patch_test_endpoint.call_with_http_info(**kwargs)

def trigger_ci_tests(
self,
body: SyntheticsCITestBody,
Expand Down Expand Up @@ -1252,7 +1301,7 @@ def update_browser_test(

Edit the configuration of a Synthetic browser test.

:param public_id: The public ID of the test to get details from.
:param public_id: The public ID of the test to edit.
:type public_id: str
:param body: New test details to be saved.
:type body: SyntheticsBrowserTest
Expand Down
42 changes: 42 additions & 0 deletions src/datadog_api_client/v1/model/synthetics_patch_test_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2019-Present Datadog, Inc.
from __future__ import annotations

from typing import List, Union, TYPE_CHECKING

from datadog_api_client.model_utils import (
ModelNormal,
cached_property,
unset,
UnsetType,
)


if TYPE_CHECKING:
from datadog_api_client.v1.model.synthetics_patch_test_operation import SyntheticsPatchTestOperation


class SyntheticsPatchTestBody(ModelNormal):
@cached_property
def openapi_types(_):
from datadog_api_client.v1.model.synthetics_patch_test_operation import SyntheticsPatchTestOperation

return {
"data": ([SyntheticsPatchTestOperation],),
}

attribute_map = {
"data": "data",
}

def __init__(self_, data: Union[List[SyntheticsPatchTestOperation], UnsetType] = unset, **kwargs):
"""
Wrapper around an array of `JSON Patch <https://jsonpatch.com>`_ operations to perform on the test

:param data: Array of `JSON Patch <https://jsonpatch.com>`_ operations to perform on the test
:type data: [SyntheticsPatchTestOperation], optional
"""
if data is not unset:
kwargs["data"] = data
super().__init__(kwargs)
Loading