See: Description
| Class | Description |
|---|---|
| AbstractTypeKeywordValidator |
Abstract validator for the
type and disallow keywords |
| AdditionalItemsKeywordValidator |
Validator for the
additionalItems keyword |
| AdditionalPropertiesKeywordValidator |
Validator for
additionalProperties |
| DependenciesKeywordValidator |
Validator for the
dependencies keyword |
| DisallowKeywordValidator |
Validator for the
disallow keyword |
| DivisibleByKeywordValidator |
Validator for the
disallow keyword |
| EnumKeywordValidator |
Validator for the
enum keyword |
| ExtendsKeywordValidator |
Validator for the
extends keyword |
| FormatKeywordValidator |
Validator for the
format keyword |
| KeywordFactory |
Factory to provide a set of
KeywordValidator instances for a given
schema |
| KeywordValidator |
Base class for a schema keyword validator
|
| MaximumKeywordValidator |
Validator for the
maximum keyword |
| MaxItemsKeywordValidator |
Validator for the
maxItems keyword |
| MaxLengthKeywordValidator |
Validator for the
maxLength keyword |
| MinimumKeywordValidator |
Validator for the
minimum keyword |
| MinItemsKeywordValidator |
Validator for the
minItems keyword |
| MinLengthKeywordValidator |
Validator for the
minLength keyword |
| NumericKeywordValidator |
Base class for numeric instances validators
|
| PatternKeywordValidator |
Validator for the
pattern keyword |
| PositiveIntegerKeywordValidator |
Base class for all keywords accepting a positive integer as an argument
|
| PropertiesKeywordValidator |
Validator for the
properties keyword |
| TypeKeywordValidator |
Validator for the
type keyword |
| UniqueItemsKeywordValidator |
Validator for the
uniqueItems keyword |
All keyword validators are built via reflection, since they are dependent
on the schema being passed as an argument. Therefore, if you create a
keyword validator of yours, you must provide a constructor with a
single argument of type JsonNode.
Not only this, but if you do, be sure to pair it with a SyntaxChecker. The principle is that the
syntax checker checks that the keyword has a correct shape, which means the
keyword validator does not have to check for this. This considerably
simplifies the constructor (you only have to do minimal type checking, if
any).
To create a new validator, you may either extend KeywordValidator or one of these two
specific subclasses:
NumericKeywordValidator
(used for numeric instance validation),PositiveIntegerKeywordValidator
(used for keywords which take a positive integer as an argument).Here is an example for a proposed minProperties keyword. This
keyword validates that an object instance has a minimum number of members.
Its argument is a positive integer, we therefore extend PositiveIntegerKeywordValidator directly
instead of KeywordValidator:
public final class MinPropertiesKeywordValidator
extends PositiveIntegerKeywordValidator
{
public MinPropertiesKeywordValidator(final JsonNode schema)
{
super("minProperties", schema, NodeType.OBJECT);
}
@Override
public void validateInstance(final ValidationContext context,
final ValidationReport report, final JsonNode instance)
{
if (instance.size() < intValue)
report.addMessage("object instance has less than "
+ "minProperties elements");
}
}
Copyright © 2012. All Rights Reserved.