/** * Returns a new {@code Snippet} that will document the links in the API operation's * response. Links will be extracted from the response automatically based on its * content type and will be documented using the given {@code descriptors}. * <p> * If a link is present in the response, but is not documented by one of the * descriptors, a failure will occur when the snippet is invoked. Similarly, if a link * is documented, is not marked as optional, and is not present in the response, a * failure will also occur. * <p> * If you do not want to document a link, a link descriptor can be marked as * {@link LinkDescriptor#ignored}. This will prevent it from appearing in the * generated snippet while avoiding the failure described above. * <p> * If a descriptor does not have a {@link LinkDescriptor#description(Object) * description}, the {@link Link#getTitle() title} of the link will be used. If the * link does not have a title a failure will occur. * @param descriptors the descriptions of the response's links * @return the snippet that will document the links */ public static LinksSnippet links(LinkDescriptor... descriptors) { return links(Arrays.asList(descriptors)); }
/** * Returns a new {@code Snippet} that will document the links in the API operation's * response. Links will be extracted from the response using the given * {@code linkExtractor} and will be documented using the given {@code descriptors}. * <p> * If a link is present in the response, but is not documented by one of the * descriptors, a failure will occur when the snippet is invoked. Similarly, if a link * is documented, is not marked as optional, and is not present in the response, a * failure will also occur. * <p> * If you do not want to document a link, a link descriptor can be marked as * {@link LinkDescriptor#ignored}. This will prevent it from appearing in the * generated snippet while avoiding the failure described above. * <p> * If a descriptor does not have a {@link LinkDescriptor#description(Object) * description}, the {@link Link#getTitle() title} of the link will be used. If the * link does not have a title a failure will occur. * @param linkExtractor used to extract the links from the response * @param descriptors the descriptions of the response's links * @return the snippet that will document the links */ public static LinksSnippet links(LinkExtractor linkExtractor, LinkDescriptor... descriptors) { return links(linkExtractor, Arrays.asList(descriptors)); }
/** * Returns a new {@code Snippet} that will document the links in the API call's * response. The given {@code attributes} will be available during snippet generation. * Links will be extracted from the response automatically based on its content type * and will be documented using the given {@code descriptors}. * <p> * If a link is present in the response, but is not documented by one of the * descriptors, a failure will occur when the snippet is invoked. Similarly, if a link * is documented, is not marked as optional, and is not present in the response, a * failure will also occur. * <p> * If you do not want to document a link, a link descriptor can be marked as * {@link LinkDescriptor#ignored}. This will prevent it from appearing in the * generated snippet while avoiding the failure described above. * <p> * If a descriptor does not have a {@link LinkDescriptor#description(Object) * description}, the {@link Link#getTitle() title} of the link will be used. If the * link does not have a title a failure will occur. * @param attributes the attributes * @param descriptors the descriptions of the response's links * @return the snippet that will document the links */ public static LinksSnippet links(Map<String, Object> attributes, LinkDescriptor... descriptors) { return links(attributes, Arrays.asList(descriptors)); }
/** * Returns a new {@code Snippet} that will document the links in the API operation's * response. The given {@code attributes} will be available during snippet generation. * Links will be extracted from the response using the given {@code linkExtractor} and * will be documented using the given {@code descriptors}. * <p> * If a link is present in the response, but is not documented by one of the * descriptors, a failure will occur when the snippet is invoked. Similarly, if a link * is documented, is not marked as optional, and is not present in the response, a * failure will also occur. * <p> * If you do not want to document a link, a link descriptor can be marked as * {@link LinkDescriptor#ignored}. This will prevent it from appearing in the * generated snippet while avoiding the failure described above. * <p> * If a descriptor does not have a {@link LinkDescriptor#description(Object) * description}, the {@link Link#getTitle() title} of the link will be used. If the * link does not have a title a failure will occur. * @param attributes the attributes * @param linkExtractor used to extract the links from the response * @param descriptors the descriptions of the response's links * @return the snippet that will document the links */ public static LinksSnippet links(LinkExtractor linkExtractor, Map<String, Object> attributes, LinkDescriptor... descriptors) { return links(linkExtractor, attributes, Arrays.asList(descriptors)); }
public static LinksSnippet links(LinkDescriptor... descriptors) { return HypermediaDocumentation.links(linkWithRel("self").ignored().optional(), linkWithRel("curies").ignored()).and(descriptors); } // end::ignore-links[]
public void use() throws Exception { // tag::use[] RestAssured.given(this.spec) .filter(document("index", links(linkWithRel("self").description("Canonical self link")))) .when().get("/") .then().assertThat().statusCode(is(200)); // end::use[] }
public void defaultExtractor() throws Exception { // tag::links[] RestAssured.given(this.spec) .accept("application/json") .filter(document("index", links( // <1> linkWithRel("alpha").description("Link to the alpha resource"), // <2> linkWithRel("bravo").description("Link to the bravo resource")))) // <3> .get("/").then().assertThat().statusCode(is(200)); // end::links[] }
public void use() throws Exception { // tag::use[] this.mockMvc.perform(get("/")) .andExpect(status().isOk()) .andDo(document("index", links(linkWithRel("self").description("Canonical self link")) )); // end::use[] }
public void explicitExtractor() throws Exception { RestAssured.given(this.spec) .accept("application/json") // tag::explicit-extractor[] .filter(document("index", links(halLinks(), // <1> linkWithRel("alpha").description("Link to the alpha resource"), linkWithRel("bravo").description("Link to the bravo resource")))) // end::explicit-extractor[] .get("/").then().assertThat().statusCode(is(200)); }
public void use() throws Exception { // tag::use[] this.webTestClient.get().uri("/").exchange().expectStatus().isOk() .expectBody().consumeWith(document("index", links(linkWithRel("self").description("Canonical self link")))); // end::use[] }
@Test public void linksSnippet() throws Exception { given().port(tomcat.getPort()) .filter(documentationConfiguration(this.restDocumentation)) .filter(document("links", links(linkWithRel("rel").description("The description")))) .accept("application/json").get("/").then().statusCode(200); assertExpectedSnippetFilesExist(new File("build/generated-snippets/links"), "http-request.adoc", "http-response.adoc", "curl-request.adoc", "links.adoc"); }
@Test public void additionalDescriptors() throws IOException { HypermediaDocumentation .links(new StubLinkExtractor().withLinks(new Link("a", "alpha"), new Link("b", "bravo")), new LinkDescriptor("a").description("one")) .and(new LinkDescriptor("b").description("two")) .document(this.operationBuilder.build()); assertThat(this.generatedSnippets.links()) .is(tableWithHeader("Relation", "Description").row("`a`", "one") .row("`b`", "two")); }
@Test public void linksSnippet() throws Exception { MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context) .apply(documentationConfiguration(this.restDocumentation)).build(); mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()).andDo(document("links", links(linkWithRel("rel").description("The description")))); assertExpectedSnippetFilesExist(new File("build/generated-snippets/links"), "http-request.adoc", "http-response.adoc", "curl-request.adoc", "links.adoc"); }
public void defaultExtractor() throws Exception { // tag::links[] this.webTestClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange() .expectStatus().isOk().expectBody() .consumeWith(document("index",links( // <1> linkWithRel("alpha").description("Link to the alpha resource"), // <2> linkWithRel("bravo").description("Link to the bravo resource")))); // <3> // end::links[] }
public void defaultExtractor() throws Exception { // tag::links[] this.mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andDo(document("index", links( // <1> linkWithRel("alpha").description("Link to the alpha resource"), // <2> linkWithRel("bravo").description("Link to the bravo resource")))); // <3> // end::links[] }
public void explicitExtractor() throws Exception { this.mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) //tag::explicit-extractor[] .andDo(document("index", links(halLinks(), // <1> linkWithRel("alpha").description("Link to the alpha resource"), linkWithRel("bravo").description("Link to the bravo resource")))); // end::explicit-extractor[] }
public void explicitExtractor() throws Exception { this.webTestClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange() .expectStatus().isOk().expectBody() // tag::explicit-extractor[] .consumeWith(document("index",links(halLinks(), // <1> linkWithRel("alpha").description("Link to the alpha resource"), linkWithRel("bravo").description("Link to the bravo resource")))); // end::explicit-extractor[] }
links(halLinks(), linkWithRel("curies").description("CUR-ies"), linkWithRel("self").description("This ad"),
links(halLinks(), linkWithRel("curies").description("CUR-ies"), linkWithRel("self").description("This ad"),