docusaurus-plugin-openapi-docs 0.0.0-722 → 0.0.0-724
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/createSchema.test.js +1 -0
- package/lib/markdown/utils.d.ts +3 -0
- package/lib/markdown/utils.js +22 -1
- package/lib/openapi/openapi.js +36 -31
- package/lib/openapi/openapi.test.js +2 -0
- package/lib/openapi/types.d.ts +1 -0
- package/lib/sidebars/index.js +16 -11
- package/package.json +2 -2
- package/src/markdown/createSchema.test.ts +1 -0
- 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 +40 -30
- package/src/openapi/types.ts +1 -0
- package/src/sidebars/index.ts +35 -25
package/lib/markdown/utils.d.ts
CHANGED
|
@@ -8,3 +8,6 @@ export declare function render(children: Children): string;
|
|
|
8
8
|
export declare const lessThan: RegExp;
|
|
9
9
|
export declare const greaterThan: RegExp;
|
|
10
10
|
export declare const codeFence: RegExp;
|
|
11
|
+
export declare const curlyBrackets: RegExp;
|
|
12
|
+
export declare const codeBlock: RegExp;
|
|
13
|
+
export declare function clean(value: string | undefined): string;
|
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.codeFence = exports.greaterThan = exports.lessThan = exports.render = exports.guard = exports.create = void 0;
|
|
9
|
+
exports.clean = exports.codeBlock = exports.curlyBrackets = exports.codeFence = 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 = "";
|
|
@@ -38,3 +38,24 @@ exports.render = render;
|
|
|
38
38
|
exports.lessThan = /<(?!(=|button|\s?\/button|code|\s?\/code|details|\s?\/details|summary|\s?\/summary|hr|\s?\/hr|br|\s?\/br|span|\s?\/span|strong|\s?\/strong|small|\s?\/small|table|\s?\/table|thead|\s?\/thead|tbody|\s?\/tbody|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|bold|\s?\/bold|a|\s?\/a|table|\s?\/table|li|\s?\/li|ol|\s?\/ol|ul|\s?\/ul|img|\s?\/img|svg|\s?\/svg|div|\s?\/div|center|\s?\/center))/gu;
|
|
39
39
|
exports.greaterThan = /(?<!(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;
|
|
40
40
|
exports.codeFence = /`{1,3}[\s\S]*?`{1,3}/g;
|
|
41
|
+
exports.curlyBrackets = /([{}])/g;
|
|
42
|
+
exports.codeBlock = /(^```.*[\s\S]*?```$|`[^`].+?`)/gm;
|
|
43
|
+
function clean(value) {
|
|
44
|
+
if (!value) {
|
|
45
|
+
return "";
|
|
46
|
+
}
|
|
47
|
+
let sections = value.split(exports.codeBlock);
|
|
48
|
+
for (let sectionIndex in sections) {
|
|
49
|
+
if (!sections[sectionIndex].startsWith("`")) {
|
|
50
|
+
sections[sectionIndex] = sections[sectionIndex]
|
|
51
|
+
.replace(exports.lessThan, "<")
|
|
52
|
+
.replace(exports.greaterThan, ">")
|
|
53
|
+
.replace(exports.codeFence, function (match) {
|
|
54
|
+
return match.replace(/\\>/g, ">");
|
|
55
|
+
})
|
|
56
|
+
.replace(exports.curlyBrackets, "\\$1");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return sections.join("");
|
|
60
|
+
}
|
|
61
|
+
exports.clean = clean;
|
package/lib/openapi/openapi.js
CHANGED
|
@@ -61,7 +61,7 @@ async function createPostmanCollection(openapiData) {
|
|
|
61
61
|
return await jsonToCollection(data);
|
|
62
62
|
}
|
|
63
63
|
function createItems(openapiData, options, sidebarOptions) {
|
|
64
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
|
|
64
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6;
|
|
65
65
|
// TODO: Find a better way to handle this
|
|
66
66
|
let items = [];
|
|
67
67
|
const infoIdSpaces = openapiData.info.title.replace(" ", "-").toLowerCase();
|
|
@@ -324,42 +324,47 @@ function createItems(openapiData, options, sidebarOptions) {
|
|
|
324
324
|
items.push(apiPage);
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
|
-
if ((options === null || options === void 0 ? void 0 : options.showSchemas) === true
|
|
327
|
+
if ((options === null || options === void 0 ? void 0 : options.showSchemas) === true ||
|
|
328
|
+
Object.entries((_1 = (_0 = openapiData === null || openapiData === void 0 ? void 0 : openapiData.components) === null || _0 === void 0 ? void 0 : _0.schemas) !== null && _1 !== void 0 ? _1 : {})
|
|
329
|
+
.flatMap(([_, s]) => s["x-tags"])
|
|
330
|
+
.filter((item) => !!item).length > 0) {
|
|
328
331
|
// Gather schemas
|
|
329
|
-
for (let [schema, schemaObject] of Object.entries((
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
frontMatter: {
|
|
349
|
-
description: splitDescription
|
|
350
|
-
? splitDescription[0]
|
|
351
|
-
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
352
|
-
.replace(/\s+$/, "")
|
|
332
|
+
for (let [schema, schemaObject] of Object.entries((_3 = (_2 = openapiData === null || openapiData === void 0 ? void 0 : openapiData.components) === null || _2 === void 0 ? void 0 : _2.schemas) !== null && _3 !== void 0 ? _3 : {})) {
|
|
333
|
+
if ((options === null || options === void 0 ? void 0 : options.showSchemas) === true || schemaObject["x-tags"]) {
|
|
334
|
+
const baseIdSpaces = (_5 = (_4 = schemaObject === null || schemaObject === void 0 ? void 0 : schemaObject.title) === null || _4 === void 0 ? void 0 : _4.replace(" ", "-").toLowerCase()) !== null && _5 !== void 0 ? _5 : "";
|
|
335
|
+
const baseId = (0, kebabCase_1.default)(baseIdSpaces);
|
|
336
|
+
const schemaDescription = schemaObject.description;
|
|
337
|
+
let splitDescription;
|
|
338
|
+
if (schemaDescription) {
|
|
339
|
+
splitDescription = schemaDescription.match(/[^\r\n]+/g);
|
|
340
|
+
}
|
|
341
|
+
const schemaPage = {
|
|
342
|
+
type: "schema",
|
|
343
|
+
id: baseId,
|
|
344
|
+
infoId: infoId !== null && infoId !== void 0 ? infoId : "",
|
|
345
|
+
unversionedId: baseId,
|
|
346
|
+
title: schemaObject.title
|
|
347
|
+
? schemaObject.title.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
348
|
+
: schema,
|
|
349
|
+
description: schemaObject.description
|
|
350
|
+
? schemaObject.description.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
353
351
|
: "",
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
352
|
+
frontMatter: {
|
|
353
|
+
description: splitDescription
|
|
354
|
+
? splitDescription[0]
|
|
355
|
+
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
356
|
+
.replace(/\s+$/, "")
|
|
357
|
+
: "",
|
|
358
|
+
},
|
|
359
|
+
schema: schemaObject,
|
|
360
|
+
};
|
|
361
|
+
items.push(schemaPage);
|
|
362
|
+
}
|
|
358
363
|
}
|
|
359
364
|
}
|
|
360
365
|
if ((sidebarOptions === null || sidebarOptions === void 0 ? void 0 : sidebarOptions.categoryLinkSource) === "tag") {
|
|
361
366
|
// Get global tags
|
|
362
|
-
const tags = (
|
|
367
|
+
const tags = (_6 = openapiData.tags) !== null && _6 !== void 0 ? _6 : [];
|
|
363
368
|
// Get operation tags
|
|
364
369
|
const apiItems = items.filter((item) => {
|
|
365
370
|
return item.type === "api";
|
|
@@ -17,6 +17,7 @@ const _1 = require(".");
|
|
|
17
17
|
describe("openapi", () => {
|
|
18
18
|
describe("readOpenapiFiles", () => {
|
|
19
19
|
it("readOpenapiFiles", async () => {
|
|
20
|
+
var _a, _b;
|
|
20
21
|
const results = await (0, _1.readOpenapiFiles)((0, utils_1.posixPath)(path_1.default.join(__dirname, "__fixtures__/examples")));
|
|
21
22
|
const categoryMeta = results.find((x) => x.source.endsWith("_category_.json"));
|
|
22
23
|
expect(categoryMeta).toBeFalsy();
|
|
@@ -26,6 +27,7 @@ describe("openapi", () => {
|
|
|
26
27
|
expect(yaml === null || yaml === void 0 ? void 0 : yaml.sourceDirName).toBe(".");
|
|
27
28
|
expect(yaml === null || yaml === void 0 ? void 0 : yaml.data.tags).toBeDefined();
|
|
28
29
|
expect(yaml === null || yaml === void 0 ? void 0 : yaml.data["x-tagGroups"]).toBeDefined();
|
|
30
|
+
expect((_b = (_a = yaml === null || yaml === void 0 ? void 0 : yaml.data.components) === null || _a === void 0 ? void 0 : _a.schemas) === null || _b === void 0 ? void 0 : _b.HelloString["x-tags"]).toBeDefined();
|
|
29
31
|
});
|
|
30
32
|
});
|
|
31
33
|
});
|
package/lib/openapi/types.d.ts
CHANGED
|
@@ -278,6 +278,7 @@ export type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf"
|
|
|
278
278
|
externalDocs?: ExternalDocumentationObject;
|
|
279
279
|
example?: any;
|
|
280
280
|
deprecated?: boolean;
|
|
281
|
+
"x-tags"?: string[];
|
|
281
282
|
};
|
|
282
283
|
export type SchemaObjectWithRef = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
|
|
283
284
|
type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
|
package/lib/sidebars/index.js
CHANGED
|
@@ -24,7 +24,7 @@ function isSchemaItem(item) {
|
|
|
24
24
|
return item.type === "schema";
|
|
25
25
|
}
|
|
26
26
|
function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
27
|
-
let { outputDir, label } = options;
|
|
27
|
+
let { outputDir, label, showSchemas } = options;
|
|
28
28
|
// Remove trailing slash before proceeding
|
|
29
29
|
outputDir = outputDir.replace(/\/$/, "");
|
|
30
30
|
const { sidebarCollapsed, sidebarCollapsible, customProps, categoryLinkSource, } = sidebarOptions;
|
|
@@ -43,16 +43,19 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
43
43
|
const operationTags = (0, uniq_1.default)(apiItems
|
|
44
44
|
.flatMap((item) => item.api.tags)
|
|
45
45
|
.filter((item) => !!item));
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const schemaTags = (0, uniq_1.default)(schemaItems
|
|
47
|
+
.flatMap((item) => item.schema["x-tags"])
|
|
48
|
+
.filter((item) => !!item));
|
|
49
|
+
// Combine globally defined tags with operation and schema tags
|
|
50
|
+
// Only include global tag if referenced in operation/schema tags
|
|
48
51
|
let apiTags = [];
|
|
49
52
|
tags.flat().forEach((tag) => {
|
|
50
53
|
// Should we also check x-displayName?
|
|
51
|
-
if (operationTags.includes(tag.name)) {
|
|
54
|
+
if (operationTags.includes(tag.name) || schemaTags.includes(tag.name)) {
|
|
52
55
|
apiTags.push(tag.name);
|
|
53
56
|
}
|
|
54
57
|
});
|
|
55
|
-
apiTags = (0, uniq_1.default)(apiTags.concat(operationTags));
|
|
58
|
+
apiTags = (0, uniq_1.default)(apiTags.concat(operationTags, schemaTags));
|
|
56
59
|
const basePath = docPath
|
|
57
60
|
? outputDir.split(docPath)[1].replace(/^\/+/g, "")
|
|
58
61
|
: outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
|
|
@@ -68,7 +71,7 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
68
71
|
}, item.api.method)
|
|
69
72
|
: (0, clsx_1.default)({
|
|
70
73
|
"menu__list-item--deprecated": item.schema.deprecated,
|
|
71
|
-
});
|
|
74
|
+
}, "schema");
|
|
72
75
|
return {
|
|
73
76
|
type: "doc",
|
|
74
77
|
id: basePath === "" || undefined ? `${id}` : `${basePath}/${id}`,
|
|
@@ -126,15 +129,15 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
126
129
|
: (0, utils_1.posixPath)(path_1.default.join("/category", basePath, (0, lodash_1.kebabCase)(tag))),
|
|
127
130
|
};
|
|
128
131
|
}
|
|
132
|
+
const taggedApiItems = apiItems.filter((item) => { var _a; return !!((_a = item.api.tags) === null || _a === void 0 ? void 0 : _a.includes(tag)); });
|
|
133
|
+
const taggedSchemaItems = schemaItems.filter((item) => { var _a; return !!((_a = item.schema["x-tags"]) === null || _a === void 0 ? void 0 : _a.includes(tag)); });
|
|
129
134
|
return {
|
|
130
135
|
type: "category",
|
|
131
136
|
label: (_a = tagObject === null || tagObject === void 0 ? void 0 : tagObject["x-displayName"]) !== null && _a !== void 0 ? _a : tag,
|
|
132
137
|
link: linkConfig,
|
|
133
138
|
collapsible: sidebarCollapsible,
|
|
134
139
|
collapsed: sidebarCollapsed,
|
|
135
|
-
items:
|
|
136
|
-
.filter((item) => { var _a; return !!((_a = item.api.tags) === null || _a === void 0 ? void 0 : _a.includes(tag)); })
|
|
137
|
-
.map(createDocItem),
|
|
140
|
+
items: [...taggedSchemaItems, ...taggedApiItems].map(createDocItem),
|
|
138
141
|
};
|
|
139
142
|
})
|
|
140
143
|
.filter((item) => item.items.length > 0); // Filter out any categories with no items.
|
|
@@ -157,14 +160,16 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
157
160
|
];
|
|
158
161
|
}
|
|
159
162
|
let schemas = [];
|
|
160
|
-
if (schemaItems.length > 0) {
|
|
163
|
+
if (showSchemas && schemaItems.length > 0) {
|
|
161
164
|
schemas = [
|
|
162
165
|
{
|
|
163
166
|
type: "category",
|
|
164
167
|
label: "Schemas",
|
|
165
168
|
collapsible: sidebarCollapsible,
|
|
166
169
|
collapsed: sidebarCollapsed,
|
|
167
|
-
items: schemaItems
|
|
170
|
+
items: schemaItems
|
|
171
|
+
.filter(({ schema }) => !schema["x-tags"])
|
|
172
|
+
.map(createDocItem),
|
|
168
173
|
},
|
|
169
174
|
];
|
|
170
175
|
}
|
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": "0.0.0-
|
|
4
|
+
"version": "0.0.0-724",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"engines": {
|
|
61
61
|
"node": ">=14"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "210bdf060a30737037cd96cf410991c2401d7d45"
|
|
64
64
|
}
|
|
@@ -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: {
|
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
|
@@ -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
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,22 @@ 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
|
-
apiTags = uniq(apiTags.concat(operationTags));
|
|
96
|
+
apiTags = uniq(apiTags.concat(operationTags, schemaTags));
|
|
91
97
|
|
|
92
98
|
const basePath = docPath
|
|
93
99
|
? outputDir.split(docPath!)[1].replace(/^\/+/g, "")
|
|
@@ -107,9 +113,12 @@ function groupByTags(
|
|
|
107
113
|
},
|
|
108
114
|
item.api.method
|
|
109
115
|
)
|
|
110
|
-
: clsx(
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
: clsx(
|
|
117
|
+
{
|
|
118
|
+
"menu__list-item--deprecated": item.schema.deprecated,
|
|
119
|
+
},
|
|
120
|
+
"schema"
|
|
121
|
+
);
|
|
113
122
|
return {
|
|
114
123
|
type: "doc" as const,
|
|
115
124
|
id: basePath === "" || undefined ? `${id}` : `${basePath}/${id}`,
|
|
@@ -183,15 +192,20 @@ function groupByTags(
|
|
|
183
192
|
} as SidebarItemCategoryLinkConfig;
|
|
184
193
|
}
|
|
185
194
|
|
|
195
|
+
const taggedApiItems = apiItems.filter(
|
|
196
|
+
(item) => !!item.api.tags?.includes(tag)
|
|
197
|
+
);
|
|
198
|
+
const taggedSchemaItems = schemaItems.filter(
|
|
199
|
+
(item) => !!item.schema["x-tags"]?.includes(tag)
|
|
200
|
+
);
|
|
201
|
+
|
|
186
202
|
return {
|
|
187
203
|
type: "category" as const,
|
|
188
204
|
label: tagObject?.["x-displayName"] ?? tag,
|
|
189
205
|
link: linkConfig,
|
|
190
206
|
collapsible: sidebarCollapsible,
|
|
191
207
|
collapsed: sidebarCollapsed,
|
|
192
|
-
items:
|
|
193
|
-
.filter((item) => !!item.api.tags?.includes(tag))
|
|
194
|
-
.map(createDocItem),
|
|
208
|
+
items: [...taggedSchemaItems, ...taggedApiItems].map(createDocItem),
|
|
195
209
|
};
|
|
196
210
|
})
|
|
197
211
|
.filter((item) => item.items.length > 0); // Filter out any categories with no items.
|
|
@@ -216,14 +230,16 @@ function groupByTags(
|
|
|
216
230
|
}
|
|
217
231
|
|
|
218
232
|
let schemas: SidebarItemCategory[] = [];
|
|
219
|
-
if (schemaItems.length > 0) {
|
|
233
|
+
if (showSchemas && schemaItems.length > 0) {
|
|
220
234
|
schemas = [
|
|
221
235
|
{
|
|
222
236
|
type: "category" as const,
|
|
223
237
|
label: "Schemas",
|
|
224
238
|
collapsible: sidebarCollapsible!,
|
|
225
239
|
collapsed: sidebarCollapsed!,
|
|
226
|
-
items: schemaItems
|
|
240
|
+
items: schemaItems
|
|
241
|
+
.filter(({ schema }) => !schema["x-tags"])
|
|
242
|
+
.map(createDocItem),
|
|
227
243
|
},
|
|
228
244
|
];
|
|
229
245
|
}
|
|
@@ -263,7 +279,7 @@ export default function generateSidebarSlice(
|
|
|
263
279
|
collapsible: true,
|
|
264
280
|
collapsed: true,
|
|
265
281
|
items: groupByTags(
|
|
266
|
-
api
|
|
282
|
+
api,
|
|
267
283
|
sidebarOptions,
|
|
268
284
|
options,
|
|
269
285
|
[filteredTags],
|
|
@@ -274,13 +290,7 @@ export default function generateSidebarSlice(
|
|
|
274
290
|
sidebarSlice.push(groupCategory);
|
|
275
291
|
});
|
|
276
292
|
} else if (sidebarOptions.groupPathsBy === "tag") {
|
|
277
|
-
sidebarSlice = groupByTags(
|
|
278
|
-
api as ApiPageMetadata[],
|
|
279
|
-
sidebarOptions,
|
|
280
|
-
options,
|
|
281
|
-
tags,
|
|
282
|
-
docPath
|
|
283
|
-
);
|
|
293
|
+
sidebarSlice = groupByTags(api, sidebarOptions, options, tags, docPath);
|
|
284
294
|
}
|
|
285
295
|
|
|
286
296
|
return sidebarSlice;
|