docusaurus-plugin-openapi-docs 1.1.7 → 1.1.8

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Palo Alto Networks
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -577,7 +577,7 @@ function createResponseSchema({ title, body, ...rest }) {
577
577
  groupId: "schema-tabs",
578
578
  children: [
579
579
  firstBody &&
580
- (0, utils_1.create)("TabTtem", {
580
+ (0, utils_1.create)("TabItem", {
581
581
  label: `${title}`,
582
582
  value: `${title}`,
583
583
  children: [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-openapi-docs",
3
3
  "description": "OpenAPI plugin for Docusaurus.",
4
- "version": "1.1.7",
4
+ "version": "1.1.8",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -66,5 +66,6 @@
66
66
  },
67
67
  "engines": {
68
68
  "node": ">=14"
69
- }
69
+ },
70
+ "gitHead": "619aa16c52e6de8fd752ff583681b0da093b679c"
70
71
  }
@@ -748,7 +748,7 @@ export function createResponseSchema({ title, body, ...rest }: Props) {
748
748
  groupId: "schema-tabs",
749
749
  children: [
750
750
  firstBody &&
751
- create("TabTtem", {
751
+ create("TabItem", {
752
752
  label: `${title}`,
753
753
  value: `${title}`,
754
754
  children: [
@@ -1,14 +0,0 @@
1
- import { MediaTypeObject } from "../openapi/types";
2
- interface Props {
3
- style?: any;
4
- title: string;
5
- body: {
6
- content?: {
7
- [key: string]: MediaTypeObject;
8
- };
9
- description?: string;
10
- required?: string[] | boolean;
11
- };
12
- }
13
- export declare function createSchemaDetails({ title, body, ...rest }: Props): string | undefined;
14
- export {};
@@ -1,674 +0,0 @@
1
- "use strict";
2
- /* ============================================================================
3
- * Copyright (c) Palo Alto Networks
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- * ========================================================================== */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.createSchemaDetails = void 0;
10
- const createDescription_1 = require("./createDescription");
11
- const createDetails_1 = require("./createDetails");
12
- const createDetailsSummary_1 = require("./createDetailsSummary");
13
- const schema_1 = require("./schema");
14
- const utils_1 = require("./utils");
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
- resolvers: {
22
- readOnly: function () {
23
- return true;
24
- },
25
- example: function () {
26
- return true;
27
- },
28
- },
29
- });
30
- const required = allOf.reduce((acc, cur) => {
31
- if (Array.isArray(cur.required)) {
32
- const next = [...acc, ...cur.required];
33
- return next;
34
- }
35
- return acc;
36
- }, []);
37
- return { mergedSchemas, required };
38
- }
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;
81
- }),
82
- }),
83
- ],
84
- }),
85
- ],
86
- });
87
- }
88
- function createProperties(schema) {
89
- const discriminator = schema.discriminator;
90
- return Object.entries(schema.properties).map(([key, val]) => createEdges({
91
- name: key,
92
- schema: val,
93
- required: Array.isArray(schema.required)
94
- ? schema.required.includes(key)
95
- : false,
96
- discriminator,
97
- }));
98
- }
99
- function createAdditionalProperties(schema) {
100
- // TODO?:
101
- // {
102
- // description: 'Integration configuration. See \n' +
103
- // '[Integration Configurations](https://prisma.pan.dev/api/cloud/api-integration-config/).\n',
104
- // example: { webhookUrl: 'https://hooks.slack.com/abcdef' },
105
- // externalDocs: { url: 'https://prisma.pan.dev/api/cloud/api-integration-config' },
106
- // type: 'object'
107
- // }
108
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
109
- // TODO?:
110
- // {
111
- // items: {
112
- // properties: {
113
- // aliasField: [Object],
114
- // displayName: [Object],
115
- // fieldName: [Object],
116
- // maxLength: [Object],
117
- // options: [Object],
118
- // redlockMapping: [Object],
119
- // required: [Object],
120
- // type: [Object],
121
- // typeaheadUri: [Object],
122
- // value: [Object]
123
- // },
124
- // type: 'object'
125
- // },
126
- // type: 'array'
127
- // }
128
- if (((_a = schema.additionalProperties) === null || _a === void 0 ? void 0 : _a.type) === "string" ||
129
- ((_b = schema.additionalProperties) === null || _b === void 0 ? void 0 : _b.type) === "object" ||
130
- ((_c = schema.additionalProperties) === null || _c === void 0 ? void 0 : _c.type) === "boolean" ||
131
- ((_d = schema.additionalProperties) === null || _d === void 0 ? void 0 : _d.type) === "integer" ||
132
- ((_e = schema.additionalProperties) === null || _e === void 0 ? void 0 : _e.type) === "number") {
133
- const type = (_f = schema.additionalProperties) === null || _f === void 0 ? void 0 : _f.type;
134
- const additionalProperties = (_g = schema.additionalProperties) === null || _g === void 0 ? void 0 : _g.additionalProperties;
135
- if (additionalProperties !== undefined) {
136
- const type = (_j = (_h = schema.additionalProperties) === null || _h === void 0 ? void 0 : _h.additionalProperties) === null || _j === void 0 ? void 0 : _j.type;
137
- const format = (_l = (_k = schema.additionalProperties) === null || _k === void 0 ? void 0 : _k.additionalProperties) === null || _l === void 0 ? void 0 : _l.format;
138
- return (0, utils_1.create)("li", {
139
- children: (0, utils_1.create)("div", {
140
- children: [
141
- (0, utils_1.create)("code", { children: `property name*` }),
142
- (0, utils_1.guard)(type, (type) => (0, utils_1.create)("span", {
143
- style: { opacity: "0.6" },
144
- children: ` ${type}`,
145
- })),
146
- (0, utils_1.guard)(format, (format) => (0, utils_1.create)("span", {
147
- style: { opacity: "0.6" },
148
- children: ` (${format})`,
149
- })),
150
- (0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema.additionalProperties), (message) => (0, utils_1.create)("div", {
151
- style: { marginTop: "var(--ifm-table-cell-padding)" },
152
- children: (0, createDescription_1.createDescription)(message),
153
- })),
154
- ],
155
- }),
156
- });
157
- }
158
- return (0, utils_1.create)("li", {
159
- children: (0, utils_1.create)("div", {
160
- children: [
161
- (0, utils_1.create)("code", { children: `property name*` }),
162
- (0, utils_1.guard)(type, (type) => (0, utils_1.create)("span", {
163
- style: { opacity: "0.6" },
164
- children: ` ${type}`,
165
- })),
166
- (0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema.additionalProperties), (message) => (0, utils_1.create)("div", {
167
- style: { marginTop: "var(--ifm-table-cell-padding)" },
168
- children: (0, createDescription_1.createDescription)(message),
169
- })),
170
- ],
171
- }),
172
- });
173
- }
174
- return Object.entries(schema.additionalProperties).map(([key, val]) => createEdges({
175
- name: key,
176
- schema: val,
177
- required: Array.isArray(schema.required)
178
- ? schema.required.includes(key)
179
- : false,
180
- }));
181
- }
182
- // TODO: figure out how to handle array of objects
183
- function createItems(schema) {
184
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
185
- if (((_a = schema.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
186
- return createProperties(schema.items);
187
- }
188
- if (((_b = schema.items) === null || _b === void 0 ? void 0 : _b.additionalProperties) !== undefined) {
189
- return createAdditionalProperties(schema.items);
190
- }
191
- 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) {
192
- return createAnyOneOf(schema.items);
193
- }
194
- if (((_e = schema.items) === null || _e === void 0 ? void 0 : _e.allOf) !== undefined) {
195
- // TODO: figure out if and how we should pass merged required array
196
- const { mergedSchemas, } = mergeAllOf((_f = schema.items) === null || _f === void 0 ? void 0 : _f.allOf);
197
- // Handles combo anyOf/oneOf + properties
198
- if ((mergedSchemas.oneOf !== undefined ||
199
- mergedSchemas.anyOf !== undefined) &&
200
- mergedSchemas.properties) {
201
- return (0, utils_1.create)("div", {
202
- children: [
203
- createAnyOneOf(mergedSchemas),
204
- createProperties(mergedSchemas),
205
- ],
206
- });
207
- }
208
- // Handles only anyOf/oneOf
209
- if (mergedSchemas.oneOf !== undefined ||
210
- mergedSchemas.anyOf !== undefined) {
211
- return (0, utils_1.create)("div", {
212
- children: [
213
- createAnyOneOf(mergedSchemas),
214
- createProperties(mergedSchemas),
215
- ],
216
- });
217
- }
218
- }
219
- if (((_g = schema.items) === null || _g === void 0 ? void 0 : _g.type) === "string" ||
220
- ((_h = schema.items) === null || _h === void 0 ? void 0 : _h.type) === "number" ||
221
- ((_j = schema.items) === null || _j === void 0 ? void 0 : _j.type) === "integer" ||
222
- ((_k = schema.items) === null || _k === void 0 ? void 0 : _k.type) === "boolean") {
223
- return createNodes(schema.items);
224
- }
225
- // TODO: clean this up or eliminate it?
226
- return Object.entries(schema.items).map(([key, val]) => createEdges({
227
- name: key,
228
- schema: val,
229
- required: Array.isArray(schema.required)
230
- ? schema.required.includes(key)
231
- : false,
232
- }));
233
- }
234
- /**
235
- * For handling discriminators that do not map to a same-level property
236
- */
237
- function createDiscriminator(schema) {
238
- var _a;
239
- const discriminator = schema.discriminator;
240
- const propertyName = discriminator === null || discriminator === void 0 ? void 0 : discriminator.propertyName;
241
- const propertyType = "string"; // should always be string
242
- const mapping = discriminator === null || discriminator === void 0 ? void 0 : discriminator.mapping;
243
- // Explicit mapping is required since we can't support implicit
244
- if (mapping === undefined) {
245
- return undefined;
246
- }
247
- // Attempt to get the property description we want to display
248
- // TODO: how to make it predictable when handling allOf
249
- let propertyDescription;
250
- const firstMappingSchema = mapping[Object.keys(mapping)[0]];
251
- if (firstMappingSchema.properties !== undefined) {
252
- propertyDescription =
253
- firstMappingSchema.properties[propertyName].description;
254
- }
255
- if (firstMappingSchema.allOf !== undefined) {
256
- const { mergedSchemas } = mergeAllOf(firstMappingSchema.allOf);
257
- if (mergedSchemas.properties !== undefined) {
258
- propertyDescription =
259
- (_a = mergedSchemas.properties[propertyName]) === null || _a === void 0 ? void 0 : _a.description;
260
- }
261
- }
262
- if (propertyDescription === undefined) {
263
- if (schema.properties !== undefined &&
264
- schema.properties[propertyName] !== undefined) {
265
- propertyDescription = schema.properties[propertyName].description;
266
- }
267
- }
268
- return (0, utils_1.create)("div", {
269
- className: "discriminatorItem",
270
- children: (0, utils_1.create)("div", {
271
- children: [
272
- (0, utils_1.create)("strong", {
273
- style: { paddingLeft: "1rem" },
274
- children: propertyName,
275
- }),
276
- (0, utils_1.guard)(propertyType, (name) => (0, utils_1.create)("span", {
277
- style: { opacity: "0.6" },
278
- children: ` ${propertyType}`,
279
- })),
280
- (0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema.discriminator), (message) => (0, utils_1.create)("div", {
281
- style: {
282
- paddingLeft: "1rem",
283
- },
284
- children: (0, createDescription_1.createDescription)(message),
285
- })),
286
- (0, utils_1.guard)(propertyDescription, (description) => (0, utils_1.create)("div", {
287
- style: {
288
- paddingLeft: "1rem",
289
- },
290
- children: (0, createDescription_1.createDescription)(description),
291
- })),
292
- (0, utils_1.create)("DiscriminatorTabs", {
293
- children: Object.keys(mapping).map((key, index) => {
294
- if (mapping[key].allOf !== undefined) {
295
- const { mergedSchemas } = mergeAllOf(mapping[key].allOf);
296
- // Cleanup duplicate property from mapping schema
297
- delete mergedSchemas.properties[propertyName];
298
- mapping[key] = mergedSchemas;
299
- }
300
- if (mapping[key].properties !== undefined) {
301
- // Cleanup duplicate property from mapping schema
302
- delete mapping[key].properties[propertyName];
303
- }
304
- const label = key;
305
- return (0, utils_1.create)("TabItem", {
306
- label: label,
307
- value: `${index}-item-discriminator`,
308
- children: [
309
- (0, utils_1.create)("div", {
310
- style: { marginLeft: "-4px" },
311
- children: createNodes(mapping[key]),
312
- }),
313
- ],
314
- });
315
- }),
316
- }),
317
- ],
318
- }),
319
- });
320
- }
321
- function createDetailsNode(name, schemaName, schema, required) {
322
- return (0, utils_1.create)("SchemaItem", {
323
- collapsible: true,
324
- className: "schemaItem",
325
- children: [
326
- (0, createDetails_1.createDetails)({
327
- children: [
328
- (0, createDetailsSummary_1.createDetailsSummary)({
329
- children: [
330
- (0, utils_1.create)("strong", { children: name }),
331
- (0, utils_1.create)("span", {
332
- style: { opacity: "0.6" },
333
- children: ` ${schemaName}`,
334
- }),
335
- (0, utils_1.guard)(schema.required && schema.required === true, () => [
336
- (0, utils_1.create)("strong", {
337
- style: {
338
- fontSize: "var(--ifm-code-font-size)",
339
- color: "var(--openapi-required)",
340
- },
341
- children: " required",
342
- }),
343
- ]),
344
- ],
345
- }),
346
- (0, utils_1.create)("div", {
347
- style: { marginLeft: "1rem" },
348
- children: [
349
- (0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
350
- style: { marginTop: ".5rem", marginBottom: ".5rem" },
351
- children: (0, createDescription_1.createDescription)(message),
352
- })),
353
- (0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
354
- style: { marginTop: ".5rem", marginBottom: ".5rem" },
355
- children: (0, createDescription_1.createDescription)(description),
356
- })),
357
- createNodes(schema),
358
- ],
359
- }),
360
- ],
361
- }),
362
- ],
363
- });
364
- }
365
- /**
366
- * For handling discriminators that map to a same-level property (like 'petType').
367
- * Note: These should only be encountered while iterating through properties.
368
- */
369
- function createPropertyDiscriminator(name, schemaName, schema, discriminator, required) {
370
- if (schema === undefined) {
371
- return undefined;
372
- }
373
- if (discriminator.mapping === undefined) {
374
- return undefined;
375
- }
376
- return (0, utils_1.create)("div", {
377
- className: "discriminatorItem",
378
- children: (0, utils_1.create)("div", {
379
- children: [
380
- (0, utils_1.create)("strong", { style: { paddingLeft: "1rem" }, children: name }),
381
- (0, utils_1.guard)(schemaName, (name) => (0, utils_1.create)("span", {
382
- style: { opacity: "0.6" },
383
- children: ` ${schemaName}`,
384
- })),
385
- (0, utils_1.guard)(required, () => [
386
- (0, utils_1.create)("strong", {
387
- style: {
388
- fontSize: "var(--ifm-code-font-size)",
389
- color: "var(--openapi-required)",
390
- },
391
- children: " required",
392
- }),
393
- ]),
394
- (0, utils_1.guard)((0, schema_1.getQualifierMessage)(discriminator), (message) => (0, utils_1.create)("div", {
395
- style: {
396
- paddingLeft: "1rem",
397
- },
398
- children: (0, createDescription_1.createDescription)(message),
399
- })),
400
- (0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
401
- style: {
402
- paddingLeft: "1rem",
403
- },
404
- children: (0, createDescription_1.createDescription)(description),
405
- })),
406
- (0, utils_1.create)("DiscriminatorTabs", {
407
- children: Object.keys(discriminator === null || discriminator === void 0 ? void 0 : discriminator.mapping).map((key, index) => {
408
- const label = key;
409
- return (0, utils_1.create)("TabItem", {
410
- label: label,
411
- value: `${index}-item-discriminator`,
412
- children: [
413
- (0, utils_1.create)("div", {
414
- style: { marginLeft: "-4px" },
415
- children: createNodes(discriminator === null || discriminator === void 0 ? void 0 : discriminator.mapping[key]),
416
- }),
417
- ],
418
- });
419
- }),
420
- }),
421
- ],
422
- }),
423
- });
424
- }
425
- /**
426
- * Creates the edges or "leaves" of a schema tree. Edges can branch into sub-nodes with createDetails().
427
- */
428
- function createEdges({ name, schema, required, discriminator, }) {
429
- var _a, _b;
430
- const schemaName = (0, schema_1.getSchemaName)(schema);
431
- // if (name === "id") console.log(name, schema, required);
432
- if (discriminator !== undefined && discriminator.propertyName === name) {
433
- return createPropertyDiscriminator(name, "string", schema, discriminator, required);
434
- }
435
- if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
436
- return createDetailsNode(name, schemaName, schema, required);
437
- }
438
- if (schema.allOf !== undefined) {
439
- const { mergedSchemas, required, } = mergeAllOf(schema.allOf);
440
- const mergedSchemaName = (0, schema_1.getSchemaName)(mergedSchemas);
441
- if (mergedSchemas.oneOf !== undefined ||
442
- mergedSchemas.anyOf !== undefined) {
443
- return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
444
- }
445
- if (mergedSchemas.properties !== undefined) {
446
- return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
447
- }
448
- if (mergedSchemas.additionalProperties !== undefined) {
449
- return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
450
- }
451
- // array of objects
452
- if (((_a = mergedSchemas.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
453
- return createDetailsNode(name, mergedSchemaName, mergedSchemas, required);
454
- }
455
- return (0, utils_1.create)("SchemaItem", {
456
- collapsible: false,
457
- name,
458
- required: Array.isArray(required) ? required.includes(name) : required,
459
- schemaDescription: mergedSchemas.description,
460
- schemaName: schemaName,
461
- qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
462
- defaultValue: schema.default,
463
- });
464
- }
465
- if (schema.properties !== undefined) {
466
- return createDetailsNode(name, schemaName, schema, required);
467
- }
468
- if (schema.additionalProperties !== undefined) {
469
- return createDetailsNode(name, schemaName, schema, required);
470
- }
471
- // array of objects
472
- if (((_b = schema.items) === null || _b === void 0 ? void 0 : _b.properties) !== undefined) {
473
- return createDetailsNode(name, schemaName, schema, required);
474
- }
475
- // primitives and array of non-objects
476
- return (0, utils_1.create)("SchemaItem", {
477
- collapsible: false,
478
- name,
479
- required: Array.isArray(required) ? required.includes(name) : required,
480
- schemaDescription: schema.description,
481
- schemaName: schemaName,
482
- qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
483
- defaultValue: schema.default,
484
- });
485
- }
486
- /**
487
- * Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
488
- */
489
- function createNodes(schema) {
490
- if (schema.discriminator !== undefined) {
491
- return createDiscriminator(schema);
492
- }
493
- if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
494
- return createAnyOneOf(schema);
495
- }
496
- if (schema.allOf !== undefined) {
497
- const { mergedSchemas } = mergeAllOf(schema.allOf);
498
- // allOf seems to always result in properties
499
- if (mergedSchemas.properties !== undefined) {
500
- return createProperties(mergedSchemas);
501
- }
502
- }
503
- if (schema.properties !== undefined) {
504
- return createProperties(schema);
505
- }
506
- if (schema.additionalProperties !== undefined) {
507
- return createAdditionalProperties(schema);
508
- }
509
- // TODO: figure out how to handle array of objects
510
- if (schema.items !== undefined) {
511
- return createItems(schema);
512
- }
513
- // primitive
514
- if (schema.type !== undefined) {
515
- return (0, utils_1.create)("li", {
516
- children: (0, utils_1.create)("div", {
517
- children: [
518
- (0, utils_1.create)("strong", { children: schema.type }),
519
- (0, utils_1.guard)(schema.format, (format) => (0, utils_1.create)("span", {
520
- style: { opacity: "0.6" },
521
- children: ` ${format}`,
522
- })),
523
- (0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
524
- style: { marginTop: "var(--ifm-table-cell-padding)" },
525
- children: (0, createDescription_1.createDescription)(message),
526
- })),
527
- (0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
528
- style: { marginTop: "var(--ifm-table-cell-padding)" },
529
- children: (0, createDescription_1.createDescription)(description),
530
- })),
531
- ],
532
- }),
533
- });
534
- }
535
- // Unknown node/schema type should return undefined
536
- // So far, haven't seen this hit in testing
537
- return undefined;
538
- }
539
- function createSchemaDetails({ title, body, ...rest }) {
540
- if (body === undefined ||
541
- body.content === undefined ||
542
- Object.keys(body).length === 0 ||
543
- Object.keys(body.content).length === 0) {
544
- return undefined;
545
- }
546
- // Get all MIME types, including vendor-specific
547
- const mimeTypes = Object.keys(body.content);
548
- if (mimeTypes && mimeTypes.length > 1) {
549
- return (0, utils_1.create)("MimeTabs", {
550
- groupId: "mime-type",
551
- children: mimeTypes.map((mimeType) => {
552
- const firstBody = body.content[mimeType].schema;
553
- if (firstBody === undefined) {
554
- return undefined;
555
- }
556
- if (firstBody.properties !== undefined) {
557
- if (Object.keys(firstBody.properties).length === 0) {
558
- return undefined;
559
- }
560
- }
561
- return (0, utils_1.create)("TabItem", {
562
- label: mimeType,
563
- value: `${mimeType}`,
564
- children: [
565
- (0, createDetails_1.createDetails)({
566
- "data-collapsed": false,
567
- open: true,
568
- ...rest,
569
- children: [
570
- (0, createDetailsSummary_1.createDetailsSummary)({
571
- style: { textAlign: "left" },
572
- children: [
573
- (0, utils_1.create)("strong", { children: `${title}` }),
574
- (0, utils_1.guard)(firstBody.type === "array", (format) => (0, utils_1.create)("span", {
575
- style: { opacity: "0.6" },
576
- children: ` array`,
577
- })),
578
- (0, utils_1.guard)(body.required && body.required === true, () => [
579
- (0, utils_1.create)("strong", {
580
- style: {
581
- fontSize: "var(--ifm-code-font-size)",
582
- color: "var(--openapi-required)",
583
- },
584
- children: " required",
585
- }),
586
- ]),
587
- ],
588
- }),
589
- (0, utils_1.create)("div", {
590
- style: { textAlign: "left", marginLeft: "1rem" },
591
- children: [
592
- (0, utils_1.guard)(body.description, () => [
593
- (0, utils_1.create)("div", {
594
- style: { marginTop: "1rem", marginBottom: "1rem" },
595
- children: (0, createDescription_1.createDescription)(body.description),
596
- }),
597
- ]),
598
- ],
599
- }),
600
- (0, utils_1.create)("ul", {
601
- style: { marginLeft: "1rem" },
602
- children: createNodes(firstBody),
603
- }),
604
- ],
605
- }),
606
- ],
607
- });
608
- }),
609
- });
610
- }
611
- const randomFirstKey = Object.keys(body.content)[0];
612
- const firstBody = body.content[randomFirstKey].schema;
613
- if (firstBody === undefined) {
614
- return undefined;
615
- }
616
- // we don't show the table if there is no properties to show
617
- if (firstBody.properties !== undefined) {
618
- if (Object.keys(firstBody.properties).length === 0) {
619
- return undefined;
620
- }
621
- }
622
- return (0, utils_1.create)("MimeTabs", {
623
- children: [
624
- (0, utils_1.create)("TabItem", {
625
- label: randomFirstKey,
626
- value: `${randomFirstKey}-schema`,
627
- children: [
628
- (0, createDetails_1.createDetails)({
629
- "data-collapsed": false,
630
- open: true,
631
- ...rest,
632
- children: [
633
- (0, createDetailsSummary_1.createDetailsSummary)({
634
- style: { textAlign: "left" },
635
- children: [
636
- (0, utils_1.create)("strong", { children: `${title}` }),
637
- (0, utils_1.guard)(firstBody.type === "array", (format) => (0, utils_1.create)("span", {
638
- style: { opacity: "0.6" },
639
- children: ` array`,
640
- })),
641
- (0, utils_1.guard)(body.required, () => [
642
- (0, utils_1.create)("strong", {
643
- style: {
644
- fontSize: "var(--ifm-code-font-size)",
645
- color: "var(--openapi-required)",
646
- },
647
- children: " required",
648
- }),
649
- ]),
650
- ],
651
- }),
652
- (0, utils_1.create)("div", {
653
- style: { textAlign: "left", marginLeft: "1rem" },
654
- children: [
655
- (0, utils_1.guard)(body.description, () => [
656
- (0, utils_1.create)("div", {
657
- style: { marginTop: "1rem", marginBottom: "1rem" },
658
- children: (0, createDescription_1.createDescription)(body.description),
659
- }),
660
- ]),
661
- ],
662
- }),
663
- (0, utils_1.create)("ul", {
664
- style: { marginLeft: "1rem" },
665
- children: createNodes(firstBody),
666
- }),
667
- ],
668
- }),
669
- ],
670
- }),
671
- ],
672
- });
673
- }
674
- exports.createSchemaDetails = createSchemaDetails;