WSO2 Rule Validator is a JSON/YAML linter that is a Java implementation of Stoplight Spectral. https://github.com/stoplightio/spectral
WSO2 Rule validator supports most features that Spectral itself does. With the exception of a few due to disadvantages in language and environment.
- Given path is a JSON Path. But currently WSO2 Rule Validator does not support JSON Path Plus features, even though Spectral does.
- All core functions of Spectral are supported.
- Custom functions are not supported.
- Documents are always resolved before the validation happens.
- Supports both YAML and JSON rulesets
- Extends are currently not supported
- Parser options are not supported
- Overrides are currently not supported
- Only Async API and Open API are supported (all versions)
- Above formats are supported at all levels (Ruleset and Rule level)
- Aliases are supported.
- Build using
mvn clean install
. - Use the
.jar
file generated incomponent/target
. - Use the following maven dependency
<dependency> <groupId>org.wso2.carbon</groupId> <artifactId>rule.validator</artifactId> <version>${rule.validator.version}</version> </dependency>
- Read the ruleset file into a string and call the
validateRuleset
method to validate the ruleset.String document = new String(Files.readAllBytes(Paths.get("path/to/ruleset/ruleset.yaml"))); String rulesetValidationResult = Validator.validateRuleset(ruleset);
- Read the target document file and the ruleset into strings and call the
validateDocument
method to validate the document against the ruleset.String document = new String(Files.readAllBytes(Paths.get("path/to/document/document.yaml"))); String documentValidationResult = Validator.validateDocument(document, ruleset);