docusaurus-plugin-openapi-docs 0.0.0-348 → 0.0.0-351

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.
Files changed (58) hide show
  1. package/lib/index.d.ts +3 -0
  2. package/lib/index.js +194 -0
  3. package/lib/markdown/createContactInfo.d.ts +2 -0
  4. package/lib/markdown/createContactInfo.js +49 -0
  5. package/lib/markdown/createDeprecationNotice.d.ts +6 -0
  6. package/lib/markdown/createDeprecationNotice.js +19 -0
  7. package/lib/markdown/createDescription.d.ts +1 -0
  8. package/lib/markdown/createDescription.js +16 -0
  9. package/lib/markdown/createDetails.d.ts +2 -0
  10. package/lib/markdown/createDetails.js +18 -0
  11. package/lib/markdown/createDetailsSummary.d.ts +2 -0
  12. package/lib/markdown/createDetailsSummary.js +18 -0
  13. package/lib/markdown/createLicense.d.ts +2 -0
  14. package/lib/markdown/createLicense.js +33 -0
  15. package/lib/markdown/createParamsDetails.d.ts +7 -0
  16. package/lib/markdown/createParamsDetails.js +44 -0
  17. package/lib/markdown/createRequestBodyDetails.d.ts +6 -0
  18. package/lib/markdown/createRequestBodyDetails.js +14 -0
  19. package/lib/markdown/createSchemaDetails.d.ts +14 -0
  20. package/lib/markdown/createSchemaDetails.js +244 -0
  21. package/lib/markdown/createStatusCodes.d.ts +6 -0
  22. package/lib/markdown/createStatusCodes.js +47 -0
  23. package/lib/markdown/createTermsOfService.d.ts +1 -0
  24. package/lib/markdown/createTermsOfService.js +32 -0
  25. package/lib/markdown/createVersionBadge.d.ts +1 -0
  26. package/lib/markdown/createVersionBadge.js +20 -0
  27. package/lib/markdown/index.d.ts +3 -0
  28. package/lib/markdown/index.js +49 -0
  29. package/lib/markdown/schema.d.ts +3 -0
  30. package/lib/markdown/schema.js +100 -0
  31. package/lib/markdown/schema.test.d.ts +1 -0
  32. package/lib/markdown/schema.test.js +171 -0
  33. package/lib/markdown/utils.d.ts +7 -0
  34. package/lib/markdown/utils.js +33 -0
  35. package/lib/openapi/createExample.d.ts +2 -0
  36. package/lib/openapi/createExample.js +113 -0
  37. package/lib/openapi/index.d.ts +1 -0
  38. package/lib/openapi/index.js +12 -0
  39. package/lib/openapi/openapi.d.ts +11 -0
  40. package/lib/openapi/openapi.js +231 -0
  41. package/lib/openapi/openapi.test.d.ts +1 -0
  42. package/lib/openapi/openapi.test.js +33 -0
  43. package/lib/openapi/types.d.ts +334 -0
  44. package/{src/markdown/createRequestBodyTable.ts → lib/openapi/types.js} +2 -11
  45. package/lib/options.d.ts +4 -0
  46. package/lib/options.js +18 -0
  47. package/lib/sidebars/index.d.ts +3 -0
  48. package/lib/sidebars/index.js +89 -0
  49. package/lib/types.d.ts +68 -0
  50. package/{src/markdown/createFullWidthTable.ts → lib/types.js} +2 -10
  51. package/package.json +2 -2
  52. package/src/markdown/createContactInfo.ts +48 -0
  53. package/src/markdown/createLicense.ts +32 -0
  54. package/src/markdown/createTermsOfService.ts +30 -0
  55. package/src/markdown/index.ts +8 -1
  56. package/src/openapi/types.ts +2 -0
  57. package/src/markdown/createParamsTable.ts +0 -102
  58. package/src/markdown/createSchemaTable.ts +0 -275
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { LoadContext, Plugin } from "@docusaurus/types";
2
+ import type { PluginOptions, LoadedContent } from "./types";
3
+ export default function pluginOpenAPI(context: LoadContext, options: PluginOptions): Plugin<LoadedContent>;
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,2 @@
1
+ import { ContactObject } from "../openapi/types";
2
+ export declare function createContactInfo(contact: ContactObject): string;
@@ -0,0 +1,49 @@
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.createContactInfo = void 0;
10
+ const utils_1 = require("./utils");
11
+ function createContactInfo(contact) {
12
+ if (!contact)
13
+ return "";
14
+ const { name, url, email } = contact;
15
+ return (0, utils_1.create)("div", {
16
+ style: {
17
+ display: "flex",
18
+ flexDirection: "column",
19
+ marginBottom: "var(--ifm-paragraph-margin-bottom)",
20
+ },
21
+ children: [
22
+ (0, utils_1.create)("h3", {
23
+ style: {
24
+ marginBottom: "0.25rem",
25
+ },
26
+ children: "Contact",
27
+ }),
28
+ (0, utils_1.create)("span", {
29
+ children: [
30
+ `${name}: `,
31
+ (0, utils_1.create)("a", {
32
+ href: `mailto:${email}`,
33
+ children: `${email}`,
34
+ }),
35
+ ],
36
+ }),
37
+ (0, utils_1.create)("span", {
38
+ children: [
39
+ "URL: ",
40
+ (0, utils_1.create)("a", {
41
+ href: `${url}`,
42
+ children: `${url}`,
43
+ }),
44
+ ],
45
+ }),
46
+ ],
47
+ });
48
+ }
49
+ exports.createContactInfo = createContactInfo;
@@ -0,0 +1,6 @@
1
+ interface DeprecationNoticeProps {
2
+ deprecated?: boolean;
3
+ description?: string;
4
+ }
5
+ export declare function createDeprecationNotice({ deprecated, description, }: DeprecationNoticeProps): string;
6
+ export {};
@@ -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,2 @@
1
+ import { Props } from "./utils";
2
+ export declare function createDetails({ children, style, ...rest }: Props): string;
@@ -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,2 @@
1
+ import { Props } from "./utils";
2
+ export declare function createDetailsSummary({ children, style, ...rest }: Props): string;
@@ -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,2 @@
1
+ import { LicenseObject } from "../openapi/types";
2
+ export declare function createLicense(license: LicenseObject): string;
@@ -0,0 +1,33 @@
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.createLicense = void 0;
10
+ const utils_1 = require("./utils");
11
+ function createLicense(license) {
12
+ if (!license)
13
+ return "";
14
+ const { name, url } = license;
15
+ return (0, utils_1.create)("div", {
16
+ style: {
17
+ marginBottom: "var(--ifm-paragraph-margin-bottom)",
18
+ },
19
+ children: [
20
+ (0, utils_1.create)("h3", {
21
+ style: {
22
+ marginBottom: "0.25rem",
23
+ },
24
+ children: "License",
25
+ }),
26
+ (0, utils_1.create)("a", {
27
+ href: url,
28
+ children: name,
29
+ }),
30
+ ],
31
+ });
32
+ }
33
+ exports.createLicense = createLicense;
@@ -0,0 +1,7 @@
1
+ import { ApiItem } from "../types";
2
+ interface Props {
3
+ parameters: ApiItem["parameters"];
4
+ type: "path" | "query" | "header" | "cookie";
5
+ }
6
+ export declare function createParamsDetails({ parameters, type }: Props): string | undefined;
7
+ export {};
@@ -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;
@@ -0,0 +1,6 @@
1
+ interface Props {
2
+ title: string;
3
+ body: any;
4
+ }
5
+ export declare function createRequestBodyDetails({ title, body }: Props): string | undefined;
6
+ export {};
@@ -0,0 +1,14 @@
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.createRequestBodyDetails = void 0;
10
+ const createSchemaDetails_1 = require("./createSchemaDetails");
11
+ function createRequestBodyDetails({ title, body }) {
12
+ return (0, createSchemaDetails_1.createSchemaDetails)({ title, body });
13
+ }
14
+ exports.createRequestBodyDetails = createRequestBodyDetails;
@@ -0,0 +1,14 @@
1
+ import { MediaTypeObject } from "../openapi/types";
2
+ interface Props {
3
+ style?: any;
4
+ title: string;
5
+ body: {
6
+ content?: {
7
+ [key: string]: MediaTypeObject;
8
+ };
9
+ description?: string;
10
+ required?: boolean;
11
+ };
12
+ }
13
+ export declare function createSchemaDetails({ title, body, ...rest }: Props): string | undefined;
14
+ export {};