Class OpenApiRuntimeExpressionResolver

java.lang.Object
org.mockserver.openapi.OpenApiRuntimeExpressionResolver

public class OpenApiRuntimeExpressionResolver extends Object
Resolves OpenAPI runtime expressions (RFC 3.4.16) in callback after-action requests using values from the triggering HTTP request.

Supported expressions:

  • {$request.body#/<json-pointer>} — JSON Pointer into the triggering request body
  • {$request.query.<name>} — query parameter value from the triggering request
  • {$request.header.<name>} — header value from the triggering request
  • {$request.path.<name>} — path parameter (best-effort; empty if unavailable)
  • {$request.method} — HTTP method of the triggering request
  • {$url} — full URL of the triggering request

Response-based expressions ({$response.body#/...}, {$response.header.*}) are out of scope — the response object is not available at after-action dispatch time. These expressions are replaced with empty string for consistency.

Unresolvable expressions (unknown format or missing values) are replaced with empty string.

  • Method Details

    • containsExpression

      public static boolean containsExpression(String value)
      Returns true if the given string contains at least one OpenAPI runtime expression.
    • containsExpressions

      public static boolean containsExpressions(HttpRequest afterActionRequest)
      Returns true if the after-action HttpRequest contains any runtime expressions in its path, headers, Host header, or string body.
    • resolve

      public static HttpRequest resolve(HttpRequest afterActionRequest, HttpRequest triggeringRequest)
      Resolves all OpenAPI runtime expressions in the after-action request using values from the triggering request. Returns a new HttpRequest with resolved values. The original afterActionRequest is NOT mutated.

      If the afterActionRequest contains no expressions, this method returns it unchanged (no clone, no allocation — strict no-op).

      Parameters:
      afterActionRequest - the callback request template (may contain expressions)
      triggeringRequest - the HTTP request that triggered the expectation
      Returns:
      a resolved copy, or the original if no expressions were present