Class OpenApiMockResponseHandler

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

    public class OpenApiMockResponseHandler
    extends Object
    implements org.forgerock.http.Handler
    A Handler that generates valid mock HTTP responses with realistic test data derived from an OpenAPI / Swagger specification.

    Instead of proxying to an upstream service the handler:

    1. Matches the incoming request path + method against the paths declared in the spec.
    2. Locates the best response schema (prefers 200, then 201, then first 2xx, then default).
    3. Recursively generates a JSON body from that schema using MockDataGenerator.
    4. Returns the generated body with Content-Type: application/json.

    If no matching path is found the handler returns 404 Not Found; if a path is matched but the HTTP method is not declared the handler returns 405 Method Not Allowed.

    Heap configuration

    
     {
       "name": "MockHandler",
       "type": "OpenApiMockResponseHandler",
       "config": {
         "spec": "${read('/path/to/openapi.yaml')}",
         "defaultStatusCode": 200,
         "arraySize": 3
       }
     }
     
    Configuration properties
    PropertyTypeRequiredDefaultDescription
    specStringYes OpenAPI spec content (YAML or JSON)
    defaultStatusCodeIntegerNo200 HTTP status code to use for generated responses
    arraySizeIntegerNo1 Number of items to generate for array-typed responses
    • Constructor Detail

      • OpenApiMockResponseHandler

        public OpenApiMockResponseHandler​(String specContent,
                                          int defaultStatusCode,
                                          int arraySize)
        Creates a new mock handler backed by the supplied spec content.
        Parameters:
        specContent - the raw OpenAPI spec (YAML or JSON)
        defaultStatusCode - HTTP status code to use for generated responses
        arraySize - number of items to generate for array-typed responses
    • Method Detail

      • handle

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