If you use Spring REST Docs, you will be using the Asciidoctor
include directive a lot to include the request and responses that are generated from the unit tests. Drawback is that the Asciidoctor plugin for IntelliJ IDEA will not render them by default and looks like this:
The reason is simple, the
snippets attribute is only available when running the Maven or Gradle task to build the final documentation.
As a workaround, you can add the following at the top of your document:
ifndef::snippets :snippets: ../../../target/generated-snippets endif::
We use the ifndef directive to define the
snippets attribute in case the build system did not define it yet.
Now the preview works nicely:
Note that it will only work if you are using default locations for the asciidoc source files and the generated snippets. Adjust the path if you use something else.