docusaurus-plugin-openapi-docs 0.0.0-352 → 0.0.0-355
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 +7 -6
- package/lib/index.js +1 -1
- package/lib/markdown/createContactInfo.js +6 -6
- package/lib/markdown/createLicense.js +4 -4
- package/lib/markdown/createTermsOfService.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/markdown/createContactInfo.ts +20 -16
- package/src/markdown/createLicense.ts +8 -6
- package/src/markdown/createTermsOfService.ts +1 -1
- package/src/sidebars/index.ts +23 -13
- package/src/types.ts +0 -1
package/README.md
CHANGED
|
@@ -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 "tags".
|
|
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 "tags". |
|
|
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/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"`));
|
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.createContactInfo = void 0;
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
11
|
function createContactInfo(contact) {
|
|
12
|
-
if (!contact)
|
|
12
|
+
if (!contact || !Object.keys(contact).length)
|
|
13
13
|
return "";
|
|
14
14
|
const { name, url, email } = contact;
|
|
15
15
|
return (0, utils_1.create)("div", {
|
|
@@ -27,14 +27,14 @@ function createContactInfo(contact) {
|
|
|
27
27
|
}),
|
|
28
28
|
(0, utils_1.create)("span", {
|
|
29
29
|
children: [
|
|
30
|
-
`${name}:
|
|
31
|
-
(0, utils_1.create)("a", {
|
|
30
|
+
(0, utils_1.guard)(name, () => `${name}: `),
|
|
31
|
+
(0, utils_1.guard)(email, () => (0, utils_1.create)("a", {
|
|
32
32
|
href: `mailto:${email}`,
|
|
33
33
|
children: `${email}`,
|
|
34
|
-
}),
|
|
34
|
+
})),
|
|
35
35
|
],
|
|
36
36
|
}),
|
|
37
|
-
(0, utils_1.create)("span", {
|
|
37
|
+
(0, utils_1.guard)(url, () => (0, utils_1.create)("span", {
|
|
38
38
|
children: [
|
|
39
39
|
"URL: ",
|
|
40
40
|
(0, utils_1.create)("a", {
|
|
@@ -42,7 +42,7 @@ function createContactInfo(contact) {
|
|
|
42
42
|
children: `${url}`,
|
|
43
43
|
}),
|
|
44
44
|
],
|
|
45
|
-
}),
|
|
45
|
+
})),
|
|
46
46
|
],
|
|
47
47
|
});
|
|
48
48
|
}
|
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.createLicense = void 0;
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
11
|
function createLicense(license) {
|
|
12
|
-
if (!license)
|
|
12
|
+
if (!license || !Object.keys(license).length)
|
|
13
13
|
return "";
|
|
14
14
|
const { name, url } = license;
|
|
15
15
|
return (0, utils_1.create)("div", {
|
|
@@ -23,10 +23,10 @@ function createLicense(license) {
|
|
|
23
23
|
},
|
|
24
24
|
children: "License",
|
|
25
25
|
}),
|
|
26
|
-
(0, utils_1.create)("a", {
|
|
26
|
+
(0, utils_1.guard)(url, () => (0, utils_1.create)("a", {
|
|
27
27
|
href: url,
|
|
28
|
-
children: name,
|
|
29
|
-
}),
|
|
28
|
+
children: name !== null && name !== void 0 ? name : url,
|
|
29
|
+
})),
|
|
30
30
|
],
|
|
31
31
|
});
|
|
32
32
|
}
|
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.createTermsOfService = void 0;
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
11
|
function createTermsOfService(termsOfService) {
|
|
12
|
-
if (!
|
|
12
|
+
if (!termsOfService)
|
|
13
13
|
return "";
|
|
14
14
|
return (0, utils_1.create)("div", {
|
|
15
15
|
style: {
|
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-355",
|
|
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": "7b46d0266d04d1e64a5ae9025a2dd3452bca492c"
|
|
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,
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
8
|
import { ContactObject } from "../openapi/types";
|
|
9
|
-
import { create } from "./utils";
|
|
9
|
+
import { create, guard } from "./utils";
|
|
10
10
|
|
|
11
11
|
export function createContactInfo(contact: ContactObject) {
|
|
12
|
-
if (!contact) return "";
|
|
12
|
+
if (!contact || !Object.keys(contact).length) return "";
|
|
13
13
|
const { name, url, email } = contact;
|
|
14
14
|
|
|
15
15
|
return create("div", {
|
|
@@ -27,22 +27,26 @@ export function createContactInfo(contact: ContactObject) {
|
|
|
27
27
|
}),
|
|
28
28
|
create("span", {
|
|
29
29
|
children: [
|
|
30
|
-
`${name}:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
create("span", {
|
|
38
|
-
children: [
|
|
39
|
-
"URL: ",
|
|
40
|
-
create("a", {
|
|
41
|
-
href: `${url}`,
|
|
42
|
-
children: `${url}`,
|
|
43
|
-
}),
|
|
30
|
+
guard(name, () => `${name}: `),
|
|
31
|
+
guard(email, () =>
|
|
32
|
+
create("a", {
|
|
33
|
+
href: `mailto:${email}`,
|
|
34
|
+
children: `${email}`,
|
|
35
|
+
})
|
|
36
|
+
),
|
|
44
37
|
],
|
|
45
38
|
}),
|
|
39
|
+
guard(url, () =>
|
|
40
|
+
create("span", {
|
|
41
|
+
children: [
|
|
42
|
+
"URL: ",
|
|
43
|
+
create("a", {
|
|
44
|
+
href: `${url}`,
|
|
45
|
+
children: `${url}`,
|
|
46
|
+
}),
|
|
47
|
+
],
|
|
48
|
+
})
|
|
49
|
+
),
|
|
46
50
|
],
|
|
47
51
|
});
|
|
48
52
|
}
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
8
|
import { LicenseObject } from "../openapi/types";
|
|
9
|
-
import { create } from "./utils";
|
|
9
|
+
import { create, guard } from "./utils";
|
|
10
10
|
|
|
11
11
|
export function createLicense(license: LicenseObject) {
|
|
12
|
-
if (!license) return "";
|
|
12
|
+
if (!license || !Object.keys(license).length) return "";
|
|
13
13
|
const { name, url } = license;
|
|
14
14
|
|
|
15
15
|
return create("div", {
|
|
@@ -23,10 +23,12 @@ export function createLicense(license: LicenseObject) {
|
|
|
23
23
|
},
|
|
24
24
|
children: "License",
|
|
25
25
|
}),
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
guard(url, () =>
|
|
27
|
+
create("a", {
|
|
28
|
+
href: url,
|
|
29
|
+
children: name ?? url,
|
|
30
|
+
})
|
|
31
|
+
),
|
|
30
32
|
],
|
|
31
33
|
});
|
|
32
34
|
}
|
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;
|