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