docusaurus-plugin-openapi-docs 0.0.0-353 → 0.0.0-354
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.js +1 -1
- package/lib/sidebars/index.js +22 -13
- package/lib/types.d.ts +0 -1
- package/package.json +2 -2
- package/src/index.ts +1 -1
- package/src/sidebars/index.ts +23 -13
- package/src/types.ts +0 -1
package/lib/index.js
CHANGED
|
@@ -122,7 +122,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
122
122
|
if (item.type === "info") {
|
|
123
123
|
if (!fs_1.default.existsSync(`${outputDir}/${item.id}.info.mdx`)) {
|
|
124
124
|
try {
|
|
125
|
-
(sidebarOptions === null || sidebarOptions === void 0 ? void 0 : sidebarOptions.
|
|
125
|
+
(sidebarOptions === null || sidebarOptions === void 0 ? void 0 : sidebarOptions.categoryLinkSource) === "info" // Only use utils template if set to "info"
|
|
126
126
|
? fs_1.default.writeFileSync(`${outputDir}/${item.id}.info.mdx`, utils, "utf8")
|
|
127
127
|
: fs_1.default.writeFileSync(`${outputDir}/${item.id}.info.mdx`, view, "utf8");
|
|
128
128
|
console.log(chalk_1.default.green(`Successfully created "${outputDir}/${item.id}.info.mdx"`));
|
package/lib/sidebars/index.js
CHANGED
|
@@ -21,7 +21,6 @@ function isInfoItem(item) {
|
|
|
21
21
|
function groupByTags(items, sidebarOptions, options, tags) {
|
|
22
22
|
const { outputDir } = options;
|
|
23
23
|
const { sidebarCollapsed, sidebarCollapsible, customProps, categoryLinkSource, } = sidebarOptions;
|
|
24
|
-
const linkSource = categoryLinkSource !== null && categoryLinkSource !== void 0 ? categoryLinkSource : "tag";
|
|
25
24
|
const apiItems = items.filter(isApiItem);
|
|
26
25
|
const infoItems = items.filter(isInfoItem);
|
|
27
26
|
const intros = infoItems.map((item) => {
|
|
@@ -33,7 +32,7 @@ function groupByTags(items, sidebarOptions, options, tags) {
|
|
|
33
32
|
};
|
|
34
33
|
});
|
|
35
34
|
// TODO: make sure we only take the first tag
|
|
36
|
-
const
|
|
35
|
+
const apiTags = (0, uniq_1.default)(apiItems
|
|
37
36
|
.flatMap((item) => item.api.tags)
|
|
38
37
|
.filter((item) => !!item));
|
|
39
38
|
// TODO: optimize this or make it a function
|
|
@@ -56,18 +55,18 @@ function groupByTags(items, sidebarOptions, options, tags) {
|
|
|
56
55
|
}, item.api.method),
|
|
57
56
|
};
|
|
58
57
|
}
|
|
59
|
-
let
|
|
60
|
-
if (
|
|
58
|
+
let rootIntroDoc = undefined;
|
|
59
|
+
if (infoItems.length === 1) {
|
|
61
60
|
const infoItem = infoItems[0];
|
|
62
61
|
const id = infoItem.id;
|
|
63
|
-
|
|
62
|
+
rootIntroDoc = {
|
|
64
63
|
type: "doc",
|
|
65
64
|
id: `${basePath}/${id}`,
|
|
66
65
|
};
|
|
67
66
|
}
|
|
68
|
-
const tagged =
|
|
67
|
+
const tagged = apiTags
|
|
69
68
|
.map((tag) => {
|
|
70
|
-
//
|
|
69
|
+
// Map info object to tag
|
|
71
70
|
const infoObject = intros.find((i) => i.tags.includes(tag));
|
|
72
71
|
const tagObject = tags.flat().find((t) => {
|
|
73
72
|
var _a;
|
|
@@ -76,15 +75,16 @@ function groupByTags(items, sidebarOptions, options, tags) {
|
|
|
76
75
|
description: `${tag} Index`,
|
|
77
76
|
};
|
|
78
77
|
});
|
|
79
|
-
// TODO: perhaps move
|
|
78
|
+
// TODO: perhaps move this into a getLinkConfig() function
|
|
80
79
|
let linkConfig = undefined;
|
|
81
|
-
if (infoObject !== undefined &&
|
|
80
|
+
if (infoObject !== undefined && categoryLinkSource === "info") {
|
|
82
81
|
linkConfig = {
|
|
83
82
|
type: "doc",
|
|
84
83
|
id: `${basePath}/${infoObject.id}`,
|
|
85
84
|
};
|
|
86
85
|
}
|
|
87
|
-
|
|
86
|
+
// TODO: perhaps move this into a getLinkConfig() function
|
|
87
|
+
if (tagObject !== undefined && categoryLinkSource === "tag") {
|
|
88
88
|
const linkDescription = tagObject === null || tagObject === void 0 ? void 0 : tagObject.description;
|
|
89
89
|
linkConfig = {
|
|
90
90
|
type: "generated-index",
|
|
@@ -93,6 +93,14 @@ function groupByTags(items, sidebarOptions, options, tags) {
|
|
|
93
93
|
slug: "/category/" + (0, lodash_1.kebabCase)(tag),
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
|
+
// Default behavior
|
|
97
|
+
if (categoryLinkSource === undefined) {
|
|
98
|
+
linkConfig = {
|
|
99
|
+
type: "generated-index",
|
|
100
|
+
title: tag,
|
|
101
|
+
slug: "/category/" + (0, lodash_1.kebabCase)(tag),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
96
104
|
return {
|
|
97
105
|
type: "category",
|
|
98
106
|
label: tag,
|
|
@@ -117,9 +125,10 @@ function groupByTags(items, sidebarOptions, options, tags) {
|
|
|
117
125
|
// .map(createDocItem),
|
|
118
126
|
// },
|
|
119
127
|
// ];
|
|
120
|
-
// Shift intro doc to top of sidebar
|
|
121
|
-
|
|
122
|
-
|
|
128
|
+
// Shift root intro doc to top of sidebar
|
|
129
|
+
// TODO: Add input validation for categoryLinkSource options
|
|
130
|
+
if (rootIntroDoc && categoryLinkSource !== "info") {
|
|
131
|
+
tagged.unshift(rootIntroDoc);
|
|
123
132
|
}
|
|
124
133
|
return [...tagged];
|
|
125
134
|
}
|
package/lib/types.d.ts
CHANGED
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-354",
|
|
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": "14f792796067d499c5d244976da0f3adcdbbb383"
|
|
64
64
|
}
|
package/src/index.ts
CHANGED
|
@@ -155,7 +155,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
155
155
|
if (item.type === "info") {
|
|
156
156
|
if (!fs.existsSync(`${outputDir}/${item.id}.info.mdx`)) {
|
|
157
157
|
try {
|
|
158
|
-
sidebarOptions?.
|
|
158
|
+
sidebarOptions?.categoryLinkSource === "info" // Only use utils template if set to "info"
|
|
159
159
|
? fs.writeFileSync(
|
|
160
160
|
`${outputDir}/${item.id}.info.mdx`,
|
|
161
161
|
utils,
|
package/src/sidebars/index.ts
CHANGED
|
@@ -43,7 +43,6 @@ function groupByTags(
|
|
|
43
43
|
customProps,
|
|
44
44
|
categoryLinkSource,
|
|
45
45
|
} = sidebarOptions;
|
|
46
|
-
const linkSource = categoryLinkSource ?? "tag";
|
|
47
46
|
|
|
48
47
|
const apiItems = items.filter(isApiItem);
|
|
49
48
|
const infoItems = items.filter(isInfoItem);
|
|
@@ -57,7 +56,7 @@ function groupByTags(
|
|
|
57
56
|
});
|
|
58
57
|
|
|
59
58
|
// TODO: make sure we only take the first tag
|
|
60
|
-
const
|
|
59
|
+
const apiTags = uniq(
|
|
61
60
|
apiItems
|
|
62
61
|
.flatMap((item) => item.api.tags)
|
|
63
62
|
.filter((item): item is string => !!item)
|
|
@@ -87,19 +86,19 @@ function groupByTags(
|
|
|
87
86
|
};
|
|
88
87
|
}
|
|
89
88
|
|
|
90
|
-
let
|
|
91
|
-
if (
|
|
89
|
+
let rootIntroDoc = undefined;
|
|
90
|
+
if (infoItems.length === 1) {
|
|
92
91
|
const infoItem = infoItems[0];
|
|
93
92
|
const id = infoItem.id;
|
|
94
|
-
|
|
93
|
+
rootIntroDoc = {
|
|
95
94
|
type: "doc" as const,
|
|
96
95
|
id: `${basePath}/${id}`,
|
|
97
96
|
};
|
|
98
97
|
}
|
|
99
98
|
|
|
100
|
-
const tagged =
|
|
99
|
+
const tagged = apiTags
|
|
101
100
|
.map((tag) => {
|
|
102
|
-
//
|
|
101
|
+
// Map info object to tag
|
|
103
102
|
const infoObject = intros.find((i) => i.tags.includes(tag));
|
|
104
103
|
const tagObject = tags.flat().find(
|
|
105
104
|
(t) =>
|
|
@@ -109,16 +108,17 @@ function groupByTags(
|
|
|
109
108
|
}
|
|
110
109
|
);
|
|
111
110
|
|
|
112
|
-
// TODO: perhaps move
|
|
111
|
+
// TODO: perhaps move this into a getLinkConfig() function
|
|
113
112
|
let linkConfig = undefined;
|
|
114
|
-
if (infoObject !== undefined &&
|
|
113
|
+
if (infoObject !== undefined && categoryLinkSource === "info") {
|
|
115
114
|
linkConfig = {
|
|
116
115
|
type: "doc",
|
|
117
116
|
id: `${basePath}/${infoObject.id}`,
|
|
118
117
|
} as SidebarItemCategoryLinkConfig;
|
|
119
118
|
}
|
|
120
119
|
|
|
121
|
-
|
|
120
|
+
// TODO: perhaps move this into a getLinkConfig() function
|
|
121
|
+
if (tagObject !== undefined && categoryLinkSource === "tag") {
|
|
122
122
|
const linkDescription = tagObject?.description;
|
|
123
123
|
linkConfig = {
|
|
124
124
|
type: "generated-index" as "generated-index",
|
|
@@ -128,6 +128,15 @@ function groupByTags(
|
|
|
128
128
|
} as SidebarItemCategoryLinkConfig;
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
// Default behavior
|
|
132
|
+
if (categoryLinkSource === undefined) {
|
|
133
|
+
linkConfig = {
|
|
134
|
+
type: "generated-index" as "generated-index",
|
|
135
|
+
title: tag,
|
|
136
|
+
slug: "/category/" + kebabCase(tag),
|
|
137
|
+
} as SidebarItemCategoryLinkConfig;
|
|
138
|
+
}
|
|
139
|
+
|
|
131
140
|
return {
|
|
132
141
|
type: "category" as const,
|
|
133
142
|
label: tag,
|
|
@@ -154,9 +163,10 @@ function groupByTags(
|
|
|
154
163
|
// },
|
|
155
164
|
// ];
|
|
156
165
|
|
|
157
|
-
// Shift intro doc to top of sidebar
|
|
158
|
-
|
|
159
|
-
|
|
166
|
+
// Shift root intro doc to top of sidebar
|
|
167
|
+
// TODO: Add input validation for categoryLinkSource options
|
|
168
|
+
if (rootIntroDoc && categoryLinkSource !== "info") {
|
|
169
|
+
tagged.unshift(rootIntroDoc as any);
|
|
160
170
|
}
|
|
161
171
|
|
|
162
172
|
return [...tagged];
|
package/src/types.ts
CHANGED
|
@@ -90,7 +90,6 @@ export interface ApiNavLink {
|
|
|
90
90
|
|
|
91
91
|
export interface SidebarOptions {
|
|
92
92
|
groupPathsBy?: string;
|
|
93
|
-
useInfoAsCategoryLink?: boolean; // TODO: confirm name of option
|
|
94
93
|
categoryLinkSource?: string;
|
|
95
94
|
customProps?: { [key: string]: unknown };
|
|
96
95
|
sidebarCollapsible?: boolean;
|