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
|
@@ -5,833 +5,13 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import { MediaTypeObject
|
|
9
|
-
import {
|
|
10
|
-
createClosingArrayBracket,
|
|
11
|
-
createOpeningArrayBracket,
|
|
12
|
-
} from "./createArrayBracket";
|
|
8
|
+
import { MediaTypeObject } from "../openapi/types";
|
|
13
9
|
import { createDescription } from "./createDescription";
|
|
14
10
|
import { createDetails } from "./createDetails";
|
|
15
11
|
import { createDetailsSummary } from "./createDetailsSummary";
|
|
16
|
-
import {
|
|
12
|
+
import { createNodes } from "./createSchema";
|
|
17
13
|
import { create, guard } from "./utils";
|
|
18
14
|
|
|
19
|
-
const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Returns a merged representation of allOf array of schemas.
|
|
23
|
-
*/
|
|
24
|
-
export function mergeAllOf(allOf: SchemaObject[]) {
|
|
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
|
-
|
|
40
|
-
const required = allOf.reduce((acc, cur) => {
|
|
41
|
-
if (Array.isArray(cur.required)) {
|
|
42
|
-
const next = [...acc, ...cur.required];
|
|
43
|
-
return next;
|
|
44
|
-
}
|
|
45
|
-
return acc;
|
|
46
|
-
}, [] as any);
|
|
47
|
-
|
|
48
|
-
return { mergedSchemas, required };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* For handling nested anyOf/oneOf.
|
|
53
|
-
*/
|
|
54
|
-
function createAnyOneOf(schema: SchemaObject): any {
|
|
55
|
-
const type = schema.oneOf ? "oneOf" : "anyOf";
|
|
56
|
-
return create("li", {
|
|
57
|
-
children: [
|
|
58
|
-
create("span", {
|
|
59
|
-
className: "badge badge--info",
|
|
60
|
-
children: type,
|
|
61
|
-
}),
|
|
62
|
-
create("SchemaTabs", {
|
|
63
|
-
children: schema[type]!.map((anyOneSchema, index) => {
|
|
64
|
-
const label = anyOneSchema.title
|
|
65
|
-
? anyOneSchema.title
|
|
66
|
-
: `MOD${index + 1}`;
|
|
67
|
-
const anyOneChildren = [];
|
|
68
|
-
|
|
69
|
-
if (anyOneSchema.properties !== undefined) {
|
|
70
|
-
anyOneChildren.push(createProperties(anyOneSchema));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (anyOneSchema.allOf !== undefined) {
|
|
74
|
-
anyOneChildren.push(createNodes(anyOneSchema));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (anyOneSchema.items !== undefined) {
|
|
78
|
-
anyOneChildren.push(createItems(anyOneSchema));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (
|
|
82
|
-
anyOneSchema.type === "string" ||
|
|
83
|
-
anyOneSchema.type === "number" ||
|
|
84
|
-
anyOneSchema.type === "integer" ||
|
|
85
|
-
anyOneSchema.type === "boolean"
|
|
86
|
-
) {
|
|
87
|
-
anyOneChildren.push(createNodes(anyOneSchema));
|
|
88
|
-
}
|
|
89
|
-
if (anyOneChildren.length) {
|
|
90
|
-
if (schema.type === "array") {
|
|
91
|
-
return create("TabItem", {
|
|
92
|
-
label: label,
|
|
93
|
-
value: `${index}-item-properties`,
|
|
94
|
-
children: [
|
|
95
|
-
createOpeningArrayBracket(),
|
|
96
|
-
anyOneChildren,
|
|
97
|
-
createClosingArrayBracket(),
|
|
98
|
-
]
|
|
99
|
-
.filter(Boolean)
|
|
100
|
-
.flat(),
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
return create("TabItem", {
|
|
104
|
-
label: label,
|
|
105
|
-
value: `${index}-item-properties`,
|
|
106
|
-
children: anyOneChildren.filter(Boolean).flat(),
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return undefined;
|
|
111
|
-
}),
|
|
112
|
-
}),
|
|
113
|
-
],
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function createProperties(schema: SchemaObject) {
|
|
118
|
-
const discriminator = schema.discriminator;
|
|
119
|
-
return Object.entries(schema.properties!).map(([key, val]) => {
|
|
120
|
-
return createEdges({
|
|
121
|
-
name: key,
|
|
122
|
-
schema: val,
|
|
123
|
-
required: Array.isArray(schema.required)
|
|
124
|
-
? schema.required.includes(key)
|
|
125
|
-
: false,
|
|
126
|
-
discriminator,
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function createAdditionalProperties(schema: SchemaObject) {
|
|
132
|
-
// TODO?:
|
|
133
|
-
// {
|
|
134
|
-
// description: 'Integration configuration. See \n' +
|
|
135
|
-
// '[Integration Configurations](https://prisma.pan.dev/api/cloud/api-integration-config/).\n',
|
|
136
|
-
// example: { webhookUrl: 'https://hooks.slack.com/abcdef' },
|
|
137
|
-
// externalDocs: { url: 'https://prisma.pan.dev/api/cloud/api-integration-config' },
|
|
138
|
-
// type: 'object'
|
|
139
|
-
// }
|
|
140
|
-
|
|
141
|
-
// TODO?:
|
|
142
|
-
// {
|
|
143
|
-
// items: {
|
|
144
|
-
// properties: {
|
|
145
|
-
// aliasField: [Object],
|
|
146
|
-
// displayName: [Object],
|
|
147
|
-
// fieldName: [Object],
|
|
148
|
-
// maxLength: [Object],
|
|
149
|
-
// options: [Object],
|
|
150
|
-
// redlockMapping: [Object],
|
|
151
|
-
// required: [Object],
|
|
152
|
-
// type: [Object],
|
|
153
|
-
// typeaheadUri: [Object],
|
|
154
|
-
// value: [Object]
|
|
155
|
-
// },
|
|
156
|
-
// type: 'object'
|
|
157
|
-
// },
|
|
158
|
-
// type: 'array'
|
|
159
|
-
// }
|
|
160
|
-
const additionalProperties = schema.additionalProperties;
|
|
161
|
-
const type: string | unknown = additionalProperties?.type;
|
|
162
|
-
if (
|
|
163
|
-
(type === "object" || type === "array") &&
|
|
164
|
-
(additionalProperties?.properties ||
|
|
165
|
-
additionalProperties?.items ||
|
|
166
|
-
additionalProperties?.allOf ||
|
|
167
|
-
additionalProperties?.additionalProperties ||
|
|
168
|
-
additionalProperties?.oneOf ||
|
|
169
|
-
additionalProperties?.anyOf)
|
|
170
|
-
) {
|
|
171
|
-
const title = additionalProperties.title;
|
|
172
|
-
const schemaName = title ? `object (${title})` : "object";
|
|
173
|
-
const required = schema.required ?? false;
|
|
174
|
-
return createDetailsNode(
|
|
175
|
-
"property name*",
|
|
176
|
-
schemaName,
|
|
177
|
-
additionalProperties,
|
|
178
|
-
required,
|
|
179
|
-
schema.nullable
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (
|
|
184
|
-
(schema.additionalProperties?.type as string) === "string" ||
|
|
185
|
-
(schema.additionalProperties?.type as string) === "object" ||
|
|
186
|
-
(schema.additionalProperties?.type as string) === "boolean" ||
|
|
187
|
-
(schema.additionalProperties?.type as string) === "integer" ||
|
|
188
|
-
(schema.additionalProperties?.type as string) === "number"
|
|
189
|
-
) {
|
|
190
|
-
const additionalProperties =
|
|
191
|
-
schema.additionalProperties?.additionalProperties;
|
|
192
|
-
if (additionalProperties !== undefined) {
|
|
193
|
-
const type = schema.additionalProperties?.additionalProperties?.type;
|
|
194
|
-
const format = schema.additionalProperties?.additionalProperties?.format;
|
|
195
|
-
return create("li", {
|
|
196
|
-
children: create("div", {
|
|
197
|
-
children: [
|
|
198
|
-
create("code", { children: `property name*` }),
|
|
199
|
-
guard(type, (type) =>
|
|
200
|
-
create("span", {
|
|
201
|
-
style: { opacity: "0.6" },
|
|
202
|
-
children: ` ${type}`,
|
|
203
|
-
})
|
|
204
|
-
),
|
|
205
|
-
guard(format, (format) =>
|
|
206
|
-
create("span", {
|
|
207
|
-
style: { opacity: "0.6" },
|
|
208
|
-
children: ` (${format})`,
|
|
209
|
-
})
|
|
210
|
-
),
|
|
211
|
-
guard(getQualifierMessage(schema.additionalProperties), (message) =>
|
|
212
|
-
create("div", {
|
|
213
|
-
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
214
|
-
children: createDescription(message),
|
|
215
|
-
})
|
|
216
|
-
),
|
|
217
|
-
],
|
|
218
|
-
}),
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
return create("li", {
|
|
222
|
-
children: create("div", {
|
|
223
|
-
children: [
|
|
224
|
-
create("code", { children: `property name*` }),
|
|
225
|
-
guard(type, (type) =>
|
|
226
|
-
create("span", {
|
|
227
|
-
style: { opacity: "0.6" },
|
|
228
|
-
children: ` ${type}`,
|
|
229
|
-
})
|
|
230
|
-
),
|
|
231
|
-
guard(getQualifierMessage(schema.additionalProperties), (message) =>
|
|
232
|
-
create("div", {
|
|
233
|
-
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
234
|
-
children: createDescription(message),
|
|
235
|
-
})
|
|
236
|
-
),
|
|
237
|
-
],
|
|
238
|
-
}),
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
return Object.entries(schema.additionalProperties!).map(([key, val]) =>
|
|
242
|
-
createEdges({
|
|
243
|
-
name: key,
|
|
244
|
-
schema: val,
|
|
245
|
-
required: Array.isArray(schema.required)
|
|
246
|
-
? schema.required.includes(key)
|
|
247
|
-
: false,
|
|
248
|
-
})
|
|
249
|
-
);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// TODO: figure out how to handle array of objects
|
|
253
|
-
function createItems(schema: SchemaObject) {
|
|
254
|
-
if (schema.items?.properties !== undefined) {
|
|
255
|
-
return [
|
|
256
|
-
createOpeningArrayBracket(),
|
|
257
|
-
createProperties(schema.items),
|
|
258
|
-
createClosingArrayBracket(),
|
|
259
|
-
].flat();
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
if (schema.items?.additionalProperties !== undefined) {
|
|
263
|
-
return [
|
|
264
|
-
createOpeningArrayBracket(),
|
|
265
|
-
createAdditionalProperties(schema.items),
|
|
266
|
-
createClosingArrayBracket(),
|
|
267
|
-
].flat();
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
if (schema.items?.oneOf !== undefined || schema.items?.anyOf !== undefined) {
|
|
271
|
-
return [
|
|
272
|
-
createOpeningArrayBracket(),
|
|
273
|
-
createAnyOneOf(schema.items!),
|
|
274
|
-
createClosingArrayBracket(),
|
|
275
|
-
].flat();
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
if (schema.items?.allOf !== undefined) {
|
|
279
|
-
// TODO: figure out if and how we should pass merged required array
|
|
280
|
-
const {
|
|
281
|
-
mergedSchemas,
|
|
282
|
-
}: { mergedSchemas: SchemaObject; required: string[] } = mergeAllOf(
|
|
283
|
-
schema.items?.allOf
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
// Handles combo anyOf/oneOf + properties
|
|
287
|
-
if (
|
|
288
|
-
(mergedSchemas.oneOf !== undefined ||
|
|
289
|
-
mergedSchemas.anyOf !== undefined) &&
|
|
290
|
-
mergedSchemas.properties
|
|
291
|
-
) {
|
|
292
|
-
return [
|
|
293
|
-
createOpeningArrayBracket(),
|
|
294
|
-
createAnyOneOf(mergedSchemas),
|
|
295
|
-
createProperties(mergedSchemas),
|
|
296
|
-
createClosingArrayBracket(),
|
|
297
|
-
].flat();
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// Handles only anyOf/oneOf
|
|
301
|
-
if (
|
|
302
|
-
mergedSchemas.oneOf !== undefined ||
|
|
303
|
-
mergedSchemas.anyOf !== undefined
|
|
304
|
-
) {
|
|
305
|
-
return [
|
|
306
|
-
createOpeningArrayBracket(),
|
|
307
|
-
createAnyOneOf(mergedSchemas),
|
|
308
|
-
createClosingArrayBracket(),
|
|
309
|
-
].flat();
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
// Handles properties
|
|
313
|
-
if (mergedSchemas.properties !== undefined) {
|
|
314
|
-
return [
|
|
315
|
-
createOpeningArrayBracket(),
|
|
316
|
-
createProperties(mergedSchemas),
|
|
317
|
-
createClosingArrayBracket(),
|
|
318
|
-
].flat();
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
if (
|
|
323
|
-
schema.items?.type === "string" ||
|
|
324
|
-
schema.items?.type === "number" ||
|
|
325
|
-
schema.items?.type === "integer" ||
|
|
326
|
-
schema.items?.type === "boolean" ||
|
|
327
|
-
schema.items?.type === "object"
|
|
328
|
-
) {
|
|
329
|
-
return [
|
|
330
|
-
createOpeningArrayBracket(),
|
|
331
|
-
createNodes(schema.items),
|
|
332
|
-
createClosingArrayBracket(),
|
|
333
|
-
].flat();
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
// TODO: clean this up or eliminate it?
|
|
337
|
-
return [
|
|
338
|
-
createOpeningArrayBracket(),
|
|
339
|
-
Object.entries(schema.items!).map(([key, val]) =>
|
|
340
|
-
createEdges({
|
|
341
|
-
name: key,
|
|
342
|
-
schema: val,
|
|
343
|
-
required: Array.isArray(schema.required)
|
|
344
|
-
? schema.required.includes(key)
|
|
345
|
-
: false,
|
|
346
|
-
})
|
|
347
|
-
),
|
|
348
|
-
createClosingArrayBracket(),
|
|
349
|
-
].flat();
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* For handling discriminators that do not map to a same-level property
|
|
354
|
-
*/
|
|
355
|
-
// function createDiscriminator(schema: SchemaObject) {
|
|
356
|
-
// const discriminator = schema.discriminator;
|
|
357
|
-
// const propertyName = discriminator?.propertyName;
|
|
358
|
-
// const propertyType = "string"; // should always be string
|
|
359
|
-
// const mapping: any = discriminator?.mapping;
|
|
360
|
-
|
|
361
|
-
// // Explicit mapping is required since we can't support implicit
|
|
362
|
-
// if (mapping === undefined) {
|
|
363
|
-
// return undefined;
|
|
364
|
-
// }
|
|
365
|
-
|
|
366
|
-
// // Attempt to get the property description we want to display
|
|
367
|
-
// // TODO: how to make it predictable when handling allOf
|
|
368
|
-
// let propertyDescription;
|
|
369
|
-
// const firstMappingSchema = mapping[Object.keys(mapping)[0]];
|
|
370
|
-
// if (firstMappingSchema.properties !== undefined) {
|
|
371
|
-
// propertyDescription =
|
|
372
|
-
// firstMappingSchema.properties![propertyName!].description;
|
|
373
|
-
// }
|
|
374
|
-
// if (firstMappingSchema.allOf !== undefined) {
|
|
375
|
-
// const { mergedSchemas }: { mergedSchemas: SchemaObject } = mergeAllOf(
|
|
376
|
-
// firstMappingSchema.allOf
|
|
377
|
-
// );
|
|
378
|
-
// if (mergedSchemas.properties !== undefined) {
|
|
379
|
-
// propertyDescription =
|
|
380
|
-
// mergedSchemas.properties[propertyName!]?.description;
|
|
381
|
-
// }
|
|
382
|
-
// }
|
|
383
|
-
|
|
384
|
-
// if (propertyDescription === undefined) {
|
|
385
|
-
// if (
|
|
386
|
-
// schema.properties !== undefined &&
|
|
387
|
-
// schema.properties![propertyName!] !== undefined
|
|
388
|
-
// ) {
|
|
389
|
-
// propertyDescription = schema.properties![propertyName!].description;
|
|
390
|
-
// }
|
|
391
|
-
// }
|
|
392
|
-
|
|
393
|
-
// return create("div", {
|
|
394
|
-
// className: "openapi-discriminator__item",
|
|
395
|
-
// children: create("div", {
|
|
396
|
-
// children: [
|
|
397
|
-
// create("strong", {
|
|
398
|
-
// style: { paddingLeft: "1rem" },
|
|
399
|
-
// children: propertyName,
|
|
400
|
-
// }),
|
|
401
|
-
// guard(propertyType, (name) =>
|
|
402
|
-
// create("span", {
|
|
403
|
-
// style: { opacity: "0.6" },
|
|
404
|
-
// children: ` ${propertyType}`,
|
|
405
|
-
// })
|
|
406
|
-
// ),
|
|
407
|
-
// guard(getQualifierMessage(schema.discriminator as any), (message) =>
|
|
408
|
-
// create("div", {
|
|
409
|
-
// style: {
|
|
410
|
-
// paddingLeft: "1rem",
|
|
411
|
-
// },
|
|
412
|
-
// children: createDescription(message),
|
|
413
|
-
// })
|
|
414
|
-
// ),
|
|
415
|
-
// guard(propertyDescription, (description) =>
|
|
416
|
-
// create("div", {
|
|
417
|
-
// style: {
|
|
418
|
-
// paddingLeft: "1rem",
|
|
419
|
-
// },
|
|
420
|
-
// children: createDescription(description),
|
|
421
|
-
// })
|
|
422
|
-
// ),
|
|
423
|
-
// create("DiscriminatorTabs", {
|
|
424
|
-
// children: Object.keys(mapping!).map((key, index) => {
|
|
425
|
-
// if (mapping[key].allOf !== undefined) {
|
|
426
|
-
// const { mergedSchemas }: { mergedSchemas: SchemaObject } =
|
|
427
|
-
// mergeAllOf(mapping[key].allOf);
|
|
428
|
-
// // Cleanup duplicate property from mapping schema
|
|
429
|
-
// delete mergedSchemas.properties![propertyName!];
|
|
430
|
-
// mapping[key] = mergedSchemas;
|
|
431
|
-
// }
|
|
432
|
-
|
|
433
|
-
// if (mapping[key].properties !== undefined) {
|
|
434
|
-
// // Cleanup duplicate property from mapping schema
|
|
435
|
-
// delete mapping[key].properties![propertyName!];
|
|
436
|
-
// }
|
|
437
|
-
|
|
438
|
-
// const label = key;
|
|
439
|
-
// return create("TabItem", {
|
|
440
|
-
// label: label,
|
|
441
|
-
// value: `${index}-item-discriminator`,
|
|
442
|
-
// children: [
|
|
443
|
-
// create("div", {
|
|
444
|
-
// style: { marginLeft: "-4px" },
|
|
445
|
-
// children: createNodes(mapping[key]),
|
|
446
|
-
// }),
|
|
447
|
-
// ],
|
|
448
|
-
// });
|
|
449
|
-
// }),
|
|
450
|
-
// }),
|
|
451
|
-
// ],
|
|
452
|
-
// }),
|
|
453
|
-
// });
|
|
454
|
-
// }
|
|
455
|
-
|
|
456
|
-
function createDetailsNode(
|
|
457
|
-
name: string,
|
|
458
|
-
schemaName: string,
|
|
459
|
-
schema: SchemaObject,
|
|
460
|
-
required: string[] | boolean,
|
|
461
|
-
nullable: boolean | unknown
|
|
462
|
-
): any {
|
|
463
|
-
return create("SchemaItem", {
|
|
464
|
-
collapsible: true,
|
|
465
|
-
className: "schemaItem",
|
|
466
|
-
children: [
|
|
467
|
-
createDetails({
|
|
468
|
-
className: "openapi-markdown__details",
|
|
469
|
-
children: [
|
|
470
|
-
createDetailsSummary({
|
|
471
|
-
children: [
|
|
472
|
-
create("strong", { children: name }),
|
|
473
|
-
create("span", {
|
|
474
|
-
style: { opacity: "0.6" },
|
|
475
|
-
children: ` ${schemaName}`,
|
|
476
|
-
}),
|
|
477
|
-
guard(
|
|
478
|
-
(schema.nullable && schema.nullable === true) ||
|
|
479
|
-
(nullable && nullable === true),
|
|
480
|
-
() => [
|
|
481
|
-
create("strong", {
|
|
482
|
-
style: {
|
|
483
|
-
fontSize: "var(--ifm-code-font-size)",
|
|
484
|
-
color: "var(--openapi-nullable)",
|
|
485
|
-
},
|
|
486
|
-
children: " nullable",
|
|
487
|
-
}),
|
|
488
|
-
]
|
|
489
|
-
),
|
|
490
|
-
guard(
|
|
491
|
-
Array.isArray(required)
|
|
492
|
-
? required.includes(name)
|
|
493
|
-
: required === true,
|
|
494
|
-
() => [
|
|
495
|
-
create("strong", {
|
|
496
|
-
style: {
|
|
497
|
-
fontSize: "var(--ifm-code-font-size)",
|
|
498
|
-
color: "var(--openapi-required)",
|
|
499
|
-
},
|
|
500
|
-
children: " required",
|
|
501
|
-
}),
|
|
502
|
-
]
|
|
503
|
-
),
|
|
504
|
-
],
|
|
505
|
-
}),
|
|
506
|
-
create("div", {
|
|
507
|
-
style: { marginLeft: "1rem" },
|
|
508
|
-
children: [
|
|
509
|
-
guard(getQualifierMessage(schema), (message) =>
|
|
510
|
-
create("div", {
|
|
511
|
-
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
512
|
-
children: createDescription(message),
|
|
513
|
-
})
|
|
514
|
-
),
|
|
515
|
-
guard(schema.description, (description) =>
|
|
516
|
-
create("div", {
|
|
517
|
-
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
518
|
-
children: createDescription(description),
|
|
519
|
-
})
|
|
520
|
-
),
|
|
521
|
-
createNodes(schema),
|
|
522
|
-
],
|
|
523
|
-
}),
|
|
524
|
-
],
|
|
525
|
-
}),
|
|
526
|
-
],
|
|
527
|
-
});
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
/**
|
|
531
|
-
* For handling discriminators that map to a same-level property (like 'petType').
|
|
532
|
-
* Note: These should only be encountered while iterating through properties.
|
|
533
|
-
*/
|
|
534
|
-
function createPropertyDiscriminator(
|
|
535
|
-
name: string,
|
|
536
|
-
schemaName: string,
|
|
537
|
-
schema: SchemaObject,
|
|
538
|
-
discriminator: any,
|
|
539
|
-
required: string[] | boolean
|
|
540
|
-
): any {
|
|
541
|
-
if (schema === undefined) {
|
|
542
|
-
return undefined;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
if (discriminator.mapping === undefined) {
|
|
546
|
-
return undefined;
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
return create("div", {
|
|
550
|
-
className: "openapi-discriminator__item",
|
|
551
|
-
children: create("div", {
|
|
552
|
-
children: [
|
|
553
|
-
create("strong", { style: { paddingLeft: "1rem" }, children: name }),
|
|
554
|
-
guard(schemaName, (name) =>
|
|
555
|
-
create("span", {
|
|
556
|
-
style: { opacity: "0.6" },
|
|
557
|
-
children: ` ${schemaName}`,
|
|
558
|
-
})
|
|
559
|
-
),
|
|
560
|
-
guard(required, () => [
|
|
561
|
-
create("strong", {
|
|
562
|
-
style: {
|
|
563
|
-
fontSize: "var(--ifm-code-font-size)",
|
|
564
|
-
color: "var(--openapi-required)",
|
|
565
|
-
},
|
|
566
|
-
children: " required",
|
|
567
|
-
}),
|
|
568
|
-
]),
|
|
569
|
-
guard(getQualifierMessage(discriminator), (message) =>
|
|
570
|
-
create("div", {
|
|
571
|
-
style: {
|
|
572
|
-
paddingLeft: "1rem",
|
|
573
|
-
},
|
|
574
|
-
children: createDescription(message),
|
|
575
|
-
})
|
|
576
|
-
),
|
|
577
|
-
guard(schema.description, (description) =>
|
|
578
|
-
create("div", {
|
|
579
|
-
style: {
|
|
580
|
-
paddingLeft: "1rem",
|
|
581
|
-
},
|
|
582
|
-
children: createDescription(description),
|
|
583
|
-
})
|
|
584
|
-
),
|
|
585
|
-
create("DiscriminatorTabs", {
|
|
586
|
-
className: "openapi-tabs__discriminator",
|
|
587
|
-
children: Object.keys(discriminator?.mapping!).map((key, index) => {
|
|
588
|
-
const label = key;
|
|
589
|
-
return create("TabItem", {
|
|
590
|
-
// className: "openapi-tabs__discriminator-item",
|
|
591
|
-
label: label,
|
|
592
|
-
value: `${index}-item-discriminator`,
|
|
593
|
-
children: [createNodes(discriminator?.mapping[key])],
|
|
594
|
-
});
|
|
595
|
-
}),
|
|
596
|
-
}),
|
|
597
|
-
],
|
|
598
|
-
}),
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
interface EdgeProps {
|
|
603
|
-
name: string;
|
|
604
|
-
schema: SchemaObject;
|
|
605
|
-
required: string[] | boolean;
|
|
606
|
-
discriminator?: any | unknown;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
/**
|
|
610
|
-
* Creates the edges or "leaves" of a schema tree. Edges can branch into sub-nodes with createDetails().
|
|
611
|
-
*/
|
|
612
|
-
function createEdges({
|
|
613
|
-
name,
|
|
614
|
-
schema,
|
|
615
|
-
required,
|
|
616
|
-
discriminator,
|
|
617
|
-
}: EdgeProps): any {
|
|
618
|
-
const schemaName = getSchemaName(schema);
|
|
619
|
-
|
|
620
|
-
if (discriminator !== undefined && discriminator.propertyName === name) {
|
|
621
|
-
return createPropertyDiscriminator(
|
|
622
|
-
name,
|
|
623
|
-
"string",
|
|
624
|
-
schema,
|
|
625
|
-
discriminator,
|
|
626
|
-
required
|
|
627
|
-
);
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
631
|
-
return createDetailsNode(
|
|
632
|
-
name,
|
|
633
|
-
schemaName,
|
|
634
|
-
schema,
|
|
635
|
-
required,
|
|
636
|
-
schema.nullable
|
|
637
|
-
);
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
if (schema.allOf !== undefined) {
|
|
641
|
-
const {
|
|
642
|
-
mergedSchemas,
|
|
643
|
-
required,
|
|
644
|
-
}: { mergedSchemas: SchemaObject; required: string[] | boolean } =
|
|
645
|
-
mergeAllOf(schema.allOf);
|
|
646
|
-
const mergedSchemaName = getSchemaName(mergedSchemas);
|
|
647
|
-
|
|
648
|
-
if (
|
|
649
|
-
mergedSchemas.oneOf !== undefined ||
|
|
650
|
-
mergedSchemas.anyOf !== undefined
|
|
651
|
-
) {
|
|
652
|
-
return createDetailsNode(
|
|
653
|
-
name,
|
|
654
|
-
mergedSchemaName,
|
|
655
|
-
mergedSchemas,
|
|
656
|
-
required,
|
|
657
|
-
schema.nullable
|
|
658
|
-
);
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
if (mergedSchemas.properties !== undefined) {
|
|
662
|
-
return createDetailsNode(
|
|
663
|
-
name,
|
|
664
|
-
mergedSchemaName,
|
|
665
|
-
mergedSchemas,
|
|
666
|
-
required,
|
|
667
|
-
schema.nullable
|
|
668
|
-
);
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
if (mergedSchemas.additionalProperties !== undefined) {
|
|
672
|
-
return createDetailsNode(
|
|
673
|
-
name,
|
|
674
|
-
mergedSchemaName,
|
|
675
|
-
mergedSchemas,
|
|
676
|
-
required,
|
|
677
|
-
schema.nullable
|
|
678
|
-
);
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
// array of objects
|
|
682
|
-
if (mergedSchemas.items?.properties !== undefined) {
|
|
683
|
-
return createDetailsNode(
|
|
684
|
-
name,
|
|
685
|
-
mergedSchemaName,
|
|
686
|
-
mergedSchemas,
|
|
687
|
-
required,
|
|
688
|
-
schema.nullable
|
|
689
|
-
);
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
|
|
693
|
-
return undefined;
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
return create("SchemaItem", {
|
|
697
|
-
collapsible: false,
|
|
698
|
-
name,
|
|
699
|
-
required: Array.isArray(required) ? required.includes(name) : required,
|
|
700
|
-
schemaName: schemaName,
|
|
701
|
-
qualifierMessage: getQualifierMessage(schema),
|
|
702
|
-
schema: mergedSchemas,
|
|
703
|
-
});
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
if (schema.properties !== undefined) {
|
|
707
|
-
return createDetailsNode(
|
|
708
|
-
name,
|
|
709
|
-
schemaName,
|
|
710
|
-
schema,
|
|
711
|
-
required,
|
|
712
|
-
schema.nullable
|
|
713
|
-
);
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
if (schema.additionalProperties !== undefined) {
|
|
717
|
-
return createDetailsNode(
|
|
718
|
-
name,
|
|
719
|
-
schemaName,
|
|
720
|
-
schema,
|
|
721
|
-
required,
|
|
722
|
-
schema.nullable
|
|
723
|
-
);
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
// array of objects
|
|
727
|
-
if (schema.items?.properties !== undefined) {
|
|
728
|
-
return createDetailsNode(
|
|
729
|
-
name,
|
|
730
|
-
schemaName,
|
|
731
|
-
schema,
|
|
732
|
-
required,
|
|
733
|
-
schema.nullable
|
|
734
|
-
);
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
if (schema.items?.anyOf !== undefined || schema.items?.oneOf !== undefined) {
|
|
738
|
-
return createDetailsNode(
|
|
739
|
-
name,
|
|
740
|
-
schemaName,
|
|
741
|
-
schema,
|
|
742
|
-
required,
|
|
743
|
-
schema.nullable
|
|
744
|
-
);
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
if (schema.readOnly && schema.readOnly === true) {
|
|
748
|
-
return undefined;
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
// primitives and array of non-objects
|
|
752
|
-
return create("SchemaItem", {
|
|
753
|
-
collapsible: false,
|
|
754
|
-
name,
|
|
755
|
-
required: Array.isArray(required) ? required.includes(name) : required,
|
|
756
|
-
schemaName: schemaName,
|
|
757
|
-
qualifierMessage: getQualifierMessage(schema),
|
|
758
|
-
schema: schema,
|
|
759
|
-
});
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
/**
|
|
763
|
-
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
764
|
-
*/
|
|
765
|
-
function createNodes(schema: SchemaObject): any {
|
|
766
|
-
const nodes = [];
|
|
767
|
-
// if (schema.discriminator !== undefined) {
|
|
768
|
-
// return createDiscriminator(schema);
|
|
769
|
-
// }
|
|
770
|
-
|
|
771
|
-
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
772
|
-
nodes.push(createAnyOneOf(schema));
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
if (schema.allOf !== undefined) {
|
|
776
|
-
const { mergedSchemas } = mergeAllOf(schema.allOf);
|
|
777
|
-
|
|
778
|
-
// allOf seems to always result in properties
|
|
779
|
-
if (mergedSchemas.properties !== undefined) {
|
|
780
|
-
nodes.push(createProperties(mergedSchemas));
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
if (schema.properties !== undefined) {
|
|
785
|
-
nodes.push(createProperties(schema));
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
if (schema.additionalProperties !== undefined) {
|
|
789
|
-
nodes.push(createAdditionalProperties(schema));
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
// TODO: figure out how to handle array of objects
|
|
793
|
-
if (schema.items !== undefined) {
|
|
794
|
-
nodes.push(createItems(schema));
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
if (nodes.length && nodes.length > 0) {
|
|
798
|
-
return nodes.filter(Boolean).flat();
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
// primitive
|
|
802
|
-
if (schema.type !== undefined) {
|
|
803
|
-
return create("li", {
|
|
804
|
-
children: create("div", {
|
|
805
|
-
children: [
|
|
806
|
-
create("strong", { children: schema.type }),
|
|
807
|
-
guard(schema.format, (format) =>
|
|
808
|
-
create("span", {
|
|
809
|
-
style: { opacity: "0.6" },
|
|
810
|
-
children: ` ${format}`,
|
|
811
|
-
})
|
|
812
|
-
),
|
|
813
|
-
guard(getQualifierMessage(schema), (message) =>
|
|
814
|
-
create("div", {
|
|
815
|
-
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
816
|
-
children: createDescription(message),
|
|
817
|
-
})
|
|
818
|
-
),
|
|
819
|
-
guard(schema.description, (description) =>
|
|
820
|
-
create("div", {
|
|
821
|
-
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
822
|
-
children: createDescription(description),
|
|
823
|
-
})
|
|
824
|
-
),
|
|
825
|
-
],
|
|
826
|
-
}),
|
|
827
|
-
});
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
// Unknown node/schema type should return undefined
|
|
831
|
-
// So far, haven't seen this hit in testing
|
|
832
|
-
return "any";
|
|
833
|
-
}
|
|
834
|
-
|
|
835
15
|
interface Props {
|
|
836
16
|
style?: any;
|
|
837
17
|
title: string;
|
|
@@ -876,22 +56,23 @@ export function createRequestSchema({ title, body, ...rest }: Props) {
|
|
|
876
56
|
value: `${mimeType}`,
|
|
877
57
|
children: [
|
|
878
58
|
createDetails({
|
|
879
|
-
className: "openapi-markdown__details",
|
|
59
|
+
className: "openapi-markdown__details mime",
|
|
880
60
|
"data-collapsed": false,
|
|
881
61
|
open: true,
|
|
882
62
|
...rest,
|
|
883
63
|
children: [
|
|
884
64
|
createDetailsSummary({
|
|
885
|
-
|
|
65
|
+
className: "openapi-markdown__details-summary-mime",
|
|
886
66
|
children: [
|
|
887
|
-
create("
|
|
67
|
+
create("h3", {
|
|
68
|
+
className:
|
|
69
|
+
"openapi-markdown__details-summary-header-body",
|
|
70
|
+
children: `${title}`,
|
|
71
|
+
}),
|
|
888
72
|
guard(body.required && body.required === true, () => [
|
|
889
|
-
create("
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
color: "var(--openapi-required)",
|
|
893
|
-
},
|
|
894
|
-
children: " required",
|
|
73
|
+
create("span", {
|
|
74
|
+
className: "openapi-schema__required",
|
|
75
|
+
children: "required",
|
|
895
76
|
}),
|
|
896
77
|
]),
|
|
897
78
|
],
|
|
@@ -941,15 +122,18 @@ export function createRequestSchema({ title, body, ...rest }: Props) {
|
|
|
941
122
|
value: `${randomFirstKey}-schema`,
|
|
942
123
|
children: [
|
|
943
124
|
createDetails({
|
|
944
|
-
className: "openapi-markdown__details",
|
|
125
|
+
className: "openapi-markdown__details mime",
|
|
945
126
|
"data-collapsed": false,
|
|
946
127
|
open: true,
|
|
947
128
|
...rest,
|
|
948
129
|
children: [
|
|
949
130
|
createDetailsSummary({
|
|
950
|
-
|
|
131
|
+
className: "openapi-markdown__details-summary-mime",
|
|
951
132
|
children: [
|
|
952
|
-
create("
|
|
133
|
+
create("h3", {
|
|
134
|
+
className: "openapi-markdown__details-summary-header-body",
|
|
135
|
+
children: `${title}`,
|
|
136
|
+
}),
|
|
953
137
|
guard(firstBody.type === "array", (format) =>
|
|
954
138
|
create("span", {
|
|
955
139
|
style: { opacity: "0.6" },
|
|
@@ -958,11 +142,8 @@ export function createRequestSchema({ title, body, ...rest }: Props) {
|
|
|
958
142
|
),
|
|
959
143
|
guard(body.required, () => [
|
|
960
144
|
create("strong", {
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
color: "var(--openapi-required)",
|
|
964
|
-
},
|
|
965
|
-
children: " required",
|
|
145
|
+
className: "openapi-schema__required",
|
|
146
|
+
children: "required",
|
|
966
147
|
}),
|
|
967
148
|
]),
|
|
968
149
|
],
|