Package org.mockserver.openapi.examples
Class GenerationOptions
java.lang.Object
org.mockserver.openapi.examples.GenerationOptions
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
SampleDataGeneratorso a given spec produces identical realistic output across runs. Whennullthe 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 everyuserIdfield.
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringReserved key under which a caller may embed these options inside theoperationsAndResponsesmap of an OpenAPI import request. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic GenerationOptionsfromOperationsMap(Map<String, Object> operationsAndResponses) Builds aGenerationOptionsfrom the reservedOPERATIONS_KEYentry of an OpenAPI importoperationsAndResponsesmap, ornullif none is present.getOverride(String propertyName) getSeed()booleanbooleanhasOverrideFor(String propertyName)
-
Field Details
-
OPERATIONS_KEY
Reserved key under which a caller may embed these options inside theoperationsAndResponsesmap of an OpenAPI import request. The value is a map with optional"seed"(number),"fieldOverrides"(object) and"realisticValues"(boolean) entries. The key is deliberately namespaced so it can never collide with a realoperationId.- See Also:
-
-
Constructor Details
-
GenerationOptions
-
GenerationOptions
-
-
Method Details
-
getSeed
- Returns:
- the caller-chosen seed, or
nullto use the historic fixed seed (42)
-
getRealisticValues
- Returns:
- an explicit per-run choice of whether to generate realistic (Datafaker) example values,
or
nullto defer to the globalgenerateRealisticExampleValuesconfiguration default. Threading this decision through the options (rather than reading the global deep in generation) lets callers — and tests — drive realistic generation without mutating shared process-wide state.
-
getFieldOverrides
-
hasFieldOverrides
public boolean hasFieldOverrides() -
hasOverrideFor
- Parameters:
propertyName- the leaf property/field name currently being generated- Returns:
trueif a fixed override value is registered for that exact property name
-
getOverride
-
fromOperationsMap
Builds aGenerationOptionsfrom the reservedOPERATIONS_KEYentry of an OpenAPI importoperationsAndResponsesmap, ornullif none is present.
-