'Spring + OpenAPI3 getting Swagger 404 when using static openApi.yaml file

I have a simple spring application setup, with an openAPI dependency, in my pom file I added:

    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-ui</artifactId>
        <version>1.6.6</version>
    </dependency>

and I put a sample openapi.yaml file in the static resource folder, I then followed the instructions in the document:

  1. Turn off auto-generation in the project property file:

    springdoc.api-docs.enabled=false
    
  2. Put your yaml file in src/main/resources/static such as src/main/resources/static/myApiFile.yaml

  3. Set the swagger-ui URL for the file:

    springdoc.swagger-ui.url=/myApiFile.yaml
    
  4. Enable the minimal beans configuration:

    @Configurationpublic class SpringDocsConfiguration {
    @Bean
    SpringDocConfiguration springDocConfiguration() {return new SpringDocConfiguration();}
    @Bean
    public SpringDocConfigProperties springDocConfigProperties() {return new SpringDocConfigProperties();}}
    

When I run the application and go to the URL: localhost:8080/swagger-ui.html, it shows that the .yaml file can not be fetched:

Here is my 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.dao.diy</groupId>
        <artifactId>ADO-Diy</artifactId>
        <version>1.0</version>
    </parent>

<!--    <groupId>org.dao.diy</groupId>-->
    <artifactId>backend</artifactId>
    <name>backend</name>
<!--    <version>0.0.1-SNAPSHOT</version>-->


    <packaging>war</packaging>

<!--    <name>backend</name>-->
    <description>backend</description>


    <properties>
        <java.version>11</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-mongodb</artifactId>-->
<!--        </dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-oauth2-client</artifactId>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
<!--            <artifactId>spring-boot-starter-security</artifactId>-->
<!--        </dependency>-->
        <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>com.h2database</groupId>
            <artifactId>h2</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-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>org.springframework.security</groupId>-->
<!--            <artifactId>spring-security-test</artifactId>-->
<!--            <scope>test</scope>-->
<!--        </dependency>-->

        
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.6.6</version>
        </dependency>

    </dependencies>

    <build>
      <finalName>ADO-DIY-TESTING</finalName>
        <plugins>

            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>./src/main/resources/static/</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>../frontend/dist/frontend/</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

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


        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>
    </build>

</project>

My debugging steps include:

  1. Following the documentation
  2. Googling for existing solutions
  3. Changing file locations
  4. Trying different configuration combinations


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source