Add support for automating the documentation of HAL Links
This commit is contained in:
@@ -132,15 +132,7 @@ include::{generated}/index-example/response.asciidoc[]
|
||||
[[resources-index-links]]
|
||||
==== Links
|
||||
|
||||
|===
|
||||
| Relation | Description
|
||||
|
||||
| notes
|
||||
| The <<resources-notes,Notes resource>>
|
||||
|
||||
| tags
|
||||
| The <<resources-tags,Tags resource>>
|
||||
|===
|
||||
include::{generated}/index-example/links.asciidoc[]
|
||||
|
||||
|
||||
|
||||
@@ -270,15 +262,7 @@ The Note resource is used to retrieve, update, and delete individual notes
|
||||
[[resources-note-links]]
|
||||
=== Links
|
||||
|
||||
|===
|
||||
| Relation | Description
|
||||
|
||||
| self
|
||||
| This <<resources-note,note>>
|
||||
|
||||
| note-tags
|
||||
| This note's <<resources-note-tags,tags>>
|
||||
|===
|
||||
include::{generated}/note-get-example/links.asciidoc[]
|
||||
|
||||
|
||||
|
||||
@@ -347,15 +331,7 @@ The Tag resource is used to retrieve, update, and delete individual tags
|
||||
[[resources-tag-links]]
|
||||
=== Links
|
||||
|
||||
|===
|
||||
| Relation | Description
|
||||
|
||||
| self
|
||||
| This <<resources-tag,tag>>
|
||||
|
||||
| tagged-notes
|
||||
| The <<resources-tagged-notes,notes>> that have this tag
|
||||
|===
|
||||
include::{generated}/tag-get-example/links.asciidoc[]
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.example.notes;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.springframework.restdocs.core.RestDocumentation.document;
|
||||
import static org.springframework.restdocs.core.RestDocumentation.linkWithRel;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
@@ -93,7 +94,12 @@ public class ApiDocumentation {
|
||||
@Test
|
||||
public void indexExample() throws Exception {
|
||||
document("index-example",
|
||||
this.mockMvc.perform(get("/")).andExpect(status().isOk()));
|
||||
this.mockMvc.perform(get("/")).andExpect(status().isOk()))
|
||||
.andDocumentHalLinks(
|
||||
linkWithRel("notes").description(
|
||||
"The <<resources-notes,Notes resource>>"),
|
||||
linkWithRel("tags").description(
|
||||
"The <<resources-tags,Tags resource>>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -164,7 +170,11 @@ public class ApiDocumentation {
|
||||
.andExpect(jsonPath("title", is(note.get("title"))))
|
||||
.andExpect(jsonPath("body", is(note.get("body"))))
|
||||
.andExpect(jsonPath("_links.self.href", is(noteLocation)))
|
||||
.andExpect(jsonPath("_links.note-tags", is(notNullValue())));
|
||||
.andExpect(jsonPath("_links.note-tags", is(notNullValue())))
|
||||
.andDocumentHalLinks(
|
||||
linkWithRel("self").description("This <<resources-note,note>>"),
|
||||
linkWithRel("note-tags").description(
|
||||
"This note's <<resources-note-tags,tags>>"));
|
||||
|
||||
}
|
||||
|
||||
@@ -249,8 +259,11 @@ public class ApiDocumentation {
|
||||
document("tag-get-example", this.mockMvc.perform(get(tagLocation)))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("name", is(tag.get("name"))))
|
||||
.andExpect(jsonPath("_links.self.href", is(tagLocation)))
|
||||
.andExpect(jsonPath("_links.tagged-notes", is(notNullValue())));
|
||||
.andDocumentHalLinks(
|
||||
linkWithRel("self").description("This <<resources-tag,tag>>"),
|
||||
linkWithRel("tagged-notes")
|
||||
.description(
|
||||
"The <<resources-tagged-notes,notes>> that have this tag"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user