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,11 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import { createDetails } from "./createDetails";
|
|
10
|
-
import { createDetailsSummary } from "./createDetailsSummary";
|
|
11
|
-
import { createNodes } from "./createSchema";
|
|
12
|
-
import { create, guard } from "./utils";
|
|
8
|
+
import { create } from "./utils";
|
|
13
9
|
import { MediaTypeObject } from "../openapi/types";
|
|
14
10
|
|
|
15
11
|
interface Props {
|
|
@@ -25,142 +21,12 @@ interface Props {
|
|
|
25
21
|
}
|
|
26
22
|
|
|
27
23
|
export function createRequestSchema({ title, body, ...rest }: Props) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// Get all MIME types, including vendor-specific
|
|
38
|
-
const mimeTypes = Object.keys(body.content);
|
|
39
|
-
|
|
40
|
-
if (mimeTypes && mimeTypes.length > 1) {
|
|
41
|
-
return create("MimeTabs", {
|
|
42
|
-
className: "openapi-tabs__mime",
|
|
43
|
-
schemaType: "request",
|
|
44
|
-
children: mimeTypes.map((mimeType) => {
|
|
45
|
-
const firstBody = body.content![mimeType].schema;
|
|
46
|
-
if (firstBody === undefined) {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
if (firstBody.properties !== undefined) {
|
|
50
|
-
if (Object.keys(firstBody.properties).length === 0) {
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return create("TabItem", {
|
|
55
|
-
label: mimeType,
|
|
56
|
-
value: `${mimeType}`,
|
|
57
|
-
children: [
|
|
58
|
-
createDetails({
|
|
59
|
-
className: "openapi-markdown__details mime",
|
|
60
|
-
"data-collapsed": false,
|
|
61
|
-
open: true,
|
|
62
|
-
...rest,
|
|
63
|
-
children: [
|
|
64
|
-
createDetailsSummary({
|
|
65
|
-
className: "openapi-markdown__details-summary-mime",
|
|
66
|
-
children: [
|
|
67
|
-
create("h3", {
|
|
68
|
-
className:
|
|
69
|
-
"openapi-markdown__details-summary-header-body",
|
|
70
|
-
children: `${title}`,
|
|
71
|
-
}),
|
|
72
|
-
guard(body.required && body.required === true, () => [
|
|
73
|
-
create("span", {
|
|
74
|
-
className: "openapi-schema__required",
|
|
75
|
-
children: "required",
|
|
76
|
-
}),
|
|
77
|
-
]),
|
|
78
|
-
],
|
|
79
|
-
}),
|
|
80
|
-
create("div", {
|
|
81
|
-
style: { textAlign: "left", marginLeft: "1rem" },
|
|
82
|
-
children: [
|
|
83
|
-
guard(body.description, () => [
|
|
84
|
-
create("div", {
|
|
85
|
-
style: { marginTop: "1rem", marginBottom: "1rem" },
|
|
86
|
-
children: createDescription(body.description),
|
|
87
|
-
}),
|
|
88
|
-
]),
|
|
89
|
-
],
|
|
90
|
-
}),
|
|
91
|
-
create("ul", {
|
|
92
|
-
style: { marginLeft: "1rem" },
|
|
93
|
-
children: createNodes(firstBody, "request"),
|
|
94
|
-
}),
|
|
95
|
-
],
|
|
96
|
-
}),
|
|
97
|
-
],
|
|
98
|
-
});
|
|
99
|
-
}),
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const randomFirstKey = Object.keys(body.content)[0];
|
|
104
|
-
const firstBody: any =
|
|
105
|
-
body.content[randomFirstKey].schema ?? body.content![randomFirstKey];
|
|
106
|
-
|
|
107
|
-
if (firstBody === undefined) {
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return create("MimeTabs", {
|
|
112
|
-
className: "openapi-tabs__mime",
|
|
113
|
-
children: [
|
|
114
|
-
create("TabItem", {
|
|
115
|
-
label: randomFirstKey,
|
|
116
|
-
value: `${randomFirstKey}-schema`,
|
|
117
|
-
children: [
|
|
118
|
-
createDetails({
|
|
119
|
-
className: "openapi-markdown__details mime",
|
|
120
|
-
"data-collapsed": false,
|
|
121
|
-
open: true,
|
|
122
|
-
...rest,
|
|
123
|
-
children: [
|
|
124
|
-
createDetailsSummary({
|
|
125
|
-
className: "openapi-markdown__details-summary-mime",
|
|
126
|
-
children: [
|
|
127
|
-
create("h3", {
|
|
128
|
-
className: "openapi-markdown__details-summary-header-body",
|
|
129
|
-
children: `${title}`,
|
|
130
|
-
}),
|
|
131
|
-
guard(firstBody.type === "array", (format) =>
|
|
132
|
-
create("span", {
|
|
133
|
-
style: { opacity: "0.6" },
|
|
134
|
-
children: ` array`,
|
|
135
|
-
})
|
|
136
|
-
),
|
|
137
|
-
guard(body.required, () => [
|
|
138
|
-
create("strong", {
|
|
139
|
-
className: "openapi-schema__required",
|
|
140
|
-
children: "required",
|
|
141
|
-
}),
|
|
142
|
-
]),
|
|
143
|
-
],
|
|
144
|
-
}),
|
|
145
|
-
create("div", {
|
|
146
|
-
style: { textAlign: "left", marginLeft: "1rem" },
|
|
147
|
-
children: [
|
|
148
|
-
guard(body.description, () => [
|
|
149
|
-
create("div", {
|
|
150
|
-
style: { marginTop: "1rem", marginBottom: "1rem" },
|
|
151
|
-
children: createDescription(body.description),
|
|
152
|
-
}),
|
|
153
|
-
]),
|
|
154
|
-
],
|
|
155
|
-
}),
|
|
156
|
-
create("ul", {
|
|
157
|
-
style: { marginLeft: "1rem" },
|
|
158
|
-
children: createNodes(firstBody, "request"),
|
|
159
|
-
}),
|
|
160
|
-
],
|
|
161
|
-
}),
|
|
162
|
-
],
|
|
163
|
-
}),
|
|
164
|
-
],
|
|
165
|
-
});
|
|
24
|
+
return [
|
|
25
|
+
create("RequestSchema", {
|
|
26
|
+
title: title,
|
|
27
|
+
body: body,
|
|
28
|
+
...rest,
|
|
29
|
+
}),
|
|
30
|
+
"\n\n",
|
|
31
|
+
];
|
|
166
32
|
}
|
|
@@ -5,16 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import { createDetails } from "./createDetails";
|
|
10
|
-
import { createDetailsSummary } from "./createDetailsSummary";
|
|
11
|
-
import { createNodes } from "./createSchema";
|
|
12
|
-
import {
|
|
13
|
-
createExampleFromSchema,
|
|
14
|
-
createResponseExample,
|
|
15
|
-
createResponseExamples,
|
|
16
|
-
} from "./createStatusCodes";
|
|
17
|
-
import { create, guard } from "./utils";
|
|
8
|
+
import { create } from "./utils";
|
|
18
9
|
import { MediaTypeObject } from "../openapi/types";
|
|
19
10
|
|
|
20
11
|
interface Props {
|
|
@@ -30,106 +21,12 @@ interface Props {
|
|
|
30
21
|
}
|
|
31
22
|
|
|
32
23
|
export function createResponseSchema({ title, body, ...rest }: Props) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// Get all MIME types, including vendor-specific
|
|
43
|
-
const mimeTypes = Object.keys(body.content);
|
|
44
|
-
|
|
45
|
-
if (mimeTypes && mimeTypes.length) {
|
|
46
|
-
return create("MimeTabs", {
|
|
47
|
-
className: "openapi-tabs__mime",
|
|
48
|
-
schemaType: "response",
|
|
49
|
-
children: mimeTypes.map((mimeType: any) => {
|
|
50
|
-
const responseExamples = body.content![mimeType].examples;
|
|
51
|
-
const responseExample = body.content![mimeType].example;
|
|
52
|
-
const firstBody: any =
|
|
53
|
-
body.content![mimeType].schema ?? body.content![mimeType];
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
firstBody === undefined &&
|
|
57
|
-
responseExample === undefined &&
|
|
58
|
-
responseExamples === undefined
|
|
59
|
-
) {
|
|
60
|
-
return undefined;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return create("TabItem", {
|
|
64
|
-
label: `${mimeType}`,
|
|
65
|
-
value: `${mimeType}`,
|
|
66
|
-
children: [
|
|
67
|
-
create("SchemaTabs", {
|
|
68
|
-
className: "openapi-tabs__schema",
|
|
69
|
-
// TODO: determine if we should persist this
|
|
70
|
-
// groupId: "schema-tabs",
|
|
71
|
-
children: [
|
|
72
|
-
firstBody &&
|
|
73
|
-
create("TabItem", {
|
|
74
|
-
label: `${title}`,
|
|
75
|
-
value: `${title}`,
|
|
76
|
-
children: [
|
|
77
|
-
createDetails({
|
|
78
|
-
className: "openapi-markdown__details response",
|
|
79
|
-
"data-collapsed": false,
|
|
80
|
-
open: true,
|
|
81
|
-
...rest,
|
|
82
|
-
children: [
|
|
83
|
-
createDetailsSummary({
|
|
84
|
-
className:
|
|
85
|
-
"openapi-markdown__details-summary-response",
|
|
86
|
-
children: [
|
|
87
|
-
create("strong", { children: `${title}` }),
|
|
88
|
-
guard(
|
|
89
|
-
body.required && body.required === true,
|
|
90
|
-
() => [
|
|
91
|
-
create("span", {
|
|
92
|
-
className: "openapi-schema__required",
|
|
93
|
-
children: "required",
|
|
94
|
-
}),
|
|
95
|
-
]
|
|
96
|
-
),
|
|
97
|
-
],
|
|
98
|
-
}),
|
|
99
|
-
create("div", {
|
|
100
|
-
style: { textAlign: "left", marginLeft: "1rem" },
|
|
101
|
-
children: [
|
|
102
|
-
guard(body.description, () => [
|
|
103
|
-
create("div", {
|
|
104
|
-
style: {
|
|
105
|
-
marginTop: "1rem",
|
|
106
|
-
marginBottom: "1rem",
|
|
107
|
-
},
|
|
108
|
-
children: createDescription(body.description),
|
|
109
|
-
}),
|
|
110
|
-
]),
|
|
111
|
-
],
|
|
112
|
-
}),
|
|
113
|
-
create("ul", {
|
|
114
|
-
style: { marginLeft: "1rem" },
|
|
115
|
-
children: createNodes(firstBody!, "response"),
|
|
116
|
-
}),
|
|
117
|
-
],
|
|
118
|
-
}),
|
|
119
|
-
],
|
|
120
|
-
}),
|
|
121
|
-
firstBody && createExampleFromSchema(firstBody, mimeType),
|
|
122
|
-
responseExamples &&
|
|
123
|
-
createResponseExamples(responseExamples, mimeType),
|
|
124
|
-
responseExample &&
|
|
125
|
-
createResponseExample(responseExample, mimeType),
|
|
126
|
-
],
|
|
127
|
-
}),
|
|
128
|
-
],
|
|
129
|
-
});
|
|
130
|
-
}),
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return undefined;
|
|
24
|
+
return [
|
|
25
|
+
create("ResponseSchema", {
|
|
26
|
+
title: title,
|
|
27
|
+
body: body,
|
|
28
|
+
...rest,
|
|
29
|
+
}),
|
|
30
|
+
"\n\n",
|
|
31
|
+
];
|
|
135
32
|
}
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
9
|
+
import { merge } from "allof-merge";
|
|
8
10
|
import clsx from "clsx";
|
|
9
11
|
import isEmpty from "lodash/isEmpty";
|
|
10
12
|
|
|
@@ -19,41 +21,18 @@ import { getQualifierMessage, getSchemaName } from "./schema";
|
|
|
19
21
|
import { create, guard } from "./utils";
|
|
20
22
|
import { SchemaObject } from "../openapi/types";
|
|
21
23
|
|
|
22
|
-
const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
|
|
23
|
-
|
|
24
24
|
let SCHEMA_TYPE: "request" | "response";
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Returns a merged representation of allOf array of schemas.
|
|
28
28
|
*/
|
|
29
|
-
export function mergeAllOf(allOf: SchemaObject
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return true;
|
|
34
|
-
},
|
|
35
|
-
writeOnly: function () {
|
|
36
|
-
return true;
|
|
37
|
-
},
|
|
38
|
-
example: function () {
|
|
39
|
-
return true;
|
|
40
|
-
},
|
|
41
|
-
"x-examples": function () {
|
|
42
|
-
return true;
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
ignoreAdditionalProperties: true,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const mergedRequired = allOf.reduce((acc, cur) => {
|
|
49
|
-
if (Array.isArray(cur.required)) {
|
|
50
|
-
const next = [...acc, ...cur.required];
|
|
51
|
-
return next;
|
|
52
|
-
}
|
|
53
|
-
return acc;
|
|
54
|
-
}, [] as any);
|
|
29
|
+
export function mergeAllOf(allOf: SchemaObject) {
|
|
30
|
+
const onMergeError = (msg: string) => {
|
|
31
|
+
console.warn(msg);
|
|
32
|
+
};
|
|
55
33
|
|
|
56
|
-
|
|
34
|
+
const mergedSchemas = merge(allOf, { onMergeError }) as SchemaObject;
|
|
35
|
+
return mergedSchemas;
|
|
57
36
|
}
|
|
58
37
|
|
|
59
38
|
/**
|
|
@@ -271,10 +250,7 @@ function createItems(schema: SchemaObject) {
|
|
|
271
250
|
|
|
272
251
|
if (schema.items?.allOf !== undefined) {
|
|
273
252
|
// TODO: figure out if and how we should pass merged required array
|
|
274
|
-
const
|
|
275
|
-
mergedSchemas,
|
|
276
|
-
}: { mergedSchemas: SchemaObject; mergedRequired: string[] | boolean } =
|
|
277
|
-
mergeAllOf(schema.items?.allOf);
|
|
253
|
+
const mergedSchemas = mergeAllOf(schema.items) as SchemaObject;
|
|
278
254
|
|
|
279
255
|
// Handles combo anyOf/oneOf + properties
|
|
280
256
|
if (
|
|
@@ -683,61 +659,53 @@ function createEdges({
|
|
|
683
659
|
);
|
|
684
660
|
}
|
|
685
661
|
|
|
686
|
-
if (schema.allOf !== undefined) {
|
|
687
|
-
const
|
|
688
|
-
schema.allOf
|
|
689
|
-
);
|
|
690
|
-
delete schema.allOf;
|
|
691
|
-
const combinedSchemas = { ...schema, ...mergedSchemas };
|
|
662
|
+
if (schema.items?.allOf !== undefined) {
|
|
663
|
+
const mergedSchemas = mergeAllOf(schema.items);
|
|
692
664
|
|
|
693
665
|
if (SCHEMA_TYPE === "request") {
|
|
694
|
-
if (
|
|
666
|
+
if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
|
|
695
667
|
return undefined;
|
|
696
668
|
}
|
|
697
669
|
}
|
|
698
670
|
|
|
699
671
|
if (SCHEMA_TYPE === "response") {
|
|
700
|
-
if (
|
|
672
|
+
if (mergedSchemas.writeOnly && mergedSchemas.writeOnly === true) {
|
|
701
673
|
return undefined;
|
|
702
674
|
}
|
|
703
675
|
}
|
|
704
676
|
|
|
705
|
-
const mergedSchemaName = getSchemaName(
|
|
706
|
-
|
|
707
|
-
if (name === "eventName") {
|
|
708
|
-
console.log(mergedSchemaName, combinedSchemas);
|
|
709
|
-
}
|
|
677
|
+
const mergedSchemaName = getSchemaName(mergedSchemas);
|
|
710
678
|
|
|
711
679
|
if (
|
|
712
|
-
|
|
713
|
-
|
|
680
|
+
mergedSchemas.oneOf !== undefined ||
|
|
681
|
+
mergedSchemas.anyOf !== undefined
|
|
714
682
|
) {
|
|
715
683
|
return createDetailsNode(
|
|
716
684
|
name,
|
|
717
685
|
mergedSchemaName,
|
|
718
|
-
|
|
686
|
+
mergedSchemas,
|
|
719
687
|
required,
|
|
720
|
-
|
|
688
|
+
mergedSchemas.nullable
|
|
721
689
|
);
|
|
722
690
|
}
|
|
723
691
|
|
|
724
|
-
if (
|
|
692
|
+
if (mergedSchemas.properties !== undefined) {
|
|
725
693
|
return createDetailsNode(
|
|
726
694
|
name,
|
|
727
695
|
mergedSchemaName,
|
|
728
|
-
|
|
696
|
+
mergedSchemas,
|
|
729
697
|
required,
|
|
730
|
-
|
|
698
|
+
mergedSchemas.nullable
|
|
731
699
|
);
|
|
732
700
|
}
|
|
733
701
|
|
|
734
|
-
if (
|
|
702
|
+
if (mergedSchemas.additionalProperties !== undefined) {
|
|
735
703
|
return createDetailsNode(
|
|
736
704
|
name,
|
|
737
705
|
mergedSchemaName,
|
|
738
|
-
|
|
706
|
+
mergedSchemas,
|
|
739
707
|
required,
|
|
740
|
-
|
|
708
|
+
mergedSchemas.nullable
|
|
741
709
|
);
|
|
742
710
|
}
|
|
743
711
|
|
|
@@ -746,9 +714,9 @@ function createEdges({
|
|
|
746
714
|
return createDetailsNode(
|
|
747
715
|
name,
|
|
748
716
|
mergedSchemaName,
|
|
749
|
-
|
|
717
|
+
mergedSchemas,
|
|
750
718
|
required,
|
|
751
|
-
|
|
719
|
+
mergedSchemas.nullable
|
|
752
720
|
);
|
|
753
721
|
}
|
|
754
722
|
|
|
@@ -757,8 +725,8 @@ function createEdges({
|
|
|
757
725
|
name,
|
|
758
726
|
required: Array.isArray(required) ? required.includes(name) : required,
|
|
759
727
|
schemaName: mergedSchemaName,
|
|
760
|
-
qualifierMessage: getQualifierMessage(
|
|
761
|
-
schema:
|
|
728
|
+
qualifierMessage: getQualifierMessage(mergedSchemas),
|
|
729
|
+
schema: mergedSchemas,
|
|
762
730
|
});
|
|
763
731
|
}
|
|
764
732
|
|
|
@@ -815,7 +783,7 @@ export function createNodes(
|
|
|
815
783
|
}
|
|
816
784
|
|
|
817
785
|
if (schema.allOf !== undefined) {
|
|
818
|
-
const
|
|
786
|
+
const mergedSchemas = mergeAllOf(schema) as SchemaObject;
|
|
819
787
|
|
|
820
788
|
if (
|
|
821
789
|
mergedSchemas.oneOf !== undefined ||
|