Atlassian Swagger Request Validator checks HTTP requests and responses against an OpenAPI definition. In Java, it supports both end-to-end Rest Assured tests and Spring MockMvc controller tests, turning schema mismatches into test failures. section 7.2.1 section 7.2.2
Choose the test boundary according to the behavior you need to verify:
- Use OpenApiValidationFilter with Rest Assured for an end-to-end request through the API gateway and service. section 7.2.1
- Use OpenApiValidationMatchers.openApi with MockMvc to validate a controller without starting the application server. section 7.2.2
- Test both successful and error responses with the faster controller boundary, but retain end-to-end coverage for gateway behavior such as API-key authentication. section 7.2.2
- Account for maintenance: each new endpoint and its relevant success and failure responses requires additional test code. section 7.3
Detecting an undocumented response field
A Product Catalog test requests GET /v1/catalog/products/{uuid} and expects status 200. Validation fails when the API returns numberOfReviews and reviewRating while the OpenAPI schema sets additionalProperties to false. The failure identifies the response location, request path, method, and disallowed properties, giving the team a concrete contract decision: update the schema or remove the undocumented fields. section 7.2.1
Listing 7.2 Product controller schema test
package com.acmepetsupplies.productcatalog;
import com.acmepetsupplies.productcatalog.controller.ProductsApiController;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
import static com.atlassian.oai.validator.mockmvc
.OpenApiValidationMatchers.openApi;
import static io.restassured.module.mockmvc.RestAssuredMockMvc.given;
@SpringBootTest
public class ControllerSchemaTest {
@Test
public void testGetProductController() {
given()
.standaloneSetup(
new ProductsApiController()) #1
.when()
.get
("/v1/catalog/products/612b4280-b5c0-4ad5-bce7-ede7ab2b90fc")
.then()
.assertThat()
.expect(openApi()
.isValid("../product-catalog-v1-0.oas.yaml")) #2
.statusCode(200);
}
}
The controller test shows standaloneSetup for ProductsApiController and an OpenAPI matcher that validates the response definition. section 7.2.2
