docusaurus-plugin-openapi-docs 0.0.0-354 → 0.0.0-359
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 +8 -7
- package/lib/sidebars/index.js +23 -17
- package/package.json +2 -2
- package/src/sidebars/index.ts +26 -17
package/README.md
CHANGED
|
@@ -80,7 +80,7 @@ Here is an example of properly configuring your `docusaurus.config.js` file for
|
|
|
80
80
|
specPath: "examples/petstore.yaml", // Path to designated spec file
|
|
81
81
|
outputDir: "api/petstore", // Output directory for generated .mdx docs
|
|
82
82
|
sidebarOptions: {
|
|
83
|
-
groupPathsBy: "
|
|
83
|
+
groupPathsBy: "tag",
|
|
84
84
|
},
|
|
85
85
|
},
|
|
86
86
|
burgers: {
|
|
@@ -110,12 +110,13 @@ Here is an example of properly configuring your `docusaurus.config.js` file for
|
|
|
110
110
|
|
|
111
111
|
`sidebarOptions` can be configured with the following options:
|
|
112
112
|
|
|
113
|
-
| Name | Type | Default | Description
|
|
114
|
-
| -------------------- | --------- | ------- |
|
|
115
|
-
| `groupPathsBy` | `string` | `null` | Organize and group sidebar slice by specified option. Note: Currently, `groupPathsBy` only contains support for grouping by
|
|
116
|
-
| `
|
|
117
|
-
| `
|
|
118
|
-
| `
|
|
113
|
+
| Name | Type | Default | Description |
|
|
114
|
+
| -------------------- | --------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
115
|
+
| `groupPathsBy` | `string` | `null` | Organize and group sidebar slice by specified option. Note: Currently, `groupPathsBy` only contains support for grouping by `tag`. |
|
|
116
|
+
| `categoryLinkSource` | `string` | `null` | Defines what source to use for rendering category link pages when grouping paths by tag. <br/></br>The supported options are as follows: <br/></br> `tag`: Sets the category link config type to `generated-index` and uses the tag description as the link config description. <br/><br/>`info`: Sets the category link config type to `doc` and renders the `info` section as the category link (recommended only for multi/micro-spec scenarios). |
|
|
117
|
+
| `sidebarCollapsible` | `boolean` | `true` | Whether sidebar categories are collapsible by default. |
|
|
118
|
+
| `sidebarCollapsed` | `boolean` | `true` | Whether sidebar categories are collapsed by default. |
|
|
119
|
+
| `customProps` | `object` | `null` | Additional props for customizing a sidebar item. |
|
|
119
120
|
|
|
120
121
|
> Note: You may optionally configure a `sidebarOptions`. In doing so, an individual `sidebar.js` slice with the configured options will be generated within the respective `outputDir`.
|
|
121
122
|
|
package/lib/sidebars/index.js
CHANGED
|
@@ -67,7 +67,7 @@ function groupByTags(items, sidebarOptions, options, tags) {
|
|
|
67
67
|
const tagged = apiTags
|
|
68
68
|
.map((tag) => {
|
|
69
69
|
// Map info object to tag
|
|
70
|
-
const
|
|
70
|
+
const taggedInfoObject = intros.find((i) => i.tags ? i.tags.includes(tag) : undefined);
|
|
71
71
|
const tagObject = tags.flat().find((t) => {
|
|
72
72
|
var _a;
|
|
73
73
|
return (_a = (tag === t.name || tag === t["x-displayName"])) !== null && _a !== void 0 ? _a : {
|
|
@@ -77,10 +77,10 @@ function groupByTags(items, sidebarOptions, options, tags) {
|
|
|
77
77
|
});
|
|
78
78
|
// TODO: perhaps move this into a getLinkConfig() function
|
|
79
79
|
let linkConfig = undefined;
|
|
80
|
-
if (
|
|
80
|
+
if (taggedInfoObject !== undefined && categoryLinkSource === "info") {
|
|
81
81
|
linkConfig = {
|
|
82
82
|
type: "doc",
|
|
83
|
-
id: `${basePath}/${
|
|
83
|
+
id: `${basePath}/${taggedInfoObject.id}`,
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
86
|
// TODO: perhaps move this into a getLinkConfig() function
|
|
@@ -113,28 +113,34 @@ function groupByTags(items, sidebarOptions, options, tags) {
|
|
|
113
113
|
};
|
|
114
114
|
})
|
|
115
115
|
.filter((item) => item.items.length > 0); // Filter out any categories with no items.
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
116
|
+
// Handle items with no tag
|
|
117
|
+
const untaggedItems = apiItems
|
|
118
|
+
.filter(({ api }) => api.tags === undefined || api.tags.length === 0)
|
|
119
|
+
.map(createDocItem);
|
|
120
|
+
let untagged = [];
|
|
121
|
+
if (untaggedItems.length > 0) {
|
|
122
|
+
untagged = [
|
|
123
|
+
{
|
|
124
|
+
type: "category",
|
|
125
|
+
label: "UNTAGGED",
|
|
126
|
+
collapsible: sidebarCollapsible,
|
|
127
|
+
collapsed: sidebarCollapsed,
|
|
128
|
+
items: apiItems
|
|
129
|
+
.filter(({ api }) => api.tags === undefined || api.tags.length === 0)
|
|
130
|
+
.map(createDocItem),
|
|
131
|
+
},
|
|
132
|
+
];
|
|
133
|
+
}
|
|
128
134
|
// Shift root intro doc to top of sidebar
|
|
129
135
|
// TODO: Add input validation for categoryLinkSource options
|
|
130
136
|
if (rootIntroDoc && categoryLinkSource !== "info") {
|
|
131
137
|
tagged.unshift(rootIntroDoc);
|
|
132
138
|
}
|
|
133
|
-
return [...tagged];
|
|
139
|
+
return [...tagged, ...untagged];
|
|
134
140
|
}
|
|
135
141
|
function generateSidebarSlice(sidebarOptions, options, api, tags) {
|
|
136
142
|
let sidebarSlice = [];
|
|
137
|
-
if (sidebarOptions.groupPathsBy === "
|
|
143
|
+
if (sidebarOptions.groupPathsBy === "tag") {
|
|
138
144
|
sidebarSlice = groupByTags(api, sidebarOptions, options, tags);
|
|
139
145
|
}
|
|
140
146
|
return sidebarSlice;
|
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-359",
|
|
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": "ec537d885e9432e381404f0b741b70b3156766d2"
|
|
64
64
|
}
|
package/src/sidebars/index.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import {
|
|
9
9
|
ProcessedSidebar,
|
|
10
|
+
SidebarItemCategory,
|
|
10
11
|
SidebarItemCategoryLinkConfig,
|
|
11
12
|
SidebarItemDoc,
|
|
12
13
|
} from "@docusaurus/plugin-content-docs/src/sidebars/types";
|
|
@@ -99,7 +100,9 @@ function groupByTags(
|
|
|
99
100
|
const tagged = apiTags
|
|
100
101
|
.map((tag) => {
|
|
101
102
|
// Map info object to tag
|
|
102
|
-
const
|
|
103
|
+
const taggedInfoObject = intros.find((i) =>
|
|
104
|
+
i.tags ? i.tags.includes(tag) : undefined
|
|
105
|
+
);
|
|
103
106
|
const tagObject = tags.flat().find(
|
|
104
107
|
(t) =>
|
|
105
108
|
(tag === t.name || tag === t["x-displayName"]) ?? {
|
|
@@ -110,10 +113,10 @@ function groupByTags(
|
|
|
110
113
|
|
|
111
114
|
// TODO: perhaps move this into a getLinkConfig() function
|
|
112
115
|
let linkConfig = undefined;
|
|
113
|
-
if (
|
|
116
|
+
if (taggedInfoObject !== undefined && categoryLinkSource === "info") {
|
|
114
117
|
linkConfig = {
|
|
115
118
|
type: "doc",
|
|
116
|
-
id: `${basePath}/${
|
|
119
|
+
id: `${basePath}/${taggedInfoObject.id}`,
|
|
117
120
|
} as SidebarItemCategoryLinkConfig;
|
|
118
121
|
}
|
|
119
122
|
|
|
@@ -150,18 +153,24 @@ function groupByTags(
|
|
|
150
153
|
})
|
|
151
154
|
.filter((item) => item.items.length > 0); // Filter out any categories with no items.
|
|
152
155
|
|
|
153
|
-
//
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
156
|
+
// Handle items with no tag
|
|
157
|
+
const untaggedItems = apiItems
|
|
158
|
+
.filter(({ api }) => api.tags === undefined || api.tags.length === 0)
|
|
159
|
+
.map(createDocItem);
|
|
160
|
+
let untagged: SidebarItemCategory[] = [];
|
|
161
|
+
if (untaggedItems.length > 0) {
|
|
162
|
+
untagged = [
|
|
163
|
+
{
|
|
164
|
+
type: "category" as const,
|
|
165
|
+
label: "UNTAGGED",
|
|
166
|
+
collapsible: sidebarCollapsible!,
|
|
167
|
+
collapsed: sidebarCollapsed!,
|
|
168
|
+
items: apiItems
|
|
169
|
+
.filter(({ api }) => api.tags === undefined || api.tags.length === 0)
|
|
170
|
+
.map(createDocItem),
|
|
171
|
+
},
|
|
172
|
+
];
|
|
173
|
+
}
|
|
165
174
|
|
|
166
175
|
// Shift root intro doc to top of sidebar
|
|
167
176
|
// TODO: Add input validation for categoryLinkSource options
|
|
@@ -169,7 +178,7 @@ function groupByTags(
|
|
|
169
178
|
tagged.unshift(rootIntroDoc as any);
|
|
170
179
|
}
|
|
171
180
|
|
|
172
|
-
return [...tagged];
|
|
181
|
+
return [...tagged, ...untagged];
|
|
173
182
|
}
|
|
174
183
|
|
|
175
184
|
export default function generateSidebarSlice(
|
|
@@ -179,7 +188,7 @@ export default function generateSidebarSlice(
|
|
|
179
188
|
tags: TagObject[]
|
|
180
189
|
) {
|
|
181
190
|
let sidebarSlice: ProcessedSidebar = [];
|
|
182
|
-
if (sidebarOptions.groupPathsBy === "
|
|
191
|
+
if (sidebarOptions.groupPathsBy === "tag") {
|
|
183
192
|
sidebarSlice = groupByTags(
|
|
184
193
|
api as ApiPageMetadata[],
|
|
185
194
|
sidebarOptions,
|