adding an `isOptional` in MultipartCustomValidator
Since a parameter can be 'not required', if it is not in the request, it
does not mean it's an error
@@ -26,10 +26,12 @@ public class OpenAPI3RequestValidationHandlerImpl extends HTTPOperationRequestVa
Pattern contentTypePattern;
String parameterName;
+ boolean isOptional;
- public MultipartCustomValidator(Pattern contentTypeRegex, String parameterName) {
+ public MultipartCustomValidator(Pattern contentTypeRegex, String parameterName, boolean isOptional) {
this.contentTypePattern = contentTypeRegex;
this.parameterName = parameterName;
+ this.isOptional = isOptional;
}
private boolean existFileUpload(Set<FileUpload> files, String name, Pattern contentType) {
@@ -42,7 +44,7 @@ public class OpenAPI3RequestValidationHandlerImpl extends HTTPOperationRequestVa
@Override
public void validate(RoutingContext routingContext) throws ValidationException {
if (!existFileUpload(routingContext.fileUploads(), parameterName, contentTypePattern)) {
- if (!routingContext.request().formAttributes().contains(parameterName))
+ if (!routingContext.request().formAttributes().contains(parameterName) && !isOptional)
throw ValidationException.ValidationExceptionFactory.generateNotFoundValidationException(parameterName,
ParameterLocation.BODY_FORM);
}
