I am basically starting using spring rest docs to generate the documentation of my rest services. The problem is that I don't know how can I visualize the documentation from my application. I was suposse to see the results in: http://localhost:8080/docs/index.html. But when I open this url I'm seeing the issue: Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed May 22 22:36:46 COT 2019 There was an unexpected error (type=Not Found, status=404). No message available
I have used the nex tutorial step by step: https://spring.io/guides/gs/testing-restdocs/. I was able to follow all the steps and now in my project I have the snippets:
And also the index.html page was created in the path: target/generated-docs/index.html:
In my pom.xml I have added the next plugin:
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.6</version>
<executions>
<execution>
<id>generate-docs</id>
<phase>prepare-package</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<sourceDocumentName>index.adoc</sourceDocumentName>
<backend>html</backend>
<attributes>
<snippets>${project.build.directory}/snippets</snippets>
</attributes>
</configuration>
</execution>
</executions>
</plugin>
Finally I am runing my application with the next class:
@Configuration
@Order(Ordered.HIGHEST_PRECEDENCE)
@EnableAutoConfiguration
@ComponentScan(
basePackages = [
"com.espn.csemobile.espnapp",
"com.espn.personalization"]
)
open class SportscenterProductApi
fun main(args: Array<String>) {
val app = SpringApplication(SportscenterProductApi::class.java)
app.setBannerMode(Mode.LOG)
app.setLogStartupInfo(true)
app.run(*args)
}
Any ideas?
As described in the documentation, you need to configure your build to copy the generated HTML into a location where it'll be packaged in your app.
Add the following plugin configuration to your pom.xml
after the configuration of the asciidoctor-maven-plugin
:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.outputDirectory}/static/docs
</outputDirectory>
<resources>
<resource>
<directory>
${project.build.directory}/generated-docs
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
This should make the documentation be available at http://localhost:8080/docs/index.html.