liveBook · Manning

Atlassian Swagger Request Validator

As explained in Automating API Delivery

swagger-request-validator-mockmvc is an Atlassian library module that validates HTTP requests and responses against OpenAPI descriptions and integrates with MockMvc.

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

How Automating API Delivery covers it

How deep it goes
Provides runnable integrations and diagnostic failures, but does not replace broader gateway or design-level testing.
Examples
Uses a Product Catalog endpoint, OpenApiValidationFilter, OpenAPI matchers, and failures for undocumented response properties.
What it assumes
Assumes Java and OpenAPI familiarity while demonstrating dependencies, test setup, and executable examples.
What you can do after
Diagnose API conformance failures and choose fast controller or gateway-inclusive end-to-end validation boundaries.
How it connects
Connects OpenAPI, Rest Assured, MockMvc, schema testing, controller testing, and API gateway behavior.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Automating API Delivery. The section links point to the parts of the book it draws on.