Package com.jsgalactic.axiom.validation
Class Validation
java.lang.Object
com.jsgalactic.axiom.validation.Validation
Entry point for checking values in handlers.
var command = Validation.require(CREATE_NOTE, parse(ctx));
A failed check throws core's ValidationException, which the server maps to a 422
application/problem+json response listing only each violation's field path and code.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMost violations reported for one value; the same limitValidationExceptionenforces. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TChecks a value and returns it when valid.static <T> TChecks one request parameter or header value and prefixes each violation's field path with the parameter name.
-
Field Details
-
MAX_VIOLATIONS
public static final int MAX_VIOLATIONSMost violations reported for one value; the same limitValidationExceptionenforces.- See Also:
-
-
Method Details
-
require
Checks a value and returns it when valid.- Type Parameters:
T- value type- Parameters:
validator- validator to runvalue- value to check; may be null if the validator accepts null- Returns:
value- Throws:
ValidationException- with at mostMAX_VIOLATIONSviolations, in the order the validator reported them, when the value is invalidIllegalStateException- if the validator returns null or a null violation
-
require
Checks one request parameter or header value and prefixes each violation's field path with the parameter name. This lets the sameValidatorrule set cover bodies (throughrequire(Validator, Object)) and values already parsed byContext's typed path, query and header accessors, with paths such asquery.qorheader.X-Api-Keyin the 422 problem response.- Type Parameters:
T- value type- Parameters:
field- safe property path naming the parameter; never derived from client inputvalidator- validator to runvalue- parsed value to check; may be null if the validator accepts null- Returns:
value- Throws:
ValidationException- with at mostMAX_VIOLATIONSviolations, in the order the validator reported them, when the value is invalidIllegalStateException- if the validator returns null or a null violation
-