- Swagger v2 (OpenAPI 2.0) — full request and response validation
- OpenAPI v3.0 — full request and response validation
- OpenAPI v3.1 — partial support (see notes in the OpenAPI v3 doc)
- YAML and JSON spec formats
- Specs loaded from:
- HTTP / HTTPS URLs
- Classpath resources
- Local file paths
- Inline string payloads
- Request validation
- Path and HTTP method matching
- Path, query, header, and cookie parameter validation (type, format, constraints)
- Request body validation (JSON Schema, content-type negotiation)
- Required parameter and body enforcement
- Security requirement presence checks (
apiKey,httptype schemes)
- Response validation
- HTTP status code validation
- Response header validation
- Response body validation (JSON Schema, content-type negotiation)
- Webhook validation (OpenAPI v3.1)
validateWebhookRequest(),validateWebhookResponse(),validateWebhook()
- JSON Schema validation — full draft-07 support including
$ref,allOf,oneOf,anyOf, composition, discriminators, and all standard keywords
The core library has no dependency on any HTTP framework or testing library. It works with plain Request and Response objects, making it easy to integrate anywhere.
| Adapter | Description | Artifact |
|---|---|---|
| Spring MockMVC | ResultMatcher for Spring MockMVC test interactions (Spring 7 / Spring Boot 4+) |
openapi-request-validator-mockmvc |
| Spring WebMVC | Servlet Filter + MVC Interceptor for runtime production validation |
openapi-request-validator-spring-webmvc |
| Spring Web Client | ClientHttpRequestInterceptor for Spring RestTemplate / RestClient |
openapi-request-validator-spring-web-client |
| REST Assured | OpenApiValidationFilter for REST Assured test interactions |
openapi-request-validator-restassured |
| WireMock (JUnit 5) | OpenApiValidationListener (ServeEventListener) for WireMock stubs |
openapi-request-validator-wiremock-junit5 |
| Pact | Consumer- and provider-side validation against Pact files | openapi-request-validator-pact |
| Ktor Client | OpenAPIValidation plugin for Ktor 3.x HTTP client (Kotlin) |
openapi-request-validator-ktor-client |
See the core module README for full details.
Validation messages have a configurable severity level (ERROR, WARN, INFO, IGNORED). Levels can be adjusted globally or per message key using a LevelResolver:
OpenApiInteractionValidator.createForSpecificationUrl(specUrl)
.withLevelResolver(
LevelResolver.create()
.withLevel("validation.request.body.missing", ValidationReport.Level.WARN)
.build()
)
.build();Framework-specific level resolver factories are also available (e.g. SpringMVCLevelResolverFactory).
A ValidationErrorsWhitelist lets you suppress specific validation errors that are expected or acceptable in your context. Rules can be composed with allOf / anyOf logic:
ValidationErrorsWhitelist whitelist = ValidationErrorsWhitelist.create()
.withRule("Ignore 404 body errors",
allOf(isResponse(), responseStatusIs(404), messageHasKey("validation.response.body.missing")))
.withRule("Ignore OPTIONS requests",
allOf(isRequest(), methodIs(HttpMethod.OPTIONS)));Available built-in rules (WhitelistRules):
| Rule | Description |
|---|---|
messageHasKey(key) |
Match by validation message key |
messageContainsSubstring(s) |
Match if message text contains a substring |
messageContainsRegexp(re) |
Match if message text matches a regexp |
pathContainsSubstring(s) |
Match if request path contains a substring |
pathContainsRegexp(re) |
Match if request path matches a regexp |
isRequest() / isResponse() |
Match request-only or response-only messages |
methodIs(method) |
Match by HTTP method |
responseStatusIs(code) |
Match by HTTP response status code |
responseStatusTypeIs(type) |
Match by response status type (1xx, 2xx, …) |
entityIs(name) |
Match by entity/schema name |
headerContainsSubstring(header, s) |
Match if a header contains a substring |
headerContainsRegexp(header, re) |
Match if a header matches a regexp |
missingRequestContentType() |
Match missing Content-Type header errors |
allOf(rules…) |
All rules must match (AND composition) |
anyOf(rules…) |
Any rule must match (OR composition) |
Plug in your own validation logic alongside the built-in validators:
OpenApiInteractionValidator.createForSpecificationUrl(specUrl)
.withCustomRequestValidation(myCustomRequestValidator)
.withCustomResponseValidation(myCustomResponseValidator)
.build();The OpenApiInteractionValidator.Builder exposes the following options:
| Method | Description |
|---|---|
withInlineApiSpecification(spec) |
Load spec from an inline string |
withApiSpecificationUrl(url) |
Load spec from a URL (HTTP, classpath, file) |
withApi(OpenAPI) |
Use a pre-parsed OpenAPI model object |
withBasePathOverride(path) |
Override the base path from the spec |
withLevelResolver(resolver) |
Configure message severity levels |
withWhitelist(whitelist) |
Suppress specific validation errors |
withAuthHeaderData(key, value) |
Provide auth credentials for spec fetching |
withCustomRequestValidation(v) |
Add a custom request validator |
withCustomResponseValidation(v) |
Add a custom response validator |
withResolveRefs(bool) |
Control $ref resolution (default: true) |
withResolveCombinators(bool) |
Control combinator resolution (default: true) |
withParseOptions(opts) |
Pass custom ParseOptions to the OpenAPI parser |
withSchemaValidationConfiguration(cfg) |
Configure JSON Schema validation cache size |
withStrictOperationPathMatching() |
Require exact path matching (no trailing slash tolerance) |
ValidationReport— immutable, thread-safe collection of validation messages- Each
Messagecontains:- A stable message key (e.g.
validation.request.body.schema.additionalProperties) - A human-readable message string
- A severity level (
ERROR,WARN,INFO,IGNORED) - Rich context: operation, path, method, parameter, content-type, response status, JSON pointer location
- A stable message key (e.g.
- Reports can be merged:
MergedValidationReport - Report formatting:
SimpleValidationReportFormat— human-readable text for loggingJsonValidationReportFormat— machine-readable JSON
- Full JSON Schema draft-07 support via the
SchemaValidator - Schema cache with configurable maximum size (
ValidationConfiguration.setMaxCacheSize()) - Built-in format validators:
int32,int64,float,double,byte(Base64) - Schema transformation pipeline applied before validation:
AdditionalPropertiesInjectionTransformer— prevents spuriousadditionalPropertieserrorsDiscriminatorMappingTransformer— resolves discriminator mappingsRequiredFieldTransformer— handlesreadOnly/writeOnlyfields in request vs response contextSchemaDefinitionsInjectionTransformer— injects global definitions into schemas
Multiple body representations are supported to accommodate different integration patterns:
| Type | Description |
|---|---|
StringBody |
In-memory string body |
ByteArrayBody |
In-memory byte array body |
InputStreamBody |
Streaming body (read once) |
ResettableInputStreamBody |
Buffered/resettable stream (Spring WebMVC) |
See the FAQ for answers to common questions about configuration, known limitations, and integration patterns.