public final class SpringCloudContractRestDocs extends Object
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.| Modifier and Type | Method and Description |
|---|---|
static org.springframework.restdocs.snippet.Snippet |
dslContract()
Returns a new
Snippet that will document Spring Cloud Contract DSL for the
API operation. |
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. |
public static org.springframework.restdocs.snippet.Snippet dslContract()
Snippet that will document Spring Cloud Contract DSL for the
API operation.public static org.springframework.restdocs.snippet.Snippet dslContract(Map<String,Object> attributes)
Snippet that will document the Spring Cloud Contract DSL for
the API operation. The given attributes will be available during snippet
generation.attributes - the attributesCopyright © 2016–2020 Spring. All rights reserved.