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 Details

  • Constructor Details

  • 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 an InvalidRequestException will be thrown leading to an error response.

      Only wrapped HttpServletRequest can be validated. Wrapping is done within the OpenApiValidationFilter.

      Parameters:
      servletRequest - the HttpServletRequest to validate
      servletResponse - the servlet response
      handler - a handler
      Returns:
      true if the request is valid against or not defined in the API specification or the servlet is not a ResettableRequestServletWrapper
      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 an InvalidResponseException will be thrown leading to an error response.

      Only wrapped HttpServletResponse can be validated. Wrapping is done within the OpenApiValidationFilter.

      Parameters:
      servletRequest - the servlet request
      servletResponse - the HttpServletResponse to validate
      handler - a handler
      modelAndView - a model and view