[JavaJaxRs-resteasy] Missing @Valid annotation for bean-validation ( jaxrs-resteasy-eap generator)
Versions
1.0.25 - swagger-codegen-generators
3.0.25 - swagger-codegen-maven-plugin - generator jaxrs-resteasy-eap
Description
I generate java components from swagger with the jaxrs-resteasy-eap generator using swagger-codegen-maven-plugin maven plugin.
I define my "components" objects with validation restrictions such as maxLength:, given in the following example :
components:
schemas:
MyObject:
type: object
properties:
uuid:
type: string
maxLength: 36
The problem is that the Java Code generated for MyObjectApi does not contain @Valid annotations and thus, validation is not properly working.
Steps to reproduce
-
Define a component with restrictions (on size with
maxLength=36for example) and a create_myobject path endpoint -
Generate the java code with
swagger-codegen-maven-pluginplugin andjaxrs-resteasy-eap generator -
You'll find
@Size(max=36)on your model object, but no@Validon yourMyObjectApi -
Launch the project, and call your endpoint with an attribute that exceed the restriction (in my example, the
uuid.length> 36).
The endpoint will be working instead of returning a 400 Bad request and ValidationException as expected.
Related issues/PRs
Same issue but with Java generator : PR #5517
Suggest a fix/enhancement
We could add the @Valid annotation to mustache template for generator jaxrs-resteasy-eap similar to what can be found in this PR: #5517 but for JavaJaxRs.