Class OpenApiValidationFilter

  • All Implemented Interfaces:
    org.forgerock.http.Filter

    public class OpenApiValidationFilter
    extends Object
    implements org.forgerock.http.Filter
    Validates HTTP requests and responses against an OpenAPI (Swagger 2.x / OpenAPI 3.x) specification

    Request validation

    If the request fails validation the filter stops processing and delegates to requestValidationErrorHandler instead of forwarding the request downstream. The default requestValidationErrorHandler returns 400 Bad Request.

    Response validation

    After the downstream handler returns a response, the filter validates it against the spec. Behaviour depends on failOnResponseViolation:

    • true – delegate to responseValidationErrorHandler. The default returns 503 Service Unavailable
    • false (default) – log a warning and pass the original response through.

    Heap configuration

    
     {
       "name": "myValidator",
       "type": "OpenApiValidationFilter",
       "config": {
         "specFile": "/path/to/openapi.yaml",
         "failOnResponseViolation": false,
         "requestValidationErrorHandler": "403BadRequest",
         "responseValidationErrorHandler": "503ServiceUnavailable"
       }
     }
     
    • Field Detail

      • ATTR_OPENAPI_VALIDATION_REPORT

        public static final String ATTR_OPENAPI_VALIDATION_REPORT
        Key under which the ValidationReport is stored in the AttributesContext before delegating to an error handler.
        See Also:
        Constant Field Values
    • Method Detail

      • filter

        public org.forgerock.util.promise.Promise<org.forgerock.http.protocol.Response,​org.forgerock.util.promise.NeverThrowsException> filter​(org.forgerock.services.context.Context context,
                                                                                                                                                     org.forgerock.http.protocol.Request request,
                                                                                                                                                     org.forgerock.http.Handler next)
        Specified by:
        filter in interface org.forgerock.http.Filter
      • defaultRequestValidationErrorHandler

        public static org.forgerock.http.Handler defaultRequestValidationErrorHandler()
      • defaultResponseValidationErrorHandler

        public static org.forgerock.http.Handler defaultResponseValidationErrorHandler()