Skip to main content
Validates data against a JSON schema using the AJV validator. This function can validate any given data against a given schema. It supports validating custom data types such as the Attachment type.
def validate_data_using_schema(
    data: dict[str, Any] | list[dict[str, Any]],
    schema: dict[str, Any],
)

Examples

from typing import TypedDict
from playwright.async_api import Page
from intuned_browser import validate_data_using_schema
class Params(TypedDict):
    pass
async def automation(page: Page, params: Params, **_kwargs):
    upload_data = {
        "file": {
            "file_name": "documents/report.pdf",
            "bucket": "my-bucket",
            "region": "us-east-1",
            "key": "documents/report.pdf",
            "endpoint": None,
            "suggested_file_name": "Monthly Report.pdf",
            "file_type": "document"
        },
        "name": "Test File Upload"
    }
    upload_schema = {
        "type": "object",
        "required": ["file", "name"],
        "properties": {
            "file": {"type": "attachment"},
            "name": {"type": "string"}
        }
    }
    validate_data_using_schema(upload_data, upload_schema)
    # Validation passes with Attachment type
    print("Validation passed")
    return "Validation passed"

Arguments

data
dict[str, Any] | list[dict[str, Any]]
required
The data to validate. Can be a single data object or an array of data objects.
schema
dict[str, Any]
required
JSON schema object defining validation rules

Returns: None

Returns nothing if validation passes, raises ValidationError if it fails

Raises

ValidationError

If validation fails