【问题标题】:swagger codegen jaxrs validationswagger codegen jaxrs 验证
【发布时间】:2017-06-18 21:16:01
【问题描述】:

有没有办法让swagger codegen为路径参数和输出模型的验证添加jaxrs验证注解。

我的意思是以下代码中的@Valid 和@NotNull 注释:

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

谢谢!

【问题讨论】:

  • 你必须自己扩展swagger codegen才能添加bean验证。
  • maven 插件版本 2.2.2 有一个 'useBeanValidation' 选项。我们正在使用的 jaxrs/cxf 的一些 mustache 模板引用了这个条目(参见例如 beanValidation.mustache 和 queryParams.mustache)。但是,pathParam.mustache 似乎没有使用它,这就解释了为什么插件不会为路径参数生成 bean 验证。

标签: jax-rs swagger swagger-codegen


【解决方案1】:

您还可以使用 maven 插件生成代码并将 javax.validation 添加为依赖项

 <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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    • 2016-04-21
    • 2021-10-10
    • 2017-01-01
    • 2015-10-13
    相关资源
    最近更新 更多