docusaurus-plugin-openapi-docs 3.0.0-beta.9 → 3.0.0
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 +86 -61
- package/lib/index.d.ts +1 -1
- package/lib/index.js +24 -24
- package/lib/markdown/createRequestSchema.js +0 -6
- package/lib/markdown/createResponseSchema.js +0 -5
- package/lib/markdown/createSchema.js +66 -60
- package/lib/markdown/createSchema.test.js +77 -0
- package/lib/markdown/createStatusCodes.js +1 -1
- package/lib/markdown/createVersionBadge.js +1 -1
- package/lib/markdown/utils.js +1 -1
- package/lib/openapi/openapi.js +38 -33
- package/lib/openapi/openapi.test.js +2 -0
- package/lib/openapi/types.d.ts +2 -1
- package/lib/options.js +3 -0
- package/lib/sidebars/index.js +30 -11
- package/lib/types.d.ts +4 -1
- package/package.json +4 -4
- package/src/index.ts +35 -31
- package/src/markdown/__snapshots__/createSchema.test.ts.snap +221 -0
- package/src/markdown/createRequestSchema.ts +0 -6
- package/src/markdown/createResponseSchema.ts +0 -6
- package/src/markdown/createSchema.test.ts +88 -0
- package/src/markdown/createSchema.ts +76 -70
- package/src/markdown/createStatusCodes.ts +1 -1
- package/src/markdown/createVersionBadge.ts +8 -4
- package/src/markdown/utils.ts +1 -1
- package/src/openapi/__fixtures__/examples/openapi.yaml +7 -0
- package/src/openapi/openapi.test.ts +4 -0
- package/src/openapi/openapi.ts +43 -33
- package/src/openapi/types.ts +2 -1
- package/src/openapi-to-postmanv2.d.ts +1 -1
- package/src/options.ts +3 -0
- package/src/postman-collection.d.ts +1 -1
- package/src/sidebars/index.ts +55 -27
- package/src/types.ts +4 -1
package/README.md
CHANGED
|
@@ -6,23 +6,33 @@
|
|
|
6
6
|
|
|
7
7
|
<div align="center">
|
|
8
8
|
|
|
9
|
-
OpenAPI plugin for generating API reference docs in Docusaurus
|
|
9
|
+
OpenAPI plugin for generating API reference docs in Docusaurus v3.
|
|
10
|
+
|
|
11
|
+
<img src="https://img.shields.io/badge/dynamic/json?style=for-the-badge&logo=meta&color=blueviolet&label=Docusaurus&query=dependencies%5B%22%40docusaurus%2Fcore%22%5D&url=https%3A%2F%2Fraw.githubusercontent.com%2FPaloAltoNetworks%2Fdocusaurus-openapi-docs%2Fmain%2Fdemo%2Fpackage.json" />
|
|
12
|
+
<br/><br/>
|
|
13
|
+
|
|
14
|
+
[](https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/blob/HEAD/LICENSE) [](https://www.npmjs.com/package/docusaurus-plugin-openapi-docs) [](https://www.npmjs.com/package/docusaurus-plugin-openapi-docs) [](https://www.npmjs.com/package/docusaurus-plugin-openapi-docs) [](https://www.npmjs.com/package/docusaurus-plugin-openapi-docs)
|
|
15
|
+
<br/>
|
|
16
|
+
[](https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/actions/workflows/validate.yaml) [](https://github.com/prettier/prettier) [](https://www.cypress.io/) [](https://github.com/facebook/jest) [](https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/blob/HEAD/CONTRIBUTING.md#pull-requests)
|
|
17
|
+
<br />
|
|
10
18
|
|
|
11
19
|
</div>
|
|
12
20
|
|
|
13
21
|
<p align="center">
|
|
14
22
|
|
|
15
|
-
<img
|
|
23
|
+
<img src="https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/assets/9343811/d4e75f15-7daf-48d2-a772-a0c49aa25d26" width="900" />
|
|
16
24
|
|
|
17
25
|
</p>
|
|
18
26
|
|
|
27
|
+
---
|
|
28
|
+
|
|
19
29
|
## Overview
|
|
20
30
|
|
|
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
|
|
31
|
+
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 when combined with the `docusaurus-theme-openapi-docs` theme.
|
|
22
32
|
|
|
23
33
|
Key Features:
|
|
24
34
|
|
|
25
|
-
- **Compatible:** Works with Swagger 2.0 and OpenAPI 3.
|
|
35
|
+
- **Compatible:** Works with Swagger 2.0 and OpenAPI 3.x.
|
|
26
36
|
- **Fast:** Convert large OpenAPI specs into MDX docs in seconds. 🔥
|
|
27
37
|
- **Stylish:** Based on the same [Infima styling framework](https://infima.dev/) that powers the Docusaurus UI.
|
|
28
38
|
- **Flexible:** Supports single, multi and _even micro_ OpenAPI specs.
|
|
@@ -31,16 +41,16 @@ Key Features:
|
|
|
31
41
|
|
|
32
42
|
| Docusaurus OpenAPI Docs | Docusaurus |
|
|
33
43
|
| ----------------------- | --------------- |
|
|
34
|
-
| 3.0.0
|
|
35
|
-
| 2.0
|
|
44
|
+
| 3.0.0 (current) | `3.0.1 - 3.4.0` |
|
|
45
|
+
| 2.2.0 (legacy) | `2.4.1 - 2.4.3` |
|
|
36
46
|
| 1.7.3 (legacy) | `2.0.1 - 2.2.0` |
|
|
37
47
|
|
|
38
48
|
## Bootstrapping from Template (new Docusaurus site)
|
|
39
49
|
|
|
40
|
-
Run the following to bootstrap a Docsaurus
|
|
50
|
+
Run the following to bootstrap a Docsaurus v3 site (classic theme) with `docusaurus-openapi-docs`:
|
|
41
51
|
|
|
42
52
|
```bash
|
|
43
|
-
npx create-docusaurus@
|
|
53
|
+
npx create-docusaurus@3.4.0 my-website --package-manager yarn
|
|
44
54
|
```
|
|
45
55
|
|
|
46
56
|
> When prompted to select a template choose `Git repository`.
|
|
@@ -51,57 +61,59 @@ Template Repository URL:
|
|
|
51
61
|
https://github.com/PaloAltoNetworks/docusaurus-template-openapi-docs.git
|
|
52
62
|
```
|
|
53
63
|
|
|
54
|
-
> When asked how the template repo should be cloned choose "copy"
|
|
64
|
+
> When asked how the template repo should be cloned choose "copy".
|
|
55
65
|
|
|
56
66
|
```bash
|
|
57
67
|
cd my-website
|
|
58
68
|
yarn start
|
|
59
69
|
```
|
|
60
70
|
|
|
71
|
+
If all goes well, you should be greeted by a brand new Docusaurus site that includes API reference docs for the ubiquitous Petstore API!
|
|
72
|
+
|
|
61
73
|
## Installation (existing Docusaurus site)
|
|
62
74
|
|
|
63
|
-
|
|
75
|
+
> Both the plugin and theme are currently designed to pair with a specific Docusaurus release. The Docusaurus badge in the `README.md` and at the top of this page will always reflect the current compatible versions.
|
|
76
|
+
|
|
77
|
+
### Plugin
|
|
64
78
|
|
|
65
79
|
```bash
|
|
66
80
|
yarn add docusaurus-plugin-openapi-docs
|
|
67
81
|
```
|
|
68
82
|
|
|
69
|
-
Theme
|
|
83
|
+
### Theme
|
|
70
84
|
|
|
71
85
|
```bash
|
|
72
86
|
yarn add docusaurus-theme-openapi-docs
|
|
73
87
|
```
|
|
74
88
|
|
|
75
|
-
## Configuring `docusaurus.config.
|
|
89
|
+
## Configuring `docusaurus.config.ts` (Plugin and theme usage)
|
|
76
90
|
|
|
77
|
-
Here is an example of properly configuring `docusaurus.config.
|
|
91
|
+
Here is an example of properly configuring `docusaurus.config.ts` for `docusaurus-plugin-openapi-docs` and `docusaurus-theme-openapi-docs` usage.
|
|
78
92
|
|
|
79
|
-
|
|
80
|
-
|
|
93
|
+
> Note: Instructions may differ slightly for sites that haven't migrated to typescript.
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
// docusaurus.config.ts
|
|
97
|
+
// note that parts of the complete config were left out for brevity
|
|
98
|
+
import type * as Preset from "@docusaurus/preset-classic";
|
|
99
|
+
import type { Config } from "@docusaurus/types";
|
|
100
|
+
import type * as Plugin from "@docusaurus/types/src/plugin";
|
|
101
|
+
import type * as OpenApiPlugin from "docusaurus-plugin-openapi-docs";
|
|
81
102
|
|
|
82
103
|
{
|
|
83
104
|
presets: [
|
|
84
105
|
[
|
|
85
106
|
"classic",
|
|
86
|
-
|
|
87
|
-
({
|
|
107
|
+
{
|
|
88
108
|
docs: {
|
|
89
|
-
sidebarPath:
|
|
90
|
-
|
|
91
|
-
"https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/",
|
|
92
|
-
docLayoutComponent: "@theme/DocPage",
|
|
93
|
-
docItemComponent: "@theme/ApiItem" // derived from docusaurus-theme-openapi-docs
|
|
94
|
-
},
|
|
95
|
-
blog: {
|
|
96
|
-
showReadingTime: true,
|
|
97
|
-
editUrl:
|
|
98
|
-
"https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/"
|
|
109
|
+
sidebarPath: "./sidebars.ts",
|
|
110
|
+
docItemComponent: "@theme/ApiItem", // Derived from docusaurus-theme-openapi
|
|
99
111
|
},
|
|
100
112
|
theme: {
|
|
101
|
-
customCss:
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
]
|
|
113
|
+
customCss: "./src/css/custom.css",
|
|
114
|
+
},
|
|
115
|
+
} satisfies Preset.Options,
|
|
116
|
+
],
|
|
105
117
|
],
|
|
106
118
|
|
|
107
119
|
plugins: [
|
|
@@ -109,19 +121,15 @@ Here is an example of properly configuring `docusaurus.config.js` file for `docu
|
|
|
109
121
|
'docusaurus-plugin-openapi-docs',
|
|
110
122
|
{
|
|
111
123
|
id: "api", // plugin id
|
|
112
|
-
docsPluginId: "classic", //
|
|
124
|
+
docsPluginId: "classic", // configured for preset-classic
|
|
113
125
|
config: {
|
|
114
|
-
petstore: {
|
|
115
|
-
specPath: "examples/petstore.yaml",
|
|
116
|
-
outputDir: "
|
|
117
|
-
sidebarOptions: {
|
|
118
|
-
groupPathsBy: "tag",
|
|
126
|
+
petstore: {
|
|
127
|
+
specPath: "examples/petstore.yaml",
|
|
128
|
+
outputDir: "docs/petstore",
|
|
129
|
+
sidebarOptions: {
|
|
130
|
+
groupPathsBy: "tag",
|
|
119
131
|
},
|
|
120
|
-
},
|
|
121
|
-
burgers: {
|
|
122
|
-
specPath: "examples/food/burgers/openapi.yaml",
|
|
123
|
-
outputDir: "api/food/burgers",
|
|
124
|
-
}
|
|
132
|
+
} satisfies OpenApiPlugin.Options,
|
|
125
133
|
}
|
|
126
134
|
},
|
|
127
135
|
]
|
|
@@ -136,10 +144,11 @@ Here is an example of properly configuring `docusaurus.config.js` file for `docu
|
|
|
136
144
|
|
|
137
145
|
The `docusaurus-plugin-openapi-docs` plugin can be configured with the following options:
|
|
138
146
|
|
|
139
|
-
| Name | Type | Default
|
|
140
|
-
| -------------- | -------- |
|
|
141
|
-
| `id` | `string` | `null`
|
|
142
|
-
| `
|
|
147
|
+
| Name | Type | Default | Description |
|
|
148
|
+
| -------------- | -------- | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
149
|
+
| `id` | `string` | `null` | A unique plugin ID. |
|
|
150
|
+
| `docsPlugin` | `string` | `@docusaurus/plugin-content-docs` | The plugin used to render the OpenAPI docs (ignored if the plugin instance referenced by `docsPluginId` is a `preset`). |
|
|
151
|
+
| `docsPluginId` | `string` | `null` | The plugin ID associated with the `preset` or configured `docsPlugin` instance used to render the OpenAPI docs (e.g. "your-plugin-id", "classic", "default"). |
|
|
143
152
|
|
|
144
153
|
### config
|
|
145
154
|
|
|
@@ -148,7 +157,7 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
|
|
|
148
157
|
| Name | Type | Default | Description |
|
|
149
158
|
| -------------------- | --------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
150
159
|
| `specPath` | `string` | `null` | Designated URL or path to the source of an OpenAPI specification file or directory of multiple OpenAPI specification files. |
|
|
151
|
-
| `ouputDir` | `string` | `null` | Desired output path for generated MDX files.
|
|
160
|
+
| `ouputDir` | `string` | `null` | Desired output path for generated MDX and sidebar files. |
|
|
152
161
|
| `proxy` | `string` | `null` | _Optional:_ Proxy URL to prepend to base URL when performing API requests from browser. |
|
|
153
162
|
| `template` | `string` | `null` | _Optional:_ Customize MDX content with a desired template. |
|
|
154
163
|
| `downloadUrl` | `string` | `null` | _Optional:_ Designated URL for downloading OpenAPI specification. (requires `info` section/doc) |
|
|
@@ -166,7 +175,7 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
|
|
|
166
175
|
|
|
167
176
|
| Name | Type | Default | Description |
|
|
168
177
|
| -------------------- | --------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
169
|
-
| `groupPathsBy` | `string` | `null` | Organize and group sidebar slice by specified option. Note: Currently, `groupPathsBy` only contains support for grouping by `tag`.
|
|
178
|
+
| `groupPathsBy` | `string` | `null` | Organize and group sidebar slice by specified option. Note: Currently, `groupPathsBy` only contains support for grouping by `tag` and `tagGroup`. |
|
|
170
179
|
| `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). <br/><br/>`none`: Does not create pages for categories, only groups that can be expanded/collapsed. |
|
|
171
180
|
| `sidebarCollapsible` | `boolean` | `true` | Whether sidebar categories are collapsible by default. |
|
|
172
181
|
| `sidebarCollapsed` | `boolean` | `true` | Whether sidebar categories are collapsed by default. |
|
|
@@ -189,11 +198,12 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
|
|
|
189
198
|
|
|
190
199
|
`markdownGenerators` can be configured with the following options:
|
|
191
200
|
|
|
192
|
-
| Name
|
|
193
|
-
|
|
|
194
|
-
| `createApiPageMD`
|
|
195
|
-
| `createInfoPageMD`
|
|
196
|
-
| `createTagPageMD`
|
|
201
|
+
| Name | Type | Default | Description |
|
|
202
|
+
| -------------------- | ---------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
203
|
+
| `createApiPageMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for API pages.<br/><br/>**Function type:** `(pageData: ApiPageMetadata) => string` |
|
|
204
|
+
| `createInfoPageMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for info pages.<br/><br/>**Function type:** `(pageData: InfoPageMetadata) => string` |
|
|
205
|
+
| `createTagPageMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for tag pages.<br/><br/>**Function type:** `(pageData: TagPageMetadata) => string` |
|
|
206
|
+
| `createSchemaPageMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for schema pages.<br/><br/>**Function type:** `(pageData: SchemaPageMetadata) => string` |
|
|
197
207
|
|
|
198
208
|
## CLI Usage
|
|
199
209
|
|
|
@@ -214,11 +224,12 @@ Commands:
|
|
|
214
224
|
write-translations [options] [siteDir] Extract required translations of your site.
|
|
215
225
|
write-heading-ids [options] [siteDir] [files...] Generate heading ids in Markdown content.
|
|
216
226
|
docs:version <version> Tag a new docs version
|
|
217
|
-
gen-api-docs <id>
|
|
218
|
-
gen-api-docs:version <id:version>
|
|
219
|
-
clean-api-docs <id> Clears the generated OpenAPI docs MDX files and sidebar.js (if enabled).
|
|
220
|
-
clean-api-docs:version <id:version> Clears the versioned, generated OpenAPI docs MDX files, versions.json and sidebar.js (if
|
|
227
|
+
gen-api-docs [options] <id> Generates OpenAPI docs in MDX file format and sidebar.ts (if enabled).
|
|
228
|
+
gen-api-docs:version [options] <id:version> Generates versioned OpenAPI docs in MDX file format, versions.js and sidebar.ts (if
|
|
221
229
|
enabled).
|
|
230
|
+
clean-api-docs [options] <id> Clears the generated OpenAPI docs MDX files and sidebar.ts (if enabled).
|
|
231
|
+
clean-api-docs:version [options] <id:version> Clears the versioned, generated OpenAPI docs MDX files, versions.json and sidebar.ts
|
|
232
|
+
(if enabled)
|
|
222
233
|
```
|
|
223
234
|
|
|
224
235
|
### Generating OpenAPI Docs
|
|
@@ -240,10 +251,10 @@ yarn docusaurus gen-api-docs <id>
|
|
|
240
251
|
Example:
|
|
241
252
|
|
|
242
253
|
```bash
|
|
243
|
-
yarn docusaurus gen-api-docs
|
|
254
|
+
yarn docusaurus gen-api-docs petstore
|
|
244
255
|
```
|
|
245
256
|
|
|
246
|
-
> The example above will only generate API docs relative to `
|
|
257
|
+
> The example above will only generate API docs relative to `petstore`.
|
|
247
258
|
|
|
248
259
|
### Cleaning API Docs
|
|
249
260
|
|
|
@@ -262,7 +273,7 @@ yarn docusaurus clean-api-docs <id>
|
|
|
262
273
|
Example:
|
|
263
274
|
|
|
264
275
|
```bash
|
|
265
|
-
yarn docusaurus clean-api-docs
|
|
276
|
+
yarn docusaurus clean-api-docs petstore
|
|
266
277
|
```
|
|
267
278
|
|
|
268
279
|
> The example above will remove all API docs relative to `burgers`.
|
|
@@ -299,6 +310,20 @@ yarn build-packages
|
|
|
299
310
|
yarn watch:demo
|
|
300
311
|
```
|
|
301
312
|
|
|
313
|
+
## Credits
|
|
314
|
+
|
|
315
|
+
Special thanks to @bourdakos1 (Nick Bourdakos), the author of [docusaurus-openapi](https://github.com/cloud-annotations/docusaurus-openapi), which this project is heavily based on.
|
|
316
|
+
|
|
317
|
+
For more insight into why we decided to completely fork see [#47](https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/pull/47)
|
|
318
|
+
|
|
319
|
+
## Contributors
|
|
320
|
+
|
|
321
|
+
<a href="https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/graphs/contributors">
|
|
322
|
+
<img src="https://contrib.rocks/image?repo=PaloAltoNetworks/docusaurus-openapi-docs" />
|
|
323
|
+
</a>
|
|
324
|
+
|
|
302
325
|
## Support
|
|
303
326
|
|
|
304
|
-
|
|
327
|
+
See [SUPPORT.md](https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/blob/main/SUPPORT.md) for our support agreement and guidelines.
|
|
328
|
+
|
|
329
|
+
If you believe you found a bug or have an idea you'd like to suggest you may [report an issue](https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/issues/new/choose) or [start a discussion](https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/discussions/new/choose).
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { LoadContext, Plugin } from "@docusaurus/types";
|
|
2
2
|
import type { PluginOptions, LoadedContent } from "./types";
|
|
3
3
|
export declare function isURL(str: string): boolean;
|
|
4
|
-
export declare function getDocsPluginConfig(presetsPlugins: any[], pluginId: string): Object | undefined;
|
|
4
|
+
export declare function getDocsPluginConfig(presetsPlugins: any[], plugin: string, pluginId: string): Object | undefined;
|
|
5
5
|
declare function pluginOpenAPIDocs(context: LoadContext, options: PluginOptions): Plugin<LoadedContent>;
|
|
6
6
|
declare namespace pluginOpenAPIDocs {
|
|
7
7
|
var validateOptions: ({ options, validate }: any) => any;
|
package/lib/index.js
CHANGED
|
@@ -25,7 +25,7 @@ function isURL(str) {
|
|
|
25
25
|
return /^(https?:)\/\//m.test(str);
|
|
26
26
|
}
|
|
27
27
|
exports.isURL = isURL;
|
|
28
|
-
function getDocsPluginConfig(presetsPlugins, pluginId) {
|
|
28
|
+
function getDocsPluginConfig(presetsPlugins, plugin, pluginId) {
|
|
29
29
|
// eslint-disable-next-line array-callback-return
|
|
30
30
|
const filteredConfig = presetsPlugins.filter((data) => {
|
|
31
31
|
// Search presets
|
|
@@ -34,8 +34,7 @@ function getDocsPluginConfig(presetsPlugins, pluginId) {
|
|
|
34
34
|
return data[1];
|
|
35
35
|
}
|
|
36
36
|
// Search plugin-content-docs instances
|
|
37
|
-
if (typeof data[0] === "string" &&
|
|
38
|
-
data[0] === "@docusaurus/plugin-content-docs") {
|
|
37
|
+
if (typeof data[0] === "string" && data[0] === plugin) {
|
|
39
38
|
const configPluginId = data[1].id ? data[1].id : "default";
|
|
40
39
|
if (configPluginId === pluginId) {
|
|
41
40
|
return data[1];
|
|
@@ -49,7 +48,7 @@ function getDocsPluginConfig(presetsPlugins, pluginId) {
|
|
|
49
48
|
return filteredConfig[1].docs;
|
|
50
49
|
}
|
|
51
50
|
// Search plugin-content-docs instances
|
|
52
|
-
if (filteredConfig[0] ===
|
|
51
|
+
if (filteredConfig[0] === plugin) {
|
|
53
52
|
const configPluginId = filteredConfig[1].id
|
|
54
53
|
? filteredConfig[1].id
|
|
55
54
|
: "default";
|
|
@@ -68,23 +67,23 @@ function getPluginInstances(plugins) {
|
|
|
68
67
|
return plugins.filter((data) => data[0] === "docusaurus-plugin-openapi-docs");
|
|
69
68
|
}
|
|
70
69
|
function pluginOpenAPIDocs(context, options) {
|
|
71
|
-
const { config, docsPluginId } = options;
|
|
70
|
+
const { config, docsPlugin = "@docusaurus/plugin-content-docs", docsPluginId, } = options;
|
|
72
71
|
const { siteDir, siteConfig } = context;
|
|
73
72
|
// Get routeBasePath and path from plugin-content-docs or preset
|
|
74
73
|
const presets = siteConfig.presets;
|
|
75
74
|
const plugins = siteConfig.plugins;
|
|
76
75
|
const presetsPlugins = presets.concat(plugins);
|
|
77
|
-
let docData = getDocsPluginConfig(presetsPlugins, docsPluginId);
|
|
76
|
+
let docData = getDocsPluginConfig(presetsPlugins, docsPlugin, docsPluginId);
|
|
78
77
|
let docRouteBasePath = docData ? docData.routeBasePath : undefined;
|
|
79
78
|
let docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
|
|
80
79
|
async function generateApiDocs(options, pluginId) {
|
|
81
80
|
var _a, _b, _c, _d;
|
|
82
|
-
let { specPath, outputDir, template, markdownGenerators, downloadUrl, sidebarOptions, } = options;
|
|
81
|
+
let { specPath, outputDir, template, markdownGenerators, downloadUrl, sidebarOptions, disableCompression, } = options;
|
|
83
82
|
// Remove trailing slash before proceeding
|
|
84
83
|
outputDir = outputDir.replace(/\/$/, "");
|
|
85
84
|
// Override docPath if pluginId provided
|
|
86
85
|
if (pluginId) {
|
|
87
|
-
docData = getDocsPluginConfig(presetsPlugins, pluginId);
|
|
86
|
+
docData = getDocsPluginConfig(presetsPlugins, docsPlugin, pluginId);
|
|
88
87
|
docRouteBasePath = docData ? docData.routeBasePath : undefined;
|
|
89
88
|
docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
|
|
90
89
|
}
|
|
@@ -222,7 +221,7 @@ custom_edit_url: null
|
|
|
222
221
|
};
|
|
223
222
|
loadedApi.map(async (item) => {
|
|
224
223
|
if (item.type === "info") {
|
|
225
|
-
if (downloadUrl
|
|
224
|
+
if (downloadUrl) {
|
|
226
225
|
item.downloadUrl = downloadUrl;
|
|
227
226
|
}
|
|
228
227
|
}
|
|
@@ -236,9 +235,11 @@ custom_edit_url: null
|
|
|
236
235
|
// const deserialize = (s: any) => {
|
|
237
236
|
// return zlib.inflateSync(Buffer.from(s, "base64")).toString();
|
|
238
237
|
// };
|
|
239
|
-
|
|
240
|
-
.
|
|
241
|
-
.
|
|
238
|
+
disableCompression === true
|
|
239
|
+
? (item.json = JSON.stringify(item.api))
|
|
240
|
+
: (item.json = zlib_1.default
|
|
241
|
+
.deflateSync(JSON.stringify(item.api))
|
|
242
|
+
.toString("base64"));
|
|
242
243
|
let infoBasePath = `${outputDir}/${item.infoId}`;
|
|
243
244
|
if (docRouteBasePath) {
|
|
244
245
|
infoBasePath = `${docRouteBasePath}/${outputDir
|
|
@@ -334,11 +335,7 @@ custom_edit_url: null
|
|
|
334
335
|
cwd: path_1.default.resolve(apiDir),
|
|
335
336
|
deep: 1,
|
|
336
337
|
});
|
|
337
|
-
const
|
|
338
|
-
cwd: path_1.default.resolve(apiDir, "schemas"),
|
|
339
|
-
deep: 1,
|
|
340
|
-
});
|
|
341
|
-
const sidebarFile = await (0, utils_1.Globby)(["sidebar.js"], {
|
|
338
|
+
const sidebarFile = await (0, utils_1.Globby)(["sidebar.js", "sidebar.ts"], {
|
|
342
339
|
cwd: path_1.default.resolve(apiDir),
|
|
343
340
|
deep: 1,
|
|
344
341
|
});
|
|
@@ -350,14 +347,15 @@ custom_edit_url: null
|
|
|
350
347
|
console.log(chalk_1.default.green(`Cleanup succeeded for "${apiDir}/${mdx}"`));
|
|
351
348
|
}
|
|
352
349
|
}));
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
350
|
+
try {
|
|
351
|
+
fs_1.default.rmSync(`${apiDir}/schemas`, { recursive: true });
|
|
352
|
+
console.log(chalk_1.default.green(`Cleanup succeeded for "${apiDir}/schemas"`));
|
|
353
|
+
}
|
|
354
|
+
catch (err) {
|
|
355
|
+
if (err.code !== "ENOENT") {
|
|
356
|
+
console.error(chalk_1.default.red(`Cleanup failed for "${apiDir}/schemas"`), chalk_1.default.yellow(err));
|
|
359
357
|
}
|
|
360
|
-
}
|
|
358
|
+
}
|
|
361
359
|
sidebarFile.map((sidebar) => fs_1.default.unlink(`${apiDir}/${sidebar}`, (err) => {
|
|
362
360
|
if (err) {
|
|
363
361
|
console.error(chalk_1.default.red(`Cleanup failed for "${apiDir}/${sidebar}"`), chalk_1.default.yellow(err));
|
|
@@ -374,6 +372,7 @@ custom_edit_url: null
|
|
|
374
372
|
version: version,
|
|
375
373
|
label: metadata.label,
|
|
376
374
|
baseUrl: metadata.baseUrl,
|
|
375
|
+
downloadUrl: metadata.downloadUrl,
|
|
377
376
|
});
|
|
378
377
|
}
|
|
379
378
|
const versionsJson = JSON.stringify(versionsArray, null, 2);
|
|
@@ -493,6 +492,7 @@ custom_edit_url: null
|
|
|
493
492
|
delete parentConfig.version;
|
|
494
493
|
delete parentConfig.label;
|
|
495
494
|
delete parentConfig.baseUrl;
|
|
495
|
+
delete parentConfig.downloadUrl;
|
|
496
496
|
// TODO: handle when no versions are defined by version command is passed
|
|
497
497
|
if (versionId === "all") {
|
|
498
498
|
if (versions[id]) {
|
|
@@ -88,12 +88,6 @@ function createRequestSchema({ title, body, ...rest }) {
|
|
|
88
88
|
if (firstBody === undefined) {
|
|
89
89
|
return undefined;
|
|
90
90
|
}
|
|
91
|
-
// we don't show the table if there is no properties to show
|
|
92
|
-
if (firstBody.properties !== undefined) {
|
|
93
|
-
if (Object.keys(firstBody.properties).length === 0) {
|
|
94
|
-
return undefined;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
91
|
return (0, utils_1.create)("MimeTabs", {
|
|
98
92
|
className: "openapi-tabs__mime",
|
|
99
93
|
children: [
|
|
@@ -36,11 +36,6 @@ function createResponseSchema({ title, body, ...rest }) {
|
|
|
36
36
|
responseExamples === undefined) {
|
|
37
37
|
return undefined;
|
|
38
38
|
}
|
|
39
|
-
if ((firstBody === null || firstBody === void 0 ? void 0 : firstBody.properties) !== undefined) {
|
|
40
|
-
if (Object.keys(firstBody === null || firstBody === void 0 ? void 0 : firstBody.properties).length === 0) {
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
39
|
return (0, utils_1.create)("TabItem", {
|
|
45
40
|
label: `${mimeType}`,
|
|
46
41
|
value: `${mimeType}`,
|