Class JsonSchemaResponseSynthesizer

java.lang.Object
org.mockserver.openapi.JsonSchemaResponseSynthesizer

public class JsonSchemaResponseSynthesizer extends Object
Synthesizes a schema-valid response body from a plain (inline) JSON Schema, without requiring a full OpenAPI specification to be attached to the expectation. This is the JSON-Schema analogue of the OpenAPI response-generation path: the inline schema is wrapped in a minimal OpenAPI document, parsed with the same OpenAPIParser (so $ref, allOf, OpenAPI 3.1 type arrays and the typed swagger Schema subclasses are produced exactly as for a real spec), and then handed to the existing ExampleBuilder/SampleDataGenerator engine to produce a body that respects types, required, enum, default and arrays.

No example-generation logic is reimplemented here — only the plumbing that turns a bare JSON Schema into the typed schema the engine already understands.

Trust model: the inline schema is parsed via the same OpenAPIParser used for full OpenAPI specs, so a remote or file: $ref inside the schema is resolved (fetched) exactly as it would be for an attached spec. This deliberately follows the OpenAPI-spec trust model — the field is settable only via the (JWT-protectable) control plane, which already permits attaching an arbitrary spec via specUrlOrPayload — and is not gated by the jsonSchemaAllowRemoteRefs property that guards remote $refs on the JSON-Schema body-matching path. Treat an inline generateFromSchema with the same trust as a specUrlOrPayload.

  • Constructor Details

    • JsonSchemaResponseSynthesizer

      public JsonSchemaResponseSynthesizer(MockServerLogger mockServerLogger)
  • Method Details

    • synthesizeResponse

      public String synthesizeResponse(String jsonSchema)
      Generates a schema-valid JSON body for the supplied inline JSON Schema.
      Parameters:
      jsonSchema - the inline JSON Schema (a plain JSON Schema object, not a full OpenAPI doc)
      Returns:
      a schema-valid JSON body, or null when the schema is blank or no example could be generated (the caller then leaves the response body unset)