When I launch my request, the ConstraintViolationException does not want to be thrown for a field with a regex in the contract
Here the request in postman
apiName/v1/account?cardNumer=55^fields=customerName
Here the contract AccountApi with a regex on the field cardNumber
@Pattern(regexp = "^[0-9]{6}[A-Z][0-9]{9}$") @Parameter(name = "cardNumber")
Here the Controller.java with the @Validated annotation
The AccountController .java implements AccountApi which is the contract
@RestController
@Validated
@Slf4j
public class AccountController implements AccountApi {
@Override
public ResponseEntity<List<Account>> getAccount(String cardNumer) {
}
}
Here the AccountControllerExceptionHandler.java with the ConstraintViolationException
@ControllerAdvice
public class AccountControllerExceptionHandler{
@ExceptionHandler(value = {ConstraintViolationException.class})
@ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST)
public Error manageErrorRegexViolation(final ConstraintViolationException e, HttpServletResponse response) {
log.error("Error ConstraintViolationException {}.", e.getMessage());
}
}
The regex in the contract for the field cardNumber is here
The @Validated annotation in the Controller is here
The ConstraintViolationException in the ExceptionHandler.java is here
In others threads they only said to add thoses 3 things