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
|
@@ -0,0 +1,89 @@
|
|
|
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 clsx_1 = __importDefault(require("clsx"));
|
|
13
|
+
const uniq_1 = __importDefault(require("lodash/uniq"));
|
|
14
|
+
function isApiItem(item) {
|
|
15
|
+
return item.type === "api";
|
|
16
|
+
}
|
|
17
|
+
function groupByTags(items, sidebarOptions, options) {
|
|
18
|
+
// TODO: Figure out how to handle these
|
|
19
|
+
// const intros = items.filter(isInfoItem).map((item) => {
|
|
20
|
+
// return {
|
|
21
|
+
// type: "link" as const,
|
|
22
|
+
// label: item.title,
|
|
23
|
+
// href: item.permalink,
|
|
24
|
+
// docId: item.id,
|
|
25
|
+
// };
|
|
26
|
+
// });
|
|
27
|
+
const { outputDir } = options;
|
|
28
|
+
const { sidebarCollapsed, sidebarCollapsible, customProps } = sidebarOptions;
|
|
29
|
+
const apiItems = items.filter(isApiItem);
|
|
30
|
+
// TODO: make sure we only take the first tag
|
|
31
|
+
const tags = (0, uniq_1.default)(apiItems
|
|
32
|
+
.flatMap((item) => item.api.tags)
|
|
33
|
+
.filter((item) => !!item));
|
|
34
|
+
// TODO: optimize this or make it a function
|
|
35
|
+
const basePath = outputDir
|
|
36
|
+
.slice(outputDir.indexOf("/", 1))
|
|
37
|
+
.replace(/^\/+/g, "");
|
|
38
|
+
function createDocItem(item) {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
const sidebar_label = item.frontMatter.sidebar_label;
|
|
41
|
+
const title = item.title;
|
|
42
|
+
const id = item.id;
|
|
43
|
+
return {
|
|
44
|
+
type: "doc",
|
|
45
|
+
id: `${basePath}/${item.id}`,
|
|
46
|
+
label: (_b = (_a = sidebar_label) !== null && _a !== void 0 ? _a : title) !== null && _b !== void 0 ? _b : id,
|
|
47
|
+
customProps: customProps,
|
|
48
|
+
className: (0, clsx_1.default)({
|
|
49
|
+
"menu__list-item--deprecated": item.api.deprecated,
|
|
50
|
+
"api-method": !!item.api.method,
|
|
51
|
+
}, item.api.method),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const tagged = tags
|
|
55
|
+
.map((tag) => {
|
|
56
|
+
return {
|
|
57
|
+
type: "category",
|
|
58
|
+
label: tag,
|
|
59
|
+
collapsible: sidebarCollapsible,
|
|
60
|
+
collapsed: sidebarCollapsed,
|
|
61
|
+
items: apiItems
|
|
62
|
+
.filter((item) => { var _a; return !!((_a = item.api.tags) === null || _a === void 0 ? void 0 : _a.includes(tag)); })
|
|
63
|
+
.map(createDocItem),
|
|
64
|
+
};
|
|
65
|
+
})
|
|
66
|
+
.filter((item) => item.items.length > 0); // Filter out any categories with no items.
|
|
67
|
+
// const untagged = [
|
|
68
|
+
// // TODO: determine if needed and how
|
|
69
|
+
// {
|
|
70
|
+
// type: "category" as const,
|
|
71
|
+
// label: "UNTAGGED",
|
|
72
|
+
// // collapsible: options.sidebarCollapsible, TODO: add option
|
|
73
|
+
// // collapsed: options.sidebarCollapsed, TODO: add option
|
|
74
|
+
// items: apiItems
|
|
75
|
+
// //@ts-ignore
|
|
76
|
+
// .filter(({ api }) => api.tags === undefined || api.tags.length === 0)
|
|
77
|
+
// .map(createDocItem),
|
|
78
|
+
// },
|
|
79
|
+
// ];
|
|
80
|
+
return [...tagged];
|
|
81
|
+
}
|
|
82
|
+
function generateSidebarSlice(sidebarOptions, options, api) {
|
|
83
|
+
let sidebarSlice = [];
|
|
84
|
+
if (sidebarOptions.groupPathsBy === "tags") {
|
|
85
|
+
sidebarSlice = groupByTags(api, sidebarOptions, options);
|
|
86
|
+
}
|
|
87
|
+
return sidebarSlice;
|
|
88
|
+
}
|
|
89
|
+
exports.default = generateSidebarSlice;
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Request } from "@paloaltonetworks/postman-collection";
|
|
2
|
+
import { InfoObject, OperationObject, SecuritySchemeObject } from "./openapi/types";
|
|
3
|
+
export type { PropSidebarItemCategory, SidebarItemLink, PropSidebar, PropSidebarItem, } from "@docusaurus/plugin-content-docs-types";
|
|
4
|
+
export interface PluginOptions {
|
|
5
|
+
id?: string;
|
|
6
|
+
config: {
|
|
7
|
+
[key: string]: APIOptions;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export interface APIOptions {
|
|
11
|
+
specPath: string;
|
|
12
|
+
outputDir: string;
|
|
13
|
+
template?: string;
|
|
14
|
+
sidebarOptions?: SidebarOptions;
|
|
15
|
+
}
|
|
16
|
+
export interface LoadedContent {
|
|
17
|
+
loadedApi: ApiMetadata[];
|
|
18
|
+
}
|
|
19
|
+
export declare type ApiMetadata = ApiPageMetadata | InfoPageMetadata;
|
|
20
|
+
export interface ApiMetadataBase {
|
|
21
|
+
sidebar?: string;
|
|
22
|
+
previous?: ApiNavLink;
|
|
23
|
+
next?: ApiNavLink;
|
|
24
|
+
id: string;
|
|
25
|
+
unversionedId: string;
|
|
26
|
+
title: string;
|
|
27
|
+
description: string;
|
|
28
|
+
source: string;
|
|
29
|
+
sourceDirName: string;
|
|
30
|
+
slug: string;
|
|
31
|
+
permalink: string;
|
|
32
|
+
sidebarPosition?: number;
|
|
33
|
+
frontMatter: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
export interface ApiPageMetadata extends ApiMetadataBase {
|
|
36
|
+
json?: string;
|
|
37
|
+
type: "api";
|
|
38
|
+
api: ApiItem;
|
|
39
|
+
markdown?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface ApiItem extends OperationObject {
|
|
42
|
+
method: string;
|
|
43
|
+
path: string;
|
|
44
|
+
jsonRequestBodyExample: string;
|
|
45
|
+
securitySchemes?: {
|
|
46
|
+
[key: string]: SecuritySchemeObject;
|
|
47
|
+
};
|
|
48
|
+
postman?: Request;
|
|
49
|
+
info: InfoObject;
|
|
50
|
+
}
|
|
51
|
+
export interface InfoPageMetadata extends ApiMetadataBase {
|
|
52
|
+
type: "info";
|
|
53
|
+
info: ApiInfo;
|
|
54
|
+
markdown?: string;
|
|
55
|
+
}
|
|
56
|
+
export declare type ApiInfo = InfoObject;
|
|
57
|
+
export interface ApiNavLink {
|
|
58
|
+
title: string;
|
|
59
|
+
permalink: string;
|
|
60
|
+
}
|
|
61
|
+
export interface SidebarOptions {
|
|
62
|
+
groupPathsBy?: string;
|
|
63
|
+
customProps?: {
|
|
64
|
+
[key: string]: unknown;
|
|
65
|
+
};
|
|
66
|
+
sidebarCollapsible?: boolean;
|
|
67
|
+
sidebarCollapsed?: boolean;
|
|
68
|
+
}
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
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 });
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "docusaurus-plugin-openapi-docs",
|
|
3
|
+
"description": "OpenAPI plugin for Docusaurus.",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/PaloAltoNetworks/docusaurus-openapi.git",
|
|
12
|
+
"directory": "packages/docusaurus-plugin-openapi-docs"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/PaloAltoNetworks/docusaurus-openapi/issues"
|
|
16
|
+
},
|
|
17
|
+
"main": "lib/index.js",
|
|
18
|
+
"types": "src/plugin-openapi.d.ts",
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"watch": "tsc --watch"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@docusaurus/module-type-aliases": "^2.0.0-beta.18",
|
|
25
|
+
"@docusaurus/types": "^2.0.0-beta.18",
|
|
26
|
+
"@types/fs-extra": "^9.0.13",
|
|
27
|
+
"@types/json-schema": "^7.0.9",
|
|
28
|
+
"@types/lodash": "^4.14.176",
|
|
29
|
+
"@types/postman-collection": "^3.5.7",
|
|
30
|
+
"utility-types": "^3.10.0"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@docusaurus/mdx-loader": "^2.0.0-beta.18",
|
|
34
|
+
"@docusaurus/plugin-content-docs": "^2.0.0-beta.18",
|
|
35
|
+
"@docusaurus/utils": "^2.0.0-beta.18",
|
|
36
|
+
"@docusaurus/utils-validation": "^2.0.0-beta.18",
|
|
37
|
+
"@paloaltonetworks/openapi-to-postmanv2": "3.1.0-hotfix.1",
|
|
38
|
+
"@paloaltonetworks/postman-collection": "^4.1.0",
|
|
39
|
+
"@types/js-yaml": "^4.0.5",
|
|
40
|
+
"@types/mustache": "^4.1.2",
|
|
41
|
+
"chalk": "^4.1.2",
|
|
42
|
+
"clsx": "^1.1.1",
|
|
43
|
+
"fs-extra": "^9.0.1",
|
|
44
|
+
"js-yaml": "^4.1.0",
|
|
45
|
+
"json-refs": "^3.0.15",
|
|
46
|
+
"json-schema-merge-allof": "^0.8.1",
|
|
47
|
+
"lodash": "^4.17.20",
|
|
48
|
+
"mustache": "^4.2.0",
|
|
49
|
+
"webpack": "^5.61.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"react": "^16.8.4 || ^17.0.0"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=14"
|
|
56
|
+
},
|
|
57
|
+
"gitHead": "8905a438e86fc0a5cb9f033fb1b29630ff059af8"
|
|
58
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import fs from "fs";
|
|
9
|
+
import path from "path";
|
|
10
|
+
|
|
11
|
+
import type { LoadContext, Plugin } from "@docusaurus/types";
|
|
12
|
+
import { Globby } from "@docusaurus/utils";
|
|
13
|
+
import chalk from "chalk";
|
|
14
|
+
import { render } from "mustache";
|
|
15
|
+
|
|
16
|
+
import { createApiPageMD, createInfoPageMD } from "./markdown";
|
|
17
|
+
import { readOpenapiFiles, processOpenapiFiles } from "./openapi";
|
|
18
|
+
import generateSidebarSlice from "./sidebars";
|
|
19
|
+
import type { PluginOptions, LoadedContent, APIOptions } from "./types";
|
|
20
|
+
|
|
21
|
+
export default function pluginOpenAPI(
|
|
22
|
+
context: LoadContext,
|
|
23
|
+
options: PluginOptions
|
|
24
|
+
): Plugin<LoadedContent> {
|
|
25
|
+
let { config } = options;
|
|
26
|
+
let { siteDir } = context;
|
|
27
|
+
|
|
28
|
+
async function generateApiDocs(options: APIOptions) {
|
|
29
|
+
let { specPath, outputDir, template, sidebarOptions } = options;
|
|
30
|
+
|
|
31
|
+
const contentPath = path.resolve(siteDir, specPath);
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
const openapiFiles = await readOpenapiFiles(contentPath, {});
|
|
35
|
+
const loadedApi = await processOpenapiFiles(openapiFiles);
|
|
36
|
+
|
|
37
|
+
if (!fs.existsSync(outputDir)) {
|
|
38
|
+
try {
|
|
39
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
40
|
+
console.log(chalk.green(`Successfully created "${outputDir}"`));
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.error(
|
|
43
|
+
chalk.red(`Failed to create "${outputDir}"`),
|
|
44
|
+
chalk.yellow(err)
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// TODO: figure out better way to set default
|
|
50
|
+
if (Object.keys(sidebarOptions ?? {}).length > 0) {
|
|
51
|
+
const sidebarSlice = generateSidebarSlice(
|
|
52
|
+
sidebarOptions!, // TODO: find a better way to handle null
|
|
53
|
+
options,
|
|
54
|
+
loadedApi
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const sidebarSliceTemplate = template
|
|
58
|
+
? fs.readFileSync(template).toString()
|
|
59
|
+
: `module.exports = {{{slice}}};`;
|
|
60
|
+
|
|
61
|
+
const view = render(sidebarSliceTemplate, {
|
|
62
|
+
slice: JSON.stringify(sidebarSlice),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
if (!fs.existsSync(`${outputDir}/sidebar.js`)) {
|
|
66
|
+
try {
|
|
67
|
+
fs.writeFileSync(`${outputDir}/sidebar.js`, view, "utf8");
|
|
68
|
+
console.log(
|
|
69
|
+
chalk.green(`Successfully created "${outputDir}/sidebar.js"`)
|
|
70
|
+
);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
console.error(
|
|
73
|
+
chalk.red(`Failed to write "${outputDir}/sidebar.js"`),
|
|
74
|
+
chalk.yellow(err)
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const mdTemplate = template
|
|
81
|
+
? fs.readFileSync(template).toString()
|
|
82
|
+
: `---
|
|
83
|
+
id: {{{id}}}
|
|
84
|
+
sidebar_label: {{{title}}}
|
|
85
|
+
{{^api}}
|
|
86
|
+
sidebar_position: 0
|
|
87
|
+
{{/api}}
|
|
88
|
+
hide_title: true
|
|
89
|
+
{{#api}}
|
|
90
|
+
hide_table_of_contents: true
|
|
91
|
+
{{/api}}
|
|
92
|
+
{{#json}}
|
|
93
|
+
api: {{{json}}}
|
|
94
|
+
{{/json}}
|
|
95
|
+
{{#api.method}}
|
|
96
|
+
sidebar_class_name: "{{{api.method}}} api-method"
|
|
97
|
+
{{/api.method}}
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
{{{markdown}}}
|
|
101
|
+
`;
|
|
102
|
+
|
|
103
|
+
loadedApi.map(async (item) => {
|
|
104
|
+
const markdown =
|
|
105
|
+
item.type === "api" ? createApiPageMD(item) : createInfoPageMD(item);
|
|
106
|
+
item.markdown = markdown;
|
|
107
|
+
if (item.type === "api") {
|
|
108
|
+
item.json = JSON.stringify(item.api);
|
|
109
|
+
}
|
|
110
|
+
const view = render(mdTemplate, item);
|
|
111
|
+
|
|
112
|
+
if (item.type === "api") {
|
|
113
|
+
if (!fs.existsSync(`${outputDir}/${item.id}.api.mdx`)) {
|
|
114
|
+
try {
|
|
115
|
+
fs.writeFileSync(`${outputDir}/${item.id}.api.mdx`, view, "utf8");
|
|
116
|
+
console.log(
|
|
117
|
+
chalk.green(
|
|
118
|
+
`Successfully created "${outputDir}/${item.id}.api.mdx"`
|
|
119
|
+
)
|
|
120
|
+
);
|
|
121
|
+
} catch (err) {
|
|
122
|
+
console.error(
|
|
123
|
+
chalk.red(`Failed to write "${outputDir}/${item.id}.api.mdx"`),
|
|
124
|
+
chalk.yellow(err)
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// TODO: determine if we actually want/need this
|
|
131
|
+
if (item.type === "info") {
|
|
132
|
+
if (!fs.existsSync(`${outputDir}/index.api.mdx`)) {
|
|
133
|
+
try {
|
|
134
|
+
fs.writeFileSync(`${outputDir}/index.api.mdx`, view, "utf8");
|
|
135
|
+
console.log(
|
|
136
|
+
chalk.green(`Successfully created "${outputDir}/index.api.mdx"`)
|
|
137
|
+
);
|
|
138
|
+
} catch (err) {
|
|
139
|
+
console.error(
|
|
140
|
+
chalk.red(`Failed to write "${outputDir}/index.api.mdx"`),
|
|
141
|
+
chalk.yellow(err)
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return;
|
|
147
|
+
});
|
|
148
|
+
return;
|
|
149
|
+
} catch (e) {
|
|
150
|
+
console.error(chalk.red(`Loading of api failed for "${contentPath}"`));
|
|
151
|
+
throw e;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async function cleanApiDocs(options: APIOptions) {
|
|
156
|
+
const { outputDir } = options;
|
|
157
|
+
const apiDir = path.join(siteDir, outputDir);
|
|
158
|
+
const apiMdxFiles = await Globby(["*.api.mdx"], {
|
|
159
|
+
cwd: path.resolve(apiDir),
|
|
160
|
+
});
|
|
161
|
+
const sidebarFile = await Globby(["sidebar.js"], {
|
|
162
|
+
cwd: path.resolve(apiDir),
|
|
163
|
+
});
|
|
164
|
+
apiMdxFiles.map((mdx) =>
|
|
165
|
+
fs.unlink(`${apiDir}/${mdx}`, (err) => {
|
|
166
|
+
if (err) {
|
|
167
|
+
console.error(
|
|
168
|
+
chalk.red(`Cleanup failed for "${apiDir}/${mdx}"`),
|
|
169
|
+
chalk.yellow(err)
|
|
170
|
+
);
|
|
171
|
+
} else {
|
|
172
|
+
console.log(chalk.green(`Cleanup succeeded for "${apiDir}/${mdx}"`));
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
sidebarFile.map((sidebar) =>
|
|
178
|
+
fs.unlink(`${apiDir}/${sidebar}`, (err) => {
|
|
179
|
+
if (err) {
|
|
180
|
+
console.error(
|
|
181
|
+
chalk.red(`Cleanup failed for "${apiDir}/${sidebar}"`),
|
|
182
|
+
chalk.yellow(err)
|
|
183
|
+
);
|
|
184
|
+
} else {
|
|
185
|
+
console.log(
|
|
186
|
+
chalk.green(`Cleanup succeeded for "${apiDir}/${sidebar}"`)
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return {
|
|
194
|
+
name: `docusaurus-plugin-openapi`,
|
|
195
|
+
|
|
196
|
+
extendCli(cli): void {
|
|
197
|
+
cli
|
|
198
|
+
.command(`gen-api-docs`)
|
|
199
|
+
.description(`Generates API Docs mdx and sidebars.`)
|
|
200
|
+
.usage(
|
|
201
|
+
"[options] <id key value in plugin config within docusaurus.config.js>"
|
|
202
|
+
)
|
|
203
|
+
.arguments("<id>")
|
|
204
|
+
.action(async (id) => {
|
|
205
|
+
if (id === "all") {
|
|
206
|
+
if (config[id]) {
|
|
207
|
+
console.error(chalk.red("Can't use id 'all' for API Doc."));
|
|
208
|
+
} else {
|
|
209
|
+
Object.keys(config).forEach(async function (key) {
|
|
210
|
+
await generateApiDocs(config[key]);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
} else if (!config[id]) {
|
|
214
|
+
console.error(
|
|
215
|
+
chalk.red(`ID ${id} does not exist in openapi-plugin config`)
|
|
216
|
+
);
|
|
217
|
+
} else {
|
|
218
|
+
await generateApiDocs(config[id]);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
cli
|
|
223
|
+
.command(`clean-api-docs`)
|
|
224
|
+
.description(`Clears the Generated API Docs mdx and sidebars.`)
|
|
225
|
+
.usage(
|
|
226
|
+
"[options] <id key value in plugin config within docusaurus.config.js>"
|
|
227
|
+
)
|
|
228
|
+
.arguments("<id>")
|
|
229
|
+
.action(async (id) => {
|
|
230
|
+
if (id === "all") {
|
|
231
|
+
if (config[id]) {
|
|
232
|
+
console.error(chalk.red("Can't use id 'all' for API Doc."));
|
|
233
|
+
} else {
|
|
234
|
+
Object.keys(config).forEach(async function (key) {
|
|
235
|
+
await cleanApiDocs(config[key]);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
} else {
|
|
239
|
+
await cleanApiDocs(config[id]);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import { guard, Props, render } from "./utils";
|
|
9
|
+
|
|
10
|
+
function createAdmonition({ children }: Props) {
|
|
11
|
+
return `:::caution deprecated\n\n${render(children)}\n\n:::`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface DeprecationNoticeProps {
|
|
15
|
+
deprecated?: boolean;
|
|
16
|
+
description?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function createDeprecationNotice({
|
|
20
|
+
deprecated,
|
|
21
|
+
description,
|
|
22
|
+
}: DeprecationNoticeProps) {
|
|
23
|
+
return guard(deprecated, () =>
|
|
24
|
+
createAdmonition({
|
|
25
|
+
children:
|
|
26
|
+
description ??
|
|
27
|
+
"This endpoint has been deprecated and may be removed in future versions of the API.",
|
|
28
|
+
})
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
export function createDescription(description: string | undefined) {
|
|
9
|
+
if (!description) {
|
|
10
|
+
return "";
|
|
11
|
+
}
|
|
12
|
+
return `\n\n${description}\n\n`;
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import { create, Props } from "./utils";
|
|
9
|
+
|
|
10
|
+
export function createDetails({ children, style, ...rest }: Props) {
|
|
11
|
+
return create("details", {
|
|
12
|
+
style: { ...style },
|
|
13
|
+
...rest,
|
|
14
|
+
children,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import { create, Props } from "./utils";
|
|
9
|
+
|
|
10
|
+
export function createDetailsSummary({ children, style, ...rest }: Props) {
|
|
11
|
+
return create("summary", {
|
|
12
|
+
style: { ...style },
|
|
13
|
+
...rest,
|
|
14
|
+
children,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import { create, Props } from "./utils";
|
|
9
|
+
|
|
10
|
+
export function createFullWidthTable({ children, style, ...rest }: Props) {
|
|
11
|
+
return create("table", {
|
|
12
|
+
style: { display: "table", width: "100%", ...style },
|
|
13
|
+
...rest,
|
|
14
|
+
children,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import { ApiItem } from "../types";
|
|
9
|
+
import { createDetails } from "./createDetails";
|
|
10
|
+
import { createDetailsSummary } from "./createDetailsSummary";
|
|
11
|
+
import { create } from "./utils";
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
parameters: ApiItem["parameters"];
|
|
15
|
+
type: "path" | "query" | "header" | "cookie";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function createParamsDetails({ parameters, type }: Props) {
|
|
19
|
+
if (parameters === undefined) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const params = parameters.filter((param) => param?.in === type);
|
|
23
|
+
if (params.length === 0) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return createDetails({
|
|
28
|
+
style: { marginBottom: "1rem" },
|
|
29
|
+
children: [
|
|
30
|
+
createDetailsSummary({
|
|
31
|
+
children: [
|
|
32
|
+
create("strong", {
|
|
33
|
+
children: `${
|
|
34
|
+
type.charAt(0).toUpperCase() + type.slice(1)
|
|
35
|
+
} Parameters`,
|
|
36
|
+
}),
|
|
37
|
+
],
|
|
38
|
+
}),
|
|
39
|
+
create("div", {
|
|
40
|
+
children: [
|
|
41
|
+
create("ul", {
|
|
42
|
+
children: params.map((param) =>
|
|
43
|
+
create("ParamsItem", {
|
|
44
|
+
className: "paramsItem",
|
|
45
|
+
param: param,
|
|
46
|
+
})
|
|
47
|
+
),
|
|
48
|
+
}),
|
|
49
|
+
],
|
|
50
|
+
}),
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
}
|