docusaurus-plugin-openapi-docs 0.0.0-beta.662 → 0.0.0-beta.663
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 +594 -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 +793 -0
- package/src/openapi/createRequestExample.ts +1 -1
- package/src/openapi/createResponseExample.ts +1 -1
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import { MediaTypeObject
|
|
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
|
-
};
|
|
1
|
+
import { MediaTypeObject } from "../openapi/types";
|
|
9
2
|
interface Props {
|
|
10
3
|
style?: any;
|
|
11
4
|
title: string;
|
|
@@ -5,648 +5,13 @@
|
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
* ========================================================================== */
|
|
8
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.createRequestSchema =
|
|
13
|
-
const clsx_1 = __importDefault(require("clsx"));
|
|
14
|
-
const createArrayBracket_1 = require("./createArrayBracket");
|
|
9
|
+
exports.createRequestSchema = void 0;
|
|
15
10
|
const createDescription_1 = require("./createDescription");
|
|
16
11
|
const createDetails_1 = require("./createDetails");
|
|
17
12
|
const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
18
|
-
const
|
|
13
|
+
const createSchema_1 = require("./createSchema");
|
|
19
14
|
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
|
-
function createProperties(schema) {
|
|
111
|
-
const discriminator = schema.discriminator;
|
|
112
|
-
return Object.entries(schema.properties).map(([key, val]) => {
|
|
113
|
-
return createEdges({
|
|
114
|
-
name: key,
|
|
115
|
-
schema: val,
|
|
116
|
-
required: Array.isArray(schema.required)
|
|
117
|
-
? schema.required.includes(key)
|
|
118
|
-
: false,
|
|
119
|
-
discriminator,
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
function createAdditionalProperties(schema) {
|
|
124
|
-
// TODO?:
|
|
125
|
-
// {
|
|
126
|
-
// description: 'Integration configuration. See \n' +
|
|
127
|
-
// '[Integration Configurations](https://prisma.pan.dev/api/cloud/api-integration-config/).\n',
|
|
128
|
-
// example: { webhookUrl: 'https://hooks.slack.com/abcdef' },
|
|
129
|
-
// externalDocs: { url: 'https://prisma.pan.dev/api/cloud/api-integration-config' },
|
|
130
|
-
// type: 'object'
|
|
131
|
-
// }
|
|
132
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
133
|
-
// TODO?:
|
|
134
|
-
// {
|
|
135
|
-
// items: {
|
|
136
|
-
// properties: {
|
|
137
|
-
// aliasField: [Object],
|
|
138
|
-
// displayName: [Object],
|
|
139
|
-
// fieldName: [Object],
|
|
140
|
-
// maxLength: [Object],
|
|
141
|
-
// options: [Object],
|
|
142
|
-
// redlockMapping: [Object],
|
|
143
|
-
// required: [Object],
|
|
144
|
-
// type: [Object],
|
|
145
|
-
// typeaheadUri: [Object],
|
|
146
|
-
// value: [Object]
|
|
147
|
-
// },
|
|
148
|
-
// type: 'object'
|
|
149
|
-
// },
|
|
150
|
-
// type: 'array'
|
|
151
|
-
// }
|
|
152
|
-
const additionalProperties = schema.additionalProperties;
|
|
153
|
-
const type = additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.type;
|
|
154
|
-
// Handle free-form objects
|
|
155
|
-
if (String(additionalProperties) === "true" && schema.type === "object") {
|
|
156
|
-
return (0, utils_1.create)("SchemaItem", {
|
|
157
|
-
name: "property name*",
|
|
158
|
-
required: false,
|
|
159
|
-
schemaName: "any",
|
|
160
|
-
qualifierMessage: (0, schema_1.getQualifierMessage)(schema.additionalProperties),
|
|
161
|
-
schema: schema,
|
|
162
|
-
collapsible: false,
|
|
163
|
-
discriminator: false,
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
if ((type === "object" || type === "array") &&
|
|
167
|
-
((additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.properties) ||
|
|
168
|
-
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.items) ||
|
|
169
|
-
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.allOf) ||
|
|
170
|
-
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.additionalProperties) ||
|
|
171
|
-
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.oneOf) ||
|
|
172
|
-
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.anyOf))) {
|
|
173
|
-
const title = additionalProperties.title;
|
|
174
|
-
const schemaName = (0, schema_1.getSchemaName)(additionalProperties);
|
|
175
|
-
const required = (_a = schema.required) !== null && _a !== void 0 ? _a : false;
|
|
176
|
-
return createDetailsNode("property name*", title !== null && title !== void 0 ? title : schemaName, additionalProperties, required, schema.nullable);
|
|
177
|
-
}
|
|
178
|
-
if (((_b = schema.additionalProperties) === null || _b === void 0 ? void 0 : _b.type) === "string" ||
|
|
179
|
-
((_c = schema.additionalProperties) === null || _c === void 0 ? void 0 : _c.type) === "object" ||
|
|
180
|
-
((_d = schema.additionalProperties) === null || _d === void 0 ? void 0 : _d.type) === "boolean" ||
|
|
181
|
-
((_e = schema.additionalProperties) === null || _e === void 0 ? void 0 : _e.type) === "integer" ||
|
|
182
|
-
((_f = schema.additionalProperties) === null || _f === void 0 ? void 0 : _f.type) === "number") {
|
|
183
|
-
const additionalProperties = (_g = schema.additionalProperties) === null || _g === void 0 ? void 0 : _g.additionalProperties;
|
|
184
|
-
if (additionalProperties !== undefined) {
|
|
185
|
-
const type = (_j = (_h = schema.additionalProperties) === null || _h === void 0 ? void 0 : _h.additionalProperties) === null || _j === void 0 ? void 0 : _j.type;
|
|
186
|
-
const schemaName = (0, schema_1.getSchemaName)((_k = schema.additionalProperties) === null || _k === void 0 ? void 0 : _k.additionalProperties);
|
|
187
|
-
return (0, utils_1.create)("SchemaItem", {
|
|
188
|
-
name: "property name*",
|
|
189
|
-
required: false,
|
|
190
|
-
schemaName: schemaName !== null && schemaName !== void 0 ? schemaName : type,
|
|
191
|
-
qualifierMessage: (_l = schema.additionalProperties) !== null && _l !== void 0 ? _l : (0, schema_1.getQualifierMessage)(schema.additionalProperties),
|
|
192
|
-
schema: schema,
|
|
193
|
-
collapsible: false,
|
|
194
|
-
discriminator: false,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
const schemaName = (0, schema_1.getSchemaName)(schema.additionalProperties);
|
|
198
|
-
return (0, utils_1.create)("SchemaItem", {
|
|
199
|
-
name: "property name*",
|
|
200
|
-
required: false,
|
|
201
|
-
schemaName: schemaName,
|
|
202
|
-
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
203
|
-
schema: schema.additionalProperties,
|
|
204
|
-
collapsible: false,
|
|
205
|
-
discriminator: false,
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
return Object.entries(schema.additionalProperties).map(([key, val]) => createEdges({
|
|
209
|
-
name: key,
|
|
210
|
-
schema: val,
|
|
211
|
-
required: Array.isArray(schema.required)
|
|
212
|
-
? schema.required.includes(key)
|
|
213
|
-
: false,
|
|
214
|
-
}));
|
|
215
|
-
}
|
|
216
|
-
// TODO: figure out how to handle array of objects
|
|
217
|
-
function createItems(schema) {
|
|
218
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
219
|
-
if (((_a = schema.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
|
|
220
|
-
return [
|
|
221
|
-
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
222
|
-
createProperties(schema.items),
|
|
223
|
-
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
224
|
-
].flat();
|
|
225
|
-
}
|
|
226
|
-
if (((_b = schema.items) === null || _b === void 0 ? void 0 : _b.additionalProperties) !== undefined) {
|
|
227
|
-
return [
|
|
228
|
-
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
229
|
-
createAdditionalProperties(schema.items),
|
|
230
|
-
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
231
|
-
].flat();
|
|
232
|
-
}
|
|
233
|
-
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) {
|
|
234
|
-
return [
|
|
235
|
-
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
236
|
-
createAnyOneOf(schema.items),
|
|
237
|
-
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
238
|
-
].flat();
|
|
239
|
-
}
|
|
240
|
-
if (((_e = schema.items) === null || _e === void 0 ? void 0 : _e.allOf) !== undefined) {
|
|
241
|
-
// TODO: figure out if and how we should pass merged required array
|
|
242
|
-
const { mergedSchemas, } = mergeAllOf((_f = schema.items) === null || _f === void 0 ? void 0 : _f.allOf);
|
|
243
|
-
// Handles combo anyOf/oneOf + properties
|
|
244
|
-
if ((mergedSchemas.oneOf !== undefined ||
|
|
245
|
-
mergedSchemas.anyOf !== undefined) &&
|
|
246
|
-
mergedSchemas.properties) {
|
|
247
|
-
return [
|
|
248
|
-
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
249
|
-
createAnyOneOf(mergedSchemas),
|
|
250
|
-
createProperties(mergedSchemas),
|
|
251
|
-
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
252
|
-
].flat();
|
|
253
|
-
}
|
|
254
|
-
// Handles only anyOf/oneOf
|
|
255
|
-
if (mergedSchemas.oneOf !== undefined ||
|
|
256
|
-
mergedSchemas.anyOf !== undefined) {
|
|
257
|
-
return [
|
|
258
|
-
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
259
|
-
createAnyOneOf(mergedSchemas),
|
|
260
|
-
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
261
|
-
].flat();
|
|
262
|
-
}
|
|
263
|
-
// Handles properties
|
|
264
|
-
if (mergedSchemas.properties !== undefined) {
|
|
265
|
-
return [
|
|
266
|
-
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
267
|
-
createProperties(mergedSchemas),
|
|
268
|
-
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
269
|
-
].flat();
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
if (((_g = schema.items) === null || _g === void 0 ? void 0 : _g.type) === "string" ||
|
|
273
|
-
((_h = schema.items) === null || _h === void 0 ? void 0 : _h.type) === "number" ||
|
|
274
|
-
((_j = schema.items) === null || _j === void 0 ? void 0 : _j.type) === "integer" ||
|
|
275
|
-
((_k = schema.items) === null || _k === void 0 ? void 0 : _k.type) === "boolean" ||
|
|
276
|
-
((_l = schema.items) === null || _l === void 0 ? void 0 : _l.type) === "object") {
|
|
277
|
-
return [
|
|
278
|
-
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
279
|
-
createNodes(schema.items),
|
|
280
|
-
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
281
|
-
].flat();
|
|
282
|
-
}
|
|
283
|
-
// TODO: clean this up or eliminate it?
|
|
284
|
-
return [
|
|
285
|
-
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
286
|
-
Object.entries(schema.items).map(([key, val]) => createEdges({
|
|
287
|
-
name: key,
|
|
288
|
-
schema: val,
|
|
289
|
-
required: Array.isArray(schema.required)
|
|
290
|
-
? schema.required.includes(key)
|
|
291
|
-
: false,
|
|
292
|
-
})),
|
|
293
|
-
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
294
|
-
].flat();
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* For handling discriminators that do not map to a same-level property
|
|
298
|
-
*/
|
|
299
|
-
// function createDiscriminator(schema: SchemaObject) {
|
|
300
|
-
// const discriminator = schema.discriminator;
|
|
301
|
-
// const propertyName = discriminator?.propertyName;
|
|
302
|
-
// const propertyType = "string"; // should always be string
|
|
303
|
-
// const mapping: any = discriminator?.mapping;
|
|
304
|
-
// // Explicit mapping is required since we can't support implicit
|
|
305
|
-
// if (mapping === undefined) {
|
|
306
|
-
// return undefined;
|
|
307
|
-
// }
|
|
308
|
-
// // Attempt to get the property description we want to display
|
|
309
|
-
// // TODO: how to make it predictable when handling allOf
|
|
310
|
-
// let propertyDescription;
|
|
311
|
-
// const firstMappingSchema = mapping[Object.keys(mapping)[0]];
|
|
312
|
-
// if (firstMappingSchema.properties !== undefined) {
|
|
313
|
-
// propertyDescription =
|
|
314
|
-
// firstMappingSchema.properties![propertyName!].description;
|
|
315
|
-
// }
|
|
316
|
-
// if (firstMappingSchema.allOf !== undefined) {
|
|
317
|
-
// const { mergedSchemas }: { mergedSchemas: SchemaObject } = mergeAllOf(
|
|
318
|
-
// firstMappingSchema.allOf
|
|
319
|
-
// );
|
|
320
|
-
// if (mergedSchemas.properties !== undefined) {
|
|
321
|
-
// propertyDescription =
|
|
322
|
-
// mergedSchemas.properties[propertyName!]?.description;
|
|
323
|
-
// }
|
|
324
|
-
// }
|
|
325
|
-
// if (propertyDescription === undefined) {
|
|
326
|
-
// if (
|
|
327
|
-
// schema.properties !== undefined &&
|
|
328
|
-
// schema.properties![propertyName!] !== undefined
|
|
329
|
-
// ) {
|
|
330
|
-
// propertyDescription = schema.properties![propertyName!].description;
|
|
331
|
-
// }
|
|
332
|
-
// }
|
|
333
|
-
// return create("div", {
|
|
334
|
-
// className: "openapi-discriminator__item",
|
|
335
|
-
// children: create("div", {
|
|
336
|
-
// children: [
|
|
337
|
-
// create("strong", {
|
|
338
|
-
// style: { paddingLeft: "1rem" },
|
|
339
|
-
// children: propertyName,
|
|
340
|
-
// }),
|
|
341
|
-
// guard(propertyType, (name) =>
|
|
342
|
-
// create("span", {
|
|
343
|
-
// style: { opacity: "0.6" },
|
|
344
|
-
// children: ` ${propertyType}`,
|
|
345
|
-
// })
|
|
346
|
-
// ),
|
|
347
|
-
// guard(getQualifierMessage(schema.discriminator as any), (message) =>
|
|
348
|
-
// create("div", {
|
|
349
|
-
// style: {
|
|
350
|
-
// paddingLeft: "1rem",
|
|
351
|
-
// },
|
|
352
|
-
// children: createDescription(message),
|
|
353
|
-
// })
|
|
354
|
-
// ),
|
|
355
|
-
// guard(propertyDescription, (description) =>
|
|
356
|
-
// create("div", {
|
|
357
|
-
// style: {
|
|
358
|
-
// paddingLeft: "1rem",
|
|
359
|
-
// },
|
|
360
|
-
// children: createDescription(description),
|
|
361
|
-
// })
|
|
362
|
-
// ),
|
|
363
|
-
// create("DiscriminatorTabs", {
|
|
364
|
-
// children: Object.keys(mapping!).map((key, index) => {
|
|
365
|
-
// if (mapping[key].allOf !== undefined) {
|
|
366
|
-
// const { mergedSchemas }: { mergedSchemas: SchemaObject } =
|
|
367
|
-
// mergeAllOf(mapping[key].allOf);
|
|
368
|
-
// // Cleanup duplicate property from mapping schema
|
|
369
|
-
// delete mergedSchemas.properties![propertyName!];
|
|
370
|
-
// mapping[key] = mergedSchemas;
|
|
371
|
-
// }
|
|
372
|
-
// if (mapping[key].properties !== undefined) {
|
|
373
|
-
// // Cleanup duplicate property from mapping schema
|
|
374
|
-
// delete mapping[key].properties![propertyName!];
|
|
375
|
-
// }
|
|
376
|
-
// const label = key;
|
|
377
|
-
// return create("TabItem", {
|
|
378
|
-
// label: label,
|
|
379
|
-
// value: `${index}-item-discriminator`,
|
|
380
|
-
// children: [
|
|
381
|
-
// create("div", {
|
|
382
|
-
// style: { marginLeft: "-4px" },
|
|
383
|
-
// children: createNodes(mapping[key]),
|
|
384
|
-
// }),
|
|
385
|
-
// ],
|
|
386
|
-
// });
|
|
387
|
-
// }),
|
|
388
|
-
// }),
|
|
389
|
-
// ],
|
|
390
|
-
// }),
|
|
391
|
-
// });
|
|
392
|
-
// }
|
|
393
|
-
function createDetailsNode(name, schemaName, schema, required, nullable) {
|
|
394
|
-
return (0, utils_1.create)("SchemaItem", {
|
|
395
|
-
collapsible: true,
|
|
396
|
-
className: "schemaItem",
|
|
397
|
-
children: [
|
|
398
|
-
(0, createDetails_1.createDetails)({
|
|
399
|
-
className: "openapi-markdown__details",
|
|
400
|
-
children: [
|
|
401
|
-
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
402
|
-
children: [
|
|
403
|
-
(0, utils_1.create)("span", {
|
|
404
|
-
className: "openapi-schema__container",
|
|
405
|
-
children: [
|
|
406
|
-
(0, utils_1.create)("strong", {
|
|
407
|
-
className: (0, clsx_1.default)("openapi-schema__property", {
|
|
408
|
-
"openapi-schema__strikethrough": schema.deprecated,
|
|
409
|
-
}),
|
|
410
|
-
children: name,
|
|
411
|
-
}),
|
|
412
|
-
(0, utils_1.create)("span", {
|
|
413
|
-
className: "openapi-schema__name",
|
|
414
|
-
children: ` ${schemaName}`,
|
|
415
|
-
}),
|
|
416
|
-
(0, utils_1.guard)((Array.isArray(required)
|
|
417
|
-
? required.includes(name)
|
|
418
|
-
: required === true) ||
|
|
419
|
-
schema.deprecated ||
|
|
420
|
-
nullable, () => [
|
|
421
|
-
(0, utils_1.create)("span", {
|
|
422
|
-
className: "openapi-schema__divider",
|
|
423
|
-
}),
|
|
424
|
-
]),
|
|
425
|
-
(0, utils_1.guard)(nullable, () => [
|
|
426
|
-
(0, utils_1.create)("span", {
|
|
427
|
-
className: "openapi-schema__nullable",
|
|
428
|
-
children: "nullable",
|
|
429
|
-
}),
|
|
430
|
-
]),
|
|
431
|
-
(0, utils_1.guard)(Array.isArray(required)
|
|
432
|
-
? required.includes(name)
|
|
433
|
-
: required === true, () => [
|
|
434
|
-
(0, utils_1.create)("span", {
|
|
435
|
-
className: "openapi-schema__required",
|
|
436
|
-
children: "required",
|
|
437
|
-
}),
|
|
438
|
-
]),
|
|
439
|
-
(0, utils_1.guard)(schema.deprecated, () => [
|
|
440
|
-
(0, utils_1.create)("span", {
|
|
441
|
-
className: "openapi-schema__deprecated",
|
|
442
|
-
children: "deprecated",
|
|
443
|
-
}),
|
|
444
|
-
]),
|
|
445
|
-
],
|
|
446
|
-
}),
|
|
447
|
-
],
|
|
448
|
-
}),
|
|
449
|
-
(0, utils_1.create)("div", {
|
|
450
|
-
style: { marginLeft: "1rem" },
|
|
451
|
-
children: [
|
|
452
|
-
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
|
|
453
|
-
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
454
|
-
children: (0, createDescription_1.createDescription)(message),
|
|
455
|
-
})),
|
|
456
|
-
(0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
|
|
457
|
-
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
458
|
-
children: (0, createDescription_1.createDescription)(description),
|
|
459
|
-
})),
|
|
460
|
-
createNodes(schema),
|
|
461
|
-
],
|
|
462
|
-
}),
|
|
463
|
-
],
|
|
464
|
-
}),
|
|
465
|
-
],
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* For handling discriminators that map to a same-level property (like 'petType').
|
|
470
|
-
* Note: These should only be encountered while iterating through properties.
|
|
471
|
-
*/
|
|
472
|
-
function createPropertyDiscriminator(name, schemaName, schema, discriminator, required) {
|
|
473
|
-
if (schema === undefined) {
|
|
474
|
-
return undefined;
|
|
475
|
-
}
|
|
476
|
-
if (discriminator.mapping === undefined) {
|
|
477
|
-
return undefined;
|
|
478
|
-
}
|
|
479
|
-
return (0, utils_1.create)("div", {
|
|
480
|
-
className: "openapi-discriminator__item openapi-schema__list-item",
|
|
481
|
-
children: (0, utils_1.create)("div", {
|
|
482
|
-
children: [
|
|
483
|
-
(0, utils_1.create)("span", {
|
|
484
|
-
className: "openapi-schema__container",
|
|
485
|
-
children: [
|
|
486
|
-
(0, utils_1.create)("strong", {
|
|
487
|
-
className: "openapi-discriminator__name openapi-schema__property",
|
|
488
|
-
children: name,
|
|
489
|
-
}),
|
|
490
|
-
(0, utils_1.guard)(schemaName, (name) => (0, utils_1.create)("span", {
|
|
491
|
-
className: "openapi-schema__name",
|
|
492
|
-
children: ` ${schemaName}`,
|
|
493
|
-
})),
|
|
494
|
-
(0, utils_1.guard)(required, () => [
|
|
495
|
-
(0, utils_1.create)("span", {
|
|
496
|
-
className: "openapi-schema__required",
|
|
497
|
-
children: "required",
|
|
498
|
-
}),
|
|
499
|
-
]),
|
|
500
|
-
],
|
|
501
|
-
}),
|
|
502
|
-
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(discriminator), (message) => (0, utils_1.create)("div", {
|
|
503
|
-
style: {
|
|
504
|
-
paddingLeft: "1rem",
|
|
505
|
-
},
|
|
506
|
-
children: (0, createDescription_1.createDescription)(message),
|
|
507
|
-
})),
|
|
508
|
-
(0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
|
|
509
|
-
style: {
|
|
510
|
-
paddingLeft: "1rem",
|
|
511
|
-
},
|
|
512
|
-
children: (0, createDescription_1.createDescription)(description),
|
|
513
|
-
})),
|
|
514
|
-
(0, utils_1.create)("DiscriminatorTabs", {
|
|
515
|
-
className: "openapi-tabs__discriminator",
|
|
516
|
-
children: Object.keys(discriminator === null || discriminator === void 0 ? void 0 : discriminator.mapping).map((key, index) => {
|
|
517
|
-
const label = key;
|
|
518
|
-
return (0, utils_1.create)("TabItem", {
|
|
519
|
-
// className: "openapi-tabs__discriminator-item",
|
|
520
|
-
label: label,
|
|
521
|
-
value: `${index}-item-discriminator`,
|
|
522
|
-
children: [createNodes(discriminator === null || discriminator === void 0 ? void 0 : discriminator.mapping[key])],
|
|
523
|
-
});
|
|
524
|
-
}),
|
|
525
|
-
}),
|
|
526
|
-
],
|
|
527
|
-
}),
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
/**
|
|
531
|
-
* Creates the edges or "leaves" of a schema tree. Edges can branch into sub-nodes with createDetails().
|
|
532
|
-
*/
|
|
533
|
-
function createEdges({ name, schema, required, discriminator, }) {
|
|
534
|
-
var _a, _b, _c, _d;
|
|
535
|
-
const schemaName = (0, schema_1.getSchemaName)(schema);
|
|
536
|
-
if (discriminator !== undefined && discriminator.propertyName === name) {
|
|
537
|
-
return createPropertyDiscriminator(name, "string", schema, discriminator, required);
|
|
538
|
-
}
|
|
539
|
-
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
540
|
-
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
541
|
-
}
|
|
542
|
-
if (schema.allOf !== undefined) {
|
|
543
|
-
const { mergedSchemas, required, } = mergeAllOf(schema.allOf);
|
|
544
|
-
const mergedSchemaName = (0, schema_1.getSchemaName)(mergedSchemas);
|
|
545
|
-
if (mergedSchemas.oneOf !== undefined ||
|
|
546
|
-
mergedSchemas.anyOf !== undefined) {
|
|
547
|
-
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
548
|
-
}
|
|
549
|
-
if (mergedSchemas.properties !== undefined) {
|
|
550
|
-
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
551
|
-
}
|
|
552
|
-
if (mergedSchemas.additionalProperties !== undefined) {
|
|
553
|
-
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
554
|
-
}
|
|
555
|
-
// array of objects
|
|
556
|
-
if (((_a = mergedSchemas.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
|
|
557
|
-
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
558
|
-
}
|
|
559
|
-
if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
|
|
560
|
-
return undefined;
|
|
561
|
-
}
|
|
562
|
-
return (0, utils_1.create)("SchemaItem", {
|
|
563
|
-
collapsible: false,
|
|
564
|
-
name,
|
|
565
|
-
required: Array.isArray(required) ? required.includes(name) : required,
|
|
566
|
-
schemaName: schemaName,
|
|
567
|
-
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
568
|
-
schema: mergedSchemas,
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
if (schema.properties !== undefined) {
|
|
572
|
-
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
573
|
-
}
|
|
574
|
-
if (schema.additionalProperties !== undefined) {
|
|
575
|
-
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
576
|
-
}
|
|
577
|
-
// array of objects
|
|
578
|
-
if (((_b = schema.items) === null || _b === void 0 ? void 0 : _b.properties) !== undefined) {
|
|
579
|
-
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
580
|
-
}
|
|
581
|
-
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) {
|
|
582
|
-
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
583
|
-
}
|
|
584
|
-
if (schema.readOnly && schema.readOnly === true) {
|
|
585
|
-
return undefined;
|
|
586
|
-
}
|
|
587
|
-
// primitives and array of non-objects
|
|
588
|
-
return (0, utils_1.create)("SchemaItem", {
|
|
589
|
-
collapsible: false,
|
|
590
|
-
name,
|
|
591
|
-
required: Array.isArray(required) ? required.includes(name) : required,
|
|
592
|
-
schemaName: schemaName,
|
|
593
|
-
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
594
|
-
schema: schema,
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
/**
|
|
598
|
-
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
599
|
-
*/
|
|
600
|
-
function createNodes(schema) {
|
|
601
|
-
const nodes = [];
|
|
602
|
-
// if (schema.discriminator !== undefined) {
|
|
603
|
-
// return createDiscriminator(schema);
|
|
604
|
-
// }
|
|
605
|
-
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
606
|
-
nodes.push(createAnyOneOf(schema));
|
|
607
|
-
}
|
|
608
|
-
if (schema.allOf !== undefined) {
|
|
609
|
-
const { mergedSchemas } = mergeAllOf(schema.allOf);
|
|
610
|
-
// allOf seems to always result in properties
|
|
611
|
-
if (mergedSchemas.properties !== undefined) {
|
|
612
|
-
nodes.push(createProperties(mergedSchemas));
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
if (schema.properties !== undefined) {
|
|
616
|
-
nodes.push(createProperties(schema));
|
|
617
|
-
}
|
|
618
|
-
if (schema.additionalProperties !== undefined) {
|
|
619
|
-
nodes.push(createAdditionalProperties(schema));
|
|
620
|
-
}
|
|
621
|
-
// TODO: figure out how to handle array of objects
|
|
622
|
-
if (schema.items !== undefined) {
|
|
623
|
-
nodes.push(createItems(schema));
|
|
624
|
-
}
|
|
625
|
-
if (nodes.length && nodes.length > 0) {
|
|
626
|
-
return nodes.filter(Boolean).flat();
|
|
627
|
-
}
|
|
628
|
-
// primitive
|
|
629
|
-
if (schema.type !== undefined) {
|
|
630
|
-
return (0, utils_1.create)("SchemaItem", {
|
|
631
|
-
collapsible: false,
|
|
632
|
-
name: schema.type,
|
|
633
|
-
required: false,
|
|
634
|
-
schemaName: schema.format,
|
|
635
|
-
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
636
|
-
schema: schema,
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
// Unknown node/schema type should return undefined
|
|
640
|
-
// So far, haven't seen this hit in testing
|
|
641
|
-
return (0, utils_1.create)("SchemaItem", {
|
|
642
|
-
collapsible: false,
|
|
643
|
-
name: "any",
|
|
644
|
-
required: false,
|
|
645
|
-
schemaName: schema.format,
|
|
646
|
-
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
647
|
-
schema: schema,
|
|
648
|
-
});
|
|
649
|
-
}
|
|
650
15
|
function createRequestSchema({ title, body, ...rest }) {
|
|
651
16
|
var _a;
|
|
652
17
|
if (body === undefined ||
|
|
@@ -709,7 +74,7 @@ function createRequestSchema({ title, body, ...rest }) {
|
|
|
709
74
|
}),
|
|
710
75
|
(0, utils_1.create)("ul", {
|
|
711
76
|
style: { marginLeft: "1rem" },
|
|
712
|
-
children: createNodes(firstBody),
|
|
77
|
+
children: (0, createSchema_1.createNodes)(firstBody),
|
|
713
78
|
}),
|
|
714
79
|
],
|
|
715
80
|
}),
|
|
@@ -774,7 +139,7 @@ function createRequestSchema({ title, body, ...rest }) {
|
|
|
774
139
|
}),
|
|
775
140
|
(0, utils_1.create)("ul", {
|
|
776
141
|
style: { marginLeft: "1rem" },
|
|
777
|
-
children: createNodes(firstBody),
|
|
142
|
+
children: (0, createSchema_1.createNodes)(firstBody),
|
|
778
143
|
}),
|
|
779
144
|
],
|
|
780
145
|
}),
|