/** * 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 automatically based on its * content type and will be documented using the given {@code descriptors}. * <p> * If a link is documented, is not marked as optional, and is not present in the * response, a failure will occur. Any undocumented links will be ignored. * <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 relaxedLinks(LinkDescriptor... descriptors) { return relaxedLinks(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 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 documentation() throws Exception { // tag::use[] RestAssured.given(this.spec) .accept("application/json") .filter(document("example", this.pagingLinks.and( // <1> linkWithRel("alpha").description("Link to the alpha resource"), linkWithRel("bravo").description("Link to the bravo resource")))) .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 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 documentation() throws Exception { // tag::use[] this.mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andDo(document("example", this.pagingLinks.and( // <1> linkWithRel("alpha").description("Link to the alpha resource"), linkWithRel("bravo").description("Link to the bravo resource")))); // end::use[] }
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.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[] }
/** * 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)); }
public void documentation() throws Exception { // tag::use[] this.webTestClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange() .expectStatus().isOk().expectBody() .consumeWith(document("example", this.pagingLinks.and( // <1> linkWithRel("alpha").description("Link to the alpha resource"), linkWithRel("bravo").description("Link to the bravo resource")))); // end::use[] }
/** * 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 documented, is not marked as optional, and is not present in the * response, a failure will occur. Any undocumented links will be ignored. * <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 relaxedLinks(LinkExtractor linkExtractor, LinkDescriptor... descriptors) { return relaxedLinks(linkExtractor, Arrays.asList(descriptors)); }
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[] }
links(halLinks(), linkWithRel("curies").description("CUR-ies"), linkWithRel("self").description("This ad"), linkWithRel("black-market:ad").description("This <<ads, ad>>"), linkWithRel("black-market:user").description("Author of this ad"), linkWithRel("black-market:update").description("Updates this ad via PATCH"), linkWithRel("black-market:deletion").description("Deletes this ad via DELETE"), linkWithRel("black-market:publishing").description("Publishes this ad via POST with empty body") ), responseFields(
/** * 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 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 documented, is not marked as optional, and is not present in the * response, a failure will occur. Any undocumented links will be ignored. * <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 relaxedLinks(Map<String, Object> attributes, LinkDescriptor... descriptors) { return relaxedLinks(attributes, Arrays.asList(descriptors)); }
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[] }
links(halLinks(), linkWithRel("curies").description("CUR-ies"), linkWithRel("self").description("This ad"), linkWithRel("black-market:ad").description("This <<ads, ad>>"), linkWithRel("black-market:user").description("Author of this ad"), linkWithRel("black-market:expiration").description("Expires this ad via POST") ), responseFields(
/** * 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)); }