docusaurus-plugin-openapi-docs 1.0.6 → 1.1.2
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 +1 -2
- package/lib/markdown/createSchemaDetails.js +325 -132
- package/lib/markdown/index.js +1 -0
- package/lib/markdown/schema.js +25 -9
- package/lib/markdown/utils.d.ts +1 -1
- package/lib/markdown/utils.js +4 -1
- package/lib/openapi/openapi.d.ts +3 -3
- package/lib/openapi/openapi.js +30 -26
- 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/lib/openapi/utils/services/OpenAPIParser.d.ts +52 -0
- package/lib/openapi/utils/services/OpenAPIParser.js +342 -0
- package/lib/openapi/utils/services/RedocNormalizedOptions.d.ts +100 -0
- package/lib/openapi/utils/services/RedocNormalizedOptions.js +170 -0
- package/lib/openapi/utils/types/index.d.ts +2 -0
- package/lib/openapi/utils/types/index.js +23 -0
- package/lib/openapi/utils/types/open-api.d.ts +305 -0
- package/lib/openapi/utils/types/open-api.js +8 -0
- package/lib/openapi/utils/utils/JsonPointer.d.ts +51 -0
- package/lib/openapi/utils/utils/JsonPointer.js +95 -0
- package/lib/openapi/utils/utils/helpers.d.ts +43 -0
- package/lib/openapi/utils/utils/helpers.js +230 -0
- package/lib/openapi/utils/utils/index.d.ts +3 -0
- package/lib/openapi/utils/utils/index.js +25 -0
- package/lib/openapi/utils/utils/openapi.d.ts +40 -0
- package/lib/openapi/utils/utils/openapi.js +605 -0
- package/lib/sidebars/index.js +5 -3
- package/package.json +15 -11
- package/src/markdown/createSchemaDetails.ts +405 -159
- package/src/markdown/index.ts +1 -0
- package/src/markdown/schema.ts +28 -8
- package/src/markdown/utils.ts +5 -2
- package/src/openapi/openapi.ts +42 -38
- package/src/openapi/types.ts +2 -1
- package/src/openapi/utils/loadAndResolveSpec.ts +123 -0
- package/src/openapi/utils/services/OpenAPIParser.ts +433 -0
- package/src/openapi/utils/services/RedocNormalizedOptions.ts +330 -0
- package/src/openapi/utils/types/index.ts +10 -0
- package/src/openapi/utils/types/open-api.ts +303 -0
- package/src/openapi/utils/utils/JsonPointer.ts +99 -0
- package/src/openapi/utils/utils/helpers.ts +239 -0
- package/src/openapi/utils/utils/index.ts +11 -0
- package/src/openapi/utils/utils/openapi.ts +771 -0
- package/src/sidebars/index.ts +7 -4
- package/lib/openapi/utils/loadAndBundleSpec.d.ts +0 -3
- package/src/openapi/utils/loadAndBundleSpec.ts +0 -93
|
@@ -12,12 +12,13 @@ import { createDetailsSummary } from "./createDetailsSummary";
|
|
|
12
12
|
import { getQualifierMessage, getSchemaName } from "./schema";
|
|
13
13
|
import { create, guard } from "./utils";
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Returns a merged representation of allOf array of schemas.
|
|
19
|
+
*/
|
|
20
|
+
function mergeAllOf(allOf: SchemaObject[]) {
|
|
21
|
+
const mergedSchemas = jsonSchemaMergeAllOf(allOf, {
|
|
21
22
|
resolvers: {
|
|
22
23
|
readOnly: function () {
|
|
23
24
|
return true;
|
|
@@ -28,205 +29,444 @@ function resolveAllOf(allOf: SchemaObject[]) {
|
|
|
28
29
|
},
|
|
29
30
|
});
|
|
30
31
|
|
|
31
|
-
if (mergedSchemas.properties) {
|
|
32
|
-
properties = mergedSchemas.properties;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
32
|
const required = allOf.reduce((acc, cur) => {
|
|
36
33
|
if (Array.isArray(cur.required)) {
|
|
37
34
|
const next = [...acc, ...cur.required];
|
|
38
35
|
return next;
|
|
39
36
|
}
|
|
40
37
|
return acc;
|
|
41
|
-
}, [] as
|
|
38
|
+
}, [] as any);
|
|
42
39
|
|
|
43
|
-
return {
|
|
40
|
+
return { mergedSchemas, required };
|
|
44
41
|
}
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
/**
|
|
44
|
+
* For handling nested anyOf/oneOf.
|
|
45
|
+
*/
|
|
46
|
+
function createAnyOneOf(schema: SchemaObject): any {
|
|
47
|
+
const type = schema.oneOf ? "oneOf" : "anyOf";
|
|
48
|
+
return create("li", {
|
|
49
|
+
children: [
|
|
50
|
+
create("div", {
|
|
51
|
+
children: [
|
|
52
|
+
create("span", {
|
|
53
|
+
className: "badge badge--info",
|
|
54
|
+
children: type,
|
|
55
|
+
}),
|
|
56
|
+
create("SchemaTabs", {
|
|
57
|
+
children: schema[type]!.map((anyOneSchema, index) => {
|
|
58
|
+
const label = anyOneSchema.title
|
|
59
|
+
? anyOneSchema.title
|
|
60
|
+
: `MOD${index + 1}`;
|
|
61
|
+
const anyOneChildren = [];
|
|
62
|
+
|
|
63
|
+
if (anyOneSchema.properties !== undefined) {
|
|
64
|
+
anyOneChildren.push(createProperties(anyOneSchema));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (anyOneSchema.allOf !== undefined) {
|
|
68
|
+
anyOneChildren.push(createNodes(anyOneSchema));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (anyOneSchema.items !== undefined) {
|
|
72
|
+
anyOneChildren.push(createItems(anyOneSchema));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (
|
|
76
|
+
anyOneSchema.type === "string" ||
|
|
77
|
+
anyOneSchema.type === "number" ||
|
|
78
|
+
anyOneSchema.type === "integer" ||
|
|
79
|
+
anyOneSchema.type === "boolean"
|
|
80
|
+
) {
|
|
81
|
+
anyOneChildren.push(createNodes(anyOneSchema));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (anyOneChildren.length) {
|
|
85
|
+
return create("TabItem", {
|
|
86
|
+
label: label,
|
|
87
|
+
value: `${index}-item-properties`,
|
|
88
|
+
children: anyOneChildren,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return undefined;
|
|
93
|
+
}),
|
|
94
|
+
}),
|
|
95
|
+
],
|
|
96
|
+
}),
|
|
97
|
+
],
|
|
98
|
+
});
|
|
50
99
|
}
|
|
51
100
|
|
|
52
|
-
function
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
101
|
+
function createProperties(schema: SchemaObject) {
|
|
102
|
+
return Object.entries(schema.properties!).map(([key, val]) =>
|
|
103
|
+
createEdges({
|
|
104
|
+
name: key,
|
|
105
|
+
schema: val,
|
|
106
|
+
required: Array.isArray(schema.required)
|
|
107
|
+
? schema.required.includes(key)
|
|
108
|
+
: false,
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function createAdditionalProperties(schema: SchemaObject) {
|
|
114
|
+
// TODO?:
|
|
115
|
+
// {
|
|
116
|
+
// description: 'Integration configuration. See \n' +
|
|
117
|
+
// '[Integration Configurations](https://prisma.pan.dev/api/cloud/api-integration-config/).\n',
|
|
118
|
+
// example: { webhookUrl: 'https://hooks.slack.com/abcdef' },
|
|
119
|
+
// externalDocs: { url: 'https://prisma.pan.dev/api/cloud/api-integration-config' },
|
|
120
|
+
// type: 'object'
|
|
121
|
+
// }
|
|
122
|
+
|
|
123
|
+
// TODO?:
|
|
124
|
+
// {
|
|
125
|
+
// items: {
|
|
126
|
+
// properties: {
|
|
127
|
+
// aliasField: [Object],
|
|
128
|
+
// displayName: [Object],
|
|
129
|
+
// fieldName: [Object],
|
|
130
|
+
// maxLength: [Object],
|
|
131
|
+
// options: [Object],
|
|
132
|
+
// redlockMapping: [Object],
|
|
133
|
+
// required: [Object],
|
|
134
|
+
// type: [Object],
|
|
135
|
+
// typeaheadUri: [Object],
|
|
136
|
+
// value: [Object]
|
|
137
|
+
// },
|
|
138
|
+
// type: 'object'
|
|
139
|
+
// },
|
|
140
|
+
// type: 'array'
|
|
141
|
+
// }
|
|
142
|
+
|
|
143
|
+
if (
|
|
144
|
+
schema.additionalProperties?.type === "string" ||
|
|
145
|
+
schema.additionalProperties?.type === "object" ||
|
|
146
|
+
schema.additionalProperties?.type === "boolean" ||
|
|
147
|
+
schema.additionalProperties?.type === "integer" ||
|
|
148
|
+
schema.additionalProperties?.type === "number"
|
|
149
|
+
) {
|
|
150
|
+
const type = schema.additionalProperties?.type;
|
|
151
|
+
const additionalProperties =
|
|
152
|
+
schema.additionalProperties?.additionalProperties;
|
|
153
|
+
if (additionalProperties !== undefined) {
|
|
154
|
+
const type = schema.additionalProperties?.additionalProperties?.type;
|
|
155
|
+
const format = schema.additionalProperties?.additionalProperties?.format;
|
|
156
|
+
return create("li", {
|
|
157
|
+
children: create("div", {
|
|
60
158
|
children: [
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
style: { marginLeft: "1rem" },
|
|
81
|
-
children: [
|
|
82
|
-
guard(getQualifierMessage(schema), (message) =>
|
|
83
|
-
create("div", {
|
|
84
|
-
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
85
|
-
children: createDescription(message),
|
|
86
|
-
})
|
|
87
|
-
),
|
|
88
|
-
guard(schema.description, (description) =>
|
|
89
|
-
create("div", {
|
|
90
|
-
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
91
|
-
children: createDescription(description),
|
|
92
|
-
})
|
|
93
|
-
),
|
|
94
|
-
createRows({ schema: schema }),
|
|
95
|
-
],
|
|
96
|
-
}),
|
|
159
|
+
create("code", { children: `property name*` }),
|
|
160
|
+
guard(type, (type) =>
|
|
161
|
+
create("span", {
|
|
162
|
+
style: { opacity: "0.6" },
|
|
163
|
+
children: ` ${type}`,
|
|
164
|
+
})
|
|
165
|
+
),
|
|
166
|
+
guard(format, (format) =>
|
|
167
|
+
create("span", {
|
|
168
|
+
style: { opacity: "0.6" },
|
|
169
|
+
children: ` (${format})`,
|
|
170
|
+
})
|
|
171
|
+
),
|
|
172
|
+
guard(getQualifierMessage(schema.additionalProperties), (message) =>
|
|
173
|
+
create("div", {
|
|
174
|
+
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
175
|
+
children: createDescription(message),
|
|
176
|
+
})
|
|
177
|
+
),
|
|
97
178
|
],
|
|
98
179
|
}),
|
|
99
|
-
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
return create("li", {
|
|
183
|
+
children: create("div", {
|
|
184
|
+
children: [
|
|
185
|
+
create("code", { children: `property name*` }),
|
|
186
|
+
guard(type, (type) =>
|
|
187
|
+
create("span", {
|
|
188
|
+
style: { opacity: "0.6" },
|
|
189
|
+
children: ` ${type}`,
|
|
190
|
+
})
|
|
191
|
+
),
|
|
192
|
+
guard(getQualifierMessage(schema.additionalProperties), (message) =>
|
|
193
|
+
create("div", {
|
|
194
|
+
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
195
|
+
children: createDescription(message),
|
|
196
|
+
})
|
|
197
|
+
),
|
|
198
|
+
],
|
|
199
|
+
}),
|
|
100
200
|
});
|
|
101
201
|
}
|
|
202
|
+
return Object.entries(schema.additionalProperties!).map(([key, val]) =>
|
|
203
|
+
createEdges({
|
|
204
|
+
name: key,
|
|
205
|
+
schema: val,
|
|
206
|
+
required: Array.isArray(schema.required)
|
|
207
|
+
? schema.required.includes(key)
|
|
208
|
+
: false,
|
|
209
|
+
})
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// TODO: figure out how to handle array of objects
|
|
214
|
+
function createItems(schema: SchemaObject) {
|
|
215
|
+
if (schema.items?.properties !== undefined) {
|
|
216
|
+
return createProperties(schema.items);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (schema.items?.additionalProperties !== undefined) {
|
|
220
|
+
return createAdditionalProperties(schema.items);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (schema.items?.oneOf !== undefined || schema.items?.anyOf !== undefined) {
|
|
224
|
+
return createAnyOneOf(schema.items!);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (schema.items?.allOf !== undefined) {
|
|
228
|
+
const { mergedSchemas }: { mergedSchemas: SchemaObject; required: any } =
|
|
229
|
+
mergeAllOf(schema.items?.allOf);
|
|
230
|
+
|
|
231
|
+
// Handles combo anyOf/oneOf + properties
|
|
232
|
+
if (
|
|
233
|
+
(mergedSchemas.oneOf !== undefined ||
|
|
234
|
+
mergedSchemas.anyOf !== undefined) &&
|
|
235
|
+
mergedSchemas.properties
|
|
236
|
+
) {
|
|
237
|
+
return create("div", {
|
|
238
|
+
children: [
|
|
239
|
+
createAnyOneOf(mergedSchemas),
|
|
240
|
+
createProperties(mergedSchemas),
|
|
241
|
+
],
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Handles only anyOf/oneOf
|
|
246
|
+
if (
|
|
247
|
+
mergedSchemas.oneOf !== undefined ||
|
|
248
|
+
mergedSchemas.anyOf !== undefined
|
|
249
|
+
) {
|
|
250
|
+
return create("div", {
|
|
251
|
+
children: [
|
|
252
|
+
createAnyOneOf(mergedSchemas),
|
|
253
|
+
createProperties(mergedSchemas),
|
|
254
|
+
],
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (
|
|
260
|
+
schema.items?.type === "string" ||
|
|
261
|
+
schema.items?.type === "number" ||
|
|
262
|
+
schema.items?.type === "integer" ||
|
|
263
|
+
schema.items?.type === "boolean"
|
|
264
|
+
) {
|
|
265
|
+
return createNodes(schema.items);
|
|
266
|
+
}
|
|
102
267
|
|
|
268
|
+
// TODO: clean this up or eliminate it?
|
|
269
|
+
return Object.entries(schema.items!).map(([key, val]) =>
|
|
270
|
+
createEdges({
|
|
271
|
+
name: key,
|
|
272
|
+
schema: val,
|
|
273
|
+
required: Array.isArray(schema.required)
|
|
274
|
+
? schema.required.includes(key)
|
|
275
|
+
: false,
|
|
276
|
+
})
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function createDetailsNode(
|
|
281
|
+
name: string,
|
|
282
|
+
schemaName: string,
|
|
283
|
+
schema: SchemaObject,
|
|
284
|
+
required: any
|
|
285
|
+
): any {
|
|
103
286
|
return create("SchemaItem", {
|
|
104
|
-
collapsible:
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
287
|
+
collapsible: true,
|
|
288
|
+
className: "schemaItem",
|
|
289
|
+
children: [
|
|
290
|
+
createDetails({
|
|
291
|
+
children: [
|
|
292
|
+
createDetailsSummary({
|
|
293
|
+
children: [
|
|
294
|
+
create("strong", { children: name }),
|
|
295
|
+
create("span", {
|
|
296
|
+
style: { opacity: "0.6" },
|
|
297
|
+
children: ` ${schemaName}`,
|
|
298
|
+
}),
|
|
299
|
+
guard(required, () => [
|
|
300
|
+
create("strong", {
|
|
301
|
+
style: {
|
|
302
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
303
|
+
color: "var(--openapi-required)",
|
|
304
|
+
},
|
|
305
|
+
children: " required",
|
|
306
|
+
}),
|
|
307
|
+
]),
|
|
308
|
+
],
|
|
309
|
+
}),
|
|
310
|
+
create("div", {
|
|
311
|
+
style: { marginLeft: "1rem" },
|
|
312
|
+
children: [
|
|
313
|
+
guard(getQualifierMessage(schema), (message) =>
|
|
314
|
+
create("div", {
|
|
315
|
+
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
316
|
+
children: createDescription(message),
|
|
317
|
+
})
|
|
318
|
+
),
|
|
319
|
+
guard(schema.description, (description) =>
|
|
320
|
+
create("div", {
|
|
321
|
+
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
322
|
+
children: createDescription(description),
|
|
323
|
+
})
|
|
324
|
+
),
|
|
325
|
+
createNodes(schema),
|
|
326
|
+
],
|
|
327
|
+
}),
|
|
328
|
+
],
|
|
329
|
+
}),
|
|
330
|
+
],
|
|
110
331
|
});
|
|
111
332
|
}
|
|
112
333
|
|
|
113
|
-
interface
|
|
334
|
+
interface EdgeProps {
|
|
335
|
+
name: string;
|
|
114
336
|
schema: SchemaObject;
|
|
337
|
+
required: boolean;
|
|
115
338
|
}
|
|
116
339
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
required: Array.isArray(schema.required)
|
|
126
|
-
? schema.required.includes(key)
|
|
127
|
-
: false,
|
|
128
|
-
})
|
|
129
|
-
),
|
|
130
|
-
});
|
|
340
|
+
/**
|
|
341
|
+
* Creates the edges or "leaves" of a schema tree. Edges can branch into sub-nodes with createDetails().
|
|
342
|
+
*/
|
|
343
|
+
function createEdges({ name, schema, required }: EdgeProps): any {
|
|
344
|
+
const schemaName = getSchemaName(schema);
|
|
345
|
+
|
|
346
|
+
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
347
|
+
return createDetailsNode(name, schemaName, schema, required);
|
|
131
348
|
}
|
|
132
349
|
|
|
133
|
-
// 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
|
|
134
350
|
if (schema.allOf !== undefined) {
|
|
135
|
-
const {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
351
|
+
const {
|
|
352
|
+
mergedSchemas,
|
|
353
|
+
required,
|
|
354
|
+
}: { mergedSchemas: SchemaObject; required: any } = mergeAllOf(
|
|
355
|
+
schema.allOf
|
|
356
|
+
);
|
|
357
|
+
const mergedSchemaName = getSchemaName(mergedSchemas);
|
|
358
|
+
|
|
359
|
+
if (
|
|
360
|
+
mergedSchemas.oneOf !== undefined ||
|
|
361
|
+
mergedSchemas.anyOf !== undefined
|
|
362
|
+
) {
|
|
363
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (mergedSchemas.properties !== undefined) {
|
|
367
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (mergedSchemas.additionalProperties !== undefined) {
|
|
371
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
return create("SchemaItem", {
|
|
375
|
+
collapsible: false,
|
|
376
|
+
name,
|
|
377
|
+
required,
|
|
378
|
+
schemaDescription: mergedSchemas.description,
|
|
379
|
+
schemaName: schemaName,
|
|
380
|
+
qualifierMessage: getQualifierMessage(schema),
|
|
156
381
|
});
|
|
157
382
|
}
|
|
158
383
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return createRows({ schema: schema.items });
|
|
384
|
+
if (schema.properties !== undefined) {
|
|
385
|
+
return createDetailsNode(name, schemaName, schema, required);
|
|
162
386
|
}
|
|
163
387
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
388
|
+
if (schema.additionalProperties !== undefined) {
|
|
389
|
+
return createDetailsNode(name, schemaName, schema, required);
|
|
390
|
+
}
|
|
167
391
|
|
|
168
|
-
|
|
169
|
-
schema
|
|
392
|
+
// array of objects
|
|
393
|
+
if (schema.items?.properties !== undefined) {
|
|
394
|
+
return createDetailsNode(name, schemaName, schema, required);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// primitives and array of non-objects
|
|
398
|
+
return create("SchemaItem", {
|
|
399
|
+
collapsible: false,
|
|
400
|
+
name,
|
|
401
|
+
required,
|
|
402
|
+
schemaDescription: schema.description,
|
|
403
|
+
schemaName: schemaName,
|
|
404
|
+
qualifierMessage: getQualifierMessage(schema),
|
|
405
|
+
});
|
|
170
406
|
}
|
|
171
407
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
schema: val,
|
|
179
|
-
required: Array.isArray(schema.required)
|
|
180
|
-
? schema.required.includes(key)
|
|
181
|
-
: false,
|
|
182
|
-
})
|
|
183
|
-
);
|
|
408
|
+
/**
|
|
409
|
+
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
410
|
+
*/
|
|
411
|
+
function createNodes(schema: SchemaObject): any {
|
|
412
|
+
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
413
|
+
return createAnyOneOf(schema);
|
|
184
414
|
}
|
|
185
415
|
|
|
186
|
-
// 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
|
|
187
416
|
if (schema.allOf !== undefined) {
|
|
188
|
-
const {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
417
|
+
const { mergedSchemas } = mergeAllOf(schema.allOf);
|
|
418
|
+
|
|
419
|
+
// allOf seems to always result in properties
|
|
420
|
+
if (mergedSchemas.properties !== undefined) {
|
|
421
|
+
return createProperties(mergedSchemas);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (schema.properties !== undefined) {
|
|
426
|
+
return createProperties(schema);
|
|
196
427
|
}
|
|
197
428
|
|
|
198
|
-
|
|
429
|
+
if (schema.additionalProperties !== undefined) {
|
|
430
|
+
return createAdditionalProperties(schema);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// TODO: figure out how to handle array of objects
|
|
199
434
|
if (schema.items !== undefined) {
|
|
435
|
+
return createItems(schema);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// primitive
|
|
439
|
+
if (schema.type !== undefined) {
|
|
200
440
|
return create("li", {
|
|
201
441
|
children: create("div", {
|
|
202
|
-
children: [
|
|
442
|
+
children: [
|
|
443
|
+
create("strong", { children: schema.type }),
|
|
444
|
+
guard(schema.format, (format) =>
|
|
445
|
+
create("span", {
|
|
446
|
+
style: { opacity: "0.6" },
|
|
447
|
+
children: ` ${format}`,
|
|
448
|
+
})
|
|
449
|
+
),
|
|
450
|
+
guard(getQualifierMessage(schema), (message) =>
|
|
451
|
+
create("div", {
|
|
452
|
+
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
453
|
+
children: createDescription(message),
|
|
454
|
+
})
|
|
455
|
+
),
|
|
456
|
+
guard(schema.description, (description) =>
|
|
457
|
+
create("div", {
|
|
458
|
+
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
459
|
+
children: createDescription(description),
|
|
460
|
+
})
|
|
461
|
+
),
|
|
462
|
+
],
|
|
203
463
|
}),
|
|
204
464
|
});
|
|
205
465
|
}
|
|
206
466
|
|
|
207
|
-
//
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
children: [
|
|
211
|
-
create("span", {
|
|
212
|
-
style: { opacity: "0.6" },
|
|
213
|
-
children: ` ${schema.type}`,
|
|
214
|
-
}),
|
|
215
|
-
guard(getQualifierMessage(schema), (message) =>
|
|
216
|
-
create("div", {
|
|
217
|
-
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
218
|
-
children: createDescription(message),
|
|
219
|
-
})
|
|
220
|
-
),
|
|
221
|
-
guard(schema.description, (description) =>
|
|
222
|
-
create("div", {
|
|
223
|
-
style: { marginTop: "var(--ifm-table-cell-padding)" },
|
|
224
|
-
children: createDescription(description),
|
|
225
|
-
})
|
|
226
|
-
),
|
|
227
|
-
],
|
|
228
|
-
}),
|
|
229
|
-
});
|
|
467
|
+
// Unknown node/schema type should return undefined
|
|
468
|
+
// So far, haven't seen this hit in testing
|
|
469
|
+
return undefined;
|
|
230
470
|
}
|
|
231
471
|
|
|
232
472
|
interface Props {
|
|
@@ -251,7 +491,6 @@ export function createSchemaDetails({ title, body, ...rest }: Props) {
|
|
|
251
491
|
return undefined;
|
|
252
492
|
}
|
|
253
493
|
|
|
254
|
-
// TODO:
|
|
255
494
|
// NOTE: We just pick a random content-type.
|
|
256
495
|
// How common is it to have multiple?
|
|
257
496
|
const randomFirstKey = Object.keys(body.content)[0];
|
|
@@ -268,6 +507,7 @@ export function createSchemaDetails({ title, body, ...rest }: Props) {
|
|
|
268
507
|
}
|
|
269
508
|
}
|
|
270
509
|
|
|
510
|
+
// Root-level schema dropdown
|
|
271
511
|
return createDetails({
|
|
272
512
|
"data-collapsed": false,
|
|
273
513
|
open: true,
|
|
@@ -277,6 +517,12 @@ export function createSchemaDetails({ title, body, ...rest }: Props) {
|
|
|
277
517
|
style: { textAlign: "left" },
|
|
278
518
|
children: [
|
|
279
519
|
create("strong", { children: `${title}` }),
|
|
520
|
+
guard(firstBody.type === "array", (format) =>
|
|
521
|
+
create("span", {
|
|
522
|
+
style: { opacity: "0.6" },
|
|
523
|
+
children: ` array`,
|
|
524
|
+
})
|
|
525
|
+
),
|
|
280
526
|
guard(body.required, () => [
|
|
281
527
|
create("strong", {
|
|
282
528
|
style: {
|
|
@@ -301,7 +547,7 @@ export function createSchemaDetails({ title, body, ...rest }: Props) {
|
|
|
301
547
|
}),
|
|
302
548
|
create("ul", {
|
|
303
549
|
style: { marginLeft: "1rem" },
|
|
304
|
-
children:
|
|
550
|
+
children: createNodes(firstBody),
|
|
305
551
|
}),
|
|
306
552
|
],
|
|
307
553
|
});
|
package/src/markdown/index.ts
CHANGED
|
@@ -40,6 +40,7 @@ export function createApiPageMD({
|
|
|
40
40
|
`import ParamsItem from "@theme/ParamsItem";\n`,
|
|
41
41
|
`import SchemaItem from "@theme/SchemaItem"\n`,
|
|
42
42
|
`import ApiTabs from "@theme/ApiTabs";\n`,
|
|
43
|
+
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
43
44
|
`import TabItem from "@theme/TabItem";\n\n`,
|
|
44
45
|
`## ${escape(title)}\n\n`,
|
|
45
46
|
createDeprecationNotice({ deprecated, description: deprecatedDescription }),
|