docusaurus-plugin-openapi-docs 1.3.0 → 1.3.2
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 +3 -2
- package/lib/markdown/createDescription.js +4 -1
- package/lib/markdown/index.js +3 -4
- package/lib/markdown/utils.d.ts +2 -0
- package/lib/markdown/utils.js +4 -1
- package/lib/openapi/createResponseExample.js +3 -5
- package/lib/openapi/openapi.js +0 -1
- package/package.json +2 -2
- package/src/index.ts +3 -2
- package/src/markdown/createDescription.ts +5 -1
- package/src/markdown/index.ts +4 -6
- package/src/markdown/utils.ts +6 -0
- package/src/openapi/createResponseExample.ts +3 -5
- package/src/openapi/openapi.ts +0 -6
package/lib/index.js
CHANGED
|
@@ -26,7 +26,8 @@ exports.isURL = isURL;
|
|
|
26
26
|
function getDocsPluginConfig(presetsPlugins, pluginId) {
|
|
27
27
|
// eslint-disable-next-line array-callback-return
|
|
28
28
|
const filteredConfig = presetsPlugins.filter((data) => {
|
|
29
|
-
|
|
29
|
+
// Search presets
|
|
30
|
+
if (data[0].endsWith(pluginId)) {
|
|
30
31
|
return data[1];
|
|
31
32
|
}
|
|
32
33
|
// Search plugin-content-docs instances
|
|
@@ -39,7 +40,7 @@ function getDocsPluginConfig(presetsPlugins, pluginId) {
|
|
|
39
40
|
})[0];
|
|
40
41
|
if (filteredConfig) {
|
|
41
42
|
// Search presets, e.g. "classic"
|
|
42
|
-
if (filteredConfig[0]
|
|
43
|
+
if (filteredConfig[0].endsWith(pluginId)) {
|
|
43
44
|
return filteredConfig[1].docs;
|
|
44
45
|
}
|
|
45
46
|
// Search plugin-content-docs instances
|
|
@@ -7,10 +7,13 @@
|
|
|
7
7
|
* ========================================================================== */
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createDescription = void 0;
|
|
10
|
+
const utils_1 = require("./utils");
|
|
10
11
|
function createDescription(description) {
|
|
11
12
|
if (!description) {
|
|
12
13
|
return "";
|
|
13
14
|
}
|
|
14
|
-
return `\n\n${description
|
|
15
|
+
return `\n\n${description
|
|
16
|
+
.replace(utils_1.lessThan, "<")
|
|
17
|
+
.replace(utils_1.greaterThan, ">")}\n\n`;
|
|
15
18
|
}
|
|
16
19
|
exports.createDescription = createDescription;
|
package/lib/markdown/index.js
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
* ========================================================================== */
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createTagPageMD = exports.createInfoPageMD = exports.createApiPageMD = void 0;
|
|
10
|
-
const lodash_1 = require("lodash");
|
|
11
10
|
const createAuthentication_1 = require("./createAuthentication");
|
|
12
11
|
const createContactInfo_1 = require("./createContactInfo");
|
|
13
12
|
const createDeprecationNotice_1 = require("./createDeprecationNotice");
|
|
@@ -30,9 +29,9 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
|
|
|
30
29
|
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
31
30
|
`import DiscriminatorTabs from "@theme/DiscriminatorTabs";\n`,
|
|
32
31
|
`import TabItem from "@theme/TabItem";\n\n`,
|
|
33
|
-
`## ${(
|
|
32
|
+
`## ${title.replace(utils_1.lessThan, "<").replace(utils_1.greaterThan, ">")}\n\n`,
|
|
34
33
|
(0, createDeprecationNotice_1.createDeprecationNotice)({ deprecated, description: deprecatedDescription }),
|
|
35
|
-
(0, createDescription_1.createDescription)(
|
|
34
|
+
(0, createDescription_1.createDescription)(description),
|
|
36
35
|
(0, createParamsDetails_1.createParamsDetails)({ parameters, type: "path" }),
|
|
37
36
|
(0, createParamsDetails_1.createParamsDetails)({ parameters, type: "query" }),
|
|
38
37
|
(0, createParamsDetails_1.createParamsDetails)({ parameters, type: "header" }),
|
|
@@ -51,7 +50,7 @@ function createInfoPageMD({ info: { title, version, description, contact, licens
|
|
|
51
50
|
`import Tabs from "@theme/Tabs";\n`,
|
|
52
51
|
`import TabItem from "@theme/TabItem";\n\n`,
|
|
53
52
|
(0, createVersionBadge_1.createVersionBadge)(version),
|
|
54
|
-
`# ${(
|
|
53
|
+
`# ${title.replace(utils_1.lessThan, "<").replace(utils_1.greaterThan, ">")}\n\n`,
|
|
55
54
|
(0, createLogo_1.createLogo)(logo, darkLogo),
|
|
56
55
|
(0, createDescription_1.createDescription)(description),
|
|
57
56
|
(0, createAuthentication_1.createAuthentication)(securitySchemes),
|
package/lib/markdown/utils.d.ts
CHANGED
|
@@ -5,3 +5,5 @@ export declare type Props = Record<string, any> & {
|
|
|
5
5
|
export declare function create(tag: string, props: Props): string;
|
|
6
6
|
export declare function guard<T>(value: T | undefined, cb: (value: T) => Children): string;
|
|
7
7
|
export declare function render(children: Children): string;
|
|
8
|
+
export declare const lessThan: RegExp;
|
|
9
|
+
export declare const greaterThan: RegExp;
|
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.render = exports.guard = exports.create = void 0;
|
|
9
|
+
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 = "";
|
|
@@ -34,3 +34,6 @@ function render(children) {
|
|
|
34
34
|
return children !== null && children !== void 0 ? children : "";
|
|
35
35
|
}
|
|
36
36
|
exports.render = render;
|
|
37
|
+
// Regex to selectively URL-encode '>' and '<' chars
|
|
38
|
+
exports.lessThan = /<(?!(button|\s?\/button|details|\s?\/details|summary|\s?\/summary|hr|\s?\/hr|br|\s?\/br|span|\s?\/span|strong|\s?\/strong|small|\s?\/small|table|\s?\/table|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|a|\s?\/a|li|\s?\/li|ol|\s?\/ol|ul|\s?\/ul|img|\s?\/img|div|\s?\/div|center|\s?\/center))/giu;
|
|
39
|
+
exports.greaterThan = /(?<!(button|details|summary|hr|br|span|strong|small|table|td|tr|th|h1|h2|h3|h4|h5|h6|title|p|em|b|i|u|strike|a|tag|li|ol|ul|img|div|center|\/|\s|"|'))>/giu;
|
|
@@ -60,12 +60,10 @@ function sampleResponseFromProp(name, prop, obj) {
|
|
|
60
60
|
}
|
|
61
61
|
const sampleResponseFromSchema = (schema = {}) => {
|
|
62
62
|
try {
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
64
63
|
let { type, example, allOf, oneOf, anyOf, properties, items } = schema;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// }
|
|
64
|
+
if (example !== undefined) {
|
|
65
|
+
return example;
|
|
66
|
+
}
|
|
69
67
|
if (allOf) {
|
|
70
68
|
const { mergedSchemas } = (0, createResponseSchema_1.mergeAllOf)(allOf);
|
|
71
69
|
if (mergedSchemas.properties) {
|
package/lib/openapi/openapi.js
CHANGED
|
@@ -213,7 +213,6 @@ async function readOpenapiFiles(openapiPath, options) {
|
|
|
213
213
|
if (!(0, index_1.isURL)(openapiPath)) {
|
|
214
214
|
const stat = await fs_extra_1.default.lstat(openapiPath);
|
|
215
215
|
if (stat.isDirectory()) {
|
|
216
|
-
console.warn(chalk_1.default.yellow("WARNING: Loading a directory of OpenAPI definitions is experimental and subject to unannounced breaking changes."));
|
|
217
216
|
// TODO: Add config for inlcude/ignore
|
|
218
217
|
const allFiles = await (0, utils_1.Globby)(["**/*.{json,yaml,yml}"], {
|
|
219
218
|
cwd: openapiPath,
|
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": "1.3.
|
|
4
|
+
"version": "1.3.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"engines": {
|
|
69
69
|
"node": ">=14"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "761a89172da04573369441cf7342f6c643bc3ecd"
|
|
72
72
|
}
|
package/src/index.ts
CHANGED
|
@@ -29,7 +29,8 @@ export function getDocsPluginConfig(
|
|
|
29
29
|
): Object | undefined {
|
|
30
30
|
// eslint-disable-next-line array-callback-return
|
|
31
31
|
const filteredConfig = presetsPlugins.filter((data) => {
|
|
32
|
-
|
|
32
|
+
// Search presets
|
|
33
|
+
if (data[0].endsWith(pluginId)) {
|
|
33
34
|
return data[1];
|
|
34
35
|
}
|
|
35
36
|
|
|
@@ -43,7 +44,7 @@ export function getDocsPluginConfig(
|
|
|
43
44
|
})[0];
|
|
44
45
|
if (filteredConfig) {
|
|
45
46
|
// Search presets, e.g. "classic"
|
|
46
|
-
if (filteredConfig[0]
|
|
47
|
+
if (filteredConfig[0].endsWith(pluginId)) {
|
|
47
48
|
return filteredConfig[1].docs;
|
|
48
49
|
}
|
|
49
50
|
|
|
@@ -5,9 +5,13 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
+
import { greaterThan, lessThan } from "./utils";
|
|
9
|
+
|
|
8
10
|
export function createDescription(description: string | undefined) {
|
|
9
11
|
if (!description) {
|
|
10
12
|
return "";
|
|
11
13
|
}
|
|
12
|
-
return `\n\n${description
|
|
14
|
+
return `\n\n${description
|
|
15
|
+
.replace(lessThan, "<")
|
|
16
|
+
.replace(greaterThan, ">")}\n\n`;
|
|
13
17
|
}
|
package/src/markdown/index.ts
CHANGED
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import { escape } from "lodash";
|
|
9
|
-
|
|
10
8
|
import {
|
|
11
9
|
ContactObject,
|
|
12
10
|
LicenseObject,
|
|
@@ -25,7 +23,7 @@ import { createRequestBodyDetails } from "./createRequestBodyDetails";
|
|
|
25
23
|
import { createStatusCodes } from "./createStatusCodes";
|
|
26
24
|
import { createTermsOfService } from "./createTermsOfService";
|
|
27
25
|
import { createVersionBadge } from "./createVersionBadge";
|
|
28
|
-
import { render } from "./utils";
|
|
26
|
+
import { greaterThan, lessThan, render } from "./utils";
|
|
29
27
|
|
|
30
28
|
interface Props {
|
|
31
29
|
title: string;
|
|
@@ -58,9 +56,9 @@ export function createApiPageMD({
|
|
|
58
56
|
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
59
57
|
`import DiscriminatorTabs from "@theme/DiscriminatorTabs";\n`,
|
|
60
58
|
`import TabItem from "@theme/TabItem";\n\n`,
|
|
61
|
-
`## ${
|
|
59
|
+
`## ${title.replace(lessThan, "<").replace(greaterThan, ">")}\n\n`,
|
|
62
60
|
createDeprecationNotice({ deprecated, description: deprecatedDescription }),
|
|
63
|
-
createDescription(
|
|
61
|
+
createDescription(description),
|
|
64
62
|
createParamsDetails({ parameters, type: "path" }),
|
|
65
63
|
createParamsDetails({ parameters, type: "query" }),
|
|
66
64
|
createParamsDetails({ parameters, type: "header" }),
|
|
@@ -92,7 +90,7 @@ export function createInfoPageMD({
|
|
|
92
90
|
`import TabItem from "@theme/TabItem";\n\n`,
|
|
93
91
|
|
|
94
92
|
createVersionBadge(version),
|
|
95
|
-
`# ${
|
|
93
|
+
`# ${title.replace(lessThan, "<").replace(greaterThan, ">")}\n\n`,
|
|
96
94
|
createLogo(logo, darkLogo),
|
|
97
95
|
createDescription(description),
|
|
98
96
|
createAuthentication(securitySchemes as unknown as SecuritySchemeObject),
|
package/src/markdown/utils.ts
CHANGED
|
@@ -40,3 +40,9 @@ export function render(children: Children): string {
|
|
|
40
40
|
}
|
|
41
41
|
return children ?? "";
|
|
42
42
|
}
|
|
43
|
+
|
|
44
|
+
// Regex to selectively URL-encode '>' and '<' chars
|
|
45
|
+
export const lessThan =
|
|
46
|
+
/<(?!(button|\s?\/button|details|\s?\/details|summary|\s?\/summary|hr|\s?\/hr|br|\s?\/br|span|\s?\/span|strong|\s?\/strong|small|\s?\/small|table|\s?\/table|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|a|\s?\/a|li|\s?\/li|ol|\s?\/ol|ul|\s?\/ul|img|\s?\/img|div|\s?\/div|center|\s?\/center))/giu;
|
|
47
|
+
export const greaterThan =
|
|
48
|
+
/(?<!(button|details|summary|hr|br|span|strong|small|table|td|tr|th|h1|h2|h3|h4|h5|h6|title|p|em|b|i|u|strike|a|tag|li|ol|ul|img|div|center|\/|\s|"|'))>/giu;
|
|
@@ -77,13 +77,11 @@ function sampleResponseFromProp(name: string, prop: any, obj: any): any {
|
|
|
77
77
|
|
|
78
78
|
export const sampleResponseFromSchema = (schema: SchemaObject = {}): any => {
|
|
79
79
|
try {
|
|
80
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
81
80
|
let { type, example, allOf, oneOf, anyOf, properties, items } = schema;
|
|
82
81
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// }
|
|
82
|
+
if (example !== undefined) {
|
|
83
|
+
return example;
|
|
84
|
+
}
|
|
87
85
|
|
|
88
86
|
if (allOf) {
|
|
89
87
|
const { mergedSchemas }: { mergedSchemas: SchemaObject } =
|
package/src/openapi/openapi.ts
CHANGED
|
@@ -280,12 +280,6 @@ export async function readOpenapiFiles(
|
|
|
280
280
|
if (!isURL(openapiPath)) {
|
|
281
281
|
const stat = await fs.lstat(openapiPath);
|
|
282
282
|
if (stat.isDirectory()) {
|
|
283
|
-
console.warn(
|
|
284
|
-
chalk.yellow(
|
|
285
|
-
"WARNING: Loading a directory of OpenAPI definitions is experimental and subject to unannounced breaking changes."
|
|
286
|
-
)
|
|
287
|
-
);
|
|
288
|
-
|
|
289
283
|
// TODO: Add config for inlcude/ignore
|
|
290
284
|
const allFiles = await Globby(["**/*.{json,yaml,yml}"], {
|
|
291
285
|
cwd: openapiPath,
|