Class SpringCloudContractRestDocs

java.lang.Object
org.springframework.cloud.contract.wiremock.restdocs.SpringCloudContractRestDocs

public final class SpringCloudContractRestDocs extends Object
Convenience class for setting up RestDocs to generate a Snippet with Spring Cloud Contract DSL. Example usage:
 @RunWith(SpringRunner.class)
 @SpringBootTest
 @AutoConfigureRestDocs(outputDir = "target/snippets")
 @AutoConfigureMockMvc
 public class ContractRestDocsApplicationTests {

        @Autowired
        private MockMvc mockMvc;

        @Test
        public void contextLoads() throws Exception {
     this.mockMvc.perform(post("/foo")
          .accept(MediaType.APPLICATION_PDF)
          .accept(MediaType.APPLICATION_JSON)
          .contentType(MediaType.APPLICATION_JSON)
          .content("{\"foo\": 23 }"))
     .andExpect(status().isOk())
     .andExpect(content().string("bar"))
     // first WireMock
     .andDo(WireMockRestDocs.verify()
          .jsonPath("$[?(@.foo >= 20)]")
          .contentType(MediaType.valueOf("application/json")))
     // then Contract DSL documentation
     .andDo(document("index", SpringCloudContractRestDocs.dslContract()));
        }
 
which creates a file "target/snippets/contracts/index.groovy" and a standard documentation entitled `dsl-contract.adoc` containing that contract.
Since:
1.0.4
Author:
Marcin Grzejszczak
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.springframework.restdocs.snippet.Snippet
    Returns a new Snippet that will document Spring Cloud Contract DSL for the API operation.
    static org.springframework.restdocs.snippet.Snippet
    Returns a new Snippet that will document the Spring Cloud Contract DSL for the API operation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • dslContract

      public static org.springframework.restdocs.snippet.Snippet dslContract()
      Returns a new Snippet that will document Spring Cloud Contract DSL for the API operation.
      Returns:
      the snippet that will document the Spring Cloud Contract DSL
    • dslContract

      public static org.springframework.restdocs.snippet.Snippet dslContract(Map<String,Object> attributes)
      Returns a new Snippet that will document the Spring Cloud Contract DSL for the API operation. The given attributes will be available during snippet generation.
      Parameters:
      attributes - the attributes
      Returns:
      the snippet that will document the Spring Cloud Contract DSL