docusaurus-plugin-openapi-docs 2.1.3 → 2.2.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/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/index.ts
CHANGED
|
@@ -40,6 +40,7 @@ export function isURL(str: string): boolean {
|
|
|
40
40
|
|
|
41
41
|
export function getDocsPluginConfig(
|
|
42
42
|
presetsPlugins: any[],
|
|
43
|
+
plugin: string,
|
|
43
44
|
pluginId: string
|
|
44
45
|
): Object | undefined {
|
|
45
46
|
// eslint-disable-next-line array-callback-return
|
|
@@ -51,10 +52,7 @@ export function getDocsPluginConfig(
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
// Search plugin-content-docs instances
|
|
54
|
-
if (
|
|
55
|
-
typeof data[0] === "string" &&
|
|
56
|
-
data[0] === "@docusaurus/plugin-content-docs"
|
|
57
|
-
) {
|
|
55
|
+
if (typeof data[0] === "string" && data[0] === plugin) {
|
|
58
56
|
const configPluginId = data[1].id ? data[1].id : "default";
|
|
59
57
|
if (configPluginId === pluginId) {
|
|
60
58
|
return data[1];
|
|
@@ -70,7 +68,7 @@ export function getDocsPluginConfig(
|
|
|
70
68
|
}
|
|
71
69
|
|
|
72
70
|
// Search plugin-content-docs instances
|
|
73
|
-
if (filteredConfig[0] ===
|
|
71
|
+
if (filteredConfig[0] === plugin) {
|
|
74
72
|
const configPluginId = filteredConfig[1].id
|
|
75
73
|
? filteredConfig[1].id
|
|
76
74
|
: "default";
|
|
@@ -94,14 +92,22 @@ export default function pluginOpenAPIDocs(
|
|
|
94
92
|
context: LoadContext,
|
|
95
93
|
options: PluginOptions
|
|
96
94
|
): Plugin<LoadedContent> {
|
|
97
|
-
const {
|
|
95
|
+
const {
|
|
96
|
+
config,
|
|
97
|
+
docsPlugin = "@docusaurus/plugin-content-docs",
|
|
98
|
+
docsPluginId,
|
|
99
|
+
} = options;
|
|
98
100
|
const { siteDir, siteConfig } = context;
|
|
99
101
|
|
|
100
102
|
// Get routeBasePath and path from plugin-content-docs or preset
|
|
101
103
|
const presets: any = siteConfig.presets;
|
|
102
104
|
const plugins: any = siteConfig.plugins;
|
|
103
105
|
const presetsPlugins = presets.concat(plugins);
|
|
104
|
-
let docData: any = getDocsPluginConfig(
|
|
106
|
+
let docData: any = getDocsPluginConfig(
|
|
107
|
+
presetsPlugins,
|
|
108
|
+
docsPlugin,
|
|
109
|
+
docsPluginId
|
|
110
|
+
);
|
|
105
111
|
let docRouteBasePath = docData ? docData.routeBasePath : undefined;
|
|
106
112
|
let docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
|
|
107
113
|
|
|
@@ -113,6 +119,7 @@ export default function pluginOpenAPIDocs(
|
|
|
113
119
|
markdownGenerators,
|
|
114
120
|
downloadUrl,
|
|
115
121
|
sidebarOptions,
|
|
122
|
+
disableCompression,
|
|
116
123
|
} = options;
|
|
117
124
|
|
|
118
125
|
// Remove trailing slash before proceeding
|
|
@@ -120,7 +127,7 @@ export default function pluginOpenAPIDocs(
|
|
|
120
127
|
|
|
121
128
|
// Override docPath if pluginId provided
|
|
122
129
|
if (pluginId) {
|
|
123
|
-
docData = getDocsPluginConfig(presetsPlugins, pluginId);
|
|
130
|
+
docData = getDocsPluginConfig(presetsPlugins, docsPlugin, pluginId);
|
|
124
131
|
docRouteBasePath = docData ? docData.routeBasePath : undefined;
|
|
125
132
|
docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
|
|
126
133
|
}
|
|
@@ -299,7 +306,7 @@ custom_edit_url: null
|
|
|
299
306
|
|
|
300
307
|
loadedApi.map(async (item) => {
|
|
301
308
|
if (item.type === "info") {
|
|
302
|
-
if (downloadUrl
|
|
309
|
+
if (downloadUrl) {
|
|
303
310
|
item.downloadUrl = downloadUrl;
|
|
304
311
|
}
|
|
305
312
|
}
|
|
@@ -313,9 +320,11 @@ custom_edit_url: null
|
|
|
313
320
|
// const deserialize = (s: any) => {
|
|
314
321
|
// return zlib.inflateSync(Buffer.from(s, "base64")).toString();
|
|
315
322
|
// };
|
|
316
|
-
|
|
317
|
-
.
|
|
318
|
-
.
|
|
323
|
+
disableCompression === true
|
|
324
|
+
? (item.json = JSON.stringify(item.api))
|
|
325
|
+
: (item.json = zlib
|
|
326
|
+
.deflateSync(JSON.stringify(item.api))
|
|
327
|
+
.toString("base64"));
|
|
319
328
|
let infoBasePath = `${outputDir}/${item.infoId}`;
|
|
320
329
|
if (docRouteBasePath) {
|
|
321
330
|
infoBasePath = `${docRouteBasePath}/${outputDir
|
|
@@ -468,7 +477,7 @@ custom_edit_url: null
|
|
|
468
477
|
cwd: path.resolve(apiDir, "schemas"),
|
|
469
478
|
deep: 1,
|
|
470
479
|
});
|
|
471
|
-
const sidebarFile = await Globby(["sidebar.js"], {
|
|
480
|
+
const sidebarFile = await Globby(["sidebar.{js,ts}"], {
|
|
472
481
|
cwd: path.resolve(apiDir),
|
|
473
482
|
deep: 1,
|
|
474
483
|
});
|
|
@@ -523,6 +532,7 @@ custom_edit_url: null
|
|
|
523
532
|
version: version,
|
|
524
533
|
label: metadata.label,
|
|
525
534
|
baseUrl: metadata.baseUrl,
|
|
535
|
+
downloadUrl: metadata.downloadUrl,
|
|
526
536
|
});
|
|
527
537
|
}
|
|
528
538
|
|
|
@@ -673,6 +683,7 @@ custom_edit_url: null
|
|
|
673
683
|
delete parentConfig.version;
|
|
674
684
|
delete parentConfig.label;
|
|
675
685
|
delete parentConfig.baseUrl;
|
|
686
|
+
delete parentConfig.downloadUrl;
|
|
676
687
|
|
|
677
688
|
// TODO: handle when no versions are defined by version command is passed
|
|
678
689
|
if (versionId === "all") {
|
|
@@ -108,12 +108,6 @@ export function createRequestSchema({ title, body, ...rest }: Props) {
|
|
|
108
108
|
return undefined;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
// we don't show the table if there is no properties to show
|
|
112
|
-
if (firstBody.properties !== undefined) {
|
|
113
|
-
if (Object.keys(firstBody.properties).length === 0) {
|
|
114
|
-
return undefined;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
111
|
return create("MimeTabs", {
|
|
118
112
|
className: "openapi-tabs__mime",
|
|
119
113
|
children: [
|
|
@@ -60,12 +60,6 @@ export function createResponseSchema({ title, body, ...rest }: Props) {
|
|
|
60
60
|
return undefined;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
if (firstBody?.properties !== undefined) {
|
|
64
|
-
if (Object.keys(firstBody?.properties).length === 0) {
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
63
|
return create("TabItem", {
|
|
70
64
|
label: `${mimeType}`,
|
|
71
65
|
value: `${mimeType}`,
|
|
@@ -13,6 +13,7 @@ import { SchemaObject } from "../openapi/types";
|
|
|
13
13
|
describe("createNodes", () => {
|
|
14
14
|
it("should create readable MODs for oneOf primitive properties", () => {
|
|
15
15
|
const schema: SchemaObject = {
|
|
16
|
+
"x-tags": ["clown"],
|
|
16
17
|
type: "object",
|
|
17
18
|
properties: {
|
|
18
19
|
oneOfProperty: {
|
|
@@ -129,6 +129,16 @@ function createAnyOneOf(schema: SchemaObject): any {
|
|
|
129
129
|
*/
|
|
130
130
|
function createProperties(schema: SchemaObject) {
|
|
131
131
|
const discriminator = schema.discriminator;
|
|
132
|
+
if (Object.keys(schema.properties!).length === 0) {
|
|
133
|
+
return create("SchemaItem", {
|
|
134
|
+
collapsible: false,
|
|
135
|
+
name: "",
|
|
136
|
+
required: false,
|
|
137
|
+
schemaName: "object",
|
|
138
|
+
qualifierMessage: undefined,
|
|
139
|
+
schema: {},
|
|
140
|
+
});
|
|
141
|
+
}
|
|
132
142
|
return Object.entries(schema.properties!).map(([key, val]) => {
|
|
133
143
|
return createEdges({
|
|
134
144
|
name: key,
|
|
@@ -594,6 +604,18 @@ function createEdges({
|
|
|
594
604
|
required,
|
|
595
605
|
discriminator,
|
|
596
606
|
}: EdgeProps): any {
|
|
607
|
+
if (SCHEMA_TYPE === "request") {
|
|
608
|
+
if (schema.readOnly && schema.readOnly === true) {
|
|
609
|
+
return undefined;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
if (SCHEMA_TYPE === "response") {
|
|
614
|
+
if (schema.writeOnly && schema.writeOnly === true) {
|
|
615
|
+
return undefined;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
597
619
|
const schemaName = getSchemaName(schema);
|
|
598
620
|
if (discriminator !== undefined && discriminator.propertyName === name) {
|
|
599
621
|
return createPropertyDiscriminator(
|
|
@@ -619,6 +641,19 @@ function createEdges({
|
|
|
619
641
|
const { mergedSchemas }: { mergedSchemas: SchemaObject } = mergeAllOf(
|
|
620
642
|
schema.allOf
|
|
621
643
|
);
|
|
644
|
+
|
|
645
|
+
if (SCHEMA_TYPE === "request") {
|
|
646
|
+
if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
|
|
647
|
+
return undefined;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
if (SCHEMA_TYPE === "response") {
|
|
652
|
+
if (mergedSchemas.writeOnly && mergedSchemas.writeOnly === true) {
|
|
653
|
+
return undefined;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
622
657
|
const mergedSchemaName = getSchemaName(mergedSchemas);
|
|
623
658
|
if (
|
|
624
659
|
mergedSchemas.oneOf !== undefined ||
|
|
@@ -664,18 +699,6 @@ function createEdges({
|
|
|
664
699
|
);
|
|
665
700
|
}
|
|
666
701
|
|
|
667
|
-
if (SCHEMA_TYPE === "request") {
|
|
668
|
-
if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
|
|
669
|
-
return undefined;
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
if (SCHEMA_TYPE === "response") {
|
|
674
|
-
if (mergedSchemas.writeOnly && mergedSchemas.writeOnly === true) {
|
|
675
|
-
return undefined;
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
|
|
679
702
|
return create("SchemaItem", {
|
|
680
703
|
collapsible: false,
|
|
681
704
|
name,
|
|
@@ -727,18 +750,6 @@ function createEdges({
|
|
|
727
750
|
);
|
|
728
751
|
}
|
|
729
752
|
|
|
730
|
-
if (SCHEMA_TYPE === "request") {
|
|
731
|
-
if (schema.readOnly && schema.readOnly === true) {
|
|
732
|
-
return undefined;
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
if (SCHEMA_TYPE === "response") {
|
|
737
|
-
if (schema.writeOnly && schema.writeOnly === true) {
|
|
738
|
-
return undefined;
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
|
|
742
753
|
// primitives and array of non-objects
|
|
743
754
|
return create("SchemaItem", {
|
|
744
755
|
collapsible: false,
|
|
@@ -758,6 +769,17 @@ export function createNodes(
|
|
|
758
769
|
schemaType: "request" | "response"
|
|
759
770
|
): any {
|
|
760
771
|
SCHEMA_TYPE = schemaType;
|
|
772
|
+
if (SCHEMA_TYPE === "request") {
|
|
773
|
+
if (schema.readOnly && schema.readOnly === true) {
|
|
774
|
+
return undefined;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
if (SCHEMA_TYPE === "response") {
|
|
779
|
+
if (schema.writeOnly && schema.writeOnly === true) {
|
|
780
|
+
return undefined;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
761
783
|
const nodes = [];
|
|
762
784
|
// if (schema.discriminator !== undefined) {
|
|
763
785
|
// return createDiscriminator(schema);
|
|
@@ -285,7 +285,7 @@ export function createStatusCodes({ label, id, responses }: Props) {
|
|
|
285
285
|
responseHeaders &&
|
|
286
286
|
createDetails({
|
|
287
287
|
className: "openapi-markdown__details",
|
|
288
|
-
"data-
|
|
288
|
+
"data-collapsed": true,
|
|
289
289
|
open: false,
|
|
290
290
|
style: { textAlign: "left", marginBottom: "1rem" },
|
|
291
291
|
children: [
|
package/src/markdown/utils.ts
CHANGED
|
@@ -47,3 +47,25 @@ export const lessThan =
|
|
|
47
47
|
export const greaterThan =
|
|
48
48
|
/(?<!(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;
|
|
49
49
|
export const codeFence = /`{1,3}[\s\S]*?`{1,3}/g;
|
|
50
|
+
export const curlyBrackets = /([{}])/g;
|
|
51
|
+
export const codeBlock = /(^```.*[\s\S]*?```$|`[^`].+?`)/gm;
|
|
52
|
+
|
|
53
|
+
export function clean(value: string | undefined): string {
|
|
54
|
+
if (!value) {
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let sections = value.split(codeBlock);
|
|
59
|
+
for (let sectionIndex in sections) {
|
|
60
|
+
if (!sections[sectionIndex].startsWith("`")) {
|
|
61
|
+
sections[sectionIndex] = sections[sectionIndex]
|
|
62
|
+
.replace(lessThan, "<")
|
|
63
|
+
.replace(greaterThan, ">")
|
|
64
|
+
.replace(codeFence, function (match) {
|
|
65
|
+
return match.replace(/\\>/g, ">");
|
|
66
|
+
})
|
|
67
|
+
.replace(curlyBrackets, "\\$1");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return sections.join("");
|
|
71
|
+
}
|
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;
|