docusaurus-plugin-openapi-docs 0.0.0-395 → 0.0.0-398
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/markdown/createSchemaDetails.js +322 -148
- package/lib/markdown/schema.js +25 -9
- package/lib/openapi/openapi.d.ts +3 -3
- package/lib/openapi/openapi.js +26 -25
- package/lib/openapi/types.d.ts +2 -1
- package/lib/openapi/utils/loadAndResolveSpec.d.ts +2 -0
- package/lib/openapi/utils/{loadAndBundleSpec.js → loadAndResolveSpec.js} +61 -28
- package/package.json +2 -2
- package/src/markdown/createSchemaDetails.ts +398 -175
- package/src/markdown/schema.ts +28 -8
- package/src/openapi/openapi.ts +38 -37
- package/src/openapi/types.ts +2 -1
- package/src/openapi/utils/loadAndResolveSpec.ts +123 -0
- package/lib/markdown/createAnyOneOf.d.ts +0 -1
- package/lib/markdown/createAnyOneOf.js +0 -84
- package/lib/openapi/utils/loadAndBundleSpec.d.ts +0 -3
- package/src/markdown/createAnyOneOf.ts +0 -88
- package/src/openapi/utils/loadAndBundleSpec.ts +0 -93
|
@@ -7,17 +7,17 @@
|
|
|
7
7
|
* ========================================================================== */
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createSchemaDetails = void 0;
|
|
10
|
-
const createAnyOneOf_1 = require("./createAnyOneOf");
|
|
11
10
|
const createDescription_1 = require("./createDescription");
|
|
12
11
|
const createDetails_1 = require("./createDetails");
|
|
13
12
|
const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
14
13
|
const schema_1 = require("./schema");
|
|
15
14
|
const utils_1 = require("./utils");
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
|
|
16
|
+
/**
|
|
17
|
+
* Returns a merged representation of allOf array of schemas.
|
|
18
|
+
*/
|
|
19
|
+
function mergeAllOf(allOf) {
|
|
20
|
+
const mergedSchemas = jsonSchemaMergeAllOf(allOf, {
|
|
21
21
|
resolvers: {
|
|
22
22
|
readOnly: function () {
|
|
23
23
|
return true;
|
|
@@ -27,9 +27,6 @@ function resolveAllOf(allOf) {
|
|
|
27
27
|
},
|
|
28
28
|
},
|
|
29
29
|
});
|
|
30
|
-
if (mergedSchemas.properties) {
|
|
31
|
-
properties = mergedSchemas.properties;
|
|
32
|
-
}
|
|
33
30
|
const required = allOf.reduce((acc, cur) => {
|
|
34
31
|
if (Array.isArray(cur.required)) {
|
|
35
32
|
const next = [...acc, ...cur.required];
|
|
@@ -37,171 +34,344 @@ function resolveAllOf(allOf) {
|
|
|
37
34
|
}
|
|
38
35
|
return acc;
|
|
39
36
|
}, []);
|
|
40
|
-
return {
|
|
37
|
+
return { mergedSchemas, required };
|
|
41
38
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
39
|
+
/**
|
|
40
|
+
* For handling nested anyOf/oneOf.
|
|
41
|
+
*/
|
|
42
|
+
function createAnyOneOf(schema) {
|
|
43
|
+
const type = schema.oneOf ? "oneOf" : "anyOf";
|
|
44
|
+
return (0, utils_1.create)("li", {
|
|
45
|
+
children: [
|
|
46
|
+
(0, utils_1.create)("div", {
|
|
47
|
+
children: [
|
|
48
|
+
(0, utils_1.create)("span", {
|
|
49
|
+
className: "badge badge--info",
|
|
50
|
+
children: type,
|
|
51
|
+
}),
|
|
52
|
+
(0, utils_1.create)("SchemaTabs", {
|
|
53
|
+
children: schema[type].map((anyOneSchema, index) => {
|
|
54
|
+
const label = anyOneSchema.title
|
|
55
|
+
? anyOneSchema.title
|
|
56
|
+
: `MOD${index + 1}`;
|
|
57
|
+
const anyOneChildren = [];
|
|
58
|
+
if (anyOneSchema.properties !== undefined) {
|
|
59
|
+
anyOneChildren.push(createProperties(anyOneSchema));
|
|
60
|
+
}
|
|
61
|
+
if (anyOneSchema.allOf !== undefined) {
|
|
62
|
+
anyOneChildren.push(createNodes(anyOneSchema));
|
|
63
|
+
}
|
|
64
|
+
if (anyOneSchema.items !== undefined) {
|
|
65
|
+
anyOneChildren.push(createItems(anyOneSchema));
|
|
66
|
+
}
|
|
67
|
+
if (anyOneSchema.type === "string" ||
|
|
68
|
+
anyOneSchema.type === "number" ||
|
|
69
|
+
anyOneSchema.type === "integer" ||
|
|
70
|
+
anyOneSchema.type === "boolean") {
|
|
71
|
+
anyOneChildren.push(createNodes(anyOneSchema));
|
|
72
|
+
}
|
|
73
|
+
if (anyOneChildren.length) {
|
|
74
|
+
return (0, utils_1.create)("TabItem", {
|
|
75
|
+
label: label,
|
|
76
|
+
value: `${index}-item-properties`,
|
|
77
|
+
children: anyOneChildren,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
82
81
|
}),
|
|
82
|
+
}),
|
|
83
|
+
],
|
|
84
|
+
}),
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function createProperties(schema) {
|
|
89
|
+
return Object.entries(schema.properties).map(([key, val]) => createEdges({
|
|
90
|
+
name: key,
|
|
91
|
+
schema: val,
|
|
92
|
+
required: Array.isArray(schema.required)
|
|
93
|
+
? schema.required.includes(key)
|
|
94
|
+
: false,
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
function createAdditionalProperties(schema) {
|
|
98
|
+
// TODO?:
|
|
99
|
+
// {
|
|
100
|
+
// description: 'Integration configuration. See \n' +
|
|
101
|
+
// '[Integration Configurations](https://prisma.pan.dev/api/cloud/api-integration-config/).\n',
|
|
102
|
+
// example: { webhookUrl: 'https://hooks.slack.com/abcdef' },
|
|
103
|
+
// externalDocs: { url: 'https://prisma.pan.dev/api/cloud/api-integration-config' },
|
|
104
|
+
// type: 'object'
|
|
105
|
+
// }
|
|
106
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
107
|
+
// TODO?:
|
|
108
|
+
// {
|
|
109
|
+
// items: {
|
|
110
|
+
// properties: {
|
|
111
|
+
// aliasField: [Object],
|
|
112
|
+
// displayName: [Object],
|
|
113
|
+
// fieldName: [Object],
|
|
114
|
+
// maxLength: [Object],
|
|
115
|
+
// options: [Object],
|
|
116
|
+
// redlockMapping: [Object],
|
|
117
|
+
// required: [Object],
|
|
118
|
+
// type: [Object],
|
|
119
|
+
// typeaheadUri: [Object],
|
|
120
|
+
// value: [Object]
|
|
121
|
+
// },
|
|
122
|
+
// type: 'object'
|
|
123
|
+
// },
|
|
124
|
+
// type: 'array'
|
|
125
|
+
// }
|
|
126
|
+
if (((_a = schema.additionalProperties) === null || _a === void 0 ? void 0 : _a.type) === "string" ||
|
|
127
|
+
((_b = schema.additionalProperties) === null || _b === void 0 ? void 0 : _b.type) === "object" ||
|
|
128
|
+
((_c = schema.additionalProperties) === null || _c === void 0 ? void 0 : _c.type) === "boolean" ||
|
|
129
|
+
((_d = schema.additionalProperties) === null || _d === void 0 ? void 0 : _d.type) === "integer" ||
|
|
130
|
+
((_e = schema.additionalProperties) === null || _e === void 0 ? void 0 : _e.type) === "number") {
|
|
131
|
+
const type = (_f = schema.additionalProperties) === null || _f === void 0 ? void 0 : _f.type;
|
|
132
|
+
const additionalProperties = (_g = schema.additionalProperties) === null || _g === void 0 ? void 0 : _g.additionalProperties;
|
|
133
|
+
if (additionalProperties !== undefined) {
|
|
134
|
+
const type = (_j = (_h = schema.additionalProperties) === null || _h === void 0 ? void 0 : _h.additionalProperties) === null || _j === void 0 ? void 0 : _j.type;
|
|
135
|
+
const format = (_l = (_k = schema.additionalProperties) === null || _k === void 0 ? void 0 : _k.additionalProperties) === null || _l === void 0 ? void 0 : _l.format;
|
|
136
|
+
return (0, utils_1.create)("li", {
|
|
137
|
+
children: (0, utils_1.create)("div", {
|
|
138
|
+
children: [
|
|
139
|
+
(0, utils_1.create)("code", { children: `property name*` }),
|
|
140
|
+
(0, utils_1.guard)(type, (type) => (0, utils_1.create)("span", {
|
|
141
|
+
style: { opacity: "0.6" },
|
|
142
|
+
children: ` ${type}`,
|
|
143
|
+
})),
|
|
144
|
+
(0, utils_1.guard)(format, (format) => (0, utils_1.create)("span", {
|
|
145
|
+
style: { opacity: "0.6" },
|
|
146
|
+
children: ` (${format})`,
|
|
147
|
+
})),
|
|
148
|
+
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema.additionalProperties), (message) => (0, utils_1.create)("div", {
|
|
149
|
+
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
150
|
+
children: (0, createDescription_1.createDescription)(message),
|
|
151
|
+
})),
|
|
83
152
|
],
|
|
84
153
|
}),
|
|
85
|
-
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return (0, utils_1.create)("li", {
|
|
157
|
+
children: (0, utils_1.create)("div", {
|
|
158
|
+
children: [
|
|
159
|
+
(0, utils_1.create)("code", { children: `property name*` }),
|
|
160
|
+
(0, utils_1.guard)(type, (type) => (0, utils_1.create)("span", {
|
|
161
|
+
style: { opacity: "0.6" },
|
|
162
|
+
children: ` ${type}`,
|
|
163
|
+
})),
|
|
164
|
+
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema.additionalProperties), (message) => (0, utils_1.create)("div", {
|
|
165
|
+
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
166
|
+
children: (0, createDescription_1.createDescription)(message),
|
|
167
|
+
})),
|
|
168
|
+
],
|
|
169
|
+
}),
|
|
86
170
|
});
|
|
87
171
|
}
|
|
172
|
+
return Object.entries(schema.additionalProperties).map(([key, val]) => createEdges({
|
|
173
|
+
name: key,
|
|
174
|
+
schema: val,
|
|
175
|
+
required: Array.isArray(schema.required)
|
|
176
|
+
? schema.required.includes(key)
|
|
177
|
+
: false,
|
|
178
|
+
}));
|
|
179
|
+
}
|
|
180
|
+
// TODO: figure out how to handle array of objects
|
|
181
|
+
function createItems(schema) {
|
|
182
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
183
|
+
if (((_a = schema.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
|
|
184
|
+
return createProperties(schema.items);
|
|
185
|
+
}
|
|
186
|
+
if (((_b = schema.items) === null || _b === void 0 ? void 0 : _b.additionalProperties) !== undefined) {
|
|
187
|
+
return createAdditionalProperties(schema.items);
|
|
188
|
+
}
|
|
189
|
+
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) {
|
|
190
|
+
return createAnyOneOf(schema.items);
|
|
191
|
+
}
|
|
192
|
+
if (((_e = schema.items) === null || _e === void 0 ? void 0 : _e.allOf) !== undefined) {
|
|
193
|
+
const { mergedSchemas } = mergeAllOf((_f = schema.items) === null || _f === void 0 ? void 0 : _f.allOf);
|
|
194
|
+
// Handles combo anyOf/oneOf + properties
|
|
195
|
+
if ((mergedSchemas.oneOf !== undefined ||
|
|
196
|
+
mergedSchemas.anyOf !== undefined) &&
|
|
197
|
+
mergedSchemas.properties) {
|
|
198
|
+
return (0, utils_1.create)("div", {
|
|
199
|
+
children: [
|
|
200
|
+
createAnyOneOf(mergedSchemas),
|
|
201
|
+
createProperties(mergedSchemas),
|
|
202
|
+
],
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
// Handles only anyOf/oneOf
|
|
206
|
+
if (mergedSchemas.oneOf !== undefined ||
|
|
207
|
+
mergedSchemas.anyOf !== undefined) {
|
|
208
|
+
return (0, utils_1.create)("div", {
|
|
209
|
+
children: [
|
|
210
|
+
createAnyOneOf(mergedSchemas),
|
|
211
|
+
createProperties(mergedSchemas),
|
|
212
|
+
],
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (((_g = schema.items) === null || _g === void 0 ? void 0 : _g.type) === "string" ||
|
|
217
|
+
((_h = schema.items) === null || _h === void 0 ? void 0 : _h.type) === "number" ||
|
|
218
|
+
((_j = schema.items) === null || _j === void 0 ? void 0 : _j.type) === "integer" ||
|
|
219
|
+
((_k = schema.items) === null || _k === void 0 ? void 0 : _k.type) === "boolean") {
|
|
220
|
+
return createNodes(schema.items);
|
|
221
|
+
}
|
|
222
|
+
// TODO: clean this up or eliminate it?
|
|
223
|
+
return Object.entries(schema.items).map(([key, val]) => createEdges({
|
|
224
|
+
name: key,
|
|
225
|
+
schema: val,
|
|
226
|
+
required: Array.isArray(schema.required)
|
|
227
|
+
? schema.required.includes(key)
|
|
228
|
+
: false,
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
231
|
+
function createDetailsNode(name, schemaName, schema, required) {
|
|
88
232
|
return (0, utils_1.create)("SchemaItem", {
|
|
89
|
-
collapsible:
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
233
|
+
collapsible: true,
|
|
234
|
+
className: "schemaItem",
|
|
235
|
+
children: [
|
|
236
|
+
(0, createDetails_1.createDetails)({
|
|
237
|
+
children: [
|
|
238
|
+
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
239
|
+
children: [
|
|
240
|
+
(0, utils_1.create)("strong", { children: name }),
|
|
241
|
+
(0, utils_1.create)("span", {
|
|
242
|
+
style: { opacity: "0.6" },
|
|
243
|
+
children: ` ${schemaName}`,
|
|
244
|
+
}),
|
|
245
|
+
(0, utils_1.guard)(required, () => [
|
|
246
|
+
(0, utils_1.create)("strong", {
|
|
247
|
+
style: {
|
|
248
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
249
|
+
color: "var(--openapi-required)",
|
|
250
|
+
},
|
|
251
|
+
children: " required",
|
|
252
|
+
}),
|
|
253
|
+
]),
|
|
254
|
+
],
|
|
255
|
+
}),
|
|
256
|
+
(0, utils_1.create)("div", {
|
|
257
|
+
style: { marginLeft: "1rem" },
|
|
258
|
+
children: [
|
|
259
|
+
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
|
|
260
|
+
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
261
|
+
children: (0, createDescription_1.createDescription)(message),
|
|
262
|
+
})),
|
|
263
|
+
(0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
|
|
264
|
+
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
265
|
+
children: (0, createDescription_1.createDescription)(description),
|
|
266
|
+
})),
|
|
267
|
+
createNodes(schema),
|
|
268
|
+
],
|
|
269
|
+
}),
|
|
270
|
+
],
|
|
271
|
+
}),
|
|
272
|
+
],
|
|
95
273
|
});
|
|
96
274
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
? schema.required.includes(key)
|
|
106
|
-
: false,
|
|
107
|
-
})),
|
|
108
|
-
});
|
|
275
|
+
/**
|
|
276
|
+
* Creates the edges or "leaves" of a schema tree. Edges can branch into sub-nodes with createDetails().
|
|
277
|
+
*/
|
|
278
|
+
function createEdges({ name, schema, required }) {
|
|
279
|
+
var _a;
|
|
280
|
+
const schemaName = (0, schema_1.getSchemaName)(schema);
|
|
281
|
+
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
282
|
+
return createDetailsNode(name, schemaName, schema, required);
|
|
109
283
|
}
|
|
110
|
-
// TODO: This can be a bit complicated types can be missmatched and there can be nested allOfs which need to be resolved before merging properties
|
|
111
284
|
if (schema.allOf !== undefined) {
|
|
112
|
-
const {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
285
|
+
const { mergedSchemas, required, } = mergeAllOf(schema.allOf);
|
|
286
|
+
const mergedSchemaName = (0, schema_1.getSchemaName)(mergedSchemas);
|
|
287
|
+
if (mergedSchemas.oneOf !== undefined ||
|
|
288
|
+
mergedSchemas.anyOf !== undefined) {
|
|
289
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
|
|
290
|
+
}
|
|
291
|
+
if (mergedSchemas.properties !== undefined) {
|
|
292
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
|
|
293
|
+
}
|
|
294
|
+
if (mergedSchemas.additionalProperties !== undefined) {
|
|
295
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
|
|
296
|
+
}
|
|
297
|
+
return (0, utils_1.create)("SchemaItem", {
|
|
298
|
+
collapsible: false,
|
|
299
|
+
name,
|
|
300
|
+
required,
|
|
301
|
+
schemaDescription: mergedSchemas.description,
|
|
302
|
+
schemaName: schemaName,
|
|
303
|
+
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
126
304
|
});
|
|
127
305
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return (0, createAnyOneOf_1.createAnyOneOf)(schema.oneOf, "oneOf");
|
|
306
|
+
if (schema.properties !== undefined) {
|
|
307
|
+
return createDetailsNode(name, schemaName, schema, required);
|
|
131
308
|
}
|
|
132
|
-
if (schema.
|
|
133
|
-
return (
|
|
309
|
+
if (schema.additionalProperties !== undefined) {
|
|
310
|
+
return createDetailsNode(name, schemaName, schema, required);
|
|
134
311
|
}
|
|
135
|
-
// array
|
|
136
|
-
if (schema.items !== undefined) {
|
|
137
|
-
return
|
|
312
|
+
// array of objects
|
|
313
|
+
if (((_a = schema.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
|
|
314
|
+
return createDetailsNode(name, schemaName, schema, required);
|
|
138
315
|
}
|
|
139
|
-
//
|
|
140
|
-
return
|
|
316
|
+
// primitives and array of non-objects
|
|
317
|
+
return (0, utils_1.create)("SchemaItem", {
|
|
318
|
+
collapsible: false,
|
|
319
|
+
name,
|
|
320
|
+
required,
|
|
321
|
+
schemaDescription: schema.description,
|
|
322
|
+
schemaName: schemaName,
|
|
323
|
+
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
324
|
+
});
|
|
141
325
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
required: Array.isArray(schema.required)
|
|
149
|
-
? schema.required.includes(key)
|
|
150
|
-
: false,
|
|
151
|
-
}));
|
|
326
|
+
/**
|
|
327
|
+
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
328
|
+
*/
|
|
329
|
+
function createNodes(schema) {
|
|
330
|
+
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
331
|
+
return createAnyOneOf(schema);
|
|
152
332
|
}
|
|
153
|
-
// TODO: This can be a bit complicated types can be missmatched and there can be nested allOfs which need to be resolved before merging properties
|
|
154
333
|
if (schema.allOf !== undefined) {
|
|
155
|
-
const {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
style: { marginBottom: "1rem" },
|
|
161
|
-
children: "allOf",
|
|
162
|
-
}),
|
|
163
|
-
Object.entries(properties).map(([key, val]) => createRow({
|
|
164
|
-
name: key,
|
|
165
|
-
schema: val,
|
|
166
|
-
required: Array.isArray(required) ? required.includes(key) : false,
|
|
167
|
-
})),
|
|
168
|
-
],
|
|
169
|
-
});
|
|
334
|
+
const { mergedSchemas } = mergeAllOf(schema.allOf);
|
|
335
|
+
// allOf seems to always result in properties
|
|
336
|
+
if (mergedSchemas.properties !== undefined) {
|
|
337
|
+
return createProperties(mergedSchemas);
|
|
338
|
+
}
|
|
170
339
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return (0, createAnyOneOf_1.createAnyOneOf)(schema.oneOf, "oneOf");
|
|
340
|
+
if (schema.properties !== undefined) {
|
|
341
|
+
return createProperties(schema);
|
|
174
342
|
}
|
|
175
|
-
if (schema.
|
|
176
|
-
return (
|
|
343
|
+
if (schema.additionalProperties !== undefined) {
|
|
344
|
+
return createAdditionalProperties(schema);
|
|
177
345
|
}
|
|
178
|
-
// array
|
|
346
|
+
// TODO: figure out how to handle array of objects
|
|
179
347
|
if (schema.items !== undefined) {
|
|
348
|
+
return createItems(schema);
|
|
349
|
+
}
|
|
350
|
+
// primitive
|
|
351
|
+
if (schema.type !== undefined) {
|
|
180
352
|
return (0, utils_1.create)("li", {
|
|
181
353
|
children: (0, utils_1.create)("div", {
|
|
182
|
-
children: [
|
|
354
|
+
children: [
|
|
355
|
+
(0, utils_1.create)("strong", { children: schema.type }),
|
|
356
|
+
(0, utils_1.guard)(schema.format, (format) => (0, utils_1.create)("span", {
|
|
357
|
+
style: { opacity: "0.6" },
|
|
358
|
+
children: ` ${format}`,
|
|
359
|
+
})),
|
|
360
|
+
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
|
|
361
|
+
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
362
|
+
children: (0, createDescription_1.createDescription)(message),
|
|
363
|
+
})),
|
|
364
|
+
(0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
|
|
365
|
+
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
366
|
+
children: (0, createDescription_1.createDescription)(description),
|
|
367
|
+
})),
|
|
368
|
+
],
|
|
183
369
|
}),
|
|
184
370
|
});
|
|
185
371
|
}
|
|
186
|
-
//
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
children: [
|
|
190
|
-
(0, utils_1.create)("span", {
|
|
191
|
-
style: { opacity: "0.6" },
|
|
192
|
-
children: ` ${schema.type}`,
|
|
193
|
-
}),
|
|
194
|
-
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
|
|
195
|
-
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
196
|
-
children: (0, createDescription_1.createDescription)(message),
|
|
197
|
-
})),
|
|
198
|
-
(0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
|
|
199
|
-
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
200
|
-
children: (0, createDescription_1.createDescription)(description),
|
|
201
|
-
})),
|
|
202
|
-
],
|
|
203
|
-
}),
|
|
204
|
-
});
|
|
372
|
+
// Unknown node/schema type should return undefined
|
|
373
|
+
// So far, haven't seen this hit in testing
|
|
374
|
+
return undefined;
|
|
205
375
|
}
|
|
206
376
|
function createSchemaDetails({ title, body, ...rest }) {
|
|
207
377
|
if (body === undefined ||
|
|
@@ -210,7 +380,6 @@ function createSchemaDetails({ title, body, ...rest }) {
|
|
|
210
380
|
Object.keys(body.content).length === 0) {
|
|
211
381
|
return undefined;
|
|
212
382
|
}
|
|
213
|
-
// TODO:
|
|
214
383
|
// NOTE: We just pick a random content-type.
|
|
215
384
|
// How common is it to have multiple?
|
|
216
385
|
const randomFirstKey = Object.keys(body.content)[0];
|
|
@@ -224,6 +393,7 @@ function createSchemaDetails({ title, body, ...rest }) {
|
|
|
224
393
|
return undefined;
|
|
225
394
|
}
|
|
226
395
|
}
|
|
396
|
+
// Root-level schema dropdown
|
|
227
397
|
return (0, createDetails_1.createDetails)({
|
|
228
398
|
"data-collapsed": false,
|
|
229
399
|
open: true,
|
|
@@ -233,6 +403,10 @@ function createSchemaDetails({ title, body, ...rest }) {
|
|
|
233
403
|
style: { textAlign: "left" },
|
|
234
404
|
children: [
|
|
235
405
|
(0, utils_1.create)("strong", { children: `${title}` }),
|
|
406
|
+
(0, utils_1.guard)(firstBody.type === "array", (format) => (0, utils_1.create)("span", {
|
|
407
|
+
style: { opacity: "0.6" },
|
|
408
|
+
children: ` array`,
|
|
409
|
+
})),
|
|
236
410
|
(0, utils_1.guard)(body.required, () => [
|
|
237
411
|
(0, utils_1.create)("strong", {
|
|
238
412
|
style: {
|
|
@@ -257,7 +431,7 @@ function createSchemaDetails({ title, body, ...rest }) {
|
|
|
257
431
|
}),
|
|
258
432
|
(0, utils_1.create)("ul", {
|
|
259
433
|
style: { marginLeft: "1rem" },
|
|
260
|
-
children:
|
|
434
|
+
children: createNodes(firstBody),
|
|
261
435
|
}),
|
|
262
436
|
],
|
|
263
437
|
});
|
package/lib/markdown/schema.js
CHANGED
|
@@ -8,22 +8,34 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.getQualifierMessage = exports.getSchemaName = void 0;
|
|
10
10
|
function prettyName(schema, circular) {
|
|
11
|
-
var _a, _b, _c;
|
|
12
|
-
if (schema.$ref) {
|
|
13
|
-
return schema.$ref.replace("#/components/schemas/", "") + circular
|
|
14
|
-
? " (circular)"
|
|
15
|
-
: "";
|
|
16
|
-
}
|
|
11
|
+
var _a, _b, _c, _d, _e;
|
|
17
12
|
if (schema.format) {
|
|
18
13
|
return schema.format;
|
|
19
14
|
}
|
|
20
15
|
if (schema.allOf) {
|
|
16
|
+
if (typeof schema.allOf[0] === "string") {
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
if (schema.allOf[0].includes("circular")) {
|
|
19
|
+
return schema.allOf[0];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return "object";
|
|
23
|
+
}
|
|
24
|
+
if (schema.oneOf) {
|
|
25
|
+
return "object";
|
|
26
|
+
}
|
|
27
|
+
if (schema.anyOf) {
|
|
21
28
|
return "object";
|
|
22
29
|
}
|
|
23
30
|
if (schema.type === "object") {
|
|
24
31
|
return (_b = (_a = schema.xml) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : schema.type;
|
|
32
|
+
// return schema.type;
|
|
33
|
+
}
|
|
34
|
+
if (schema.type === "array") {
|
|
35
|
+
return (_d = (_c = schema.xml) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : schema.type;
|
|
36
|
+
// return schema.type;
|
|
25
37
|
}
|
|
26
|
-
return (
|
|
38
|
+
return (_e = schema.title) !== null && _e !== void 0 ? _e : schema.type;
|
|
27
39
|
}
|
|
28
40
|
function getSchemaName(schema, circular) {
|
|
29
41
|
var _a;
|
|
@@ -35,8 +47,6 @@ function getSchemaName(schema, circular) {
|
|
|
35
47
|
exports.getSchemaName = getSchemaName;
|
|
36
48
|
function getQualifierMessage(schema) {
|
|
37
49
|
// TODO:
|
|
38
|
-
// - maxItems
|
|
39
|
-
// - minItems
|
|
40
50
|
// - uniqueItems
|
|
41
51
|
// - maxProperties
|
|
42
52
|
// - minProperties
|
|
@@ -92,6 +102,12 @@ function getQualifierMessage(schema) {
|
|
|
92
102
|
if (schema.enum) {
|
|
93
103
|
qualifierGroups.push(`[${schema.enum.map((e) => `\`${e}\``).join(", ")}]`);
|
|
94
104
|
}
|
|
105
|
+
if (schema.minItems) {
|
|
106
|
+
qualifierGroups.push(`items >= ${schema.minItems}`);
|
|
107
|
+
}
|
|
108
|
+
if (schema.maxItems) {
|
|
109
|
+
qualifierGroups.push(`items <= ${schema.maxItems}`);
|
|
110
|
+
}
|
|
95
111
|
if (qualifierGroups.length === 0) {
|
|
96
112
|
return undefined;
|
|
97
113
|
}
|
package/lib/openapi/openapi.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ApiMetadata, APIOptions, SidebarOptions } from "../types";
|
|
2
|
-
import {
|
|
2
|
+
import { OpenApiObject, TagObject } from "./types";
|
|
3
3
|
interface OpenApiFiles {
|
|
4
4
|
source: string;
|
|
5
5
|
sourceDirName: string;
|
|
6
|
-
data:
|
|
6
|
+
data: OpenApiObject;
|
|
7
7
|
}
|
|
8
8
|
export declare function readOpenapiFiles(openapiPath: string, options: APIOptions): Promise<OpenApiFiles[]>;
|
|
9
9
|
export declare function processOpenapiFiles(files: OpenApiFiles[], sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[]]>;
|
|
10
|
-
export declare function processOpenapiFile(
|
|
10
|
+
export declare function processOpenapiFile(openapiData: OpenApiObject, sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[]]>;
|
|
11
11
|
export declare function getTagDisplayName(tagName: string, tags: TagObject[]): string;
|
|
12
12
|
export {};
|