swagger-api / swagger-api/swagger-codegen

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

Open
#10,994 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Swagger-codegen version

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 at all.

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 https://github.com/swagger-api/swagger-codegen/pull/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: https://github.com/swagger-api/swagger-codegen/pull/5517 but for JavaJaxRs.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the mustache templates used by the jaxrs-resteasy-eap generator and compare their handling with the Java generator change in PR 5517. Reproduce the example through swagger-codegen-maven-plugin; done means the generated MyObjectApi includes @Valid and constrained input produces the expected validation failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.