Unable to load custom openapi.yaml file using springdoc-openapi-starter-webmvc-ui

830 views Asked by At

I am using Spring Boot 3 and the library springdoc-openapi-starter-webmvc-ui for swagger documentation. The swagger ui works fine http://localhost:8080/swagger-ui/index.html when it reads from the existing controllers. My current dependencies are as follows -

        <!-- Swagger dependency-->
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>2.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>webjars-locator</artifactId>
            <version>0.45</version>
        </dependency>

But now I am trying to use a custom yaml file which has the openapi specs defined in it. For this I added the following in my application.properties file

springdoc.api-docs.path=classpath:/swagger-config.yaml

On running the server again, the same swagger link gives the following error Failed to load remote configuration. enter image description here

I tried various other configurations, but none seem to pick up the specs from the swagger-config.yaml file. Any inputs here would be highly helpful !!!

Please note that my swagger-config.yaml is a valid file and it works perfectly fine in the online swagger editor.

1

There are 1 answers

2
IceMajor On

The property you'll want to set is springdoc.swagger-ui.url not springdoc.api-docs.path.

springdoc.swagger-ui.url=/swagger-config.yml should do the trick.

Also, note that the YML file should be put inside src/main/resources/static directory.