docusaurus-plugin-openapi-docs 2.1.3 → 2.2.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/README.md +86 -61
- package/lib/index.d.ts +1 -1
- package/lib/index.js +16 -13
- package/lib/markdown/createRequestSchema.js +0 -6
- package/lib/markdown/createResponseSchema.js +0 -5
- package/lib/markdown/createSchema.js +40 -20
- package/lib/markdown/createSchema.test.js +1 -0
- package/lib/markdown/createStatusCodes.js +1 -1
- package/lib/markdown/utils.d.ts +3 -0
- package/lib/markdown/utils.js +22 -1
- package/lib/openapi/openapi.js +38 -33
- package/lib/openapi/openapi.test.js +2 -0
- package/lib/openapi/types.d.ts +1 -0
- package/lib/options.js +3 -0
- package/lib/sidebars/index.js +30 -11
- package/lib/types.d.ts +4 -1
- package/package.json +4 -4
- package/src/index.ts +24 -13
- package/src/markdown/createRequestSchema.ts +0 -6
- package/src/markdown/createResponseSchema.ts +0 -6
- package/src/markdown/createSchema.test.ts +1 -0
- package/src/markdown/createSchema.ts +46 -24
- package/src/markdown/createStatusCodes.ts +1 -1
- package/src/markdown/utils.ts +22 -0
- package/src/openapi/__fixtures__/examples/openapi.yaml +7 -0
- package/src/openapi/openapi.test.ts +4 -0
- package/src/openapi/openapi.ts +43 -33
- package/src/openapi/types.ts +1 -0
- package/src/openapi-to-postmanv2.d.ts +1 -1
- package/src/options.ts +3 -0
- package/src/postman-collection.d.ts +1 -1
- package/src/sidebars/index.ts +55 -27
- package/src/types.ts +4 -1
package/src/openapi/openapi.ts
CHANGED
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
import path from "path";
|
|
9
9
|
|
|
10
10
|
import { Globby, GlobExcludeDefault, posixPath } from "@docusaurus/utils";
|
|
11
|
-
import Converter from "@paloaltonetworks/openapi-to-postmanv2";
|
|
12
|
-
import sdk from "@paloaltonetworks/postman-collection";
|
|
13
|
-
import Collection from "@paloaltonetworks/postman-collection";
|
|
14
11
|
import chalk from "chalk";
|
|
15
12
|
import fs from "fs-extra";
|
|
16
13
|
import cloneDeep from "lodash/cloneDeep";
|
|
17
14
|
import kebabCase from "lodash/kebabCase";
|
|
18
15
|
import unionBy from "lodash/unionBy";
|
|
19
16
|
import uniq from "lodash/uniq";
|
|
17
|
+
import Converter from "openapi-to-postmanv2";
|
|
18
|
+
import Collection from "postman-collection";
|
|
19
|
+
import sdk from "postman-collection";
|
|
20
20
|
|
|
21
21
|
import { sampleRequestFromSchema } from "./createRequestExample";
|
|
22
22
|
import { OpenApiObject, TagGroupObject, TagObject } from "./types";
|
|
@@ -410,43 +410,53 @@ function createItems(
|
|
|
410
410
|
}
|
|
411
411
|
}
|
|
412
412
|
|
|
413
|
-
if (
|
|
413
|
+
if (
|
|
414
|
+
options?.showSchemas === true ||
|
|
415
|
+
Object.entries(openapiData?.components?.schemas ?? {})
|
|
416
|
+
.flatMap(([_, s]) => s["x-tags"])
|
|
417
|
+
.filter((item) => !!item).length > 0
|
|
418
|
+
) {
|
|
414
419
|
// Gather schemas
|
|
415
420
|
for (let [schema, schemaObject] of Object.entries(
|
|
416
421
|
openapiData?.components?.schemas ?? {}
|
|
417
422
|
)) {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
423
|
+
if (options?.showSchemas === true || schemaObject["x-tags"]) {
|
|
424
|
+
const baseIdSpaces =
|
|
425
|
+
schemaObject?.title?.replace(" ", "-").toLowerCase() ?? "";
|
|
426
|
+
const baseId = kebabCase(baseIdSpaces);
|
|
427
|
+
|
|
428
|
+
const schemaDescription = schemaObject.description;
|
|
429
|
+
let splitDescription: any;
|
|
430
|
+
if (schemaDescription) {
|
|
431
|
+
splitDescription = schemaDescription.match(/[^\r\n]+/g);
|
|
432
|
+
}
|
|
427
433
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
? splitDescription[0]
|
|
442
|
-
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
443
|
-
.replace(/\s+$/, "")
|
|
434
|
+
const schemaPage: PartialPage<SchemaPageMetadata> = {
|
|
435
|
+
type: "schema",
|
|
436
|
+
id: baseId,
|
|
437
|
+
infoId: infoId ?? "",
|
|
438
|
+
unversionedId: baseId,
|
|
439
|
+
title: schemaObject.title
|
|
440
|
+
? schemaObject.title.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
441
|
+
: schema,
|
|
442
|
+
description: schemaObject.description
|
|
443
|
+
? schemaObject.description.replace(
|
|
444
|
+
/((?:^|[^\\])(?:\\{2})*)"/g,
|
|
445
|
+
"$1'"
|
|
446
|
+
)
|
|
444
447
|
: "",
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
+
frontMatter: {
|
|
449
|
+
description: splitDescription
|
|
450
|
+
? splitDescription[0]
|
|
451
|
+
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
452
|
+
.replace(/\s+$/, "")
|
|
453
|
+
: "",
|
|
454
|
+
},
|
|
455
|
+
schema: schemaObject,
|
|
456
|
+
};
|
|
448
457
|
|
|
449
|
-
|
|
458
|
+
items.push(schemaPage);
|
|
459
|
+
}
|
|
450
460
|
}
|
|
451
461
|
}
|
|
452
462
|
|
package/src/openapi/types.ts
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
declare module "
|
|
8
|
+
declare module "openapi-to-postmanv2" {
|
|
9
9
|
export default any;
|
|
10
10
|
}
|
package/src/options.ts
CHANGED
|
@@ -23,6 +23,7 @@ const markdownGenerators = Joi.object({
|
|
|
23
23
|
|
|
24
24
|
export const OptionsSchema = Joi.object({
|
|
25
25
|
id: Joi.string().required(),
|
|
26
|
+
docsPlugin: Joi.string(),
|
|
26
27
|
docsPluginId: Joi.string().required(),
|
|
27
28
|
config: Joi.object()
|
|
28
29
|
.pattern(
|
|
@@ -38,6 +39,7 @@ export const OptionsSchema = Joi.object({
|
|
|
38
39
|
sidebarOptions: sidebarOptions,
|
|
39
40
|
markdownGenerators: markdownGenerators,
|
|
40
41
|
showSchemas: Joi.boolean(),
|
|
42
|
+
disableCompression: Joi.boolean(),
|
|
41
43
|
version: Joi.string().when("versions", {
|
|
42
44
|
is: Joi.exist(),
|
|
43
45
|
then: Joi.required(),
|
|
@@ -57,6 +59,7 @@ export const OptionsSchema = Joi.object({
|
|
|
57
59
|
outputDir: Joi.string().required(),
|
|
58
60
|
label: Joi.string().required(),
|
|
59
61
|
baseUrl: Joi.string().required(),
|
|
62
|
+
downloadUrl: Joi.string(),
|
|
60
63
|
})
|
|
61
64
|
),
|
|
62
65
|
})
|
package/src/sidebars/index.ts
CHANGED
|
@@ -25,6 +25,7 @@ import type {
|
|
|
25
25
|
APIOptions,
|
|
26
26
|
ApiPageMetadata,
|
|
27
27
|
ApiMetadata,
|
|
28
|
+
InfoPageMetadata,
|
|
28
29
|
SchemaPageMetadata,
|
|
29
30
|
} from "../types";
|
|
30
31
|
|
|
@@ -41,13 +42,13 @@ function isSchemaItem(item: ApiMetadata): item is ApiMetadata {
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
function groupByTags(
|
|
44
|
-
items:
|
|
45
|
+
items: ApiMetadata[],
|
|
45
46
|
sidebarOptions: SidebarOptions,
|
|
46
47
|
options: APIOptions,
|
|
47
48
|
tags: TagObject[][],
|
|
48
49
|
docPath: string
|
|
49
50
|
): ProcessedSidebar {
|
|
50
|
-
let { outputDir, label } = options;
|
|
51
|
+
let { outputDir, label, showSchemas } = options;
|
|
51
52
|
|
|
52
53
|
// Remove trailing slash before proceeding
|
|
53
54
|
outputDir = outputDir.replace(/\/$/, "");
|
|
@@ -59,9 +60,9 @@ function groupByTags(
|
|
|
59
60
|
categoryLinkSource,
|
|
60
61
|
} = sidebarOptions;
|
|
61
62
|
|
|
62
|
-
const apiItems = items.filter(isApiItem);
|
|
63
|
-
const infoItems = items.filter(isInfoItem);
|
|
64
|
-
const schemaItems = items.filter(isSchemaItem);
|
|
63
|
+
const apiItems = items.filter(isApiItem) as ApiPageMetadata[];
|
|
64
|
+
const infoItems = items.filter(isInfoItem) as InfoPageMetadata[];
|
|
65
|
+
const schemaItems = items.filter(isSchemaItem) as SchemaPageMetadata[];
|
|
65
66
|
const intros = infoItems.map((item: any) => {
|
|
66
67
|
return {
|
|
67
68
|
id: item.id,
|
|
@@ -77,17 +78,25 @@ function groupByTags(
|
|
|
77
78
|
.flatMap((item) => item.api.tags)
|
|
78
79
|
.filter((item): item is string => !!item)
|
|
79
80
|
);
|
|
81
|
+
const schemaTags = uniq(
|
|
82
|
+
schemaItems
|
|
83
|
+
.flatMap((item) => item.schema["x-tags"])
|
|
84
|
+
.filter((item): item is string => !!item)
|
|
85
|
+
);
|
|
80
86
|
|
|
81
|
-
// Combine globally defined tags with operation tags
|
|
82
|
-
// Only include global tag if referenced in operation tags
|
|
87
|
+
// Combine globally defined tags with operation and schema tags
|
|
88
|
+
// Only include global tag if referenced in operation/schema tags
|
|
83
89
|
let apiTags: string[] = [];
|
|
84
90
|
tags.flat().forEach((tag) => {
|
|
85
91
|
// Should we also check x-displayName?
|
|
86
|
-
if (operationTags.includes(tag.name!)) {
|
|
92
|
+
if (operationTags.includes(tag.name!) || schemaTags.includes(tag.name!)) {
|
|
87
93
|
apiTags.push(tag.name!);
|
|
88
94
|
}
|
|
89
95
|
});
|
|
90
|
-
|
|
96
|
+
|
|
97
|
+
if (sidebarOptions.groupPathsBy !== "tagGroup") {
|
|
98
|
+
apiTags = uniq(apiTags.concat(operationTags, schemaTags));
|
|
99
|
+
}
|
|
91
100
|
|
|
92
101
|
const basePath = docPath
|
|
93
102
|
? outputDir.split(docPath!)[1].replace(/^\/+/g, "")
|
|
@@ -107,9 +116,12 @@ function groupByTags(
|
|
|
107
116
|
},
|
|
108
117
|
item.api.method
|
|
109
118
|
)
|
|
110
|
-
: clsx(
|
|
111
|
-
|
|
112
|
-
|
|
119
|
+
: clsx(
|
|
120
|
+
{
|
|
121
|
+
"menu__list-item--deprecated": item.schema.deprecated,
|
|
122
|
+
},
|
|
123
|
+
"schema"
|
|
124
|
+
);
|
|
113
125
|
return {
|
|
114
126
|
type: "doc" as const,
|
|
115
127
|
id: basePath === "" || undefined ? `${id}` : `${basePath}/${id}`,
|
|
@@ -183,15 +195,20 @@ function groupByTags(
|
|
|
183
195
|
} as SidebarItemCategoryLinkConfig;
|
|
184
196
|
}
|
|
185
197
|
|
|
198
|
+
const taggedApiItems = apiItems.filter(
|
|
199
|
+
(item) => !!item.api.tags?.includes(tag)
|
|
200
|
+
);
|
|
201
|
+
const taggedSchemaItems = schemaItems.filter(
|
|
202
|
+
(item) => !!item.schema["x-tags"]?.includes(tag)
|
|
203
|
+
);
|
|
204
|
+
|
|
186
205
|
return {
|
|
187
206
|
type: "category" as const,
|
|
188
207
|
label: tagObject?.["x-displayName"] ?? tag,
|
|
189
208
|
link: linkConfig,
|
|
190
209
|
collapsible: sidebarCollapsible,
|
|
191
210
|
collapsed: sidebarCollapsed,
|
|
192
|
-
items:
|
|
193
|
-
.filter((item) => !!item.api.tags?.includes(tag))
|
|
194
|
-
.map(createDocItem),
|
|
211
|
+
items: [...taggedSchemaItems, ...taggedApiItems].map(createDocItem),
|
|
195
212
|
};
|
|
196
213
|
})
|
|
197
214
|
.filter((item) => item.items.length > 0); // Filter out any categories with no items.
|
|
@@ -216,14 +233,16 @@ function groupByTags(
|
|
|
216
233
|
}
|
|
217
234
|
|
|
218
235
|
let schemas: SidebarItemCategory[] = [];
|
|
219
|
-
if (schemaItems.length > 0) {
|
|
236
|
+
if (showSchemas && schemaItems.length > 0) {
|
|
220
237
|
schemas = [
|
|
221
238
|
{
|
|
222
239
|
type: "category" as const,
|
|
223
240
|
label: "Schemas",
|
|
224
241
|
collapsible: sidebarCollapsible!,
|
|
225
242
|
collapsed: sidebarCollapsed!,
|
|
226
|
-
items: schemaItems
|
|
243
|
+
items: schemaItems
|
|
244
|
+
.filter(({ schema }) => !schema["x-tags"])
|
|
245
|
+
.map(createDocItem),
|
|
227
246
|
},
|
|
228
247
|
];
|
|
229
248
|
}
|
|
@@ -248,6 +267,7 @@ export default function generateSidebarSlice(
|
|
|
248
267
|
let sidebarSlice: ProcessedSidebar = [];
|
|
249
268
|
|
|
250
269
|
if (sidebarOptions.groupPathsBy === "tagGroup") {
|
|
270
|
+
let schemasGroup: ProcessedSidebar = [];
|
|
251
271
|
tagGroups?.forEach((tagGroup) => {
|
|
252
272
|
//filter tags only included in group
|
|
253
273
|
const filteredTags: TagObject[] = [];
|
|
@@ -263,24 +283,32 @@ export default function generateSidebarSlice(
|
|
|
263
283
|
collapsible: true,
|
|
264
284
|
collapsed: true,
|
|
265
285
|
items: groupByTags(
|
|
266
|
-
api
|
|
286
|
+
api,
|
|
267
287
|
sidebarOptions,
|
|
268
288
|
options,
|
|
269
289
|
[filteredTags],
|
|
270
290
|
docPath
|
|
271
291
|
),
|
|
272
|
-
}
|
|
292
|
+
};
|
|
273
293
|
|
|
274
|
-
|
|
294
|
+
if (options.showSchemas) {
|
|
295
|
+
// For the first tagGroup, save the generated "Schemas" category for later.
|
|
296
|
+
if (schemasGroup.length === 0) {
|
|
297
|
+
schemasGroup = groupCategory.items?.filter(
|
|
298
|
+
(item) => item.type === "category" && item.label === "Schemas"
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
// Remove the "Schemas" category from every `groupCategory`.
|
|
302
|
+
groupCategory.items = groupCategory.items.filter((item) =>
|
|
303
|
+
"label" in item ? item.label !== "Schemas" : true
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
sidebarSlice.push(groupCategory as ProcessedSidebarItem);
|
|
275
307
|
});
|
|
308
|
+
// Add `schemasGroup` to the end of the sidebar.
|
|
309
|
+
sidebarSlice.push(...schemasGroup);
|
|
276
310
|
} else if (sidebarOptions.groupPathsBy === "tag") {
|
|
277
|
-
sidebarSlice = groupByTags(
|
|
278
|
-
api as ApiPageMetadata[],
|
|
279
|
-
sidebarOptions,
|
|
280
|
-
options,
|
|
281
|
-
tags,
|
|
282
|
-
docPath
|
|
283
|
-
);
|
|
311
|
+
sidebarSlice = groupByTags(api, sidebarOptions, options, tags, docPath);
|
|
284
312
|
}
|
|
285
313
|
|
|
286
314
|
return sidebarSlice;
|
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 type Request from "
|
|
8
|
+
import type Request from "postman-collection";
|
|
9
9
|
|
|
10
10
|
import {
|
|
11
11
|
InfoObject,
|
|
@@ -23,6 +23,7 @@ export type {
|
|
|
23
23
|
} from "@docusaurus/plugin-content-docs-types";
|
|
24
24
|
export interface PluginOptions {
|
|
25
25
|
id?: string;
|
|
26
|
+
docsPlugin?: string;
|
|
26
27
|
docsPluginId: string;
|
|
27
28
|
config: {
|
|
28
29
|
[key: string]: APIOptions;
|
|
@@ -46,6 +47,7 @@ export interface APIOptions {
|
|
|
46
47
|
proxy?: string;
|
|
47
48
|
markdownGenerators?: MarkdownGenerator;
|
|
48
49
|
showSchemas?: boolean;
|
|
50
|
+
disableCompression?: boolean;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
export interface MarkdownGenerator {
|
|
@@ -68,6 +70,7 @@ export interface APIVersionOptions {
|
|
|
68
70
|
outputDir: string;
|
|
69
71
|
label: string;
|
|
70
72
|
baseUrl: string;
|
|
73
|
+
downloadUrl?: string;
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
export interface LoadedContent {
|