swagger-api / swagger-api/swagger-codegen
[JavaJaxRs-resteasy] Missing @Valid annotation for bean-validation ( jaxrs-resteasy-eap generator)
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
- 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 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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