Class LoadScenarioFromOpenAPI

java.lang.Object
org.mockserver.load.LoadScenarioFromOpenAPI

public class LoadScenarioFromOpenAPI extends Object
Seeds an editable, runnable LoadScenario from an OpenAPI specification.

One LoadStep is emitted per operation (in the stable, path-then-method order produced by OpenAPISerialiser.retrieveOperations(OpenAPI, String, String)), each carrying a concrete HttpRequest with the operation's method and (server-prefixed) path, a representative request body example (built from the request-body schema via ExampleBuilder, the same engine the OpenAPI expectation converter uses) and a Content-Type header.

Target precedence for where each generated request is sent (carried as the request's Host header and secure flag, the same routing surface every other load step uses):

  1. an explicit LoadScenarioFromOpenAPI.Target supplied by the caller, else
  2. the spec's servers[0] URL (host, port and https scheme), else
  3. nothing — the request is left path-only and the operator edits in a target before running.

When the caller supplies no LoadProfile a conservative default is applied — a single short constant-VU stage — so the generated scenario is immediately runnable yet safe; the operator is expected to edit the profile afterward. Steps are plain and ordered (no weighting in v1).

This is a pure generator: it produces a LoadScenario object and drives no traffic.

  • Constructor Details

    • LoadScenarioFromOpenAPI

      public LoadScenarioFromOpenAPI()
  • Method Details

    • generate

      public static LoadScenario generate(String name, String specUrlOrPayload, LoadScenarioFromOpenAPI.Target target, LoadProfile profile, MockServerLogger mockServerLogger)
      Generates a LoadScenario from an OpenAPI spec.
      Parameters:
      name - the generated scenario name
      specUrlOrPayload - the OpenAPI spec as an inline JSON/YAML payload, URL or file/classpath reference (accepted identically to PUT /mockserver/openapi/expectation)
      target - explicit network target (may be null — see class-level precedence)
      profile - explicit load profile (may be null — a conservative default is applied)
      mockServerLogger - logger used by the shared OpenAPI parse
      Returns:
      the generated, editable LoadScenario
      Throws:
      IllegalArgumentException - if the spec cannot be parsed or contains no operations