Path
The Path
class is used to pass JSONPath expressions to assertion methods of the Check
class. It enables automatic handling of non-existent paths by raising NoDataError
when the specified path doesn't exist in the component data.
Constructor
Path(json_path)
Creates a new Path
instance. The provided json_path always starts from the root of the component data, so the leading $
is optional.
json_path (str): A JSONPath expression to query component data
Usage
The primary use of the Path
class is to provide a wrapper around JSONPath expressions that will be automatically evaluated by assertion methods in the Check
class.
from lunar_policy import Check, Path
with Check("my-check") as check:
# Using Path in assertions
check.assert_true(Path(".api.requires_auth"))
check.assert_equals(Path(".api.version"), "v1")
check.assert_contains(Path(".tags"), "security")
Last updated