Link Search Menu Expand Document


Table of contents

  1. Installation
  2. Usage
    1. Client side validation
    2. Mock MVC tests
  3. License


Add the following to your pom.xml :

  <!-- for MockMVC testing, not for client side validation: -->

Release version Snapshot version


Client side validation

Client side validation of requests and reponses using an interceptor for the RestTemplate.

Resource spec = new ClassPathResource("openapi3.yaml");
RestTemplate client = new RestTemplate();
// add the open API interceptor, should be the last in case of multiple interceptors

Mock MVC tests

Mock MVC tests get automatic request and response validation. A dependency of spring-test is needed and openapi-operation-spring can also be of scope test if client validation is not needed.

// Test setup
Resource spec = new ClassPathResource("openapi3.yaml");
MockMvc mvc = MockMvcBuilders.standaloneSetup(new TestController())
  .apply(OpenApiMatchers.openApi(spec)) // customize for request and response validation

// Test
  mvc.perform(get("/examples")) // perform fails for an undocumented request
  // always expect a documented response first
Library Version Client Server Dependency
Spring >= 5.0 ClientRequest, ClientResponse MvcRequest, MvcResponse The Spring web/test dependency you use


See main page