Search code examples
javaspring-bootswagger-uiopenapispringdoc

Failed to load api definition when loading files from application properties


I have an openapi file generated through restdocs and converted into this format. They are added to the resources folder, and the properties file is pointing to their format, however, swagger is failing to load and I'm not sure what else I could be missing.

enter image description here

enter image description here

        <dependency>
            <groupId>org.springframework.restdocs</groupId>
            <artifactId>spring-restdocs-mockmvc</artifactId>
            <version>${spring-restdocs-mockmvc.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>${springdoc-openapi-ui.version}</version>
        </dependency>
        <dependency>
            <groupId>capital.scalable</groupId>
            <artifactId>spring-auto-restdocs-core</artifactId>
            <version>${spring-auto-restdocs-core.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.epages</groupId>
            <artifactId>restdocs-api-spec</artifactId>
            <version>${restdocs-api-spec.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.epages</groupId>
            <artifactId>restdocs-api-spec-mockmvc</artifactId>
            <version>${restdocs-api-spec.version}</version>
            <scope>test</scope>
        </dependency>

       <plugin>
                <groupId>io.github.berkleytechnologyservices</groupId>
                <artifactId>restdocs-spec-maven-plugin</artifactId>
                <version>${restdocs-spec.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <!--suppress MavenModelInspection -->
                            <skip>${skipTests}</skip>
                            <host>localhost:8081</host>
                            <specification>OPENAPI_V3</specification>
                            
     <outputDirectory>${project.build.directory}/classes/static/docs</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Thank you very much.


Solution

  • A related question was posted here and this answer solved the issue: https://stackoverflow.com/a/75273492/6654475

    In summary, it was related to this line that needed to be removed spring.web.resources.add-mappings=false and the yml file that needed to be moved to the resources/static/ folder.