Class OpenApiContractTest

java.lang.Object
org.mockserver.openapi.OpenApiContractTest

public class OpenApiContractTest extends Object
Given an OpenAPI spec, builds representative example requests for each operation, sends them via an injected HTTP-send function, and validates each response against the spec.

The class is HTTP-client-agnostic; the caller wires in the real client via the httpSender function passed to runContractTests(java.lang.String, java.lang.String, java.lang.String, java.util.function.Function<org.mockserver.model.HttpRequest, org.mockserver.model.HttpResponse>).

  • Constructor Details

    • OpenApiContractTest

      public OpenApiContractTest(MockServerLogger mockServerLogger)
  • Method Details

    • runContractTests

      public List<OpenApiContractTest.ContractTestResult> runContractTests(String specUrlOrPayload, String baseUrl, String operationIdFilter, Function<HttpRequest,HttpResponse> httpSender)
      Runs contract tests for each operation in the spec.
      Parameters:
      specUrlOrPayload - URL, file path, or inline JSON/YAML of the OpenAPI spec
      baseUrl - base URL of the service under test (e.g. "http://localhost:8080")
      operationIdFilter - optional filter to test only a specific operation
      httpSender - function that sends an HttpRequest and returns an HttpResponse
      Returns:
      list of per-operation results