docusaurus-plugin-openapi-docs 4.5.0 → 4.6.0
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 +87 -22
- package/lib/index.js +80 -48
- package/lib/markdown/createHeading.js +1 -1
- package/lib/markdown/createRequestHeader.js +5 -3
- package/lib/markdown/createSchema.js +2 -2
- package/lib/markdown/index.js +3 -2
- package/lib/openapi/createSchemaExample.js +16 -2
- package/lib/openapi/createSchemaExample.test.d.ts +1 -0
- package/lib/openapi/createSchemaExample.test.js +48 -0
- package/lib/openapi/openapi.js +38 -17
- package/lib/openapi/openapi.test.js +48 -0
- package/lib/openapi/webhooks.test.d.ts +1 -0
- package/lib/openapi/webhooks.test.js +23 -0
- package/lib/options.js +3 -0
- package/lib/sidebars/index.js +12 -3
- package/lib/types.d.ts +5 -2
- package/package.json +16 -16
- package/src/index.ts +104 -60
- package/src/markdown/createHeading.ts +2 -2
- package/src/markdown/createRequestHeader.ts +9 -11
- package/src/markdown/createSchema.ts +4 -2
- package/src/markdown/index.ts +3 -2
- package/src/openapi/__fixtures__/webhook/openapi.yaml +17 -0
- package/src/openapi/createSchemaExample.test.ts +57 -0
- package/src/openapi/createSchemaExample.ts +26 -2
- package/src/openapi/openapi.test.ts +58 -0
- package/src/openapi/openapi.ts +35 -6
- package/src/openapi/webhooks.test.ts +30 -0
- package/src/options.ts +3 -0
- package/src/plugin-openapi.d.ts +1 -1
- package/src/sidebars/index.ts +15 -3
- package/src/types.ts +5 -2
- package/src/plugin-content-docs-types.d.ts +0 -42
package/src/openapi/openapi.ts
CHANGED
|
@@ -43,9 +43,15 @@ function jsonToCollection(data: OpenApiObject): Promise<Collection> {
|
|
|
43
43
|
{ schemaFaker: false }
|
|
44
44
|
);
|
|
45
45
|
schemaPack.computedOptions.schemaFaker = false;
|
|
46
|
+
|
|
47
|
+
// Make sure the schema was properly validated or reject with error
|
|
48
|
+
if (!schemaPack.validationResult?.result) {
|
|
49
|
+
return reject(schemaPack.validationResult?.reason);
|
|
50
|
+
}
|
|
51
|
+
|
|
46
52
|
schemaPack.convert((_err: any, conversionResult: any) => {
|
|
47
|
-
if (!conversionResult.result) {
|
|
48
|
-
return reject(conversionResult.reason);
|
|
53
|
+
if (_err || !conversionResult.result) {
|
|
54
|
+
return reject(_err || conversionResult.reason);
|
|
49
55
|
}
|
|
50
56
|
return resolve(new sdk.Collection(conversionResult.output[0].data));
|
|
51
57
|
});
|
|
@@ -89,9 +95,13 @@ function createItems(
|
|
|
89
95
|
let items: PartialPage<ApiMetadata>[] = [];
|
|
90
96
|
const infoIdSpaces = openapiData.info.title.replace(" ", "-").toLowerCase();
|
|
91
97
|
const infoId = kebabCase(infoIdSpaces);
|
|
98
|
+
const schemasOnly = options?.schemasOnly === true;
|
|
92
99
|
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
// Only create an info page if we have a description/title AND showInfoPage is not false
|
|
101
|
+
if (
|
|
102
|
+
(openapiData.info.description || openapiData.info.title) &&
|
|
103
|
+
options?.showInfoPage !== false
|
|
104
|
+
) {
|
|
95
105
|
const infoDescription = openapiData.info?.description;
|
|
96
106
|
let splitDescription: any;
|
|
97
107
|
if (infoDescription) {
|
|
@@ -250,6 +260,9 @@ function createItems(
|
|
|
250
260
|
...(options?.showExtensions && {
|
|
251
261
|
show_extensions: options.showExtensions,
|
|
252
262
|
}),
|
|
263
|
+
...(options?.maskCredentials === false && {
|
|
264
|
+
mask_credentials_disabled: true,
|
|
265
|
+
}),
|
|
253
266
|
},
|
|
254
267
|
api: {
|
|
255
268
|
...defaults,
|
|
@@ -274,11 +287,19 @@ function createItems(
|
|
|
274
287
|
for (let [path, pathObject] of Object.entries(
|
|
275
288
|
openapiData["x-webhooks"] ?? openapiData["webhooks"] ?? {}
|
|
276
289
|
)) {
|
|
290
|
+
const eventName = path;
|
|
277
291
|
path = "webhook";
|
|
278
292
|
const { $ref, description, parameters, servers, summary, ...rest } =
|
|
279
293
|
pathObject;
|
|
280
294
|
for (let [method, operationObject] of Object.entries({ ...rest })) {
|
|
281
295
|
method = "event";
|
|
296
|
+
if (
|
|
297
|
+
operationObject.summary === undefined &&
|
|
298
|
+
operationObject.operationId === undefined
|
|
299
|
+
) {
|
|
300
|
+
operationObject.summary = eventName;
|
|
301
|
+
}
|
|
302
|
+
|
|
282
303
|
const title =
|
|
283
304
|
operationObject.summary ??
|
|
284
305
|
operationObject.operationId ??
|
|
@@ -290,7 +311,7 @@ function createItems(
|
|
|
290
311
|
|
|
291
312
|
const baseId = operationObject.operationId
|
|
292
313
|
? kebabCase(operationObject.operationId)
|
|
293
|
-
: kebabCase(operationObject.summary);
|
|
314
|
+
: kebabCase(operationObject.summary ?? eventName);
|
|
294
315
|
|
|
295
316
|
const extensions = [];
|
|
296
317
|
const commonExtensions = ["x-codeSamples"];
|
|
@@ -395,6 +416,9 @@ function createItems(
|
|
|
395
416
|
...(options?.showExtensions && {
|
|
396
417
|
show_extensions: options.showExtensions,
|
|
397
418
|
}),
|
|
419
|
+
...(options?.maskCredentials === false && {
|
|
420
|
+
mask_credentials_disabled: true,
|
|
421
|
+
}),
|
|
398
422
|
},
|
|
399
423
|
api: {
|
|
400
424
|
...defaults,
|
|
@@ -414,6 +438,7 @@ function createItems(
|
|
|
414
438
|
}
|
|
415
439
|
|
|
416
440
|
if (
|
|
441
|
+
schemasOnly ||
|
|
417
442
|
options?.showSchemas === true ||
|
|
418
443
|
Object.entries(openapiData?.components?.schemas ?? {})
|
|
419
444
|
.flatMap(([_, s]) => s["x-tags"])
|
|
@@ -423,7 +448,11 @@ function createItems(
|
|
|
423
448
|
for (let [schema, schemaObject] of Object.entries(
|
|
424
449
|
openapiData?.components?.schemas ?? {}
|
|
425
450
|
)) {
|
|
426
|
-
if (
|
|
451
|
+
if (
|
|
452
|
+
schemasOnly ||
|
|
453
|
+
options?.showSchemas === true ||
|
|
454
|
+
schemaObject["x-tags"]
|
|
455
|
+
) {
|
|
427
456
|
const baseIdSpaces =
|
|
428
457
|
schemaObject?.title?.replace(" ", "-").toLowerCase() ?? "";
|
|
429
458
|
const baseId = kebabCase(baseIdSpaces);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import path from "path";
|
|
9
|
+
|
|
10
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
11
|
+
import { posixPath } from "@docusaurus/utils";
|
|
12
|
+
|
|
13
|
+
import { readOpenapiFiles, processOpenapiFiles } from ".";
|
|
14
|
+
|
|
15
|
+
describe("webhooks", () => {
|
|
16
|
+
it("uses event name when summary and operationId are missing", async () => {
|
|
17
|
+
const files = await readOpenapiFiles(
|
|
18
|
+
posixPath(path.join(__dirname, "__fixtures__/webhook/openapi.yaml"))
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const [items] = await processOpenapiFiles(
|
|
22
|
+
files,
|
|
23
|
+
{ specPath: "", outputDir: "" } as any,
|
|
24
|
+
{}
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const webhookItem = items.find((item) => item.type === "api");
|
|
28
|
+
expect(webhookItem?.id).toBe("order-created");
|
|
29
|
+
});
|
|
30
|
+
});
|
package/src/options.ts
CHANGED
|
@@ -48,7 +48,10 @@ export const OptionsSchema = Joi.object({
|
|
|
48
48
|
sidebarOptions: sidebarOptions,
|
|
49
49
|
markdownGenerators: markdownGenerators,
|
|
50
50
|
showSchemas: Joi.boolean(),
|
|
51
|
+
showInfoPage: Joi.boolean(),
|
|
52
|
+
schemasOnly: Joi.boolean(),
|
|
51
53
|
disableCompression: Joi.boolean(),
|
|
54
|
+
maskCredentials: Joi.boolean(),
|
|
52
55
|
version: Joi.string().when("versions", {
|
|
53
56
|
is: Joi.exist(),
|
|
54
57
|
then: Joi.required(),
|
package/src/plugin-openapi.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type { FrontMatter as DocsFrontMatter } from "@docusaurus/types";
|
|
|
11
11
|
import type { Props as DocsProps } from "@docusaurus/types";
|
|
12
12
|
|
|
13
13
|
declare module "docusaurus-plugin-openapi-docs" {
|
|
14
|
-
import type { PropSidebars } from "@docusaurus/plugin-content-docs
|
|
14
|
+
import type { PropSidebars } from "@docusaurus/plugin-content-docs/lib/sidebars/types";
|
|
15
15
|
|
|
16
16
|
export type Options = Partial<import("./types").APIOptions>;
|
|
17
17
|
|
package/src/sidebars/index.ts
CHANGED
|
@@ -125,9 +125,21 @@ function groupByTags(
|
|
|
125
125
|
apiTags = uniq(apiTags.concat(operationTags, schemaTags));
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
:
|
|
128
|
+
// Extract base path from outputDir, handling cases where docPath may not be in outputDir
|
|
129
|
+
const getBasePathFromOutput = (
|
|
130
|
+
output: string,
|
|
131
|
+
doc: string | undefined
|
|
132
|
+
): string => {
|
|
133
|
+
if (doc && output.includes(doc)) {
|
|
134
|
+
return output.split(doc)[1]?.replace(/^\/+/g, "") ?? "";
|
|
135
|
+
}
|
|
136
|
+
const slashIndex = output.indexOf("/", 1);
|
|
137
|
+
return slashIndex === -1
|
|
138
|
+
? ""
|
|
139
|
+
: output.slice(slashIndex).replace(/^\/+/g, "");
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const basePath = getBasePathFromOutput(outputDir, docPath);
|
|
131
143
|
|
|
132
144
|
const createDocItemFnContext = {
|
|
133
145
|
sidebarOptions,
|
package/src/types.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import { SidebarItemDoc } from "@docusaurus/plugin-content-docs/
|
|
8
|
+
import type { SidebarItemDoc } from "@docusaurus/plugin-content-docs/lib/sidebars/types";
|
|
9
9
|
import Request from "postman-collection";
|
|
10
10
|
|
|
11
11
|
import {
|
|
@@ -21,7 +21,7 @@ export type {
|
|
|
21
21
|
SidebarItemLink,
|
|
22
22
|
PropSidebar,
|
|
23
23
|
PropSidebarItem,
|
|
24
|
-
} from "@docusaurus/plugin-content-docs
|
|
24
|
+
} from "@docusaurus/plugin-content-docs/lib/sidebars/types";
|
|
25
25
|
export interface PluginOptions {
|
|
26
26
|
id?: string;
|
|
27
27
|
docsPlugin?: string;
|
|
@@ -51,7 +51,10 @@ export interface APIOptions {
|
|
|
51
51
|
proxy?: string;
|
|
52
52
|
markdownGenerators?: MarkdownGenerator;
|
|
53
53
|
showSchemas?: boolean;
|
|
54
|
+
showInfoPage?: boolean;
|
|
55
|
+
schemasOnly?: boolean;
|
|
54
56
|
disableCompression?: boolean;
|
|
57
|
+
maskCredentials?: boolean;
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
export interface MarkdownGenerator {
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/* ============================================================================
|
|
2
|
-
* Copyright (c) Palo Alto Networks
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
* ========================================================================== */
|
|
7
|
-
|
|
8
|
-
declare module "@docusaurus/plugin-content-docs-types" {
|
|
9
|
-
// Makes all properties visible when hovering over the type
|
|
10
|
-
type Expand<T extends Record<string, unknown>> = { [P in keyof T]: T[P] };
|
|
11
|
-
|
|
12
|
-
export type SidebarItemBase = {
|
|
13
|
-
className?: string;
|
|
14
|
-
customProps?: Record<string, unknown>;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export type SidebarItemLink = SidebarItemBase & {
|
|
18
|
-
type: "link";
|
|
19
|
-
href: string;
|
|
20
|
-
label: string;
|
|
21
|
-
docId: string;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
type SidebarItemCategoryBase = SidebarItemBase & {
|
|
25
|
-
type: "category";
|
|
26
|
-
label: string;
|
|
27
|
-
collapsed: boolean;
|
|
28
|
-
collapsible: boolean;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type PropSidebarItemCategory = Expand<
|
|
32
|
-
SidebarItemCategoryBase & {
|
|
33
|
-
items: PropSidebarItem[];
|
|
34
|
-
}
|
|
35
|
-
>;
|
|
36
|
-
|
|
37
|
-
export type PropSidebarItem = SidebarItemLink | PropSidebarItemCategory;
|
|
38
|
-
export type PropSidebar = PropSidebarItem[];
|
|
39
|
-
export type PropSidebars = {
|
|
40
|
-
[sidebarId: string]: PropSidebar;
|
|
41
|
-
};
|
|
42
|
-
}
|