|
2 | 2 |
|
3 | 3 | 
|
4 | 4 |
|
5 |
| -[Redoc](https://github.com/redocly/redoc) for [Docusaurus v2](https://v2.docusaurus.io/). |
| 5 | +[Redoc](https://github.com/redocly/redoc) for [Docusaurus](https://docusaurus.io/). |
6 | 6 |
|
7 | 7 | ## Usage
|
8 | 8 |
|
| 9 | +1. Setup [docusaurus project](https://docusaurus.io/docs/installation) |
| 10 | + |
9 | 11 | 1. Install redocusaurus:
|
10 | 12 |
|
11 |
| - ```sh |
12 |
| - npm i --save redocusaurus |
13 |
| - # OR |
14 |
| - yarn add redocusaurus |
15 |
| - ``` |
| 13 | +```sh |
| 14 | +yarn add redocusaurus |
| 15 | +# OR |
| 16 | +pnpm add redocusaurus |
| 17 | +# OR |
| 18 | +npm i --save redocusaurus |
| 19 | +``` |
16 | 20 |
|
17 | 21 | 1. Add it as a preset to your docusaurus config along with [@docusaurus/preset-classic](https://docusaurus.io/docs/using-plugins#docusauruspreset-classic) and pass options:
|
18 | 22 |
|
19 |
| - - Pass it a path to a local OpenAPI YAML file |
20 |
| - |
21 |
| - ```js |
22 |
| - // docusaurus.config.js |
23 |
| - |
24 |
| - module.exports = { |
25 |
| - // ... |
26 |
| - presets: [ |
27 |
| - // .. Your other presets' config |
28 |
| - '@docusaurus/preset-classic', |
29 |
| - // Redocusaurus config |
30 |
| - [ |
31 |
| - 'redocusaurus', |
32 |
| - { |
33 |
| - // Plugin Options for loading OpenAPI files |
34 |
| - specs: [ |
35 |
| - { |
36 |
| - spec: 'openapi/openapi.yaml', |
37 |
| - route: '/api/', |
38 |
| - }, |
39 |
| - ], |
40 |
| - // Theme Options for modifying how redoc renders them |
41 |
| - theme: { |
42 |
| - // Change with your site colors |
43 |
| - primaryColor: '#1890ff', |
44 |
| - }, |
45 |
| - }, |
46 |
| - ], |
47 |
| - ], |
48 |
| - // ... |
49 |
| - }; |
50 |
| - ``` |
51 |
| - |
52 |
| -- OR Pass it a OpenAPI spec URL |
53 |
| - |
54 |
| - ```js |
55 |
| - // docusaurus.config.js |
56 |
| -
|
57 |
| - module.exports = { |
58 |
| - // ... |
59 |
| - presets: [ |
60 |
| - // .. Your other presets' config |
61 |
| - '@docusaurus/preset-classic', |
62 |
| - // Redocusaurus config |
63 |
| - [ |
64 |
| - 'redocusaurus', |
65 |
| - { |
66 |
| - // Plugin Options for loading OpenAPI files |
67 |
| - specs: [ |
68 |
| - { |
69 |
| - spec: 'https://redocly.github.io/redoc/openapi.yaml', |
70 |
| - route: '/api/', |
71 |
| - }, |
72 |
| - ], |
73 |
| - // Theme Options for modifying how redoc renders them |
74 |
| - theme: { |
75 |
| - // Change with your site colors |
76 |
| - primaryColor: '#1890ff', |
77 |
| - }, |
78 |
| - }, |
79 |
| - ], |
80 |
| - ], |
81 |
| - // ... |
82 |
| - }; |
83 |
| - ``` |
| 23 | + ```js |
| 24 | + // docusaurus.config.ts |
| 25 | + import type { Config } from '@docusaurus/types'; |
| 26 | + import type * as Preset from '@docusaurus/preset-classic'; |
| 27 | + import type * as Redocusaurus from 'redocusaurus'; |
| 28 | + |
| 29 | + const config: Config = { |
| 30 | + // ... |
| 31 | + presets: [ |
| 32 | + // .. Your other presets' config |
| 33 | + [ |
| 34 | + '@docusaurus/preset-classic', |
| 35 | + { |
| 36 | + googleAnalytics: { |
| 37 | + trackingID: 'XXXXXX', |
| 38 | + }, |
| 39 | + } satisfies Preset.Options, |
| 40 | + ] |
| 41 | + // Redocusaurus config |
| 42 | + [ |
| 43 | + 'redocusaurus', |
| 44 | + { |
| 45 | + // Plugin Options for loading OpenAPI files |
| 46 | + specs: [ |
| 47 | + // Pass it a path to a local OpenAPI YAML file |
| 48 | + { |
| 49 | + // Redocusaurus will automatically bundle your spec into a single file during the build |
| 50 | + spec: 'openapi/index.yaml', |
| 51 | + route: '/api/', |
| 52 | + }, |
| 53 | + // You can also pass it a OpenAPI spec URL |
| 54 | + { |
| 55 | + spec: 'https://redocly.github.io/redoc/openapi.yaml', |
| 56 | + route: '/openapi/', |
| 57 | + }, |
| 58 | + ], |
| 59 | + // Theme Options for modifying how redoc renders them |
| 60 | + theme: { |
| 61 | + // Change with your site colors |
| 62 | + primaryColor: '#1890ff', |
| 63 | + }, |
| 64 | + }, |
| 65 | + ] satisfies Redocusaurus.PresetEntry, |
| 66 | + ], |
| 67 | + // ... Rest of your config |
| 68 | + }; |
| 69 | + |
| 70 | + export default config; |
| 71 | + ``` |
84 | 72 |
|
85 | 73 | The API Doc will be available at the route specified (`/api/` in the example above). To customize it see [full plugin options](https://redocusaurus.vercel.app/docs/getting-started/plugin-options).
|
86 | 74 |
|
|
0 commit comments