docusaurus-plugin-openapi-docs 4.1.0 → 4.2.0
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 +4 -0
- package/lib/markdown/createContactInfo.js +1 -1
- package/lib/markdown/createParamsDetails.d.ts +1 -2
- package/lib/markdown/createParamsDetails.js +7 -42
- package/lib/markdown/createRequestBodyDetails.d.ts +1 -1
- package/lib/markdown/createRequestSchema.d.ts +1 -1
- package/lib/markdown/createRequestSchema.js +8 -132
- package/lib/markdown/createResponseSchema.d.ts +1 -1
- package/lib/markdown/createResponseSchema.js +8 -94
- package/lib/markdown/createSchema.d.ts +1 -4
- package/lib/markdown/createSchema.js +32 -56
- package/lib/markdown/createStatusCodes.d.ts +1 -4
- package/lib/markdown/createStatusCodes.js +10 -259
- package/lib/markdown/index.js +11 -22
- package/lib/openapi/createRequestExample.js +2 -2
- package/lib/openapi/createResponseExample.js +2 -2
- package/lib/openapi/openapi.js +3 -1
- package/lib/openapi/types.d.ts +1 -0
- package/lib/options.js +1 -0
- package/package.json +3 -3
- package/src/index.ts +4 -0
- package/src/markdown/__snapshots__/createSchema.test.ts.snap +55 -0
- package/src/markdown/createContactInfo.ts +1 -1
- package/src/markdown/createParamsDetails.ts +7 -49
- package/src/markdown/createRequestSchema.ts +9 -143
- package/src/markdown/createResponseSchema.ts +9 -112
- package/src/markdown/createSchema.ts +29 -61
- package/src/markdown/createStatusCodes.ts +9 -268
- package/src/markdown/index.ts +11 -22
- package/src/openapi/createRequestExample.ts +2 -5
- package/src/openapi/createResponseExample.ts +2 -5
- package/src/openapi/openapi.ts +3 -1
- package/src/openapi/types.ts +1 -0
- package/src/openapi/utils/loadAndResolveSpec.ts +1 -1
- package/src/options.ts +1 -0
|
@@ -5,15 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import format from "xml-formatter";
|
|
9
|
-
|
|
10
|
-
import { createDescription } from "./createDescription";
|
|
11
|
-
import { createDetails } from "./createDetails";
|
|
12
|
-
import { createDetailsSummary } from "./createDetailsSummary";
|
|
13
|
-
import { createResponseSchema } from "./createResponseSchema";
|
|
14
8
|
import { create } from "./utils";
|
|
15
|
-
import { guard } from "./utils";
|
|
16
|
-
import { sampleResponseFromSchema } from "../openapi/createResponseExample";
|
|
17
9
|
import { ApiItem } from "../types";
|
|
18
10
|
|
|
19
11
|
export default function json2xml(o: any, tab: any) {
|
|
@@ -59,264 +51,13 @@ interface Props {
|
|
|
59
51
|
responses: ApiItem["responses"];
|
|
60
52
|
}
|
|
61
53
|
|
|
62
|
-
function
|
|
63
|
-
return
|
|
64
|
-
create("
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return create("li", {
|
|
73
|
-
className: "schemaItem",
|
|
74
|
-
children: [
|
|
75
|
-
createDetailsSummary({
|
|
76
|
-
children: [
|
|
77
|
-
create("strong", { children: headerName }),
|
|
78
|
-
guard(type, () => [
|
|
79
|
-
create("span", {
|
|
80
|
-
style: { opacity: "0.6" },
|
|
81
|
-
children: ` ${type}`,
|
|
82
|
-
}),
|
|
83
|
-
]),
|
|
84
|
-
],
|
|
85
|
-
}),
|
|
86
|
-
create("div", {
|
|
87
|
-
children: [
|
|
88
|
-
guard(description, (description) =>
|
|
89
|
-
create("div", {
|
|
90
|
-
style: {
|
|
91
|
-
marginTop: ".5rem",
|
|
92
|
-
marginBottom: ".5rem",
|
|
93
|
-
},
|
|
94
|
-
children: [
|
|
95
|
-
guard(example, () => `Example: ${example}`),
|
|
96
|
-
createDescription(description),
|
|
97
|
-
],
|
|
98
|
-
})
|
|
99
|
-
),
|
|
100
|
-
],
|
|
101
|
-
}),
|
|
102
|
-
],
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
),
|
|
106
|
-
],
|
|
107
|
-
})
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export function createResponseExamples(
|
|
112
|
-
responseExamples: any,
|
|
113
|
-
mimeType: string
|
|
114
|
-
) {
|
|
115
|
-
let language = "shell";
|
|
116
|
-
if (mimeType.endsWith("json")) {
|
|
117
|
-
language = "json";
|
|
118
|
-
}
|
|
119
|
-
if (mimeType.endsWith("xml")) {
|
|
120
|
-
language = "xml";
|
|
121
|
-
}
|
|
122
|
-
return Object.entries(responseExamples).map(
|
|
123
|
-
([exampleName, exampleValue]: any) => {
|
|
124
|
-
if (typeof exampleValue.value === "object") {
|
|
125
|
-
return create("TabItem", {
|
|
126
|
-
label: `${exampleName}`,
|
|
127
|
-
value: `${exampleName}`,
|
|
128
|
-
children: [
|
|
129
|
-
guard(exampleValue.summary, (summary) => [
|
|
130
|
-
create("div", {
|
|
131
|
-
children: `${summary}`,
|
|
132
|
-
className: "openapi-example__summary",
|
|
133
|
-
}),
|
|
134
|
-
]),
|
|
135
|
-
create("ResponseSamples", {
|
|
136
|
-
responseExample: JSON.stringify(exampleValue.value, null, 2),
|
|
137
|
-
language: language,
|
|
138
|
-
}),
|
|
139
|
-
],
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
return create("TabItem", {
|
|
143
|
-
label: `${exampleName}`,
|
|
144
|
-
value: `${exampleName}`,
|
|
145
|
-
children: [
|
|
146
|
-
guard(exampleValue.summary, (summary) => [
|
|
147
|
-
create("div", {
|
|
148
|
-
children: `${summary}`,
|
|
149
|
-
className: "openapi-example__summary",
|
|
150
|
-
}),
|
|
151
|
-
]),
|
|
152
|
-
create("ResponseSamples", {
|
|
153
|
-
responseExample: exampleValue.value,
|
|
154
|
-
language: language,
|
|
155
|
-
}),
|
|
156
|
-
],
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export function createResponseExample(responseExample: any, mimeType: string) {
|
|
163
|
-
let language = "shell";
|
|
164
|
-
if (mimeType.endsWith("json")) {
|
|
165
|
-
language = "json";
|
|
166
|
-
}
|
|
167
|
-
if (mimeType.endsWith("xml")) {
|
|
168
|
-
language = "xml";
|
|
169
|
-
}
|
|
170
|
-
if (typeof responseExample === "object") {
|
|
171
|
-
return create("TabItem", {
|
|
172
|
-
label: `Example`,
|
|
173
|
-
value: `Example`,
|
|
174
|
-
children: [
|
|
175
|
-
guard(responseExample.summary, (summary) => [
|
|
176
|
-
create("div", {
|
|
177
|
-
children: `${summary}`,
|
|
178
|
-
className: "openapi-example__summary",
|
|
179
|
-
}),
|
|
180
|
-
]),
|
|
181
|
-
create("ResponseSamples", {
|
|
182
|
-
responseExample: JSON.stringify(responseExample, null, 2),
|
|
183
|
-
language: language,
|
|
184
|
-
}),
|
|
185
|
-
],
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
return create("TabItem", {
|
|
189
|
-
label: `Example`,
|
|
190
|
-
value: `Example`,
|
|
191
|
-
children: [
|
|
192
|
-
guard(responseExample.summary, (summary) => [
|
|
193
|
-
create("div", {
|
|
194
|
-
children: `${summary}`,
|
|
195
|
-
className: "openapi-example__summary",
|
|
196
|
-
}),
|
|
197
|
-
]),
|
|
198
|
-
create("ResponseSamples", {
|
|
199
|
-
responseExample: responseExample,
|
|
200
|
-
language: language,
|
|
201
|
-
}),
|
|
202
|
-
],
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export function createExampleFromSchema(schema: any, mimeType: string) {
|
|
207
|
-
const responseExample = sampleResponseFromSchema(schema);
|
|
208
|
-
if (mimeType.endsWith("xml")) {
|
|
209
|
-
let responseExampleObject;
|
|
210
|
-
try {
|
|
211
|
-
responseExampleObject = JSON.parse(JSON.stringify(responseExample));
|
|
212
|
-
} catch {
|
|
213
|
-
return undefined;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if (typeof responseExampleObject === "object") {
|
|
217
|
-
let xmlExample;
|
|
218
|
-
try {
|
|
219
|
-
xmlExample = format(json2xml(responseExampleObject, ""), {
|
|
220
|
-
indentation: " ",
|
|
221
|
-
lineSeparator: "\n",
|
|
222
|
-
collapseContent: true,
|
|
223
|
-
});
|
|
224
|
-
} catch {
|
|
225
|
-
const xmlExampleWithRoot = { root: responseExampleObject };
|
|
226
|
-
try {
|
|
227
|
-
xmlExample = format(json2xml(xmlExampleWithRoot, ""), {
|
|
228
|
-
indentation: " ",
|
|
229
|
-
lineSeparator: "\n",
|
|
230
|
-
collapseContent: true,
|
|
231
|
-
});
|
|
232
|
-
} catch {
|
|
233
|
-
xmlExample = json2xml(responseExampleObject, "");
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
return create("TabItem", {
|
|
237
|
-
label: `Example (from schema)`,
|
|
238
|
-
value: `Example (from schema)`,
|
|
239
|
-
children: [
|
|
240
|
-
create("ResponseSamples", {
|
|
241
|
-
responseExample: xmlExample,
|
|
242
|
-
language: "xml",
|
|
243
|
-
}),
|
|
244
|
-
],
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
if (typeof responseExample === "object") {
|
|
249
|
-
return create("TabItem", {
|
|
250
|
-
label: `Example (from schema)`,
|
|
251
|
-
value: `Example (from schema)`,
|
|
252
|
-
children: [
|
|
253
|
-
create("ResponseSamples", {
|
|
254
|
-
responseExample: JSON.stringify(responseExample, null, 2),
|
|
255
|
-
language: "json",
|
|
256
|
-
}),
|
|
257
|
-
],
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
return undefined;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
export function createStatusCodes({ label, id, responses }: Props) {
|
|
264
|
-
if (responses === undefined) {
|
|
265
|
-
return undefined;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
const codes = Object.keys(responses);
|
|
269
|
-
if (codes.length === 0) {
|
|
270
|
-
return undefined;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
return create("div", {
|
|
274
|
-
children: [
|
|
275
|
-
create("div", {
|
|
276
|
-
children: [
|
|
277
|
-
create("ApiTabs", {
|
|
278
|
-
label,
|
|
279
|
-
id,
|
|
280
|
-
children: codes.map((code) => {
|
|
281
|
-
const responseHeaders: any = responses[code].headers;
|
|
282
|
-
return create("TabItem", {
|
|
283
|
-
label: code,
|
|
284
|
-
value: code,
|
|
285
|
-
children: [
|
|
286
|
-
create("div", {
|
|
287
|
-
children: createDescription(responses[code].description),
|
|
288
|
-
}),
|
|
289
|
-
responseHeaders &&
|
|
290
|
-
createDetails({
|
|
291
|
-
className: "openapi-markdown__details",
|
|
292
|
-
"data-collapsed": true,
|
|
293
|
-
open: false,
|
|
294
|
-
style: { textAlign: "left", marginBottom: "1rem" },
|
|
295
|
-
children: [
|
|
296
|
-
createDetailsSummary({
|
|
297
|
-
children: [
|
|
298
|
-
create("strong", {
|
|
299
|
-
children: "Response Headers",
|
|
300
|
-
}),
|
|
301
|
-
],
|
|
302
|
-
}),
|
|
303
|
-
createResponseHeaders(responseHeaders),
|
|
304
|
-
],
|
|
305
|
-
}),
|
|
306
|
-
create("div", {
|
|
307
|
-
children: createResponseSchema({
|
|
308
|
-
title: "Schema",
|
|
309
|
-
body: {
|
|
310
|
-
content: responses[code].content,
|
|
311
|
-
},
|
|
312
|
-
}),
|
|
313
|
-
}),
|
|
314
|
-
],
|
|
315
|
-
});
|
|
316
|
-
}),
|
|
317
|
-
}),
|
|
318
|
-
],
|
|
319
|
-
}),
|
|
320
|
-
],
|
|
321
|
-
});
|
|
54
|
+
export function createStatusCodes({ id, label, responses }: Props) {
|
|
55
|
+
return [
|
|
56
|
+
create("StatusCodes", {
|
|
57
|
+
id: id,
|
|
58
|
+
label: label,
|
|
59
|
+
responses: responses,
|
|
60
|
+
}),
|
|
61
|
+
"\n\n",
|
|
62
|
+
];
|
|
322
63
|
}
|
package/src/markdown/index.ts
CHANGED
|
@@ -19,7 +19,6 @@ import { createMethodEndpoint } from "./createMethodEndpoint";
|
|
|
19
19
|
import { createParamsDetails } from "./createParamsDetails";
|
|
20
20
|
import { createRequestBodyDetails } from "./createRequestBodyDetails";
|
|
21
21
|
import { createRequestHeader } from "./createRequestHeader";
|
|
22
|
-
import { createNodes } from "./createSchema";
|
|
23
22
|
import { createStatusCodes } from "./createStatusCodes";
|
|
24
23
|
import { createTermsOfService } from "./createTermsOfService";
|
|
25
24
|
import { createVendorExtensions } from "./createVendorExtensions";
|
|
@@ -67,18 +66,13 @@ export function createApiPageMD({
|
|
|
67
66
|
frontMatter,
|
|
68
67
|
}: ApiPageMetadata) {
|
|
69
68
|
return render([
|
|
70
|
-
`import ApiTabs from "@theme/ApiTabs";\n`,
|
|
71
|
-
`import DiscriminatorTabs from "@theme/DiscriminatorTabs";\n`,
|
|
72
69
|
`import MethodEndpoint from "@theme/ApiExplorer/MethodEndpoint";\n`,
|
|
73
|
-
`import
|
|
74
|
-
`import
|
|
75
|
-
`import
|
|
76
|
-
`import ResponseSamples from "@theme/ResponseSamples";\n`,
|
|
77
|
-
`import SchemaItem from "@theme/SchemaItem";\n`,
|
|
78
|
-
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
79
|
-
`import Heading from "@theme/Heading";\n`,
|
|
70
|
+
`import ParamsDetails from "@theme/ParamsDetails";\n`,
|
|
71
|
+
`import RequestSchema from "@theme/RequestSchema";\n`,
|
|
72
|
+
`import StatusCodes from "@theme/StatusCodes";\n`,
|
|
80
73
|
`import OperationTabs from "@theme/OperationTabs";\n`,
|
|
81
|
-
`import TabItem from "@theme/TabItem";\n
|
|
74
|
+
`import TabItem from "@theme/TabItem";\n`,
|
|
75
|
+
`import Heading from "@theme/Heading";\n\n`,
|
|
82
76
|
createHeading(title),
|
|
83
77
|
createMethodEndpoint(method, path),
|
|
84
78
|
infoPath && createAuthorization(infoPath),
|
|
@@ -88,10 +82,7 @@ export function createApiPageMD({
|
|
|
88
82
|
createDeprecationNotice({ deprecated, description: deprecatedDescription }),
|
|
89
83
|
createDescription(description),
|
|
90
84
|
requestBody || parameters ? createRequestHeader("Request") : undefined,
|
|
91
|
-
createParamsDetails({ parameters
|
|
92
|
-
createParamsDetails({ parameters, type: "query" }),
|
|
93
|
-
createParamsDetails({ parameters, type: "header" }),
|
|
94
|
-
createParamsDetails({ parameters, type: "cookie" }),
|
|
85
|
+
createParamsDetails({ parameters }),
|
|
95
86
|
createRequestBodyDetails({
|
|
96
87
|
title: "Body",
|
|
97
88
|
body: requestBody,
|
|
@@ -141,15 +132,13 @@ export function createTagPageMD({ tag: { description } }: TagPageMetadata) {
|
|
|
141
132
|
export function createSchemaPageMD({ schema }: SchemaPageMetadata) {
|
|
142
133
|
const { title = "", description } = schema;
|
|
143
134
|
return render([
|
|
144
|
-
`import
|
|
145
|
-
`import
|
|
146
|
-
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
147
|
-
`import Heading from "@theme/Heading";\n`,
|
|
148
|
-
`import TabItem from "@theme/TabItem";\n\n`,
|
|
135
|
+
`import Schema from "@theme/Schema";\n`,
|
|
136
|
+
`import Heading from "@theme/Heading";\n\n`,
|
|
149
137
|
createHeading(title.replace(lessThan, "<").replace(greaterThan, ">")),
|
|
150
138
|
createDescription(description),
|
|
151
|
-
create("
|
|
152
|
-
|
|
139
|
+
create("Schema", {
|
|
140
|
+
schema: schema,
|
|
141
|
+
schemaType: "response",
|
|
153
142
|
}),
|
|
154
143
|
]);
|
|
155
144
|
}
|
|
@@ -66,9 +66,7 @@ function sampleRequestFromProp(name: string, prop: any, obj: any): any {
|
|
|
66
66
|
} else if (prop.anyOf) {
|
|
67
67
|
obj[name] = sampleRequestFromSchema(prop.anyOf[0]);
|
|
68
68
|
} else if (prop.allOf) {
|
|
69
|
-
const
|
|
70
|
-
prop.allOf
|
|
71
|
-
);
|
|
69
|
+
const mergedSchemas = mergeAllOf(prop) as SchemaObject;
|
|
72
70
|
sampleRequestFromProp(name, mergedSchemas, obj);
|
|
73
71
|
} else {
|
|
74
72
|
obj[name] = sampleRequestFromSchema(prop);
|
|
@@ -107,8 +105,7 @@ export const sampleRequestFromSchema = (schema: SchemaObject = {}): any => {
|
|
|
107
105
|
}
|
|
108
106
|
|
|
109
107
|
if (allOf) {
|
|
110
|
-
const
|
|
111
|
-
mergeAllOf(allOf);
|
|
108
|
+
const mergedSchemas = mergeAllOf(schemaCopy) as SchemaObject;
|
|
112
109
|
if (mergedSchemas.properties) {
|
|
113
110
|
for (const [key, value] of Object.entries(mergedSchemas.properties)) {
|
|
114
111
|
if ((value.readOnly && value.readOnly === true) || value.deprecated) {
|
|
@@ -66,9 +66,7 @@ function sampleResponseFromProp(name: string, prop: any, obj: any): any {
|
|
|
66
66
|
} else if (prop.anyOf) {
|
|
67
67
|
obj[name] = sampleResponseFromSchema(prop.anyOf[0]);
|
|
68
68
|
} else if (prop.allOf) {
|
|
69
|
-
const
|
|
70
|
-
prop.allOf
|
|
71
|
-
);
|
|
69
|
+
const mergedSchemas = mergeAllOf(prop) as SchemaObject;
|
|
72
70
|
sampleResponseFromProp(name, mergedSchemas, obj);
|
|
73
71
|
} else {
|
|
74
72
|
obj[name] = sampleResponseFromSchema(prop);
|
|
@@ -87,8 +85,7 @@ export const sampleResponseFromSchema = (schema: SchemaObject = {}): any => {
|
|
|
87
85
|
}
|
|
88
86
|
|
|
89
87
|
if (allOf) {
|
|
90
|
-
const
|
|
91
|
-
mergeAllOf(allOf);
|
|
88
|
+
const mergedSchemas = mergeAllOf(schemaCopy) as SchemaObject;
|
|
92
89
|
if (mergedSchemas.properties) {
|
|
93
90
|
for (const [key, value] of Object.entries(mergedSchemas.properties)) {
|
|
94
91
|
if (
|
package/src/openapi/openapi.ts
CHANGED
|
@@ -20,7 +20,6 @@ import sdk from "postman-collection";
|
|
|
20
20
|
|
|
21
21
|
import { sampleRequestFromSchema } from "./createRequestExample";
|
|
22
22
|
import { OpenApiObject, TagGroupObject, TagObject } from "./types";
|
|
23
|
-
import { loadAndResolveSpec } from "./utils/loadAndResolveSpec";
|
|
24
23
|
import { isURL } from "../index";
|
|
25
24
|
import {
|
|
26
25
|
ApiMetadata,
|
|
@@ -31,6 +30,8 @@ import {
|
|
|
31
30
|
SidebarOptions,
|
|
32
31
|
TagPageMetadata,
|
|
33
32
|
} from "../types";
|
|
33
|
+
import { sampleResponseFromSchema } from "./createResponseExample";
|
|
34
|
+
import { loadAndResolveSpec } from "./utils/loadAndResolveSpec";
|
|
34
35
|
|
|
35
36
|
/**
|
|
36
37
|
* Convenience function for converting raw JSON to a Postman Collection object.
|
|
@@ -451,6 +452,7 @@ function createItems(
|
|
|
451
452
|
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
452
453
|
.replace(/\s+$/, "")
|
|
453
454
|
: "",
|
|
455
|
+
sample: JSON.stringify(sampleResponseFromSchema(schemaObject)),
|
|
454
456
|
},
|
|
455
457
|
schema: schemaObject,
|
|
456
458
|
};
|
package/src/openapi/types.ts
CHANGED
|
@@ -13,8 +13,8 @@ import chalk from "chalk";
|
|
|
13
13
|
// @ts-ignore
|
|
14
14
|
import { convertObj } from "swagger2openapi";
|
|
15
15
|
|
|
16
|
-
import { OpenAPIParser } from "./services/OpenAPIParser";
|
|
17
16
|
import { OpenApiObject } from "../types";
|
|
17
|
+
import { OpenAPIParser } from "./services/OpenAPIParser";
|
|
18
18
|
|
|
19
19
|
function serializer(replacer: any, cycleReplacer: any) {
|
|
20
20
|
var stack: any = [],
|
package/src/options.ts
CHANGED