Skip to content

Options

Configuration Options

OptionTypeDefaultDescription
specSource{ type: "object"; spec: OpenAPISpec } | { type: "url"; spec: string } | { type: "file"; spec: string }Provide your OpenAPI 3.x spec as an object, or point to it via URL or file path.
enablebooleantrueMaster switch: registers the mock interceptor globally. When false, interceptor is not registered.
mockByDefaultbooleanfalseControls default mocking behavior. When false, mock only when explicitly requested via headers or decorators.
strategyOrderArray<"records" | "mediatype-examples" | "schema-examples" | "jsf" | "primitive" | "passthrough">["mediatype-examples", "schema-examples", "jsf"]Ordered list of strategies to attempt when generating responses.
defaultStatusnumber200Default HTTP status code when not specified elsewhere.
seednumber | stringundefinedSeed for deterministic mock generation. Useful for snapshot testing.
delayMsnumber | ((ctx: ExecutionContext) => number)undefinedSimulated network latency in milliseconds.
jsfobject(jsf defaults)JSON Schema Faker configuration.
recordingobjectundefinedRecording and replay configuration.
debugbooleanfalseVerbose logging for troubleshooting.

specSource

TypeTypeTypical use
"object"OpenAPISpecStatic spec object.
"url"stringLink to a centralized or externally hosted spec.
"file"stringLocal file path to a json/yaml file.

jsf

JSON Schema Faker configuration:

OptionTypeDefaultDescription
alwaysFakeOptionalsbooleanInclude optional properties in generated data.
useDefaultValuebooleanUse schema default values when present.
minItemsnumberMinimum array size.
maxItemsnumberMaximum array size.
formatsRecord<string, () => any>Custom format generators.
extend(jsf: any) => voidAdvanced configuration hook.

Example:

ts
jsf: {
  alwaysFakeOptionals: true,
  useDefaultValue: true,
  minItems: 1,
  maxItems: 5,
  formats: {
    uuid: () => crypto.randomUUID(),
  },
  extend: (jsf) => {
    jsf.option("failOnInvalidTypes", false);
  },
}

recording

Recording and replay configuration for capturing real (non-mocked) responses. See Recording & Replay for detailed documentation.

OptionTypeDefaultDescription
dirstringDirectory to store/load recordings.
capturebooleanfalseSave real controller responses to disk.
matchBodybooleanfalseInclude request body in replay key matching.
redactArray<string>Headers to redact from stored recordings.

Async Configuration

Use forRootAsync() for dependency injection:

ts
MockModule.forRootAsync({
  imports: [ConfigModule],
  useFactory: (config: ConfigService) => ({
    specSource: { type: "object", spec: config.get("OPENAPI_SPEC") },
    enable: config.get("MOCK_ENABLED"),
    strategyOrder: config.get("MOCK_STRATEGY").split(","),
  }),
  inject: [ConfigService],
});

Released under the MIT License.