Allow documentation of extra attributes on fields, links, and query parameters

This commit adds support for associating custom attributes with field,
link, and query parameter descriptors. These attributes are then
included in the model during snippet rendering. Coupled with a custom
snippet template, this enables the inclusion of extra column(s) in the
generated tables.

Closes gh-70
This commit is contained in:
Andy Wilkinson
2015-07-23 18:01:57 +01:00
parent 4f850cddd9
commit 70824aa509
19 changed files with 364 additions and 46 deletions

View File

@@ -19,6 +19,7 @@ package com.example;
import static org.springframework.restdocs.RestDocumentation.document;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.springframework.http.MediaType;
@@ -51,4 +52,18 @@ private MockMvc mockMvc;
// end::explicit-type[]
}
public void constraints() throws Exception {
this.mockMvc.perform(post("/users/").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
// tag::constraints[]
.andDo(document("create-user").withRequestFields(
fieldWithPath("name")
.description("The user's name")
.attribute("constraints", "Must not be null. Must not be empty"),
fieldWithPath("email")
.description("The user's email address")
.attribute("constrains", "Must be a valid email address")));
// end::constraints[]
}
}