docusaurus-plugin-openapi-docs 1.4.0 → 1.4.2
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 +14 -11
- package/lib/markdown/createResponseSchema.js +2 -1
- package/lib/openapi/openapi.js +42 -13
- package/lib/sidebars/index.js +1 -1
- package/package.json +2 -2
- package/src/index.ts +18 -12
- package/src/markdown/createResponseSchema.ts +2 -1
- package/src/openapi/openapi.ts +33 -3
- package/src/sidebars/index.ts +1 -1
package/lib/index.js
CHANGED
|
@@ -27,15 +27,18 @@ function getDocsPluginConfig(presetsPlugins, pluginId) {
|
|
|
27
27
|
// eslint-disable-next-line array-callback-return
|
|
28
28
|
const filteredConfig = presetsPlugins.filter((data) => {
|
|
29
29
|
// Search presets
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
// Search plugin-content-docs instances
|
|
34
|
-
if (data[0] === "@docusaurus/plugin-content-docs") {
|
|
35
|
-
const configPluginId = data[1].id ? data[1].id : "default";
|
|
36
|
-
if (configPluginId === pluginId) {
|
|
30
|
+
if (Array.isArray(data)) {
|
|
31
|
+
if (typeof data[0] === "string" && data[0].endsWith(pluginId)) {
|
|
37
32
|
return data[1];
|
|
38
33
|
}
|
|
34
|
+
// Search plugin-content-docs instances
|
|
35
|
+
if (typeof data[0] === "string" &&
|
|
36
|
+
data[0] === "@docusaurus/plugin-content-docs") {
|
|
37
|
+
const configPluginId = data[1].id ? data[1].id : "default";
|
|
38
|
+
if (configPluginId === pluginId) {
|
|
39
|
+
return data[1];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
39
42
|
}
|
|
40
43
|
})[0];
|
|
41
44
|
if (filteredConfig) {
|
|
@@ -117,7 +120,7 @@ function pluginOpenAPIDocs(context, options) {
|
|
|
117
120
|
: `---
|
|
118
121
|
id: {{{id}}}
|
|
119
122
|
title: "{{{title}}}"
|
|
120
|
-
description: "{{{description}}}"
|
|
123
|
+
description: "{{{frontMatter.description}}}"
|
|
121
124
|
{{^api}}
|
|
122
125
|
sidebar_label: Introduction
|
|
123
126
|
{{/api}}
|
|
@@ -147,7 +150,7 @@ info_path: {{{infoPath}}}
|
|
|
147
150
|
const infoMdTemplate = `---
|
|
148
151
|
id: {{{id}}}
|
|
149
152
|
title: "{{{title}}}"
|
|
150
|
-
description: "{{{description}}}"
|
|
153
|
+
description: "{{{frontMatter.description}}}"
|
|
151
154
|
sidebar_label: {{{title}}}
|
|
152
155
|
hide_title: true
|
|
153
156
|
custom_edit_url: null
|
|
@@ -164,8 +167,8 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
164
167
|
`;
|
|
165
168
|
const tagMdTemplate = `---
|
|
166
169
|
id: {{{id}}}
|
|
167
|
-
title: "{{{description}}}"
|
|
168
|
-
description: "{{{description}}}"
|
|
170
|
+
title: "{{{frontMatter.description}}}"
|
|
171
|
+
description: "{{{frontMatter.description}}}"
|
|
169
172
|
custom_edit_url: null
|
|
170
173
|
---
|
|
171
174
|
|
|
@@ -586,7 +586,8 @@ function createResponseSchema({ title, body, ...rest }) {
|
|
|
586
586
|
value: `${mimeType}`,
|
|
587
587
|
children: [
|
|
588
588
|
(0, utils_1.create)("SchemaTabs", {
|
|
589
|
-
|
|
589
|
+
// TODO: determine if we should persist this
|
|
590
|
+
// groupId: "schema-tabs",
|
|
590
591
|
children: [
|
|
591
592
|
firstBody &&
|
|
592
593
|
(0, utils_1.create)("TabItem", {
|
package/lib/openapi/openapi.js
CHANGED
|
@@ -60,7 +60,7 @@ async function createPostmanCollection(openapiData) {
|
|
|
60
60
|
return await jsonToCollection(data);
|
|
61
61
|
}
|
|
62
62
|
function createItems(openapiData, sidebarOptions) {
|
|
63
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
63
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
64
64
|
// TODO: Find a better way to handle this
|
|
65
65
|
let items = [];
|
|
66
66
|
const infoId = (0, kebabCase_1.default)(openapiData.info.title);
|
|
@@ -75,13 +75,20 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
75
75
|
var _a;
|
|
76
76
|
const description = getTagDisplayName(tag.name, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []);
|
|
77
77
|
const tagId = (0, kebabCase_1.default)(tag.name);
|
|
78
|
+
const splitDescription = description.match(/[^\r\n]+/g);
|
|
78
79
|
const tagPage = {
|
|
79
80
|
type: "tag",
|
|
80
81
|
id: tagId,
|
|
81
82
|
unversionedId: tagId,
|
|
82
83
|
title: description !== null && description !== void 0 ? description : "",
|
|
83
84
|
description: description !== null && description !== void 0 ? description : "",
|
|
84
|
-
frontMatter: {
|
|
85
|
+
frontMatter: {
|
|
86
|
+
description: splitDescription
|
|
87
|
+
? splitDescription[0]
|
|
88
|
+
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
89
|
+
.replace(/\s+$/, "")
|
|
90
|
+
: "",
|
|
91
|
+
},
|
|
85
92
|
tag: {
|
|
86
93
|
...tag,
|
|
87
94
|
},
|
|
@@ -91,6 +98,11 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
91
98
|
}
|
|
92
99
|
if (openapiData.info.description) {
|
|
93
100
|
// Only create an info page if we have a description.
|
|
101
|
+
const infoDescription = (_b = openapiData.info) === null || _b === void 0 ? void 0 : _b.description;
|
|
102
|
+
let splitDescription;
|
|
103
|
+
if (infoDescription) {
|
|
104
|
+
splitDescription = infoDescription.match(/[^\r\n]+/g);
|
|
105
|
+
}
|
|
94
106
|
const infoPage = {
|
|
95
107
|
type: "info",
|
|
96
108
|
id: infoId,
|
|
@@ -99,12 +111,18 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
99
111
|
description: openapiData.info.description
|
|
100
112
|
? openapiData.info.description.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
101
113
|
: "",
|
|
102
|
-
frontMatter: {
|
|
103
|
-
|
|
114
|
+
frontMatter: {
|
|
115
|
+
description: splitDescription
|
|
116
|
+
? splitDescription[0]
|
|
117
|
+
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
118
|
+
.replace(/\s+$/, "")
|
|
119
|
+
: "",
|
|
120
|
+
},
|
|
121
|
+
securitySchemes: (_c = openapiData.components) === null || _c === void 0 ? void 0 : _c.securitySchemes,
|
|
104
122
|
info: {
|
|
105
123
|
...openapiData.info,
|
|
106
124
|
tags: openapiData.tags,
|
|
107
|
-
title: (
|
|
125
|
+
title: (_d = openapiData.info.title) !== null && _d !== void 0 ? _d : "Introduction",
|
|
108
126
|
logo: openapiData.info["x-logo"],
|
|
109
127
|
darkLogo: openapiData.info["x-dark-logo"],
|
|
110
128
|
},
|
|
@@ -114,18 +132,18 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
114
132
|
for (let [path, pathObject] of Object.entries(openapiData.paths)) {
|
|
115
133
|
const { $ref, description, parameters, servers, summary, ...rest } = pathObject;
|
|
116
134
|
for (let [method, operationObject] of Object.entries({ ...rest })) {
|
|
117
|
-
const title = (
|
|
135
|
+
const title = (_f = (_e = operationObject.summary) !== null && _e !== void 0 ? _e : operationObject.operationId) !== null && _f !== void 0 ? _f : "Missing summary";
|
|
118
136
|
if (operationObject.description === undefined) {
|
|
119
137
|
operationObject.description =
|
|
120
|
-
(
|
|
138
|
+
(_h = (_g = operationObject.summary) !== null && _g !== void 0 ? _g : operationObject.operationId) !== null && _h !== void 0 ? _h : "";
|
|
121
139
|
}
|
|
122
140
|
const baseId = operationObject.operationId
|
|
123
141
|
? (0, kebabCase_1.default)(operationObject.operationId)
|
|
124
142
|
: (0, kebabCase_1.default)(operationObject.summary);
|
|
125
|
-
const servers = (
|
|
126
|
-
const security = (
|
|
143
|
+
const servers = (_k = (_j = operationObject.servers) !== null && _j !== void 0 ? _j : pathObject.servers) !== null && _k !== void 0 ? _k : openapiData.servers;
|
|
144
|
+
const security = (_l = operationObject.security) !== null && _l !== void 0 ? _l : openapiData.security;
|
|
127
145
|
// Add security schemes so we know how to handle security.
|
|
128
|
-
const securitySchemes = (
|
|
146
|
+
const securitySchemes = (_m = openapiData.components) === null || _m === void 0 ? void 0 : _m.securitySchemes;
|
|
129
147
|
// Make sure schemes are lowercase. See: https://github.com/cloud-annotations/docusaurus-plugin-openapi/issues/79
|
|
130
148
|
if (securitySchemes) {
|
|
131
149
|
for (let securityScheme of Object.values(securitySchemes)) {
|
|
@@ -135,12 +153,12 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
135
153
|
}
|
|
136
154
|
}
|
|
137
155
|
let jsonRequestBodyExample;
|
|
138
|
-
const body = (
|
|
156
|
+
const body = (_p = (_o = operationObject.requestBody) === null || _o === void 0 ? void 0 : _o.content) === null || _p === void 0 ? void 0 : _p["application/json"];
|
|
139
157
|
if (body === null || body === void 0 ? void 0 : body.schema) {
|
|
140
158
|
jsonRequestBodyExample = (0, createRequestExample_1.sampleRequestFromSchema)(body.schema);
|
|
141
159
|
}
|
|
142
160
|
// Handle vendor JSON media types
|
|
143
|
-
const bodyContent = (
|
|
161
|
+
const bodyContent = (_q = operationObject.requestBody) === null || _q === void 0 ? void 0 : _q.content;
|
|
144
162
|
if (bodyContent) {
|
|
145
163
|
const firstBodyContentKey = Object.keys(bodyContent)[0];
|
|
146
164
|
if (firstBodyContentKey.endsWith("+json")) {
|
|
@@ -162,6 +180,11 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
162
180
|
defaults.parameters = parameters;
|
|
163
181
|
}
|
|
164
182
|
}
|
|
183
|
+
const opDescription = operationObject.description;
|
|
184
|
+
let splitDescription;
|
|
185
|
+
if (opDescription) {
|
|
186
|
+
splitDescription = opDescription.match(/[^\r\n]+/g);
|
|
187
|
+
}
|
|
165
188
|
const apiPage = {
|
|
166
189
|
type: "api",
|
|
167
190
|
id: baseId,
|
|
@@ -171,7 +194,13 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
171
194
|
description: operationObject.description
|
|
172
195
|
? operationObject.description.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
173
196
|
: "",
|
|
174
|
-
frontMatter: {
|
|
197
|
+
frontMatter: {
|
|
198
|
+
description: splitDescription
|
|
199
|
+
? splitDescription[0]
|
|
200
|
+
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
201
|
+
.replace(/\s+$/, "")
|
|
202
|
+
: "",
|
|
203
|
+
},
|
|
175
204
|
api: {
|
|
176
205
|
...defaults,
|
|
177
206
|
tags: operationObject.tags,
|
package/lib/sidebars/index.js
CHANGED
|
@@ -74,7 +74,7 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
74
74
|
.map((tag) => {
|
|
75
75
|
var _a;
|
|
76
76
|
// Map info object to tag
|
|
77
|
-
const taggedInfoObject = intros.find((i) => i.tags ? i.tags.
|
|
77
|
+
const taggedInfoObject = intros.find((i) => i.tags ? i.tags.find((t) => t.name === tag) : undefined);
|
|
78
78
|
const tagObject = tags.flat().find((t) => {
|
|
79
79
|
var _a;
|
|
80
80
|
return (_a = tag === t.name) !== null && _a !== void 0 ? _a : {
|
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": "1.4.
|
|
4
|
+
"version": "1.4.2",
|
|
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": "e5337f7fecf3b082c0781f798a479b2a63237432"
|
|
72
72
|
}
|
package/src/index.ts
CHANGED
|
@@ -30,18 +30,24 @@ export function getDocsPluginConfig(
|
|
|
30
30
|
// eslint-disable-next-line array-callback-return
|
|
31
31
|
const filteredConfig = presetsPlugins.filter((data) => {
|
|
32
32
|
// Search presets
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Search plugin-content-docs instances
|
|
38
|
-
if (data[0] === "@docusaurus/plugin-content-docs") {
|
|
39
|
-
const configPluginId = data[1].id ? data[1].id : "default";
|
|
40
|
-
if (configPluginId === pluginId) {
|
|
33
|
+
if (Array.isArray(data)) {
|
|
34
|
+
if (typeof data[0] === "string" && data[0].endsWith(pluginId)) {
|
|
41
35
|
return data[1];
|
|
42
36
|
}
|
|
37
|
+
|
|
38
|
+
// Search plugin-content-docs instances
|
|
39
|
+
if (
|
|
40
|
+
typeof data[0] === "string" &&
|
|
41
|
+
data[0] === "@docusaurus/plugin-content-docs"
|
|
42
|
+
) {
|
|
43
|
+
const configPluginId = data[1].id ? data[1].id : "default";
|
|
44
|
+
if (configPluginId === pluginId) {
|
|
45
|
+
return data[1];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
43
48
|
}
|
|
44
49
|
})[0];
|
|
50
|
+
|
|
45
51
|
if (filteredConfig) {
|
|
46
52
|
// Search presets, e.g. "classic"
|
|
47
53
|
if (filteredConfig[0].endsWith(pluginId)) {
|
|
@@ -153,7 +159,7 @@ export default function pluginOpenAPIDocs(
|
|
|
153
159
|
: `---
|
|
154
160
|
id: {{{id}}}
|
|
155
161
|
title: "{{{title}}}"
|
|
156
|
-
description: "{{{description}}}"
|
|
162
|
+
description: "{{{frontMatter.description}}}"
|
|
157
163
|
{{^api}}
|
|
158
164
|
sidebar_label: Introduction
|
|
159
165
|
{{/api}}
|
|
@@ -184,7 +190,7 @@ info_path: {{{infoPath}}}
|
|
|
184
190
|
const infoMdTemplate = `---
|
|
185
191
|
id: {{{id}}}
|
|
186
192
|
title: "{{{title}}}"
|
|
187
|
-
description: "{{{description}}}"
|
|
193
|
+
description: "{{{frontMatter.description}}}"
|
|
188
194
|
sidebar_label: {{{title}}}
|
|
189
195
|
hide_title: true
|
|
190
196
|
custom_edit_url: null
|
|
@@ -202,8 +208,8 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
202
208
|
|
|
203
209
|
const tagMdTemplate = `---
|
|
204
210
|
id: {{{id}}}
|
|
205
|
-
title: "{{{description}}}"
|
|
206
|
-
description: "{{{description}}}"
|
|
211
|
+
title: "{{{frontMatter.description}}}"
|
|
212
|
+
description: "{{{frontMatter.description}}}"
|
|
207
213
|
custom_edit_url: null
|
|
208
214
|
---
|
|
209
215
|
|
|
@@ -746,7 +746,8 @@ export function createResponseSchema({ title, body, ...rest }: Props) {
|
|
|
746
746
|
value: `${mimeType}`,
|
|
747
747
|
children: [
|
|
748
748
|
create("SchemaTabs", {
|
|
749
|
-
|
|
749
|
+
// TODO: determine if we should persist this
|
|
750
|
+
// groupId: "schema-tabs",
|
|
750
751
|
children: [
|
|
751
752
|
firstBody &&
|
|
752
753
|
create("TabItem", {
|
package/src/openapi/openapi.ts
CHANGED
|
@@ -98,13 +98,20 @@ function createItems(
|
|
|
98
98
|
openapiData.tags ?? []
|
|
99
99
|
);
|
|
100
100
|
const tagId = kebabCase(tag.name);
|
|
101
|
+
const splitDescription = description.match(/[^\r\n]+/g);
|
|
101
102
|
const tagPage: PartialPage<TagPageMetadata> = {
|
|
102
103
|
type: "tag",
|
|
103
104
|
id: tagId,
|
|
104
105
|
unversionedId: tagId,
|
|
105
106
|
title: description ?? "",
|
|
106
107
|
description: description ?? "",
|
|
107
|
-
frontMatter: {
|
|
108
|
+
frontMatter: {
|
|
109
|
+
description: splitDescription
|
|
110
|
+
? splitDescription[0]
|
|
111
|
+
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
112
|
+
.replace(/\s+$/, "")
|
|
113
|
+
: "",
|
|
114
|
+
},
|
|
108
115
|
tag: {
|
|
109
116
|
...tag,
|
|
110
117
|
},
|
|
@@ -115,6 +122,11 @@ function createItems(
|
|
|
115
122
|
|
|
116
123
|
if (openapiData.info.description) {
|
|
117
124
|
// Only create an info page if we have a description.
|
|
125
|
+
const infoDescription = openapiData.info?.description;
|
|
126
|
+
let splitDescription: any;
|
|
127
|
+
if (infoDescription) {
|
|
128
|
+
splitDescription = infoDescription.match(/[^\r\n]+/g);
|
|
129
|
+
}
|
|
118
130
|
const infoPage: PartialPage<InfoPageMetadata> = {
|
|
119
131
|
type: "info",
|
|
120
132
|
id: infoId,
|
|
@@ -126,7 +138,13 @@ function createItems(
|
|
|
126
138
|
"$1'"
|
|
127
139
|
)
|
|
128
140
|
: "",
|
|
129
|
-
frontMatter: {
|
|
141
|
+
frontMatter: {
|
|
142
|
+
description: splitDescription
|
|
143
|
+
? splitDescription[0]
|
|
144
|
+
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
145
|
+
.replace(/\s+$/, "")
|
|
146
|
+
: "",
|
|
147
|
+
},
|
|
130
148
|
securitySchemes: openapiData.components?.securitySchemes,
|
|
131
149
|
info: {
|
|
132
150
|
...openapiData.info,
|
|
@@ -208,6 +226,12 @@ function createItems(
|
|
|
208
226
|
}
|
|
209
227
|
}
|
|
210
228
|
|
|
229
|
+
const opDescription = operationObject.description;
|
|
230
|
+
let splitDescription: any;
|
|
231
|
+
if (opDescription) {
|
|
232
|
+
splitDescription = opDescription.match(/[^\r\n]+/g);
|
|
233
|
+
}
|
|
234
|
+
|
|
211
235
|
const apiPage: PartialPage<ApiPageMetadata> = {
|
|
212
236
|
type: "api",
|
|
213
237
|
id: baseId,
|
|
@@ -220,7 +244,13 @@ function createItems(
|
|
|
220
244
|
"$1'"
|
|
221
245
|
)
|
|
222
246
|
: "",
|
|
223
|
-
frontMatter: {
|
|
247
|
+
frontMatter: {
|
|
248
|
+
description: splitDescription
|
|
249
|
+
? splitDescription[0]
|
|
250
|
+
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
251
|
+
.replace(/\s+$/, "")
|
|
252
|
+
: "",
|
|
253
|
+
},
|
|
224
254
|
api: {
|
|
225
255
|
...defaults,
|
|
226
256
|
tags: operationObject.tags,
|
package/src/sidebars/index.ts
CHANGED
|
@@ -110,7 +110,7 @@ function groupByTags(
|
|
|
110
110
|
.map((tag) => {
|
|
111
111
|
// Map info object to tag
|
|
112
112
|
const taggedInfoObject = intros.find((i) =>
|
|
113
|
-
i.tags ? i.tags.
|
|
113
|
+
i.tags ? i.tags.find((t: any) => t.name === tag) : undefined
|
|
114
114
|
);
|
|
115
115
|
const tagObject = tags.flat().find(
|
|
116
116
|
(t) =>
|