Class OpenApiValidationInterceptor
java.lang.Object
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
com.atlassian.oai.validator.springmvc.OpenApiValidationInterceptor
- All Implemented Interfaces:
org.springframework.web.servlet.AsyncHandlerInterceptor,org.springframework.web.servlet.HandlerInterceptor
public class OpenApiValidationInterceptor
extends org.springframework.web.servlet.handler.HandlerInterceptorAdapter
An Interceptor which validates incoming requests against the defined OpenAPI / Swagger specification.
You can customize logging output of interceptor by implementing
interface ValidationReportHandler and providing instance
to constructor.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionOpenApiValidationInterceptor(OpenApiInteractionValidator validator, ValidationReportHandler validationReportHandler) OpenApiValidationInterceptor(OpenApiValidationService openApiValidationService) OpenApiValidationInterceptor(OpenApiValidationService openApiValidationService, ValidationReportHandler validationReportHandler) OpenApiValidationInterceptor(org.springframework.core.io.support.EncodedResource apiSpecification) -
Method Summary
Modifier and TypeMethodDescriptionvoidpostHandle(javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse, Object handler, org.springframework.web.servlet.ModelAndView modelAndView) Validates the given response.booleanpreHandle(javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse, Object handler) Validates the given requests.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.web.servlet.AsyncHandlerInterceptor
afterConcurrentHandlingStartedMethods inherited from interface org.springframework.web.servlet.HandlerInterceptor
afterCompletion
-
Field Details
-
openApiValidationService
-
-
Constructor Details
-
OpenApiValidationInterceptor
public OpenApiValidationInterceptor(@Nonnull org.springframework.core.io.support.EncodedResource apiSpecification) throws IOException - Throws:
IOException
-
OpenApiValidationInterceptor
-
OpenApiValidationInterceptor
public OpenApiValidationInterceptor(@Nonnull OpenApiInteractionValidator validator, @Nonnull ValidationReportHandler validationReportHandler) -
OpenApiValidationInterceptor
-
OpenApiValidationInterceptor
public OpenApiValidationInterceptor(@Nonnull OpenApiValidationService openApiValidationService, @Nonnull ValidationReportHandler validationReportHandler)
-
-
Method Details
-
preHandle
public boolean preHandle(javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse, Object handler) throws Exception Validates the given requests. If a request is defined but invalid against the OpenAPI / Swagger specification anInvalidRequestExceptionwill be thrown leading to an error response.Only wrapped
HttpServletRequestcan be validated. Wrapping is done within theOpenApiValidationFilter.- Parameters:
servletRequest- theHttpServletRequestto validateservletResponse- the servlet responsehandler- a handler- Returns:
trueif the request is valid against or not defined in the API specification or the servlet is not aResettableRequestServletWrapper- Throws:
Exception- if the request is invalid against the API specification or the requests body can't be read
-
postHandle
public void postHandle(javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse, Object handler, org.springframework.web.servlet.ModelAndView modelAndView) Validates the given response. If a request is defined but its response is invalid against the OpenAPI / Swagger specification anInvalidResponseExceptionwill be thrown leading to an error response.Only wrapped
HttpServletResponsecan be validated. Wrapping is done within theOpenApiValidationFilter.- Parameters:
servletRequest- the servlet requestservletResponse- theHttpServletResponseto validatehandler- a handlermodelAndView- a model and view
-