docusaurus-plugin-openapi-docs 2.0.0-beta.2 → 2.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/lib/index.js +20 -7
- package/lib/markdown/createAuthorization.d.ts +1 -0
- package/lib/markdown/createAuthorization.js +16 -0
- package/lib/markdown/createParamsDetails.js +2 -1
- package/lib/markdown/createRequestHeader.d.ts +1 -0
- package/lib/markdown/createRequestHeader.js +13 -0
- package/lib/markdown/createRequestSchema.d.ts +1 -8
- package/lib/markdown/createRequestSchema.js +21 -633
- package/lib/markdown/createResponseSchema.d.ts +1 -8
- package/lib/markdown/createResponseSchema.js +8 -626
- package/lib/markdown/createSchema.d.ts +12 -0
- package/lib/markdown/createSchema.js +647 -0
- package/lib/markdown/createVendorExtensions.d.ts +1 -0
- package/lib/markdown/createVendorExtensions.js +25 -0
- package/lib/markdown/index.d.ts +1 -1
- package/lib/markdown/index.js +11 -4
- package/lib/openapi/createRequestExample.js +3 -3
- package/lib/openapi/createResponseExample.js +3 -3
- package/lib/openapi/openapi.js +22 -0
- package/lib/openapi/utils/loadAndResolveSpec.js +9 -2
- package/lib/options.js +1 -0
- package/lib/types.d.ts +2 -0
- package/package.json +9 -17
- package/src/index.ts +21 -8
- package/src/markdown/createAuthorization.ts +13 -0
- package/src/markdown/createParamsDetails.ts +2 -1
- package/src/markdown/createRequestHeader.ts +10 -0
- package/src/markdown/createRequestSchema.ts +20 -839
- package/src/markdown/createResponseSchema.ts +8 -834
- package/src/markdown/createSchema.ts +850 -0
- package/src/markdown/createVendorExtensions.ts +22 -0
- package/src/markdown/index.ts +13 -3
- package/src/openapi/createRequestExample.ts +1 -1
- package/src/openapi/createResponseExample.ts +1 -1
- package/src/openapi/openapi.ts +26 -0
- package/src/openapi/utils/loadAndResolveSpec.ts +10 -1
- package/src/options.ts +1 -0
- package/src/types.ts +2 -0
|
@@ -6,624 +6,12 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
* ========================================================================== */
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.createRequestSchema =
|
|
10
|
-
const createArrayBracket_1 = require("./createArrayBracket");
|
|
9
|
+
exports.createRequestSchema = void 0;
|
|
11
10
|
const createDescription_1 = require("./createDescription");
|
|
12
11
|
const createDetails_1 = require("./createDetails");
|
|
13
12
|
const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
14
|
-
const
|
|
13
|
+
const createSchema_1 = require("./createSchema");
|
|
15
14
|
const utils_1 = require("./utils");
|
|
16
|
-
const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
|
|
17
|
-
/**
|
|
18
|
-
* Returns a merged representation of allOf array of schemas.
|
|
19
|
-
*/
|
|
20
|
-
function mergeAllOf(allOf) {
|
|
21
|
-
const mergedSchemas = jsonSchemaMergeAllOf(allOf, {
|
|
22
|
-
resolvers: {
|
|
23
|
-
readOnly: function () {
|
|
24
|
-
return true;
|
|
25
|
-
},
|
|
26
|
-
example: function () {
|
|
27
|
-
return true;
|
|
28
|
-
},
|
|
29
|
-
"x-examples": function () {
|
|
30
|
-
return true;
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
ignoreAdditionalProperties: true,
|
|
34
|
-
});
|
|
35
|
-
const required = allOf.reduce((acc, cur) => {
|
|
36
|
-
if (Array.isArray(cur.required)) {
|
|
37
|
-
const next = [...acc, ...cur.required];
|
|
38
|
-
return next;
|
|
39
|
-
}
|
|
40
|
-
return acc;
|
|
41
|
-
}, []);
|
|
42
|
-
return { mergedSchemas, required };
|
|
43
|
-
}
|
|
44
|
-
exports.mergeAllOf = mergeAllOf;
|
|
45
|
-
/**
|
|
46
|
-
* For handling nested anyOf/oneOf.
|
|
47
|
-
*/
|
|
48
|
-
function createAnyOneOf(schema) {
|
|
49
|
-
const type = schema.oneOf ? "oneOf" : "anyOf";
|
|
50
|
-
return (0, utils_1.create)("li", {
|
|
51
|
-
children: [
|
|
52
|
-
(0, utils_1.create)("span", {
|
|
53
|
-
className: "badge badge--info",
|
|
54
|
-
children: type,
|
|
55
|
-
}),
|
|
56
|
-
(0, utils_1.create)("SchemaTabs", {
|
|
57
|
-
children: schema[type].map((anyOneSchema, index) => {
|
|
58
|
-
const label = anyOneSchema.title
|
|
59
|
-
? anyOneSchema.title
|
|
60
|
-
: `MOD${index + 1}`;
|
|
61
|
-
const anyOneChildren = [];
|
|
62
|
-
if (anyOneSchema.properties !== undefined) {
|
|
63
|
-
anyOneChildren.push(createProperties(anyOneSchema));
|
|
64
|
-
}
|
|
65
|
-
if (anyOneSchema.allOf !== undefined) {
|
|
66
|
-
anyOneChildren.push(createNodes(anyOneSchema));
|
|
67
|
-
}
|
|
68
|
-
if (anyOneSchema.items !== undefined) {
|
|
69
|
-
anyOneChildren.push(createItems(anyOneSchema));
|
|
70
|
-
}
|
|
71
|
-
if (anyOneSchema.type === "string" ||
|
|
72
|
-
anyOneSchema.type === "number" ||
|
|
73
|
-
anyOneSchema.type === "integer" ||
|
|
74
|
-
anyOneSchema.type === "boolean") {
|
|
75
|
-
anyOneChildren.push(createNodes(anyOneSchema));
|
|
76
|
-
}
|
|
77
|
-
if (anyOneChildren.length) {
|
|
78
|
-
if (schema.type === "array") {
|
|
79
|
-
return (0, utils_1.create)("TabItem", {
|
|
80
|
-
label: label,
|
|
81
|
-
value: `${index}-item-properties`,
|
|
82
|
-
children: [
|
|
83
|
-
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
84
|
-
anyOneChildren,
|
|
85
|
-
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
86
|
-
]
|
|
87
|
-
.filter(Boolean)
|
|
88
|
-
.flat(),
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
return (0, utils_1.create)("TabItem", {
|
|
92
|
-
label: label,
|
|
93
|
-
value: `${index}-item-properties`,
|
|
94
|
-
children: anyOneChildren.filter(Boolean).flat(),
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
return undefined;
|
|
98
|
-
}),
|
|
99
|
-
}),
|
|
100
|
-
],
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
function createProperties(schema) {
|
|
104
|
-
const discriminator = schema.discriminator;
|
|
105
|
-
return Object.entries(schema.properties).map(([key, val]) => {
|
|
106
|
-
return createEdges({
|
|
107
|
-
name: key,
|
|
108
|
-
schema: val,
|
|
109
|
-
required: Array.isArray(schema.required)
|
|
110
|
-
? schema.required.includes(key)
|
|
111
|
-
: false,
|
|
112
|
-
discriminator,
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
function createAdditionalProperties(schema) {
|
|
117
|
-
// TODO?:
|
|
118
|
-
// {
|
|
119
|
-
// description: 'Integration configuration. See \n' +
|
|
120
|
-
// '[Integration Configurations](https://prisma.pan.dev/api/cloud/api-integration-config/).\n',
|
|
121
|
-
// example: { webhookUrl: 'https://hooks.slack.com/abcdef' },
|
|
122
|
-
// externalDocs: { url: 'https://prisma.pan.dev/api/cloud/api-integration-config' },
|
|
123
|
-
// type: 'object'
|
|
124
|
-
// }
|
|
125
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
126
|
-
// TODO?:
|
|
127
|
-
// {
|
|
128
|
-
// items: {
|
|
129
|
-
// properties: {
|
|
130
|
-
// aliasField: [Object],
|
|
131
|
-
// displayName: [Object],
|
|
132
|
-
// fieldName: [Object],
|
|
133
|
-
// maxLength: [Object],
|
|
134
|
-
// options: [Object],
|
|
135
|
-
// redlockMapping: [Object],
|
|
136
|
-
// required: [Object],
|
|
137
|
-
// type: [Object],
|
|
138
|
-
// typeaheadUri: [Object],
|
|
139
|
-
// value: [Object]
|
|
140
|
-
// },
|
|
141
|
-
// type: 'object'
|
|
142
|
-
// },
|
|
143
|
-
// type: 'array'
|
|
144
|
-
// }
|
|
145
|
-
const additionalProperties = schema.additionalProperties;
|
|
146
|
-
const type = additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.type;
|
|
147
|
-
if ((type === "object" || type === "array") &&
|
|
148
|
-
((additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.properties) ||
|
|
149
|
-
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.items) ||
|
|
150
|
-
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.allOf) ||
|
|
151
|
-
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.additionalProperties) ||
|
|
152
|
-
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.oneOf) ||
|
|
153
|
-
(additionalProperties === null || additionalProperties === void 0 ? void 0 : additionalProperties.anyOf))) {
|
|
154
|
-
const title = additionalProperties.title;
|
|
155
|
-
const schemaName = title ? `object (${title})` : "object";
|
|
156
|
-
const required = (_a = schema.required) !== null && _a !== void 0 ? _a : false;
|
|
157
|
-
return createDetailsNode("property name*", schemaName, additionalProperties, required, schema.nullable);
|
|
158
|
-
}
|
|
159
|
-
if (((_b = schema.additionalProperties) === null || _b === void 0 ? void 0 : _b.type) === "string" ||
|
|
160
|
-
((_c = schema.additionalProperties) === null || _c === void 0 ? void 0 : _c.type) === "object" ||
|
|
161
|
-
((_d = schema.additionalProperties) === null || _d === void 0 ? void 0 : _d.type) === "boolean" ||
|
|
162
|
-
((_e = schema.additionalProperties) === null || _e === void 0 ? void 0 : _e.type) === "integer" ||
|
|
163
|
-
((_f = schema.additionalProperties) === null || _f === void 0 ? void 0 : _f.type) === "number") {
|
|
164
|
-
const additionalProperties = (_g = schema.additionalProperties) === null || _g === void 0 ? void 0 : _g.additionalProperties;
|
|
165
|
-
if (additionalProperties !== undefined) {
|
|
166
|
-
const type = (_j = (_h = schema.additionalProperties) === null || _h === void 0 ? void 0 : _h.additionalProperties) === null || _j === void 0 ? void 0 : _j.type;
|
|
167
|
-
const format = (_l = (_k = schema.additionalProperties) === null || _k === void 0 ? void 0 : _k.additionalProperties) === null || _l === void 0 ? void 0 : _l.format;
|
|
168
|
-
return (0, utils_1.create)("li", {
|
|
169
|
-
children: (0, utils_1.create)("div", {
|
|
170
|
-
children: [
|
|
171
|
-
(0, utils_1.create)("code", { children: `property name*` }),
|
|
172
|
-
(0, utils_1.guard)(type, (type) => (0, utils_1.create)("span", {
|
|
173
|
-
style: { opacity: "0.6" },
|
|
174
|
-
children: ` ${type}`,
|
|
175
|
-
})),
|
|
176
|
-
(0, utils_1.guard)(format, (format) => (0, utils_1.create)("span", {
|
|
177
|
-
style: { opacity: "0.6" },
|
|
178
|
-
children: ` (${format})`,
|
|
179
|
-
})),
|
|
180
|
-
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema.additionalProperties), (message) => (0, utils_1.create)("div", {
|
|
181
|
-
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
182
|
-
children: (0, createDescription_1.createDescription)(message),
|
|
183
|
-
})),
|
|
184
|
-
],
|
|
185
|
-
}),
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
return (0, utils_1.create)("li", {
|
|
189
|
-
children: (0, utils_1.create)("div", {
|
|
190
|
-
children: [
|
|
191
|
-
(0, utils_1.create)("code", { children: `property name*` }),
|
|
192
|
-
(0, utils_1.guard)(type, (type) => (0, utils_1.create)("span", {
|
|
193
|
-
style: { opacity: "0.6" },
|
|
194
|
-
children: ` ${type}`,
|
|
195
|
-
})),
|
|
196
|
-
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema.additionalProperties), (message) => (0, utils_1.create)("div", {
|
|
197
|
-
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
198
|
-
children: (0, createDescription_1.createDescription)(message),
|
|
199
|
-
})),
|
|
200
|
-
],
|
|
201
|
-
}),
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
return Object.entries(schema.additionalProperties).map(([key, val]) => createEdges({
|
|
205
|
-
name: key,
|
|
206
|
-
schema: val,
|
|
207
|
-
required: Array.isArray(schema.required)
|
|
208
|
-
? schema.required.includes(key)
|
|
209
|
-
: false,
|
|
210
|
-
}));
|
|
211
|
-
}
|
|
212
|
-
// TODO: figure out how to handle array of objects
|
|
213
|
-
function createItems(schema) {
|
|
214
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
215
|
-
if (((_a = schema.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
|
|
216
|
-
return [
|
|
217
|
-
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
218
|
-
createProperties(schema.items),
|
|
219
|
-
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
220
|
-
].flat();
|
|
221
|
-
}
|
|
222
|
-
if (((_b = schema.items) === null || _b === void 0 ? void 0 : _b.additionalProperties) !== undefined) {
|
|
223
|
-
return [
|
|
224
|
-
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
225
|
-
createAdditionalProperties(schema.items),
|
|
226
|
-
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
227
|
-
].flat();
|
|
228
|
-
}
|
|
229
|
-
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) {
|
|
230
|
-
return [
|
|
231
|
-
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
232
|
-
createAnyOneOf(schema.items),
|
|
233
|
-
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
234
|
-
].flat();
|
|
235
|
-
}
|
|
236
|
-
if (((_e = schema.items) === null || _e === void 0 ? void 0 : _e.allOf) !== undefined) {
|
|
237
|
-
// TODO: figure out if and how we should pass merged required array
|
|
238
|
-
const { mergedSchemas, } = mergeAllOf((_f = schema.items) === null || _f === void 0 ? void 0 : _f.allOf);
|
|
239
|
-
// Handles combo anyOf/oneOf + properties
|
|
240
|
-
if ((mergedSchemas.oneOf !== undefined ||
|
|
241
|
-
mergedSchemas.anyOf !== undefined) &&
|
|
242
|
-
mergedSchemas.properties) {
|
|
243
|
-
return [
|
|
244
|
-
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
245
|
-
createAnyOneOf(mergedSchemas),
|
|
246
|
-
createProperties(mergedSchemas),
|
|
247
|
-
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
248
|
-
].flat();
|
|
249
|
-
}
|
|
250
|
-
// Handles only anyOf/oneOf
|
|
251
|
-
if (mergedSchemas.oneOf !== undefined ||
|
|
252
|
-
mergedSchemas.anyOf !== undefined) {
|
|
253
|
-
return [
|
|
254
|
-
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
255
|
-
createAnyOneOf(mergedSchemas),
|
|
256
|
-
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
257
|
-
].flat();
|
|
258
|
-
}
|
|
259
|
-
// Handles properties
|
|
260
|
-
if (mergedSchemas.properties !== undefined) {
|
|
261
|
-
return [
|
|
262
|
-
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
263
|
-
createProperties(mergedSchemas),
|
|
264
|
-
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
265
|
-
].flat();
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
if (((_g = schema.items) === null || _g === void 0 ? void 0 : _g.type) === "string" ||
|
|
269
|
-
((_h = schema.items) === null || _h === void 0 ? void 0 : _h.type) === "number" ||
|
|
270
|
-
((_j = schema.items) === null || _j === void 0 ? void 0 : _j.type) === "integer" ||
|
|
271
|
-
((_k = schema.items) === null || _k === void 0 ? void 0 : _k.type) === "boolean" ||
|
|
272
|
-
((_l = schema.items) === null || _l === void 0 ? void 0 : _l.type) === "object") {
|
|
273
|
-
return [
|
|
274
|
-
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
275
|
-
createNodes(schema.items),
|
|
276
|
-
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
277
|
-
].flat();
|
|
278
|
-
}
|
|
279
|
-
// TODO: clean this up or eliminate it?
|
|
280
|
-
return [
|
|
281
|
-
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
282
|
-
Object.entries(schema.items).map(([key, val]) => createEdges({
|
|
283
|
-
name: key,
|
|
284
|
-
schema: val,
|
|
285
|
-
required: Array.isArray(schema.required)
|
|
286
|
-
? schema.required.includes(key)
|
|
287
|
-
: false,
|
|
288
|
-
})),
|
|
289
|
-
(0, createArrayBracket_1.createClosingArrayBracket)(),
|
|
290
|
-
].flat();
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* For handling discriminators that do not map to a same-level property
|
|
294
|
-
*/
|
|
295
|
-
// function createDiscriminator(schema: SchemaObject) {
|
|
296
|
-
// const discriminator = schema.discriminator;
|
|
297
|
-
// const propertyName = discriminator?.propertyName;
|
|
298
|
-
// const propertyType = "string"; // should always be string
|
|
299
|
-
// const mapping: any = discriminator?.mapping;
|
|
300
|
-
// // Explicit mapping is required since we can't support implicit
|
|
301
|
-
// if (mapping === undefined) {
|
|
302
|
-
// return undefined;
|
|
303
|
-
// }
|
|
304
|
-
// // Attempt to get the property description we want to display
|
|
305
|
-
// // TODO: how to make it predictable when handling allOf
|
|
306
|
-
// let propertyDescription;
|
|
307
|
-
// const firstMappingSchema = mapping[Object.keys(mapping)[0]];
|
|
308
|
-
// if (firstMappingSchema.properties !== undefined) {
|
|
309
|
-
// propertyDescription =
|
|
310
|
-
// firstMappingSchema.properties![propertyName!].description;
|
|
311
|
-
// }
|
|
312
|
-
// if (firstMappingSchema.allOf !== undefined) {
|
|
313
|
-
// const { mergedSchemas }: { mergedSchemas: SchemaObject } = mergeAllOf(
|
|
314
|
-
// firstMappingSchema.allOf
|
|
315
|
-
// );
|
|
316
|
-
// if (mergedSchemas.properties !== undefined) {
|
|
317
|
-
// propertyDescription =
|
|
318
|
-
// mergedSchemas.properties[propertyName!]?.description;
|
|
319
|
-
// }
|
|
320
|
-
// }
|
|
321
|
-
// if (propertyDescription === undefined) {
|
|
322
|
-
// if (
|
|
323
|
-
// schema.properties !== undefined &&
|
|
324
|
-
// schema.properties![propertyName!] !== undefined
|
|
325
|
-
// ) {
|
|
326
|
-
// propertyDescription = schema.properties![propertyName!].description;
|
|
327
|
-
// }
|
|
328
|
-
// }
|
|
329
|
-
// return create("div", {
|
|
330
|
-
// className: "openapi-discriminator__item",
|
|
331
|
-
// children: create("div", {
|
|
332
|
-
// children: [
|
|
333
|
-
// create("strong", {
|
|
334
|
-
// style: { paddingLeft: "1rem" },
|
|
335
|
-
// children: propertyName,
|
|
336
|
-
// }),
|
|
337
|
-
// guard(propertyType, (name) =>
|
|
338
|
-
// create("span", {
|
|
339
|
-
// style: { opacity: "0.6" },
|
|
340
|
-
// children: ` ${propertyType}`,
|
|
341
|
-
// })
|
|
342
|
-
// ),
|
|
343
|
-
// guard(getQualifierMessage(schema.discriminator as any), (message) =>
|
|
344
|
-
// create("div", {
|
|
345
|
-
// style: {
|
|
346
|
-
// paddingLeft: "1rem",
|
|
347
|
-
// },
|
|
348
|
-
// children: createDescription(message),
|
|
349
|
-
// })
|
|
350
|
-
// ),
|
|
351
|
-
// guard(propertyDescription, (description) =>
|
|
352
|
-
// create("div", {
|
|
353
|
-
// style: {
|
|
354
|
-
// paddingLeft: "1rem",
|
|
355
|
-
// },
|
|
356
|
-
// children: createDescription(description),
|
|
357
|
-
// })
|
|
358
|
-
// ),
|
|
359
|
-
// create("DiscriminatorTabs", {
|
|
360
|
-
// children: Object.keys(mapping!).map((key, index) => {
|
|
361
|
-
// if (mapping[key].allOf !== undefined) {
|
|
362
|
-
// const { mergedSchemas }: { mergedSchemas: SchemaObject } =
|
|
363
|
-
// mergeAllOf(mapping[key].allOf);
|
|
364
|
-
// // Cleanup duplicate property from mapping schema
|
|
365
|
-
// delete mergedSchemas.properties![propertyName!];
|
|
366
|
-
// mapping[key] = mergedSchemas;
|
|
367
|
-
// }
|
|
368
|
-
// if (mapping[key].properties !== undefined) {
|
|
369
|
-
// // Cleanup duplicate property from mapping schema
|
|
370
|
-
// delete mapping[key].properties![propertyName!];
|
|
371
|
-
// }
|
|
372
|
-
// const label = key;
|
|
373
|
-
// return create("TabItem", {
|
|
374
|
-
// label: label,
|
|
375
|
-
// value: `${index}-item-discriminator`,
|
|
376
|
-
// children: [
|
|
377
|
-
// create("div", {
|
|
378
|
-
// style: { marginLeft: "-4px" },
|
|
379
|
-
// children: createNodes(mapping[key]),
|
|
380
|
-
// }),
|
|
381
|
-
// ],
|
|
382
|
-
// });
|
|
383
|
-
// }),
|
|
384
|
-
// }),
|
|
385
|
-
// ],
|
|
386
|
-
// }),
|
|
387
|
-
// });
|
|
388
|
-
// }
|
|
389
|
-
function createDetailsNode(name, schemaName, schema, required, nullable) {
|
|
390
|
-
return (0, utils_1.create)("SchemaItem", {
|
|
391
|
-
collapsible: true,
|
|
392
|
-
className: "schemaItem",
|
|
393
|
-
children: [
|
|
394
|
-
(0, createDetails_1.createDetails)({
|
|
395
|
-
className: "openapi-markdown__details",
|
|
396
|
-
children: [
|
|
397
|
-
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
398
|
-
children: [
|
|
399
|
-
(0, utils_1.create)("strong", { children: name }),
|
|
400
|
-
(0, utils_1.create)("span", {
|
|
401
|
-
style: { opacity: "0.6" },
|
|
402
|
-
children: ` ${schemaName}`,
|
|
403
|
-
}),
|
|
404
|
-
(0, utils_1.guard)((schema.nullable && schema.nullable === true) ||
|
|
405
|
-
(nullable && nullable === true), () => [
|
|
406
|
-
(0, utils_1.create)("strong", {
|
|
407
|
-
style: {
|
|
408
|
-
fontSize: "var(--ifm-code-font-size)",
|
|
409
|
-
color: "var(--openapi-nullable)",
|
|
410
|
-
},
|
|
411
|
-
children: " nullable",
|
|
412
|
-
}),
|
|
413
|
-
]),
|
|
414
|
-
(0, utils_1.guard)(Array.isArray(required)
|
|
415
|
-
? required.includes(name)
|
|
416
|
-
: required === true, () => [
|
|
417
|
-
(0, utils_1.create)("strong", {
|
|
418
|
-
style: {
|
|
419
|
-
fontSize: "var(--ifm-code-font-size)",
|
|
420
|
-
color: "var(--openapi-required)",
|
|
421
|
-
},
|
|
422
|
-
children: " required",
|
|
423
|
-
}),
|
|
424
|
-
]),
|
|
425
|
-
],
|
|
426
|
-
}),
|
|
427
|
-
(0, utils_1.create)("div", {
|
|
428
|
-
style: { marginLeft: "1rem" },
|
|
429
|
-
children: [
|
|
430
|
-
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
|
|
431
|
-
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
432
|
-
children: (0, createDescription_1.createDescription)(message),
|
|
433
|
-
})),
|
|
434
|
-
(0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
|
|
435
|
-
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
436
|
-
children: (0, createDescription_1.createDescription)(description),
|
|
437
|
-
})),
|
|
438
|
-
createNodes(schema),
|
|
439
|
-
],
|
|
440
|
-
}),
|
|
441
|
-
],
|
|
442
|
-
}),
|
|
443
|
-
],
|
|
444
|
-
});
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* For handling discriminators that map to a same-level property (like 'petType').
|
|
448
|
-
* Note: These should only be encountered while iterating through properties.
|
|
449
|
-
*/
|
|
450
|
-
function createPropertyDiscriminator(name, schemaName, schema, discriminator, required) {
|
|
451
|
-
if (schema === undefined) {
|
|
452
|
-
return undefined;
|
|
453
|
-
}
|
|
454
|
-
if (discriminator.mapping === undefined) {
|
|
455
|
-
return undefined;
|
|
456
|
-
}
|
|
457
|
-
return (0, utils_1.create)("div", {
|
|
458
|
-
className: "openapi-discriminator__item",
|
|
459
|
-
children: (0, utils_1.create)("div", {
|
|
460
|
-
children: [
|
|
461
|
-
(0, utils_1.create)("strong", { style: { paddingLeft: "1rem" }, children: name }),
|
|
462
|
-
(0, utils_1.guard)(schemaName, (name) => (0, utils_1.create)("span", {
|
|
463
|
-
style: { opacity: "0.6" },
|
|
464
|
-
children: ` ${schemaName}`,
|
|
465
|
-
})),
|
|
466
|
-
(0, utils_1.guard)(required, () => [
|
|
467
|
-
(0, utils_1.create)("strong", {
|
|
468
|
-
style: {
|
|
469
|
-
fontSize: "var(--ifm-code-font-size)",
|
|
470
|
-
color: "var(--openapi-required)",
|
|
471
|
-
},
|
|
472
|
-
children: " required",
|
|
473
|
-
}),
|
|
474
|
-
]),
|
|
475
|
-
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(discriminator), (message) => (0, utils_1.create)("div", {
|
|
476
|
-
style: {
|
|
477
|
-
paddingLeft: "1rem",
|
|
478
|
-
},
|
|
479
|
-
children: (0, createDescription_1.createDescription)(message),
|
|
480
|
-
})),
|
|
481
|
-
(0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
|
|
482
|
-
style: {
|
|
483
|
-
paddingLeft: "1rem",
|
|
484
|
-
},
|
|
485
|
-
children: (0, createDescription_1.createDescription)(description),
|
|
486
|
-
})),
|
|
487
|
-
(0, utils_1.create)("DiscriminatorTabs", {
|
|
488
|
-
className: "openapi-tabs__discriminator",
|
|
489
|
-
children: Object.keys(discriminator === null || discriminator === void 0 ? void 0 : discriminator.mapping).map((key, index) => {
|
|
490
|
-
const label = key;
|
|
491
|
-
return (0, utils_1.create)("TabItem", {
|
|
492
|
-
// className: "openapi-tabs__discriminator-item",
|
|
493
|
-
label: label,
|
|
494
|
-
value: `${index}-item-discriminator`,
|
|
495
|
-
children: [createNodes(discriminator === null || discriminator === void 0 ? void 0 : discriminator.mapping[key])],
|
|
496
|
-
});
|
|
497
|
-
}),
|
|
498
|
-
}),
|
|
499
|
-
],
|
|
500
|
-
}),
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
/**
|
|
504
|
-
* Creates the edges or "leaves" of a schema tree. Edges can branch into sub-nodes with createDetails().
|
|
505
|
-
*/
|
|
506
|
-
function createEdges({ name, schema, required, discriminator, }) {
|
|
507
|
-
var _a, _b, _c, _d;
|
|
508
|
-
const schemaName = (0, schema_1.getSchemaName)(schema);
|
|
509
|
-
if (discriminator !== undefined && discriminator.propertyName === name) {
|
|
510
|
-
return createPropertyDiscriminator(name, "string", schema, discriminator, required);
|
|
511
|
-
}
|
|
512
|
-
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
513
|
-
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
514
|
-
}
|
|
515
|
-
if (schema.allOf !== undefined) {
|
|
516
|
-
const { mergedSchemas, required, } = mergeAllOf(schema.allOf);
|
|
517
|
-
const mergedSchemaName = (0, schema_1.getSchemaName)(mergedSchemas);
|
|
518
|
-
if (mergedSchemas.oneOf !== undefined ||
|
|
519
|
-
mergedSchemas.anyOf !== undefined) {
|
|
520
|
-
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
521
|
-
}
|
|
522
|
-
if (mergedSchemas.properties !== undefined) {
|
|
523
|
-
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
524
|
-
}
|
|
525
|
-
if (mergedSchemas.additionalProperties !== undefined) {
|
|
526
|
-
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
527
|
-
}
|
|
528
|
-
// array of objects
|
|
529
|
-
if (((_a = mergedSchemas.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
|
|
530
|
-
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
531
|
-
}
|
|
532
|
-
if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
|
|
533
|
-
return undefined;
|
|
534
|
-
}
|
|
535
|
-
return (0, utils_1.create)("SchemaItem", {
|
|
536
|
-
collapsible: false,
|
|
537
|
-
name,
|
|
538
|
-
required: Array.isArray(required) ? required.includes(name) : required,
|
|
539
|
-
schemaName: schemaName,
|
|
540
|
-
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
541
|
-
schema: mergedSchemas,
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
if (schema.properties !== undefined) {
|
|
545
|
-
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
546
|
-
}
|
|
547
|
-
if (schema.additionalProperties !== undefined) {
|
|
548
|
-
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
549
|
-
}
|
|
550
|
-
// array of objects
|
|
551
|
-
if (((_b = schema.items) === null || _b === void 0 ? void 0 : _b.properties) !== undefined) {
|
|
552
|
-
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
553
|
-
}
|
|
554
|
-
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) {
|
|
555
|
-
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
556
|
-
}
|
|
557
|
-
if (schema.readOnly && schema.readOnly === true) {
|
|
558
|
-
return undefined;
|
|
559
|
-
}
|
|
560
|
-
// primitives and array of non-objects
|
|
561
|
-
return (0, utils_1.create)("SchemaItem", {
|
|
562
|
-
collapsible: false,
|
|
563
|
-
name,
|
|
564
|
-
required: Array.isArray(required) ? required.includes(name) : required,
|
|
565
|
-
schemaName: schemaName,
|
|
566
|
-
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
567
|
-
schema: schema,
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
/**
|
|
571
|
-
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
572
|
-
*/
|
|
573
|
-
function createNodes(schema) {
|
|
574
|
-
const nodes = [];
|
|
575
|
-
// if (schema.discriminator !== undefined) {
|
|
576
|
-
// return createDiscriminator(schema);
|
|
577
|
-
// }
|
|
578
|
-
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
579
|
-
nodes.push(createAnyOneOf(schema));
|
|
580
|
-
}
|
|
581
|
-
if (schema.allOf !== undefined) {
|
|
582
|
-
const { mergedSchemas } = mergeAllOf(schema.allOf);
|
|
583
|
-
// allOf seems to always result in properties
|
|
584
|
-
if (mergedSchemas.properties !== undefined) {
|
|
585
|
-
nodes.push(createProperties(mergedSchemas));
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
if (schema.properties !== undefined) {
|
|
589
|
-
nodes.push(createProperties(schema));
|
|
590
|
-
}
|
|
591
|
-
if (schema.additionalProperties !== undefined) {
|
|
592
|
-
nodes.push(createAdditionalProperties(schema));
|
|
593
|
-
}
|
|
594
|
-
// TODO: figure out how to handle array of objects
|
|
595
|
-
if (schema.items !== undefined) {
|
|
596
|
-
nodes.push(createItems(schema));
|
|
597
|
-
}
|
|
598
|
-
if (nodes.length && nodes.length > 0) {
|
|
599
|
-
return nodes.filter(Boolean).flat();
|
|
600
|
-
}
|
|
601
|
-
// primitive
|
|
602
|
-
if (schema.type !== undefined) {
|
|
603
|
-
return (0, utils_1.create)("li", {
|
|
604
|
-
children: (0, utils_1.create)("div", {
|
|
605
|
-
children: [
|
|
606
|
-
(0, utils_1.create)("strong", { children: schema.type }),
|
|
607
|
-
(0, utils_1.guard)(schema.format, (format) => (0, utils_1.create)("span", {
|
|
608
|
-
style: { opacity: "0.6" },
|
|
609
|
-
children: ` ${format}`,
|
|
610
|
-
})),
|
|
611
|
-
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
|
|
612
|
-
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
613
|
-
children: (0, createDescription_1.createDescription)(message),
|
|
614
|
-
})),
|
|
615
|
-
(0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
|
|
616
|
-
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
617
|
-
children: (0, createDescription_1.createDescription)(description),
|
|
618
|
-
})),
|
|
619
|
-
],
|
|
620
|
-
}),
|
|
621
|
-
});
|
|
622
|
-
}
|
|
623
|
-
// Unknown node/schema type should return undefined
|
|
624
|
-
// So far, haven't seen this hit in testing
|
|
625
|
-
return "any";
|
|
626
|
-
}
|
|
627
15
|
function createRequestSchema({ title, body, ...rest }) {
|
|
628
16
|
var _a;
|
|
629
17
|
if (body === undefined ||
|
|
@@ -653,22 +41,22 @@ function createRequestSchema({ title, body, ...rest }) {
|
|
|
653
41
|
value: `${mimeType}`,
|
|
654
42
|
children: [
|
|
655
43
|
(0, createDetails_1.createDetails)({
|
|
656
|
-
className: "openapi-markdown__details",
|
|
44
|
+
className: "openapi-markdown__details mime",
|
|
657
45
|
"data-collapsed": false,
|
|
658
46
|
open: true,
|
|
659
47
|
...rest,
|
|
660
48
|
children: [
|
|
661
49
|
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
662
|
-
|
|
50
|
+
className: "openapi-markdown__details-summary-mime",
|
|
663
51
|
children: [
|
|
664
|
-
(0, utils_1.create)("
|
|
52
|
+
(0, utils_1.create)("h3", {
|
|
53
|
+
className: "openapi-markdown__details-summary-header-body",
|
|
54
|
+
children: `${title}`,
|
|
55
|
+
}),
|
|
665
56
|
(0, utils_1.guard)(body.required && body.required === true, () => [
|
|
666
|
-
(0, utils_1.create)("
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
color: "var(--openapi-required)",
|
|
670
|
-
},
|
|
671
|
-
children: " required",
|
|
57
|
+
(0, utils_1.create)("span", {
|
|
58
|
+
className: "openapi-schema__required",
|
|
59
|
+
children: "required",
|
|
672
60
|
}),
|
|
673
61
|
]),
|
|
674
62
|
],
|
|
@@ -686,7 +74,7 @@ function createRequestSchema({ title, body, ...rest }) {
|
|
|
686
74
|
}),
|
|
687
75
|
(0, utils_1.create)("ul", {
|
|
688
76
|
style: { marginLeft: "1rem" },
|
|
689
|
-
children: createNodes(firstBody),
|
|
77
|
+
children: (0, createSchema_1.createNodes)(firstBody),
|
|
690
78
|
}),
|
|
691
79
|
],
|
|
692
80
|
}),
|
|
@@ -714,26 +102,26 @@ function createRequestSchema({ title, body, ...rest }) {
|
|
|
714
102
|
value: `${randomFirstKey}-schema`,
|
|
715
103
|
children: [
|
|
716
104
|
(0, createDetails_1.createDetails)({
|
|
717
|
-
className: "openapi-markdown__details",
|
|
105
|
+
className: "openapi-markdown__details mime",
|
|
718
106
|
"data-collapsed": false,
|
|
719
107
|
open: true,
|
|
720
108
|
...rest,
|
|
721
109
|
children: [
|
|
722
110
|
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
723
|
-
|
|
111
|
+
className: "openapi-markdown__details-summary-mime",
|
|
724
112
|
children: [
|
|
725
|
-
(0, utils_1.create)("
|
|
113
|
+
(0, utils_1.create)("h3", {
|
|
114
|
+
className: "openapi-markdown__details-summary-header-body",
|
|
115
|
+
children: `${title}`,
|
|
116
|
+
}),
|
|
726
117
|
(0, utils_1.guard)(firstBody.type === "array", (format) => (0, utils_1.create)("span", {
|
|
727
118
|
style: { opacity: "0.6" },
|
|
728
119
|
children: ` array`,
|
|
729
120
|
})),
|
|
730
121
|
(0, utils_1.guard)(body.required, () => [
|
|
731
122
|
(0, utils_1.create)("strong", {
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
color: "var(--openapi-required)",
|
|
735
|
-
},
|
|
736
|
-
children: " required",
|
|
123
|
+
className: "openapi-schema__required",
|
|
124
|
+
children: "required",
|
|
737
125
|
}),
|
|
738
126
|
]),
|
|
739
127
|
],
|
|
@@ -751,7 +139,7 @@ function createRequestSchema({ title, body, ...rest }) {
|
|
|
751
139
|
}),
|
|
752
140
|
(0, utils_1.create)("ul", {
|
|
753
141
|
style: { marginLeft: "1rem" },
|
|
754
|
-
children: createNodes(firstBody),
|
|
142
|
+
children: (0, createSchema_1.createNodes)(firstBody),
|
|
755
143
|
}),
|
|
756
144
|
],
|
|
757
145
|
}),
|