0

I have a final project that I am trying to complete to finish my program. I am still kind of a newbie to back end, so I am not entirely sure what I need to show you here in terms of code.

I created a project using Spring Tool Suite, i have my controller, service, entity and DAO layers all set up. But when I run the app and try to access Swagger I am getting the "no operations defined in spec!" error. I met with one of my class mentors and she gave me access to her project, and everything seems to matchup with my project. So this has me thinking that it has to be something in the configuration or setup. This is my pom file(which also exactly mirrors my mentors pom file, and she has no issues). I have spent the last week searching the entire internet and have not been able to find a solution. Any suggestions or help you can provide is TRULY appreciated. Thanks!

<?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>2.7.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    
    <groupId>com.danceevents</groupId>
    <artifactId>Dance-Events</artifactId> <!-- come back to this if there is an error -->
    <version>0.0.1-SNAPSHOT</version>
    <name>Dance-Events</name>
    <description>Dance-Events</description>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        
                <!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui -->
<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>1.6.9</version>
</dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jdbc</artifactId>
    
    
 
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
  
</dependency>

        
    </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>
JarveyD
  • 1
  • 2
  • The error is telling you that your OpenAPI Specification, obviously documented via Springdoc, cannot find any documented endpoints. How do you configure Springdoc, are you using a openapi.yaml file or java annotations to document on the fly? If you're using annotations take a look at [Springdoc](https://springdoc.org/), you're missing a dependency `org.springdoc:springdoc-openapi-webmvc-core` for Spring MVC documentation. – 0x1C1B Jul 03 '22 at 12:04
  • Thank you so much for jumping in! I have an application.yaml file that is currently just pointing to spring, datasource, with username & password and the URL. – JarveyD Jul 03 '22 at 12:11
  • `application.yaml` and `openapi.yaml` are completely different files, the first one is configuring Spring as application and the latter is used to document RESTful endpoints using the [OpenAPI Format](https://spec.openapis.org/oas/latest.html), don't mix them up. But I guess you should using java annotations like `@Tag` and `@Operation` to document endpoints. Hence take a look at the [Springdoc Documentation](https://springdoc.org). – 0x1C1B Jul 03 '22 at 12:16
  • 1
    Can you show a short piece of code (a method heading) that you think should show up in Swagger? (doesn't have a complete [mre] in this case, you can omit the actual implementation) – cyberbrain Jul 03 '22 at 12:22
  • it can also happen when property springdoc.packagesToScan is not set in application.properties – Anand Nov 04 '22 at 07:39

1 Answers1

0

https://stackoverflow.com/a/76374465/4085134

@Configuration
@EnableSwagger2
@Import(SpringDataRestConfiguration.class)
public class SwaggerConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("org.zaid.aitfriha.controller.api"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo());
    }
Ait Friha Zaid
  • 1,222
  • 1
  • 13
  • 20