Package org.forgerock.openig.handler
Class OpenApiMockResponseHandler
- java.lang.Object
-
- org.forgerock.openig.handler.OpenApiMockResponseHandler
-
- All Implemented Interfaces:
org.forgerock.http.Handler
public class OpenApiMockResponseHandler extends Object implements org.forgerock.http.Handler
AHandlerthat generates valid mock HTTP responses with realistic test data derived from an OpenAPI / Swagger specification.Instead of proxying to an upstream service the handler:
- Matches the incoming request path + method against the paths declared in the spec.
- Locates the best response schema (prefers 200, then 201, then first 2xx, then
default). - Recursively generates a JSON body from that schema using
MockDataGenerator. - 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 returns405 Method Not Allowed.Heap configuration
{ "name": "MockHandler", "type": "OpenApiMockResponseHandler", "config": { "spec": "${read('/path/to/openapi.yaml')}", "defaultStatusCode": 200, "arraySize": 3 } }Configuration properties Property Type Required Default Description spec String Yes – OpenAPI spec content (YAML or JSON) defaultStatusCode Integer No 200 HTTP status code to use for generated responses arraySize Integer No 1 Number of items to generate for array-typed responses
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOpenApiMockResponseHandler.HeapletCreates and initialises anOpenApiMockResponseHandlerin a heap environment.
-
Constructor Summary
Constructors Constructor Description OpenApiMockResponseHandler(String specContent, int defaultStatusCode, int arraySize)Creates a new mock handler backed by the supplied spec content.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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)
-
-
-
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 responsesarraySize- 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:
handlein interfaceorg.forgerock.http.Handler
-
-