Skip to content

Validation

Jan Bernitt edited this page Jan 30, 2024 · 6 revisions

Features

Most of the validations specified by the JSON schema are supported. However, since annotations are used to add validation to a property method some of the validations work slightly different than specified so that each targets the annotated method's value. For example required is specified on each required property instead of specifying a list of required properties on their parent. This is also to avoid string name references to be required that are not safe to refactor.

Validations include:

Target JSON schema @Validation attribute Description
(any) type type() annotated property must have on of the JSON node types (with INTEGER being a distinct type)
(any) enum/const oneOfValues() + enumeration() annotated property's value must be one of a given set of JSON values or the given enum constant names
(any) required required() or use @Required annotated property must be present (unconditionally), that means defined and non-null
(any) dependentRequired dependentRequired() annotated property must be present (conditionally). Conditions are modeled using named groups and roles in this group (details below)
STRING minLength minLength() annotated text property must have a minimum length, this implicitly makes it required unless required explicitly states NO
STRING maxLength maxLength() annotated text property must not be longer than the maximum length (inclusive)
STRING pattern pattern() annotated text property must match the given regex pattern
NUMBER minimum minimum() annotated number property must be larger than or equal to the minimum value
NUMBER maximum maximum() annotated number property must be less than or equal to the maximum value
NUMBER exclusiveMinimum exclusiveMinimum() annotated number property must be larger than the minimum value
NUMBER exclusiveMaximum exclusiveMaximum() annotated number property must be less than the maximum value
NUMBER multipleOf multipleOf() annotated number property must dividable by the given number without rest
ARRAY minItems minItems() annotated array property must have at least the number of elements, this implicitly makes it required unless required explicitly states NO
ARRAY maxItems maxItems() annotated array property must have at most the number of elements
ARRAY uniqueItems uniqueItems() annotated array property must not have any duplicates (same "normalized" JSON)
OBJECT minProperties minProperties() annotated object property must have at least the number of members, this implicitly makes it required unless required explicitly states NO
OBJECT maxProperties maxProperties() annotated object property must have at most the number of members

Note

If a validation for a target type is used but that type does not apply based on the return type analysis or the type(s) declared via type() the validation has no effect as it does not apply to any valid value for the property.

Usage

Precedence

Custom Validators

Dependent Required

Clone this wiki locally