docusaurus-plugin-openapi-docs 1.2.2 → 1.3.1
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/markdown/createDescription.js +4 -1
- package/lib/markdown/createRequestSchema.js +1 -1
- package/lib/markdown/createResponseSchema.js +1 -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 +11 -1
- package/package.json +2 -2
- package/src/markdown/createDescription.ts +5 -1
- package/src/markdown/createRequestSchema.ts +1 -1
- package/src/markdown/createResponseSchema.ts +1 -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 +15 -6
|
@@ -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;
|
|
@@ -566,7 +566,7 @@ function createRequestSchema({ title, body, ...rest }) {
|
|
|
566
566
|
const mimeTypes = Object.keys(body.content);
|
|
567
567
|
if (mimeTypes && mimeTypes.length > 1) {
|
|
568
568
|
return (0, utils_1.create)("MimeTabs", {
|
|
569
|
-
|
|
569
|
+
schemaType: "request",
|
|
570
570
|
children: mimeTypes.map((mimeType) => {
|
|
571
571
|
const firstBody = body.content[mimeType].schema;
|
|
572
572
|
if (firstBody === undefined) {
|
|
@@ -566,7 +566,7 @@ function createResponseSchema({ title, body, ...rest }) {
|
|
|
566
566
|
const mimeTypes = Object.keys(body.content);
|
|
567
567
|
if (mimeTypes && mimeTypes.length) {
|
|
568
568
|
return (0, utils_1.create)("MimeTabs", {
|
|
569
|
-
|
|
569
|
+
schemaType: "response",
|
|
570
570
|
children: mimeTypes.map((mimeType) => {
|
|
571
571
|
const responseExamples = body.content[mimeType].examples;
|
|
572
572
|
const responseExample = body.content[mimeType].example;
|
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
|
@@ -18,6 +18,7 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
18
18
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
19
19
|
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
20
20
|
const kebabCase_1 = __importDefault(require("lodash/kebabCase"));
|
|
21
|
+
const unionBy_1 = __importDefault(require("lodash/unionBy"));
|
|
21
22
|
const index_1 = require("../index");
|
|
22
23
|
const createRequestExample_1 = require("./createRequestExample");
|
|
23
24
|
const loadAndResolveSpec_1 = require("./utils/loadAndResolveSpec");
|
|
@@ -151,6 +152,16 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
151
152
|
}
|
|
152
153
|
// TODO: Don't include summary temporarilly
|
|
153
154
|
const { summary, ...defaults } = operationObject;
|
|
155
|
+
// Merge common parameters with operation parameters
|
|
156
|
+
// Operation params take precendence over common params
|
|
157
|
+
if (parameters !== undefined) {
|
|
158
|
+
if (operationObject.parameters !== undefined) {
|
|
159
|
+
defaults.parameters = (0, unionBy_1.default)(operationObject.parameters, parameters, "name");
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
defaults.parameters = parameters;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
154
165
|
const apiPage = {
|
|
155
166
|
type: "api",
|
|
156
167
|
id: baseId,
|
|
@@ -202,7 +213,6 @@ async function readOpenapiFiles(openapiPath, options) {
|
|
|
202
213
|
if (!(0, index_1.isURL)(openapiPath)) {
|
|
203
214
|
const stat = await fs_extra_1.default.lstat(openapiPath);
|
|
204
215
|
if (stat.isDirectory()) {
|
|
205
|
-
console.warn(chalk_1.default.yellow("WARNING: Loading a directory of OpenAPI definitions is experimental and subject to unannounced breaking changes."));
|
|
206
216
|
// TODO: Add config for inlcude/ignore
|
|
207
217
|
const allFiles = await (0, utils_1.Globby)(["**/*.{json,yaml,yml}"], {
|
|
208
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.
|
|
4
|
+
"version": "1.3.1",
|
|
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": "5f41e8dc4981409902ae96a7d127a2ae7eb9a47d"
|
|
72
72
|
}
|
|
@@ -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
|
}
|
|
@@ -721,7 +721,7 @@ export function createRequestSchema({ title, body, ...rest }: Props) {
|
|
|
721
721
|
|
|
722
722
|
if (mimeTypes && mimeTypes.length > 1) {
|
|
723
723
|
return create("MimeTabs", {
|
|
724
|
-
|
|
724
|
+
schemaType: "request",
|
|
725
725
|
children: mimeTypes.map((mimeType) => {
|
|
726
726
|
const firstBody = body.content![mimeType].schema;
|
|
727
727
|
if (firstBody === undefined) {
|
|
@@ -721,7 +721,7 @@ export function createResponseSchema({ title, body, ...rest }: Props) {
|
|
|
721
721
|
|
|
722
722
|
if (mimeTypes && mimeTypes.length) {
|
|
723
723
|
return create("MimeTabs", {
|
|
724
|
-
|
|
724
|
+
schemaType: "response",
|
|
725
725
|
children: mimeTypes.map((mimeType: any) => {
|
|
726
726
|
const responseExamples = body.content![mimeType].examples;
|
|
727
727
|
const responseExample = body.content![mimeType].example;
|
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
|
@@ -15,6 +15,7 @@ import chalk from "chalk";
|
|
|
15
15
|
import fs from "fs-extra";
|
|
16
16
|
import cloneDeep from "lodash/cloneDeep";
|
|
17
17
|
import kebabCase from "lodash/kebabCase";
|
|
18
|
+
import unionBy from "lodash/unionBy";
|
|
18
19
|
|
|
19
20
|
import { isURL } from "../index";
|
|
20
21
|
import {
|
|
@@ -193,6 +194,20 @@ function createItems(
|
|
|
193
194
|
// TODO: Don't include summary temporarilly
|
|
194
195
|
const { summary, ...defaults } = operationObject;
|
|
195
196
|
|
|
197
|
+
// Merge common parameters with operation parameters
|
|
198
|
+
// Operation params take precendence over common params
|
|
199
|
+
if (parameters !== undefined) {
|
|
200
|
+
if (operationObject.parameters !== undefined) {
|
|
201
|
+
defaults.parameters = unionBy(
|
|
202
|
+
operationObject.parameters,
|
|
203
|
+
parameters,
|
|
204
|
+
"name"
|
|
205
|
+
);
|
|
206
|
+
} else {
|
|
207
|
+
defaults.parameters = parameters;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
196
211
|
const apiPage: PartialPage<ApiPageMetadata> = {
|
|
197
212
|
type: "api",
|
|
198
213
|
id: baseId,
|
|
@@ -265,12 +280,6 @@ export async function readOpenapiFiles(
|
|
|
265
280
|
if (!isURL(openapiPath)) {
|
|
266
281
|
const stat = await fs.lstat(openapiPath);
|
|
267
282
|
if (stat.isDirectory()) {
|
|
268
|
-
console.warn(
|
|
269
|
-
chalk.yellow(
|
|
270
|
-
"WARNING: Loading a directory of OpenAPI definitions is experimental and subject to unannounced breaking changes."
|
|
271
|
-
)
|
|
272
|
-
);
|
|
273
|
-
|
|
274
283
|
// TODO: Add config for inlcude/ignore
|
|
275
284
|
const allFiles = await Globby(["**/*.{json,yaml,yml}"], {
|
|
276
285
|
cwd: openapiPath,
|