docusaurus-plugin-openapi-docs 0.0.0-429 → 0.0.0-433
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/createRequestSchema.js +97 -87
- package/lib/markdown/createResponseSchema.js +103 -90
- package/lib/markdown/createStatusCodes.d.ts +4 -2
- package/lib/markdown/createStatusCodes.js +130 -5
- package/lib/openapi/createRequestExample.d.ts +2 -0
- package/lib/openapi/{createExample.js → createRequestExample.js} +40 -9
- package/lib/openapi/createResponseExample.d.ts +2 -0
- package/lib/openapi/createResponseExample.js +167 -0
- package/lib/openapi/openapi.js +3 -3
- package/package.json +4 -3
- package/src/markdown/createRequestSchema.ts +103 -103
- package/src/markdown/createResponseSchema.ts +110 -106
- package/src/markdown/createStatusCodes.ts +122 -4
- package/src/openapi/{createExample.ts → createRequestExample.ts} +43 -7
- package/src/openapi/createResponseExample.ts +205 -0
- package/src/openapi/openapi.ts +3 -3
- package/lib/openapi/createExample.d.ts +0 -2
|
@@ -235,90 +235,100 @@ function createItems(schema) {
|
|
|
235
235
|
/**
|
|
236
236
|
* For handling discriminators that do not map to a same-level property
|
|
237
237
|
*/
|
|
238
|
-
function createDiscriminator(schema) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
238
|
+
// function createDiscriminator(schema: SchemaObject) {
|
|
239
|
+
// const discriminator = schema.discriminator;
|
|
240
|
+
// const propertyName = discriminator?.propertyName;
|
|
241
|
+
// const propertyType = "string"; // should always be string
|
|
242
|
+
// const mapping: any = 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 }: { mergedSchemas: SchemaObject } = mergeAllOf(
|
|
257
|
+
// firstMappingSchema.allOf
|
|
258
|
+
// );
|
|
259
|
+
// if (mergedSchemas.properties !== undefined) {
|
|
260
|
+
// propertyDescription =
|
|
261
|
+
// mergedSchemas.properties[propertyName!]?.description;
|
|
262
|
+
// }
|
|
263
|
+
// }
|
|
264
|
+
// if (propertyDescription === undefined) {
|
|
265
|
+
// if (
|
|
266
|
+
// schema.properties !== undefined &&
|
|
267
|
+
// schema.properties![propertyName!] !== undefined
|
|
268
|
+
// ) {
|
|
269
|
+
// propertyDescription = schema.properties![propertyName!].description;
|
|
270
|
+
// }
|
|
271
|
+
// }
|
|
272
|
+
// return create("div", {
|
|
273
|
+
// className: "discriminatorItem",
|
|
274
|
+
// children: create("div", {
|
|
275
|
+
// children: [
|
|
276
|
+
// create("strong", {
|
|
277
|
+
// style: { paddingLeft: "1rem" },
|
|
278
|
+
// children: propertyName,
|
|
279
|
+
// }),
|
|
280
|
+
// guard(propertyType, (name) =>
|
|
281
|
+
// create("span", {
|
|
282
|
+
// style: { opacity: "0.6" },
|
|
283
|
+
// children: ` ${propertyType}`,
|
|
284
|
+
// })
|
|
285
|
+
// ),
|
|
286
|
+
// guard(getQualifierMessage(schema.discriminator as any), (message) =>
|
|
287
|
+
// create("div", {
|
|
288
|
+
// style: {
|
|
289
|
+
// paddingLeft: "1rem",
|
|
290
|
+
// },
|
|
291
|
+
// children: createDescription(message),
|
|
292
|
+
// })
|
|
293
|
+
// ),
|
|
294
|
+
// guard(propertyDescription, (description) =>
|
|
295
|
+
// create("div", {
|
|
296
|
+
// style: {
|
|
297
|
+
// paddingLeft: "1rem",
|
|
298
|
+
// },
|
|
299
|
+
// children: createDescription(description),
|
|
300
|
+
// })
|
|
301
|
+
// ),
|
|
302
|
+
// create("DiscriminatorTabs", {
|
|
303
|
+
// children: Object.keys(mapping!).map((key, index) => {
|
|
304
|
+
// if (mapping[key].allOf !== undefined) {
|
|
305
|
+
// const { mergedSchemas }: { mergedSchemas: SchemaObject } =
|
|
306
|
+
// mergeAllOf(mapping[key].allOf);
|
|
307
|
+
// // Cleanup duplicate property from mapping schema
|
|
308
|
+
// delete mergedSchemas.properties![propertyName!];
|
|
309
|
+
// mapping[key] = mergedSchemas;
|
|
310
|
+
// }
|
|
311
|
+
// if (mapping[key].properties !== undefined) {
|
|
312
|
+
// // Cleanup duplicate property from mapping schema
|
|
313
|
+
// delete mapping[key].properties![propertyName!];
|
|
314
|
+
// }
|
|
315
|
+
// const label = key;
|
|
316
|
+
// return create("TabItem", {
|
|
317
|
+
// label: label,
|
|
318
|
+
// value: `${index}-item-discriminator`,
|
|
319
|
+
// children: [
|
|
320
|
+
// create("div", {
|
|
321
|
+
// style: { marginLeft: "-4px" },
|
|
322
|
+
// children: createNodes(mapping[key]),
|
|
323
|
+
// }),
|
|
324
|
+
// ],
|
|
325
|
+
// });
|
|
326
|
+
// }),
|
|
327
|
+
// }),
|
|
328
|
+
// ],
|
|
329
|
+
// }),
|
|
330
|
+
// });
|
|
331
|
+
// }
|
|
322
332
|
function createDetailsNode(name, schemaName, schema, required) {
|
|
323
333
|
return (0, utils_1.create)("SchemaItem", {
|
|
324
334
|
collapsible: true,
|
|
@@ -493,9 +503,9 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
493
503
|
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
494
504
|
*/
|
|
495
505
|
function createNodes(schema) {
|
|
496
|
-
if (schema.discriminator !== undefined) {
|
|
497
|
-
|
|
498
|
-
}
|
|
506
|
+
// if (schema.discriminator !== undefined) {
|
|
507
|
+
// return createDiscriminator(schema);
|
|
508
|
+
// }
|
|
499
509
|
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
500
510
|
return createAnyOneOf(schema);
|
|
501
511
|
}
|
|
@@ -235,90 +235,100 @@ function createItems(schema) {
|
|
|
235
235
|
/**
|
|
236
236
|
* For handling discriminators that do not map to a same-level property
|
|
237
237
|
*/
|
|
238
|
-
function createDiscriminator(schema) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
238
|
+
// function createDiscriminator(schema: SchemaObject) {
|
|
239
|
+
// const discriminator = schema.discriminator;
|
|
240
|
+
// const propertyName = discriminator?.propertyName;
|
|
241
|
+
// const propertyType = "string"; // should always be string
|
|
242
|
+
// const mapping: any = 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 }: { mergedSchemas: SchemaObject } = mergeAllOf(
|
|
257
|
+
// firstMappingSchema.allOf
|
|
258
|
+
// );
|
|
259
|
+
// if (mergedSchemas.properties !== undefined) {
|
|
260
|
+
// propertyDescription =
|
|
261
|
+
// mergedSchemas.properties[propertyName!]?.description;
|
|
262
|
+
// }
|
|
263
|
+
// }
|
|
264
|
+
// if (propertyDescription === undefined) {
|
|
265
|
+
// if (
|
|
266
|
+
// schema.properties !== undefined &&
|
|
267
|
+
// schema.properties![propertyName!] !== undefined
|
|
268
|
+
// ) {
|
|
269
|
+
// propertyDescription = schema.properties![propertyName!].description;
|
|
270
|
+
// }
|
|
271
|
+
// }
|
|
272
|
+
// return create("div", {
|
|
273
|
+
// className: "discriminatorItem",
|
|
274
|
+
// children: create("div", {
|
|
275
|
+
// children: [
|
|
276
|
+
// create("strong", {
|
|
277
|
+
// style: { paddingLeft: "1rem" },
|
|
278
|
+
// children: propertyName,
|
|
279
|
+
// }),
|
|
280
|
+
// guard(propertyType, (name) =>
|
|
281
|
+
// create("span", {
|
|
282
|
+
// style: { opacity: "0.6" },
|
|
283
|
+
// children: ` ${propertyType}`,
|
|
284
|
+
// })
|
|
285
|
+
// ),
|
|
286
|
+
// guard(getQualifierMessage(schema.discriminator as any), (message) =>
|
|
287
|
+
// create("div", {
|
|
288
|
+
// style: {
|
|
289
|
+
// paddingLeft: "1rem",
|
|
290
|
+
// },
|
|
291
|
+
// children: createDescription(message),
|
|
292
|
+
// })
|
|
293
|
+
// ),
|
|
294
|
+
// guard(propertyDescription, (description) =>
|
|
295
|
+
// create("div", {
|
|
296
|
+
// style: {
|
|
297
|
+
// paddingLeft: "1rem",
|
|
298
|
+
// },
|
|
299
|
+
// children: createDescription(description),
|
|
300
|
+
// })
|
|
301
|
+
// ),
|
|
302
|
+
// create("DiscriminatorTabs", {
|
|
303
|
+
// children: Object.keys(mapping!).map((key, index) => {
|
|
304
|
+
// if (mapping[key].allOf !== undefined) {
|
|
305
|
+
// const { mergedSchemas }: { mergedSchemas: SchemaObject } =
|
|
306
|
+
// mergeAllOf(mapping[key].allOf);
|
|
307
|
+
// // Cleanup duplicate property from mapping schema
|
|
308
|
+
// delete mergedSchemas.properties![propertyName!];
|
|
309
|
+
// mapping[key] = mergedSchemas;
|
|
310
|
+
// }
|
|
311
|
+
// if (mapping[key].properties !== undefined) {
|
|
312
|
+
// // Cleanup duplicate property from mapping schema
|
|
313
|
+
// delete mapping[key].properties![propertyName!];
|
|
314
|
+
// }
|
|
315
|
+
// const label = key;
|
|
316
|
+
// return create("TabItem", {
|
|
317
|
+
// label: label,
|
|
318
|
+
// value: `${index}-item-discriminator`,
|
|
319
|
+
// children: [
|
|
320
|
+
// create("div", {
|
|
321
|
+
// style: { marginLeft: "-4px" },
|
|
322
|
+
// children: createNodes(mapping[key]),
|
|
323
|
+
// }),
|
|
324
|
+
// ],
|
|
325
|
+
// });
|
|
326
|
+
// }),
|
|
327
|
+
// }),
|
|
328
|
+
// ],
|
|
329
|
+
// }),
|
|
330
|
+
// });
|
|
331
|
+
// }
|
|
322
332
|
function createDetailsNode(name, schemaName, schema, required) {
|
|
323
333
|
return (0, utils_1.create)("SchemaItem", {
|
|
324
334
|
collapsible: true,
|
|
@@ -493,9 +503,9 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
493
503
|
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
494
504
|
*/
|
|
495
505
|
function createNodes(schema) {
|
|
496
|
-
if (schema.discriminator !== undefined) {
|
|
497
|
-
|
|
498
|
-
}
|
|
506
|
+
// if (schema.discriminator !== undefined) {
|
|
507
|
+
// return createDiscriminator(schema);
|
|
508
|
+
// }
|
|
499
509
|
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
500
510
|
return createAnyOneOf(schema);
|
|
501
511
|
}
|
|
@@ -577,7 +587,7 @@ function createResponseSchema({ title, body, ...rest }) {
|
|
|
577
587
|
groupId: "schema-tabs",
|
|
578
588
|
children: [
|
|
579
589
|
firstBody &&
|
|
580
|
-
(0, utils_1.create)("
|
|
590
|
+
(0, utils_1.create)("TabItem", {
|
|
581
591
|
label: `${title}`,
|
|
582
592
|
value: `${title}`,
|
|
583
593
|
children: [
|
|
@@ -627,8 +637,11 @@ function createResponseSchema({ title, body, ...rest }) {
|
|
|
627
637
|
}),
|
|
628
638
|
],
|
|
629
639
|
}),
|
|
630
|
-
|
|
631
|
-
|
|
640
|
+
firstBody && (0, createStatusCodes_1.createExampleFromSchema)(firstBody, mimeType),
|
|
641
|
+
responseExamples &&
|
|
642
|
+
(0, createStatusCodes_1.createResponseExamples)(responseExamples, mimeType),
|
|
643
|
+
responseExample &&
|
|
644
|
+
(0, createStatusCodes_1.createResponseExample)(responseExample, mimeType),
|
|
632
645
|
],
|
|
633
646
|
}),
|
|
634
647
|
],
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ApiItem } from "../types";
|
|
2
|
+
export default function json2xml(o: any, tab: any): string;
|
|
2
3
|
interface Props {
|
|
3
4
|
responses: ApiItem["responses"];
|
|
4
5
|
}
|
|
5
|
-
export declare function createResponseExamples(responseExamples: any): string[];
|
|
6
|
-
export declare function createResponseExample(responseExample: any): string;
|
|
6
|
+
export declare function createResponseExamples(responseExamples: any, mimeType: string): string[];
|
|
7
|
+
export declare function createResponseExample(responseExample: any, mimeType: string): string;
|
|
8
|
+
export declare function createExampleFromSchema(schema: any, mimeType: string): string | undefined;
|
|
7
9
|
export declare function createStatusCodes({ responses }: Props): string | undefined;
|
|
8
10
|
export {};
|
|
@@ -5,14 +5,62 @@
|
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
* ========================================================================== */
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
8
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.createStatusCodes = exports.createResponseExample = exports.createResponseExamples = void 0;
|
|
12
|
+
exports.createStatusCodes = exports.createExampleFromSchema = exports.createResponseExample = exports.createResponseExamples = void 0;
|
|
13
|
+
const xml_formatter_1 = __importDefault(require("xml-formatter"));
|
|
14
|
+
const createResponseExample_1 = require("../openapi/createResponseExample");
|
|
10
15
|
const createDescription_1 = require("./createDescription");
|
|
11
16
|
const createDetails_1 = require("./createDetails");
|
|
12
17
|
const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
13
18
|
const createResponseSchema_1 = require("./createResponseSchema");
|
|
14
19
|
const utils_1 = require("./utils");
|
|
15
20
|
const utils_2 = require("./utils");
|
|
21
|
+
function json2xml(o, tab) {
|
|
22
|
+
var toXml = function (v, name, ind) {
|
|
23
|
+
var xml = "";
|
|
24
|
+
if (v instanceof Array) {
|
|
25
|
+
for (var i = 0, n = v.length; i < n; i++)
|
|
26
|
+
xml += ind + toXml(v[i], name, ind + "\t") + "\n";
|
|
27
|
+
}
|
|
28
|
+
else if (typeof v == "object") {
|
|
29
|
+
var hasChild = false;
|
|
30
|
+
xml += ind + "<" + name;
|
|
31
|
+
for (var m in v) {
|
|
32
|
+
if (m.charAt(0) === "@")
|
|
33
|
+
xml += " " + m.substr(1) + '="' + v[m].toString() + '"';
|
|
34
|
+
else
|
|
35
|
+
hasChild = true;
|
|
36
|
+
}
|
|
37
|
+
xml += hasChild ? ">" : "/>";
|
|
38
|
+
if (hasChild) {
|
|
39
|
+
for (var m2 in v) {
|
|
40
|
+
if (m2 === "#text")
|
|
41
|
+
xml += v[m2];
|
|
42
|
+
else if (m2 === "#cdata")
|
|
43
|
+
xml += "<![CDATA[" + v[m2] + "]]>";
|
|
44
|
+
else if (m2.charAt(0) !== "@")
|
|
45
|
+
xml += toXml(v[m2], m2, ind + "\t");
|
|
46
|
+
}
|
|
47
|
+
xml +=
|
|
48
|
+
(xml.charAt(xml.length - 1) === "\n" ? ind : "") +
|
|
49
|
+
"</" +
|
|
50
|
+
name +
|
|
51
|
+
">";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
xml += ind + "<" + name + ">" + v.toString() + "</" + name + ">";
|
|
56
|
+
}
|
|
57
|
+
return xml;
|
|
58
|
+
}, xml = "";
|
|
59
|
+
for (var m3 in o)
|
|
60
|
+
xml += toXml(o[m3], m3, "");
|
|
61
|
+
return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, "");
|
|
62
|
+
}
|
|
63
|
+
exports.default = json2xml;
|
|
16
64
|
function createResponseHeaders(responseHeaders) {
|
|
17
65
|
return (0, utils_2.guard)(responseHeaders, () => (0, utils_1.create)("ul", {
|
|
18
66
|
style: { marginLeft: "1rem" },
|
|
@@ -53,7 +101,14 @@ function createResponseHeaders(responseHeaders) {
|
|
|
53
101
|
],
|
|
54
102
|
}));
|
|
55
103
|
}
|
|
56
|
-
function createResponseExamples(responseExamples) {
|
|
104
|
+
function createResponseExamples(responseExamples, mimeType) {
|
|
105
|
+
let language = "shell";
|
|
106
|
+
if (mimeType.endsWith("json")) {
|
|
107
|
+
language = "json";
|
|
108
|
+
}
|
|
109
|
+
if (mimeType.endsWith("xml")) {
|
|
110
|
+
language = "xml";
|
|
111
|
+
}
|
|
57
112
|
return Object.entries(responseExamples).map(([exampleName, exampleValue]) => {
|
|
58
113
|
const camelToSpaceName = exampleName.replace(/([A-Z])/g, " $1");
|
|
59
114
|
let finalFormattedName = camelToSpaceName.charAt(0).toUpperCase() + camelToSpaceName.slice(1);
|
|
@@ -64,6 +119,7 @@ function createResponseExamples(responseExamples) {
|
|
|
64
119
|
children: [
|
|
65
120
|
(0, utils_1.create)("ResponseSamples", {
|
|
66
121
|
responseExample: JSON.stringify(exampleValue.value, null, 2),
|
|
122
|
+
language: language,
|
|
67
123
|
}),
|
|
68
124
|
],
|
|
69
125
|
});
|
|
@@ -74,13 +130,21 @@ function createResponseExamples(responseExamples) {
|
|
|
74
130
|
children: [
|
|
75
131
|
(0, utils_1.create)("ResponseSamples", {
|
|
76
132
|
responseExample: exampleValue.value,
|
|
133
|
+
language: language,
|
|
77
134
|
}),
|
|
78
135
|
],
|
|
79
136
|
});
|
|
80
137
|
});
|
|
81
138
|
}
|
|
82
139
|
exports.createResponseExamples = createResponseExamples;
|
|
83
|
-
function createResponseExample(responseExample) {
|
|
140
|
+
function createResponseExample(responseExample, mimeType) {
|
|
141
|
+
let language = "shell";
|
|
142
|
+
if (mimeType.endsWith("json")) {
|
|
143
|
+
language = "json";
|
|
144
|
+
}
|
|
145
|
+
if (mimeType.endsWith("xml")) {
|
|
146
|
+
language = "xml";
|
|
147
|
+
}
|
|
84
148
|
if (typeof responseExample === "object") {
|
|
85
149
|
return (0, utils_1.create)("TabItem", {
|
|
86
150
|
label: `Example`,
|
|
@@ -88,6 +152,7 @@ function createResponseExample(responseExample) {
|
|
|
88
152
|
children: [
|
|
89
153
|
(0, utils_1.create)("ResponseSamples", {
|
|
90
154
|
responseExample: JSON.stringify(responseExample, null, 2),
|
|
155
|
+
language: language,
|
|
91
156
|
}),
|
|
92
157
|
],
|
|
93
158
|
});
|
|
@@ -98,11 +163,71 @@ function createResponseExample(responseExample) {
|
|
|
98
163
|
children: [
|
|
99
164
|
(0, utils_1.create)("ResponseSamples", {
|
|
100
165
|
responseExample: responseExample,
|
|
166
|
+
language: language,
|
|
101
167
|
}),
|
|
102
168
|
],
|
|
103
169
|
});
|
|
104
170
|
}
|
|
105
171
|
exports.createResponseExample = createResponseExample;
|
|
172
|
+
function createExampleFromSchema(schema, mimeType) {
|
|
173
|
+
const responseExample = (0, createResponseExample_1.sampleResponseFromSchema)(schema);
|
|
174
|
+
if (mimeType.endsWith("xml")) {
|
|
175
|
+
let responseExampleObject;
|
|
176
|
+
try {
|
|
177
|
+
responseExampleObject = JSON.parse(JSON.stringify(responseExample));
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
if (typeof responseExampleObject === "object") {
|
|
183
|
+
let xmlExample;
|
|
184
|
+
try {
|
|
185
|
+
xmlExample = (0, xml_formatter_1.default)(json2xml(responseExampleObject, ""), {
|
|
186
|
+
indentation: " ",
|
|
187
|
+
lineSeparator: "\n",
|
|
188
|
+
collapseContent: true,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
const xmlExampleWithRoot = { root: responseExampleObject };
|
|
193
|
+
try {
|
|
194
|
+
xmlExample = (0, xml_formatter_1.default)(json2xml(xmlExampleWithRoot, ""), {
|
|
195
|
+
indentation: " ",
|
|
196
|
+
lineSeparator: "\n",
|
|
197
|
+
collapseContent: true,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
xmlExample = json2xml(responseExampleObject, "");
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return (0, utils_1.create)("TabItem", {
|
|
205
|
+
label: `Example (from schema)`,
|
|
206
|
+
value: `Example (from schema)`,
|
|
207
|
+
children: [
|
|
208
|
+
(0, utils_1.create)("ResponseSamples", {
|
|
209
|
+
responseExample: xmlExample,
|
|
210
|
+
language: "xml",
|
|
211
|
+
}),
|
|
212
|
+
],
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (typeof responseExample === "object") {
|
|
217
|
+
return (0, utils_1.create)("TabItem", {
|
|
218
|
+
label: `Example (from schema)`,
|
|
219
|
+
value: `Example (from schema)`,
|
|
220
|
+
children: [
|
|
221
|
+
(0, utils_1.create)("ResponseSamples", {
|
|
222
|
+
responseExample: JSON.stringify(responseExample, null, 2),
|
|
223
|
+
language: "json",
|
|
224
|
+
}),
|
|
225
|
+
],
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
return undefined;
|
|
229
|
+
}
|
|
230
|
+
exports.createExampleFromSchema = createExampleFromSchema;
|
|
106
231
|
function createStatusCodes({ responses }) {
|
|
107
232
|
if (responses === undefined) {
|
|
108
233
|
return undefined;
|
|
@@ -127,8 +252,8 @@ function createStatusCodes({ responses }) {
|
|
|
127
252
|
}),
|
|
128
253
|
responseHeaders &&
|
|
129
254
|
(0, createDetails_1.createDetails)({
|
|
130
|
-
"data-collaposed":
|
|
131
|
-
open:
|
|
255
|
+
"data-collaposed": true,
|
|
256
|
+
open: false,
|
|
132
257
|
style: { textAlign: "left", marginBottom: "1rem" },
|
|
133
258
|
children: [
|
|
134
259
|
(0, createDetailsSummary_1.createDetailsSummary)({
|