-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Validation of the requestbody is not triggered while bean-validation
is true
in the configuration.
I think because the @Valid
annotation is missing for the method arguments in the generated code.
If I add the @Valid
annotation in the method implementation, I get an exception:
javax.validation.ConstraintDeclarationException: HV000151: A method overriding another method must not redefine the parameter constraint configuration, but method TestRequest#setSomeBoolean(Boolean) redefines the configuration of CreateTestRequest#setSomeBoolean(Boolean).
CreateTestRequest & TestRequest (with lombok):
@Data
public class CreateTestRequest {
@NotNull
private Boolean someBoolean;
}
@Data
public class TestRequest extends CreateTestRequest {
@NotNull
private Long id;
}
TestRequest
is a subclass of CreateTestRequest
where the javax constraints are.
I use specific type mapping to generate the code:
openapi-processor-mapping: v2
options:
package-name: com.apis.test
one-of-interface: true
bean-validation: true
generated-date: true
format-code: false
javadoc: false
map:
result: org.springframework.http.ResponseEntity
types:
- type: TestRequest => com.apis.custom.TestRequest
- type: CreateTestRequest => com.apis.custom.CreateTestRequest
Generated code:
@PutMapping(path = "/api/test/{id}", consumes = {"application/json"}, produces = {"application/json"})
ResponseEntity<TestResponse> update(
@PathVariable(name = "id") @NotNull @DecimalMin(value = "1") Long id,
@RequestBody @NotNull TestRequest body);
Implementation:
@Override
public ResponseEntity<TestResponse> update(
final Long id,
final TestRequest input) {
// implementation
}