swagger-codegen-generators icon indicating copy to clipboard operation
swagger-codegen-generators copied to clipboard

[JavaJaxRs-resteasy] Missing @Valid annotation for bean-validation ( jaxrs-resteasy-eap generator)

Open fperie opened this issue 4 years ago • 0 comments

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

  1. Define a component with restrictions (on size with maxLength=36 for example) and a create_myobject path endpoint

  2. Generate the java code with swagger-codegen-maven-plugin plugin and jaxrs-resteasy-eap generator

  3. You'll find @Size(max=36) on your model object, but no @Valid on your MyObjectApi

  4. 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.

fperie avatar Apr 29 '21 09:04 fperie