docusaurus-plugin-openapi-docs 0.0.0-376 → 0.0.0-380
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -13
- package/lib/index.js +8 -2
- package/lib/options.js +3 -2
- package/lib/sidebars/index.js +2 -1
- package/lib/types.d.ts +11 -10
- package/package.json +2 -2
- package/src/index.ts +15 -2
- package/src/options.ts +3 -2
- package/src/sidebars/index.ts +2 -1
- package/src/types.ts +10 -9
package/README.md
CHANGED
|
@@ -20,6 +20,13 @@ OpenAPI plugin for generating API reference docs in Docusaurus v2.
|
|
|
20
20
|
|
|
21
21
|
The `docusaurus-plugin-openapi-docs` package extends the Docusaurus CLI with commands for generating MDX using the OpenAPI specification as the source. The resulting MDX is fully compatible with [plugin-content-docs](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-docs) and can be used to render beautiful reference API docs by setting `docItemComponent` to `@theme/ApiItem`, a custom component included in the `docusaurus-theme-openapi-docs` theme.
|
|
22
22
|
|
|
23
|
+
Key Features:
|
|
24
|
+
|
|
25
|
+
- **Compatible:** Works with Swagger 2.0 and OpenAPI 3.x.
|
|
26
|
+
- **Fast:** Convert large OpenAPI specs into MDX docs in seconds. 🔥
|
|
27
|
+
- **Stylish:** Based on the same [Infima styling framework](https://infima.dev/) that powers the Docusaurus UI.
|
|
28
|
+
- **Capable:** Supports single, multi and _even micro_ OpenAPI specs.
|
|
29
|
+
|
|
23
30
|
## Installation
|
|
24
31
|
|
|
25
32
|
Plugin:
|
|
@@ -71,7 +78,6 @@ Here is an example of properly configuring your `docusaurus.config.js` file for
|
|
|
71
78
|
],
|
|
72
79
|
|
|
73
80
|
plugins: [
|
|
74
|
-
[
|
|
75
81
|
'docusaurus-plugin-openapi-docs',
|
|
76
82
|
{
|
|
77
83
|
id: "apiDocs",
|
|
@@ -101,24 +107,42 @@ Here is an example of properly configuring your `docusaurus.config.js` file for
|
|
|
101
107
|
|
|
102
108
|
`docusaurus-plugin-openapi-docs` can be configured with the following options:
|
|
103
109
|
|
|
104
|
-
| Name
|
|
105
|
-
|
|
|
106
|
-
| `specPath`
|
|
107
|
-
| `ouputDir`
|
|
108
|
-
| `
|
|
109
|
-
| `
|
|
110
|
+
| Name | Type | Default | Description |
|
|
111
|
+
| ----------------- | -------- | ------- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
112
|
+
| `specPath` | `string` | `null` | Designated URL or path to the source of an OpenAPI specification file or directory of multiple OpenAPI specification files. |
|
|
113
|
+
| `ouputDir` | `string` | `null` | Desired output path for generated MDX files. |
|
|
114
|
+
| `contentDocsPath` | `string` | `null` | Should be equal to the `path` value set in `plugin-content-docs` or preset. |
|
|
115
|
+
| `ouputDir` | `string` | `null` | Desired output path for generated MDX files. |
|
|
116
|
+
| `routeBasePath` | `string` | `null` | _Optional:_ Should be equal to the `routeBasePath` value set in `plugin-content-docs or preset (if present). |
|
|
117
|
+
| `template` | `string` | `null` | _Optional:_ Customize MDX content with a desired template. |
|
|
118
|
+
| `sidebarOptions` | `object` | `null` | _Optional:_ Set of options for sidebar configuration. See below for a list of supported options. |
|
|
119
|
+
| `version` | `string` | `null` | _Optional:_ Version assigned to single or micro-spec API specified in `specPath`. |
|
|
120
|
+
| `label` | `string` | `null` | _Optional:_ Version label used when generating version selector dropdown menu. |
|
|
121
|
+
| `baseUrl` | `string` | `null` | _Optional:_ Version base URL used when generating version selector dropdown menu. |
|
|
122
|
+
| `versions` | `object` | `null` | _Optional:_ Set of options for versioning configuration. See below for a list of supported options. |
|
|
110
123
|
|
|
111
124
|
`sidebarOptions` can be configured with the following options:
|
|
112
125
|
|
|
113
126
|
| Name | Type | Default | Description |
|
|
114
127
|
| -------------------- | --------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
115
128
|
| `groupPathsBy` | `string` | `null` | Organize and group sidebar slice by specified option. Note: Currently, `groupPathsBy` only contains support for grouping by `tag`. |
|
|
116
|
-
| `categoryLinkSource` | `string` | `null` | Defines what source to use for rendering category link pages when grouping paths by tag. <br
|
|
129
|
+
| `categoryLinkSource` | `string` | `null` | Defines what source to use for rendering category link pages when grouping paths by tag. <br/><br/>The supported options are as follows: <br/><br/> `tag`: Sets the category link config type to `generated-index` and uses the tag description as the link config description. <br/><br/>`info`: Sets the category link config type to `doc` and renders the `info` section as the category link (recommended only for multi/micro-spec scenarios). |
|
|
117
130
|
| `sidebarCollapsible` | `boolean` | `true` | Whether sidebar categories are collapsible by default. |
|
|
118
131
|
| `sidebarCollapsed` | `boolean` | `true` | Whether sidebar categories are collapsed by default. |
|
|
119
132
|
| `customProps` | `object` | `null` | Additional props for customizing a sidebar item. |
|
|
120
133
|
|
|
121
|
-
>
|
|
134
|
+
> You may optionally configure a `sidebarOptions`. In doing so, an individual `sidebar.js` slice with the configured options will be generated within the respective `outputDir`.
|
|
135
|
+
|
|
136
|
+
`versions` can be configured with the following options:
|
|
137
|
+
|
|
138
|
+
| Name | Type | Default | Description |
|
|
139
|
+
| ---------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------ |
|
|
140
|
+
| `specPath` | `string` | `null` | Designated URL or path to the source of an OpenAPI specification file or directory of micro OpenAPI specification files. |
|
|
141
|
+
| `ouputDir` | `string` | `null` | Desired output path for versioned, generated MDX files. |
|
|
142
|
+
| `label` | `string` | `null` | _Optional:_ Version label used when generating version selector dropdown menu. |
|
|
143
|
+
| `baseUrl` | `string` | `null` | _Optional:_ Version base URL used when generating version selector dropdown menu. |
|
|
144
|
+
|
|
145
|
+
> All versions will automatically inherit `sidebarOptions` from the parent/base config.
|
|
122
146
|
|
|
123
147
|
## CLI Usage
|
|
124
148
|
|
|
@@ -139,9 +163,11 @@ Commands:
|
|
|
139
163
|
write-translations [options] [siteDir] Extract required translations of your site.
|
|
140
164
|
write-heading-ids [options] [siteDir] [files...] Generate heading ids in Markdown content.
|
|
141
165
|
docs:version <version> Tag a new docs version
|
|
142
|
-
gen-api-docs <id> Generates
|
|
143
|
-
|
|
144
|
-
docs
|
|
166
|
+
gen-api-docs <id> Generates OpenAPI docs in MDX file format and sidebar.js (if enabled).
|
|
167
|
+
gen-api-docs:version <id:version> Generates versioned OpenAPI docs in MDX file format, versions.js and sidebar.js (if enabled).
|
|
168
|
+
clean-api-docs <id> Clears the generated OpenAPI docs MDX files and sidebar.js (if enabled).
|
|
169
|
+
clean-api-docs:version <id:version> Clears the versioned, generated OpenAPI docs MDX files, versions.json and sidebar.js (if
|
|
170
|
+
enabled).
|
|
145
171
|
```
|
|
146
172
|
|
|
147
173
|
### Generating OpenAPI Docs
|
|
@@ -190,6 +216,61 @@ yarn docusaurus clean-api-docs burgers
|
|
|
190
216
|
|
|
191
217
|
> The example above will remove all API docs relative to `burgers`.
|
|
192
218
|
|
|
219
|
+
### Versioning OpenAPI docs
|
|
220
|
+
|
|
221
|
+
To generate _all_ versioned OpenAPI docs, run the following command from the root directory of your project:
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
yarn docusaurus gen-api-docs:version <id>:all
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Example:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
yarn docusaurus gen-api-docs:version petstore:all
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
> This will generate API docs for all of the OpenAPI specification (OAS) files referenced in your `versions` config and will also generate a `versions.json` file.
|
|
234
|
+
|
|
235
|
+
> Substitue `all` with a specific version ID to generate/clean a specific version. Generating for `all` or a specific version ID will automatically update the `versions.json` file.
|
|
236
|
+
|
|
237
|
+
## Installing from Template
|
|
238
|
+
|
|
239
|
+
Run the following to bootstrap a Docsaurus v2 site (classic theme) with `docusaurus-openapi-docs`:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
npx create-docusaurus@2.0.0-beta.21 my-website --package-manager yarn
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
> When prompted to select a template choose `Git repository`.
|
|
246
|
+
|
|
247
|
+
Template Repository URL:
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
https://github.com/PaloAltoNetworks/docusaurus-template-openapi-docs.git
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
> When asked how the template repo should be cloned choose "copy" (unless you know better).
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
cd my-website
|
|
257
|
+
yarn
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Developer Quick Start
|
|
261
|
+
|
|
262
|
+
> Looking to make a contribution? Make sure to checkout out our contributing guide.
|
|
263
|
+
|
|
264
|
+
After [forking](https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/fork) the main repository, run the following:
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
git clone https://github.com/<your account>/docusaurus-openapi-docs.git
|
|
268
|
+
cd docusaurus-openapi-docs
|
|
269
|
+
yarn
|
|
270
|
+
yarn build-packages
|
|
271
|
+
yarn watch:demo
|
|
272
|
+
```
|
|
273
|
+
|
|
193
274
|
## Support
|
|
194
275
|
|
|
195
|
-
Please read [SUPPORT.md](SUPPORT.md) for details on how to get support for this project.
|
|
276
|
+
Please read [SUPPORT.md](https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/blob/main/SUPPORT.md) for details on how to get support for this project.
|
package/lib/index.js
CHANGED
|
@@ -27,7 +27,7 @@ function pluginOpenAPIDocs(context, options) {
|
|
|
27
27
|
let { config } = options;
|
|
28
28
|
let { siteDir } = context;
|
|
29
29
|
async function generateApiDocs(options) {
|
|
30
|
-
let { specPath, outputDir, template, sidebarOptions } = options;
|
|
30
|
+
let { specPath, outputDir, contentDocsPath, routeBasePath, template, sidebarOptions, } = options;
|
|
31
31
|
const contentPath = isURL(specPath)
|
|
32
32
|
? specPath
|
|
33
33
|
: path_1.default.resolve(siteDir, specPath);
|
|
@@ -135,8 +135,14 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
135
135
|
item.markdown = markdown;
|
|
136
136
|
if (item.type === "api") {
|
|
137
137
|
item.json = JSON.stringify(item.api);
|
|
138
|
+
let infoBasePath = `${outputDir}/${item.infoId}`;
|
|
139
|
+
if (routeBasePath) {
|
|
140
|
+
infoBasePath = `${routeBasePath}/${outputDir
|
|
141
|
+
.split(contentDocsPath)[1]
|
|
142
|
+
.replace(/^\/+/g, "")}/${item.infoId}`.replace(/^\/+/g, "");
|
|
143
|
+
}
|
|
138
144
|
if (item.infoId)
|
|
139
|
-
item.infoPath =
|
|
145
|
+
item.infoPath = infoBasePath;
|
|
140
146
|
}
|
|
141
147
|
const view = (0, mustache_1.render)(mdTemplate, item);
|
|
142
148
|
const utils = (0, mustache_1.render)(infoMdTemplate, item);
|
package/lib/options.js
CHANGED
|
@@ -9,19 +9,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.OptionsSchema = void 0;
|
|
10
10
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
11
11
|
const sidebarOptions = utils_validation_1.Joi.object({
|
|
12
|
-
contentDocsPath: utils_validation_1.Joi.string(),
|
|
13
12
|
groupPathsBy: utils_validation_1.Joi.string().valid("tag"),
|
|
14
13
|
categoryLinkSource: utils_validation_1.Joi.string().valid("tag", "info"),
|
|
15
14
|
customProps: utils_validation_1.Joi.object(),
|
|
16
15
|
sidebarCollapsible: utils_validation_1.Joi.boolean(),
|
|
17
16
|
sidebarCollapsed: utils_validation_1.Joi.boolean(),
|
|
18
|
-
})
|
|
17
|
+
});
|
|
19
18
|
exports.OptionsSchema = utils_validation_1.Joi.object({
|
|
20
19
|
id: utils_validation_1.Joi.string().required(),
|
|
21
20
|
config: utils_validation_1.Joi.object()
|
|
22
21
|
.pattern(/^/, utils_validation_1.Joi.object({
|
|
23
22
|
specPath: utils_validation_1.Joi.string().required(),
|
|
24
23
|
outputDir: utils_validation_1.Joi.string().required(),
|
|
24
|
+
contentDocsPath: utils_validation_1.Joi.string().required(),
|
|
25
|
+
routeBasePath: utils_validation_1.Joi.string(),
|
|
25
26
|
template: utils_validation_1.Joi.string(),
|
|
26
27
|
sidebarOptions: sidebarOptions,
|
|
27
28
|
version: utils_validation_1.Joi.string().when("versions", {
|
package/lib/sidebars/index.js
CHANGED
|
@@ -20,7 +20,8 @@ function isInfoItem(item) {
|
|
|
20
20
|
}
|
|
21
21
|
function groupByTags(items, sidebarOptions, options, tags) {
|
|
22
22
|
const { outputDir } = options;
|
|
23
|
-
const { sidebarCollapsed, sidebarCollapsible, customProps, categoryLinkSource,
|
|
23
|
+
const { sidebarCollapsed, sidebarCollapsible, customProps, categoryLinkSource, } = sidebarOptions;
|
|
24
|
+
const { contentDocsPath } = options;
|
|
24
25
|
const apiItems = items.filter(isApiItem);
|
|
25
26
|
const infoItems = items.filter(isInfoItem);
|
|
26
27
|
const intros = infoItems.map((item) => {
|
package/lib/types.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export interface PluginOptions {
|
|
|
10
10
|
export interface APIOptions {
|
|
11
11
|
specPath: string;
|
|
12
12
|
outputDir: string;
|
|
13
|
+
contentDocsPath: string;
|
|
14
|
+
routeBasePath?: string;
|
|
13
15
|
template?: string;
|
|
14
16
|
sidebarOptions?: SidebarOptions;
|
|
15
17
|
version?: string;
|
|
@@ -19,6 +21,15 @@ export interface APIOptions {
|
|
|
19
21
|
[key: string]: APIVersionOptions;
|
|
20
22
|
};
|
|
21
23
|
}
|
|
24
|
+
export interface SidebarOptions {
|
|
25
|
+
groupPathsBy?: string;
|
|
26
|
+
categoryLinkSource?: string;
|
|
27
|
+
customProps?: {
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
};
|
|
30
|
+
sidebarCollapsible?: boolean;
|
|
31
|
+
sidebarCollapsed?: boolean;
|
|
32
|
+
}
|
|
22
33
|
export interface APIVersionOptions {
|
|
23
34
|
specPath: string;
|
|
24
35
|
outputDir: string;
|
|
@@ -80,13 +91,3 @@ export interface ApiNavLink {
|
|
|
80
91
|
title: string;
|
|
81
92
|
permalink: string;
|
|
82
93
|
}
|
|
83
|
-
export interface SidebarOptions {
|
|
84
|
-
contentDocsPath?: string;
|
|
85
|
-
groupPathsBy?: string;
|
|
86
|
-
categoryLinkSource?: string;
|
|
87
|
-
customProps?: {
|
|
88
|
-
[key: string]: unknown;
|
|
89
|
-
};
|
|
90
|
-
sidebarCollapsible?: boolean;
|
|
91
|
-
sidebarCollapsed?: boolean;
|
|
92
|
-
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docusaurus-plugin-openapi-docs",
|
|
3
3
|
"description": "OpenAPI plugin for Docusaurus.",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-380",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"engines": {
|
|
63
63
|
"node": ">=14"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "3322e621893b40124fed23abd7f7aa8f12fed5af"
|
|
66
66
|
}
|
package/src/index.ts
CHANGED
|
@@ -31,7 +31,14 @@ export default function pluginOpenAPIDocs(
|
|
|
31
31
|
let { siteDir } = context;
|
|
32
32
|
|
|
33
33
|
async function generateApiDocs(options: APIOptions) {
|
|
34
|
-
let {
|
|
34
|
+
let {
|
|
35
|
+
specPath,
|
|
36
|
+
outputDir,
|
|
37
|
+
contentDocsPath,
|
|
38
|
+
routeBasePath,
|
|
39
|
+
template,
|
|
40
|
+
sidebarOptions,
|
|
41
|
+
} = options;
|
|
35
42
|
|
|
36
43
|
const contentPath = isURL(specPath)
|
|
37
44
|
? specPath
|
|
@@ -164,7 +171,13 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
164
171
|
item.markdown = markdown;
|
|
165
172
|
if (item.type === "api") {
|
|
166
173
|
item.json = JSON.stringify(item.api);
|
|
167
|
-
|
|
174
|
+
let infoBasePath = `${outputDir}/${item.infoId}`;
|
|
175
|
+
if (routeBasePath) {
|
|
176
|
+
infoBasePath = `${routeBasePath}/${outputDir
|
|
177
|
+
.split(contentDocsPath!)[1]
|
|
178
|
+
.replace(/^\/+/g, "")}/${item.infoId}`.replace(/^\/+/g, "");
|
|
179
|
+
}
|
|
180
|
+
if (item.infoId) item.infoPath = infoBasePath;
|
|
168
181
|
}
|
|
169
182
|
|
|
170
183
|
const view = render(mdTemplate, item);
|
package/src/options.ts
CHANGED
|
@@ -8,13 +8,12 @@
|
|
|
8
8
|
import { Joi } from "@docusaurus/utils-validation";
|
|
9
9
|
|
|
10
10
|
const sidebarOptions = Joi.object({
|
|
11
|
-
contentDocsPath: Joi.string(),
|
|
12
11
|
groupPathsBy: Joi.string().valid("tag"),
|
|
13
12
|
categoryLinkSource: Joi.string().valid("tag", "info"),
|
|
14
13
|
customProps: Joi.object(),
|
|
15
14
|
sidebarCollapsible: Joi.boolean(),
|
|
16
15
|
sidebarCollapsed: Joi.boolean(),
|
|
17
|
-
})
|
|
16
|
+
});
|
|
18
17
|
|
|
19
18
|
export const OptionsSchema = Joi.object({
|
|
20
19
|
id: Joi.string().required(),
|
|
@@ -24,6 +23,8 @@ export const OptionsSchema = Joi.object({
|
|
|
24
23
|
Joi.object({
|
|
25
24
|
specPath: Joi.string().required(),
|
|
26
25
|
outputDir: Joi.string().required(),
|
|
26
|
+
contentDocsPath: Joi.string().required(),
|
|
27
|
+
routeBasePath: Joi.string(),
|
|
27
28
|
template: Joi.string(),
|
|
28
29
|
sidebarOptions: sidebarOptions,
|
|
29
30
|
version: Joi.string().when("versions", {
|
package/src/sidebars/index.ts
CHANGED
|
@@ -43,9 +43,10 @@ function groupByTags(
|
|
|
43
43
|
sidebarCollapsible,
|
|
44
44
|
customProps,
|
|
45
45
|
categoryLinkSource,
|
|
46
|
-
contentDocsPath,
|
|
47
46
|
} = sidebarOptions;
|
|
48
47
|
|
|
48
|
+
const { contentDocsPath } = options;
|
|
49
|
+
|
|
49
50
|
const apiItems = items.filter(isApiItem);
|
|
50
51
|
const infoItems = items.filter(isInfoItem);
|
|
51
52
|
const intros = infoItems.map((item: any) => {
|
package/src/types.ts
CHANGED
|
@@ -30,6 +30,8 @@ export interface PluginOptions {
|
|
|
30
30
|
export interface APIOptions {
|
|
31
31
|
specPath: string;
|
|
32
32
|
outputDir: string;
|
|
33
|
+
contentDocsPath: string;
|
|
34
|
+
routeBasePath?: string;
|
|
33
35
|
template?: string;
|
|
34
36
|
sidebarOptions?: SidebarOptions;
|
|
35
37
|
version?: string;
|
|
@@ -40,6 +42,14 @@ export interface APIOptions {
|
|
|
40
42
|
};
|
|
41
43
|
}
|
|
42
44
|
|
|
45
|
+
export interface SidebarOptions {
|
|
46
|
+
groupPathsBy?: string;
|
|
47
|
+
categoryLinkSource?: string;
|
|
48
|
+
customProps?: { [key: string]: unknown };
|
|
49
|
+
sidebarCollapsible?: boolean;
|
|
50
|
+
sidebarCollapsed?: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
43
53
|
export interface APIVersionOptions {
|
|
44
54
|
specPath: string;
|
|
45
55
|
outputDir: string;
|
|
@@ -112,12 +122,3 @@ export interface ApiNavLink {
|
|
|
112
122
|
title: string;
|
|
113
123
|
permalink: string;
|
|
114
124
|
}
|
|
115
|
-
|
|
116
|
-
export interface SidebarOptions {
|
|
117
|
-
contentDocsPath?: string;
|
|
118
|
-
groupPathsBy?: string;
|
|
119
|
-
categoryLinkSource?: string;
|
|
120
|
-
customProps?: { [key: string]: unknown };
|
|
121
|
-
sidebarCollapsible?: boolean;
|
|
122
|
-
sidebarCollapsed?: boolean;
|
|
123
|
-
}
|