我已尝试在Swagger文档中添加更多信息,但我在具体问题上遇到了@ApiPropertyModel
注释的一些问题。
我尝试做什么并不重要,它只是不起作用。该插件正确生成Swagger.json
,所有@ApiOperation
注释都适用于REST资源,但对于模型部分,它只会对模型类进行内省检测。属性并没有查看它们上面的注释。
以下是插件的配置方式:
<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
属性,但它不会创建我在该注释中设置的任何示例或任何其他属性。在吸气剂中使用它时会发生同样的情况,所以我认为这不是问题。
我做错了吗? 另外,我查看了Kongchen的示例项目,我看不出有什么特别的东西能让它发挥作用。
答案 0 :(得分:1)
我试图再次弄乱代码,我发现问题出在项目的结构上。它具有不同的模块,它具有一般开发的配置文件和仅用于RESTful API文档的配置文件。
我分心了一段时间并开始使用mvn clean package
构建项目,因为它安装了项目的一个版本,它正在使用它来创建文档,这就是为什么它永远不会改变,在主要源代码中使用mvn clean install
后,我可以看到注释产生任何效果。
我很抱歉,除了我可以提供的关于文档项目的任何信息之外,因为它与我正在使用的整个结构有关。但至少我会保留这个答案,以便下一个人可能会意识到这一点。
感谢您的关注!
答案 1 :(得分:0)
也许您忘记了Model类的@ApiModel
注释?
像:
@ApiModel
public class PostRequest {
@ApiModelProperty(example = "test example")
public String test;
}
或您的模型包与pom.xml中的内容不匹配。