3

I have a basic problem with openapi maven codegen plugin. Validations annotation (maxLength, pattern) is missing in the java generated code.

Here is my pom:

   <dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>io.swagger.core.v3</groupId>
        <artifactId>swagger-annotations</artifactId>
        <version>2.0.9</version>
    </dependency

</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>io.swagger.codegen.v3</groupId>
            <artifactId>swagger-codegen-maven-plugin</artifactId>
            <version>3.0.11</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <inputSpec>${project.basedir}/src/main/resources/customer-service-api.yaml</inputSpec>
                        <output>${project.build.directory}/generated-sources</output>
                        <modelPackage>${default.package}.customer.model</modelPackage>
                        <generateModels>true</generateModels>
                        <generateApis>false</generateApis>
                        <generateApiTests>false</generateApiTests>
                        <generateSupportingFiles>false</generateSupportingFiles>
                        <language>java</language>
                        <library>resttemplate</library>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

and this is my swagger:

name:
  type: object
  properties:
    firstName:
      type: string
      pattern: "^[A-Z]{1,50}$"
      maxLength: 50

Now the generated java file is:

public class Name {
  @JsonProperty("firstName")
  private String firstName = null;

  @JsonProperty("middleName")
  private String middleName = null;

  @JsonProperty("lastName")
  private String lastName = null;

I expect to have RegularExpression on the attributes. so, I will be able to validate my java object by Java validator.

It works in RAML and its generated java code, and wondering why its not in my swagger's code.

Thanks,

Nav
  • 4,450
  • 10
  • 53
  • 84

0 Answers0