docusaurus-plugin-openapi-docs 4.0.1 → 4.2.0
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 +11 -0
- package/lib/index.js +4 -0
- package/lib/markdown/createCallbackMethodEndpoint.d.ts +1 -0
- package/lib/markdown/createCallbackMethodEndpoint.js +21 -0
- package/lib/markdown/createCallbacks.js +2 -2
- package/lib/markdown/createContactInfo.js +1 -1
- package/lib/markdown/createDeprecationNotice.js +5 -6
- package/lib/markdown/createMethodEndpoint.js +8 -1
- package/lib/markdown/createParamsDetails.d.ts +1 -2
- package/lib/markdown/createParamsDetails.js +7 -36
- package/lib/markdown/createRequestBodyDetails.d.ts +1 -1
- package/lib/markdown/createRequestSchema.d.ts +1 -1
- package/lib/markdown/createRequestSchema.js +8 -132
- package/lib/markdown/createResponseSchema.d.ts +1 -1
- package/lib/markdown/createResponseSchema.js +8 -94
- package/lib/markdown/createSchema.d.ts +1 -4
- package/lib/markdown/createSchema.js +35 -50
- package/lib/markdown/createSchema.test.js +48 -0
- package/lib/markdown/createStatusCodes.d.ts +1 -4
- package/lib/markdown/createStatusCodes.js +10 -259
- package/lib/markdown/index.js +11 -22
- package/lib/markdown/utils.d.ts +4 -0
- package/lib/openapi/createRequestExample.js +2 -2
- package/lib/openapi/createResponseExample.js +2 -2
- package/lib/openapi/openapi.js +16 -14
- package/lib/openapi/types.d.ts +4 -0
- package/lib/openapi/utils/services/OpenAPIParser.js +1 -1
- package/lib/options.js +5 -0
- package/lib/sidebars/index.js +32 -26
- package/lib/types.d.ts +9 -0
- package/package.json +7 -7
- package/src/index.ts +4 -0
- package/src/markdown/__snapshots__/createSchema.test.ts.snap +142 -0
- package/src/markdown/createCallbackMethodEndpoint.ts +19 -0
- package/src/markdown/createCallbacks.ts +2 -2
- package/src/markdown/createContactInfo.ts +1 -1
- package/src/markdown/createDeprecationNotice.ts +3 -2
- package/src/markdown/createMethodEndpoint.ts +8 -1
- package/src/markdown/createParamsDetails.ts +7 -42
- package/src/markdown/createRequestSchema.ts +9 -143
- package/src/markdown/createResponseSchema.ts +9 -112
- package/src/markdown/createSchema.test.ts +64 -0
- package/src/markdown/createSchema.ts +30 -50
- package/src/markdown/createStatusCodes.ts +9 -268
- package/src/markdown/index.ts +11 -22
- package/src/markdown/utils.ts +4 -0
- package/src/openapi/createRequestExample.ts +2 -5
- package/src/openapi/createResponseExample.ts +2 -5
- package/src/openapi/openapi.ts +4 -2
- package/src/openapi/types.ts +4 -0
- package/src/openapi/utils/loadAndResolveSpec.ts +1 -1
- package/src/openapi/utils/services/OpenAPIParser.ts +1 -0
- package/src/options.ts +6 -0
- package/src/sidebars/index.ts +47 -40
- package/src/types.ts +11 -0
|
@@ -10,6 +10,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.createNodes = exports.mergeAllOf = void 0;
|
|
13
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
14
|
+
const allof_merge_1 = require("allof-merge");
|
|
13
15
|
const clsx_1 = __importDefault(require("clsx"));
|
|
14
16
|
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
15
17
|
const createArrayBracket_1 = require("./createArrayBracket");
|
|
@@ -18,37 +20,16 @@ const createDetails_1 = require("./createDetails");
|
|
|
18
20
|
const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
19
21
|
const schema_1 = require("./schema");
|
|
20
22
|
const utils_1 = require("./utils");
|
|
21
|
-
const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
|
|
22
23
|
let SCHEMA_TYPE;
|
|
23
24
|
/**
|
|
24
25
|
* Returns a merged representation of allOf array of schemas.
|
|
25
26
|
*/
|
|
26
27
|
function mergeAllOf(allOf) {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
writeOnly: function () {
|
|
33
|
-
return true;
|
|
34
|
-
},
|
|
35
|
-
example: function () {
|
|
36
|
-
return true;
|
|
37
|
-
},
|
|
38
|
-
"x-examples": function () {
|
|
39
|
-
return true;
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
ignoreAdditionalProperties: true,
|
|
43
|
-
});
|
|
44
|
-
const mergedRequired = allOf.reduce((acc, cur) => {
|
|
45
|
-
if (Array.isArray(cur.required)) {
|
|
46
|
-
const next = [...acc, ...cur.required];
|
|
47
|
-
return next;
|
|
48
|
-
}
|
|
49
|
-
return acc;
|
|
50
|
-
}, []);
|
|
51
|
-
return { mergedSchemas, mergedRequired };
|
|
28
|
+
const onMergeError = (msg) => {
|
|
29
|
+
console.warn(msg);
|
|
30
|
+
};
|
|
31
|
+
const mergedSchemas = (0, allof_merge_1.merge)(allOf, { onMergeError });
|
|
32
|
+
return mergedSchemas;
|
|
52
33
|
}
|
|
53
34
|
exports.mergeAllOf = mergeAllOf;
|
|
54
35
|
/**
|
|
@@ -90,6 +71,10 @@ function createAnyOneOf(schema) {
|
|
|
90
71
|
anyOneChildren.push(createNodes(anyOneSchema, SCHEMA_TYPE));
|
|
91
72
|
delete anyOneSchema.allOf;
|
|
92
73
|
}
|
|
74
|
+
if (anyOneSchema.oneOf !== undefined) {
|
|
75
|
+
anyOneChildren.push(createNodes(anyOneSchema, SCHEMA_TYPE));
|
|
76
|
+
delete anyOneSchema.oneOf;
|
|
77
|
+
}
|
|
93
78
|
if (anyOneSchema.items !== undefined) {
|
|
94
79
|
anyOneChildren.push(createItems(anyOneSchema));
|
|
95
80
|
delete anyOneSchema.items;
|
|
@@ -207,7 +192,7 @@ function createAdditionalProperties(schema) {
|
|
|
207
192
|
* For handling items.
|
|
208
193
|
*/
|
|
209
194
|
function createItems(schema) {
|
|
210
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k
|
|
195
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
211
196
|
if (((_a = schema.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
|
|
212
197
|
return [
|
|
213
198
|
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
@@ -231,7 +216,7 @@ function createItems(schema) {
|
|
|
231
216
|
}
|
|
232
217
|
if (((_e = schema.items) === null || _e === void 0 ? void 0 : _e.allOf) !== undefined) {
|
|
233
218
|
// TODO: figure out if and how we should pass merged required array
|
|
234
|
-
const
|
|
219
|
+
const mergedSchemas = mergeAllOf(schema.items);
|
|
235
220
|
// Handles combo anyOf/oneOf + properties
|
|
236
221
|
if ((mergedSchemas.oneOf !== undefined ||
|
|
237
222
|
mergedSchemas.anyOf !== undefined) &&
|
|
@@ -261,11 +246,11 @@ function createItems(schema) {
|
|
|
261
246
|
].flat();
|
|
262
247
|
}
|
|
263
248
|
}
|
|
264
|
-
if (((
|
|
265
|
-
((
|
|
266
|
-
((
|
|
267
|
-
((
|
|
268
|
-
((
|
|
249
|
+
if (((_f = schema.items) === null || _f === void 0 ? void 0 : _f.type) === "string" ||
|
|
250
|
+
((_g = schema.items) === null || _g === void 0 ? void 0 : _g.type) === "number" ||
|
|
251
|
+
((_h = schema.items) === null || _h === void 0 ? void 0 : _h.type) === "integer" ||
|
|
252
|
+
((_j = schema.items) === null || _j === void 0 ? void 0 : _j.type) === "boolean" ||
|
|
253
|
+
((_k = schema.items) === null || _k === void 0 ? void 0 : _k.type) === "object") {
|
|
269
254
|
return [
|
|
270
255
|
(0, createArrayBracket_1.createOpeningArrayBracket)(),
|
|
271
256
|
createNodes(schema.items, SCHEMA_TYPE),
|
|
@@ -347,14 +332,14 @@ function createDetailsNode(name, schemaName, schema, required, nullable) {
|
|
|
347
332
|
(0, utils_1.create)("div", {
|
|
348
333
|
style: { marginLeft: "1rem" },
|
|
349
334
|
children: [
|
|
350
|
-
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
|
|
351
|
-
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
352
|
-
children: (0, createDescription_1.createDescription)(message),
|
|
353
|
-
})),
|
|
354
335
|
(0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
|
|
355
336
|
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
356
337
|
children: (0, createDescription_1.createDescription)(description),
|
|
357
338
|
})),
|
|
339
|
+
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
|
|
340
|
+
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
341
|
+
children: (0, createDescription_1.createDescription)(message),
|
|
342
|
+
})),
|
|
358
343
|
createNodes(schema, SCHEMA_TYPE),
|
|
359
344
|
],
|
|
360
345
|
}),
|
|
@@ -474,17 +459,17 @@ function createPropertyDiscriminator(name, schemaName, schema, discriminator, re
|
|
|
474
459
|
]),
|
|
475
460
|
],
|
|
476
461
|
}),
|
|
477
|
-
(0, utils_1.guard)(
|
|
462
|
+
(0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
|
|
478
463
|
style: {
|
|
479
464
|
paddingLeft: "1rem",
|
|
480
465
|
},
|
|
481
|
-
children: (0, createDescription_1.createDescription)(
|
|
466
|
+
children: (0, createDescription_1.createDescription)(description),
|
|
482
467
|
})),
|
|
483
|
-
(0, utils_1.guard)(
|
|
468
|
+
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(discriminator), (message) => (0, utils_1.create)("div", {
|
|
484
469
|
style: {
|
|
485
470
|
paddingLeft: "1rem",
|
|
486
471
|
},
|
|
487
|
-
children: (0, createDescription_1.createDescription)(
|
|
472
|
+
children: (0, createDescription_1.createDescription)(message),
|
|
488
473
|
})),
|
|
489
474
|
(0, utils_1.create)("DiscriminatorTabs", {
|
|
490
475
|
className: "openapi-tabs__discriminator",
|
|
@@ -506,7 +491,7 @@ function createPropertyDiscriminator(name, schemaName, schema, discriminator, re
|
|
|
506
491
|
* Creates the edges or "leaves" of a schema tree. Edges can branch into sub-nodes with createDetails().
|
|
507
492
|
*/
|
|
508
493
|
function createEdges({ name, schema, required, discriminator, }) {
|
|
509
|
-
var _a, _b, _c, _d;
|
|
494
|
+
var _a, _b, _c, _d, _e;
|
|
510
495
|
if (SCHEMA_TYPE === "request") {
|
|
511
496
|
if (schema.readOnly && schema.readOnly === true) {
|
|
512
497
|
return undefined;
|
|
@@ -537,8 +522,8 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
537
522
|
if (((_b = schema.items) === null || _b === void 0 ? void 0 : _b.anyOf) !== undefined || ((_c = schema.items) === null || _c === void 0 ? void 0 : _c.oneOf) !== undefined) {
|
|
538
523
|
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
539
524
|
}
|
|
540
|
-
if (schema.allOf !== undefined) {
|
|
541
|
-
const
|
|
525
|
+
if (((_d = schema.items) === null || _d === void 0 ? void 0 : _d.allOf) !== undefined) {
|
|
526
|
+
const mergedSchemas = mergeAllOf(schema.items);
|
|
542
527
|
if (SCHEMA_TYPE === "request") {
|
|
543
528
|
if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
|
|
544
529
|
return undefined;
|
|
@@ -552,17 +537,17 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
552
537
|
const mergedSchemaName = (0, schema_1.getSchemaName)(mergedSchemas);
|
|
553
538
|
if (mergedSchemas.oneOf !== undefined ||
|
|
554
539
|
mergedSchemas.anyOf !== undefined) {
|
|
555
|
-
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required,
|
|
540
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, mergedSchemas.nullable);
|
|
556
541
|
}
|
|
557
542
|
if (mergedSchemas.properties !== undefined) {
|
|
558
|
-
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required,
|
|
543
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, mergedSchemas.nullable);
|
|
559
544
|
}
|
|
560
545
|
if (mergedSchemas.additionalProperties !== undefined) {
|
|
561
|
-
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required,
|
|
546
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, mergedSchemas.nullable);
|
|
562
547
|
}
|
|
563
548
|
// array of objects
|
|
564
|
-
if (((
|
|
565
|
-
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required,
|
|
549
|
+
if (((_e = mergedSchemas.items) === null || _e === void 0 ? void 0 : _e.properties) !== undefined) {
|
|
550
|
+
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, mergedSchemas.nullable);
|
|
566
551
|
}
|
|
567
552
|
return (0, utils_1.create)("SchemaItem", {
|
|
568
553
|
collapsible: false,
|
|
@@ -616,7 +601,7 @@ function createNodes(schema, schemaType) {
|
|
|
616
601
|
nodes.push(createItems(schema));
|
|
617
602
|
}
|
|
618
603
|
if (schema.allOf !== undefined) {
|
|
619
|
-
const
|
|
604
|
+
const mergedSchemas = mergeAllOf(schema);
|
|
620
605
|
if (mergedSchemas.oneOf !== undefined ||
|
|
621
606
|
mergedSchemas.anyOf !== undefined) {
|
|
622
607
|
nodes.push(createAnyOneOf(mergedSchemas));
|
|
@@ -218,6 +218,54 @@ describe("createNodes", () => {
|
|
|
218
218
|
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
219
219
|
});
|
|
220
220
|
});
|
|
221
|
+
describe("anyOf", () => {
|
|
222
|
+
it("should render primitives within anyOf", async () => {
|
|
223
|
+
const schema = {
|
|
224
|
+
type: "object",
|
|
225
|
+
properties: {
|
|
226
|
+
oneOfProperty: {
|
|
227
|
+
anyOf: [
|
|
228
|
+
{
|
|
229
|
+
type: "integer",
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
type: "boolean",
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
title: "One of int or bool",
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
240
|
+
});
|
|
241
|
+
it("should render oneOf within anyOf", async () => {
|
|
242
|
+
const schema = {
|
|
243
|
+
type: "object",
|
|
244
|
+
properties: {
|
|
245
|
+
oneOfProperty: {
|
|
246
|
+
anyOf: [
|
|
247
|
+
{
|
|
248
|
+
oneOf: [
|
|
249
|
+
{
|
|
250
|
+
type: "integer",
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
type: "boolean",
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
title: "An int or a bool",
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
type: "string",
|
|
260
|
+
},
|
|
261
|
+
],
|
|
262
|
+
title: "One of int or bool, or a string",
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
267
|
+
});
|
|
268
|
+
});
|
|
221
269
|
describe("allOf", () => {
|
|
222
270
|
it("should render same-level properties with allOf", async () => {
|
|
223
271
|
const schema = {
|
|
@@ -5,8 +5,5 @@ interface Props {
|
|
|
5
5
|
label?: string;
|
|
6
6
|
responses: ApiItem["responses"];
|
|
7
7
|
}
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function createResponseExample(responseExample: any, mimeType: string): string;
|
|
10
|
-
export declare function createExampleFromSchema(schema: any, mimeType: string): string | undefined;
|
|
11
|
-
export declare function createStatusCodes({ label, id, responses }: Props): string | undefined;
|
|
8
|
+
export declare function createStatusCodes({ id, label, responses }: Props): string[];
|
|
12
9
|
export {};
|
|
@@ -5,19 +5,9 @@
|
|
|
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
|
-
};
|
|
11
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.createStatusCodes =
|
|
13
|
-
const xml_formatter_1 = __importDefault(require("xml-formatter"));
|
|
14
|
-
const createDescription_1 = require("./createDescription");
|
|
15
|
-
const createDetails_1 = require("./createDetails");
|
|
16
|
-
const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
17
|
-
const createResponseSchema_1 = require("./createResponseSchema");
|
|
9
|
+
exports.createStatusCodes = void 0;
|
|
18
10
|
const utils_1 = require("./utils");
|
|
19
|
-
const utils_2 = require("./utils");
|
|
20
|
-
const createResponseExample_1 = require("../openapi/createResponseExample");
|
|
21
11
|
function json2xml(o, tab) {
|
|
22
12
|
var toXml = function (v, name, ind) {
|
|
23
13
|
var xml = "";
|
|
@@ -61,253 +51,14 @@ function json2xml(o, tab) {
|
|
|
61
51
|
return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, "");
|
|
62
52
|
}
|
|
63
53
|
exports.default = json2xml;
|
|
64
|
-
function
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
className: "schemaItem",
|
|
74
|
-
children: [
|
|
75
|
-
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
76
|
-
children: [
|
|
77
|
-
(0, utils_1.create)("strong", { children: headerName }),
|
|
78
|
-
(0, utils_2.guard)(type, () => [
|
|
79
|
-
(0, utils_1.create)("span", {
|
|
80
|
-
style: { opacity: "0.6" },
|
|
81
|
-
children: ` ${type}`,
|
|
82
|
-
}),
|
|
83
|
-
]),
|
|
84
|
-
],
|
|
85
|
-
}),
|
|
86
|
-
(0, utils_1.create)("div", {
|
|
87
|
-
children: [
|
|
88
|
-
(0, utils_2.guard)(description, (description) => (0, utils_1.create)("div", {
|
|
89
|
-
style: {
|
|
90
|
-
marginTop: ".5rem",
|
|
91
|
-
marginBottom: ".5rem",
|
|
92
|
-
},
|
|
93
|
-
children: [
|
|
94
|
-
(0, utils_2.guard)(example, () => `Example: ${example}`),
|
|
95
|
-
(0, createDescription_1.createDescription)(description),
|
|
96
|
-
],
|
|
97
|
-
})),
|
|
98
|
-
],
|
|
99
|
-
}),
|
|
100
|
-
],
|
|
101
|
-
});
|
|
102
|
-
}),
|
|
103
|
-
],
|
|
104
|
-
}));
|
|
105
|
-
}
|
|
106
|
-
function createResponseExamples(responseExamples, mimeType) {
|
|
107
|
-
let language = "shell";
|
|
108
|
-
if (mimeType.endsWith("json")) {
|
|
109
|
-
language = "json";
|
|
110
|
-
}
|
|
111
|
-
if (mimeType.endsWith("xml")) {
|
|
112
|
-
language = "xml";
|
|
113
|
-
}
|
|
114
|
-
return Object.entries(responseExamples).map(([exampleName, exampleValue]) => {
|
|
115
|
-
if (typeof exampleValue.value === "object") {
|
|
116
|
-
return (0, utils_1.create)("TabItem", {
|
|
117
|
-
label: `${exampleName}`,
|
|
118
|
-
value: `${exampleName}`,
|
|
119
|
-
children: [
|
|
120
|
-
(0, utils_2.guard)(exampleValue.summary, (summary) => [
|
|
121
|
-
(0, utils_1.create)("div", {
|
|
122
|
-
children: `${summary}`,
|
|
123
|
-
className: "openapi-example__summary",
|
|
124
|
-
}),
|
|
125
|
-
]),
|
|
126
|
-
(0, utils_1.create)("ResponseSamples", {
|
|
127
|
-
responseExample: JSON.stringify(exampleValue.value, null, 2),
|
|
128
|
-
language: language,
|
|
129
|
-
}),
|
|
130
|
-
],
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
return (0, utils_1.create)("TabItem", {
|
|
134
|
-
label: `${exampleName}`,
|
|
135
|
-
value: `${exampleName}`,
|
|
136
|
-
children: [
|
|
137
|
-
(0, utils_2.guard)(exampleValue.summary, (summary) => [
|
|
138
|
-
(0, utils_1.create)("div", {
|
|
139
|
-
children: `${summary}`,
|
|
140
|
-
className: "openapi-example__summary",
|
|
141
|
-
}),
|
|
142
|
-
]),
|
|
143
|
-
(0, utils_1.create)("ResponseSamples", {
|
|
144
|
-
responseExample: exampleValue.value,
|
|
145
|
-
language: language,
|
|
146
|
-
}),
|
|
147
|
-
],
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
exports.createResponseExamples = createResponseExamples;
|
|
152
|
-
function createResponseExample(responseExample, mimeType) {
|
|
153
|
-
let language = "shell";
|
|
154
|
-
if (mimeType.endsWith("json")) {
|
|
155
|
-
language = "json";
|
|
156
|
-
}
|
|
157
|
-
if (mimeType.endsWith("xml")) {
|
|
158
|
-
language = "xml";
|
|
159
|
-
}
|
|
160
|
-
if (typeof responseExample === "object") {
|
|
161
|
-
return (0, utils_1.create)("TabItem", {
|
|
162
|
-
label: `Example`,
|
|
163
|
-
value: `Example`,
|
|
164
|
-
children: [
|
|
165
|
-
(0, utils_2.guard)(responseExample.summary, (summary) => [
|
|
166
|
-
(0, utils_1.create)("div", {
|
|
167
|
-
children: `${summary}`,
|
|
168
|
-
className: "openapi-example__summary",
|
|
169
|
-
}),
|
|
170
|
-
]),
|
|
171
|
-
(0, utils_1.create)("ResponseSamples", {
|
|
172
|
-
responseExample: JSON.stringify(responseExample, null, 2),
|
|
173
|
-
language: language,
|
|
174
|
-
}),
|
|
175
|
-
],
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
return (0, utils_1.create)("TabItem", {
|
|
179
|
-
label: `Example`,
|
|
180
|
-
value: `Example`,
|
|
181
|
-
children: [
|
|
182
|
-
(0, utils_2.guard)(responseExample.summary, (summary) => [
|
|
183
|
-
(0, utils_1.create)("div", {
|
|
184
|
-
children: `${summary}`,
|
|
185
|
-
className: "openapi-example__summary",
|
|
186
|
-
}),
|
|
187
|
-
]),
|
|
188
|
-
(0, utils_1.create)("ResponseSamples", {
|
|
189
|
-
responseExample: responseExample,
|
|
190
|
-
language: language,
|
|
191
|
-
}),
|
|
192
|
-
],
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
exports.createResponseExample = createResponseExample;
|
|
196
|
-
function createExampleFromSchema(schema, mimeType) {
|
|
197
|
-
const responseExample = (0, createResponseExample_1.sampleResponseFromSchema)(schema);
|
|
198
|
-
if (mimeType.endsWith("xml")) {
|
|
199
|
-
let responseExampleObject;
|
|
200
|
-
try {
|
|
201
|
-
responseExampleObject = JSON.parse(JSON.stringify(responseExample));
|
|
202
|
-
}
|
|
203
|
-
catch {
|
|
204
|
-
return undefined;
|
|
205
|
-
}
|
|
206
|
-
if (typeof responseExampleObject === "object") {
|
|
207
|
-
let xmlExample;
|
|
208
|
-
try {
|
|
209
|
-
xmlExample = (0, xml_formatter_1.default)(json2xml(responseExampleObject, ""), {
|
|
210
|
-
indentation: " ",
|
|
211
|
-
lineSeparator: "\n",
|
|
212
|
-
collapseContent: true,
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
catch {
|
|
216
|
-
const xmlExampleWithRoot = { root: responseExampleObject };
|
|
217
|
-
try {
|
|
218
|
-
xmlExample = (0, xml_formatter_1.default)(json2xml(xmlExampleWithRoot, ""), {
|
|
219
|
-
indentation: " ",
|
|
220
|
-
lineSeparator: "\n",
|
|
221
|
-
collapseContent: true,
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
catch {
|
|
225
|
-
xmlExample = json2xml(responseExampleObject, "");
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return (0, utils_1.create)("TabItem", {
|
|
229
|
-
label: `Example (from schema)`,
|
|
230
|
-
value: `Example (from schema)`,
|
|
231
|
-
children: [
|
|
232
|
-
(0, utils_1.create)("ResponseSamples", {
|
|
233
|
-
responseExample: xmlExample,
|
|
234
|
-
language: "xml",
|
|
235
|
-
}),
|
|
236
|
-
],
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
if (typeof responseExample === "object") {
|
|
241
|
-
return (0, utils_1.create)("TabItem", {
|
|
242
|
-
label: `Example (from schema)`,
|
|
243
|
-
value: `Example (from schema)`,
|
|
244
|
-
children: [
|
|
245
|
-
(0, utils_1.create)("ResponseSamples", {
|
|
246
|
-
responseExample: JSON.stringify(responseExample, null, 2),
|
|
247
|
-
language: "json",
|
|
248
|
-
}),
|
|
249
|
-
],
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
return undefined;
|
|
253
|
-
}
|
|
254
|
-
exports.createExampleFromSchema = createExampleFromSchema;
|
|
255
|
-
function createStatusCodes({ label, id, responses }) {
|
|
256
|
-
if (responses === undefined) {
|
|
257
|
-
return undefined;
|
|
258
|
-
}
|
|
259
|
-
const codes = Object.keys(responses);
|
|
260
|
-
if (codes.length === 0) {
|
|
261
|
-
return undefined;
|
|
262
|
-
}
|
|
263
|
-
return (0, utils_1.create)("div", {
|
|
264
|
-
children: [
|
|
265
|
-
(0, utils_1.create)("div", {
|
|
266
|
-
children: [
|
|
267
|
-
(0, utils_1.create)("ApiTabs", {
|
|
268
|
-
label,
|
|
269
|
-
id,
|
|
270
|
-
children: codes.map((code) => {
|
|
271
|
-
const responseHeaders = responses[code].headers;
|
|
272
|
-
return (0, utils_1.create)("TabItem", {
|
|
273
|
-
label: code,
|
|
274
|
-
value: code,
|
|
275
|
-
children: [
|
|
276
|
-
(0, utils_1.create)("div", {
|
|
277
|
-
children: (0, createDescription_1.createDescription)(responses[code].description),
|
|
278
|
-
}),
|
|
279
|
-
responseHeaders &&
|
|
280
|
-
(0, createDetails_1.createDetails)({
|
|
281
|
-
className: "openapi-markdown__details",
|
|
282
|
-
"data-collapsed": true,
|
|
283
|
-
open: false,
|
|
284
|
-
style: { textAlign: "left", marginBottom: "1rem" },
|
|
285
|
-
children: [
|
|
286
|
-
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
287
|
-
children: [
|
|
288
|
-
(0, utils_1.create)("strong", {
|
|
289
|
-
children: "Response Headers",
|
|
290
|
-
}),
|
|
291
|
-
],
|
|
292
|
-
}),
|
|
293
|
-
createResponseHeaders(responseHeaders),
|
|
294
|
-
],
|
|
295
|
-
}),
|
|
296
|
-
(0, utils_1.create)("div", {
|
|
297
|
-
children: (0, createResponseSchema_1.createResponseSchema)({
|
|
298
|
-
title: "Schema",
|
|
299
|
-
body: {
|
|
300
|
-
content: responses[code].content,
|
|
301
|
-
},
|
|
302
|
-
}),
|
|
303
|
-
}),
|
|
304
|
-
],
|
|
305
|
-
});
|
|
306
|
-
}),
|
|
307
|
-
}),
|
|
308
|
-
],
|
|
309
|
-
}),
|
|
310
|
-
],
|
|
311
|
-
});
|
|
54
|
+
function createStatusCodes({ id, label, responses }) {
|
|
55
|
+
return [
|
|
56
|
+
(0, utils_1.create)("StatusCodes", {
|
|
57
|
+
id: id,
|
|
58
|
+
label: label,
|
|
59
|
+
responses: responses,
|
|
60
|
+
}),
|
|
61
|
+
"\n\n",
|
|
62
|
+
];
|
|
312
63
|
}
|
|
313
64
|
exports.createStatusCodes = createStatusCodes;
|
package/lib/markdown/index.js
CHANGED
|
@@ -21,7 +21,6 @@ const createMethodEndpoint_1 = require("./createMethodEndpoint");
|
|
|
21
21
|
const createParamsDetails_1 = require("./createParamsDetails");
|
|
22
22
|
const createRequestBodyDetails_1 = require("./createRequestBodyDetails");
|
|
23
23
|
const createRequestHeader_1 = require("./createRequestHeader");
|
|
24
|
-
const createSchema_1 = require("./createSchema");
|
|
25
24
|
const createStatusCodes_1 = require("./createStatusCodes");
|
|
26
25
|
const createTermsOfService_1 = require("./createTermsOfService");
|
|
27
26
|
const createVendorExtensions_1 = require("./createVendorExtensions");
|
|
@@ -29,18 +28,13 @@ const createVersionBadge_1 = require("./createVersionBadge");
|
|
|
29
28
|
const utils_1 = require("./utils");
|
|
30
29
|
function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, method, path, extensions, parameters, requestBody, responses, callbacks, }, infoPath, frontMatter, }) {
|
|
31
30
|
return (0, utils_1.render)([
|
|
32
|
-
`import ApiTabs from "@theme/ApiTabs";\n`,
|
|
33
|
-
`import DiscriminatorTabs from "@theme/DiscriminatorTabs";\n`,
|
|
34
31
|
`import MethodEndpoint from "@theme/ApiExplorer/MethodEndpoint";\n`,
|
|
35
|
-
`import
|
|
36
|
-
`import
|
|
37
|
-
`import
|
|
38
|
-
`import ResponseSamples from "@theme/ResponseSamples";\n`,
|
|
39
|
-
`import SchemaItem from "@theme/SchemaItem";\n`,
|
|
40
|
-
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
41
|
-
`import Heading from "@theme/Heading";\n`,
|
|
32
|
+
`import ParamsDetails from "@theme/ParamsDetails";\n`,
|
|
33
|
+
`import RequestSchema from "@theme/RequestSchema";\n`,
|
|
34
|
+
`import StatusCodes from "@theme/StatusCodes";\n`,
|
|
42
35
|
`import OperationTabs from "@theme/OperationTabs";\n`,
|
|
43
|
-
`import TabItem from "@theme/TabItem";\n
|
|
36
|
+
`import TabItem from "@theme/TabItem";\n`,
|
|
37
|
+
`import Heading from "@theme/Heading";\n\n`,
|
|
44
38
|
(0, createHeading_1.createHeading)(title),
|
|
45
39
|
(0, createMethodEndpoint_1.createMethodEndpoint)(method, path),
|
|
46
40
|
infoPath && (0, createAuthorization_1.createAuthorization)(infoPath),
|
|
@@ -50,10 +44,7 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
|
|
|
50
44
|
(0, createDeprecationNotice_1.createDeprecationNotice)({ deprecated, description: deprecatedDescription }),
|
|
51
45
|
(0, createDescription_1.createDescription)(description),
|
|
52
46
|
requestBody || parameters ? (0, createRequestHeader_1.createRequestHeader)("Request") : undefined,
|
|
53
|
-
(0, createParamsDetails_1.createParamsDetails)({ parameters
|
|
54
|
-
(0, createParamsDetails_1.createParamsDetails)({ parameters, type: "query" }),
|
|
55
|
-
(0, createParamsDetails_1.createParamsDetails)({ parameters, type: "header" }),
|
|
56
|
-
(0, createParamsDetails_1.createParamsDetails)({ parameters, type: "cookie" }),
|
|
47
|
+
(0, createParamsDetails_1.createParamsDetails)({ parameters }),
|
|
57
48
|
(0, createRequestBodyDetails_1.createRequestBodyDetails)({
|
|
58
49
|
title: "Body",
|
|
59
50
|
body: requestBody,
|
|
@@ -89,15 +80,13 @@ exports.createTagPageMD = createTagPageMD;
|
|
|
89
80
|
function createSchemaPageMD({ schema }) {
|
|
90
81
|
const { title = "", description } = schema;
|
|
91
82
|
return (0, utils_1.render)([
|
|
92
|
-
`import
|
|
93
|
-
`import
|
|
94
|
-
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
95
|
-
`import Heading from "@theme/Heading";\n`,
|
|
96
|
-
`import TabItem from "@theme/TabItem";\n\n`,
|
|
83
|
+
`import Schema from "@theme/Schema";\n`,
|
|
84
|
+
`import Heading from "@theme/Heading";\n\n`,
|
|
97
85
|
(0, createHeading_1.createHeading)(title.replace(utils_1.lessThan, "<").replace(utils_1.greaterThan, ">")),
|
|
98
86
|
(0, createDescription_1.createDescription)(description),
|
|
99
|
-
(0, utils_1.create)("
|
|
100
|
-
|
|
87
|
+
(0, utils_1.create)("Schema", {
|
|
88
|
+
schema: schema,
|
|
89
|
+
schemaType: "response",
|
|
101
90
|
}),
|
|
102
91
|
]);
|
|
103
92
|
}
|
package/lib/markdown/utils.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Children in the plugin does not accept DOM elements, when compared with Children in the theme.
|
|
3
|
+
* It is designed for rendering HTML a strings.
|
|
4
|
+
*/
|
|
1
5
|
export type Children = string | undefined | (string | string[] | undefined)[];
|
|
2
6
|
export type Props = Record<string, any> & {
|
|
3
7
|
children?: Children;
|
|
@@ -51,7 +51,7 @@ function sampleRequestFromProp(name, prop, obj) {
|
|
|
51
51
|
obj[name] = (0, exports.sampleRequestFromSchema)(prop.anyOf[0]);
|
|
52
52
|
}
|
|
53
53
|
else if (prop.allOf) {
|
|
54
|
-
const
|
|
54
|
+
const mergedSchemas = (0, createSchema_1.mergeAllOf)(prop);
|
|
55
55
|
sampleRequestFromProp(name, mergedSchemas, obj);
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
@@ -86,7 +86,7 @@ const sampleRequestFromSchema = (schema = {}) => {
|
|
|
86
86
|
return (0, exports.sampleRequestFromSchema)(anyOf[0]);
|
|
87
87
|
}
|
|
88
88
|
if (allOf) {
|
|
89
|
-
const
|
|
89
|
+
const mergedSchemas = (0, createSchema_1.mergeAllOf)(schemaCopy);
|
|
90
90
|
if (mergedSchemas.properties) {
|
|
91
91
|
for (const [key, value] of Object.entries(mergedSchemas.properties)) {
|
|
92
92
|
if ((value.readOnly && value.readOnly === true) || value.deprecated) {
|
|
@@ -51,7 +51,7 @@ function sampleResponseFromProp(name, prop, obj) {
|
|
|
51
51
|
obj[name] = (0, exports.sampleResponseFromSchema)(prop.anyOf[0]);
|
|
52
52
|
}
|
|
53
53
|
else if (prop.allOf) {
|
|
54
|
-
const
|
|
54
|
+
const mergedSchemas = (0, createSchema_1.mergeAllOf)(prop);
|
|
55
55
|
sampleResponseFromProp(name, mergedSchemas, obj);
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
@@ -68,7 +68,7 @@ const sampleResponseFromSchema = (schema = {}) => {
|
|
|
68
68
|
return example;
|
|
69
69
|
}
|
|
70
70
|
if (allOf) {
|
|
71
|
-
const
|
|
71
|
+
const mergedSchemas = (0, createSchema_1.mergeAllOf)(schemaCopy);
|
|
72
72
|
if (mergedSchemas.properties) {
|
|
73
73
|
for (const [key, value] of Object.entries(mergedSchemas.properties)) {
|
|
74
74
|
if ((value.writeOnly && value.writeOnly === true) ||
|