Spring REST Docs takes a test-driven approach to documenting RESTful APIs. It uses Spring MVC Test, Spring WebFlux’s WebTestClient or REST Assured to generate accurate, tested documentation snippets that can then be included in documentation written in Asciidoctor or Markdown. Use this tag for questions about Spring REST Docs and its interaction with one of the test frameworks and markup languages.
Questions tagged [spring-restdocs]
274 questions
46
votes
5 answers
What is the benefit of using Spring REST Docs comparing to Swagger
Spring REST Docs was released recently and the documentation says:
This approach frees you from the limitations imposed by tools like Swagger
So, I wanted to ask when Spring REST Docs is preferable to use comparing to Swagger and which limitations…

evgeniy44
- 2,862
- 7
- 28
- 51
37
votes
1 answer
pathParameters documentation exception (urlTemplate not found)
When using pathParameters to document the URI path parameters like below
@Test
public void documentGetRouteById() throws Exception {
this.mockMvc.perform(get("/route/{id}", "FooBar")).andExpect(status().isOk())
…

FrVaBe
- 47,963
- 16
- 124
- 157
15
votes
2 answers
How to document top-level array as response payload with Spring REST Docs
I am using Spring REST Docs to document a REST API. I'm trying to document the following API operations:
GET /subsystems
GET /subsystems/some_name
For example, a call to GET /subsystems/samba returns the following JSON object:
{
"id": "samba",
…

aaguilera
- 1,080
- 10
- 27
10
votes
2 answers
restdocs SnippetException due to HAL "_links" elements from spring-data-rest
My app is using spring-data-rest and spring-restdocs.
My setup is really standard; copied from the docs almost entirely, but I've included the samples below in case I'm missing something.
When my mvc test runs, it fails…

Eric J Turley
- 350
- 1
- 5
- 20
9
votes
2 answers
Spring Rest Doc not producing html
I followed the getting started guide for Spring Rest Doc word by word, but I cannot get any html out of the generated snippets.
The snippets are generated fine in the directory I configure (build/generated-snippets), but I can't see any html5/…

Francesco
- 857
- 1
- 11
- 26
8
votes
2 answers
Spring REST docs: How to migrate Rule to JUnit 5
I migrated my Spring tests to JUnit 5, and they work fine. However, I don't know how to migrate @Rule public JUnitRestDocumentation restDocumentation = ....
Any hint is appreciated.

Juergen Zimmermann
- 2,084
- 7
- 29
- 43
7
votes
1 answer
Configuring asciidoctor when using Spring Restdoc
I'm adopting Spring Rest Docs and the test successfully created *.adoc files.
I made api-guide.doc file in src/docs/asciidoc directory to create html, but when I run asciidoc as a gradle task, it produces the following error.
Some problems were…

pepsi
- 181
- 1
- 13
6
votes
2 answers
How to change host in curl snippet in Spring REST Docs
Spring REST Docs produces a curl snippet which is very convenient when testing. It is equivalent to the MockMvc call as said in its docs but it would be good if its host part can be replaced with a test server's hostname (including port) instead of…

Johnny Lim
- 5,623
- 8
- 38
- 53
5
votes
1 answer
jsonDoclet task: Javadoc generation failed
I am trying to setup spring-auto-restdocs in my project, which uses JDK 11, Gradle 5, JUnit5 and Spring Webflux with spring boot 2.1.1.
I've followed the normal spring-restdocs setup guide here:…

logi0517
- 813
- 1
- 13
- 32
5
votes
2 answers
How to format Spring REST Docs in response body with mockMvc
I write my API documentation with Spring REST Docs.
Code example:
@Override
public void getById(String urlTemplate, PathParametersSnippet pathParametersSnippet, Object... urlVariables) throws Exception {
resultActions =…

FreeOnGoo
- 868
- 1
- 8
- 26
5
votes
1 answer
Documenting null values with Spring REST Docs
Let's say we have the following API:
@RestController
public class PersonController {
@GetMapping("/api/person")
public List findPeople() {
return Arrays.asList(new Person("Doe", "Foo", "John"), new Person("Doe", null,…

g00glen00b
- 41,995
- 13
- 95
- 133
5
votes
1 answer
Documenting byte[] response in Spring Rest Docs
I am building an API and documenting it using Spring Rest Docs (1.1.1.RELEASE) and there is an api which returns an image as byte array.
I need to describe the response type in REST docs. I am not sure how this can be done using FieldDescriptor…

Tatha
- 1,253
- 2
- 24
- 42
5
votes
1 answer
Using tabs in AsciiDoc (Spring Rest Docs)
I'm using Spring Rest Docs to generate documentation. I would like to do something like Bootstrap's Togglable tabs.
Spring documentation uses togglable tabs, but I don't know how to do it. Here is an example (MockMvc / REST Assured):…

Bilal BBB
- 1,154
- 13
- 20
5
votes
2 answers
Grails 3 - Spring Rest Docs using Rest assured giving SnippetException when using JSON views
I am trying to integrate Spring REST docs with rest assured with Grails 3.1.4 application. I am using JSON Views.
Complete code is at https://github.com/rohitpal99/rest-docs
In NoteController when I use
List noteList = Note.findAll()
Map…

rohitpal
- 455
- 1
- 6
- 21
5
votes
2 answers
Spring REST mock context path
I try to set the context path for spring rest mocks using the following code snippet:
private MockMvc mockMvc;
@Before
public void setUp() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
…

Georg Heiler
- 16,916
- 36
- 162
- 292