CustomCheck

CustomCheck(
    jsonpath: str,
    message: str,
    check: Callable[[Any], bool],
    type: str = 'custom',
)

A custom check to be done on Data Package metadata.

Attributes

jsonpath : str

The location of the field or fields the custom check applies to, expressed in JSON path notation (e.g., $.resources[*].name).

message : str

The message shown when the check is violated.

check : Callable[[Any], bool]

A function that expresses the custom check. It takes the value at the jsonpath location as input and returns true if the check is met, false if it isn’t.

type : str

The type of the custom check (e.g., a JSON schema type such as “required”, “type”, “pattern”, or “format”, or a custom type). It will be shown in error messages and can be used in an Exclusion object to exclude the check. Each custom check should have a unique type.

Examples

import check_datapackage as cdp

license_check = cdp.CustomCheck(
    type="only-mit",
    jsonpath="$.licenses[*].name",
    message="Data Packages may only be licensed under MIT.",
    check=lambda license_name: license_name == "mit",
)
config = cdp.Config(
    extensions=cdp.Extensions(
        custom_checks=[license_check]
    )
)
# check(descriptor, config=config)

Methods

Name Description
apply Applies the custom check to the properties.

apply

CustomCheck.apply(properties: dict[str, Any])

Applies the custom check to the properties.

Parameters

properties : dict[str, Any]

The properties to check.

Returns

list[Issue]

A list of Issues.