docusaurus-plugin-openapi-docs 4.1.0 → 4.3.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/README.md +21 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +66 -0
- package/lib/markdown/createAuthentication.js +3 -3
- 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/createTermsOfService.js +1 -1
- 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 +9 -6
- package/src/index.ts +88 -5
- package/src/markdown/__snapshots__/createSchema.test.ts.snap +55 -0
- package/src/markdown/createAuthentication.ts +3 -3
- 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/createTermsOfService.ts +1 -1
- 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
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ Key Features:
|
|
|
41
41
|
|
|
42
42
|
| Docusaurus OpenAPI Docs | Docusaurus |
|
|
43
43
|
| ----------------------- | --------------- |
|
|
44
|
-
| 4.0.x (current) | `3.5.0 - 3.
|
|
44
|
+
| 4.0.x (current) | `3.5.0 - 3.6.x` |
|
|
45
45
|
| 3.0.x (end-of-support) | `3.0.1 - 3.4.0` |
|
|
46
46
|
| 2.2.3 (legacy) | `2.4.1 - 2.4.3` |
|
|
47
47
|
| 1.7.3 (end-of-support) | `2.0.1 - 2.2.0` |
|
|
@@ -268,6 +268,16 @@ yarn docusaurus gen-api-docs petstore
|
|
|
268
268
|
|
|
269
269
|
> The example above will only generate API docs relative to `petstore`.
|
|
270
270
|
|
|
271
|
+
If you have multiple versions of the same API, `gen-api-docs` only generates the latest. To generate all versions, use the `--all-versions` flag.
|
|
272
|
+
|
|
273
|
+
Example:
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
yarn docusaurus gen-api-docs all --all-versions
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
> This will generate API docs for all versions of all the OpenAPI specification (OAS) files referenced in your `docusaurus-plugin-openapi-docs` config.
|
|
280
|
+
|
|
271
281
|
### Cleaning API Docs
|
|
272
282
|
|
|
273
283
|
To clean/remove all API Docs, run the following command from the root directory of your project:
|
|
@@ -290,6 +300,16 @@ yarn docusaurus clean-api-docs petstore
|
|
|
290
300
|
|
|
291
301
|
> The example above will remove all API docs relative to `burgers`.
|
|
292
302
|
|
|
303
|
+
If you have multiple versions of the same API, `clean-api-docs` only cleans the latest. To clean all versions, use the `--all-versions` flag.
|
|
304
|
+
|
|
305
|
+
Example:
|
|
306
|
+
|
|
307
|
+
```bash
|
|
308
|
+
yarn docusaurus clean-api-docs all --all-versions
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
> This will clean API docs for all versions of all the OpenAPI specification (OAS) files referenced in your `docusaurus-plugin-openapi-docs` config.
|
|
312
|
+
|
|
293
313
|
### Versioning OpenAPI docs
|
|
294
314
|
|
|
295
315
|
To generate _all_ versioned OpenAPI docs, run the following command from the root directory of your project:
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LoadContext, Plugin } from "@docusaurus/types";
|
|
2
|
-
import type {
|
|
2
|
+
import type { LoadedContent, PluginOptions } from "./types";
|
|
3
3
|
export declare function isURL(str: string): boolean;
|
|
4
4
|
export declare function getDocsPluginConfig(presetsPlugins: any[], plugin: string, pluginId: string): Object | undefined;
|
|
5
5
|
declare function pluginOpenAPIDocs(context: LoadContext, options: PluginOptions): Plugin<LoadedContent>;
|
package/lib/index.js
CHANGED
|
@@ -203,7 +203,11 @@ title: "{{{title}}}"
|
|
|
203
203
|
description: "{{{frontMatter.description}}}"
|
|
204
204
|
sidebar_label: "{{{title}}}"
|
|
205
205
|
hide_title: true
|
|
206
|
+
{{#schema}}
|
|
207
|
+
hide_table_of_contents: true
|
|
208
|
+
{{/schema}}
|
|
206
209
|
schema: true
|
|
210
|
+
sample: {{{frontMatter.sample}}}
|
|
207
211
|
custom_edit_url: null
|
|
208
212
|
---
|
|
209
213
|
|
|
@@ -405,6 +409,52 @@ custom_edit_url: null
|
|
|
405
409
|
});
|
|
406
410
|
}
|
|
407
411
|
}
|
|
412
|
+
async function generateAllVersions(options, pluginId) {
|
|
413
|
+
const parentOptions = Object.assign({}, options);
|
|
414
|
+
const { versions } = parentOptions;
|
|
415
|
+
if (versions != null && Object.keys(versions).length > 0) {
|
|
416
|
+
const version = parentOptions.version;
|
|
417
|
+
const label = parentOptions.label;
|
|
418
|
+
const baseUrl = parentOptions.baseUrl;
|
|
419
|
+
let parentVersion = {};
|
|
420
|
+
parentVersion[version] = { label: label, baseUrl: baseUrl };
|
|
421
|
+
const mergedVersions = Object.assign(parentVersion, versions);
|
|
422
|
+
// Prepare for merge
|
|
423
|
+
delete parentOptions.versions;
|
|
424
|
+
delete parentOptions.version;
|
|
425
|
+
delete parentOptions.label;
|
|
426
|
+
delete parentOptions.baseUrl;
|
|
427
|
+
delete parentOptions.downloadUrl;
|
|
428
|
+
await generateVersions(mergedVersions, parentOptions.outputDir);
|
|
429
|
+
Object.keys(versions).forEach(async (key) => {
|
|
430
|
+
if (key === "all") {
|
|
431
|
+
console.error(chalk_1.default.red("Can't use id 'all' for OpenAPI docs versions configuration key."));
|
|
432
|
+
}
|
|
433
|
+
const versionOptions = versions[key];
|
|
434
|
+
const mergedOptions = {
|
|
435
|
+
...parentOptions,
|
|
436
|
+
...versionOptions,
|
|
437
|
+
};
|
|
438
|
+
await generateApiDocs(mergedOptions, pluginId);
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
async function cleanAllVersions(options) {
|
|
443
|
+
const parentOptions = Object.assign({}, options);
|
|
444
|
+
const { versions } = parentOptions;
|
|
445
|
+
delete parentOptions.versions;
|
|
446
|
+
if (versions != null && Object.keys(versions).length > 0) {
|
|
447
|
+
await cleanVersions(parentOptions.outputDir);
|
|
448
|
+
Object.keys(versions).forEach(async (key) => {
|
|
449
|
+
const versionOptions = versions[key];
|
|
450
|
+
const mergedOptions = {
|
|
451
|
+
...parentOptions,
|
|
452
|
+
...versionOptions,
|
|
453
|
+
};
|
|
454
|
+
await cleanApiDocs(mergedOptions);
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
}
|
|
408
458
|
return {
|
|
409
459
|
name: `docusaurus-plugin-openapi-docs`,
|
|
410
460
|
extendCli(cli) {
|
|
@@ -414,10 +464,12 @@ custom_edit_url: null
|
|
|
414
464
|
.usage("<id>")
|
|
415
465
|
.arguments("<id>")
|
|
416
466
|
.option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
|
|
467
|
+
.option("--all-versions", "Generate all versions.")
|
|
417
468
|
.action(async (id, instance) => {
|
|
418
469
|
var _a;
|
|
419
470
|
const options = instance.opts();
|
|
420
471
|
const pluginId = options.pluginId;
|
|
472
|
+
const allVersions = options.allVersions;
|
|
421
473
|
const pluginInstances = getPluginInstances(plugins);
|
|
422
474
|
let targetConfig;
|
|
423
475
|
let targetDocsPluginId;
|
|
@@ -446,6 +498,9 @@ custom_edit_url: null
|
|
|
446
498
|
else {
|
|
447
499
|
Object.keys(targetConfig).forEach(async function (key) {
|
|
448
500
|
await generateApiDocs(targetConfig[key], targetDocsPluginId);
|
|
501
|
+
if (allVersions) {
|
|
502
|
+
await generateAllVersions(targetConfig[key], targetDocsPluginId);
|
|
503
|
+
}
|
|
449
504
|
});
|
|
450
505
|
}
|
|
451
506
|
}
|
|
@@ -454,6 +509,9 @@ custom_edit_url: null
|
|
|
454
509
|
}
|
|
455
510
|
else {
|
|
456
511
|
await generateApiDocs(targetConfig[id], targetDocsPluginId);
|
|
512
|
+
if (allVersions) {
|
|
513
|
+
await generateAllVersions(targetConfig[id], targetDocsPluginId);
|
|
514
|
+
}
|
|
457
515
|
}
|
|
458
516
|
});
|
|
459
517
|
cli
|
|
@@ -538,10 +596,12 @@ custom_edit_url: null
|
|
|
538
596
|
.usage("<id>")
|
|
539
597
|
.arguments("<id>")
|
|
540
598
|
.option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
|
|
599
|
+
.option("--all-versions", "Clean all versions.")
|
|
541
600
|
.action(async (id, instance) => {
|
|
542
601
|
var _a;
|
|
543
602
|
const options = instance.opts();
|
|
544
603
|
const pluginId = options.pluginId;
|
|
604
|
+
const allVersions = options.allVersions;
|
|
545
605
|
const pluginInstances = getPluginInstances(plugins);
|
|
546
606
|
let targetConfig;
|
|
547
607
|
if (pluginId) {
|
|
@@ -568,11 +628,17 @@ custom_edit_url: null
|
|
|
568
628
|
else {
|
|
569
629
|
Object.keys(targetConfig).forEach(async function (key) {
|
|
570
630
|
await cleanApiDocs(targetConfig[key]);
|
|
631
|
+
if (allVersions) {
|
|
632
|
+
await cleanAllVersions(targetConfig[key]);
|
|
633
|
+
}
|
|
571
634
|
});
|
|
572
635
|
}
|
|
573
636
|
}
|
|
574
637
|
else {
|
|
575
638
|
await cleanApiDocs(targetConfig[id]);
|
|
639
|
+
if (allVersions) {
|
|
640
|
+
await cleanAllVersions(targetConfig[id]);
|
|
641
|
+
}
|
|
576
642
|
}
|
|
577
643
|
});
|
|
578
644
|
cli
|
|
@@ -28,11 +28,11 @@ function createAuthentication(securitySchemes) {
|
|
|
28
28
|
(0, utils_1.create)("th", { children: `OAuth Flow (${flowType}):` }),
|
|
29
29
|
(0, utils_1.create)("td", {
|
|
30
30
|
children: [
|
|
31
|
-
(0, utils_1.guard)(tokenUrl, () => (0, utils_1.create)("
|
|
32
|
-
(0, utils_1.guard)(authorizationUrl, () => (0, utils_1.create)("
|
|
31
|
+
(0, utils_1.guard)(tokenUrl, () => (0, utils_1.create)("div", { children: `Token URL: ${tokenUrl}` })),
|
|
32
|
+
(0, utils_1.guard)(authorizationUrl, () => (0, utils_1.create)("div", {
|
|
33
33
|
children: `Authorization URL: ${authorizationUrl}`,
|
|
34
34
|
})),
|
|
35
|
-
(0, utils_1.guard)(refreshUrl, () => (0, utils_1.create)("
|
|
35
|
+
(0, utils_1.guard)(refreshUrl, () => (0, utils_1.create)("div", { children: `Refresh URL: ${refreshUrl}` })),
|
|
36
36
|
(0, utils_1.create)("span", { children: "Scopes:" }),
|
|
37
37
|
(0, utils_1.create)("ul", {
|
|
38
38
|
children: Object.entries(scopes).map(([scope, description]) => (0, utils_1.create)("li", { children: `${scope}: ${description}` })),
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ApiItem } from "../types";
|
|
2
2
|
interface Props {
|
|
3
3
|
parameters: ApiItem["parameters"];
|
|
4
|
-
type: "path" | "query" | "header" | "cookie";
|
|
5
4
|
}
|
|
6
|
-
export declare function createParamsDetails({ parameters
|
|
5
|
+
export declare function createParamsDetails({ parameters }: Props): string[];
|
|
7
6
|
export {};
|
|
@@ -7,48 +7,13 @@
|
|
|
7
7
|
* ========================================================================== */
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createParamsDetails = void 0;
|
|
10
|
-
const createDetails_1 = require("./createDetails");
|
|
11
|
-
const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
12
10
|
const utils_1 = require("./utils");
|
|
13
|
-
function createParamsDetails({ parameters
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
return (0, createDetails_1.createDetails)({
|
|
22
|
-
className: "openapi-markdown__details",
|
|
23
|
-
"data-collapsed": false,
|
|
24
|
-
open: true,
|
|
25
|
-
style: { marginBottom: "1rem" },
|
|
26
|
-
children: [
|
|
27
|
-
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
28
|
-
children: [
|
|
29
|
-
(0, utils_1.create)("h3", {
|
|
30
|
-
className: "openapi-markdown__details-summary-header-params",
|
|
31
|
-
children: `${type.charAt(0).toUpperCase() + type.slice(1)} Parameters`,
|
|
32
|
-
}),
|
|
33
|
-
],
|
|
34
|
-
}),
|
|
35
|
-
(0, utils_1.create)("div", {
|
|
36
|
-
children: [
|
|
37
|
-
(0, utils_1.create)("ul", {
|
|
38
|
-
children: params.map((param) => {
|
|
39
|
-
var _a, _b, _c, _d, _e;
|
|
40
|
-
return (0, utils_1.create)("ParamsItem", {
|
|
41
|
-
className: "paramsItem",
|
|
42
|
-
param: {
|
|
43
|
-
...param,
|
|
44
|
-
enumDescriptions: Object.entries((_e = (_b = (_a = param === null || param === void 0 ? void 0 : param.schema) === null || _a === void 0 ? void 0 : _a["x-enumDescriptions"]) !== null && _b !== void 0 ? _b : (_d = (_c = param === null || param === void 0 ? void 0 : param.schema) === null || _c === void 0 ? void 0 : _c.items) === null || _d === void 0 ? void 0 : _d["x-enumDescriptions"]) !== null && _e !== void 0 ? _e : {}),
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
}),
|
|
48
|
-
}),
|
|
49
|
-
],
|
|
50
|
-
}),
|
|
51
|
-
],
|
|
52
|
-
});
|
|
11
|
+
function createParamsDetails({ parameters }) {
|
|
12
|
+
return [
|
|
13
|
+
(0, utils_1.create)("ParamsDetails", {
|
|
14
|
+
parameters: parameters,
|
|
15
|
+
}),
|
|
16
|
+
"\n\n",
|
|
17
|
+
];
|
|
53
18
|
}
|
|
54
19
|
exports.createParamsDetails = createParamsDetails;
|
|
@@ -10,5 +10,5 @@ interface Props {
|
|
|
10
10
|
required?: string[] | boolean;
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
export declare function createRequestSchema({ title, body, ...rest }: Props): string
|
|
13
|
+
export declare function createRequestSchema({ title, body, ...rest }: Props): string[];
|
|
14
14
|
export {};
|
|
@@ -7,139 +7,15 @@
|
|
|
7
7
|
* ========================================================================== */
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createRequestSchema = void 0;
|
|
10
|
-
const createDescription_1 = require("./createDescription");
|
|
11
|
-
const createDetails_1 = require("./createDetails");
|
|
12
|
-
const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
13
|
-
const createSchema_1 = require("./createSchema");
|
|
14
10
|
const utils_1 = require("./utils");
|
|
15
11
|
function createRequestSchema({ title, body, ...rest }) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const mimeTypes = Object.keys(body.content);
|
|
25
|
-
if (mimeTypes && mimeTypes.length > 1) {
|
|
26
|
-
return (0, utils_1.create)("MimeTabs", {
|
|
27
|
-
className: "openapi-tabs__mime",
|
|
28
|
-
schemaType: "request",
|
|
29
|
-
children: mimeTypes.map((mimeType) => {
|
|
30
|
-
const firstBody = body.content[mimeType].schema;
|
|
31
|
-
if (firstBody === undefined) {
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
if (firstBody.properties !== undefined) {
|
|
35
|
-
if (Object.keys(firstBody.properties).length === 0) {
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return (0, utils_1.create)("TabItem", {
|
|
40
|
-
label: mimeType,
|
|
41
|
-
value: `${mimeType}`,
|
|
42
|
-
children: [
|
|
43
|
-
(0, createDetails_1.createDetails)({
|
|
44
|
-
className: "openapi-markdown__details mime",
|
|
45
|
-
"data-collapsed": false,
|
|
46
|
-
open: true,
|
|
47
|
-
...rest,
|
|
48
|
-
children: [
|
|
49
|
-
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
50
|
-
className: "openapi-markdown__details-summary-mime",
|
|
51
|
-
children: [
|
|
52
|
-
(0, utils_1.create)("h3", {
|
|
53
|
-
className: "openapi-markdown__details-summary-header-body",
|
|
54
|
-
children: `${title}`,
|
|
55
|
-
}),
|
|
56
|
-
(0, utils_1.guard)(body.required && body.required === true, () => [
|
|
57
|
-
(0, utils_1.create)("span", {
|
|
58
|
-
className: "openapi-schema__required",
|
|
59
|
-
children: "required",
|
|
60
|
-
}),
|
|
61
|
-
]),
|
|
62
|
-
],
|
|
63
|
-
}),
|
|
64
|
-
(0, utils_1.create)("div", {
|
|
65
|
-
style: { textAlign: "left", marginLeft: "1rem" },
|
|
66
|
-
children: [
|
|
67
|
-
(0, utils_1.guard)(body.description, () => [
|
|
68
|
-
(0, utils_1.create)("div", {
|
|
69
|
-
style: { marginTop: "1rem", marginBottom: "1rem" },
|
|
70
|
-
children: (0, createDescription_1.createDescription)(body.description),
|
|
71
|
-
}),
|
|
72
|
-
]),
|
|
73
|
-
],
|
|
74
|
-
}),
|
|
75
|
-
(0, utils_1.create)("ul", {
|
|
76
|
-
style: { marginLeft: "1rem" },
|
|
77
|
-
children: (0, createSchema_1.createNodes)(firstBody, "request"),
|
|
78
|
-
}),
|
|
79
|
-
],
|
|
80
|
-
}),
|
|
81
|
-
],
|
|
82
|
-
});
|
|
83
|
-
}),
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
const randomFirstKey = Object.keys(body.content)[0];
|
|
87
|
-
const firstBody = (_a = body.content[randomFirstKey].schema) !== null && _a !== void 0 ? _a : body.content[randomFirstKey];
|
|
88
|
-
if (firstBody === undefined) {
|
|
89
|
-
return undefined;
|
|
90
|
-
}
|
|
91
|
-
return (0, utils_1.create)("MimeTabs", {
|
|
92
|
-
className: "openapi-tabs__mime",
|
|
93
|
-
children: [
|
|
94
|
-
(0, utils_1.create)("TabItem", {
|
|
95
|
-
label: randomFirstKey,
|
|
96
|
-
value: `${randomFirstKey}-schema`,
|
|
97
|
-
children: [
|
|
98
|
-
(0, createDetails_1.createDetails)({
|
|
99
|
-
className: "openapi-markdown__details mime",
|
|
100
|
-
"data-collapsed": false,
|
|
101
|
-
open: true,
|
|
102
|
-
...rest,
|
|
103
|
-
children: [
|
|
104
|
-
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
105
|
-
className: "openapi-markdown__details-summary-mime",
|
|
106
|
-
children: [
|
|
107
|
-
(0, utils_1.create)("h3", {
|
|
108
|
-
className: "openapi-markdown__details-summary-header-body",
|
|
109
|
-
children: `${title}`,
|
|
110
|
-
}),
|
|
111
|
-
(0, utils_1.guard)(firstBody.type === "array", (format) => (0, utils_1.create)("span", {
|
|
112
|
-
style: { opacity: "0.6" },
|
|
113
|
-
children: ` array`,
|
|
114
|
-
})),
|
|
115
|
-
(0, utils_1.guard)(body.required, () => [
|
|
116
|
-
(0, utils_1.create)("strong", {
|
|
117
|
-
className: "openapi-schema__required",
|
|
118
|
-
children: "required",
|
|
119
|
-
}),
|
|
120
|
-
]),
|
|
121
|
-
],
|
|
122
|
-
}),
|
|
123
|
-
(0, utils_1.create)("div", {
|
|
124
|
-
style: { textAlign: "left", marginLeft: "1rem" },
|
|
125
|
-
children: [
|
|
126
|
-
(0, utils_1.guard)(body.description, () => [
|
|
127
|
-
(0, utils_1.create)("div", {
|
|
128
|
-
style: { marginTop: "1rem", marginBottom: "1rem" },
|
|
129
|
-
children: (0, createDescription_1.createDescription)(body.description),
|
|
130
|
-
}),
|
|
131
|
-
]),
|
|
132
|
-
],
|
|
133
|
-
}),
|
|
134
|
-
(0, utils_1.create)("ul", {
|
|
135
|
-
style: { marginLeft: "1rem" },
|
|
136
|
-
children: (0, createSchema_1.createNodes)(firstBody, "request"),
|
|
137
|
-
}),
|
|
138
|
-
],
|
|
139
|
-
}),
|
|
140
|
-
],
|
|
141
|
-
}),
|
|
142
|
-
],
|
|
143
|
-
});
|
|
12
|
+
return [
|
|
13
|
+
(0, utils_1.create)("RequestSchema", {
|
|
14
|
+
title: title,
|
|
15
|
+
body: body,
|
|
16
|
+
...rest,
|
|
17
|
+
}),
|
|
18
|
+
"\n\n",
|
|
19
|
+
];
|
|
144
20
|
}
|
|
145
21
|
exports.createRequestSchema = createRequestSchema;
|
|
@@ -10,5 +10,5 @@ interface Props {
|
|
|
10
10
|
required?: string[] | boolean;
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
export declare function createResponseSchema({ title, body, ...rest }: Props): string
|
|
13
|
+
export declare function createResponseSchema({ title, body, ...rest }: Props): string[];
|
|
14
14
|
export {};
|
|
@@ -7,101 +7,15 @@
|
|
|
7
7
|
* ========================================================================== */
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createResponseSchema = void 0;
|
|
10
|
-
const createDescription_1 = require("./createDescription");
|
|
11
|
-
const createDetails_1 = require("./createDetails");
|
|
12
|
-
const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
13
|
-
const createSchema_1 = require("./createSchema");
|
|
14
|
-
const createStatusCodes_1 = require("./createStatusCodes");
|
|
15
10
|
const utils_1 = require("./utils");
|
|
16
11
|
function createResponseSchema({ title, body, ...rest }) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (mimeTypes && mimeTypes.length) {
|
|
26
|
-
return (0, utils_1.create)("MimeTabs", {
|
|
27
|
-
className: "openapi-tabs__mime",
|
|
28
|
-
schemaType: "response",
|
|
29
|
-
children: mimeTypes.map((mimeType) => {
|
|
30
|
-
var _a;
|
|
31
|
-
const responseExamples = body.content[mimeType].examples;
|
|
32
|
-
const responseExample = body.content[mimeType].example;
|
|
33
|
-
const firstBody = (_a = body.content[mimeType].schema) !== null && _a !== void 0 ? _a : body.content[mimeType];
|
|
34
|
-
if (firstBody === undefined &&
|
|
35
|
-
responseExample === undefined &&
|
|
36
|
-
responseExamples === undefined) {
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
return (0, utils_1.create)("TabItem", {
|
|
40
|
-
label: `${mimeType}`,
|
|
41
|
-
value: `${mimeType}`,
|
|
42
|
-
children: [
|
|
43
|
-
(0, utils_1.create)("SchemaTabs", {
|
|
44
|
-
className: "openapi-tabs__schema",
|
|
45
|
-
// TODO: determine if we should persist this
|
|
46
|
-
// groupId: "schema-tabs",
|
|
47
|
-
children: [
|
|
48
|
-
firstBody &&
|
|
49
|
-
(0, utils_1.create)("TabItem", {
|
|
50
|
-
label: `${title}`,
|
|
51
|
-
value: `${title}`,
|
|
52
|
-
children: [
|
|
53
|
-
(0, createDetails_1.createDetails)({
|
|
54
|
-
className: "openapi-markdown__details response",
|
|
55
|
-
"data-collapsed": false,
|
|
56
|
-
open: true,
|
|
57
|
-
...rest,
|
|
58
|
-
children: [
|
|
59
|
-
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
60
|
-
className: "openapi-markdown__details-summary-response",
|
|
61
|
-
children: [
|
|
62
|
-
(0, utils_1.create)("strong", { children: `${title}` }),
|
|
63
|
-
(0, utils_1.guard)(body.required && body.required === true, () => [
|
|
64
|
-
(0, utils_1.create)("span", {
|
|
65
|
-
className: "openapi-schema__required",
|
|
66
|
-
children: "required",
|
|
67
|
-
}),
|
|
68
|
-
]),
|
|
69
|
-
],
|
|
70
|
-
}),
|
|
71
|
-
(0, utils_1.create)("div", {
|
|
72
|
-
style: { textAlign: "left", marginLeft: "1rem" },
|
|
73
|
-
children: [
|
|
74
|
-
(0, utils_1.guard)(body.description, () => [
|
|
75
|
-
(0, utils_1.create)("div", {
|
|
76
|
-
style: {
|
|
77
|
-
marginTop: "1rem",
|
|
78
|
-
marginBottom: "1rem",
|
|
79
|
-
},
|
|
80
|
-
children: (0, createDescription_1.createDescription)(body.description),
|
|
81
|
-
}),
|
|
82
|
-
]),
|
|
83
|
-
],
|
|
84
|
-
}),
|
|
85
|
-
(0, utils_1.create)("ul", {
|
|
86
|
-
style: { marginLeft: "1rem" },
|
|
87
|
-
children: (0, createSchema_1.createNodes)(firstBody, "response"),
|
|
88
|
-
}),
|
|
89
|
-
],
|
|
90
|
-
}),
|
|
91
|
-
],
|
|
92
|
-
}),
|
|
93
|
-
firstBody && (0, createStatusCodes_1.createExampleFromSchema)(firstBody, mimeType),
|
|
94
|
-
responseExamples &&
|
|
95
|
-
(0, createStatusCodes_1.createResponseExamples)(responseExamples, mimeType),
|
|
96
|
-
responseExample &&
|
|
97
|
-
(0, createStatusCodes_1.createResponseExample)(responseExample, mimeType),
|
|
98
|
-
],
|
|
99
|
-
}),
|
|
100
|
-
],
|
|
101
|
-
});
|
|
102
|
-
}),
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
return undefined;
|
|
12
|
+
return [
|
|
13
|
+
(0, utils_1.create)("ResponseSchema", {
|
|
14
|
+
title: title,
|
|
15
|
+
body: body,
|
|
16
|
+
...rest,
|
|
17
|
+
}),
|
|
18
|
+
"\n\n",
|
|
19
|
+
];
|
|
106
20
|
}
|
|
107
21
|
exports.createResponseSchema = createResponseSchema;
|
|
@@ -2,10 +2,7 @@ import { SchemaObject } from "../openapi/types";
|
|
|
2
2
|
/**
|
|
3
3
|
* Returns a merged representation of allOf array of schemas.
|
|
4
4
|
*/
|
|
5
|
-
export declare function mergeAllOf(allOf: SchemaObject
|
|
6
|
-
mergedSchemas: any;
|
|
7
|
-
mergedRequired: any;
|
|
8
|
-
};
|
|
5
|
+
export declare function mergeAllOf(allOf: SchemaObject): SchemaObject;
|
|
9
6
|
/**
|
|
10
7
|
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
11
8
|
*/
|