docusaurus-plugin-openapi-docs 3.0.1 → 4.0.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 +5 -4
- package/lib/index.js +9 -0
- package/lib/markdown/createSchema.js +112 -82
- package/lib/markdown/createSchema.test.js +247 -29
- package/lib/markdown/createStatusCodes.js +12 -8
- package/lib/markdown/index.js +0 -1
- package/lib/openapi/createRequestExample.js +2 -2
- package/lib/openapi/createResponseExample.js +2 -2
- package/package.json +2 -2
- package/src/index.ts +12 -0
- package/src/markdown/__snapshots__/createSchema.test.ts.snap +220 -56
- package/src/markdown/createSchema.test.ts +290 -34
- package/src/markdown/createSchema.ts +149 -128
- package/src/markdown/createStatusCodes.ts +12 -8
- package/src/markdown/index.ts +0 -1
- package/src/openapi/createRequestExample.ts +2 -2
- package/src/openapi/createResponseExample.ts +2 -2
package/README.md
CHANGED
|
@@ -41,16 +41,17 @@ Key Features:
|
|
|
41
41
|
|
|
42
42
|
| Docusaurus OpenAPI Docs | Docusaurus |
|
|
43
43
|
| ----------------------- | --------------- |
|
|
44
|
-
|
|
|
45
|
-
|
|
|
46
|
-
|
|
|
44
|
+
| 4.0.0 (current) | `3.5.0 - 3.5.2` |
|
|
45
|
+
| 3.0.2 (legacy) | `3.0.1 - 3.4.0` |
|
|
46
|
+
| 2.2.1 (legacy) | `2.4.1 - 2.4.3` |
|
|
47
|
+
| 1.7.3 (end-of-support) | `2.0.1 - 2.2.0` |
|
|
47
48
|
|
|
48
49
|
## Bootstrapping from Template (new Docusaurus site)
|
|
49
50
|
|
|
50
51
|
Run the following to bootstrap a Docsaurus v3 site (classic theme) with `docusaurus-openapi-docs`:
|
|
51
52
|
|
|
52
53
|
```bash
|
|
53
|
-
npx create-docusaurus@3.
|
|
54
|
+
npx create-docusaurus@3.5.2my-website --package-manager yarn
|
|
54
55
|
```
|
|
55
56
|
|
|
56
57
|
> When prompted to select a template choose `Git repository`.
|
package/lib/index.js
CHANGED
|
@@ -375,6 +375,15 @@ custom_edit_url: null
|
|
|
375
375
|
downloadUrl: metadata.downloadUrl,
|
|
376
376
|
});
|
|
377
377
|
}
|
|
378
|
+
if (!fs_1.default.existsSync(outputDir)) {
|
|
379
|
+
try {
|
|
380
|
+
fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
381
|
+
console.log(chalk_1.default.green(`Successfully created "${outputDir}"`));
|
|
382
|
+
}
|
|
383
|
+
catch (err) {
|
|
384
|
+
console.error(chalk_1.default.red(`Failed to create "${outputDir}"`), chalk_1.default.yellow(err));
|
|
385
|
+
}
|
|
386
|
+
}
|
|
378
387
|
const versionsJson = JSON.stringify(versionsArray, null, 2);
|
|
379
388
|
try {
|
|
380
389
|
fs_1.default.writeFileSync(`${outputDir}/versions.json`, versionsJson + "\n", "utf8");
|
|
@@ -61,6 +61,7 @@ function createAnyOneOf(schema) {
|
|
|
61
61
|
(0, utils_1.create)("span", {
|
|
62
62
|
className: "badge badge--info",
|
|
63
63
|
children: type,
|
|
64
|
+
style: { marginBottom: "1rem" },
|
|
64
65
|
}),
|
|
65
66
|
(0, utils_1.create)("SchemaTabs", {
|
|
66
67
|
children: schema[type].map((anyOneSchema, index) => {
|
|
@@ -68,6 +69,19 @@ function createAnyOneOf(schema) {
|
|
|
68
69
|
? anyOneSchema.title
|
|
69
70
|
: `MOD${index + 1}`;
|
|
70
71
|
const anyOneChildren = [];
|
|
72
|
+
if (anyOneSchema.description) {
|
|
73
|
+
anyOneChildren.push((0, utils_1.create)("div", {
|
|
74
|
+
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
75
|
+
className: "openapi-schema__summary",
|
|
76
|
+
children: (0, createDescription_1.createDescription)(anyOneSchema.description),
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
if (anyOneSchema.type === "object" &&
|
|
80
|
+
!anyOneSchema.properties &&
|
|
81
|
+
!anyOneSchema.allOf &&
|
|
82
|
+
!anyOneSchema.items) {
|
|
83
|
+
anyOneChildren.push(createNodes(anyOneSchema, SCHEMA_TYPE));
|
|
84
|
+
}
|
|
71
85
|
if (anyOneSchema.properties !== undefined) {
|
|
72
86
|
anyOneChildren.push(createProperties(anyOneSchema));
|
|
73
87
|
delete anyOneSchema.properties;
|
|
@@ -352,63 +366,79 @@ function createDetailsNode(name, schemaName, schema, required, nullable) {
|
|
|
352
366
|
/**
|
|
353
367
|
* For handling anyOf/oneOf properties.
|
|
354
368
|
*/
|
|
355
|
-
function createAnyOneOfProperty(
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
369
|
+
// function createAnyOneOfProperty(
|
|
370
|
+
// name: string,
|
|
371
|
+
// schemaName: string,
|
|
372
|
+
// schema: SchemaObject,
|
|
373
|
+
// required: string[] | boolean,
|
|
374
|
+
// nullable: boolean | unknown
|
|
375
|
+
// ): any {
|
|
376
|
+
// return create("SchemaItem", {
|
|
377
|
+
// collapsible: true,
|
|
378
|
+
// className: "schemaItem",
|
|
379
|
+
// children: [
|
|
380
|
+
// createDetails({
|
|
381
|
+
// className: "openapi-markdown__details",
|
|
382
|
+
// children: [
|
|
383
|
+
// createDetailsSummary({
|
|
384
|
+
// children: [
|
|
385
|
+
// create("strong", { children: name }),
|
|
386
|
+
// create("span", {
|
|
387
|
+
// style: { opacity: "0.6" },
|
|
388
|
+
// children: ` ${schemaName}`,
|
|
389
|
+
// }),
|
|
390
|
+
// guard(
|
|
391
|
+
// (schema.nullable && schema.nullable === true) ||
|
|
392
|
+
// (nullable && nullable === true),
|
|
393
|
+
// () => [
|
|
394
|
+
// create("strong", {
|
|
395
|
+
// style: {
|
|
396
|
+
// fontSize: "var(--ifm-code-font-size)",
|
|
397
|
+
// color: "var(--openapi-nullable)",
|
|
398
|
+
// },
|
|
399
|
+
// children: " nullable",
|
|
400
|
+
// }),
|
|
401
|
+
// ]
|
|
402
|
+
// ),
|
|
403
|
+
// guard(
|
|
404
|
+
// Array.isArray(required)
|
|
405
|
+
// ? required.includes(name)
|
|
406
|
+
// : required === true,
|
|
407
|
+
// () => [
|
|
408
|
+
// create("strong", {
|
|
409
|
+
// style: {
|
|
410
|
+
// fontSize: "var(--ifm-code-font-size)",
|
|
411
|
+
// color: "var(--openapi-required)",
|
|
412
|
+
// },
|
|
413
|
+
// children: " required",
|
|
414
|
+
// }),
|
|
415
|
+
// ]
|
|
416
|
+
// ),
|
|
417
|
+
// ],
|
|
418
|
+
// }),
|
|
419
|
+
// create("div", {
|
|
420
|
+
// style: { marginLeft: "1rem" },
|
|
421
|
+
// children: [
|
|
422
|
+
// guard(getQualifierMessage(schema), (message) =>
|
|
423
|
+
// create("div", {
|
|
424
|
+
// style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
425
|
+
// children: createDescription(message),
|
|
426
|
+
// })
|
|
427
|
+
// ),
|
|
428
|
+
// guard(schema.description, (description) =>
|
|
429
|
+
// create("div", {
|
|
430
|
+
// style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
431
|
+
// children: createDescription(description),
|
|
432
|
+
// })
|
|
433
|
+
// ),
|
|
434
|
+
// ],
|
|
435
|
+
// }),
|
|
436
|
+
// createAnyOneOf(schema),
|
|
437
|
+
// ],
|
|
438
|
+
// }),
|
|
439
|
+
// ],
|
|
440
|
+
// });
|
|
441
|
+
// }
|
|
412
442
|
/**
|
|
413
443
|
* For handling discriminators that map to a same-level property (like 'petType').
|
|
414
444
|
* Note: These should only be encountered while iterating through properties.
|
|
@@ -491,7 +521,20 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
491
521
|
return createPropertyDiscriminator(name, "string", schema, discriminator, required);
|
|
492
522
|
}
|
|
493
523
|
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
494
|
-
return
|
|
524
|
+
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
525
|
+
}
|
|
526
|
+
if (schema.properties !== undefined) {
|
|
527
|
+
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
528
|
+
}
|
|
529
|
+
if (schema.additionalProperties !== undefined) {
|
|
530
|
+
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
531
|
+
}
|
|
532
|
+
// array of objects
|
|
533
|
+
if (((_a = schema.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
|
|
534
|
+
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
535
|
+
}
|
|
536
|
+
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) {
|
|
537
|
+
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
495
538
|
}
|
|
496
539
|
if (schema.allOf !== undefined) {
|
|
497
540
|
const { mergedSchemas } = mergeAllOf(schema.allOf);
|
|
@@ -517,7 +560,7 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
517
560
|
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
518
561
|
}
|
|
519
562
|
// array of objects
|
|
520
|
-
if (((
|
|
563
|
+
if (((_d = mergedSchemas.items) === null || _d === void 0 ? void 0 : _d.properties) !== undefined) {
|
|
521
564
|
return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
|
|
522
565
|
}
|
|
523
566
|
return (0, utils_1.create)("SchemaItem", {
|
|
@@ -529,19 +572,6 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
529
572
|
schema: mergedSchemas,
|
|
530
573
|
});
|
|
531
574
|
}
|
|
532
|
-
if (schema.properties !== undefined) {
|
|
533
|
-
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
534
|
-
}
|
|
535
|
-
if (schema.additionalProperties !== undefined) {
|
|
536
|
-
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
537
|
-
}
|
|
538
|
-
// array of objects
|
|
539
|
-
if (((_b = schema.items) === null || _b === void 0 ? void 0 : _b.properties) !== undefined) {
|
|
540
|
-
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
541
|
-
}
|
|
542
|
-
if (((_c = schema.items) === null || _c === void 0 ? void 0 : _c.anyOf) !== undefined || ((_d = schema.items) === null || _d === void 0 ? void 0 : _d.oneOf) !== undefined) {
|
|
543
|
-
return createDetailsNode(name, schemaName, schema, required, schema.nullable);
|
|
544
|
-
}
|
|
545
575
|
// primitives and array of non-objects
|
|
546
576
|
return (0, utils_1.create)("SchemaItem", {
|
|
547
577
|
collapsible: false,
|
|
@@ -574,16 +604,6 @@ function createNodes(schema, schemaType) {
|
|
|
574
604
|
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
575
605
|
nodes.push(createAnyOneOf(schema));
|
|
576
606
|
}
|
|
577
|
-
if (schema.allOf !== undefined) {
|
|
578
|
-
const { mergedSchemas } = mergeAllOf(schema.allOf);
|
|
579
|
-
if (mergedSchemas.oneOf !== undefined ||
|
|
580
|
-
mergedSchemas.anyOf !== undefined) {
|
|
581
|
-
nodes.push(createAnyOneOf(mergedSchemas));
|
|
582
|
-
}
|
|
583
|
-
if (mergedSchemas.properties !== undefined) {
|
|
584
|
-
nodes.push(createProperties(mergedSchemas));
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
607
|
if (schema.properties !== undefined) {
|
|
588
608
|
nodes.push(createProperties(schema));
|
|
589
609
|
}
|
|
@@ -594,6 +614,16 @@ function createNodes(schema, schemaType) {
|
|
|
594
614
|
if (schema.items !== undefined) {
|
|
595
615
|
nodes.push(createItems(schema));
|
|
596
616
|
}
|
|
617
|
+
if (schema.allOf !== undefined) {
|
|
618
|
+
const { mergedSchemas } = mergeAllOf(schema.allOf);
|
|
619
|
+
if (mergedSchemas.oneOf !== undefined ||
|
|
620
|
+
mergedSchemas.anyOf !== undefined) {
|
|
621
|
+
nodes.push(createAnyOneOf(mergedSchemas));
|
|
622
|
+
}
|
|
623
|
+
if (mergedSchemas.properties !== undefined) {
|
|
624
|
+
nodes.push(createProperties(mergedSchemas));
|
|
625
|
+
}
|
|
626
|
+
}
|
|
597
627
|
if (nodes.length && nodes.length > 0) {
|
|
598
628
|
return nodes.filter(Boolean).flat();
|
|
599
629
|
}
|
|
@@ -32,44 +32,262 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
const prettier = __importStar(require("prettier"));
|
|
33
33
|
const createSchema_1 = require("./createSchema");
|
|
34
34
|
describe("createNodes", () => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
35
|
+
describe("oneOf", () => {
|
|
36
|
+
it("should create readable MODs for oneOf primitive properties", async () => {
|
|
37
|
+
const schema = {
|
|
38
|
+
"x-tags": ["clown"],
|
|
39
|
+
type: "object",
|
|
40
|
+
properties: {
|
|
41
|
+
oneOfProperty: {
|
|
42
|
+
oneOf: [
|
|
43
|
+
{
|
|
44
|
+
type: "object",
|
|
45
|
+
properties: {
|
|
46
|
+
noseLength: {
|
|
47
|
+
type: "number",
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
required: ["noseLength"],
|
|
51
|
+
description: "Clown's nose length",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
type: "array",
|
|
55
|
+
items: {
|
|
56
|
+
type: "string",
|
|
47
57
|
},
|
|
58
|
+
description: "Array of strings",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
type: "boolean",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
type: "number",
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
type: "string",
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "request").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
describe("allOf", () => {
|
|
77
|
+
it("should render same-level properties with allOf", async () => {
|
|
78
|
+
const schema = {
|
|
79
|
+
allOf: [
|
|
80
|
+
{
|
|
81
|
+
type: "object",
|
|
82
|
+
properties: {
|
|
83
|
+
allOfProp1: {
|
|
84
|
+
type: "string",
|
|
85
|
+
},
|
|
86
|
+
allOfProp2: {
|
|
87
|
+
type: "string",
|
|
48
88
|
},
|
|
49
|
-
required: ["noseLength"],
|
|
50
|
-
description: "Clown's nose length",
|
|
51
89
|
},
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
properties: {
|
|
93
|
+
parentProp1: {
|
|
94
|
+
type: "string",
|
|
95
|
+
},
|
|
96
|
+
parentProp2: {
|
|
97
|
+
type: "string",
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
102
|
+
});
|
|
103
|
+
it("should correctly merge nested properties from multiple allOf schemas", async () => {
|
|
104
|
+
const schema = {
|
|
105
|
+
allOf: [
|
|
106
|
+
{
|
|
107
|
+
type: "object",
|
|
108
|
+
properties: {
|
|
109
|
+
outerProp1: {
|
|
110
|
+
type: "object",
|
|
111
|
+
properties: {
|
|
112
|
+
innerProp1: {
|
|
113
|
+
type: "string",
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
type: "object",
|
|
121
|
+
properties: {
|
|
122
|
+
outerProp2: {
|
|
123
|
+
type: "object",
|
|
124
|
+
properties: {
|
|
125
|
+
innerProp2: {
|
|
126
|
+
type: "number",
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
};
|
|
134
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
135
|
+
});
|
|
136
|
+
it("should correctly handle shared required properties across allOf schemas", async () => {
|
|
137
|
+
const schema = {
|
|
138
|
+
allOf: [
|
|
139
|
+
{
|
|
140
|
+
type: "object",
|
|
141
|
+
properties: {
|
|
142
|
+
sharedProp: {
|
|
55
143
|
type: "string",
|
|
56
144
|
},
|
|
57
|
-
description: "Array of strings",
|
|
58
145
|
},
|
|
59
|
-
|
|
60
|
-
|
|
146
|
+
required: ["sharedProp"],
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
type: "object",
|
|
150
|
+
properties: {
|
|
151
|
+
anotherProp: {
|
|
152
|
+
type: "number",
|
|
153
|
+
},
|
|
61
154
|
},
|
|
62
|
-
|
|
63
|
-
|
|
155
|
+
required: ["anotherProp"],
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
};
|
|
159
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
160
|
+
});
|
|
161
|
+
// Could not resolve values for path:"properties.conflictingProp.type". They are probably incompatible. Values:
|
|
162
|
+
// "string"
|
|
163
|
+
// "number"
|
|
164
|
+
// eslint-disable-next-line jest/no-commented-out-tests
|
|
165
|
+
// it("should handle conflicting properties in allOf schemas", async () => {
|
|
166
|
+
// const schema: SchemaObject = {
|
|
167
|
+
// allOf: [
|
|
168
|
+
// {
|
|
169
|
+
// type: "object",
|
|
170
|
+
// properties: {
|
|
171
|
+
// conflictingProp: {
|
|
172
|
+
// type: "string",
|
|
173
|
+
// },
|
|
174
|
+
// },
|
|
175
|
+
// },
|
|
176
|
+
// {
|
|
177
|
+
// type: "object",
|
|
178
|
+
// properties: {
|
|
179
|
+
// conflictingProp: {
|
|
180
|
+
// type: "number",
|
|
181
|
+
// },
|
|
182
|
+
// },
|
|
183
|
+
// },
|
|
184
|
+
// ],
|
|
185
|
+
// };
|
|
186
|
+
// expect(
|
|
187
|
+
// await Promise.all(
|
|
188
|
+
// createNodes(schema, "response").map(
|
|
189
|
+
// async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
190
|
+
// )
|
|
191
|
+
// )
|
|
192
|
+
// ).toMatchSnapshot();
|
|
193
|
+
// });
|
|
194
|
+
// Could not resolve values for path:"type". They are probably incompatible. Values:
|
|
195
|
+
// "object"
|
|
196
|
+
// "array"
|
|
197
|
+
// eslint-disable-next-line jest/no-commented-out-tests
|
|
198
|
+
// it("should handle mixed data types in allOf schemas", async () => {
|
|
199
|
+
// const schema: SchemaObject = {
|
|
200
|
+
// allOf: [
|
|
201
|
+
// {
|
|
202
|
+
// type: "object",
|
|
203
|
+
// properties: {
|
|
204
|
+
// mixedTypeProp1: {
|
|
205
|
+
// type: "string",
|
|
206
|
+
// },
|
|
207
|
+
// },
|
|
208
|
+
// },
|
|
209
|
+
// {
|
|
210
|
+
// type: "array",
|
|
211
|
+
// items: {
|
|
212
|
+
// type: "number",
|
|
213
|
+
// },
|
|
214
|
+
// },
|
|
215
|
+
// ],
|
|
216
|
+
// };
|
|
217
|
+
// expect(
|
|
218
|
+
// await Promise.all(
|
|
219
|
+
// createNodes(schema, "response").map(
|
|
220
|
+
// async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
221
|
+
// )
|
|
222
|
+
// )
|
|
223
|
+
// ).toMatchSnapshot();
|
|
224
|
+
// });
|
|
225
|
+
it("should correctly deep merge properties in allOf schemas", async () => {
|
|
226
|
+
const schema = {
|
|
227
|
+
allOf: [
|
|
228
|
+
{
|
|
229
|
+
type: "object",
|
|
230
|
+
properties: {
|
|
231
|
+
deepProp: {
|
|
232
|
+
type: "object",
|
|
233
|
+
properties: {
|
|
234
|
+
innerProp1: {
|
|
235
|
+
type: "string",
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
},
|
|
64
239
|
},
|
|
65
|
-
|
|
66
|
-
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
type: "object",
|
|
243
|
+
properties: {
|
|
244
|
+
deepProp: {
|
|
245
|
+
type: "object",
|
|
246
|
+
properties: {
|
|
247
|
+
innerProp2: {
|
|
248
|
+
type: "number",
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
},
|
|
67
252
|
},
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
};
|
|
256
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "response").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
257
|
+
});
|
|
258
|
+
// eslint-disable-next-line jest/no-commented-out-tests
|
|
259
|
+
// it("should handle discriminator with allOf schemas", async () => {
|
|
260
|
+
// const schema: SchemaObject = {
|
|
261
|
+
// allOf: [
|
|
262
|
+
// {
|
|
263
|
+
// type: "object",
|
|
264
|
+
// discriminator: {
|
|
265
|
+
// propertyName: "type",
|
|
266
|
+
// },
|
|
267
|
+
// properties: {
|
|
268
|
+
// type: {
|
|
269
|
+
// type: "string",
|
|
270
|
+
// },
|
|
271
|
+
// },
|
|
272
|
+
// },
|
|
273
|
+
// {
|
|
274
|
+
// type: "object",
|
|
275
|
+
// properties: {
|
|
276
|
+
// specificProp: {
|
|
277
|
+
// type: "string",
|
|
278
|
+
// },
|
|
279
|
+
// },
|
|
280
|
+
// },
|
|
281
|
+
// ],
|
|
282
|
+
// };
|
|
283
|
+
// expect(
|
|
284
|
+
// await Promise.all(
|
|
285
|
+
// createNodes(schema, "response").map(
|
|
286
|
+
// async (md: any) => await prettier.format(md, { parser: "babel" })
|
|
287
|
+
// )
|
|
288
|
+
// )
|
|
289
|
+
// ).toMatchSnapshot();
|
|
290
|
+
// });
|
|
73
291
|
});
|
|
74
292
|
describe("additionalProperties", () => {
|
|
75
293
|
it.each([
|
|
@@ -118,8 +118,9 @@ function createResponseExamples(responseExamples, mimeType) {
|
|
|
118
118
|
value: `${exampleName}`,
|
|
119
119
|
children: [
|
|
120
120
|
(0, utils_2.guard)(exampleValue.summary, (summary) => [
|
|
121
|
-
(0, utils_1.create)("
|
|
122
|
-
children:
|
|
121
|
+
(0, utils_1.create)("div", {
|
|
122
|
+
children: `${summary}`,
|
|
123
|
+
className: "openapi-example__summary",
|
|
123
124
|
}),
|
|
124
125
|
]),
|
|
125
126
|
(0, utils_1.create)("ResponseSamples", {
|
|
@@ -134,8 +135,9 @@ function createResponseExamples(responseExamples, mimeType) {
|
|
|
134
135
|
value: `${exampleName}`,
|
|
135
136
|
children: [
|
|
136
137
|
(0, utils_2.guard)(exampleValue.summary, (summary) => [
|
|
137
|
-
(0, utils_1.create)("
|
|
138
|
-
children:
|
|
138
|
+
(0, utils_1.create)("div", {
|
|
139
|
+
children: `${summary}`,
|
|
140
|
+
className: "openapi-example__summary",
|
|
139
141
|
}),
|
|
140
142
|
]),
|
|
141
143
|
(0, utils_1.create)("ResponseSamples", {
|
|
@@ -161,8 +163,9 @@ function createResponseExample(responseExample, mimeType) {
|
|
|
161
163
|
value: `Example`,
|
|
162
164
|
children: [
|
|
163
165
|
(0, utils_2.guard)(responseExample.summary, (summary) => [
|
|
164
|
-
(0, utils_1.create)("
|
|
165
|
-
children:
|
|
166
|
+
(0, utils_1.create)("div", {
|
|
167
|
+
children: `${summary}`,
|
|
168
|
+
className: "openapi-example__summary",
|
|
166
169
|
}),
|
|
167
170
|
]),
|
|
168
171
|
(0, utils_1.create)("ResponseSamples", {
|
|
@@ -177,8 +180,9 @@ function createResponseExample(responseExample, mimeType) {
|
|
|
177
180
|
value: `Example`,
|
|
178
181
|
children: [
|
|
179
182
|
(0, utils_2.guard)(responseExample.summary, (summary) => [
|
|
180
|
-
(0, utils_1.create)("
|
|
181
|
-
children:
|
|
183
|
+
(0, utils_1.create)("div", {
|
|
184
|
+
children: `${summary}`,
|
|
185
|
+
className: "openapi-example__summary",
|
|
182
186
|
}),
|
|
183
187
|
]),
|
|
184
188
|
(0, utils_1.create)("ResponseSamples", {
|
package/lib/markdown/index.js
CHANGED
|
@@ -38,7 +38,6 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
|
|
|
38
38
|
`import ResponseSamples from "@theme/ResponseSamples";\n`,
|
|
39
39
|
`import SchemaItem from "@theme/SchemaItem";\n`,
|
|
40
40
|
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
41
|
-
`import Markdown from "@theme/Markdown";\n`,
|
|
42
41
|
`import Heading from "@theme/Heading";\n`,
|
|
43
42
|
`import OperationTabs from "@theme/OperationTabs";\n`,
|
|
44
43
|
`import TabItem from "@theme/TabItem";\n\n`,
|
|
@@ -17,8 +17,8 @@ const primitives = {
|
|
|
17
17
|
string: {
|
|
18
18
|
default: () => "string",
|
|
19
19
|
email: () => "user@example.com",
|
|
20
|
-
date: () =>
|
|
21
|
-
"date-time": () =>
|
|
20
|
+
date: () => "2024-07-29",
|
|
21
|
+
"date-time": () => "2024-07-29T15:51:28.071Z",
|
|
22
22
|
uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
|
23
23
|
hostname: () => "example.com",
|
|
24
24
|
ipv4: () => "198.51.100.42",
|
|
@@ -17,8 +17,8 @@ const primitives = {
|
|
|
17
17
|
string: {
|
|
18
18
|
default: () => "string",
|
|
19
19
|
email: () => "user@example.com",
|
|
20
|
-
date: () =>
|
|
21
|
-
"date-time": () =>
|
|
20
|
+
date: () => "2024-07-29",
|
|
21
|
+
"date-time": () => "2024-07-29T15:51:28.071Z",
|
|
22
22
|
uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
|
23
23
|
hostname: () => "example.com",
|
|
24
24
|
ipv4: () => "198.51.100.42",
|