gpt4 book ai didi

java - Kongchen Swagger 忽略了 @ApiModelProperty 注释

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:35:27 25 4
gpt4 key购买 nike

我已尝试在我的 Swagger 文档中添加更多信息,但我在特定的 @ApiPropertyModel 注释方面遇到了一些问题。

不管我尝试做什么,它就是行不通。该插件正确生成 Swagger.json,所有 @ApiOperation 注释都适用于 REST 资源,但对于模型部分,它仅内省(introspection)模型类的属性并且不看上面的注释。

这是插件的配置方式:

<plugin>
<groupId>com.github.kongchen</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>3.1.5</version>

<configuration>
<apiSources>
<apiSource>
<locations>
<location>com.example.rest.resources</location>
<location>com.example.rest.model</location>
</locations>
<swaggerDirectory>${project.build.directory}/generated-sources</swaggerDirectory>
<basePath>/path/to/the/api</basePath>
<info>
<title>My RESTful API Documentation</title>
<version>${project.version}</version>
</info>
</apiSource>
</apiSources>
</configuration>

<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>

如果我有例如:

@ApiModelProperty(example = "test example")
public String test;

它将生成 test 属性,但不会创建任何示例或我在该注释中设置的任何其他属性。在 getter 中使用它时也会发生同样的情况,所以我认为这不是问题所在。

我做错了什么吗? 此外,我查看了 Kongchen 的示例项目,但我看不出有什么特别之处可以使其正常工作。

最佳答案

我再次尝试修改代码,发现问题出在项目的结构上。它有不同的模块,并且有一个用于一般开发的配置文件和一个仅用于 RESTful API 文档的配置文件。

我分心了一会儿,开始使用 mvn clean package 构建项目,因为它安装了项目的一个版本,所以它正在使用它来创建文档,这就是为什么它从未改变,在我在主要源代码中使用 mvn clean install 之后,我可以看到注释产生了任何效果。

抱歉,我无法提供有关文档项目的任何信息,因为它涉及我正在使用的整个结构。但至少我会保留这个答案,以便下一个人可能知道这一点。

感谢您的关注!

关于java - Kongchen Swagger 忽略了 @ApiModelProperty 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48030203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com