Sample Micronaut project demonstrating how to use validation with Jakarta Validation API.
This is a direct translation of Quarkus' validation-quickstart project.
- In Micronaut one must use
@io.micronaut.validation.Validated
to be able to activate the validation; merely using@jakarta.validation.Valid
is not enough.@Validated
had to be used on bothBookResource
controller andBookService
. - The Restassured tests methods must use an argument
RequestSpecification
otherwise the library won't be able to connect to the test server. - The test method
BookResourceTest#testBookWithoutTitleEndPointValidation
had to be adjusted to account for the error response:
{
"message": "Bad Request",
"_links": {
"self": {
"href": "/books/end-point-method-validation",
"templated": false
}
},
"_embedded": {
"errors": [
{
"message": "book.title: Title cannot be blank"
}
]
}
}
Contrast this with Quarkus' simpler response:
{
"title": "Constraint Violation",
"status": 400,
"violations": [
{
"field": "tryMeEndPointMethodValidation.book.title",
"message": "Title cannot be blank"
}
]
}