Search code examples
javamavenannotationsswaggerimporterror

Cannot import @ApiParam or @ApiModelProperty annotation even though Swagger is added as 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:

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.

In my POM.xml I added Swagger as the following dependency:

<!-- 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. Thanks for the help!


Solution

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

    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.