swagger-api / swagger-api/swagger-codegen
[Spring] Support @Email constraint
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Add support for @javax.validation.constraints.Email
IF useBeanValidation and performBeanValidation are true
AND format: email specified for path param
THEN should be @Email on parameter
Swagger-codegen-maven-plugin version
3.0.18
pom.xml
<plugins>
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<executions>
<execution>
...
<configuration>
...
<language>spring</language>
<configOptions>
<useBeanValidation>true</useBeanValidation>
<performBeanValidation>true</performBeanValidation>
...
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Swagger declaration file content
paths:
/users/{email}:
get:
operationId: getUserByEmail
parameters:
- in: path
name: email
schema:
type: string
format: email
Expected behavior
From yaml above should be method containing @Email constraint generated:
import javax.validation.constraints.Email;
...
@RequestMapping(value = "/users/{email}", produces = { "application/json" }, method = RequestMethod.GET)
ResponseEntity<User> getUserByEmail(@Email @PathVariable("email") String email);
Currently @Email annotation is missing.
Suggest a fix/enhancement
-
Add to
CodegenParameter.class&CodegenProperty.classnew variableboolean isEmailand implement all necessary logic. -
Add to
beanValidationCore.mustachenext line:
{{#useBeanValidation}}{{#performBeanValidation}}{{#isEmail}}@Email{{/isEmail}}{{/performBeanValidation}}{{/useBeanValidation}}
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 by tracing how CodegenParameter.class and CodegenProperty.class represent schema formats, then inspect beanValidationCore.mustache and the Spring generator's existing validation handling. Add email-format support so the template emits @Email only when useBeanValidation and performBeanValidation are enabled, and verify the generated path-parameter signature matches the issue's example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100