Class OpenApiRouteBuilder


  • public class OpenApiRouteBuilder
    extends Object
    Converts a parsed OpenAPI model into an OpenIG route JsonValue.

    The generated route:

    • Has a name derived from info.title (slugified) or the spec filename stem.
    • Has a condition expression built from every (path, method) pair declared in the spec. Path parameter placeholders such as {id} are converted to the regex [^/]+, and each clause also checks request.method against the HTTP verbs declared for that path.
    • Has a heap containing a single OpenApiValidationFilter heap object pointing at the spec file.
    • Has a handler that is a Chain with the validation filter followed by a ClientHandler that proxies to the first server URL declared in the spec.

    The generated route uses the baseURI decorator if a server URL is found in the spec so that all requests are forwarded to the upstream service.

    • Constructor Detail

      • OpenApiRouteBuilder

        public OpenApiRouteBuilder()
    • Method Detail

      • buildRouteJson

        public org.forgerock.json.JsonValue buildRouteJson​(io.swagger.v3.oas.models.OpenAPI spec,
                                                           File specFile,
                                                           boolean failOnResponseViolation)
        Builds an OpenIG route JsonValue for the supplied OpenAPI specification.
        Parameters:
        spec - the parsed OpenAPI model
        specFile - the original spec file on disk (used for the validator config and as a fallback route name)
        failOnResponseViolation - if true, the generated OpenApiValidationFilter will return 502 Bad Gateway when a response violates the spec; if false (default), violations are only logged
        Returns:
        a JsonValue that can be passed directly to the RouterHandler's internal route-loading mechanism
      • buildRouteJson

        public org.forgerock.json.JsonValue buildRouteJson​(io.swagger.v3.oas.models.OpenAPI spec,
                                                           File specFile,
                                                           boolean failOnResponseViolation,
                                                           boolean mockMode)
        Builds an OpenIG route JsonValue for the supplied OpenAPI specification.
        Parameters:
        spec - the parsed OpenAPI model
        specFile - the original spec file on disk (used for the validator config and as a fallback route name)
        failOnResponseViolation - if true, the generated OpenApiValidationFilter will return 502 Bad Gateway when a response violates the spec; if false (default), violations are only logged
        mockMode - if true, the route handler chain terminates at an OpenApiMockResponseHandler instead of a ClientHandler; when false (default) requests are forwarded upstream
        Returns:
        a JsonValue that can be passed directly to the RouterHandler's internal route-loading mechanism