docusaurus-plugin-openapi-docs 1.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/LICENSE +21 -0
- package/README.md +194 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +194 -0
- package/lib/markdown/createDeprecationNotice.d.ts +6 -0
- package/lib/markdown/createDeprecationNotice.js +19 -0
- package/lib/markdown/createDescription.d.ts +1 -0
- package/lib/markdown/createDescription.js +16 -0
- package/lib/markdown/createDetails.d.ts +2 -0
- package/lib/markdown/createDetails.js +18 -0
- package/lib/markdown/createDetailsSummary.d.ts +2 -0
- package/lib/markdown/createDetailsSummary.js +18 -0
- package/lib/markdown/createFullWidthTable.d.ts +2 -0
- package/lib/markdown/createFullWidthTable.js +18 -0
- package/lib/markdown/createParamsDetails.d.ts +7 -0
- package/lib/markdown/createParamsDetails.js +44 -0
- package/lib/markdown/createParamsTable.d.ts +7 -0
- package/lib/markdown/createParamsTable.js +80 -0
- package/lib/markdown/createRequestBodyDetails.d.ts +6 -0
- package/lib/markdown/createRequestBodyDetails.js +14 -0
- package/lib/markdown/createRequestBodyTable.d.ts +6 -0
- package/lib/markdown/createRequestBodyTable.js +14 -0
- package/lib/markdown/createSchemaDetails.d.ts +14 -0
- package/lib/markdown/createSchemaDetails.js +241 -0
- package/lib/markdown/createSchemaTable.d.ts +14 -0
- package/lib/markdown/createSchemaTable.js +217 -0
- package/lib/markdown/createStatusCodes.d.ts +6 -0
- package/lib/markdown/createStatusCodes.js +47 -0
- package/lib/markdown/createVersionBadge.d.ts +1 -0
- package/lib/markdown/createVersionBadge.js +20 -0
- package/lib/markdown/index.d.ts +3 -0
- package/lib/markdown/index.js +43 -0
- package/lib/markdown/schema.d.ts +3 -0
- package/lib/markdown/schema.js +100 -0
- package/lib/markdown/schema.test.d.ts +1 -0
- package/lib/markdown/schema.test.js +171 -0
- package/lib/markdown/utils.d.ts +7 -0
- package/lib/markdown/utils.js +33 -0
- package/lib/openapi/createExample.d.ts +2 -0
- package/lib/openapi/createExample.js +113 -0
- package/lib/openapi/index.d.ts +1 -0
- package/lib/openapi/index.js +12 -0
- package/lib/openapi/openapi.d.ts +11 -0
- package/lib/openapi/openapi.js +233 -0
- package/lib/openapi/openapi.test.d.ts +1 -0
- package/lib/openapi/openapi.test.js +33 -0
- package/lib/openapi/types.d.ts +331 -0
- package/lib/openapi/types.js +8 -0
- package/lib/options.d.ts +4 -0
- package/lib/options.js +18 -0
- package/lib/sidebars/index.d.ts +3 -0
- package/lib/sidebars/index.js +89 -0
- package/lib/types.d.ts +68 -0
- package/lib/types.js +8 -0
- package/package.json +58 -0
- package/src/index.ts +244 -0
- package/src/markdown/createDeprecationNotice.ts +30 -0
- package/src/markdown/createDescription.ts +13 -0
- package/src/markdown/createDetails.ts +16 -0
- package/src/markdown/createDetailsSummary.ts +16 -0
- package/src/markdown/createFullWidthTable.ts +16 -0
- package/src/markdown/createParamsDetails.ts +53 -0
- package/src/markdown/createParamsTable.ts +102 -0
- package/src/markdown/createRequestBodyDetails.ts +17 -0
- package/src/markdown/createRequestBodyTable.ts +17 -0
- package/src/markdown/createSchemaDetails.ts +302 -0
- package/src/markdown/createSchemaTable.ts +275 -0
- package/src/markdown/createStatusCodes.ts +52 -0
- package/src/markdown/createVersionBadge.ts +18 -0
- package/src/markdown/index.ts +55 -0
- package/src/markdown/schema.test.ts +196 -0
- package/src/markdown/schema.ts +115 -0
- package/src/markdown/utils.ts +39 -0
- package/src/openapi/__fixtures__/examples/openapi.yaml +13 -0
- package/src/openapi/__fixtures__/examples/yogurtstore/_category_.json +4 -0
- package/src/openapi/__fixtures__/examples/yogurtstore/froyo.yaml +13 -0
- package/src/openapi/__fixtures__/examples/yogurtstore/nested/nested.yaml +13 -0
- package/src/openapi/createExample.ts +143 -0
- package/src/openapi/index.ts +8 -0
- package/src/openapi/openapi.test.ts +37 -0
- package/src/openapi/openapi.ts +293 -0
- package/src/openapi/types.ts +430 -0
- package/src/openapi-to-postmanv2.d.ts +10 -0
- package/src/options.ts +20 -0
- package/src/plugin-content-docs-types.d.ts +42 -0
- package/src/plugin-openapi.d.ts +87 -0
- package/src/sidebars/index.ts +121 -0
- package/src/types.ts +97 -0
- package/tsconfig.json +7 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Palo Alto Networks
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
<h1 align="center">Docusaurus OpenAPI Doc Generator</h1>
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
<img width="200" src="https://user-images.githubusercontent.com/9343811/165975569-1bc29814-884c-4931-83df-860043b625b7.svg" />
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
<div align="center">
|
|
8
|
+
|
|
9
|
+
OpenAPI plugin for generating API reference docs in Docusaurus v2.
|
|
10
|
+
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
|
|
15
|
+
<img width="650" alt="delete-a-pet" src="https://user-images.githubusercontent.com/9343811/165620346-d666db22-3587-4ddf-af58-947fddc9fe99.png">
|
|
16
|
+
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
## Overview
|
|
20
|
+
|
|
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
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
Plugin:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
yarn add docusaurus-plugin-openapi-docs
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Theme:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
yarn add docusaurus-theme-openapi-docs
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Configuring `docusaurus.config.js` (Plugin and theme usage)
|
|
38
|
+
|
|
39
|
+
Here is an example of properly configuring your `docusaurus.config.js` file for `docusaurus-plugin-openapi-docs` and `docusaurus-theme-openapi-docs` usage.
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
// docusaurus.config.js
|
|
43
|
+
|
|
44
|
+
{
|
|
45
|
+
presets: [
|
|
46
|
+
[
|
|
47
|
+
"classic",
|
|
48
|
+
/** @type {import('@docusaurus/preset-classic').Options} */
|
|
49
|
+
({
|
|
50
|
+
docs: {
|
|
51
|
+
sidebarPath: require.resolve("./sidebars.js"),
|
|
52
|
+
// Please change this to your repo.
|
|
53
|
+
// Remove this to remove the "edit this page" links.
|
|
54
|
+
editUrl:
|
|
55
|
+
"https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/",
|
|
56
|
+
docLayoutComponent: "@theme/DocPage",
|
|
57
|
+
docItemComponent: "@theme/ApiItem" // Derived from docusaurus-theme-openapi-docs
|
|
58
|
+
},
|
|
59
|
+
blog: {
|
|
60
|
+
showReadingTime: true,
|
|
61
|
+
// Please change this to your repo.
|
|
62
|
+
// Remove this to remove the "edit this page" links.
|
|
63
|
+
editUrl:
|
|
64
|
+
"https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/"
|
|
65
|
+
},
|
|
66
|
+
theme: {
|
|
67
|
+
customCss: require.resolve("./src/css/custom.css")
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
]
|
|
71
|
+
],
|
|
72
|
+
|
|
73
|
+
plugins: [
|
|
74
|
+
[
|
|
75
|
+
'docusaurus-plugin-openapi-docs',
|
|
76
|
+
{
|
|
77
|
+
id: "apiDocs",
|
|
78
|
+
config: {
|
|
79
|
+
petstore: { // Note: petstore key is treated as the <id> and can be used to specify an API doc instance when using CLI commands
|
|
80
|
+
specPath: "examples/petstore.yaml", // Path to designated spec file
|
|
81
|
+
outputDir: "api/petstore", // Output directory for generated .mdx docs
|
|
82
|
+
sidebarOptions: {
|
|
83
|
+
groupPathsBy: "tags",
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
burgers: {
|
|
87
|
+
specPath: "examples/food/burgers/openapi.yaml",
|
|
88
|
+
outputDir: "api/food/burgers",
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
]
|
|
93
|
+
],
|
|
94
|
+
themes: ["docusaurus-theme-openapi-docs"] // Allows use of @theme/ApiItem and other components
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
> Note: You may optionally configure a dedicated `@docusaurus/plugin-content-docs` instance for use with `docusaurus-theme-openapi-docs` by setting `docItemComponent` to `@theme/ApiItem`.
|
|
99
|
+
|
|
100
|
+
### Plugin Configuration Options
|
|
101
|
+
|
|
102
|
+
`docusaurus-plugin-openapi-docs` can be configured with the following options:
|
|
103
|
+
|
|
104
|
+
| Name | Type | Default | Description |
|
|
105
|
+
| ---------------- | -------- | ------- | -------------------------------------------------------------------------------------------------------------------- |
|
|
106
|
+
| `specPath` | `string` | `null` | Designated path to the source of an OpenAPI specification file or directory of multiple OpenAPI specification files. |
|
|
107
|
+
| `ouputDir` | `string` | `null` | Desired output path for generated MDX files. |
|
|
108
|
+
| `template` | `string` | `null` | _Optional:_ Customize MDX content with a desired template. |
|
|
109
|
+
| `sidebarOptions` | `object` | `null` | _Optional:_ Set of options for sidebar configuration. See below for a list of supported options. |
|
|
110
|
+
|
|
111
|
+
`sidebarOptions` can be configured with the following options:
|
|
112
|
+
|
|
113
|
+
| Name | Type | Default | Description |
|
|
114
|
+
| -------------------- | --------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
115
|
+
| `groupPathsBy` | `string` | `null` | Organize and group sidebar slice by specified option. Note: Currently, `groupPathsBy` only contains support for grouping by "tags". |
|
|
116
|
+
| `sidebarCollapsible` | `boolean` | `true` | Whether sidebar categories are collapsible by default. |
|
|
117
|
+
| `sidebarCollapsed` | `boolean` | `true` | Whether sidebar categories are collapsed by default. |
|
|
118
|
+
| `customProps` | `object` | `null` | Additional props for customizing a sidebar item. |
|
|
119
|
+
|
|
120
|
+
> Note: 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`.
|
|
121
|
+
|
|
122
|
+
## CLI Usage
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
Usage: docusaurus <command> [options]
|
|
126
|
+
|
|
127
|
+
Options:
|
|
128
|
+
-V, --version output the version number
|
|
129
|
+
-h, --help display help for command
|
|
130
|
+
|
|
131
|
+
Commands:
|
|
132
|
+
build [options] [siteDir] Build website.
|
|
133
|
+
swizzle [options] [themeName] [componentName] [siteDir] Wraps or ejects the original theme files into website folder for customization.
|
|
134
|
+
deploy [options] [siteDir] Deploy website to GitHub pages.
|
|
135
|
+
start [options] [siteDir] Start the development server.
|
|
136
|
+
serve [options] [siteDir] Serve website locally.
|
|
137
|
+
clear [siteDir] Remove build artifacts.
|
|
138
|
+
write-translations [options] [siteDir] Extract required translations of your site.
|
|
139
|
+
write-heading-ids [options] [siteDir] [files...] Generate heading ids in Markdown content.
|
|
140
|
+
docs:version <version> Tag a new docs version
|
|
141
|
+
gen-api-docs <id> Generates API Docs mdx and sidebars.
|
|
142
|
+
clean-api-docs <id> Clears the Generated API Docs mdx and sidebars.
|
|
143
|
+
docs:version:openapi <version> Tag a new docs version (openapi)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Generating OpenAPI Docs
|
|
147
|
+
|
|
148
|
+
To generate all OpenAPI docs, run the following command from the root directory of your project:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
yarn docusaurus gen-api-docs all
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
> This will generate API docs for all of the OpenAPI specification (OAS) files referenced in your `docusaurus-plugin-openapi-docs` config.
|
|
155
|
+
|
|
156
|
+
You may also generate OpenAPI docs for a single path or OAS by specifying the unique `id`:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
yarn docusaurus gen-api-docs <id>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Example:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
yarn docusaurus gen-api-docs burgers
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
> The example above will only generate API docs relative to `burgers`.
|
|
169
|
+
|
|
170
|
+
### Cleaning API Docs
|
|
171
|
+
|
|
172
|
+
To clean/remove all API Docs, run the following command from the root directory of your project:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
yarn docusaurus clean-api-docs all
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
You may also remove a particular set of API docs by specifying the unique `id` of your desired spec instance.
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
yarn docusaurus clean-api-docs <id>
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Example:
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
yarn docusaurus clean-api-docs burgers
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
> The example above will remove all API docs relative to `burgers`.
|
|
191
|
+
|
|
192
|
+
## Support
|
|
193
|
+
|
|
194
|
+
Please read [SUPPORT.md](SUPPORT.md) for details on how to get support for this project.
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
* ========================================================================== */
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const fs_1 = __importDefault(require("fs"));
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const utils_1 = require("@docusaurus/utils");
|
|
15
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
16
|
+
const mustache_1 = require("mustache");
|
|
17
|
+
const markdown_1 = require("./markdown");
|
|
18
|
+
const openapi_1 = require("./openapi");
|
|
19
|
+
const sidebars_1 = __importDefault(require("./sidebars"));
|
|
20
|
+
function pluginOpenAPI(context, options) {
|
|
21
|
+
let { config } = options;
|
|
22
|
+
let { siteDir } = context;
|
|
23
|
+
async function generateApiDocs(options) {
|
|
24
|
+
let { specPath, outputDir, template, sidebarOptions } = options;
|
|
25
|
+
const contentPath = path_1.default.resolve(siteDir, specPath);
|
|
26
|
+
try {
|
|
27
|
+
const openapiFiles = await (0, openapi_1.readOpenapiFiles)(contentPath, {});
|
|
28
|
+
const loadedApi = await (0, openapi_1.processOpenapiFiles)(openapiFiles);
|
|
29
|
+
if (!fs_1.default.existsSync(outputDir)) {
|
|
30
|
+
try {
|
|
31
|
+
fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
32
|
+
console.log(chalk_1.default.green(`Successfully created "${outputDir}"`));
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
console.error(chalk_1.default.red(`Failed to create "${outputDir}"`), chalk_1.default.yellow(err));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// TODO: figure out better way to set default
|
|
39
|
+
if (Object.keys(sidebarOptions !== null && sidebarOptions !== void 0 ? sidebarOptions : {}).length > 0) {
|
|
40
|
+
const sidebarSlice = (0, sidebars_1.default)(sidebarOptions, // TODO: find a better way to handle null
|
|
41
|
+
options, loadedApi);
|
|
42
|
+
const sidebarSliceTemplate = template
|
|
43
|
+
? fs_1.default.readFileSync(template).toString()
|
|
44
|
+
: `module.exports = {{{slice}}};`;
|
|
45
|
+
const view = (0, mustache_1.render)(sidebarSliceTemplate, {
|
|
46
|
+
slice: JSON.stringify(sidebarSlice),
|
|
47
|
+
});
|
|
48
|
+
if (!fs_1.default.existsSync(`${outputDir}/sidebar.js`)) {
|
|
49
|
+
try {
|
|
50
|
+
fs_1.default.writeFileSync(`${outputDir}/sidebar.js`, view, "utf8");
|
|
51
|
+
console.log(chalk_1.default.green(`Successfully created "${outputDir}/sidebar.js"`));
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
console.error(chalk_1.default.red(`Failed to write "${outputDir}/sidebar.js"`), chalk_1.default.yellow(err));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const mdTemplate = template
|
|
59
|
+
? fs_1.default.readFileSync(template).toString()
|
|
60
|
+
: `---
|
|
61
|
+
id: {{{id}}}
|
|
62
|
+
sidebar_label: {{{title}}}
|
|
63
|
+
{{^api}}
|
|
64
|
+
sidebar_position: 0
|
|
65
|
+
{{/api}}
|
|
66
|
+
hide_title: true
|
|
67
|
+
{{#api}}
|
|
68
|
+
hide_table_of_contents: true
|
|
69
|
+
{{/api}}
|
|
70
|
+
{{#json}}
|
|
71
|
+
api: {{{json}}}
|
|
72
|
+
{{/json}}
|
|
73
|
+
{{#api.method}}
|
|
74
|
+
sidebar_class_name: "{{{api.method}}} api-method"
|
|
75
|
+
{{/api.method}}
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
{{{markdown}}}
|
|
79
|
+
`;
|
|
80
|
+
loadedApi.map(async (item) => {
|
|
81
|
+
const markdown = item.type === "api" ? (0, markdown_1.createApiPageMD)(item) : (0, markdown_1.createInfoPageMD)(item);
|
|
82
|
+
item.markdown = markdown;
|
|
83
|
+
if (item.type === "api") {
|
|
84
|
+
item.json = JSON.stringify(item.api);
|
|
85
|
+
}
|
|
86
|
+
const view = (0, mustache_1.render)(mdTemplate, item);
|
|
87
|
+
if (item.type === "api") {
|
|
88
|
+
if (!fs_1.default.existsSync(`${outputDir}/${item.id}.api.mdx`)) {
|
|
89
|
+
try {
|
|
90
|
+
fs_1.default.writeFileSync(`${outputDir}/${item.id}.api.mdx`, view, "utf8");
|
|
91
|
+
console.log(chalk_1.default.green(`Successfully created "${outputDir}/${item.id}.api.mdx"`));
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
console.error(chalk_1.default.red(`Failed to write "${outputDir}/${item.id}.api.mdx"`), chalk_1.default.yellow(err));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// TODO: determine if we actually want/need this
|
|
99
|
+
if (item.type === "info") {
|
|
100
|
+
if (!fs_1.default.existsSync(`${outputDir}/index.api.mdx`)) {
|
|
101
|
+
try {
|
|
102
|
+
fs_1.default.writeFileSync(`${outputDir}/index.api.mdx`, view, "utf8");
|
|
103
|
+
console.log(chalk_1.default.green(`Successfully created "${outputDir}/index.api.mdx"`));
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
console.error(chalk_1.default.red(`Failed to write "${outputDir}/index.api.mdx"`), chalk_1.default.yellow(err));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return;
|
|
111
|
+
});
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
catch (e) {
|
|
115
|
+
console.error(chalk_1.default.red(`Loading of api failed for "${contentPath}"`));
|
|
116
|
+
throw e;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async function cleanApiDocs(options) {
|
|
120
|
+
const { outputDir } = options;
|
|
121
|
+
const apiDir = path_1.default.join(siteDir, outputDir);
|
|
122
|
+
const apiMdxFiles = await (0, utils_1.Globby)(["*.api.mdx"], {
|
|
123
|
+
cwd: path_1.default.resolve(apiDir),
|
|
124
|
+
});
|
|
125
|
+
const sidebarFile = await (0, utils_1.Globby)(["sidebar.js"], {
|
|
126
|
+
cwd: path_1.default.resolve(apiDir),
|
|
127
|
+
});
|
|
128
|
+
apiMdxFiles.map((mdx) => fs_1.default.unlink(`${apiDir}/${mdx}`, (err) => {
|
|
129
|
+
if (err) {
|
|
130
|
+
console.error(chalk_1.default.red(`Cleanup failed for "${apiDir}/${mdx}"`), chalk_1.default.yellow(err));
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
console.log(chalk_1.default.green(`Cleanup succeeded for "${apiDir}/${mdx}"`));
|
|
134
|
+
}
|
|
135
|
+
}));
|
|
136
|
+
sidebarFile.map((sidebar) => fs_1.default.unlink(`${apiDir}/${sidebar}`, (err) => {
|
|
137
|
+
if (err) {
|
|
138
|
+
console.error(chalk_1.default.red(`Cleanup failed for "${apiDir}/${sidebar}"`), chalk_1.default.yellow(err));
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
console.log(chalk_1.default.green(`Cleanup succeeded for "${apiDir}/${sidebar}"`));
|
|
142
|
+
}
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
name: `docusaurus-plugin-openapi`,
|
|
147
|
+
extendCli(cli) {
|
|
148
|
+
cli
|
|
149
|
+
.command(`gen-api-docs`)
|
|
150
|
+
.description(`Generates API Docs mdx and sidebars.`)
|
|
151
|
+
.usage("[options] <id key value in plugin config within docusaurus.config.js>")
|
|
152
|
+
.arguments("<id>")
|
|
153
|
+
.action(async (id) => {
|
|
154
|
+
if (id === "all") {
|
|
155
|
+
if (config[id]) {
|
|
156
|
+
console.error(chalk_1.default.red("Can't use id 'all' for API Doc."));
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
Object.keys(config).forEach(async function (key) {
|
|
160
|
+
await generateApiDocs(config[key]);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else if (!config[id]) {
|
|
165
|
+
console.error(chalk_1.default.red(`ID ${id} does not exist in openapi-plugin config`));
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
await generateApiDocs(config[id]);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
cli
|
|
172
|
+
.command(`clean-api-docs`)
|
|
173
|
+
.description(`Clears the Generated API Docs mdx and sidebars.`)
|
|
174
|
+
.usage("[options] <id key value in plugin config within docusaurus.config.js>")
|
|
175
|
+
.arguments("<id>")
|
|
176
|
+
.action(async (id) => {
|
|
177
|
+
if (id === "all") {
|
|
178
|
+
if (config[id]) {
|
|
179
|
+
console.error(chalk_1.default.red("Can't use id 'all' for API Doc."));
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
Object.keys(config).forEach(async function (key) {
|
|
183
|
+
await cleanApiDocs(config[key]);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
await cleanApiDocs(config[id]);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
exports.default = pluginOpenAPI;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
* ========================================================================== */
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createDeprecationNotice = void 0;
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
function createAdmonition({ children }) {
|
|
12
|
+
return `:::caution deprecated\n\n${(0, utils_1.render)(children)}\n\n:::`;
|
|
13
|
+
}
|
|
14
|
+
function createDeprecationNotice({ deprecated, description, }) {
|
|
15
|
+
return (0, utils_1.guard)(deprecated, () => createAdmonition({
|
|
16
|
+
children: description !== null && description !== void 0 ? description : "This endpoint has been deprecated and may be removed in future versions of the API.",
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
exports.createDeprecationNotice = createDeprecationNotice;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createDescription(description: string | undefined): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
* ========================================================================== */
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createDescription = void 0;
|
|
10
|
+
function createDescription(description) {
|
|
11
|
+
if (!description) {
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
14
|
+
return `\n\n${description}\n\n`;
|
|
15
|
+
}
|
|
16
|
+
exports.createDescription = createDescription;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
* ========================================================================== */
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createDetails = void 0;
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
function createDetails({ children, style, ...rest }) {
|
|
12
|
+
return (0, utils_1.create)("details", {
|
|
13
|
+
style: { ...style },
|
|
14
|
+
...rest,
|
|
15
|
+
children,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
exports.createDetails = createDetails;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
* ========================================================================== */
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createDetailsSummary = void 0;
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
function createDetailsSummary({ children, style, ...rest }) {
|
|
12
|
+
return (0, utils_1.create)("summary", {
|
|
13
|
+
style: { ...style },
|
|
14
|
+
...rest,
|
|
15
|
+
children,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
exports.createDetailsSummary = createDetailsSummary;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
* ========================================================================== */
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createFullWidthTable = void 0;
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
function createFullWidthTable({ children, style, ...rest }) {
|
|
12
|
+
return (0, utils_1.create)("table", {
|
|
13
|
+
style: { display: "table", width: "100%", ...style },
|
|
14
|
+
...rest,
|
|
15
|
+
children,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
exports.createFullWidthTable = createFullWidthTable;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
* ========================================================================== */
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createParamsDetails = void 0;
|
|
10
|
+
const createDetails_1 = require("./createDetails");
|
|
11
|
+
const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
12
|
+
const utils_1 = require("./utils");
|
|
13
|
+
function createParamsDetails({ parameters, type }) {
|
|
14
|
+
if (parameters === undefined) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
const params = parameters.filter((param) => (param === null || param === void 0 ? void 0 : param.in) === type);
|
|
18
|
+
if (params.length === 0) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return (0, createDetails_1.createDetails)({
|
|
22
|
+
style: { marginBottom: "1rem" },
|
|
23
|
+
children: [
|
|
24
|
+
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
25
|
+
children: [
|
|
26
|
+
(0, utils_1.create)("strong", {
|
|
27
|
+
children: `${type.charAt(0).toUpperCase() + type.slice(1)} Parameters`,
|
|
28
|
+
}),
|
|
29
|
+
],
|
|
30
|
+
}),
|
|
31
|
+
(0, utils_1.create)("div", {
|
|
32
|
+
children: [
|
|
33
|
+
(0, utils_1.create)("ul", {
|
|
34
|
+
children: params.map((param) => (0, utils_1.create)("ParamsItem", {
|
|
35
|
+
className: "paramsItem",
|
|
36
|
+
param: param,
|
|
37
|
+
})),
|
|
38
|
+
}),
|
|
39
|
+
],
|
|
40
|
+
}),
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
exports.createParamsDetails = createParamsDetails;
|