[英]Can not import @ApiParam or @ApiModelProperty annotation eventough Swagger is added as a Maven dependency
I am working on a project where we document our backend's API with Swagger. I would like to use annotation based configuration for Swagger. For my controller classes using @Tag
, @Operation
and @ApiResponses
works just fine and they can be imported with the following statements:我正在做一个项目,我们用 Swagger 记录后端的 API。我想对 Swagger 使用基于注释的配置。对于我的 controller 类,使用
@Tag
、 @ApiResponses
@Operation
得很好,它们可以用以下导入声明:
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
However if I try to add either @ApiParam
or @ApiModel
to my code, I am unable to import them in any way.但是,如果我尝试将
@ApiParam
或@ApiModel
添加到我的代码中,我将无法以任何方式导入它们。
In my POM.xml
I added Swagger as the following dependency:在我的
POM.xml
中,我添加了 Swagger 作为以下依赖项:
<!-- https://mvnrepository.com/artifact/io.swagger.core.v3/swagger-annotations -->
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.1.11</version>
</dependency>
What is it that I am missing here?我在这里想念什么? I tried following this Baeldung article and example code, however I could not get it to work.
我尝试遵循 这篇 Baeldung 文章和示例代码,但是我无法让它工作。 Thanks for the help!
谢谢您的帮助!
The "problem" was that Springdoc is used and originally I made the assumption that Springfox or a plain Swagger 2 dependency is used, as it was not removed from the codebase. “问题”是使用了Springdoc ,最初我假设使用 Springfox 或普通的 Swagger 2 依赖项,因为它没有从代码库中删除。
To fix the issue, we just simply need to add the right dependency and use the new annotations, which are mapped to the old ones like explained here .为了解决这个问题,我们只需要添加正确的依赖项并使用新的注解,这些注解会映射到旧的注解,就像这里解释的那样。
@ApiParam -> @Parameter @ApiParam -> @参数
example例子
@ApiParam(value = "xyz", example = "xyz")
becomes成为
@Parameter(description = "xyz", example = "xyz")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.