Class GenerationOptions

java.lang.Object
org.mockserver.openapi.examples.GenerationOptions

public class GenerationOptions extends Object
Per-generation-run options controlling how ExampleBuilder produces example values when the generateRealisticExampleValues configuration flag is enabled.

Two knobs are supported, both optional and backward-compatible:

  • seed — a caller-chosen seed threaded into SampleDataGenerator so a given spec produces identical realistic output across runs. When null the generator falls back to its historic fixed seed (42), so existing behaviour is unchanged.
  • fieldOverrides — a map of property name to fixed value. Whenever a schema property whose name matches a key is generated, the fixed value is emitted instead of a generated one. For example {"userId": "system-user-123"} pins every userId field.

Match semantics (v1): overrides match by leaf property name — the map key is compared against the property/JSON field name being generated, at any nesting depth. There is no JSONPath or dotted-path matching in this version; a key of userId pins every property named userId regardless of where it appears in the schema. This keeps the contract simple and predictable; richer path matching can layer on later without breaking this behaviour.

Overrides only take effect when there is no explicit example already declared on the schema (an author-declared example always wins), and they apply whether or not realistic value generation is enabled.

  • Field Details

    • OPERATIONS_KEY

      public static final String OPERATIONS_KEY
      Reserved key under which a caller may embed these options inside the operationsAndResponses map of an OpenAPI import request. The value is a map with optional "seed" (number) and "fieldOverrides" (object) entries. The key is deliberately namespaced so it can never collide with a real operationId.
      See Also:
  • Constructor Details

  • Method Details

    • getSeed

      public Long getSeed()
      Returns:
      the caller-chosen seed, or null to use the historic fixed seed (42)
    • getFieldOverrides

      public Map<String,Object> getFieldOverrides()
    • hasFieldOverrides

      public boolean hasFieldOverrides()
    • hasOverrideFor

      public boolean hasOverrideFor(String propertyName)
      Parameters:
      propertyName - the leaf property/field name currently being generated
      Returns:
      true if a fixed override value is registered for that exact property name
    • getOverride

      public Object getOverride(String propertyName)
    • fromOperationsMap

      public static GenerationOptions fromOperationsMap(Map<String,Object> operationsAndResponses)
      Builds a GenerationOptions from the reserved OPERATIONS_KEY entry of an OpenAPI import operationsAndResponses map, or null if none is present.