docusaurus-plugin-openapi-docs 3.0.0-beta.1 → 3.0.0-beta.3
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/lib/index.js +13 -11
- package/lib/markdown/createDeprecationNotice.js +6 -3
- package/lib/markdown/createDescription.js +1 -9
- package/lib/markdown/createHeading.js +1 -3
- package/lib/markdown/createRequestSchema.js +2 -2
- package/lib/markdown/createResponseSchema.js +1 -1
- package/lib/markdown/createSchema.d.ts +1 -1
- package/lib/markdown/createSchema.js +29 -10
- package/lib/markdown/createSchema.test.js +2 -2
- package/lib/markdown/index.js +2 -2
- package/lib/markdown/utils.d.ts +5 -2
- package/lib/markdown/utils.js +22 -1
- package/lib/openapi/openapi.js +1 -1
- package/lib/openapi/types.d.ts +13 -13
- package/lib/openapi/utils/services/OpenAPIParser.d.ts +1 -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/types.d.ts +2 -2
- package/package.json +8 -7
- package/src/index.ts +15 -13
- package/src/markdown/createDeprecationNotice.ts +2 -2
- package/src/markdown/createDescription.ts +2 -10
- package/src/markdown/createHeading.ts +2 -4
- package/src/markdown/createRequestSchema.ts +2 -2
- package/src/markdown/createResponseSchema.ts +1 -1
- package/src/markdown/createSchema.test.ts +5 -3
- package/src/markdown/createSchema.ts +35 -10
- package/src/markdown/index.ts +3 -3
- package/src/markdown/utils.ts +22 -0
- package/src/openapi/openapi.ts +1 -2
- package/src/openapi/utils/services/OpenAPIParser.ts +2 -2
- package/src/openapi/utils/utils/openapi.ts +1 -1
- package/src/sidebars/index.ts +1 -0
package/lib/index.js
CHANGED
|
@@ -105,17 +105,19 @@ function pluginOpenAPIDocs(context, options) {
|
|
|
105
105
|
// TODO: figure out better way to set default
|
|
106
106
|
if (Object.keys(sidebarOptions !== null && sidebarOptions !== void 0 ? sidebarOptions : {}).length > 0) {
|
|
107
107
|
const sidebarSlice = (0, sidebars_1.default)(sidebarOptions, options, loadedApi, tags, docPath);
|
|
108
|
-
|
|
108
|
+
let sidebarSliceTemplate = `import {SidebarConfig} from "@docusaurus/plugin-content-docs/src/sidebars/types";\n\n`;
|
|
109
|
+
sidebarSliceTemplate += `const sidebar: SidebarConfig = {{{slice}}};\n\n`;
|
|
110
|
+
sidebarSliceTemplate += `export default sidebar;`;
|
|
109
111
|
const view = (0, mustache_1.render)(sidebarSliceTemplate, {
|
|
110
|
-
slice: JSON.stringify(sidebarSlice),
|
|
112
|
+
slice: JSON.stringify(sidebarSlice, null, 2),
|
|
111
113
|
});
|
|
112
|
-
if (!fs_1.default.existsSync(`${outputDir}/sidebar.
|
|
114
|
+
if (!fs_1.default.existsSync(`${outputDir}/sidebar.ts`)) {
|
|
113
115
|
try {
|
|
114
|
-
fs_1.default.writeFileSync(`${outputDir}/sidebar.
|
|
115
|
-
console.log(chalk_1.default.green(`Successfully created "${outputDir}/sidebar.
|
|
116
|
+
fs_1.default.writeFileSync(`${outputDir}/sidebar.ts`, view, "utf8");
|
|
117
|
+
console.log(chalk_1.default.green(`Successfully created "${outputDir}/sidebar.ts"`));
|
|
116
118
|
}
|
|
117
119
|
catch (err) {
|
|
118
|
-
console.error(chalk_1.default.red(`Failed to write "${outputDir}/sidebar.
|
|
120
|
+
console.error(chalk_1.default.red(`Failed to write "${outputDir}/sidebar.ts"`), chalk_1.default.yellow(err));
|
|
119
121
|
}
|
|
120
122
|
}
|
|
121
123
|
}
|
|
@@ -290,7 +292,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
290
292
|
cwd: path_1.default.resolve(apiDir),
|
|
291
293
|
deep: 1,
|
|
292
294
|
});
|
|
293
|
-
const sidebarFile = await (0, utils_1.Globby)(["sidebar.
|
|
295
|
+
const sidebarFile = await (0, utils_1.Globby)(["sidebar.ts"], {
|
|
294
296
|
cwd: path_1.default.resolve(apiDir),
|
|
295
297
|
deep: 1,
|
|
296
298
|
});
|
|
@@ -346,7 +348,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
346
348
|
extendCli(cli) {
|
|
347
349
|
cli
|
|
348
350
|
.command(`gen-api-docs`)
|
|
349
|
-
.description(`Generates OpenAPI docs in MDX file format and sidebar.
|
|
351
|
+
.description(`Generates OpenAPI docs in MDX file format and sidebar.ts (if enabled).`)
|
|
350
352
|
.usage("<id>")
|
|
351
353
|
.arguments("<id>")
|
|
352
354
|
.option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
|
|
@@ -394,7 +396,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
394
396
|
});
|
|
395
397
|
cli
|
|
396
398
|
.command(`gen-api-docs:version`)
|
|
397
|
-
.description(`Generates versioned OpenAPI docs in MDX file format, versions.js and sidebar.
|
|
399
|
+
.description(`Generates versioned OpenAPI docs in MDX file format, versions.js and sidebar.ts (if enabled).`)
|
|
398
400
|
.usage("<id:version>")
|
|
399
401
|
.arguments("<id:version>")
|
|
400
402
|
.option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
|
|
@@ -469,7 +471,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
469
471
|
});
|
|
470
472
|
cli
|
|
471
473
|
.command(`clean-api-docs`)
|
|
472
|
-
.description(`Clears the generated OpenAPI docs MDX files and sidebar.
|
|
474
|
+
.description(`Clears the generated OpenAPI docs MDX files and sidebar.ts (if enabled).`)
|
|
473
475
|
.usage("<id>")
|
|
474
476
|
.arguments("<id>")
|
|
475
477
|
.option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
|
|
@@ -512,7 +514,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
512
514
|
});
|
|
513
515
|
cli
|
|
514
516
|
.command(`clean-api-docs:version`)
|
|
515
|
-
.description(`Clears the versioned, generated OpenAPI docs MDX files, versions.json and sidebar.
|
|
517
|
+
.description(`Clears the versioned, generated OpenAPI docs MDX files, versions.json and sidebar.ts (if enabled).`)
|
|
516
518
|
.usage("<id:version>")
|
|
517
519
|
.arguments("<id:version>")
|
|
518
520
|
.option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
|
|
@@ -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;
|
|
@@ -12,9 +12,7 @@ function createHeading(heading) {
|
|
|
12
12
|
return [
|
|
13
13
|
(0, utils_1.create)("h1", {
|
|
14
14
|
className: "openapi__heading",
|
|
15
|
-
children:
|
|
16
|
-
.replace(utils_1.lessThan, "<")
|
|
17
|
-
.replace(utils_1.greaterThan, ">")}`,
|
|
15
|
+
children: (0, utils_1.clean)(heading),
|
|
18
16
|
}),
|
|
19
17
|
`\n\n`,
|
|
20
18
|
];
|
|
@@ -74,7 +74,7 @@ function createRequestSchema({ title, body, ...rest }) {
|
|
|
74
74
|
}),
|
|
75
75
|
(0, utils_1.create)("ul", {
|
|
76
76
|
style: { marginLeft: "1rem" },
|
|
77
|
-
children: (0, createSchema_1.createNodes)(firstBody),
|
|
77
|
+
children: (0, createSchema_1.createNodes)(firstBody, "request"),
|
|
78
78
|
}),
|
|
79
79
|
],
|
|
80
80
|
}),
|
|
@@ -139,7 +139,7 @@ function createRequestSchema({ title, body, ...rest }) {
|
|
|
139
139
|
}),
|
|
140
140
|
(0, utils_1.create)("ul", {
|
|
141
141
|
style: { marginLeft: "1rem" },
|
|
142
|
-
children: (0, createSchema_1.createNodes)(firstBody),
|
|
142
|
+
children: (0, createSchema_1.createNodes)(firstBody, "request"),
|
|
143
143
|
}),
|
|
144
144
|
],
|
|
145
145
|
}),
|
|
@@ -89,7 +89,7 @@ function createResponseSchema({ title, body, ...rest }) {
|
|
|
89
89
|
}),
|
|
90
90
|
(0, utils_1.create)("ul", {
|
|
91
91
|
style: { marginLeft: "1rem" },
|
|
92
|
-
children: (0, createSchema_1.createNodes)(firstBody),
|
|
92
|
+
children: (0, createSchema_1.createNodes)(firstBody, "response"),
|
|
93
93
|
}),
|
|
94
94
|
],
|
|
95
95
|
}),
|
|
@@ -9,4 +9,4 @@ export declare function mergeAllOf(allOf: SchemaObject[]): {
|
|
|
9
9
|
/**
|
|
10
10
|
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
11
11
|
*/
|
|
12
|
-
export declare function createNodes(schema: SchemaObject): any;
|
|
12
|
+
export declare function createNodes(schema: SchemaObject, schemaType: "request" | "response"): any;
|
|
@@ -18,6 +18,7 @@ const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
|
18
18
|
const schema_1 = require("./schema");
|
|
19
19
|
const utils_1 = require("./utils");
|
|
20
20
|
const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
|
|
21
|
+
let SCHEMA_TYPE;
|
|
21
22
|
/**
|
|
22
23
|
* Returns a merged representation of allOf array of schemas.
|
|
23
24
|
*/
|
|
@@ -27,6 +28,9 @@ function mergeAllOf(allOf) {
|
|
|
27
28
|
readOnly: function () {
|
|
28
29
|
return true;
|
|
29
30
|
},
|
|
31
|
+
writeOnly: function () {
|
|
32
|
+
return true;
|
|
33
|
+
},
|
|
30
34
|
example: function () {
|
|
31
35
|
return true;
|
|
32
36
|
},
|
|
@@ -68,7 +72,7 @@ function createAnyOneOf(schema) {
|
|
|
68
72
|
delete anyOneSchema.properties;
|
|
69
73
|
}
|
|
70
74
|
if (anyOneSchema.allOf !== undefined) {
|
|
71
|
-
anyOneChildren.push(createNodes(anyOneSchema));
|
|
75
|
+
anyOneChildren.push(createNodes(anyOneSchema, SCHEMA_TYPE));
|
|
72
76
|
delete anyOneSchema.allOf;
|
|
73
77
|
}
|
|
74
78
|
if (anyOneSchema.items !== undefined) {
|
|
@@ -79,7 +83,7 @@ function createAnyOneOf(schema) {
|
|
|
79
83
|
anyOneSchema.type === "number" ||
|
|
80
84
|
anyOneSchema.type === "integer" ||
|
|
81
85
|
anyOneSchema.type === "boolean") {
|
|
82
|
-
anyOneChildren.push(createNodes(anyOneSchema));
|
|
86
|
+
anyOneChildren.push(createNodes(anyOneSchema, SCHEMA_TYPE));
|
|
83
87
|
}
|
|
84
88
|
if (anyOneChildren.length) {
|
|
85
89
|
if (schema.type === "array") {
|
|
@@ -257,7 +261,7 @@ function createItems(schema) {
|
|
|
257
261
|
((_l = schema.items) === null || _l === void 0 ? void 0 : _l.type) === "object") {
|
|
258
262
|
return [
|
|
259
263
|
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
260
|
-
createNodes(schema.items),
|
|
264
|
+
createNodes(schema.items, SCHEMA_TYPE),
|
|
261
265
|
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
262
266
|
].flat();
|
|
263
267
|
}
|
|
@@ -344,7 +348,7 @@ function createDetailsNode(name, schemaName, schema, required, nullable) {
|
|
|
344
348
|
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
345
349
|
children: (0, createDescription_1.createDescription)(description),
|
|
346
350
|
})),
|
|
347
|
-
createNodes(schema),
|
|
351
|
+
createNodes(schema, SCHEMA_TYPE),
|
|
348
352
|
],
|
|
349
353
|
}),
|
|
350
354
|
],
|
|
@@ -466,7 +470,7 @@ function createPropertyDiscriminator(name, schemaName, schema, discriminator, re
|
|
|
466
470
|
// className: "openapi-tabs__discriminator-item",
|
|
467
471
|
label: label,
|
|
468
472
|
value: `${index}-item-discriminator`,
|
|
469
|
-
children: [createNodes(discriminator === null || discriminator === void 0 ? void 0 : discriminator.mapping[key])],
|
|
473
|
+
children: [createNodes(discriminator === null || discriminator === void 0 ? void 0 : discriminator.mapping[key], SCHEMA_TYPE)],
|
|
470
474
|
});
|
|
471
475
|
}),
|
|
472
476
|
}),
|
|
@@ -503,8 +507,15 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
503
507
|
if (((_a = mergedSchemas.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
|
|
504
508
|
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
505
509
|
}
|
|
506
|
-
if (
|
|
507
|
-
|
|
510
|
+
if (SCHEMA_TYPE === "request") {
|
|
511
|
+
if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
|
|
512
|
+
return undefined;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
if (SCHEMA_TYPE === "response") {
|
|
516
|
+
if (mergedSchemas.writeOnly && mergedSchemas.writeOnly === true) {
|
|
517
|
+
return undefined;
|
|
518
|
+
}
|
|
508
519
|
}
|
|
509
520
|
return (0, utils_1.create)("SchemaItem", {
|
|
510
521
|
collapsible: false,
|
|
@@ -528,8 +539,15 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
528
539
|
if (((_c = schema.items) === null || _c === void 0 ? void 0 : _c.anyOf) !== undefined || ((_d = schema.items) === null || _d === void 0 ? void 0 : _d.oneOf) !== undefined) {
|
|
529
540
|
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
530
541
|
}
|
|
531
|
-
if (
|
|
532
|
-
|
|
542
|
+
if (SCHEMA_TYPE === "request") {
|
|
543
|
+
if (schema.readOnly && schema.readOnly === true) {
|
|
544
|
+
return undefined;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
if (SCHEMA_TYPE === "response") {
|
|
548
|
+
if (schema.writeOnly && schema.writeOnly === true) {
|
|
549
|
+
return undefined;
|
|
550
|
+
}
|
|
533
551
|
}
|
|
534
552
|
// primitives and array of non-objects
|
|
535
553
|
return (0, utils_1.create)("SchemaItem", {
|
|
@@ -544,7 +562,8 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
544
562
|
/**
|
|
545
563
|
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
546
564
|
*/
|
|
547
|
-
function createNodes(schema) {
|
|
565
|
+
function createNodes(schema, schemaType) {
|
|
566
|
+
SCHEMA_TYPE = schemaType;
|
|
548
567
|
const nodes = [];
|
|
549
568
|
// if (schema.discriminator !== undefined) {
|
|
550
569
|
// return createDiscriminator(schema);
|
|
@@ -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).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
|
});
|
package/lib/markdown/index.js
CHANGED
|
@@ -37,7 +37,7 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
|
|
|
37
37
|
`import SchemaItem from "@theme/SchemaItem";\n`,
|
|
38
38
|
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
39
39
|
`import TabItem from "@theme/TabItem";\n\n`,
|
|
40
|
-
(0, createHeading_1.createHeading)(title
|
|
40
|
+
(0, createHeading_1.createHeading)(title),
|
|
41
41
|
(0, createMethodEndpoint_1.createMethodEndpoint)(method, path),
|
|
42
42
|
infoPath && (0, createAuthorization_1.createAuthorization)(infoPath),
|
|
43
43
|
frontMatter.show_extensions && (0, createVendorExtensions_1.createVendorExtensions)(extensions),
|
|
@@ -64,7 +64,7 @@ function createInfoPageMD({ info: { title, version, description, contact, licens
|
|
|
64
64
|
`import Export from "@theme/ApiExplorer/Export";\n\n`,
|
|
65
65
|
(0, createVersionBadge_1.createVersionBadge)(version),
|
|
66
66
|
(0, createDownload_1.createDownload)(downloadUrl),
|
|
67
|
-
(0, createHeading_1.createHeading)(title
|
|
67
|
+
(0, createHeading_1.createHeading)(title),
|
|
68
68
|
(0, createLogo_1.createLogo)(logo, darkLogo),
|
|
69
69
|
(0, createDescription_1.createDescription)(description),
|
|
70
70
|
(0, createAuthentication_1.createAuthentication)(securitySchemes),
|
package/lib/markdown/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export type Children = string | undefined | (string | string[] | undefined)[];
|
|
2
|
+
export type Props = Record<string, any> & {
|
|
3
3
|
children?: Children;
|
|
4
4
|
};
|
|
5
5
|
export declare function create(tag: string, props: Props): string;
|
|
@@ -8,3 +8,6 @@ export declare function render(children: Children): string;
|
|
|
8
8
|
export declare const lessThan: RegExp;
|
|
9
9
|
export declare const greaterThan: RegExp;
|
|
10
10
|
export declare const codeFence: RegExp;
|
|
11
|
+
export declare const curlyBrackets: RegExp;
|
|
12
|
+
export declare const codeBlock: RegExp;
|
|
13
|
+
export declare function clean(value: string | undefined): string;
|
package/lib/markdown/utils.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
* ========================================================================== */
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.codeFence = exports.greaterThan = exports.lessThan = exports.render = exports.guard = exports.create = void 0;
|
|
9
|
+
exports.clean = exports.codeBlock = exports.curlyBrackets = exports.codeFence = exports.greaterThan = exports.lessThan = exports.render = exports.guard = exports.create = void 0;
|
|
10
10
|
function create(tag, props) {
|
|
11
11
|
const { children, ...rest } = props;
|
|
12
12
|
let propString = "";
|
|
@@ -41,3 +41,24 @@ exports.render = render;
|
|
|
41
41
|
exports.lessThan = /<=?(?!(=|button|\s?\/button|code|\s?\/code|details|\s?\/details|summary|\s?\/summary|hr|\s?\/hr|br|\s?\/br|span|\s?\/span|strong|\s?\/strong|small|\s?\/small|table|\s?\/table|thead|\s?\/thead|tbody|\s?\/tbody|td|\s?\/td|tr|\s?\/tr|th|\s?\/th|h1|\s?\/h1|h2|\s?\/h2|h3|\s?\/h3|h4|\s?\/h4|h5|\s?\/h5|h6|\s?\/h6|title|\s?\/title|p|\s?\/p|em|\s?\/em|b|\s?\/b|i|\s?\/i|u|\s?\/u|strike|\s?\/strike|bold|\s?\/bold|a|\s?\/a|table|\s?\/table|li|\s?\/li|ol|\s?\/ol|ul|\s?\/ul|img|\s?\/img|svg|\s?\/svg|div|\s?\/div|center|\s?\/center))/gu;
|
|
42
42
|
exports.greaterThan = /(?<!(button|code|details|summary|hr|br|span|strong|small|table|thead|tbody|td|tr|th|h1|h2|h3|h4|h5|h6|title|p|em|b|i|u|strike|bold|a|li|ol|ul|img|svg|div|center|\/|\s|"|'))>/gu;
|
|
43
43
|
exports.codeFence = /`{1,3}[\s\S]*?`{1,3}/g;
|
|
44
|
+
exports.curlyBrackets = /\{(.*)}/g;
|
|
45
|
+
exports.codeBlock = /^(```.*[\s\S]*?```)$/gm;
|
|
46
|
+
function clean(value) {
|
|
47
|
+
if (!value) {
|
|
48
|
+
return "";
|
|
49
|
+
}
|
|
50
|
+
let sections = value.split(exports.codeBlock);
|
|
51
|
+
for (let sectionIndex in sections) {
|
|
52
|
+
if (!sections[sectionIndex].startsWith("```")) {
|
|
53
|
+
sections[sectionIndex] = sections[sectionIndex]
|
|
54
|
+
.replace(exports.lessThan, "<")
|
|
55
|
+
.replace(exports.greaterThan, ">")
|
|
56
|
+
.replace(exports.codeFence, function (match) {
|
|
57
|
+
return match.replace(/\\>/g, ">");
|
|
58
|
+
})
|
|
59
|
+
.replace(exports.curlyBrackets, "\\{$1\\}");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return sections.join("");
|
|
63
|
+
}
|
|
64
|
+
exports.clean = clean;
|
package/lib/openapi/openapi.js
CHANGED
|
@@ -373,7 +373,7 @@ function bindCollectionToApiItems(items, postmanCollection) {
|
|
|
373
373
|
const method = item.request.method.toLowerCase();
|
|
374
374
|
const path = item.request.url
|
|
375
375
|
.getPath({ unresolved: true }) // unresolved returns "/:variableName" instead of "/<type>"
|
|
376
|
-
.replace(
|
|
376
|
+
.replace(/(?<![a-z0-9-_]+):([a-z0-9-_]+)/gi, "{$1}"); // replace "/:variableName" with "/{variableName}"
|
|
377
377
|
const apiItem = items.find((item) => {
|
|
378
378
|
if (item.type === "info" || item.type === "tag") {
|
|
379
379
|
return false;
|
package/lib/openapi/types.d.ts
CHANGED
|
@@ -81,8 +81,8 @@ export interface ComponentsObjectWithRef {
|
|
|
81
81
|
links?: Map<LinkObject | ReferenceObject>;
|
|
82
82
|
callbacks?: Map<CallbackObjectWithRef | ReferenceObject>;
|
|
83
83
|
}
|
|
84
|
-
export
|
|
85
|
-
export
|
|
84
|
+
export type PathsObject = Map<PathItemObject>;
|
|
85
|
+
export type PathsObjectWithRef = Map<PathItemObjectWithRef>;
|
|
86
86
|
export interface PathItemObject {
|
|
87
87
|
$ref?: string;
|
|
88
88
|
summary?: string;
|
|
@@ -214,8 +214,8 @@ export interface EncodingObjectWithRef {
|
|
|
214
214
|
explode?: boolean;
|
|
215
215
|
allowReserved?: boolean;
|
|
216
216
|
}
|
|
217
|
-
export
|
|
218
|
-
export
|
|
217
|
+
export type ResponsesObject = Map<ResponseObject>;
|
|
218
|
+
export type ResponsesObjectWithRef = Map<ResponseObjectWithRef | ReferenceObject>;
|
|
219
219
|
export interface ResponseObject {
|
|
220
220
|
description: string;
|
|
221
221
|
headers?: Map<HeaderObject>;
|
|
@@ -228,8 +228,8 @@ export interface ResponseObjectWithRef {
|
|
|
228
228
|
content?: Map<MediaTypeObjectWithRef>;
|
|
229
229
|
links?: Map<LinkObject | ReferenceObject>;
|
|
230
230
|
}
|
|
231
|
-
export
|
|
232
|
-
export
|
|
231
|
+
export type CallbackObject = Map<PathItemObject>;
|
|
232
|
+
export type CallbackObjectWithRef = Map<PathItemObjectWithRef>;
|
|
233
233
|
export interface ExampleObject {
|
|
234
234
|
summary?: string;
|
|
235
235
|
description?: string;
|
|
@@ -244,8 +244,8 @@ export interface LinkObject {
|
|
|
244
244
|
description?: string;
|
|
245
245
|
server?: ServerObject;
|
|
246
246
|
}
|
|
247
|
-
export
|
|
248
|
-
export
|
|
247
|
+
export type HeaderObject = Omit<ParameterObject, "name" | "in">;
|
|
248
|
+
export type HeaderObjectWithRef = Omit<ParameterObjectWithRef, "name" | "in">;
|
|
249
249
|
export interface TagObject {
|
|
250
250
|
name?: string;
|
|
251
251
|
description?: string;
|
|
@@ -255,8 +255,8 @@ export interface TagObject {
|
|
|
255
255
|
export interface ReferenceObject {
|
|
256
256
|
$ref: string;
|
|
257
257
|
}
|
|
258
|
-
export
|
|
259
|
-
export
|
|
258
|
+
export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
|
|
259
|
+
export type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
|
|
260
260
|
type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
|
|
261
261
|
allOf?: SchemaObject[];
|
|
262
262
|
oneOf?: SchemaObject[];
|
|
@@ -274,7 +274,7 @@ export declare type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" |
|
|
|
274
274
|
example?: any;
|
|
275
275
|
deprecated?: boolean;
|
|
276
276
|
};
|
|
277
|
-
export
|
|
277
|
+
export type SchemaObjectWithRef = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
|
|
278
278
|
type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
|
|
279
279
|
allOf?: (SchemaObject | ReferenceObject)[];
|
|
280
280
|
oneOf?: (SchemaObject | ReferenceObject)[];
|
|
@@ -303,7 +303,7 @@ export interface XMLObject {
|
|
|
303
303
|
attribute?: boolean;
|
|
304
304
|
wrapped?: boolean;
|
|
305
305
|
}
|
|
306
|
-
export
|
|
306
|
+
export type SecuritySchemeObject = ApiKeySecuritySchemeObject | HttpSecuritySchemeObject | Oauth2SecuritySchemeObject | OpenIdConnectSecuritySchemeObject;
|
|
307
307
|
export interface ApiKeySecuritySchemeObject {
|
|
308
308
|
type: "apiKey";
|
|
309
309
|
description?: string;
|
|
@@ -340,5 +340,5 @@ export interface OAuthFlowObject {
|
|
|
340
340
|
refreshUrl?: string;
|
|
341
341
|
scopes: Map<string>;
|
|
342
342
|
}
|
|
343
|
-
export
|
|
343
|
+
export type SecurityRequirementObject = Map<string[]>;
|
|
344
344
|
export {};
|
|
@@ -39,55 +39,6 @@ function argValueToExpandLevel(value, defaultValue = 0) {
|
|
|
39
39
|
return argValueToNumber(value) || defaultValue;
|
|
40
40
|
}
|
|
41
41
|
class RedocNormalizedOptions {
|
|
42
|
-
constructor(raw, defaults = {}) {
|
|
43
|
-
var _a;
|
|
44
|
-
raw = { ...defaults, ...raw };
|
|
45
|
-
this.hideHostname = RedocNormalizedOptions.normalizeHideHostname(raw.hideHostname);
|
|
46
|
-
this.expandResponses = RedocNormalizedOptions.normalizeExpandResponses(raw.expandResponses);
|
|
47
|
-
this.requiredPropsFirst = argValueToBoolean(raw.requiredPropsFirst);
|
|
48
|
-
this.sortPropsAlphabetically = argValueToBoolean(raw.sortPropsAlphabetically);
|
|
49
|
-
this.sortEnumValuesAlphabetically = argValueToBoolean(raw.sortEnumValuesAlphabetically);
|
|
50
|
-
this.sortOperationsAlphabetically = argValueToBoolean(raw.sortOperationsAlphabetically);
|
|
51
|
-
this.sortTagsAlphabetically = argValueToBoolean(raw.sortTagsAlphabetically);
|
|
52
|
-
this.nativeScrollbars = argValueToBoolean(raw.nativeScrollbars);
|
|
53
|
-
this.pathInMiddlePanel = argValueToBoolean(raw.pathInMiddlePanel);
|
|
54
|
-
this.untrustedSpec = argValueToBoolean(raw.untrustedSpec);
|
|
55
|
-
this.hideDownloadButton = argValueToBoolean(raw.hideDownloadButton);
|
|
56
|
-
this.downloadFileName = raw.downloadFileName;
|
|
57
|
-
this.downloadDefinitionUrl = raw.downloadDefinitionUrl;
|
|
58
|
-
this.disableSearch = argValueToBoolean(raw.disableSearch);
|
|
59
|
-
this.onlyRequiredInSamples = argValueToBoolean(raw.onlyRequiredInSamples);
|
|
60
|
-
this.showExtensions = RedocNormalizedOptions.normalizeShowExtensions(raw.showExtensions);
|
|
61
|
-
this.sideNavStyle = RedocNormalizedOptions.normalizeSideNavStyle(raw.sideNavStyle);
|
|
62
|
-
this.hideSingleRequestSampleTab = argValueToBoolean(raw.hideSingleRequestSampleTab);
|
|
63
|
-
this.menuToggle = argValueToBoolean(raw.menuToggle, true);
|
|
64
|
-
this.jsonSampleExpandLevel =
|
|
65
|
-
RedocNormalizedOptions.normalizeJsonSampleExpandLevel(raw.jsonSampleExpandLevel);
|
|
66
|
-
this.enumSkipQuotes = argValueToBoolean(raw.enumSkipQuotes);
|
|
67
|
-
this.hideSchemaTitles = argValueToBoolean(raw.hideSchemaTitles);
|
|
68
|
-
this.simpleOneOfTypeLabel = argValueToBoolean(raw.simpleOneOfTypeLabel);
|
|
69
|
-
this.payloadSampleIdx = RedocNormalizedOptions.normalizePayloadSampleIdx(raw.payloadSampleIdx);
|
|
70
|
-
this.expandSingleSchemaField = argValueToBoolean(raw.expandSingleSchemaField);
|
|
71
|
-
this.schemaExpansionLevel = argValueToExpandLevel(raw.schemaExpansionLevel);
|
|
72
|
-
this.showObjectSchemaExamples = argValueToBoolean(raw.showObjectSchemaExamples);
|
|
73
|
-
this.showSecuritySchemeType = argValueToBoolean(raw.showSecuritySchemeType);
|
|
74
|
-
this.hideSecuritySection = argValueToBoolean(raw.hideSecuritySection);
|
|
75
|
-
this.unstable_ignoreMimeParameters = argValueToBoolean(raw.unstable_ignoreMimeParameters);
|
|
76
|
-
this.expandDefaultServerVariables = argValueToBoolean(raw.expandDefaultServerVariables);
|
|
77
|
-
this.maxDisplayedEnumValues = argValueToNumber(raw.maxDisplayedEnumValues);
|
|
78
|
-
const ignoreNamedSchemas = (0, helpers_1.isArray)(raw.ignoreNamedSchemas)
|
|
79
|
-
? raw.ignoreNamedSchemas
|
|
80
|
-
: (_a = raw.ignoreNamedSchemas) === null || _a === void 0 ? void 0 : _a.split(",").map((s) => s.trim());
|
|
81
|
-
this.ignoreNamedSchemas = new Set(ignoreNamedSchemas);
|
|
82
|
-
this.hideSchemaPattern = argValueToBoolean(raw.hideSchemaPattern);
|
|
83
|
-
this.generatedPayloadSamplesMaxDepth =
|
|
84
|
-
RedocNormalizedOptions.normalizeGeneratedPayloadSamplesMaxDepth(raw.generatedPayloadSamplesMaxDepth);
|
|
85
|
-
this.nonce = raw.nonce;
|
|
86
|
-
this.hideFab = argValueToBoolean(raw.hideFab);
|
|
87
|
-
this.minCharacterLengthToInitSearch =
|
|
88
|
-
argValueToNumber(raw.minCharacterLengthToInitSearch) || 3;
|
|
89
|
-
this.showWebhookVerb = argValueToBoolean(raw.showWebhookVerb);
|
|
90
|
-
}
|
|
91
42
|
static normalizeExpandResponses(value) {
|
|
92
43
|
if (value === "all") {
|
|
93
44
|
return "all";
|
|
@@ -166,5 +117,54 @@ class RedocNormalizedOptions {
|
|
|
166
117
|
}
|
|
167
118
|
return 10;
|
|
168
119
|
}
|
|
120
|
+
constructor(raw, defaults = {}) {
|
|
121
|
+
var _a;
|
|
122
|
+
raw = { ...defaults, ...raw };
|
|
123
|
+
this.hideHostname = RedocNormalizedOptions.normalizeHideHostname(raw.hideHostname);
|
|
124
|
+
this.expandResponses = RedocNormalizedOptions.normalizeExpandResponses(raw.expandResponses);
|
|
125
|
+
this.requiredPropsFirst = argValueToBoolean(raw.requiredPropsFirst);
|
|
126
|
+
this.sortPropsAlphabetically = argValueToBoolean(raw.sortPropsAlphabetically);
|
|
127
|
+
this.sortEnumValuesAlphabetically = argValueToBoolean(raw.sortEnumValuesAlphabetically);
|
|
128
|
+
this.sortOperationsAlphabetically = argValueToBoolean(raw.sortOperationsAlphabetically);
|
|
129
|
+
this.sortTagsAlphabetically = argValueToBoolean(raw.sortTagsAlphabetically);
|
|
130
|
+
this.nativeScrollbars = argValueToBoolean(raw.nativeScrollbars);
|
|
131
|
+
this.pathInMiddlePanel = argValueToBoolean(raw.pathInMiddlePanel);
|
|
132
|
+
this.untrustedSpec = argValueToBoolean(raw.untrustedSpec);
|
|
133
|
+
this.hideDownloadButton = argValueToBoolean(raw.hideDownloadButton);
|
|
134
|
+
this.downloadFileName = raw.downloadFileName;
|
|
135
|
+
this.downloadDefinitionUrl = raw.downloadDefinitionUrl;
|
|
136
|
+
this.disableSearch = argValueToBoolean(raw.disableSearch);
|
|
137
|
+
this.onlyRequiredInSamples = argValueToBoolean(raw.onlyRequiredInSamples);
|
|
138
|
+
this.showExtensions = RedocNormalizedOptions.normalizeShowExtensions(raw.showExtensions);
|
|
139
|
+
this.sideNavStyle = RedocNormalizedOptions.normalizeSideNavStyle(raw.sideNavStyle);
|
|
140
|
+
this.hideSingleRequestSampleTab = argValueToBoolean(raw.hideSingleRequestSampleTab);
|
|
141
|
+
this.menuToggle = argValueToBoolean(raw.menuToggle, true);
|
|
142
|
+
this.jsonSampleExpandLevel =
|
|
143
|
+
RedocNormalizedOptions.normalizeJsonSampleExpandLevel(raw.jsonSampleExpandLevel);
|
|
144
|
+
this.enumSkipQuotes = argValueToBoolean(raw.enumSkipQuotes);
|
|
145
|
+
this.hideSchemaTitles = argValueToBoolean(raw.hideSchemaTitles);
|
|
146
|
+
this.simpleOneOfTypeLabel = argValueToBoolean(raw.simpleOneOfTypeLabel);
|
|
147
|
+
this.payloadSampleIdx = RedocNormalizedOptions.normalizePayloadSampleIdx(raw.payloadSampleIdx);
|
|
148
|
+
this.expandSingleSchemaField = argValueToBoolean(raw.expandSingleSchemaField);
|
|
149
|
+
this.schemaExpansionLevel = argValueToExpandLevel(raw.schemaExpansionLevel);
|
|
150
|
+
this.showObjectSchemaExamples = argValueToBoolean(raw.showObjectSchemaExamples);
|
|
151
|
+
this.showSecuritySchemeType = argValueToBoolean(raw.showSecuritySchemeType);
|
|
152
|
+
this.hideSecuritySection = argValueToBoolean(raw.hideSecuritySection);
|
|
153
|
+
this.unstable_ignoreMimeParameters = argValueToBoolean(raw.unstable_ignoreMimeParameters);
|
|
154
|
+
this.expandDefaultServerVariables = argValueToBoolean(raw.expandDefaultServerVariables);
|
|
155
|
+
this.maxDisplayedEnumValues = argValueToNumber(raw.maxDisplayedEnumValues);
|
|
156
|
+
const ignoreNamedSchemas = (0, helpers_1.isArray)(raw.ignoreNamedSchemas)
|
|
157
|
+
? raw.ignoreNamedSchemas
|
|
158
|
+
: (_a = raw.ignoreNamedSchemas) === null || _a === void 0 ? void 0 : _a.split(",").map((s) => s.trim());
|
|
159
|
+
this.ignoreNamedSchemas = new Set(ignoreNamedSchemas);
|
|
160
|
+
this.hideSchemaPattern = argValueToBoolean(raw.hideSchemaPattern);
|
|
161
|
+
this.generatedPayloadSamplesMaxDepth =
|
|
162
|
+
RedocNormalizedOptions.normalizeGeneratedPayloadSamplesMaxDepth(raw.generatedPayloadSamplesMaxDepth);
|
|
163
|
+
this.nonce = raw.nonce;
|
|
164
|
+
this.hideFab = argValueToBoolean(raw.hideFab);
|
|
165
|
+
this.minCharacterLengthToInitSearch =
|
|
166
|
+
argValueToNumber(raw.minCharacterLengthToInitSearch) || 3;
|
|
167
|
+
this.showWebhookVerb = argValueToBoolean(raw.showWebhookVerb);
|
|
168
|
+
}
|
|
169
169
|
}
|
|
170
170
|
exports.RedocNormalizedOptions = RedocNormalizedOptions;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./open-api";
|
|
2
|
-
export
|
|
2
|
+
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
@@ -38,7 +38,7 @@ export interface OpenAPIPaths {
|
|
|
38
38
|
export interface OpenAPIRef {
|
|
39
39
|
$ref: string;
|
|
40
40
|
}
|
|
41
|
-
export
|
|
41
|
+
export type Referenced<T> = OpenAPIRef | T;
|
|
42
42
|
export interface OpenAPIPath {
|
|
43
43
|
summary?: string;
|
|
44
44
|
description?: string;
|
|
@@ -182,8 +182,8 @@ export interface OpenAPIEncoding {
|
|
|
182
182
|
explode: boolean;
|
|
183
183
|
allowReserved: boolean;
|
|
184
184
|
}
|
|
185
|
-
export
|
|
186
|
-
export
|
|
185
|
+
export type OpenAPIParameterLocation = "query" | "header" | "path" | "cookie";
|
|
186
|
+
export type OpenAPIParameterStyle = "matrix" | "label" | "form" | "simple" | "spaceDelimited" | "pipeDelimited" | "deepObject";
|
|
187
187
|
export interface OpenAPIRequestBody {
|
|
188
188
|
description?: string;
|
|
189
189
|
required?: boolean;
|
|
@@ -216,7 +216,7 @@ export interface OpenAPIResponse extends Pick<OpenAPIRequestBody, "description"
|
|
|
216
216
|
export interface OpenAPILink {
|
|
217
217
|
$ref?: string;
|
|
218
218
|
}
|
|
219
|
-
export
|
|
219
|
+
export type OpenAPIHeader = Omit<OpenAPIParameter, "in" | "name">;
|
|
220
220
|
export interface OpenAPICallback {
|
|
221
221
|
[name: string]: OpenAPIPath;
|
|
222
222
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
2
2
|
export interface OpenAPISpec {
|
|
3
3
|
openapi: string;
|
|
4
4
|
info: OpenAPIInfo;
|
|
@@ -38,7 +38,7 @@ export interface OpenAPIPaths {
|
|
|
38
38
|
export interface OpenAPIRef {
|
|
39
39
|
$ref: string;
|
|
40
40
|
}
|
|
41
|
-
export
|
|
41
|
+
export type Referenced<T> = OpenAPIRef | T;
|
|
42
42
|
export interface OpenAPIPath {
|
|
43
43
|
summary?: string;
|
|
44
44
|
description?: string;
|
|
@@ -182,8 +182,8 @@ export interface OpenAPIEncoding {
|
|
|
182
182
|
explode: boolean;
|
|
183
183
|
allowReserved: boolean;
|
|
184
184
|
}
|
|
185
|
-
export
|
|
186
|
-
export
|
|
185
|
+
export type OpenAPIParameterLocation = "query" | "header" | "path" | "cookie";
|
|
186
|
+
export type OpenAPIParameterStyle = "matrix" | "label" | "form" | "simple" | "spaceDelimited" | "pipeDelimited" | "deepObject";
|
|
187
187
|
export interface OpenAPIRequestBody {
|
|
188
188
|
description?: string;
|
|
189
189
|
required?: boolean;
|
|
@@ -216,7 +216,7 @@ export interface OpenAPIResponse extends Pick<OpenAPIRequestBody, "description"
|
|
|
216
216
|
export interface OpenAPILink {
|
|
217
217
|
$ref?: string;
|
|
218
218
|
}
|
|
219
|
-
export
|
|
219
|
+
export type OpenAPIHeader = Omit<OpenAPIParameter, "in" | "name">;
|
|
220
220
|
export interface OpenAPICallback {
|
|
221
221
|
[name: string]: OpenAPIPath;
|
|
222
222
|
}
|
|
@@ -534,7 +534,7 @@ exports.setSecuritySchemePrefix = setSecuritySchemePrefix;
|
|
|
534
534
|
const shortenHTTPVerb = (verb) => ({
|
|
535
535
|
delete: "del",
|
|
536
536
|
options: "opts",
|
|
537
|
-
}[verb] || verb
|
|
537
|
+
})[verb] || verb;
|
|
538
538
|
exports.shortenHTTPVerb = shortenHTTPVerb;
|
|
539
539
|
function isRedocExtension(key) {
|
|
540
540
|
const redocExtensions = {
|
package/lib/types.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ export interface APIVersionOptions {
|
|
|
48
48
|
export interface LoadedContent {
|
|
49
49
|
loadedApi: ApiMetadata[];
|
|
50
50
|
}
|
|
51
|
-
export
|
|
51
|
+
export type ApiMetadata = ApiPageMetadata | InfoPageMetadata | TagPageMetadata;
|
|
52
52
|
export interface ApiMetadataBase {
|
|
53
53
|
sidebar?: string;
|
|
54
54
|
previous?: ApiNavLink;
|
|
@@ -100,7 +100,7 @@ export interface TagPageMetadata extends ApiMetadataBase {
|
|
|
100
100
|
tag: TagObject;
|
|
101
101
|
markdown?: string;
|
|
102
102
|
}
|
|
103
|
-
export
|
|
103
|
+
export type ApiInfo = InfoObject;
|
|
104
104
|
export interface ApiNavLink {
|
|
105
105
|
title: string;
|
|
106
106
|
permalink: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docusaurus-plugin-openapi-docs",
|
|
3
3
|
"description": "OpenAPI plugin for Docusaurus.",
|
|
4
|
-
"version": "3.0.0-beta.
|
|
4
|
+
"version": "3.0.0-beta.3",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -28,18 +28,19 @@
|
|
|
28
28
|
"watch": "tsc --watch"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@docusaurus/types": "^3.0.
|
|
31
|
+
"@docusaurus/types": "^3.0.1",
|
|
32
32
|
"@types/fs-extra": "^9.0.13",
|
|
33
33
|
"@types/json-pointer": "^1.0.31",
|
|
34
34
|
"@types/json-schema": "^7.0.9",
|
|
35
35
|
"@types/lodash": "^4.14.176",
|
|
36
|
-
"@types/mustache": "^4.1.2"
|
|
36
|
+
"@types/mustache": "^4.1.2",
|
|
37
|
+
"eslint-plugin-prettier": "^5.0.1"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
40
|
"@apidevtools/json-schema-ref-parser": "^10.1.0",
|
|
40
|
-
"@docusaurus/plugin-content-docs": "^3.0.
|
|
41
|
-
"@docusaurus/utils": "^3.0.
|
|
42
|
-
"@docusaurus/utils-validation": "^3.0.
|
|
41
|
+
"@docusaurus/plugin-content-docs": "^3.0.1",
|
|
42
|
+
"@docusaurus/utils": "^3.0.1",
|
|
43
|
+
"@docusaurus/utils-validation": "^3.0.1",
|
|
43
44
|
"@paloaltonetworks/openapi-to-postmanv2": "3.1.0-hotfix.1",
|
|
44
45
|
"@paloaltonetworks/postman-collection": "^4.1.0",
|
|
45
46
|
"@redocly/openapi-core": "^1.0.0-beta.125",
|
|
@@ -60,5 +61,5 @@
|
|
|
60
61
|
"engines": {
|
|
61
62
|
"node": ">=14"
|
|
62
63
|
},
|
|
63
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "4836267b8bcc01d496449e6d531663a00dfdb4ed"
|
|
64
65
|
}
|
package/src/index.ts
CHANGED
|
@@ -144,21 +144,23 @@ export default function pluginOpenAPIDocs(
|
|
|
144
144
|
docPath
|
|
145
145
|
);
|
|
146
146
|
|
|
147
|
-
|
|
147
|
+
let sidebarSliceTemplate = `import {SidebarConfig} from "@docusaurus/plugin-content-docs/src/sidebars/types";\n\n`;
|
|
148
|
+
sidebarSliceTemplate += `const sidebar: SidebarConfig = {{{slice}}};\n\n`;
|
|
149
|
+
sidebarSliceTemplate += `export default sidebar;`;
|
|
148
150
|
|
|
149
151
|
const view = render(sidebarSliceTemplate, {
|
|
150
|
-
slice: JSON.stringify(sidebarSlice),
|
|
152
|
+
slice: JSON.stringify(sidebarSlice, null, 2),
|
|
151
153
|
});
|
|
152
154
|
|
|
153
|
-
if (!fs.existsSync(`${outputDir}/sidebar.
|
|
155
|
+
if (!fs.existsSync(`${outputDir}/sidebar.ts`)) {
|
|
154
156
|
try {
|
|
155
|
-
fs.writeFileSync(`${outputDir}/sidebar.
|
|
157
|
+
fs.writeFileSync(`${outputDir}/sidebar.ts`, view, "utf8");
|
|
156
158
|
console.log(
|
|
157
|
-
chalk.green(`Successfully created "${outputDir}/sidebar.
|
|
159
|
+
chalk.green(`Successfully created "${outputDir}/sidebar.ts"`)
|
|
158
160
|
);
|
|
159
161
|
} catch (err) {
|
|
160
162
|
console.error(
|
|
161
|
-
chalk.red(`Failed to write "${outputDir}/sidebar.
|
|
163
|
+
chalk.red(`Failed to write "${outputDir}/sidebar.ts"`),
|
|
162
164
|
chalk.yellow(err)
|
|
163
165
|
);
|
|
164
166
|
}
|
|
@@ -261,8 +263,8 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
261
263
|
item.type === "api"
|
|
262
264
|
? apiPageGenerator(item)
|
|
263
265
|
: item.type === "info"
|
|
264
|
-
|
|
265
|
-
|
|
266
|
+
? infoPageGenerator(item)
|
|
267
|
+
: tagPageGenerator(item);
|
|
266
268
|
item.markdown = markdown;
|
|
267
269
|
if (item.type === "api") {
|
|
268
270
|
// opportunity to compress JSON
|
|
@@ -380,7 +382,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
380
382
|
cwd: path.resolve(apiDir),
|
|
381
383
|
deep: 1,
|
|
382
384
|
});
|
|
383
|
-
const sidebarFile = await Globby(["sidebar.
|
|
385
|
+
const sidebarFile = await Globby(["sidebar.ts"], {
|
|
384
386
|
cwd: path.resolve(apiDir),
|
|
385
387
|
deep: 1,
|
|
386
388
|
});
|
|
@@ -461,7 +463,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
461
463
|
cli
|
|
462
464
|
.command(`gen-api-docs`)
|
|
463
465
|
.description(
|
|
464
|
-
`Generates OpenAPI docs in MDX file format and sidebar.
|
|
466
|
+
`Generates OpenAPI docs in MDX file format and sidebar.ts (if enabled).`
|
|
465
467
|
)
|
|
466
468
|
.usage("<id>")
|
|
467
469
|
.arguments("<id>")
|
|
@@ -519,7 +521,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
519
521
|
cli
|
|
520
522
|
.command(`gen-api-docs:version`)
|
|
521
523
|
.description(
|
|
522
|
-
`Generates versioned OpenAPI docs in MDX file format, versions.js and sidebar.
|
|
524
|
+
`Generates versioned OpenAPI docs in MDX file format, versions.js and sidebar.ts (if enabled).`
|
|
523
525
|
)
|
|
524
526
|
.usage("<id:version>")
|
|
525
527
|
.arguments("<id:version>")
|
|
@@ -610,7 +612,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
610
612
|
cli
|
|
611
613
|
.command(`clean-api-docs`)
|
|
612
614
|
.description(
|
|
613
|
-
`Clears the generated OpenAPI docs MDX files and sidebar.
|
|
615
|
+
`Clears the generated OpenAPI docs MDX files and sidebar.ts (if enabled).`
|
|
614
616
|
)
|
|
615
617
|
.usage("<id>")
|
|
616
618
|
.arguments("<id>")
|
|
@@ -661,7 +663,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
661
663
|
cli
|
|
662
664
|
.command(`clean-api-docs:version`)
|
|
663
665
|
.description(
|
|
664
|
-
`Clears the versioned, generated OpenAPI docs MDX files, versions.json and sidebar.
|
|
666
|
+
`Clears the versioned, generated OpenAPI docs MDX files, versions.json and sidebar.ts (if enabled).`
|
|
665
667
|
)
|
|
666
668
|
.usage("<id:version>")
|
|
667
669
|
.arguments("<id:version>")
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import { guard, Props, render } from "./utils";
|
|
8
|
+
import { clean, guard, Props, render } from "./utils";
|
|
9
9
|
|
|
10
10
|
function createAdmonition({ children }: Props) {
|
|
11
11
|
return `:::caution deprecated\n\n${render(children)}\n\n:::`;
|
|
@@ -23,7 +23,7 @@ export function createDeprecationNotice({
|
|
|
23
23
|
return guard(deprecated, () =>
|
|
24
24
|
createAdmonition({
|
|
25
25
|
children:
|
|
26
|
-
description ??
|
|
26
|
+
clean(description) ??
|
|
27
27
|
"This endpoint has been deprecated and may be replaced or removed in future versions of the API.",
|
|
28
28
|
})
|
|
29
29
|
);
|
|
@@ -5,16 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { clean } from "./utils";
|
|
9
9
|
|
|
10
10
|
export function createDescription(description: string | undefined) {
|
|
11
|
-
|
|
12
|
-
return "";
|
|
13
|
-
}
|
|
14
|
-
return `\n\n${description
|
|
15
|
-
.replace(lessThan, "<")
|
|
16
|
-
.replace(greaterThan, ">")
|
|
17
|
-
.replace(codeFence, function (match) {
|
|
18
|
-
return match.replace(/\\>/g, ">");
|
|
19
|
-
})}\n\n`;
|
|
11
|
+
return `\n\n${clean(description)}\n\n`;
|
|
20
12
|
}
|
|
@@ -5,15 +5,13 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { clean, create } from "./utils";
|
|
9
9
|
|
|
10
10
|
export function createHeading(heading: string) {
|
|
11
11
|
return [
|
|
12
12
|
create("h1", {
|
|
13
13
|
className: "openapi__heading",
|
|
14
|
-
children:
|
|
15
|
-
.replace(lessThan, "<")
|
|
16
|
-
.replace(greaterThan, ">")}`,
|
|
14
|
+
children: clean(heading),
|
|
17
15
|
}),
|
|
18
16
|
`\n\n`,
|
|
19
17
|
];
|
|
@@ -90,7 +90,7 @@ export function createRequestSchema({ title, body, ...rest }: Props) {
|
|
|
90
90
|
}),
|
|
91
91
|
create("ul", {
|
|
92
92
|
style: { marginLeft: "1rem" },
|
|
93
|
-
children: createNodes(firstBody),
|
|
93
|
+
children: createNodes(firstBody, "request"),
|
|
94
94
|
}),
|
|
95
95
|
],
|
|
96
96
|
}),
|
|
@@ -161,7 +161,7 @@ export function createRequestSchema({ title, body, ...rest }: Props) {
|
|
|
161
161
|
}),
|
|
162
162
|
create("ul", {
|
|
163
163
|
style: { marginLeft: "1rem" },
|
|
164
|
-
children: createNodes(firstBody),
|
|
164
|
+
children: createNodes(firstBody, "request"),
|
|
165
165
|
}),
|
|
166
166
|
],
|
|
167
167
|
}),
|
|
@@ -11,7 +11,7 @@ import { SchemaObject } from "../openapi/types";
|
|
|
11
11
|
import { createNodes } from "./createSchema";
|
|
12
12
|
|
|
13
13
|
describe("createNodes", () => {
|
|
14
|
-
it("should create readable MODs for oneOf primitive properties", () => {
|
|
14
|
+
it("should create readable MODs for oneOf primitive properties", async () => {
|
|
15
15
|
const schema: SchemaObject = {
|
|
16
16
|
type: "object",
|
|
17
17
|
properties: {
|
|
@@ -48,8 +48,10 @@ describe("createNodes", () => {
|
|
|
48
48
|
},
|
|
49
49
|
};
|
|
50
50
|
expect(
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
await Promise.all(
|
|
52
|
+
createNodes(schema, "request").map(
|
|
53
|
+
async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
54
|
+
)
|
|
53
55
|
)
|
|
54
56
|
).toMatchSnapshot();
|
|
55
57
|
});
|
|
@@ -20,6 +20,8 @@ import { create, guard } from "./utils";
|
|
|
20
20
|
|
|
21
21
|
const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
|
|
22
22
|
|
|
23
|
+
let SCHEMA_TYPE: "request" | "response";
|
|
24
|
+
|
|
23
25
|
/**
|
|
24
26
|
* Returns a merged representation of allOf array of schemas.
|
|
25
27
|
*/
|
|
@@ -29,6 +31,9 @@ export function mergeAllOf(allOf: SchemaObject[]) {
|
|
|
29
31
|
readOnly: function () {
|
|
30
32
|
return true;
|
|
31
33
|
},
|
|
34
|
+
writeOnly: function () {
|
|
35
|
+
return true;
|
|
36
|
+
},
|
|
32
37
|
example: function () {
|
|
33
38
|
return true;
|
|
34
39
|
},
|
|
@@ -74,7 +79,7 @@ function createAnyOneOf(schema: SchemaObject): any {
|
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
if (anyOneSchema.allOf !== undefined) {
|
|
77
|
-
anyOneChildren.push(createNodes(anyOneSchema));
|
|
82
|
+
anyOneChildren.push(createNodes(anyOneSchema, SCHEMA_TYPE));
|
|
78
83
|
delete anyOneSchema.allOf;
|
|
79
84
|
}
|
|
80
85
|
|
|
@@ -89,7 +94,7 @@ function createAnyOneOf(schema: SchemaObject): any {
|
|
|
89
94
|
anyOneSchema.type === "integer" ||
|
|
90
95
|
anyOneSchema.type === "boolean"
|
|
91
96
|
) {
|
|
92
|
-
anyOneChildren.push(createNodes(anyOneSchema));
|
|
97
|
+
anyOneChildren.push(createNodes(anyOneSchema, SCHEMA_TYPE));
|
|
93
98
|
}
|
|
94
99
|
if (anyOneChildren.length) {
|
|
95
100
|
if (schema.type === "array") {
|
|
@@ -304,7 +309,7 @@ function createItems(schema: SchemaObject) {
|
|
|
304
309
|
) {
|
|
305
310
|
return [
|
|
306
311
|
createOpeningArrayBracket(),
|
|
307
|
-
createNodes(schema.items),
|
|
312
|
+
createNodes(schema.items, SCHEMA_TYPE),
|
|
308
313
|
createClosingArrayBracket(),
|
|
309
314
|
].flat();
|
|
310
315
|
}
|
|
@@ -411,7 +416,7 @@ function createDetailsNode(
|
|
|
411
416
|
children: createDescription(description),
|
|
412
417
|
})
|
|
413
418
|
),
|
|
414
|
-
createNodes(schema),
|
|
419
|
+
createNodes(schema, SCHEMA_TYPE),
|
|
415
420
|
],
|
|
416
421
|
}),
|
|
417
422
|
],
|
|
@@ -565,7 +570,7 @@ function createPropertyDiscriminator(
|
|
|
565
570
|
// className: "openapi-tabs__discriminator-item",
|
|
566
571
|
label: label,
|
|
567
572
|
value: `${index}-item-discriminator`,
|
|
568
|
-
children: [createNodes(discriminator?.mapping[key])],
|
|
573
|
+
children: [createNodes(discriminator?.mapping[key], SCHEMA_TYPE)],
|
|
569
574
|
});
|
|
570
575
|
}),
|
|
571
576
|
}),
|
|
@@ -664,8 +669,16 @@ function createEdges({
|
|
|
664
669
|
);
|
|
665
670
|
}
|
|
666
671
|
|
|
667
|
-
if (
|
|
668
|
-
|
|
672
|
+
if (SCHEMA_TYPE === "request") {
|
|
673
|
+
if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
|
|
674
|
+
return undefined;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
if (SCHEMA_TYPE === "response") {
|
|
679
|
+
if (mergedSchemas.writeOnly && mergedSchemas.writeOnly === true) {
|
|
680
|
+
return undefined;
|
|
681
|
+
}
|
|
669
682
|
}
|
|
670
683
|
|
|
671
684
|
return create("SchemaItem", {
|
|
@@ -719,8 +732,16 @@ function createEdges({
|
|
|
719
732
|
);
|
|
720
733
|
}
|
|
721
734
|
|
|
722
|
-
if (
|
|
723
|
-
|
|
735
|
+
if (SCHEMA_TYPE === "request") {
|
|
736
|
+
if (schema.readOnly && schema.readOnly === true) {
|
|
737
|
+
return undefined;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
if (SCHEMA_TYPE === "response") {
|
|
742
|
+
if (schema.writeOnly && schema.writeOnly === true) {
|
|
743
|
+
return undefined;
|
|
744
|
+
}
|
|
724
745
|
}
|
|
725
746
|
|
|
726
747
|
// primitives and array of non-objects
|
|
@@ -737,7 +758,11 @@ function createEdges({
|
|
|
737
758
|
/**
|
|
738
759
|
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
739
760
|
*/
|
|
740
|
-
export function createNodes(
|
|
761
|
+
export function createNodes(
|
|
762
|
+
schema: SchemaObject,
|
|
763
|
+
schemaType: "request" | "response"
|
|
764
|
+
): any {
|
|
765
|
+
SCHEMA_TYPE = schemaType;
|
|
741
766
|
const nodes = [];
|
|
742
767
|
// if (schema.discriminator !== undefined) {
|
|
743
768
|
// return createDiscriminator(schema);
|
package/src/markdown/index.ts
CHANGED
|
@@ -29,7 +29,7 @@ import { createStatusCodes } from "./createStatusCodes";
|
|
|
29
29
|
import { createTermsOfService } from "./createTermsOfService";
|
|
30
30
|
import { createVendorExtensions } from "./createVendorExtensions";
|
|
31
31
|
import { createVersionBadge } from "./createVersionBadge";
|
|
32
|
-
import {
|
|
32
|
+
import { render } from "./utils";
|
|
33
33
|
|
|
34
34
|
interface Props {
|
|
35
35
|
title: string;
|
|
@@ -69,7 +69,7 @@ export function createApiPageMD({
|
|
|
69
69
|
`import SchemaItem from "@theme/SchemaItem";\n`,
|
|
70
70
|
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
71
71
|
`import TabItem from "@theme/TabItem";\n\n`,
|
|
72
|
-
createHeading(title
|
|
72
|
+
createHeading(title),
|
|
73
73
|
createMethodEndpoint(method, path),
|
|
74
74
|
infoPath && createAuthorization(infoPath),
|
|
75
75
|
frontMatter.show_extensions && createVendorExtensions(extensions),
|
|
@@ -110,7 +110,7 @@ export function createInfoPageMD({
|
|
|
110
110
|
|
|
111
111
|
createVersionBadge(version),
|
|
112
112
|
createDownload(downloadUrl),
|
|
113
|
-
createHeading(title
|
|
113
|
+
createHeading(title),
|
|
114
114
|
createLogo(logo, darkLogo),
|
|
115
115
|
createDescription(description),
|
|
116
116
|
createAuthentication(securitySchemes as unknown as SecuritySchemeObject),
|
package/src/markdown/utils.ts
CHANGED
|
@@ -50,3 +50,25 @@ export const lessThan =
|
|
|
50
50
|
export const greaterThan =
|
|
51
51
|
/(?<!(button|code|details|summary|hr|br|span|strong|small|table|thead|tbody|td|tr|th|h1|h2|h3|h4|h5|h6|title|p|em|b|i|u|strike|bold|a|li|ol|ul|img|svg|div|center|\/|\s|"|'))>/gu;
|
|
52
52
|
export const codeFence = /`{1,3}[\s\S]*?`{1,3}/g;
|
|
53
|
+
export const curlyBrackets = /\{(.*)}/g;
|
|
54
|
+
export const codeBlock = /^(```.*[\s\S]*?```)$/gm;
|
|
55
|
+
|
|
56
|
+
export function clean(value: string | undefined): string {
|
|
57
|
+
if (!value) {
|
|
58
|
+
return "";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let sections = value.split(codeBlock);
|
|
62
|
+
for (let sectionIndex in sections) {
|
|
63
|
+
if (!sections[sectionIndex].startsWith("```")) {
|
|
64
|
+
sections[sectionIndex] = sections[sectionIndex]
|
|
65
|
+
.replace(lessThan, "<")
|
|
66
|
+
.replace(greaterThan, ">")
|
|
67
|
+
.replace(codeFence, function (match) {
|
|
68
|
+
return match.replace(/\\>/g, ">");
|
|
69
|
+
})
|
|
70
|
+
.replace(curlyBrackets, "\\{$1\\}");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return sections.join("");
|
|
74
|
+
}
|
package/src/openapi/openapi.ts
CHANGED
|
@@ -469,8 +469,7 @@ function bindCollectionToApiItems(
|
|
|
469
469
|
const method = item.request.method.toLowerCase();
|
|
470
470
|
const path = item.request.url
|
|
471
471
|
.getPath({ unresolved: true }) // unresolved returns "/:variableName" instead of "/<type>"
|
|
472
|
-
.replace(
|
|
473
|
-
|
|
472
|
+
.replace(/(?<![a-z0-9-_]+):([a-z0-9-_]+)/gi, "{$1}"); // replace "/:variableName" with "/{variableName}"
|
|
474
473
|
const apiItem = items.find((item) => {
|
|
475
474
|
if (item.type === "info" || item.type === "tag") {
|
|
476
475
|
return false;
|
|
@@ -326,8 +326,8 @@ export class OpenAPIParser {
|
|
|
326
326
|
const receiverItems = isBoolean(receiver.items)
|
|
327
327
|
? { items: receiver.items }
|
|
328
328
|
: receiver.items
|
|
329
|
-
|
|
330
|
-
|
|
329
|
+
? (Object.assign({}, receiver.items) as OpenAPISchema)
|
|
330
|
+
: {};
|
|
331
331
|
const subSchemaItems = isBoolean(items)
|
|
332
332
|
? { items }
|
|
333
333
|
: (Object.assign({}, items) as OpenAPISchema);
|