|
| 1 | +# Options |
| 2 | + |
| 3 | +## Configuration Options |
| 4 | + |
| 5 | +| Option | Type | Default | Description | |
| 6 | +| --------------------------- | ---------------------------------------------------------------------------------------------------------- | -------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | |
| 7 | +| [`specSource`](#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. | |
| 8 | +| `enable` | `boolean` | `true` | Master switch: registers the mock interceptor globally. When `false`, interceptor is not registered. | |
| 9 | +| `mockByDefault` | `boolean` | `false` | Controls default mocking behavior. When `false`, mock only when explicitly requested via headers or decorators. | |
| 10 | +| `strategyOrder` | `Array<"records" \| "mediatype-examples" \| "schema-examples" \| "jsf" \| "primitive" \| "passthrough">` | `["mediatype-examples", "schema-examples", "jsf"]` | Ordered list of strategies to attempt when generating responses. | |
| 11 | +| `defaultStatus` | `number` | `200` | Default HTTP status code when not specified elsewhere. | |
| 12 | +| `seed` | `number \| string` | `undefined` | Seed for deterministic mock generation. Useful for snapshot testing. | |
| 13 | +| `delayMs` | `number \| ((ctx: ExecutionContext) => number)` | `undefined` | Simulated network latency in milliseconds. | |
| 14 | +| [`jsf`](#jsf) | `object` | (jsf defaults) | JSON Schema Faker configuration. | |
| 15 | +| [`recording`](#recording) | `object` | `undefined` | Recording and replay configuration. | |
| 16 | +| `debug` | `boolean` | `false` | Verbose logging for troubleshooting. | |
| 17 | + |
| 18 | +### `specSource` |
| 19 | + |
| 20 | +| Type | Type | Typical use | |
| 21 | +| ---------- | ------------- | ------------------------------------------------ | |
| 22 | +| `"object"` | `OpenAPISpec` | Static spec object. | |
| 23 | +| `"url"` | `string` | Link to a centralized or externally hosted spec. | |
| 24 | +| `"file"` | `string` | Local file path to a json/yaml file. | |
| 25 | + |
| 26 | +### `jsf` |
| 27 | + |
| 28 | +JSON Schema Faker configuration: |
| 29 | + |
| 30 | +| Option | Type | Default | Description | |
| 31 | +| --------------------- | --------------------------- | ------- | ---------------------------------------------- | |
| 32 | +| `alwaysFakeOptionals` | `boolean` | — | Include optional properties in generated data. | |
| 33 | +| `useDefaultValue` | `boolean` | — | Use schema `default` values when present. | |
| 34 | +| `minItems` | `number` | — | Minimum array size. | |
| 35 | +| `maxItems` | `number` | — | Maximum array size. | |
| 36 | +| `formats` | `Record<string, () => any>` | — | Custom format generators. | |
| 37 | +| `extend` | `(jsf: any) => void` | — | Advanced configuration hook. | |
| 38 | + |
| 39 | +**Example:** |
| 40 | + |
| 41 | +```ts |
| 42 | +jsf: { |
| 43 | + alwaysFakeOptionals: true, |
| 44 | + useDefaultValue: true, |
| 45 | + minItems: 1, |
| 46 | + maxItems: 5, |
| 47 | + formats: { |
| 48 | + uuid: () => crypto.randomUUID(), |
| 49 | + }, |
| 50 | + extend: (jsf) => { |
| 51 | + jsf.option("failOnInvalidTypes", false); |
| 52 | + }, |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +### `recording` |
| 57 | + |
| 58 | +Recording and replay configuration for capturing real (non-mocked) responses. See [Recording & Replay](./recording.md) for detailed documentation. |
| 59 | + |
| 60 | +| Option | Type | Default | Description | |
| 61 | +| ----------- | --------------- | ------- | -------------------------------------------- | |
| 62 | +| `dir` | `string` | — | Directory to store/load recordings. | |
| 63 | +| `capture` | `boolean` | `false` | Save real controller responses to disk. | |
| 64 | +| `matchBody` | `boolean` | `false` | Include request body in replay key matching. | |
| 65 | +| `redact` | `Array<string>` | — | Headers to redact from stored recordings. | |
| 66 | + |
| 67 | +## Async Configuration |
| 68 | + |
| 69 | +Use `forRootAsync()` for dependency injection: |
| 70 | + |
| 71 | +```ts |
| 72 | +MockModule.forRootAsync({ |
| 73 | + imports: [ConfigModule], |
| 74 | + useFactory: (config: ConfigService) => ({ |
| 75 | + specSource: { type: "object", spec: config.get("OPENAPI_SPEC") }, |
| 76 | + enable: config.get("MOCK_ENABLED"), |
| 77 | + strategyOrder: config.get("MOCK_STRATEGY").split(","), |
| 78 | + }), |
| 79 | + inject: [ConfigService], |
| 80 | +}); |
| 81 | +``` |
0 commit comments