0

I'm trying to generate documentation for my API and i used SpringDoc for this task and i'm using maven with the following pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.app</groupId>
    <artifactId>TodoApp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>TodoApp</name>
    <description>TodoApp</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>

        <!-- AOP ( Aspect Oriented Programing-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>
        <!-- AOP ( Aspect Oriented Programing-->

        <!-- Adding Swagger Dependencies -->
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>2.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
            <version>2.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webflux-ui</artifactId>
            <version>2.0.2</version>
        </dependency>
        <!-- end of Swagger Dependencies -->

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
  • I have 3 controllers ( TaskController , UserController , RestExceptionHandlerController )

  • only 2 classes annotated with @Entity ( Task , User )

and when I open swagger doc the following appears to me

I don't need additional controllers or schemas to appear in the API doc what should I do?

  • Please clarify which of these APIs you are calling additional controller? Are you creating them? Then you can add swagger `@Hidden` annotation on top the controller class to hide its docs – Snigdhajyoti Mar 09 '23 at 19:29
  • ok but not using any of controller named profile-controller in my controllers or schemas rather than ( User and Task ) – Youssef Gamal Mar 09 '23 at 19:37
  • Additional schema is for Request Response classes, your user should know abt it. – Snigdhajyoti Mar 09 '23 at 19:46
  • ok I know that but still, the problem is that profile-controller does not exist in my project and it appears out of nowhere – Youssef Gamal Mar 09 '23 at 19:50
  • So its not the question on disable swagger doc for some controller classes, its about from where this ghost controller is coming. – Snigdhajyoti Mar 09 '23 at 19:54
  • I can see you have added `spring-boot-starter-data-rest`, this is directly expose your entity classes as a controller without any extra config. Is this what you want? then your swagger is ok. You can try to looking a solution to disable swagger for `spring-boot-starter-data-rest` – Snigdhajyoti Mar 09 '23 at 19:57
  • I tried to remove the dependency of spring-boot-starter-data-rest and it works right – Youssef Gamal Mar 09 '23 at 22:23
  • Cool. Ideally dont add any dependency you dont know of – Snigdhajyoti Mar 10 '23 at 06:30

0 Answers0