Reputation: 4136
I have my api documentation generated by restdocs through unit tests. Although it works fine for most of my needs, I'm still lacking a bit of the nice swagger features, so I was trying to have the best of both words by converting the restdocs into swagger. After trying for a long time, I finally managed to get it done with the help of some third part libraries (https://github.com/ePages-de/restdocs-api-spec https://github.com/BerkleyTechnologyServices/restdocs-spec). This generates the open api files under the static docs folder. However, when I try to access the swagger url http://localhost:8081/swagger-ui/index.html, It wouldn't show it there, which would have worked by default if adding swagger directly with the swagger annotation on the controller. I can manually import the openapi yml file and see it through the https://editor.swagger.io/ but there may be a better way to map swagger to automatically find the openapi files directly from my code so I can keep using the default swagger url for this?
Thank you.
<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>
UPDATE
Trying with the docs under the resources folder, but still getting the same error. I've opened a new question with details here Failed to load api definition when loading files from application properties
Upvotes: 1
Views: 4895
Reputation: 163
You have need to put the openapi specification yml in the resource folder and set springdoc.swagger-ui.url=/openapi-3.yaml
in the application.properties file of spring boot app.
Checkout springdoc api documentation
In application properties need to make sure
spring.web.resources.add-mappings=false
shouldn't be added its preventing to serve static content.
Also openapi-3.0.yml
should be placed inside of resources/static
folder.
Upvotes: 1