docusaurus-plugin-openapi-docs 0.0.0-beta.691 → 0.0.0-beta.720
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 +2 -0
- package/lib/index.js +75 -19
- package/lib/markdown/createAuthentication.js +4 -3
- package/lib/markdown/createCallbacks.d.ts +6 -0
- package/lib/markdown/createCallbacks.js +78 -0
- package/lib/markdown/createDeprecationNotice.js +6 -3
- package/lib/markdown/createDescription.js +1 -9
- package/lib/markdown/createHeading.js +4 -5
- package/lib/markdown/createRequestBodyDetails.d.ts +1 -1
- package/lib/markdown/createRequestHeader.d.ts +1 -1
- package/lib/markdown/createRequestHeader.js +10 -1
- package/lib/markdown/createSchema.d.ts +1 -1
- package/lib/markdown/createSchema.js +23 -9
- package/lib/markdown/createSchema.test.js +2 -2
- package/lib/markdown/createStatusCodes.d.ts +3 -1
- package/lib/markdown/createStatusCodes.js +8 -6
- package/lib/markdown/createVersionBadge.js +1 -1
- package/lib/markdown/index.d.ts +3 -2
- package/lib/markdown/index.js +31 -6
- package/lib/markdown/schema.js +3 -0
- package/lib/markdown/utils.d.ts +9 -3
- package/lib/markdown/utils.js +29 -4
- package/lib/openapi/openapi.d.ts +3 -3
- package/lib/openapi/openapi.js +60 -7
- package/lib/openapi/openapi.test.js +2 -0
- package/lib/openapi/types.d.ts +18 -13
- package/lib/openapi/utils/services/OpenAPIParser.d.ts +1 -1
- package/lib/openapi/utils/services/OpenAPIParser.js +2 -1
- package/lib/openapi/utils/services/RedocNormalizedOptions.js +49 -49
- package/lib/openapi/utils/types/index.d.ts +1 -1
- package/lib/openapi/utils/types/open-api.d.ts +4 -4
- package/lib/openapi/utils/types.d.ts +5 -5
- package/lib/openapi/utils/utils/openapi.js +1 -1
- package/lib/options.js +2 -1
- package/lib/sidebars/index.d.ts +2 -2
- package/lib/sidebars/index.js +49 -9
- package/lib/types.d.ts +16 -3
- package/package.json +11 -9
- package/src/index.ts +134 -21
- package/src/markdown/__snapshots__/createSchema.test.ts.snap +4 -28
- package/src/markdown/createAuthentication.ts +11 -6
- package/src/markdown/createCallbacks.ts +101 -0
- package/src/markdown/createContactInfo.ts +1 -1
- package/src/markdown/createDeprecationNotice.ts +2 -2
- package/src/markdown/createDescription.ts +2 -10
- package/src/markdown/createHeading.ts +10 -7
- package/src/markdown/createLicense.ts +1 -1
- package/src/markdown/createLogo.ts +1 -1
- package/src/markdown/createParamsDetails.ts +1 -1
- package/src/markdown/createRequestBodyDetails.ts +2 -2
- package/src/markdown/createRequestHeader.ts +15 -1
- package/src/markdown/createRequestSchema.ts +1 -1
- package/src/markdown/createResponseSchema.ts +1 -1
- package/src/markdown/createSchema.test.ts +6 -4
- package/src/markdown/createSchema.ts +32 -19
- package/src/markdown/createStatusCodes.ts +11 -7
- package/src/markdown/createVersionBadge.ts +8 -4
- package/src/markdown/index.ts +45 -14
- package/src/markdown/schema.ts +4 -0
- package/src/markdown/utils.ts +37 -4
- package/src/openapi/__fixtures__/examples/openapi.yaml +29 -0
- package/src/openapi/createRequestExample.ts +1 -1
- package/src/openapi/createResponseExample.ts +1 -1
- package/src/openapi/openapi.test.ts +3 -0
- package/src/openapi/openapi.ts +77 -9
- package/src/openapi/types.ts +6 -0
- package/src/openapi/utils/loadAndResolveSpec.ts +1 -1
- package/src/openapi/utils/services/OpenAPIParser.ts +3 -3
- package/src/openapi/utils/utils/openapi.ts +8 -8
- package/src/options.ts +2 -1
- package/src/sidebars/index.ts +70 -15
- package/src/types.ts +21 -1
package/README.md
CHANGED
|
@@ -31,6 +31,7 @@ Key Features:
|
|
|
31
31
|
|
|
32
32
|
| Docusaurus OpenAPI Docs | Docusaurus |
|
|
33
33
|
| ----------------------- | --------------- |
|
|
34
|
+
| 3.0.0-beta.x (beta) | `3.0.1 - 3.1.1` |
|
|
34
35
|
| 2.0.x (current) | `2.4.1 - 2.4.3` |
|
|
35
36
|
| 1.7.3 (legacy) | `2.0.1 - 2.2.0` |
|
|
36
37
|
|
|
@@ -159,6 +160,7 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
|
|
|
159
160
|
| `baseUrl` | `string` | `null` | _Optional:_ Version base URL used when generating version selector dropdown menu. |
|
|
160
161
|
| `versions` | `object` | `null` | _Optional:_ Set of options for versioning configuration. See below for a list of supported options. |
|
|
161
162
|
| `markdownGenerators` | `object` | `null` | _Optional:_ Customize MDX content with a set of options for specifying markdown generator functions. See below for a list of supported options. |
|
|
163
|
+
| `showSchemas` | `boolean` | `null` | _Optional:_ If set to `true`, generates schema pages and adds them to the sidebar. |
|
|
162
164
|
|
|
163
165
|
`sidebarOptions` can be configured with the following options:
|
|
164
166
|
|
package/lib/index.js
CHANGED
|
@@ -15,6 +15,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
15
15
|
const zlib_1 = __importDefault(require("zlib"));
|
|
16
16
|
const utils_1 = require("@docusaurus/utils");
|
|
17
17
|
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
+
const json5_1 = __importDefault(require("json5"));
|
|
18
19
|
const mustache_1 = require("mustache");
|
|
19
20
|
const markdown_1 = require("./markdown");
|
|
20
21
|
const openapi_1 = require("./openapi");
|
|
@@ -77,7 +78,7 @@ function pluginOpenAPIDocs(context, options) {
|
|
|
77
78
|
let docRouteBasePath = docData ? docData.routeBasePath : undefined;
|
|
78
79
|
let docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
|
|
79
80
|
async function generateApiDocs(options, pluginId) {
|
|
80
|
-
var _a, _b, _c;
|
|
81
|
+
var _a, _b, _c, _d;
|
|
81
82
|
let { specPath, outputDir, template, markdownGenerators, downloadUrl, sidebarOptions, } = options;
|
|
82
83
|
// Remove trailing slash before proceeding
|
|
83
84
|
outputDir = outputDir.replace(/\/$/, "");
|
|
@@ -92,7 +93,7 @@ function pluginOpenAPIDocs(context, options) {
|
|
|
92
93
|
: path_1.default.resolve(siteDir, specPath);
|
|
93
94
|
try {
|
|
94
95
|
const openapiFiles = await (0, openapi_1.readOpenapiFiles)(contentPath);
|
|
95
|
-
const [loadedApi, tags] = await (0, openapi_1.processOpenapiFiles)(openapiFiles, options, sidebarOptions);
|
|
96
|
+
const [loadedApi, tags, tagGroups] = await (0, openapi_1.processOpenapiFiles)(openapiFiles, options, sidebarOptions);
|
|
96
97
|
if (!fs_1.default.existsSync(outputDir)) {
|
|
97
98
|
try {
|
|
98
99
|
fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
@@ -104,18 +105,20 @@ function pluginOpenAPIDocs(context, options) {
|
|
|
104
105
|
}
|
|
105
106
|
// TODO: figure out better way to set default
|
|
106
107
|
if (Object.keys(sidebarOptions !== null && sidebarOptions !== void 0 ? sidebarOptions : {}).length > 0) {
|
|
107
|
-
const sidebarSlice = (0, sidebars_1.default)(sidebarOptions, options, loadedApi, tags, docPath);
|
|
108
|
-
|
|
108
|
+
const sidebarSlice = (0, sidebars_1.default)(sidebarOptions, options, loadedApi, tags, docPath, tagGroups);
|
|
109
|
+
let sidebarSliceTemplate = `import type { SidebarsConfig } from "@docusaurus/plugin-content-docs";\n\n`;
|
|
110
|
+
sidebarSliceTemplate += `const sidebar: SidebarsConfig = {{{slice}}};\n\n`;
|
|
111
|
+
sidebarSliceTemplate += `export default sidebar.apisidebar;\n`;
|
|
109
112
|
const view = (0, mustache_1.render)(sidebarSliceTemplate, {
|
|
110
|
-
slice:
|
|
113
|
+
slice: json5_1.default.stringify({ apisidebar: sidebarSlice }, { space: 2, quote: '"' }),
|
|
111
114
|
});
|
|
112
|
-
if (!fs_1.default.existsSync(`${outputDir}/sidebar.
|
|
115
|
+
if (!fs_1.default.existsSync(`${outputDir}/sidebar.ts`)) {
|
|
113
116
|
try {
|
|
114
|
-
fs_1.default.writeFileSync(`${outputDir}/sidebar.
|
|
115
|
-
console.log(chalk_1.default.green(`Successfully created "${outputDir}/sidebar.
|
|
117
|
+
fs_1.default.writeFileSync(`${outputDir}/sidebar.ts`, view, "utf8");
|
|
118
|
+
console.log(chalk_1.default.green(`Successfully created "${outputDir}/sidebar.ts"`));
|
|
116
119
|
}
|
|
117
120
|
catch (err) {
|
|
118
|
-
console.error(chalk_1.default.red(`Failed to write "${outputDir}/sidebar.
|
|
121
|
+
console.error(chalk_1.default.red(`Failed to write "${outputDir}/sidebar.ts"`), chalk_1.default.yellow(err));
|
|
119
122
|
}
|
|
120
123
|
}
|
|
121
124
|
}
|
|
@@ -195,20 +198,35 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
195
198
|
<DocCardList items={useCurrentSidebarCategory().items}/>
|
|
196
199
|
\`\`\`
|
|
197
200
|
`;
|
|
201
|
+
const schemaMdTemplate = `---
|
|
202
|
+
id: {{{id}}}
|
|
203
|
+
title: "{{{title}}}"
|
|
204
|
+
description: "{{{frontMatter.description}}}"
|
|
205
|
+
sidebar_label: "{{{title}}}"
|
|
206
|
+
hide_title: true
|
|
207
|
+
schema: true
|
|
208
|
+
custom_edit_url: null
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
{{{markdown}}}
|
|
212
|
+
`;
|
|
198
213
|
const apiPageGenerator = (_a = markdownGenerators === null || markdownGenerators === void 0 ? void 0 : markdownGenerators.createApiPageMD) !== null && _a !== void 0 ? _a : markdown_1.createApiPageMD;
|
|
199
214
|
const infoPageGenerator = (_b = markdownGenerators === null || markdownGenerators === void 0 ? void 0 : markdownGenerators.createInfoPageMD) !== null && _b !== void 0 ? _b : markdown_1.createInfoPageMD;
|
|
200
215
|
const tagPageGenerator = (_c = markdownGenerators === null || markdownGenerators === void 0 ? void 0 : markdownGenerators.createTagPageMD) !== null && _c !== void 0 ? _c : markdown_1.createTagPageMD;
|
|
216
|
+
const schemaPageGenerator = (_d = markdownGenerators === null || markdownGenerators === void 0 ? void 0 : markdownGenerators.createSchemaPageMD) !== null && _d !== void 0 ? _d : markdown_1.createSchemaPageMD;
|
|
217
|
+
const pageGeneratorByType = {
|
|
218
|
+
api: apiPageGenerator,
|
|
219
|
+
info: infoPageGenerator,
|
|
220
|
+
tag: tagPageGenerator,
|
|
221
|
+
schema: schemaPageGenerator,
|
|
222
|
+
};
|
|
201
223
|
loadedApi.map(async (item) => {
|
|
202
224
|
if (item.type === "info") {
|
|
203
225
|
if (downloadUrl && isURL(downloadUrl)) {
|
|
204
226
|
item.downloadUrl = downloadUrl;
|
|
205
227
|
}
|
|
206
228
|
}
|
|
207
|
-
const markdown = item.type
|
|
208
|
-
? apiPageGenerator(item)
|
|
209
|
-
: item.type === "info"
|
|
210
|
-
? infoPageGenerator(item)
|
|
211
|
-
: tagPageGenerator(item);
|
|
229
|
+
const markdown = pageGeneratorByType[item.type](item);
|
|
212
230
|
item.markdown = markdown;
|
|
213
231
|
if (item.type === "api") {
|
|
214
232
|
// opportunity to compress JSON
|
|
@@ -274,6 +292,32 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
274
292
|
}
|
|
275
293
|
}
|
|
276
294
|
}
|
|
295
|
+
if (item.type === "schema") {
|
|
296
|
+
if (!fs_1.default.existsSync(`${outputDir}/schemas/${item.id}.schema.mdx`)) {
|
|
297
|
+
if (!fs_1.default.existsSync(`${outputDir}/schemas`)) {
|
|
298
|
+
try {
|
|
299
|
+
fs_1.default.mkdirSync(`${outputDir}/schemas`, { recursive: true });
|
|
300
|
+
console.log(chalk_1.default.green(`Successfully created "${outputDir}/schemas"`));
|
|
301
|
+
}
|
|
302
|
+
catch (err) {
|
|
303
|
+
console.error(chalk_1.default.red(`Failed to create "${outputDir}/schemas"`), chalk_1.default.yellow(err));
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
try {
|
|
307
|
+
// kebabCase(arg) returns 0-length string when arg is undefined
|
|
308
|
+
if (item.id.length === 0) {
|
|
309
|
+
throw Error("Schema must have title defined");
|
|
310
|
+
}
|
|
311
|
+
// eslint-disable-next-line testing-library/render-result-naming-convention
|
|
312
|
+
const schemaView = (0, mustache_1.render)(schemaMdTemplate, item);
|
|
313
|
+
fs_1.default.writeFileSync(`${outputDir}/schemas/${item.id}.schema.mdx`, schemaView, "utf8");
|
|
314
|
+
console.log(chalk_1.default.green(`Successfully created "${outputDir}/${item.id}.schema.mdx"`));
|
|
315
|
+
}
|
|
316
|
+
catch (err) {
|
|
317
|
+
console.error(chalk_1.default.red(`Failed to write "${outputDir}/${item.id}.schema.mdx"`), chalk_1.default.yellow(err));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
277
321
|
return;
|
|
278
322
|
});
|
|
279
323
|
return;
|
|
@@ -290,6 +334,10 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
290
334
|
cwd: path_1.default.resolve(apiDir),
|
|
291
335
|
deep: 1,
|
|
292
336
|
});
|
|
337
|
+
const schemaMdxFiles = await (0, utils_1.Globby)(["*.schema.mdx"], {
|
|
338
|
+
cwd: path_1.default.resolve(apiDir, "schemas"),
|
|
339
|
+
deep: 1,
|
|
340
|
+
});
|
|
293
341
|
const sidebarFile = await (0, utils_1.Globby)(["sidebar.js"], {
|
|
294
342
|
cwd: path_1.default.resolve(apiDir),
|
|
295
343
|
deep: 1,
|
|
@@ -302,6 +350,14 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
302
350
|
console.log(chalk_1.default.green(`Cleanup succeeded for "${apiDir}/${mdx}"`));
|
|
303
351
|
}
|
|
304
352
|
}));
|
|
353
|
+
schemaMdxFiles.map((mdx) => fs_1.default.unlink(`${apiDir}/schemas/${mdx}`, (err) => {
|
|
354
|
+
if (err) {
|
|
355
|
+
console.error(chalk_1.default.red(`Cleanup failed for "${apiDir}/schemas/${mdx}"`), chalk_1.default.yellow(err));
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
console.log(chalk_1.default.green(`Cleanup succeeded for "${apiDir}/schemas/${mdx}"`));
|
|
359
|
+
}
|
|
360
|
+
}));
|
|
305
361
|
sidebarFile.map((sidebar) => fs_1.default.unlink(`${apiDir}/${sidebar}`, (err) => {
|
|
306
362
|
if (err) {
|
|
307
363
|
console.error(chalk_1.default.red(`Cleanup failed for "${apiDir}/${sidebar}"`), chalk_1.default.yellow(err));
|
|
@@ -322,7 +378,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
322
378
|
}
|
|
323
379
|
const versionsJson = JSON.stringify(versionsArray, null, 2);
|
|
324
380
|
try {
|
|
325
|
-
fs_1.default.writeFileSync(`${outputDir}/versions.json`, versionsJson, "utf8");
|
|
381
|
+
fs_1.default.writeFileSync(`${outputDir}/versions.json`, versionsJson + "\n", "utf8");
|
|
326
382
|
console.log(chalk_1.default.green(`Successfully created "${outputDir}/versions.json"`));
|
|
327
383
|
}
|
|
328
384
|
catch (err) {
|
|
@@ -346,7 +402,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
346
402
|
extendCli(cli) {
|
|
347
403
|
cli
|
|
348
404
|
.command(`gen-api-docs`)
|
|
349
|
-
.description(`Generates OpenAPI docs in MDX file format and sidebar.
|
|
405
|
+
.description(`Generates OpenAPI docs in MDX file format and sidebar.ts (if enabled).`)
|
|
350
406
|
.usage("<id>")
|
|
351
407
|
.arguments("<id>")
|
|
352
408
|
.option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
|
|
@@ -394,7 +450,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
394
450
|
});
|
|
395
451
|
cli
|
|
396
452
|
.command(`gen-api-docs:version`)
|
|
397
|
-
.description(`Generates versioned OpenAPI docs in MDX file format, versions.js and sidebar.
|
|
453
|
+
.description(`Generates versioned OpenAPI docs in MDX file format, versions.js and sidebar.ts (if enabled).`)
|
|
398
454
|
.usage("<id:version>")
|
|
399
455
|
.arguments("<id:version>")
|
|
400
456
|
.option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
|
|
@@ -469,7 +525,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
469
525
|
});
|
|
470
526
|
cli
|
|
471
527
|
.command(`clean-api-docs`)
|
|
472
|
-
.description(`Clears the generated OpenAPI docs MDX files and sidebar.
|
|
528
|
+
.description(`Clears the generated OpenAPI docs MDX files and sidebar.ts (if enabled).`)
|
|
473
529
|
.usage("<id>")
|
|
474
530
|
.arguments("<id>")
|
|
475
531
|
.option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
|
|
@@ -512,7 +568,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
512
568
|
});
|
|
513
569
|
cli
|
|
514
570
|
.command(`clean-api-docs:version`)
|
|
515
|
-
.description(`Clears the versioned, generated OpenAPI docs MDX files, versions.json and sidebar.
|
|
571
|
+
.description(`Clears the versioned, generated OpenAPI docs MDX files, versions.json and sidebar.ts (if enabled).`)
|
|
516
572
|
.usage("<id:version>")
|
|
517
573
|
.arguments("<id:version>")
|
|
518
574
|
.option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
|
|
@@ -148,11 +148,12 @@ function createAuthentication(securitySchemes) {
|
|
|
148
148
|
};
|
|
149
149
|
return (0, utils_1.create)("div", {
|
|
150
150
|
children: [
|
|
151
|
-
(0, utils_1.create)("
|
|
151
|
+
(0, utils_1.create)("Heading", {
|
|
152
152
|
children: "Authentication",
|
|
153
153
|
id: "authentication",
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
as: "h2",
|
|
155
|
+
className: "openapi-tabs__heading",
|
|
156
|
+
}, { inline: true }),
|
|
156
157
|
(0, utils_1.create)("SchemaTabs", {
|
|
157
158
|
className: "openapi-tabs__security-schemes",
|
|
158
159
|
children: Object.entries(securitySchemes).map(([schemeKey, schemeObj]) => (0, utils_1.create)("TabItem", {
|
|
@@ -0,0 +1,78 @@
|
|
|
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.createCallbacks = void 0;
|
|
10
|
+
const createDescription_1 = require("./createDescription");
|
|
11
|
+
const createMethodEndpoint_1 = require("./createMethodEndpoint");
|
|
12
|
+
const createRequestBodyDetails_1 = require("./createRequestBodyDetails");
|
|
13
|
+
const createStatusCodes_1 = require("./createStatusCodes");
|
|
14
|
+
const utils_1 = require("./utils");
|
|
15
|
+
function createCallbacks({ callbacks }) {
|
|
16
|
+
if (callbacks === undefined) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
const callbacksNames = Object.keys(callbacks);
|
|
20
|
+
if (callbacksNames.length === 0) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return (0, utils_1.create)("div", {
|
|
24
|
+
children: [
|
|
25
|
+
(0, utils_1.create)("div", {
|
|
26
|
+
className: "openapi__divider",
|
|
27
|
+
}),
|
|
28
|
+
(0, utils_1.create)("Heading", {
|
|
29
|
+
children: "Callbacks",
|
|
30
|
+
id: "callbacks",
|
|
31
|
+
as: "h2",
|
|
32
|
+
className: "openapi-tabs__heading",
|
|
33
|
+
}, { inline: true }),
|
|
34
|
+
(0, utils_1.create)("OperationTabs", {
|
|
35
|
+
className: "openapi-tabs__operation",
|
|
36
|
+
children: callbacksNames.flatMap((name) => {
|
|
37
|
+
const path = Object.keys(callbacks[name])[0];
|
|
38
|
+
const methods = new Map([
|
|
39
|
+
["delete", callbacks[name][path].delete],
|
|
40
|
+
["get", callbacks[name][path].get],
|
|
41
|
+
["head", callbacks[name][path].head],
|
|
42
|
+
["options", callbacks[name][path].options],
|
|
43
|
+
["patch", callbacks[name][path].patch],
|
|
44
|
+
["post", callbacks[name][path].post],
|
|
45
|
+
["put", callbacks[name][path].put],
|
|
46
|
+
["trace", callbacks[name][path].trace],
|
|
47
|
+
]);
|
|
48
|
+
return Array.from(methods).flatMap(([method, operationObject]) => {
|
|
49
|
+
if (!operationObject)
|
|
50
|
+
return [];
|
|
51
|
+
const { description, requestBody, responses } = operationObject;
|
|
52
|
+
return [
|
|
53
|
+
(0, utils_1.create)("TabItem", {
|
|
54
|
+
label: `${method.toUpperCase()} ${name}`,
|
|
55
|
+
value: `${method}-${name}`,
|
|
56
|
+
children: [
|
|
57
|
+
(0, createMethodEndpoint_1.createMethodEndpoint)(method, path),
|
|
58
|
+
// TODO: add `deprecation notice` when markdown support is added
|
|
59
|
+
(0, createDescription_1.createDescription)(description),
|
|
60
|
+
(0, createRequestBodyDetails_1.createRequestBodyDetails)({
|
|
61
|
+
title: "Body",
|
|
62
|
+
body: requestBody,
|
|
63
|
+
}),
|
|
64
|
+
(0, createStatusCodes_1.createStatusCodes)({
|
|
65
|
+
id: "callbacks-responses",
|
|
66
|
+
label: "Callbacks Responses",
|
|
67
|
+
responses,
|
|
68
|
+
}),
|
|
69
|
+
],
|
|
70
|
+
}),
|
|
71
|
+
];
|
|
72
|
+
});
|
|
73
|
+
}),
|
|
74
|
+
}),
|
|
75
|
+
],
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
exports.createCallbacks = createCallbacks;
|
|
@@ -12,8 +12,11 @@ function createAdmonition({ children }) {
|
|
|
12
12
|
return `:::caution deprecated\n\n${(0, utils_1.render)(children)}\n\n:::`;
|
|
13
13
|
}
|
|
14
14
|
function createDeprecationNotice({ deprecated, description, }) {
|
|
15
|
-
return (0, utils_1.guard)(deprecated, () =>
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
return (0, utils_1.guard)(deprecated, () => {
|
|
16
|
+
var _a;
|
|
17
|
+
return createAdmonition({
|
|
18
|
+
children: (_a = (0, utils_1.clean)(description)) !== null && _a !== void 0 ? _a : "This endpoint has been deprecated and may be replaced or removed in future versions of the API.",
|
|
19
|
+
});
|
|
20
|
+
});
|
|
18
21
|
}
|
|
19
22
|
exports.createDeprecationNotice = createDeprecationNotice;
|
|
@@ -9,14 +9,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.createDescription = void 0;
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
11
|
function createDescription(description) {
|
|
12
|
-
|
|
13
|
-
return "";
|
|
14
|
-
}
|
|
15
|
-
return `\n\n${description
|
|
16
|
-
.replace(utils_1.lessThan, "<")
|
|
17
|
-
.replace(utils_1.greaterThan, ">")
|
|
18
|
-
.replace(utils_1.codeFence, function (match) {
|
|
19
|
-
return match.replace(/\\>/g, ">");
|
|
20
|
-
})}\n\n`;
|
|
12
|
+
return `\n\n${(0, utils_1.clean)(description)}\n\n`;
|
|
21
13
|
}
|
|
22
14
|
exports.createDescription = createDescription;
|
|
@@ -10,12 +10,11 @@ exports.createHeading = void 0;
|
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
11
|
function createHeading(heading) {
|
|
12
12
|
return [
|
|
13
|
-
(0, utils_1.create)("
|
|
13
|
+
(0, utils_1.create)("Heading", {
|
|
14
|
+
children: (0, utils_1.clean)(heading),
|
|
15
|
+
as: "h1",
|
|
14
16
|
className: "openapi__heading",
|
|
15
|
-
|
|
16
|
-
.replace(utils_1.lessThan, "<")
|
|
17
|
-
.replace(utils_1.greaterThan, ">")}`,
|
|
18
|
-
}),
|
|
17
|
+
}, { inline: true }),
|
|
19
18
|
`\n\n`,
|
|
20
19
|
];
|
|
21
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function createRequestHeader(header: string): string;
|
|
1
|
+
export declare function createRequestHeader(header: string): string[];
|
|
@@ -7,7 +7,16 @@
|
|
|
7
7
|
* ========================================================================== */
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createRequestHeader = void 0;
|
|
10
|
+
const utils_1 = require("./utils");
|
|
10
11
|
function createRequestHeader(header) {
|
|
11
|
-
return
|
|
12
|
+
return [
|
|
13
|
+
(0, utils_1.create)("Heading", {
|
|
14
|
+
children: header,
|
|
15
|
+
id: header.replace(" ", "-").toLowerCase(),
|
|
16
|
+
as: "h2",
|
|
17
|
+
className: "openapi-tabs__heading",
|
|
18
|
+
}, { inline: true }),
|
|
19
|
+
`\n\n`,
|
|
20
|
+
];
|
|
12
21
|
}
|
|
13
22
|
exports.createRequestHeader = createRequestHeader;
|
|
@@ -4,7 +4,7 @@ import { SchemaObject } from "../openapi/types";
|
|
|
4
4
|
*/
|
|
5
5
|
export declare function mergeAllOf(allOf: SchemaObject[]): {
|
|
6
6
|
mergedSchemas: any;
|
|
7
|
-
|
|
7
|
+
mergedRequired: any;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
10
|
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
@@ -40,14 +40,14 @@ function mergeAllOf(allOf) {
|
|
|
40
40
|
},
|
|
41
41
|
ignoreAdditionalProperties: true,
|
|
42
42
|
});
|
|
43
|
-
const
|
|
43
|
+
const mergedRequired = allOf.reduce((acc, cur) => {
|
|
44
44
|
if (Array.isArray(cur.required)) {
|
|
45
45
|
const next = [...acc, ...cur.required];
|
|
46
46
|
return next;
|
|
47
47
|
}
|
|
48
48
|
return acc;
|
|
49
49
|
}, []);
|
|
50
|
-
return { mergedSchemas,
|
|
50
|
+
return { mergedSchemas, mergedRequired };
|
|
51
51
|
}
|
|
52
52
|
exports.mergeAllOf = mergeAllOf;
|
|
53
53
|
/**
|
|
@@ -491,7 +491,7 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
491
491
|
return createAnyOneOfProperty(name, schemaName, schema, required, schema.nullable);
|
|
492
492
|
}
|
|
493
493
|
if (schema.allOf !== undefined) {
|
|
494
|
-
const { mergedSchemas
|
|
494
|
+
const { mergedSchemas } = mergeAllOf(schema.allOf);
|
|
495
495
|
const mergedSchemaName = (0, schema_1.getSchemaName)(mergedSchemas);
|
|
496
496
|
if (mergedSchemas.oneOf !== undefined ||
|
|
497
497
|
mergedSchemas.anyOf !== undefined) {
|
|
@@ -521,8 +521,8 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
521
521
|
collapsible: false,
|
|
522
522
|
name,
|
|
523
523
|
required: Array.isArray(required) ? required.includes(name) : required,
|
|
524
|
-
schemaName:
|
|
525
|
-
qualifierMessage: (0, schema_1.getQualifierMessage)(
|
|
524
|
+
schemaName: mergedSchemaName,
|
|
525
|
+
qualifierMessage: (0, schema_1.getQualifierMessage)(mergedSchemas),
|
|
526
526
|
schema: mergedSchemas,
|
|
527
527
|
});
|
|
528
528
|
}
|
|
@@ -610,9 +610,16 @@ function createNodes(schema, schemaType) {
|
|
|
610
610
|
style: {
|
|
611
611
|
marginTop: ".5rem",
|
|
612
612
|
marginBottom: ".5rem",
|
|
613
|
-
marginLeft: "1rem",
|
|
614
613
|
},
|
|
615
|
-
children:
|
|
614
|
+
children: [
|
|
615
|
+
(0, createDescription_1.createDescription)(schema.type),
|
|
616
|
+
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
|
|
617
|
+
style: {
|
|
618
|
+
paddingTop: "1rem",
|
|
619
|
+
},
|
|
620
|
+
children: (0, createDescription_1.createDescription)(message),
|
|
621
|
+
})),
|
|
622
|
+
],
|
|
616
623
|
});
|
|
617
624
|
}
|
|
618
625
|
// handle circular references
|
|
@@ -621,9 +628,16 @@ function createNodes(schema, schemaType) {
|
|
|
621
628
|
style: {
|
|
622
629
|
marginTop: ".5rem",
|
|
623
630
|
marginBottom: ".5rem",
|
|
624
|
-
marginLeft: "1rem",
|
|
625
631
|
},
|
|
626
|
-
children: [
|
|
632
|
+
children: [
|
|
633
|
+
(0, createDescription_1.createDescription)(schema),
|
|
634
|
+
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
|
|
635
|
+
style: {
|
|
636
|
+
paddingTop: "1rem",
|
|
637
|
+
},
|
|
638
|
+
children: (0, createDescription_1.createDescription)(message),
|
|
639
|
+
})),
|
|
640
|
+
],
|
|
627
641
|
});
|
|
628
642
|
}
|
|
629
643
|
// Unknown node/schema type should return undefined
|
|
@@ -32,7 +32,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
const prettier = __importStar(require("prettier"));
|
|
33
33
|
const createSchema_1 = require("./createSchema");
|
|
34
34
|
describe("createNodes", () => {
|
|
35
|
-
it("should create readable MODs for oneOf primitive properties", () => {
|
|
35
|
+
it("should create readable MODs for oneOf primitive properties", async () => {
|
|
36
36
|
const schema = {
|
|
37
37
|
type: "object",
|
|
38
38
|
properties: {
|
|
@@ -68,6 +68,6 @@ describe("createNodes", () => {
|
|
|
68
68
|
},
|
|
69
69
|
},
|
|
70
70
|
};
|
|
71
|
-
expect((0, createSchema_1.createNodes)(schema, "request").map((md) => prettier.format(md, { parser: "babel" }))).toMatchSnapshot();
|
|
71
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "request").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
72
72
|
});
|
|
73
73
|
});
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { ApiItem } from "../types";
|
|
2
2
|
export default function json2xml(o: any, tab: any): string;
|
|
3
3
|
interface Props {
|
|
4
|
+
id?: string;
|
|
5
|
+
label?: string;
|
|
4
6
|
responses: ApiItem["responses"];
|
|
5
7
|
}
|
|
6
8
|
export declare function createResponseExamples(responseExamples: any, mimeType: string): string[];
|
|
7
9
|
export declare function createResponseExample(responseExample: any, mimeType: string): string;
|
|
8
10
|
export declare function createExampleFromSchema(schema: any, mimeType: string): string | undefined;
|
|
9
|
-
export declare function createStatusCodes({ responses }: Props): string | undefined;
|
|
11
|
+
export declare function createStatusCodes({ label, id, responses }: Props): string | undefined;
|
|
10
12
|
export {};
|
|
@@ -11,13 +11,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.createStatusCodes = exports.createExampleFromSchema = exports.createResponseExample = exports.createResponseExamples = void 0;
|
|
13
13
|
const xml_formatter_1 = __importDefault(require("xml-formatter"));
|
|
14
|
-
const createResponseExample_1 = require("../openapi/createResponseExample");
|
|
15
14
|
const createDescription_1 = require("./createDescription");
|
|
16
15
|
const createDetails_1 = require("./createDetails");
|
|
17
16
|
const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
18
17
|
const createResponseSchema_1 = require("./createResponseSchema");
|
|
19
18
|
const utils_1 = require("./utils");
|
|
20
19
|
const utils_2 = require("./utils");
|
|
20
|
+
const createResponseExample_1 = require("../openapi/createResponseExample");
|
|
21
21
|
function json2xml(o, tab) {
|
|
22
22
|
var toXml = function (v, name, ind) {
|
|
23
23
|
var xml = "";
|
|
@@ -118,7 +118,7 @@ function createResponseExamples(responseExamples, mimeType) {
|
|
|
118
118
|
value: `${exampleName}`,
|
|
119
119
|
children: [
|
|
120
120
|
(0, utils_2.guard)(exampleValue.summary, (summary) => [
|
|
121
|
-
(0, utils_1.create)("
|
|
121
|
+
(0, utils_1.create)("Markdown", {
|
|
122
122
|
children: ` ${summary}`,
|
|
123
123
|
}),
|
|
124
124
|
]),
|
|
@@ -134,7 +134,7 @@ function createResponseExamples(responseExamples, mimeType) {
|
|
|
134
134
|
value: `${exampleName}`,
|
|
135
135
|
children: [
|
|
136
136
|
(0, utils_2.guard)(exampleValue.summary, (summary) => [
|
|
137
|
-
(0, utils_1.create)("
|
|
137
|
+
(0, utils_1.create)("Markdown", {
|
|
138
138
|
children: ` ${summary}`,
|
|
139
139
|
}),
|
|
140
140
|
]),
|
|
@@ -161,7 +161,7 @@ function createResponseExample(responseExample, mimeType) {
|
|
|
161
161
|
value: `Example`,
|
|
162
162
|
children: [
|
|
163
163
|
(0, utils_2.guard)(responseExample.summary, (summary) => [
|
|
164
|
-
(0, utils_1.create)("
|
|
164
|
+
(0, utils_1.create)("Markdown", {
|
|
165
165
|
children: ` ${summary}`,
|
|
166
166
|
}),
|
|
167
167
|
]),
|
|
@@ -177,7 +177,7 @@ function createResponseExample(responseExample, mimeType) {
|
|
|
177
177
|
value: `Example`,
|
|
178
178
|
children: [
|
|
179
179
|
(0, utils_2.guard)(responseExample.summary, (summary) => [
|
|
180
|
-
(0, utils_1.create)("
|
|
180
|
+
(0, utils_1.create)("Markdown", {
|
|
181
181
|
children: ` ${summary}`,
|
|
182
182
|
}),
|
|
183
183
|
]),
|
|
@@ -248,7 +248,7 @@ function createExampleFromSchema(schema, mimeType) {
|
|
|
248
248
|
return undefined;
|
|
249
249
|
}
|
|
250
250
|
exports.createExampleFromSchema = createExampleFromSchema;
|
|
251
|
-
function createStatusCodes({ responses }) {
|
|
251
|
+
function createStatusCodes({ label, id, responses }) {
|
|
252
252
|
if (responses === undefined) {
|
|
253
253
|
return undefined;
|
|
254
254
|
}
|
|
@@ -261,6 +261,8 @@ function createStatusCodes({ responses }) {
|
|
|
261
261
|
(0, utils_1.create)("div", {
|
|
262
262
|
children: [
|
|
263
263
|
(0, utils_1.create)("ApiTabs", {
|
|
264
|
+
label,
|
|
265
|
+
id,
|
|
264
266
|
children: codes.map((code) => {
|
|
265
267
|
const responseHeaders = responses[code].headers;
|
|
266
268
|
return (0, utils_1.create)("TabItem", {
|
package/lib/markdown/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ApiPageMetadata, InfoPageMetadata, TagPageMetadata } from "../types";
|
|
2
|
-
export declare function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, method, path, extensions, parameters, requestBody, responses, }, infoPath, frontMatter, }: ApiPageMetadata): string;
|
|
1
|
+
import { ApiPageMetadata, InfoPageMetadata, SchemaPageMetadata, TagPageMetadata } from "../types";
|
|
2
|
+
export declare function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, method, path, extensions, parameters, requestBody, responses, callbacks, }, infoPath, frontMatter, }: ApiPageMetadata): string;
|
|
3
3
|
export declare function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService, logo, darkLogo, }, securitySchemes, downloadUrl, }: InfoPageMetadata): string;
|
|
4
4
|
export declare function createTagPageMD({ tag: { description } }: TagPageMetadata): string;
|
|
5
|
+
export declare function createSchemaPageMD({ schema }: SchemaPageMetadata): string;
|