0

Is there a way to get swagger codegen to add jaxrs validation annotations for the validation of path parameters and output model.

I mean the @Valid and @NotNull annotations in the following code:

@Path("/person/{personId}")
@GET
@Valid
public Response getPerson(@NotNull @PathParam Integer personId) {    
    // TO Do
}

Thanks!

medalik
  • 139
  • 1
  • 10
  • 1
    You have to extend swagger codegen by yourself to add bean validation. – ByeBye Jun 19 '17 at 05:45
  • 1
    The maven plugin version 2.2.2 has a 'useBeanValidation' option. Some of the mustache templates for jaxrs/cxf which we are using, are referring this entry (see for example beanValidation.mustache and queryParams.mustache). However, pathParam.mustache doesn't seem to be using it, which explains why the plugin does not generate bean validation for path parameters. – medalik Jun 20 '17 at 14:57

1 Answers1

0

You can also use a maven plugin to generate code and add the javax.validation as dependency

 <plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>${openapi-generator-maven-plugin.version}</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            ...
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>${validation-api.version}</version>
        </dependency>
    </dependencies>
</plugin>
sa_vedem
  • 757
  • 1
  • 7
  • 16