Enable preview of Spring REST Docs snippets in IntelliJ IDEA

Posted at — Jul 24, 2017

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:

screen shot 2017 07 24 at 14 12 36

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:

:snippets: ../../../target/generated-snippets

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:

screen shot 2017 07 24 at 14 13 51

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.

If you want to be notified in the future about new articles, as well as other interesting things I'm working on, join my mailing list!
I send emails quite infrequently, and will never share your email address with anyone else.