use of com.linkedin.data.schema.validation.ValidationResult in project rest.li by linkedin.
the class ActionArgumentBuilder method extractRequestData.
@Override
public RestLiRequestData extractRequestData(RoutingResult routingResult, DataMap data) {
ResourceMethodDescriptor resourceMethodDescriptor = routingResult.getResourceMethod();
if (data == null) {
data = new DataMap();
}
DynamicRecordTemplate template = new DynamicRecordTemplate(data, resourceMethodDescriptor.getRequestDataSchema());
ValidationResult result = ValidateDataAgainstSchema.validate(data, template.schema(), new ValidationOptions(RequiredMode.IGNORE, CoercionMode.NORMAL));
if (!result.isValid()) {
throw new RoutingException("Parameters of method '" + resourceMethodDescriptor.getActionName() + "' failed validation with error '" + result.getMessages() + "'", HttpStatus.S_400_BAD_REQUEST.getCode());
}
return new RestLiRequestDataImpl.Builder().entity(template).build();
}
Aggregations