Class MessageExampleGenerator

java.lang.Object
org.mockserver.async.MessageExampleGenerator

public class MessageExampleGenerator extends Object
Generates example JSON payloads for each channel in an AsyncApiSpec.

Uses the following precedence for each channel:

  1. The first explicit example from the spec
  2. A schema-aware example synthesized from the JSON Schema payload (applies constraints: enum, minimum/maximum, minLength/maxLength, pattern hint, required fields, default values)
  3. An empty JSON object {} as a last-resort fallback
  • Constructor Details

    • MessageExampleGenerator

      public MessageExampleGenerator()
  • Method Details

    • generateExamples

      public Map<String,String> generateExamples(AsyncApiSpec spec)
      Generate example payloads for all channels in the spec.
      Returns:
      a map from channel name to JSON string payload
    • generateExample

      public String generateExample(AsyncApiChannel channel)
      Generate an example payload for a single channel. Uses the channel's first message's examples and schema (backward compatible).
    • generateExample

      public String generateExample(AsyncApiMessage message)
      Generate an example payload for a single AsyncApiMessage. Follows the same precedence as generateExample(AsyncApiChannel): explicit example first, then schema synthesis, then empty object fallback.