swagger-api / swagger-api/swagger-codegen

[Spring] Support @Validated

Open
#10,203 0 comments 4 reactions 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

Description

Add support for @org.springframework.validation.annotation.Validated

IF useBeanValidation and performBeanValidation are true
THEN should be @Validated on generated Api & ApiController classes

Swagger-codegen version

3.0.18

Example 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>
Expected behavior

Should be Api containing @Validated generated

import org.springframework.validation.annotation.Validated;

@Validated
public interface DemoApi {
 ...
}

Currently @Validated annotation is missing.

Suggest a fix/enhancement

Add to api.mustache & apiController.mustache next line:

{{#useBeanValidation}}{{#performBeanValidation}}@Validated{{/performBeanValidation}}{{/useBeanValidation}}

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

Open api.mustache and apiController.mustache and review how useBeanValidation and performBeanValidation control generated annotations. Generate Spring Api and ApiController classes with both options enabled and verify that each includes the Validated import and annotation; confirm the annotation is absent when either option is disabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
tooling
Issue type
Feature
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.