Skip to content

Implementing your own rules

Esta Nagy edited this page Jul 1, 2020 · 3 revisions

Parameters

Each rule absolutely needs two parameters (alongside the name of the rule) and can have additional parameters on top of those at the discretion of the implementation.

The standard parameters

Name Type Meaning
order Integer The order of the rule in the rule list.
jsonPath com.jayway.jsonpath.JsonPath The path the rule should apply to.

Additional parameters

Additional parameters are either stored in the param map of the RawJsonRule or can be using one of the supported parameter types as described here.

The interface all the Rules must implement is called JsonRule.

Getting started

If you can't seem to find the rule that fits your needs, you can always implement your own rule by doing the simple steps below.

  1. Create a class implementing the JsonRule interface or feel free to extend AbstractJsonRule for a bit of convenience.
  2. Define a constructor with using only RawJsonRule and the supported parameter if needed.
  3. Annotate it with @NamedRule adding a unique name for your rule.
  4. In your constructor, figure out how to convert the input parameters you need.
  5. Implement the abstract methods coming form the interface/super class.
  6. Register your rule using JsonRuleRegistry#registerRuleClass(Class)
  7. Add your rule to the #/definitions/ruleTypes/definitions node of our JSON Schema
  8. Make sure to add it to the generic #/definitions/ruleTypes/definitions/anyRule type as well
  9. Yippee-Ki-Yay you made it! You can start using your new rule.