docusaurus-plugin-openapi-docs 0.0.0-beta.662 → 0.0.0-beta.664
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/createRequestSchema.d.ts +1 -8
- package/lib/markdown/createRequestSchema.js +4 -639
- package/lib/markdown/createResponseSchema.d.ts +1 -8
- package/lib/markdown/createResponseSchema.js +3 -640
- package/lib/markdown/createSchema.d.ts +12 -0
- package/lib/markdown/createSchema.js +646 -0
- package/lib/openapi/createRequestExample.js +3 -3
- package/lib/openapi/createResponseExample.js +3 -3
- package/package.json +2 -2
- package/src/markdown/createRequestSchema.ts +2 -831
- package/src/markdown/createResponseSchema.ts +2 -833
- package/src/markdown/createSchema.ts +848 -0
- package/src/openapi/createRequestExample.ts +1 -1
- package/src/openapi/createResponseExample.ts +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SchemaObject } from "../openapi/types";
|
|
2
|
+
/**
|
|
3
|
+
* Returns a merged representation of allOf array of schemas.
|
|
4
|
+
*/
|
|
5
|
+
export declare function mergeAllOf(allOf: SchemaObject[]): {
|
|
6
|
+
mergedSchemas: any;
|
|
7
|
+
required: any;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createNodes(schema: SchemaObject): any;
|
|
@@ -0,0 +1,646 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
* ========================================================================== */
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createNodes = exports.mergeAllOf = void 0;
|
|
13
|
+
const clsx_1 = __importDefault(require("clsx"));
|
|
14
|
+
const createArrayBracket_1 = require("./createArrayBracket");
|
|
15
|
+
const createDescription_1 = require("./createDescription");
|
|
16
|
+
const createDetails_1 = require("./createDetails");
|
|
17
|
+
const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
18
|
+
const schema_1 = require("./schema");
|
|
19
|
+
const utils_1 = require("./utils");
|
|
20
|
+
const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
|
|
21
|
+
/**
|
|
22
|
+
* Returns a merged representation of allOf array of schemas.
|
|
23
|
+
*/
|
|
24
|
+
function mergeAllOf(allOf) {
|
|
25
|
+
const mergedSchemas = jsonSchemaMergeAllOf(allOf, {
|
|
26
|
+
resolvers: {
|
|
27
|
+
readOnly: function () {
|
|
28
|
+
return true;
|
|
29
|
+
},
|
|
30
|
+
example: function () {
|
|
31
|
+
return true;
|
|
32
|
+
},
|
|
33
|
+
"x-examples": function () {
|
|
34
|
+
return true;
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
ignoreAdditionalProperties: true,
|
|
38
|
+
});
|
|
39
|
+
const required = allOf.reduce((acc, cur) => {
|
|
40
|
+
if (Array.isArray(cur.required)) {
|
|
41
|
+
const next = [...acc, ...cur.required];
|
|
42
|
+
return next;
|
|
43
|
+
}
|
|
44
|
+
return acc;
|
|
45
|
+
}, []);
|
|
46
|
+
return { mergedSchemas, required };
|
|
47
|
+
}
|
|
48
|
+
exports.mergeAllOf = mergeAllOf;
|
|
49
|
+
/**
|
|
50
|
+
* For handling nested anyOf/oneOf.
|
|
51
|
+
*/
|
|
52
|
+
function createAnyOneOf(schema) {
|
|
53
|
+
const type = schema.oneOf ? "oneOf" : "anyOf";
|
|
54
|
+
return (0, utils_1.create)("div", {
|
|
55
|
+
children: [
|
|
56
|
+
(0, utils_1.create)("span", {
|
|
57
|
+
className: "badge badge--info",
|
|
58
|
+
children: type,
|
|
59
|
+
}),
|
|
60
|
+
(0, utils_1.create)("SchemaTabs", {
|
|
61
|
+
children: schema[type].map((anyOneSchema, index) => {
|
|
62
|
+
const label = anyOneSchema.title
|
|
63
|
+
? anyOneSchema.title
|
|
64
|
+
: `MOD${index + 1}`;
|
|
65
|
+
const anyOneChildren = [];
|
|
66
|
+
if (anyOneSchema.properties !== undefined) {
|
|
67
|
+
anyOneChildren.push(createProperties(anyOneSchema));
|
|
68
|
+
delete anyOneSchema.properties;
|
|
69
|
+
}
|
|
70
|
+
if (anyOneSchema.allOf !== undefined) {
|
|
71
|
+
anyOneChildren.push(createNodes(anyOneSchema));
|
|
72
|
+
delete anyOneSchema.allOf;
|
|
73
|
+
}
|
|
74
|
+
if (anyOneSchema.items !== undefined) {
|
|
75
|
+
anyOneChildren.push(createItems(anyOneSchema));
|
|
76
|
+
delete anyOneSchema.items;
|
|
77
|
+
}
|
|
78
|
+
if (anyOneSchema.type === "string" ||
|
|
79
|
+
anyOneSchema.type === "number" ||
|
|
80
|
+
anyOneSchema.type === "integer" ||
|
|
81
|
+
anyOneSchema.type === "boolean") {
|
|
82
|
+
anyOneChildren.push(createNodes(anyOneSchema));
|
|
83
|
+
}
|
|
84
|
+
if (anyOneChildren.length) {
|
|
85
|
+
if (schema.type === "array") {
|
|
86
|
+
return (0, utils_1.create)("TabItem", {
|
|
87
|
+
label: label,
|
|
88
|
+
value: `${index}-item-properties`,
|
|
89
|
+
children: [
|
|
90
|
+
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
91
|
+
anyOneChildren,
|
|
92
|
+
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
93
|
+
]
|
|
94
|
+
.filter(Boolean)
|
|
95
|
+
.flat(),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return (0, utils_1.create)("TabItem", {
|
|
99
|
+
label: label,
|
|
100
|
+
value: `${index}-item-properties`,
|
|
101
|
+
children: anyOneChildren.filter(Boolean).flat(),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return undefined;
|
|
105
|
+
}),
|
|
106
|
+
}),
|
|
107
|
+
],
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* For handling properties.
|
|
112
|
+
*/
|
|
113
|
+
function createProperties(schema) {
|
|
114
|
+
const discriminator = schema.discriminator;
|
|
115
|
+
return Object.entries(schema.properties).map(([key, val]) => {
|
|
116
|
+
return createEdges({
|
|
117
|
+
name: key,
|
|
118
|
+
schema: val,
|
|
119
|
+
required: Array.isArray(schema.required)
|
|
120
|
+
? schema.required.includes(key)
|
|
121
|
+
: false,
|
|
122
|
+
discriminator,
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* For handling additionalProperties.
|
|
128
|
+
*/
|
|
129
|
+
function createAdditionalProperties(schema) {
|
|
130
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
131
|
+
const additionalProperties = schema.additionalProperties;
|
|
132
|
+
const type = additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.type;
|
|
133
|
+
// Handle free-form objects
|
|
134
|
+
if (String(additionalProperties) === "true" && schema.type === "object") {
|
|
135
|
+
return (0, utils_1.create)("SchemaItem", {
|
|
136
|
+
name: "property name*",
|
|
137
|
+
required: false,
|
|
138
|
+
schemaName: "any",
|
|
139
|
+
qualifierMessage: (0, schema_1.getQualifierMessage)(schema.additionalProperties),
|
|
140
|
+
schema: schema,
|
|
141
|
+
collapsible: false,
|
|
142
|
+
discriminator: false,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
if ((type === "object" || type === "array") &&
|
|
146
|
+
((additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.properties) ||
|
|
147
|
+
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.items) ||
|
|
148
|
+
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.allOf) ||
|
|
149
|
+
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.additionalProperties) ||
|
|
150
|
+
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.oneOf) ||
|
|
151
|
+
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.anyOf))) {
|
|
152
|
+
const title = additionalProperties.title;
|
|
153
|
+
const schemaName = (0, schema_1.getSchemaName)(additionalProperties);
|
|
154
|
+
const required = (_a = schema.required) !== null && _a !== void 0 ? _a : false;
|
|
155
|
+
return createDetailsNode("property name*", title !== null && title !== void 0 ? title : schemaName, additionalProperties, required, schema.nullable);
|
|
156
|
+
}
|
|
157
|
+
if (((_b = schema.additionalProperties) === null || _b === void 0 ? void 0 : _b.type) === "string" ||
|
|
158
|
+
((_c = schema.additionalProperties) === null || _c === void 0 ? void 0 : _c.type) === "object" ||
|
|
159
|
+
((_d = schema.additionalProperties) === null || _d === void 0 ? void 0 : _d.type) === "boolean" ||
|
|
160
|
+
((_e = schema.additionalProperties) === null || _e === void 0 ? void 0 : _e.type) === "integer" ||
|
|
161
|
+
((_f = schema.additionalProperties) === null || _f === void 0 ? void 0 : _f.type) === "number") {
|
|
162
|
+
const additionalProperties = (_g = schema.additionalProperties) === null || _g === void 0 ? void 0 : _g.additionalProperties;
|
|
163
|
+
if (additionalProperties !== undefined) {
|
|
164
|
+
const type = (_j = (_h = schema.additionalProperties) === null || _h === void 0 ? void 0 : _h.additionalProperties) === null || _j === void 0 ? void 0 : _j.type;
|
|
165
|
+
const schemaName = (0, schema_1.getSchemaName)((_k = schema.additionalProperties) === null || _k === void 0 ? void 0 : _k.additionalProperties);
|
|
166
|
+
return (0, utils_1.create)("SchemaItem", {
|
|
167
|
+
name: "property name*",
|
|
168
|
+
required: false,
|
|
169
|
+
schemaName: schemaName !== null && schemaName !== void 0 ? schemaName : type,
|
|
170
|
+
qualifierMessage: (_l = schema.additionalProperties) !== null && _l !== void 0 ? _l : (0, schema_1.getQualifierMessage)(schema.additionalProperties),
|
|
171
|
+
schema: schema,
|
|
172
|
+
collapsible: false,
|
|
173
|
+
discriminator: false,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
const schemaName = (0, schema_1.getSchemaName)(schema.additionalProperties);
|
|
177
|
+
return (0, utils_1.create)("SchemaItem", {
|
|
178
|
+
name: "property name*",
|
|
179
|
+
required: false,
|
|
180
|
+
schemaName: schemaName,
|
|
181
|
+
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
182
|
+
schema: schema.additionalProperties,
|
|
183
|
+
collapsible: false,
|
|
184
|
+
discriminator: false,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return Object.entries(schema.additionalProperties).map(([key, val]) => createEdges({
|
|
188
|
+
name: key,
|
|
189
|
+
schema: val,
|
|
190
|
+
required: Array.isArray(schema.required)
|
|
191
|
+
? schema.required.includes(key)
|
|
192
|
+
: false,
|
|
193
|
+
}));
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* For handling items.
|
|
197
|
+
*/
|
|
198
|
+
function createItems(schema) {
|
|
199
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
200
|
+
if (((_a = schema.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
|
|
201
|
+
return [
|
|
202
|
+
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
203
|
+
createProperties(schema.items),
|
|
204
|
+
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
205
|
+
].flat();
|
|
206
|
+
}
|
|
207
|
+
if (((_b = schema.items) === null || _b === void 0 ? void 0 : _b.additionalProperties) !== undefined) {
|
|
208
|
+
return [
|
|
209
|
+
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
210
|
+
createAdditionalProperties(schema.items),
|
|
211
|
+
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
212
|
+
].flat();
|
|
213
|
+
}
|
|
214
|
+
if (((_c = schema.items) === null || _c === void 0 ? void 0 : _c.oneOf) !== undefined || ((_d = schema.items) === null || _d === void 0 ? void 0 : _d.anyOf) !== undefined) {
|
|
215
|
+
return [
|
|
216
|
+
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
217
|
+
createAnyOneOf(schema.items),
|
|
218
|
+
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
219
|
+
].flat();
|
|
220
|
+
}
|
|
221
|
+
if (((_e = schema.items) === null || _e === void 0 ? void 0 : _e.allOf) !== undefined) {
|
|
222
|
+
// TODO: figure out if and how we should pass merged required array
|
|
223
|
+
const { mergedSchemas, } = mergeAllOf((_f = schema.items) === null || _f === void 0 ? void 0 : _f.allOf);
|
|
224
|
+
// Handles combo anyOf/oneOf + properties
|
|
225
|
+
if ((mergedSchemas.oneOf !== undefined ||
|
|
226
|
+
mergedSchemas.anyOf !== undefined) &&
|
|
227
|
+
mergedSchemas.properties) {
|
|
228
|
+
return [
|
|
229
|
+
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
230
|
+
createAnyOneOf(mergedSchemas),
|
|
231
|
+
createProperties(mergedSchemas),
|
|
232
|
+
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
233
|
+
].flat();
|
|
234
|
+
}
|
|
235
|
+
// Handles only anyOf/oneOf
|
|
236
|
+
if (mergedSchemas.oneOf !== undefined ||
|
|
237
|
+
mergedSchemas.anyOf !== undefined) {
|
|
238
|
+
return [
|
|
239
|
+
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
240
|
+
createAnyOneOf(mergedSchemas),
|
|
241
|
+
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
242
|
+
].flat();
|
|
243
|
+
}
|
|
244
|
+
// Handles properties
|
|
245
|
+
if (mergedSchemas.properties !== undefined) {
|
|
246
|
+
return [
|
|
247
|
+
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
248
|
+
createProperties(mergedSchemas),
|
|
249
|
+
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
250
|
+
].flat();
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (((_g = schema.items) === null || _g === void 0 ? void 0 : _g.type) === "string" ||
|
|
254
|
+
((_h = schema.items) === null || _h === void 0 ? void 0 : _h.type) === "number" ||
|
|
255
|
+
((_j = schema.items) === null || _j === void 0 ? void 0 : _j.type) === "integer" ||
|
|
256
|
+
((_k = schema.items) === null || _k === void 0 ? void 0 : _k.type) === "boolean" ||
|
|
257
|
+
((_l = schema.items) === null || _l === void 0 ? void 0 : _l.type) === "object") {
|
|
258
|
+
return [
|
|
259
|
+
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
260
|
+
createNodes(schema.items),
|
|
261
|
+
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
262
|
+
].flat();
|
|
263
|
+
}
|
|
264
|
+
// TODO: clean this up or eliminate it?
|
|
265
|
+
return [
|
|
266
|
+
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
267
|
+
Object.entries(schema.items).map(([key, val]) => createEdges({
|
|
268
|
+
name: key,
|
|
269
|
+
schema: val,
|
|
270
|
+
required: Array.isArray(schema.required)
|
|
271
|
+
? schema.required.includes(key)
|
|
272
|
+
: false,
|
|
273
|
+
})),
|
|
274
|
+
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
275
|
+
].flat();
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* For handling nested properties.
|
|
279
|
+
*/
|
|
280
|
+
function createDetailsNode(name, schemaName, schema, required, nullable) {
|
|
281
|
+
return (0, utils_1.create)("SchemaItem", {
|
|
282
|
+
collapsible: true,
|
|
283
|
+
className: "schemaItem",
|
|
284
|
+
children: [
|
|
285
|
+
(0, createDetails_1.createDetails)({
|
|
286
|
+
className: "openapi-markdown__details",
|
|
287
|
+
children: [
|
|
288
|
+
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
289
|
+
children: [
|
|
290
|
+
(0, utils_1.create)("span", {
|
|
291
|
+
className: "openapi-schema__container",
|
|
292
|
+
children: [
|
|
293
|
+
(0, utils_1.create)("strong", {
|
|
294
|
+
className: (0, clsx_1.default)("openapi-schema__property", {
|
|
295
|
+
"openapi-schema__strikethrough": schema.deprecated,
|
|
296
|
+
}),
|
|
297
|
+
children: name,
|
|
298
|
+
}),
|
|
299
|
+
(0, utils_1.create)("span", {
|
|
300
|
+
className: "openapi-schema__name",
|
|
301
|
+
children: ` ${schemaName}`,
|
|
302
|
+
}),
|
|
303
|
+
(0, utils_1.guard)((Array.isArray(required)
|
|
304
|
+
? required.includes(name)
|
|
305
|
+
: required === true) ||
|
|
306
|
+
schema.deprecated ||
|
|
307
|
+
nullable, () => [
|
|
308
|
+
(0, utils_1.create)("span", {
|
|
309
|
+
className: "openapi-schema__divider",
|
|
310
|
+
}),
|
|
311
|
+
]),
|
|
312
|
+
(0, utils_1.guard)(nullable, () => [
|
|
313
|
+
(0, utils_1.create)("span", {
|
|
314
|
+
className: "openapi-schema__nullable",
|
|
315
|
+
children: "nullable",
|
|
316
|
+
}),
|
|
317
|
+
]),
|
|
318
|
+
(0, utils_1.guard)(Array.isArray(required)
|
|
319
|
+
? required.includes(name)
|
|
320
|
+
: required === true, () => [
|
|
321
|
+
(0, utils_1.create)("span", {
|
|
322
|
+
className: "openapi-schema__required",
|
|
323
|
+
children: "required",
|
|
324
|
+
}),
|
|
325
|
+
]),
|
|
326
|
+
(0, utils_1.guard)(schema.deprecated, () => [
|
|
327
|
+
(0, utils_1.create)("span", {
|
|
328
|
+
className: "openapi-schema__deprecated",
|
|
329
|
+
children: "deprecated",
|
|
330
|
+
}),
|
|
331
|
+
]),
|
|
332
|
+
],
|
|
333
|
+
}),
|
|
334
|
+
],
|
|
335
|
+
}),
|
|
336
|
+
(0, utils_1.create)("div", {
|
|
337
|
+
style: { marginLeft: "1rem" },
|
|
338
|
+
children: [
|
|
339
|
+
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
|
|
340
|
+
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
341
|
+
children: (0, createDescription_1.createDescription)(message),
|
|
342
|
+
})),
|
|
343
|
+
(0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
|
|
344
|
+
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
345
|
+
children: (0, createDescription_1.createDescription)(description),
|
|
346
|
+
})),
|
|
347
|
+
createNodes(schema),
|
|
348
|
+
],
|
|
349
|
+
}),
|
|
350
|
+
],
|
|
351
|
+
}),
|
|
352
|
+
],
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* For handling anyOf/oneOf properties.
|
|
357
|
+
*/
|
|
358
|
+
function createAnyOneOfProperty(name, schemaName, schema, required, nullable) {
|
|
359
|
+
const type = schema.oneOf ? "oneOf" : "anyOf";
|
|
360
|
+
const children = schema[type] || [];
|
|
361
|
+
return (0, utils_1.create)("SchemaItem", {
|
|
362
|
+
collapsible: true,
|
|
363
|
+
className: "schemaItem",
|
|
364
|
+
children: [
|
|
365
|
+
(0, createDetails_1.createDetails)({
|
|
366
|
+
children: [
|
|
367
|
+
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
368
|
+
children: [
|
|
369
|
+
(0, utils_1.create)("strong", { children: name }),
|
|
370
|
+
(0, utils_1.create)("span", {
|
|
371
|
+
style: { opacity: "0.6" },
|
|
372
|
+
children: ` ${schemaName}`,
|
|
373
|
+
}),
|
|
374
|
+
(0, utils_1.guard)((schema.nullable && schema.nullable === true) ||
|
|
375
|
+
(nullable && nullable === true), () => [
|
|
376
|
+
(0, utils_1.create)("strong", {
|
|
377
|
+
style: {
|
|
378
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
379
|
+
color: "var(--openapi-nullable)",
|
|
380
|
+
},
|
|
381
|
+
children: " nullable",
|
|
382
|
+
}),
|
|
383
|
+
]),
|
|
384
|
+
(0, utils_1.guard)(Array.isArray(required)
|
|
385
|
+
? required.includes(name)
|
|
386
|
+
: required === true, () => [
|
|
387
|
+
(0, utils_1.create)("strong", {
|
|
388
|
+
style: {
|
|
389
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
390
|
+
color: "var(--openapi-required)",
|
|
391
|
+
},
|
|
392
|
+
children: " required",
|
|
393
|
+
}),
|
|
394
|
+
]),
|
|
395
|
+
],
|
|
396
|
+
}),
|
|
397
|
+
(0, utils_1.create)("div", {
|
|
398
|
+
style: { marginLeft: "1rem" },
|
|
399
|
+
children: [
|
|
400
|
+
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
|
|
401
|
+
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
402
|
+
children: (0, createDescription_1.createDescription)(message),
|
|
403
|
+
})),
|
|
404
|
+
(0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
|
|
405
|
+
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
406
|
+
children: (0, createDescription_1.createDescription)(description),
|
|
407
|
+
})),
|
|
408
|
+
],
|
|
409
|
+
}),
|
|
410
|
+
(0, utils_1.create)("div", {
|
|
411
|
+
children: [
|
|
412
|
+
(0, utils_1.create)("span", {
|
|
413
|
+
className: "badge badge--info",
|
|
414
|
+
children: type,
|
|
415
|
+
}),
|
|
416
|
+
(0, utils_1.create)("SchemaTabs", {
|
|
417
|
+
children: children.map((property, index) => {
|
|
418
|
+
var _a;
|
|
419
|
+
const label = (_a = property.title) !== null && _a !== void 0 ? _a : `MOD${index + 1}`;
|
|
420
|
+
if (property.properties) {
|
|
421
|
+
return (0, utils_1.create)("TabItem", {
|
|
422
|
+
label: label,
|
|
423
|
+
value: `${index}-property`,
|
|
424
|
+
children: [createNodes(property)],
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
return (0, utils_1.create)("TabItem", {
|
|
428
|
+
label: label,
|
|
429
|
+
value: `${index}-property`,
|
|
430
|
+
children: [
|
|
431
|
+
(0, utils_1.create)("p", { children: label }),
|
|
432
|
+
(0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
|
|
433
|
+
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
434
|
+
children: (0, createDescription_1.createDescription)(description),
|
|
435
|
+
})),
|
|
436
|
+
],
|
|
437
|
+
});
|
|
438
|
+
}),
|
|
439
|
+
}),
|
|
440
|
+
],
|
|
441
|
+
}),
|
|
442
|
+
],
|
|
443
|
+
}),
|
|
444
|
+
],
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* For handling discriminators that map to a same-level property (like 'petType').
|
|
449
|
+
* Note: These should only be encountered while iterating through properties.
|
|
450
|
+
*/
|
|
451
|
+
function createPropertyDiscriminator(name, schemaName, schema, discriminator, required) {
|
|
452
|
+
if (schema === undefined) {
|
|
453
|
+
return undefined;
|
|
454
|
+
}
|
|
455
|
+
if (discriminator.mapping === undefined) {
|
|
456
|
+
return undefined;
|
|
457
|
+
}
|
|
458
|
+
return (0, utils_1.create)("div", {
|
|
459
|
+
className: "openapi-discriminator__item openapi-schema__list-item",
|
|
460
|
+
children: (0, utils_1.create)("div", {
|
|
461
|
+
children: [
|
|
462
|
+
(0, utils_1.create)("span", {
|
|
463
|
+
className: "openapi-schema__container",
|
|
464
|
+
children: [
|
|
465
|
+
(0, utils_1.create)("strong", {
|
|
466
|
+
className: "openapi-discriminator__name openapi-schema__property",
|
|
467
|
+
children: name,
|
|
468
|
+
}),
|
|
469
|
+
(0, utils_1.guard)(schemaName, (name) => (0, utils_1.create)("span", {
|
|
470
|
+
className: "openapi-schema__name",
|
|
471
|
+
children: ` ${schemaName}`,
|
|
472
|
+
})),
|
|
473
|
+
(0, utils_1.guard)(required, () => [
|
|
474
|
+
(0, utils_1.create)("span", {
|
|
475
|
+
className: "openapi-schema__required",
|
|
476
|
+
children: "required",
|
|
477
|
+
}),
|
|
478
|
+
]),
|
|
479
|
+
],
|
|
480
|
+
}),
|
|
481
|
+
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(discriminator), (message) => (0, utils_1.create)("div", {
|
|
482
|
+
style: {
|
|
483
|
+
paddingLeft: "1rem",
|
|
484
|
+
},
|
|
485
|
+
children: (0, createDescription_1.createDescription)(message),
|
|
486
|
+
})),
|
|
487
|
+
(0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
|
|
488
|
+
style: {
|
|
489
|
+
paddingLeft: "1rem",
|
|
490
|
+
},
|
|
491
|
+
children: (0, createDescription_1.createDescription)(description),
|
|
492
|
+
})),
|
|
493
|
+
(0, utils_1.create)("DiscriminatorTabs", {
|
|
494
|
+
className: "openapi-tabs__discriminator",
|
|
495
|
+
children: Object.keys(discriminator === null || discriminator === void 0 ? void 0 : discriminator.mapping).map((key, index) => {
|
|
496
|
+
const label = key;
|
|
497
|
+
return (0, utils_1.create)("TabItem", {
|
|
498
|
+
// className: "openapi-tabs__discriminator-item",
|
|
499
|
+
label: label,
|
|
500
|
+
value: `${index}-item-discriminator`,
|
|
501
|
+
children: [createNodes(discriminator === null || discriminator === void 0 ? void 0 : discriminator.mapping[key])],
|
|
502
|
+
});
|
|
503
|
+
}),
|
|
504
|
+
}),
|
|
505
|
+
],
|
|
506
|
+
}),
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Creates the edges or "leaves" of a schema tree. Edges can branch into sub-nodes with createDetails().
|
|
511
|
+
*/
|
|
512
|
+
function createEdges({ name, schema, required, discriminator, }) {
|
|
513
|
+
var _a, _b, _c, _d;
|
|
514
|
+
const schemaName = (0, schema_1.getSchemaName)(schema);
|
|
515
|
+
if (discriminator !== undefined && discriminator.propertyName === name) {
|
|
516
|
+
return createPropertyDiscriminator(name, "string", schema, discriminator, required);
|
|
517
|
+
}
|
|
518
|
+
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
519
|
+
return createAnyOneOfProperty(name, schemaName, schema, required, schema.nullable);
|
|
520
|
+
}
|
|
521
|
+
if (schema.allOf !== undefined) {
|
|
522
|
+
const { mergedSchemas, required, } = mergeAllOf(schema.allOf);
|
|
523
|
+
const mergedSchemaName = (0, schema_1.getSchemaName)(mergedSchemas);
|
|
524
|
+
if (mergedSchemas.oneOf !== undefined ||
|
|
525
|
+
mergedSchemas.anyOf !== undefined) {
|
|
526
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
527
|
+
}
|
|
528
|
+
if (mergedSchemas.properties !== undefined) {
|
|
529
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
530
|
+
}
|
|
531
|
+
if (mergedSchemas.additionalProperties !== undefined) {
|
|
532
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
533
|
+
}
|
|
534
|
+
// array of objects
|
|
535
|
+
if (((_a = mergedSchemas.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
|
|
536
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
537
|
+
}
|
|
538
|
+
if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
|
|
539
|
+
return undefined;
|
|
540
|
+
}
|
|
541
|
+
return (0, utils_1.create)("SchemaItem", {
|
|
542
|
+
collapsible: false,
|
|
543
|
+
name,
|
|
544
|
+
required: Array.isArray(required) ? required.includes(name) : required,
|
|
545
|
+
schemaName: schemaName,
|
|
546
|
+
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
547
|
+
schema: mergedSchemas,
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
if (schema.properties !== undefined) {
|
|
551
|
+
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
552
|
+
}
|
|
553
|
+
if (schema.additionalProperties !== undefined) {
|
|
554
|
+
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
555
|
+
}
|
|
556
|
+
// array of objects
|
|
557
|
+
if (((_b = schema.items) === null || _b === void 0 ? void 0 : _b.properties) !== undefined) {
|
|
558
|
+
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
559
|
+
}
|
|
560
|
+
if (((_c = schema.items) === null || _c === void 0 ? void 0 : _c.anyOf) !== undefined || ((_d = schema.items) === null || _d === void 0 ? void 0 : _d.oneOf) !== undefined) {
|
|
561
|
+
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
562
|
+
}
|
|
563
|
+
if (schema.readOnly && schema.readOnly === true) {
|
|
564
|
+
return undefined;
|
|
565
|
+
}
|
|
566
|
+
// primitives and array of non-objects
|
|
567
|
+
return (0, utils_1.create)("SchemaItem", {
|
|
568
|
+
collapsible: false,
|
|
569
|
+
name,
|
|
570
|
+
required: Array.isArray(required) ? required.includes(name) : required,
|
|
571
|
+
schemaName: schemaName,
|
|
572
|
+
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
573
|
+
schema: schema,
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
578
|
+
*/
|
|
579
|
+
function createNodes(schema) {
|
|
580
|
+
const nodes = [];
|
|
581
|
+
// if (schema.discriminator !== undefined) {
|
|
582
|
+
// return createDiscriminator(schema);
|
|
583
|
+
// }
|
|
584
|
+
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
585
|
+
nodes.push(createAnyOneOf(schema));
|
|
586
|
+
}
|
|
587
|
+
if (schema.allOf !== undefined) {
|
|
588
|
+
const { mergedSchemas } = mergeAllOf(schema.allOf);
|
|
589
|
+
// allOf seems to always result in properties
|
|
590
|
+
if (mergedSchemas.properties !== undefined) {
|
|
591
|
+
nodes.push(createProperties(mergedSchemas));
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
if (schema.properties !== undefined) {
|
|
595
|
+
nodes.push(createProperties(schema));
|
|
596
|
+
}
|
|
597
|
+
if (schema.additionalProperties !== undefined) {
|
|
598
|
+
nodes.push(createAdditionalProperties(schema));
|
|
599
|
+
}
|
|
600
|
+
// TODO: figure out how to handle array of objects
|
|
601
|
+
if (schema.items !== undefined) {
|
|
602
|
+
nodes.push(createItems(schema));
|
|
603
|
+
}
|
|
604
|
+
if (nodes.length && nodes.length > 0) {
|
|
605
|
+
return nodes.filter(Boolean).flat();
|
|
606
|
+
}
|
|
607
|
+
// primitive
|
|
608
|
+
if (schema.type !== undefined) {
|
|
609
|
+
if (schema.allOf) {
|
|
610
|
+
//handle circular result in allOf
|
|
611
|
+
if (schema.allOf.length && typeof schema.allOf[0] === "string") {
|
|
612
|
+
return (0, utils_1.create)("div", {
|
|
613
|
+
style: {
|
|
614
|
+
marginTop: ".5rem",
|
|
615
|
+
marginBottom: ".5rem",
|
|
616
|
+
marginLeft: "1rem",
|
|
617
|
+
},
|
|
618
|
+
children: (0, createDescription_1.createDescription)(schema.allOf[0]),
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
return (0, utils_1.create)("div", {
|
|
623
|
+
style: {
|
|
624
|
+
marginTop: ".5rem",
|
|
625
|
+
marginBottom: ".5rem",
|
|
626
|
+
marginLeft: "1rem",
|
|
627
|
+
},
|
|
628
|
+
children: (0, createDescription_1.createDescription)(schema.type),
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
// handle circular references
|
|
632
|
+
if (typeof schema === "string") {
|
|
633
|
+
return (0, utils_1.create)("div", {
|
|
634
|
+
style: {
|
|
635
|
+
marginTop: ".5rem",
|
|
636
|
+
marginBottom: ".5rem",
|
|
637
|
+
marginLeft: "1rem",
|
|
638
|
+
},
|
|
639
|
+
children: [(0, createDescription_1.createDescription)(schema)],
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
// Unknown node/schema type should return undefined
|
|
643
|
+
// So far, haven't seen this hit in testing
|
|
644
|
+
return "any";
|
|
645
|
+
}
|
|
646
|
+
exports.createNodes = createNodes;
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.sampleRequestFromSchema = void 0;
|
|
13
13
|
const chalk_1 = __importDefault(require("chalk"));
|
|
14
14
|
const merge_1 = __importDefault(require("lodash/merge"));
|
|
15
|
-
const
|
|
15
|
+
const createSchema_1 = require("../markdown/createSchema");
|
|
16
16
|
const primitives = {
|
|
17
17
|
string: {
|
|
18
18
|
default: () => "string",
|
|
@@ -51,7 +51,7 @@ function sampleRequestFromProp(name, prop, obj) {
|
|
|
51
51
|
obj[name] = (0, exports.sampleRequestFromSchema)(prop.anyOf[0]);
|
|
52
52
|
}
|
|
53
53
|
else if (prop.allOf) {
|
|
54
|
-
const { mergedSchemas } = (0,
|
|
54
|
+
const { mergedSchemas } = (0, createSchema_1.mergeAllOf)(prop.allOf);
|
|
55
55
|
sampleRequestFromProp(name, mergedSchemas, obj);
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
@@ -86,7 +86,7 @@ const sampleRequestFromSchema = (schema = {}) => {
|
|
|
86
86
|
return (0, exports.sampleRequestFromSchema)(anyOf[0]);
|
|
87
87
|
}
|
|
88
88
|
if (allOf) {
|
|
89
|
-
const { mergedSchemas } = (0,
|
|
89
|
+
const { mergedSchemas } = (0, createSchema_1.mergeAllOf)(allOf);
|
|
90
90
|
if (mergedSchemas.properties) {
|
|
91
91
|
for (const [key, value] of Object.entries(mergedSchemas.properties)) {
|
|
92
92
|
if ((value.readOnly && value.readOnly === true) || value.deprecated) {
|