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