Enable preview of Spring REST Docs snippets in IntelliJ IDEA

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:

Preview IntelliJ IDEA with Asciidoc plugin

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:

Preview with working include statements

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s