Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions docs/content/docs/reference/configuration/output.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,64 @@ export interface Pet {
}
```

## factoryMethods

**Type:** `Object`
**Default:** `{ generate: false }`

Generate factory methods for DTOs (Data Transfer Objects) initialized with safe default values. Useful for testing and initializing empty state.
Functionality handles OpenAPI `readOnly` and `writeOnly` flags to generate appropriate payload structures:
- **Required properties:** Always included in the factory output, regardless of their visibility flags.
- **Optional `readOnly` properties:** Always omitted from the factory output, as they would be dropped by the server.
- **Optional `writeOnly` properties:** Always included in the factory output (even if `includeOptionalProperty` is set to `false`).

```ts title="orval.config.ts"
export default defineConfig({
petstore: {
output: {
factoryMethods: {
functionNamePrefix: 'create',
mode: 'split',
includeOptionalProperty: true,
outputDirectory: `#output.workspace.schemas`,
},
},
},
});
```

### functionNamePrefix

**Type:** `String`
**Default:** `'create'`

Prefix for the generated factory function names.

### mode

**Type:** `'single' | 'split' | 'single-split'`
**Default:** `'split'`

Where to generate the factory methods:
- `single`: Appends the factory function to the schema file.
- `split`: Creates a `{schema}.factory.ts` with factory method. By default it is placed next to schema file.
- `single-split`: Aggregates all factory methods into a single `factoryMethods.ts` file.

### includeOptionalProperty

**Type:** `boolean`
**Default:** `true`

Determines whether optional schema properties are included in the default factory output.

### outputDirectory

**Type:** `String`
**Default:** `#output.workspace.schemas`

Defaults to the value configured in `#output.workspace.schemas`.
Determines where factory methods will be generated (can be used to generated methods away from schema directory).
Takes effect only when used `mode` is `split` or `single-split`.
---

## Other Options
Expand Down
6 changes: 6 additions & 0 deletions packages/angular/src/http-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ const createOutput = (
optionsParamRequired: false,
unionAddMissingProperties: false,
propertySortOrder: 'Specification',
factoryMethods: {
functionNamePrefix: 'create',
mode: 'single',
outputDirectory: '',
includeOptionalProperty: false,
},
...overrides,
} satisfies NormalizedOutputOptions;

Expand Down
6 changes: 6 additions & 0 deletions packages/angular/src/http-resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ const createOutput = (
optionsParamRequired: false,
unionAddMissingProperties: false,
propertySortOrder: 'Specification',
factoryMethods: {
functionNamePrefix: 'create',
mode: 'single',
outputDirectory: '',
includeOptionalProperty: false,
},
...overrides,
} satisfies NormalizedOutputOptions;

Expand Down
Loading
Loading