docusaurus-plugin-openapi-docs 0.0.0-507 → 0.0.0-514
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/openapi/openapi.js +50 -42
- package/lib/sidebars/index.js +5 -1
- package/package.json +2 -2
- package/src/openapi/openapi.ts +47 -35
- package/src/sidebars/index.ts +5 -1
package/lib/openapi/openapi.js
CHANGED
|
@@ -19,6 +19,7 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
|
19
19
|
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
20
20
|
const kebabCase_1 = __importDefault(require("lodash/kebabCase"));
|
|
21
21
|
const unionBy_1 = __importDefault(require("lodash/unionBy"));
|
|
22
|
+
const uniq_1 = __importDefault(require("lodash/uniq"));
|
|
22
23
|
const index_1 = require("../index");
|
|
23
24
|
const createRequestExample_1 = require("./createRequestExample");
|
|
24
25
|
const loadAndResolveSpec_1 = require("./utils/loadAndResolveSpec");
|
|
@@ -64,41 +65,9 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
64
65
|
// TODO: Find a better way to handle this
|
|
65
66
|
let items = [];
|
|
66
67
|
const infoId = (0, kebabCase_1.default)(openapiData.info.title);
|
|
67
|
-
if ((sidebarOptions === null || sidebarOptions === void 0 ? void 0 : sidebarOptions.categoryLinkSource) === "tag") {
|
|
68
|
-
// Only create an tag pages if categoryLinkSource set to tag.
|
|
69
|
-
const tags = (_a = openapiData.tags) !== null && _a !== void 0 ? _a : [];
|
|
70
|
-
// eslint-disable-next-line array-callback-return
|
|
71
|
-
tags
|
|
72
|
-
.filter((tag) => { var _a; return !((_a = tag.description) === null || _a === void 0 ? void 0 : _a.includes("SchemaDefinition")); })
|
|
73
|
-
// eslint-disable-next-line array-callback-return
|
|
74
|
-
.map((tag) => {
|
|
75
|
-
var _a;
|
|
76
|
-
const description = getTagDisplayName(tag.name, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []);
|
|
77
|
-
const tagId = (0, kebabCase_1.default)(tag.name);
|
|
78
|
-
const splitDescription = description.match(/[^\r\n]+/g);
|
|
79
|
-
const tagPage = {
|
|
80
|
-
type: "tag",
|
|
81
|
-
id: tagId,
|
|
82
|
-
unversionedId: tagId,
|
|
83
|
-
title: description !== null && description !== void 0 ? description : "",
|
|
84
|
-
description: description !== null && description !== void 0 ? description : "",
|
|
85
|
-
frontMatter: {
|
|
86
|
-
description: splitDescription
|
|
87
|
-
? splitDescription[0]
|
|
88
|
-
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
89
|
-
.replace(/\s+$/, "")
|
|
90
|
-
: "",
|
|
91
|
-
},
|
|
92
|
-
tag: {
|
|
93
|
-
...tag,
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
items.push(tagPage);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
68
|
if (openapiData.info.description) {
|
|
100
69
|
// Only create an info page if we have a description.
|
|
101
|
-
const infoDescription = (
|
|
70
|
+
const infoDescription = (_a = openapiData.info) === null || _a === void 0 ? void 0 : _a.description;
|
|
102
71
|
let splitDescription;
|
|
103
72
|
if (infoDescription) {
|
|
104
73
|
splitDescription = infoDescription.match(/[^\r\n]+/g);
|
|
@@ -120,11 +89,11 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
120
89
|
.replace(/\s+$/, "")
|
|
121
90
|
: "",
|
|
122
91
|
},
|
|
123
|
-
securitySchemes: (
|
|
92
|
+
securitySchemes: (_b = openapiData.components) === null || _b === void 0 ? void 0 : _b.securitySchemes,
|
|
124
93
|
info: {
|
|
125
94
|
...openapiData.info,
|
|
126
95
|
tags: openapiData.tags,
|
|
127
|
-
title: (
|
|
96
|
+
title: (_c = openapiData.info.title) !== null && _c !== void 0 ? _c : "Introduction",
|
|
128
97
|
logo: openapiData.info["x-logo"],
|
|
129
98
|
darkLogo: openapiData.info["x-dark-logo"],
|
|
130
99
|
},
|
|
@@ -134,18 +103,18 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
134
103
|
for (let [path, pathObject] of Object.entries(openapiData.paths)) {
|
|
135
104
|
const { $ref, description, parameters, servers, summary, ...rest } = pathObject;
|
|
136
105
|
for (let [method, operationObject] of Object.entries({ ...rest })) {
|
|
137
|
-
const title = (
|
|
106
|
+
const title = (_e = (_d = operationObject.summary) !== null && _d !== void 0 ? _d : operationObject.operationId) !== null && _e !== void 0 ? _e : "Missing summary";
|
|
138
107
|
if (operationObject.description === undefined) {
|
|
139
108
|
operationObject.description =
|
|
140
|
-
(
|
|
109
|
+
(_g = (_f = operationObject.summary) !== null && _f !== void 0 ? _f : operationObject.operationId) !== null && _g !== void 0 ? _g : "";
|
|
141
110
|
}
|
|
142
111
|
const baseId = operationObject.operationId
|
|
143
112
|
? (0, kebabCase_1.default)(operationObject.operationId)
|
|
144
113
|
: (0, kebabCase_1.default)(operationObject.summary);
|
|
145
|
-
const servers = (
|
|
146
|
-
const security = (
|
|
114
|
+
const servers = (_j = (_h = operationObject.servers) !== null && _h !== void 0 ? _h : pathObject.servers) !== null && _j !== void 0 ? _j : openapiData.servers;
|
|
115
|
+
const security = (_k = operationObject.security) !== null && _k !== void 0 ? _k : openapiData.security;
|
|
147
116
|
// Add security schemes so we know how to handle security.
|
|
148
|
-
const securitySchemes = (
|
|
117
|
+
const securitySchemes = (_l = openapiData.components) === null || _l === void 0 ? void 0 : _l.securitySchemes;
|
|
149
118
|
// Make sure schemes are lowercase. See: https://github.com/cloud-annotations/docusaurus-plugin-openapi/issues/79
|
|
150
119
|
if (securitySchemes) {
|
|
151
120
|
for (let securityScheme of Object.values(securitySchemes)) {
|
|
@@ -155,12 +124,12 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
155
124
|
}
|
|
156
125
|
}
|
|
157
126
|
let jsonRequestBodyExample;
|
|
158
|
-
const body = (
|
|
127
|
+
const body = (_o = (_m = operationObject.requestBody) === null || _m === void 0 ? void 0 : _m.content) === null || _o === void 0 ? void 0 : _o["application/json"];
|
|
159
128
|
if (body === null || body === void 0 ? void 0 : body.schema) {
|
|
160
129
|
jsonRequestBodyExample = (0, createRequestExample_1.sampleRequestFromSchema)(body.schema);
|
|
161
130
|
}
|
|
162
131
|
// Handle vendor JSON media types
|
|
163
|
-
const bodyContent = (
|
|
132
|
+
const bodyContent = (_p = operationObject.requestBody) === null || _p === void 0 ? void 0 : _p.content;
|
|
164
133
|
if (bodyContent) {
|
|
165
134
|
const firstBodyContentKey = Object.keys(bodyContent)[0];
|
|
166
135
|
if (firstBodyContentKey.endsWith("+json")) {
|
|
@@ -218,6 +187,45 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
218
187
|
items.push(apiPage);
|
|
219
188
|
}
|
|
220
189
|
}
|
|
190
|
+
if ((sidebarOptions === null || sidebarOptions === void 0 ? void 0 : sidebarOptions.categoryLinkSource) === "tag") {
|
|
191
|
+
// Get global tags
|
|
192
|
+
const tags = (_q = openapiData.tags) !== null && _q !== void 0 ? _q : [];
|
|
193
|
+
// Get operation tags
|
|
194
|
+
const apiItems = items.filter((item) => {
|
|
195
|
+
return item.type === "api";
|
|
196
|
+
});
|
|
197
|
+
const operationTags = (0, uniq_1.default)(apiItems
|
|
198
|
+
.flatMap((item) => item.api.tags)
|
|
199
|
+
.filter((item) => !!item));
|
|
200
|
+
// eslint-disable-next-line array-callback-return
|
|
201
|
+
tags
|
|
202
|
+
.filter((tag) => operationTags.includes(tag.name)) // include only tags referenced by operation
|
|
203
|
+
// eslint-disable-next-line array-callback-return
|
|
204
|
+
.map((tag) => {
|
|
205
|
+
var _a;
|
|
206
|
+
const description = getTagDisplayName(tag.name, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []);
|
|
207
|
+
const tagId = (0, kebabCase_1.default)(tag.name);
|
|
208
|
+
const splitDescription = description.match(/[^\r\n]+/g);
|
|
209
|
+
const tagPage = {
|
|
210
|
+
type: "tag",
|
|
211
|
+
id: tagId,
|
|
212
|
+
unversionedId: tagId,
|
|
213
|
+
title: description !== null && description !== void 0 ? description : "",
|
|
214
|
+
description: description !== null && description !== void 0 ? description : "",
|
|
215
|
+
frontMatter: {
|
|
216
|
+
description: splitDescription
|
|
217
|
+
? splitDescription[0]
|
|
218
|
+
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
219
|
+
.replace(/\s+$/, "")
|
|
220
|
+
: "",
|
|
221
|
+
},
|
|
222
|
+
tag: {
|
|
223
|
+
...tag,
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
items.push(tagPage);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
221
229
|
return items;
|
|
222
230
|
}
|
|
223
231
|
/**
|
package/lib/sidebars/index.js
CHANGED
|
@@ -38,9 +38,13 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
38
38
|
.flatMap((item) => item.api.tags)
|
|
39
39
|
.filter((item) => !!item));
|
|
40
40
|
// Combine globally defined tags with operation tags
|
|
41
|
+
// Only include global tag if referenced in operation tags
|
|
41
42
|
let apiTags = [];
|
|
42
43
|
tags.flat().forEach((tag) => {
|
|
43
|
-
|
|
44
|
+
// Should we also check x-displayName?
|
|
45
|
+
if (operationTags.includes(tag.name)) {
|
|
46
|
+
apiTags.push(tag.name);
|
|
47
|
+
}
|
|
44
48
|
});
|
|
45
49
|
apiTags = (0, uniq_1.default)(apiTags.concat(operationTags));
|
|
46
50
|
const basePath = docPath
|
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-514",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"engines": {
|
|
69
69
|
"node": ">=14"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "a8ae6e77f423af14fbba19dbb966b46a0a0dc39f"
|
|
72
72
|
}
|
package/src/openapi/openapi.ts
CHANGED
|
@@ -16,6 +16,7 @@ import fs from "fs-extra";
|
|
|
16
16
|
import cloneDeep from "lodash/cloneDeep";
|
|
17
17
|
import kebabCase from "lodash/kebabCase";
|
|
18
18
|
import unionBy from "lodash/unionBy";
|
|
19
|
+
import uniq from "lodash/uniq";
|
|
19
20
|
|
|
20
21
|
import { isURL } from "../index";
|
|
21
22
|
import {
|
|
@@ -85,41 +86,6 @@ function createItems(
|
|
|
85
86
|
let items: PartialPage<ApiMetadata>[] = [];
|
|
86
87
|
const infoId = kebabCase(openapiData.info.title);
|
|
87
88
|
|
|
88
|
-
if (sidebarOptions?.categoryLinkSource === "tag") {
|
|
89
|
-
// Only create an tag pages if categoryLinkSource set to tag.
|
|
90
|
-
const tags: TagObject[] = openapiData.tags ?? [];
|
|
91
|
-
// eslint-disable-next-line array-callback-return
|
|
92
|
-
tags
|
|
93
|
-
.filter((tag) => !tag.description?.includes("SchemaDefinition"))
|
|
94
|
-
// eslint-disable-next-line array-callback-return
|
|
95
|
-
.map((tag) => {
|
|
96
|
-
const description = getTagDisplayName(
|
|
97
|
-
tag.name!,
|
|
98
|
-
openapiData.tags ?? []
|
|
99
|
-
);
|
|
100
|
-
const tagId = kebabCase(tag.name);
|
|
101
|
-
const splitDescription = description.match(/[^\r\n]+/g);
|
|
102
|
-
const tagPage: PartialPage<TagPageMetadata> = {
|
|
103
|
-
type: "tag",
|
|
104
|
-
id: tagId,
|
|
105
|
-
unversionedId: tagId,
|
|
106
|
-
title: description ?? "",
|
|
107
|
-
description: description ?? "",
|
|
108
|
-
frontMatter: {
|
|
109
|
-
description: splitDescription
|
|
110
|
-
? splitDescription[0]
|
|
111
|
-
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
112
|
-
.replace(/\s+$/, "")
|
|
113
|
-
: "",
|
|
114
|
-
},
|
|
115
|
-
tag: {
|
|
116
|
-
...tag,
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
items.push(tagPage);
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
89
|
if (openapiData.info.description) {
|
|
124
90
|
// Only create an info page if we have a description.
|
|
125
91
|
const infoDescription = openapiData.info?.description;
|
|
@@ -270,6 +236,52 @@ function createItems(
|
|
|
270
236
|
}
|
|
271
237
|
}
|
|
272
238
|
|
|
239
|
+
if (sidebarOptions?.categoryLinkSource === "tag") {
|
|
240
|
+
// Get global tags
|
|
241
|
+
const tags: TagObject[] = openapiData.tags ?? [];
|
|
242
|
+
|
|
243
|
+
// Get operation tags
|
|
244
|
+
const apiItems = items.filter((item) => {
|
|
245
|
+
return item.type === "api";
|
|
246
|
+
}) as ApiPageMetadata[];
|
|
247
|
+
const operationTags = uniq(
|
|
248
|
+
apiItems
|
|
249
|
+
.flatMap((item) => item.api.tags)
|
|
250
|
+
.filter((item): item is string => !!item)
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
// eslint-disable-next-line array-callback-return
|
|
254
|
+
tags
|
|
255
|
+
.filter((tag) => operationTags.includes(tag.name!)) // include only tags referenced by operation
|
|
256
|
+
// eslint-disable-next-line array-callback-return
|
|
257
|
+
.map((tag) => {
|
|
258
|
+
const description = getTagDisplayName(
|
|
259
|
+
tag.name!,
|
|
260
|
+
openapiData.tags ?? []
|
|
261
|
+
);
|
|
262
|
+
const tagId = kebabCase(tag.name);
|
|
263
|
+
const splitDescription = description.match(/[^\r\n]+/g);
|
|
264
|
+
const tagPage: PartialPage<TagPageMetadata> = {
|
|
265
|
+
type: "tag",
|
|
266
|
+
id: tagId,
|
|
267
|
+
unversionedId: tagId,
|
|
268
|
+
title: description ?? "",
|
|
269
|
+
description: description ?? "",
|
|
270
|
+
frontMatter: {
|
|
271
|
+
description: splitDescription
|
|
272
|
+
? splitDescription[0]
|
|
273
|
+
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
274
|
+
.replace(/\s+$/, "")
|
|
275
|
+
: "",
|
|
276
|
+
},
|
|
277
|
+
tag: {
|
|
278
|
+
...tag,
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
items.push(tagPage);
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
|
|
273
285
|
return items as ApiMetadata[];
|
|
274
286
|
}
|
|
275
287
|
|
package/src/sidebars/index.ts
CHANGED
|
@@ -68,9 +68,13 @@ function groupByTags(
|
|
|
68
68
|
);
|
|
69
69
|
|
|
70
70
|
// Combine globally defined tags with operation tags
|
|
71
|
+
// Only include global tag if referenced in operation tags
|
|
71
72
|
let apiTags: string[] = [];
|
|
72
73
|
tags.flat().forEach((tag) => {
|
|
73
|
-
|
|
74
|
+
// Should we also check x-displayName?
|
|
75
|
+
if (operationTags.includes(tag.name!)) {
|
|
76
|
+
apiTags.push(tag.name!);
|
|
77
|
+
}
|
|
74
78
|
});
|
|
75
79
|
apiTags = uniq(apiTags.concat(operationTags));
|
|
76
80
|
|