docusaurus-plugin-openapi-docs 1.5.1 → 1.5.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/markdown/createArrayBracket.d.ts +2 -0
- package/lib/markdown/createArrayBracket.js +37 -0
- package/lib/markdown/createRequestSchema.js +119 -79
- package/lib/markdown/createResponseSchema.js +123 -82
- package/lib/markdown/createStatusCodes.js +4 -6
- package/lib/openapi/createRequestExample.js +26 -7
- package/lib/openapi/createResponseExample.js +26 -7
- package/package.json +2 -2
- package/src/markdown/createArrayBracket.ts +35 -0
- package/src/markdown/createRequestSchema.ts +136 -95
- package/src/markdown/createResponseSchema.ts +143 -98
- package/src/markdown/createStatusCodes.ts +4 -8
- package/src/openapi/createRequestExample.ts +35 -12
- package/src/openapi/createResponseExample.ts +35 -12
|
@@ -110,12 +110,10 @@ function createResponseExamples(responseExamples, mimeType) {
|
|
|
110
110
|
language = "xml";
|
|
111
111
|
}
|
|
112
112
|
return Object.entries(responseExamples).map(([exampleName, exampleValue]) => {
|
|
113
|
-
const camelToSpaceName = exampleName.replace(/([A-Z])/g, " $1");
|
|
114
|
-
let finalFormattedName = camelToSpaceName.charAt(0).toUpperCase() + camelToSpaceName.slice(1);
|
|
115
113
|
if (typeof exampleValue.value === "object") {
|
|
116
114
|
return (0, utils_1.create)("TabItem", {
|
|
117
|
-
label: `${
|
|
118
|
-
value: `${
|
|
115
|
+
label: `${exampleName}`,
|
|
116
|
+
value: `${exampleName}`,
|
|
119
117
|
children: [
|
|
120
118
|
(0, utils_2.guard)(exampleValue.summary, (summary) => [
|
|
121
119
|
(0, utils_1.create)("p", {
|
|
@@ -130,8 +128,8 @@ function createResponseExamples(responseExamples, mimeType) {
|
|
|
130
128
|
});
|
|
131
129
|
}
|
|
132
130
|
return (0, utils_1.create)("TabItem", {
|
|
133
|
-
label: `${
|
|
134
|
-
value: `${
|
|
131
|
+
label: `${exampleName}`,
|
|
132
|
+
value: `${exampleName}`,
|
|
135
133
|
children: [
|
|
136
134
|
(0, utils_2.guard)(exampleValue.summary, (summary) => [
|
|
137
135
|
(0, utils_1.create)("p", {
|
|
@@ -11,6 +11,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.sampleRequestFromSchema = void 0;
|
|
13
13
|
const chalk_1 = __importDefault(require("chalk"));
|
|
14
|
+
const merge_1 = __importDefault(require("lodash/merge"));
|
|
14
15
|
const createRequestSchema_1 = require("../markdown/createRequestSchema");
|
|
15
16
|
const primitives = {
|
|
16
17
|
string: {
|
|
@@ -60,15 +61,27 @@ function sampleRequestFromProp(name, prop, obj) {
|
|
|
60
61
|
}
|
|
61
62
|
const sampleRequestFromSchema = (schema = {}) => {
|
|
62
63
|
try {
|
|
63
|
-
|
|
64
|
+
// deep copy schema before processing
|
|
65
|
+
let schemaCopy = JSON.parse(JSON.stringify(schema));
|
|
66
|
+
let { type, example, allOf, properties, items, oneOf, anyOf } = schemaCopy;
|
|
64
67
|
if (example !== undefined) {
|
|
65
68
|
return example;
|
|
66
69
|
}
|
|
67
70
|
if (oneOf) {
|
|
71
|
+
if (properties) {
|
|
72
|
+
const combinedSchemas = (0, merge_1.default)(schemaCopy, oneOf[0]);
|
|
73
|
+
delete combinedSchemas.oneOf;
|
|
74
|
+
return (0, exports.sampleRequestFromSchema)(combinedSchemas);
|
|
75
|
+
}
|
|
68
76
|
// Just go with first schema
|
|
69
77
|
return (0, exports.sampleRequestFromSchema)(oneOf[0]);
|
|
70
78
|
}
|
|
71
79
|
if (anyOf) {
|
|
80
|
+
if (properties) {
|
|
81
|
+
const combinedSchemas = (0, merge_1.default)(schemaCopy, anyOf[0]);
|
|
82
|
+
delete combinedSchemas.anyOf;
|
|
83
|
+
return (0, exports.sampleRequestFromSchema)(combinedSchemas);
|
|
84
|
+
}
|
|
72
85
|
// Just go with first schema
|
|
73
86
|
return (0, exports.sampleRequestFromSchema)(anyOf[0]);
|
|
74
87
|
}
|
|
@@ -81,6 +94,11 @@ const sampleRequestFromSchema = (schema = {}) => {
|
|
|
81
94
|
}
|
|
82
95
|
}
|
|
83
96
|
}
|
|
97
|
+
if (properties) {
|
|
98
|
+
const combinedSchemas = (0, merge_1.default)(schemaCopy, mergedSchemas);
|
|
99
|
+
delete combinedSchemas.allOf;
|
|
100
|
+
return (0, exports.sampleRequestFromSchema)(combinedSchemas);
|
|
101
|
+
}
|
|
84
102
|
return (0, exports.sampleRequestFromSchema)(mergedSchemas);
|
|
85
103
|
}
|
|
86
104
|
if (!type) {
|
|
@@ -133,16 +151,17 @@ const sampleRequestFromSchema = (schema = {}) => {
|
|
|
133
151
|
}
|
|
134
152
|
return [(0, exports.sampleRequestFromSchema)(items)];
|
|
135
153
|
}
|
|
136
|
-
if (
|
|
137
|
-
if (
|
|
138
|
-
return
|
|
154
|
+
if (schemaCopy.enum) {
|
|
155
|
+
if (schemaCopy.default) {
|
|
156
|
+
return schemaCopy.default;
|
|
139
157
|
}
|
|
140
|
-
return normalizeArray(
|
|
158
|
+
return normalizeArray(schemaCopy.enum)[0];
|
|
141
159
|
}
|
|
142
|
-
if ((schema.readOnly && schema.readOnly === true) ||
|
|
160
|
+
if ((schema.readOnly && schema.readOnly === true) ||
|
|
161
|
+
schemaCopy.deprecated) {
|
|
143
162
|
return undefined;
|
|
144
163
|
}
|
|
145
|
-
return primitive(
|
|
164
|
+
return primitive(schemaCopy);
|
|
146
165
|
}
|
|
147
166
|
catch (err) {
|
|
148
167
|
console.error(chalk_1.default.yellow("WARNING: failed to create example from schema object:", err));
|
|
@@ -11,6 +11,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.sampleResponseFromSchema = void 0;
|
|
13
13
|
const chalk_1 = __importDefault(require("chalk"));
|
|
14
|
+
const merge_1 = __importDefault(require("lodash/merge"));
|
|
14
15
|
const createResponseSchema_1 = require("../markdown/createResponseSchema");
|
|
15
16
|
const primitives = {
|
|
16
17
|
string: {
|
|
@@ -60,7 +61,9 @@ function sampleResponseFromProp(name, prop, obj) {
|
|
|
60
61
|
}
|
|
61
62
|
const sampleResponseFromSchema = (schema = {}) => {
|
|
62
63
|
try {
|
|
63
|
-
|
|
64
|
+
// deep copy schema before processing
|
|
65
|
+
let schemaCopy = JSON.parse(JSON.stringify(schema));
|
|
66
|
+
let { type, example, allOf, properties, items, oneOf, anyOf } = schemaCopy;
|
|
64
67
|
if (example !== undefined) {
|
|
65
68
|
return example;
|
|
66
69
|
}
|
|
@@ -74,13 +77,28 @@ const sampleResponseFromSchema = (schema = {}) => {
|
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
79
|
}
|
|
80
|
+
if (properties) {
|
|
81
|
+
const combinedSchemas = (0, merge_1.default)(schemaCopy, mergedSchemas);
|
|
82
|
+
delete combinedSchemas.allOf;
|
|
83
|
+
return (0, exports.sampleResponseFromSchema)(combinedSchemas);
|
|
84
|
+
}
|
|
77
85
|
return (0, exports.sampleResponseFromSchema)(mergedSchemas);
|
|
78
86
|
}
|
|
79
87
|
if (oneOf) {
|
|
88
|
+
if (properties) {
|
|
89
|
+
const combinedSchemas = (0, merge_1.default)(schemaCopy, oneOf[0]);
|
|
90
|
+
delete combinedSchemas.oneOf;
|
|
91
|
+
return (0, exports.sampleResponseFromSchema)(combinedSchemas);
|
|
92
|
+
}
|
|
80
93
|
// Just go with first schema
|
|
81
94
|
return (0, exports.sampleResponseFromSchema)(oneOf[0]);
|
|
82
95
|
}
|
|
83
96
|
if (anyOf) {
|
|
97
|
+
if (properties) {
|
|
98
|
+
const combinedSchemas = (0, merge_1.default)(schemaCopy, anyOf[0]);
|
|
99
|
+
delete combinedSchemas.anyOf;
|
|
100
|
+
return (0, exports.sampleResponseFromSchema)(combinedSchemas);
|
|
101
|
+
}
|
|
84
102
|
// Just go with first schema
|
|
85
103
|
return (0, exports.sampleResponseFromSchema)(anyOf[0]);
|
|
86
104
|
}
|
|
@@ -134,16 +152,17 @@ const sampleResponseFromSchema = (schema = {}) => {
|
|
|
134
152
|
}
|
|
135
153
|
return [(0, exports.sampleResponseFromSchema)(items)];
|
|
136
154
|
}
|
|
137
|
-
if (
|
|
138
|
-
if (
|
|
139
|
-
return
|
|
155
|
+
if (schemaCopy.enum) {
|
|
156
|
+
if (schemaCopy.default) {
|
|
157
|
+
return schemaCopy.default;
|
|
140
158
|
}
|
|
141
|
-
return normalizeArray(
|
|
159
|
+
return normalizeArray(schemaCopy.enum)[0];
|
|
142
160
|
}
|
|
143
|
-
if ((
|
|
161
|
+
if ((schemaCopy.writeOnly && schemaCopy.writeOnly === true) ||
|
|
162
|
+
schemaCopy.deprecated) {
|
|
144
163
|
return undefined;
|
|
145
164
|
}
|
|
146
|
-
return primitive(
|
|
165
|
+
return primitive(schemaCopy);
|
|
147
166
|
}
|
|
148
167
|
catch (err) {
|
|
149
168
|
console.error(chalk_1.default.yellow("WARNING: failed to create example from schema object:", err));
|
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.5.
|
|
4
|
+
"version": "1.5.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": "fa3096190356c0161a8e255b9950857a7b131eef"
|
|
72
72
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import { create } from "./utils";
|
|
9
|
+
|
|
10
|
+
export function createOpeningArrayBracket() {
|
|
11
|
+
return create("li", {
|
|
12
|
+
children: create("div", {
|
|
13
|
+
style: {
|
|
14
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
15
|
+
opacity: "0.6",
|
|
16
|
+
marginLeft: "-.5rem",
|
|
17
|
+
paddingBottom: ".5rem",
|
|
18
|
+
},
|
|
19
|
+
children: ["Array ["],
|
|
20
|
+
}),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function createClosingArrayBracket() {
|
|
25
|
+
return create("li", {
|
|
26
|
+
children: create("div", {
|
|
27
|
+
style: {
|
|
28
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
29
|
+
opacity: "0.6",
|
|
30
|
+
marginLeft: "-.5rem",
|
|
31
|
+
},
|
|
32
|
+
children: ["]"],
|
|
33
|
+
}),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
8
|
import { MediaTypeObject, SchemaObject } from "../openapi/types";
|
|
9
|
+
import {
|
|
10
|
+
createClosingArrayBracket,
|
|
11
|
+
createOpeningArrayBracket,
|
|
12
|
+
} from "./createArrayBracket";
|
|
9
13
|
import { createDescription } from "./createDescription";
|
|
10
14
|
import { createDetails } from "./createDetails";
|
|
11
15
|
import { createDetailsSummary } from "./createDetailsSummary";
|
|
@@ -49,54 +53,62 @@ export function mergeAllOf(allOf: SchemaObject[]) {
|
|
|
49
53
|
*/
|
|
50
54
|
function createAnyOneOf(schema: SchemaObject): any {
|
|
51
55
|
const type = schema.oneOf ? "oneOf" : "anyOf";
|
|
52
|
-
return create("
|
|
56
|
+
return create("li", {
|
|
53
57
|
children: [
|
|
54
|
-
create("
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
58
|
+
create("span", {
|
|
59
|
+
className: "badge badge--info",
|
|
60
|
+
children: type,
|
|
61
|
+
}),
|
|
62
|
+
create("SchemaTabs", {
|
|
63
|
+
children: schema[type]!.map((anyOneSchema, index) => {
|
|
64
|
+
const label = anyOneSchema.title
|
|
65
|
+
? anyOneSchema.title
|
|
66
|
+
: `MOD${index + 1}`;
|
|
67
|
+
const anyOneChildren = [];
|
|
68
|
+
|
|
69
|
+
if (anyOneSchema.properties !== undefined) {
|
|
70
|
+
anyOneChildren.push(createProperties(anyOneSchema));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (anyOneSchema.allOf !== undefined) {
|
|
74
|
+
anyOneChildren.push(createNodes(anyOneSchema));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (anyOneSchema.items !== undefined) {
|
|
78
|
+
anyOneChildren.push(createItems(anyOneSchema));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (
|
|
82
|
+
anyOneSchema.type === "string" ||
|
|
83
|
+
anyOneSchema.type === "number" ||
|
|
84
|
+
anyOneSchema.type === "integer" ||
|
|
85
|
+
anyOneSchema.type === "boolean"
|
|
86
|
+
) {
|
|
87
|
+
anyOneChildren.push(createNodes(anyOneSchema));
|
|
88
|
+
}
|
|
89
|
+
if (anyOneChildren.length) {
|
|
90
|
+
if (schema.type === "array") {
|
|
91
|
+
return create("TabItem", {
|
|
92
|
+
label: label,
|
|
93
|
+
value: `${index}-item-properties`,
|
|
94
|
+
children: [
|
|
95
|
+
createOpeningArrayBracket(),
|
|
96
|
+
anyOneChildren,
|
|
97
|
+
createClosingArrayBracket(),
|
|
98
|
+
]
|
|
99
|
+
.filter(Boolean)
|
|
100
|
+
.flat(),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return create("TabItem", {
|
|
104
|
+
label: label,
|
|
105
|
+
value: `${index}-item-properties`,
|
|
106
|
+
children: anyOneChildren.filter(Boolean).flat(),
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return undefined;
|
|
111
|
+
}),
|
|
100
112
|
}),
|
|
101
113
|
],
|
|
102
114
|
});
|
|
@@ -147,11 +159,11 @@ function createAdditionalProperties(schema: SchemaObject) {
|
|
|
147
159
|
// }
|
|
148
160
|
|
|
149
161
|
if (
|
|
150
|
-
schema.additionalProperties?.type === "string" ||
|
|
151
|
-
schema.additionalProperties?.type === "object" ||
|
|
152
|
-
schema.additionalProperties?.type === "boolean" ||
|
|
153
|
-
schema.additionalProperties?.type === "integer" ||
|
|
154
|
-
schema.additionalProperties?.type === "number"
|
|
162
|
+
(schema.additionalProperties?.type as string) === "string" ||
|
|
163
|
+
(schema.additionalProperties?.type as string) === "object" ||
|
|
164
|
+
(schema.additionalProperties?.type as string) === "boolean" ||
|
|
165
|
+
(schema.additionalProperties?.type as string) === "integer" ||
|
|
166
|
+
(schema.additionalProperties?.type as string) === "number"
|
|
155
167
|
) {
|
|
156
168
|
const type = schema.additionalProperties?.type;
|
|
157
169
|
const additionalProperties =
|
|
@@ -219,15 +231,27 @@ function createAdditionalProperties(schema: SchemaObject) {
|
|
|
219
231
|
// TODO: figure out how to handle array of objects
|
|
220
232
|
function createItems(schema: SchemaObject) {
|
|
221
233
|
if (schema.items?.properties !== undefined) {
|
|
222
|
-
return
|
|
234
|
+
return [
|
|
235
|
+
createOpeningArrayBracket(),
|
|
236
|
+
createProperties(schema.items),
|
|
237
|
+
createClosingArrayBracket(),
|
|
238
|
+
].flat();
|
|
223
239
|
}
|
|
224
240
|
|
|
225
241
|
if (schema.items?.additionalProperties !== undefined) {
|
|
226
|
-
return
|
|
242
|
+
return [
|
|
243
|
+
createOpeningArrayBracket(),
|
|
244
|
+
createAdditionalProperties(schema.items),
|
|
245
|
+
createClosingArrayBracket(),
|
|
246
|
+
].flat();
|
|
227
247
|
}
|
|
228
248
|
|
|
229
249
|
if (schema.items?.oneOf !== undefined || schema.items?.anyOf !== undefined) {
|
|
230
|
-
return
|
|
250
|
+
return [
|
|
251
|
+
createOpeningArrayBracket(),
|
|
252
|
+
createAnyOneOf(schema.items!),
|
|
253
|
+
createClosingArrayBracket(),
|
|
254
|
+
].flat();
|
|
231
255
|
}
|
|
232
256
|
|
|
233
257
|
if (schema.items?.allOf !== undefined) {
|
|
@@ -244,12 +268,12 @@ function createItems(schema: SchemaObject) {
|
|
|
244
268
|
mergedSchemas.anyOf !== undefined) &&
|
|
245
269
|
mergedSchemas.properties
|
|
246
270
|
) {
|
|
247
|
-
return
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
271
|
+
return [
|
|
272
|
+
createOpeningArrayBracket(),
|
|
273
|
+
createAnyOneOf(mergedSchemas),
|
|
274
|
+
createProperties(mergedSchemas),
|
|
275
|
+
createClosingArrayBracket(),
|
|
276
|
+
].flat();
|
|
253
277
|
}
|
|
254
278
|
|
|
255
279
|
// Handles only anyOf/oneOf
|
|
@@ -257,16 +281,20 @@ function createItems(schema: SchemaObject) {
|
|
|
257
281
|
mergedSchemas.oneOf !== undefined ||
|
|
258
282
|
mergedSchemas.anyOf !== undefined
|
|
259
283
|
) {
|
|
260
|
-
return
|
|
261
|
-
|
|
262
|
-
|
|
284
|
+
return [
|
|
285
|
+
createOpeningArrayBracket(),
|
|
286
|
+
createAnyOneOf(mergedSchemas),
|
|
287
|
+
createClosingArrayBracket(),
|
|
288
|
+
].flat();
|
|
263
289
|
}
|
|
264
290
|
|
|
265
291
|
// Handles properties
|
|
266
292
|
if (mergedSchemas.properties !== undefined) {
|
|
267
|
-
return
|
|
268
|
-
|
|
269
|
-
|
|
293
|
+
return [
|
|
294
|
+
createOpeningArrayBracket(),
|
|
295
|
+
createProperties(mergedSchemas),
|
|
296
|
+
createClosingArrayBracket(),
|
|
297
|
+
].flat();
|
|
270
298
|
}
|
|
271
299
|
}
|
|
272
300
|
|
|
@@ -274,21 +302,30 @@ function createItems(schema: SchemaObject) {
|
|
|
274
302
|
schema.items?.type === "string" ||
|
|
275
303
|
schema.items?.type === "number" ||
|
|
276
304
|
schema.items?.type === "integer" ||
|
|
277
|
-
schema.items?.type === "boolean"
|
|
305
|
+
schema.items?.type === "boolean" ||
|
|
306
|
+
schema.items?.type === "object"
|
|
278
307
|
) {
|
|
279
|
-
return
|
|
308
|
+
return [
|
|
309
|
+
createOpeningArrayBracket(),
|
|
310
|
+
createNodes(schema.items),
|
|
311
|
+
createClosingArrayBracket(),
|
|
312
|
+
].flat();
|
|
280
313
|
}
|
|
281
314
|
|
|
282
315
|
// TODO: clean this up or eliminate it?
|
|
283
|
-
return
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
:
|
|
290
|
-
|
|
291
|
-
|
|
316
|
+
return [
|
|
317
|
+
createOpeningArrayBracket(),
|
|
318
|
+
Object.entries(schema.items!).map(([key, val]) =>
|
|
319
|
+
createEdges({
|
|
320
|
+
name: key,
|
|
321
|
+
schema: val,
|
|
322
|
+
required: Array.isArray(schema.required)
|
|
323
|
+
? schema.required.includes(key)
|
|
324
|
+
: false,
|
|
325
|
+
})
|
|
326
|
+
),
|
|
327
|
+
createClosingArrayBracket(),
|
|
328
|
+
].flat();
|
|
292
329
|
}
|
|
293
330
|
|
|
294
331
|
/**
|
|
@@ -414,6 +451,15 @@ function createDetailsNode(
|
|
|
414
451
|
style: { opacity: "0.6" },
|
|
415
452
|
children: ` ${schemaName}`,
|
|
416
453
|
}),
|
|
454
|
+
guard(schema.nullable && schema.nullable === true, () => [
|
|
455
|
+
create("strong", {
|
|
456
|
+
style: {
|
|
457
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
458
|
+
color: "var(--openapi-nullable)",
|
|
459
|
+
},
|
|
460
|
+
children: " nullable",
|
|
461
|
+
}),
|
|
462
|
+
]),
|
|
417
463
|
guard(
|
|
418
464
|
Array.isArray(required)
|
|
419
465
|
? required.includes(name)
|
|
@@ -597,11 +643,9 @@ function createEdges({
|
|
|
597
643
|
collapsible: false,
|
|
598
644
|
name,
|
|
599
645
|
required: Array.isArray(required) ? required.includes(name) : required,
|
|
600
|
-
deprecated: mergedSchemas.deprecated,
|
|
601
|
-
schemaDescription: mergedSchemas.description,
|
|
602
646
|
schemaName: schemaName,
|
|
603
647
|
qualifierMessage: getQualifierMessage(schema),
|
|
604
|
-
|
|
648
|
+
schema: mergedSchemas,
|
|
605
649
|
});
|
|
606
650
|
}
|
|
607
651
|
|
|
@@ -631,11 +675,9 @@ function createEdges({
|
|
|
631
675
|
collapsible: false,
|
|
632
676
|
name,
|
|
633
677
|
required: Array.isArray(required) ? required.includes(name) : required,
|
|
634
|
-
deprecated: schema.deprecated,
|
|
635
|
-
schemaDescription: schema.description,
|
|
636
678
|
schemaName: schemaName,
|
|
637
679
|
qualifierMessage: getQualifierMessage(schema),
|
|
638
|
-
|
|
680
|
+
schema: schema,
|
|
639
681
|
});
|
|
640
682
|
}
|
|
641
683
|
|
|
@@ -643,12 +685,13 @@ function createEdges({
|
|
|
643
685
|
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
644
686
|
*/
|
|
645
687
|
function createNodes(schema: SchemaObject): any {
|
|
688
|
+
const nodes = [];
|
|
646
689
|
// if (schema.discriminator !== undefined) {
|
|
647
690
|
// return createDiscriminator(schema);
|
|
648
691
|
// }
|
|
649
692
|
|
|
650
693
|
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
651
|
-
|
|
694
|
+
nodes.push(createAnyOneOf(schema));
|
|
652
695
|
}
|
|
653
696
|
|
|
654
697
|
if (schema.allOf !== undefined) {
|
|
@@ -656,21 +699,25 @@ function createNodes(schema: SchemaObject): any {
|
|
|
656
699
|
|
|
657
700
|
// allOf seems to always result in properties
|
|
658
701
|
if (mergedSchemas.properties !== undefined) {
|
|
659
|
-
|
|
702
|
+
nodes.push(createProperties(mergedSchemas));
|
|
660
703
|
}
|
|
661
704
|
}
|
|
662
705
|
|
|
663
706
|
if (schema.properties !== undefined) {
|
|
664
|
-
|
|
707
|
+
nodes.push(createProperties(schema));
|
|
665
708
|
}
|
|
666
709
|
|
|
667
710
|
if (schema.additionalProperties !== undefined) {
|
|
668
|
-
|
|
711
|
+
nodes.push(createAdditionalProperties(schema));
|
|
669
712
|
}
|
|
670
713
|
|
|
671
714
|
// TODO: figure out how to handle array of objects
|
|
672
715
|
if (schema.items !== undefined) {
|
|
673
|
-
|
|
716
|
+
nodes.push(createItems(schema));
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
if (nodes.length && nodes.length > 0) {
|
|
720
|
+
return nodes.filter(Boolean).flat();
|
|
674
721
|
}
|
|
675
722
|
|
|
676
723
|
// primitive
|
|
@@ -758,12 +805,6 @@ export function createRequestSchema({ title, body, ...rest }: Props) {
|
|
|
758
805
|
style: { textAlign: "left" },
|
|
759
806
|
children: [
|
|
760
807
|
create("strong", { children: `${title}` }),
|
|
761
|
-
guard(firstBody.type === "array", (format) =>
|
|
762
|
-
create("span", {
|
|
763
|
-
style: { opacity: "0.6" },
|
|
764
|
-
children: ` array`,
|
|
765
|
-
})
|
|
766
|
-
),
|
|
767
808
|
guard(body.required && body.required === true, () => [
|
|
768
809
|
create("strong", {
|
|
769
810
|
style: {
|