use of io.vertx.ext.web.api.RequestParameter in project vertx-web by vert-x3.
the class BaseValidationHandler method validateHeaderParams.
private Map<String, RequestParameter> validateHeaderParams(RoutingContext routingContext) throws ValidationException {
// Validation process validate only params that are registered in the validation -> extra params are allowed
Map<String, RequestParameter> parsedParams = new HashMap<>();
MultiMap headersParams = routingContext.request().headers();
for (ParameterValidationRule rule : headerParamsRules.values()) {
String name = rule.getName();
if (headersParams.contains(name)) {
List<String> p = headersParams.getAll(name);
if (p.size() != 0) {
RequestParameter parsedParam = rule.validateArrayParam(p);
if (parsedParams.containsKey(parsedParam.getName()))
parsedParam = parsedParam.merge(parsedParams.get(parsedParam.getName()));
parsedParams.put(parsedParam.getName(), parsedParam);
} else {
throw ValidationException.ValidationExceptionFactory.generateNotMatchValidationException(name + " can't be empty");
}
} else if (rule.parameterTypeValidator().getDefault() != null) {
RequestParameter parsedParam = new RequestParameterImpl(name, rule.parameterTypeValidator().getDefault());
if (parsedParams.containsKey(parsedParam.getName()))
parsedParam = parsedParam.merge(parsedParams.get(parsedParam.getName()));
parsedParams.put(parsedParam.getName(), parsedParam);
} else if (!rule.isOptional())
throw ValidationException.ValidationExceptionFactory.generateNotFoundValidationException(name, ParameterLocation.HEADER);
}
return parsedParams;
}
use of io.vertx.ext.web.api.RequestParameter in project vertx-web by vert-x3.
the class BaseValidationHandler method validateFormParams.
private Map<String, RequestParameter> validateFormParams(RoutingContext routingContext) throws ValidationException {
// Validation process validate only params that are registered in the validation -> extra params are allowed
Map<String, RequestParameter> parsedParams = new HashMap<>();
MultiMap formParams = routingContext.request().formAttributes();
for (ParameterValidationRule rule : formParamsRules.values()) {
String name = rule.getName();
if (formParams.contains(name)) {
List<String> p = formParams.getAll(name);
if (p.size() != 0) {
RequestParameter parsedParam = rule.validateArrayParam(p);
if (parsedParams.containsKey(parsedParam.getName()))
parsedParam = parsedParam.merge(parsedParams.get(parsedParam.getName()));
parsedParams.put(parsedParam.getName(), parsedParam);
} else {
throw ValidationException.ValidationExceptionFactory.generateNotMatchValidationException(name + " can't be empty");
}
} else if (rule.parameterTypeValidator().getDefault() != null) {
RequestParameter parsedParam = new RequestParameterImpl(name, rule.parameterTypeValidator().getDefault());
if (parsedParams.containsKey(parsedParam.getName()))
parsedParam = parsedParam.merge(parsedParams.get(parsedParam.getName()));
parsedParams.put(parsedParam.getName(), parsedParam);
} else if (!rule.isOptional())
throw ValidationException.ValidationExceptionFactory.generateNotFoundValidationException(name, ParameterLocation.BODY_FORM);
}
return parsedParams;
}
use of io.vertx.ext.web.api.RequestParameter in project vertx-web by vert-x3.
the class BaseValidationHandler method validateQueryParams.
private Map<String, RequestParameter> validateQueryParams(RoutingContext routingContext) throws ValidationException {
// Validation process validate only params that are registered in the validation -> extra params are allowed
Map<String, RequestParameter> parsedParams = new HashMap<>();
MultiMap queryParams = routingContext.queryParams();
for (ParameterValidationRule rule : queryParamsRules.values()) {
String name = rule.getName();
if (queryParams.contains(name)) {
List<String> p = queryParams.getAll(name);
if (p.size() != 0) {
RequestParameter parsedParam = rule.validateArrayParam(p);
if (parsedParams.containsKey(parsedParam.getName()))
parsedParam = parsedParam.merge(parsedParams.get(parsedParam.getName()));
parsedParams.put(parsedParam.getName(), parsedParam);
} else {
throw ValidationException.ValidationExceptionFactory.generateNotMatchValidationException(name + " can't be empty");
}
} else if (rule.parameterTypeValidator().getDefault() != null) {
RequestParameter parsedParam = new RequestParameterImpl(name, rule.parameterTypeValidator().getDefault());
if (parsedParams.containsKey(parsedParam.getName()))
parsedParam = parsedParam.merge(parsedParams.get(parsedParam.getName()));
parsedParams.put(parsedParam.getName(), parsedParam);
} else if (!rule.isOptional())
throw ValidationException.ValidationExceptionFactory.generateNotFoundValidationException(name, ParameterLocation.QUERY);
}
return parsedParams;
}
use of io.vertx.ext.web.api.RequestParameter in project vertx-web by vert-x3.
the class BaseValidationHandler method validatePathParams.
private Map<String, RequestParameter> validatePathParams(RoutingContext routingContext) throws ValidationException {
// Validation process validate only params that are registered in the validation -> extra params are allowed
Map<String, RequestParameter> parsedParams = new HashMap<>();
Map<String, String> pathParams = routingContext.pathParams();
for (ParameterValidationRule rule : pathParamsRules.values()) {
String name = rule.getName();
if (pathParams.containsKey(name)) {
RequestParameter parsedParam = rule.validateSingleParam(pathParams.get(name));
if (parsedParams.containsKey(parsedParam.getName()))
parsedParam = parsedParam.merge(parsedParams.get(parsedParam.getName()));
parsedParams.put(parsedParam.getName(), parsedParam);
} else
// Path params are required!
throw ValidationException.ValidationExceptionFactory.generateNotFoundValidationException(name, ParameterLocation.PATH);
}
return parsedParams;
}
use of io.vertx.ext.web.api.RequestParameter in project vertx-web by vert-x3.
the class OpenAPI3ValidationTest method testQueryParameterArrayDefaultStyle.
@Test
public void testQueryParameterArrayDefaultStyle() throws Exception {
Operation op = testSpec.getPaths().get("/queryTests/arrayTests/default").getGet();
OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec);
loadHandlers("/queryTests/arrayTests/default", HttpMethod.GET, false, validationHandler, (routingContext) -> {
RequestParameters params = routingContext.get("parsedParameters");
List<String> result = new ArrayList<>();
for (RequestParameter r : params.queryParameter("parameter").getArray()) result.add(r.getInteger().toString());
routingContext.response().setStatusMessage(serializeInCSVStringArray(result)).end();
});
List<String> values = new ArrayList<>();
values.add("4");
values.add("2");
values.add("26");
testRequest(HttpMethod.GET, "/queryTests/arrayTests/default?parameter=" + serializeInCSVStringArray(values), 200, serializeInCSVStringArray(values));
}
Aggregations