This is a Sink plugin for MADS.
This plugins validates the JSON messages received from the subscribed topics against the JSON schemas defined in schemas.json. If a message does not conform to the schema, an error is logged.
Required MADS version: 2.1.0.
Currently, the supported platforms are:
- Linux
- MacOS
- Windows
with MADS v2.1.1 or later, install with:
mads package --install validator.pluginLinux and MacOS:
cmake -Bbuild -DCMAKE_INSTALL_PREFIX="$(mads -p)"
cmake --build build -j4
sudo cmake --install buildWindows:
cmake -Bbuild -DCMAKE_INSTALL_PREFIX="$(mads -p)"
cmake --build build --config Release
cmake --install build --config ReleaseThe plugin supports the following settings in the INI file:
[validator]
schemas = "schemas.json" # path to the JSON schemas file (default="schemas.json")
sub_topic = [""] # subscribe to these topics for validation (default=[])All settings are optional; if omitted, the default values are used.
NOTE: the plugin never deals with messages on the agent_event topic to avoid potential infinite loop, as the plugin itself may generate agent_event messages when validation fails.
The plugin expects a JSON file containing the schemas for validating the messages. The file should be in the following format:
{
"topic_name": {
"$id": "https://example.com/schema_name.json",
"$schema": "http://json-schema.org/draft/2020-12/schema",
"properties": {
// schema properties
},
"required": [
// required properties
]
},
// more schemas for other topics...
}There is a useful schema editor online: JSON Schema Editor. Simply select Infer from JSON, then possibly correct the resulting schema, and finally copy the schema into the schemas.json file, under a key that matches the topic name you want to validate.
Runs some simple tests to demonstrate the plugin functionality.