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 aSnippetwith 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
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.springframework.restdocs.snippet.SnippetdslContract()Returns a newSnippetthat will document Spring Cloud Contract DSL for the API operation.static org.springframework.restdocs.snippet.SnippetdslContract(Map<String,Object> attributes)Returns a newSnippetthat will document the Spring Cloud Contract DSL for the API operation.
-
-
-
Method Detail
-
dslContract
public static org.springframework.restdocs.snippet.Snippet dslContract()
Returns a newSnippetthat 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 newSnippetthat will document the Spring Cloud Contract DSL for the API operation. The givenattributeswill be available during snippet generation.- Parameters:
attributes- the attributes- Returns:
- the snippet that will document the Spring Cloud Contract DSL
-
-