繁体   English   中英

Kongchen Swagger忽略了@ApiModelProperty注释

[英]Kongchen Swagger is ignoring the @ApiModelProperty annotation

我试图在我的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的示例项目,我看不出有什么特别的东西让它起作用。

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

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

我很抱歉,这超出了我可以提供的关于文档项目的任何信息,因为它是关于我正在使用的整个结构的东西。 但至少我会保留这个答案,以便下一个人可能会意识到这一点。

感谢您的关注!

也许你忘记了Model类的@ApiModel注释?

喜欢:

@ApiModel
public class PostRequest {

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

}

或者您的模型包与pom.xml中给出的内容不匹配。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM