Skip to content

Commit cfb9ed1

Browse files
committed
refactor: simplify output location, updated instructions, allow TypeDoc config options to be passed
1 parent 95a3459 commit cfb9ed1

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

docs/src/pages/reference/configuration/output.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,15 @@ Default Value: `false`.
394394

395395
Will generate API docs using [TypeDoc](https://typedoc.org/). by default these docs will be in Markdown format.
396396

397-
TypeDoc can be configured by creating a config file e.g. `typedoc.config.mjs` in your project root (see the [config docs](https://typedoc.org/options/configuration/#options) for a full list of supported file names) or by passing a config filename to the `config` option below.
397+
TypeDoc can be configured by passing the [options](https://typedoc.org/options/) to the `docs` object or by creating a config file e.g. `typedoc.config.mjs` in your project root (see the [config docs](https://typedoc.org/options/configuration/#options) for a full list of supported file names) or by passing a config filename to the `configPath` option below.
398398

399399
See the TypeDoc [configuration documentation](https://typedoc.org/options/) for more details.
400400

401401
The `docs` option can take some properties to customize the generation if you set it to an object. If you set it to `true`, the default options will be used.
402402

403-
#### config
403+
When no output directory destination is specified in `config`, the file will be output to the `docs` directory by default.
404+
405+
#### configPath
404406

405407
Type: `String`.
406408

packages/core/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"@types/lodash.uniq": "^4.5.9",
2525
"@types/lodash.uniqby": "^4.7.9",
2626
"@types/lodash.uniqwith": "^4.5.9",
27-
"@types/micromatch": "^4.0.9"
27+
"@types/micromatch": "^4.0.9",
28+
"typedoc": "0.26.11"
2829
},
2930
"dependencies": {
3031
"@apidevtools/swagger-parser": "^10.1.0",

packages/core/src/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
} from 'openapi3-ts/oas30';
1313
// @ts-ignore // FIXME when running `yarn test` getting `orval:test: ../core/src/types.ts(12,34): error TS7016: Could not find a declaration file for module 'swagger2openapi'. '/home/maxim/orval/node_modules/swagger2openapi/index.js' implicitly has an 'any' type.`
1414
import type swagger2openapi from 'swagger2openapi';
15+
import { TypeDocOptions } from 'typedoc';
1516

1617
export interface Options {
1718
output?: string | OutputOptions;
@@ -242,8 +243,8 @@ export const OutputMode = {
242243
export type OutputMode = (typeof OutputMode)[keyof typeof OutputMode];
243244

244245
export type OutputDocsOptions = {
245-
config: string;
246-
};
246+
configPath?: string;
247+
} & Partial<TypeDocOptions>;
247248

248249
// TODO: add support for other mock types (like cypress or playwright)
249250
export const OutputMockType = {

packages/orval/src/write-specs.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
import chalk from 'chalk';
1919
import execa from 'execa';
2020
import fs from 'fs-extra';
21-
import { Application } from 'typedoc';
21+
import { Application, TypeDocOptions } from 'typedoc';
2222
import uniq from 'lodash.uniq';
2323
import { InfoObject } from 'openapi3-ts/oas30';
2424
import { executeHook } from './utils';
@@ -201,12 +201,18 @@ export const writeSpecs = async (
201201

202202
if (output.docs) {
203203
try {
204+
let config: Partial<TypeDocOptions> = {};
205+
let configPath: string | null = null;
206+
if (typeof output.docs === 'object') {
207+
({ configPath = null, ...config } = output.docs);
208+
if (configPath) {
209+
config.options = configPath;
210+
}
211+
}
204212
const app = await Application.bootstrapWithPlugins({
205213
entryPoints: paths,
206214
// Set the custom config location if it has been provided.
207-
...(typeof output.docs === 'object'
208-
? { options: output.docs.config }
209-
: {}),
215+
...config,
210216
plugin: ['typedoc-plugin-markdown'],
211217
});
212218
// Set defaults if the have not been provided by the external config.
@@ -218,19 +224,7 @@ export const writeSpecs = async (
218224
}
219225
const project = await app.convert();
220226
if (project) {
221-
let out = 'docs';
222-
if (app.options.isSet('out')) {
223-
// Use the output location if it has been set in the external config.
224-
out = app.options.getValue('out');
225-
} else if (output.workspace) {
226-
// Generate the docs in the workspace.
227-
out = upath.join(output.workspace, 'docs');
228-
} else if (output.target) {
229-
const base = upath.dirname(output.target);
230-
// Generate the docs along side the output target.
231-
out = upath.join(base, 'docs');
232-
}
233-
await app.generateDocs(project, out);
227+
await app.generateDocs(project, app.options.getValue('out'));
234228
} else {
235229
throw new Error('TypeDoc not initialised');
236230
}

0 commit comments

Comments
 (0)