docusaurus-plugin-openapi-docs 0.0.0-430 → 0.0.0-434
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 +98 -87
- package/lib/markdown/createResponseSchema.d.ts +8 -1
- package/lib/markdown/createResponseSchema.js +105 -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 +104 -103
- package/src/markdown/createResponseSchema.ts +111 -107
- 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
|
@@ -26,6 +26,7 @@ export function mergeAllOf(allOf: SchemaObject[]) {
|
|
|
26
26
|
example: function () {
|
|
27
27
|
return true;
|
|
28
28
|
},
|
|
29
|
+
ignoreAdditionalProperties: true,
|
|
29
30
|
},
|
|
30
31
|
});
|
|
31
32
|
|
|
@@ -286,106 +287,106 @@ function createItems(schema: SchemaObject) {
|
|
|
286
287
|
/**
|
|
287
288
|
* For handling discriminators that do not map to a same-level property
|
|
288
289
|
*/
|
|
289
|
-
function createDiscriminator(schema: SchemaObject) {
|
|
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
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
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
|
-
}
|
|
290
|
+
// function createDiscriminator(schema: SchemaObject) {
|
|
291
|
+
// const discriminator = schema.discriminator;
|
|
292
|
+
// const propertyName = discriminator?.propertyName;
|
|
293
|
+
// const propertyType = "string"; // should always be string
|
|
294
|
+
// const mapping: any = discriminator?.mapping;
|
|
295
|
+
|
|
296
|
+
// // Explicit mapping is required since we can't support implicit
|
|
297
|
+
// if (mapping === undefined) {
|
|
298
|
+
// return undefined;
|
|
299
|
+
// }
|
|
300
|
+
|
|
301
|
+
// // Attempt to get the property description we want to display
|
|
302
|
+
// // TODO: how to make it predictable when handling allOf
|
|
303
|
+
// let propertyDescription;
|
|
304
|
+
// const firstMappingSchema = mapping[Object.keys(mapping)[0]];
|
|
305
|
+
// if (firstMappingSchema.properties !== undefined) {
|
|
306
|
+
// propertyDescription =
|
|
307
|
+
// firstMappingSchema.properties![propertyName!].description;
|
|
308
|
+
// }
|
|
309
|
+
// if (firstMappingSchema.allOf !== undefined) {
|
|
310
|
+
// const { mergedSchemas }: { mergedSchemas: SchemaObject } = mergeAllOf(
|
|
311
|
+
// firstMappingSchema.allOf
|
|
312
|
+
// );
|
|
313
|
+
// if (mergedSchemas.properties !== undefined) {
|
|
314
|
+
// propertyDescription =
|
|
315
|
+
// mergedSchemas.properties[propertyName!]?.description;
|
|
316
|
+
// }
|
|
317
|
+
// }
|
|
318
|
+
|
|
319
|
+
// if (propertyDescription === undefined) {
|
|
320
|
+
// if (
|
|
321
|
+
// schema.properties !== undefined &&
|
|
322
|
+
// schema.properties![propertyName!] !== undefined
|
|
323
|
+
// ) {
|
|
324
|
+
// propertyDescription = schema.properties![propertyName!].description;
|
|
325
|
+
// }
|
|
326
|
+
// }
|
|
327
|
+
|
|
328
|
+
// return create("div", {
|
|
329
|
+
// className: "discriminatorItem",
|
|
330
|
+
// children: create("div", {
|
|
331
|
+
// children: [
|
|
332
|
+
// create("strong", {
|
|
333
|
+
// style: { paddingLeft: "1rem" },
|
|
334
|
+
// children: propertyName,
|
|
335
|
+
// }),
|
|
336
|
+
// guard(propertyType, (name) =>
|
|
337
|
+
// create("span", {
|
|
338
|
+
// style: { opacity: "0.6" },
|
|
339
|
+
// children: ` ${propertyType}`,
|
|
340
|
+
// })
|
|
341
|
+
// ),
|
|
342
|
+
// guard(getQualifierMessage(schema.discriminator as any), (message) =>
|
|
343
|
+
// create("div", {
|
|
344
|
+
// style: {
|
|
345
|
+
// paddingLeft: "1rem",
|
|
346
|
+
// },
|
|
347
|
+
// children: createDescription(message),
|
|
348
|
+
// })
|
|
349
|
+
// ),
|
|
350
|
+
// guard(propertyDescription, (description) =>
|
|
351
|
+
// create("div", {
|
|
352
|
+
// style: {
|
|
353
|
+
// paddingLeft: "1rem",
|
|
354
|
+
// },
|
|
355
|
+
// children: createDescription(description),
|
|
356
|
+
// })
|
|
357
|
+
// ),
|
|
358
|
+
// create("DiscriminatorTabs", {
|
|
359
|
+
// children: Object.keys(mapping!).map((key, index) => {
|
|
360
|
+
// if (mapping[key].allOf !== undefined) {
|
|
361
|
+
// const { mergedSchemas }: { mergedSchemas: SchemaObject } =
|
|
362
|
+
// mergeAllOf(mapping[key].allOf);
|
|
363
|
+
// // Cleanup duplicate property from mapping schema
|
|
364
|
+
// delete mergedSchemas.properties![propertyName!];
|
|
365
|
+
// mapping[key] = mergedSchemas;
|
|
366
|
+
// }
|
|
367
|
+
|
|
368
|
+
// if (mapping[key].properties !== undefined) {
|
|
369
|
+
// // Cleanup duplicate property from mapping schema
|
|
370
|
+
// delete mapping[key].properties![propertyName!];
|
|
371
|
+
// }
|
|
372
|
+
|
|
373
|
+
// const label = key;
|
|
374
|
+
// return create("TabItem", {
|
|
375
|
+
// label: label,
|
|
376
|
+
// value: `${index}-item-discriminator`,
|
|
377
|
+
// children: [
|
|
378
|
+
// create("div", {
|
|
379
|
+
// style: { marginLeft: "-4px" },
|
|
380
|
+
// children: createNodes(mapping[key]),
|
|
381
|
+
// }),
|
|
382
|
+
// ],
|
|
383
|
+
// });
|
|
384
|
+
// }),
|
|
385
|
+
// }),
|
|
386
|
+
// ],
|
|
387
|
+
// }),
|
|
388
|
+
// });
|
|
389
|
+
// }
|
|
389
390
|
|
|
390
391
|
function createDetailsNode(
|
|
391
392
|
name: string,
|
|
@@ -624,9 +625,9 @@ function createEdges({
|
|
|
624
625
|
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
625
626
|
*/
|
|
626
627
|
function createNodes(schema: SchemaObject): any {
|
|
627
|
-
if (schema.discriminator !== undefined) {
|
|
628
|
-
|
|
629
|
-
}
|
|
628
|
+
// if (schema.discriminator !== undefined) {
|
|
629
|
+
// return createDiscriminator(schema);
|
|
630
|
+
// }
|
|
630
631
|
|
|
631
632
|
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
632
633
|
return createAnyOneOf(schema);
|
|
@@ -10,6 +10,7 @@ import { createDescription } from "./createDescription";
|
|
|
10
10
|
import { createDetails } from "./createDetails";
|
|
11
11
|
import { createDetailsSummary } from "./createDetailsSummary";
|
|
12
12
|
import {
|
|
13
|
+
createExampleFromSchema,
|
|
13
14
|
createResponseExample,
|
|
14
15
|
createResponseExamples,
|
|
15
16
|
} from "./createStatusCodes";
|
|
@@ -21,7 +22,7 @@ const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
|
|
|
21
22
|
/**
|
|
22
23
|
* Returns a merged representation of allOf array of schemas.
|
|
23
24
|
*/
|
|
24
|
-
function mergeAllOf(allOf: SchemaObject[]) {
|
|
25
|
+
export function mergeAllOf(allOf: SchemaObject[]) {
|
|
25
26
|
const mergedSchemas = jsonSchemaMergeAllOf(allOf, {
|
|
26
27
|
resolvers: {
|
|
27
28
|
readOnly: function () {
|
|
@@ -31,6 +32,7 @@ function mergeAllOf(allOf: SchemaObject[]) {
|
|
|
31
32
|
return true;
|
|
32
33
|
},
|
|
33
34
|
},
|
|
35
|
+
ignoreAdditionalProperties: true,
|
|
34
36
|
});
|
|
35
37
|
|
|
36
38
|
const required = allOf.reduce((acc, cur) => {
|
|
@@ -290,106 +292,106 @@ function createItems(schema: SchemaObject) {
|
|
|
290
292
|
/**
|
|
291
293
|
* For handling discriminators that do not map to a same-level property
|
|
292
294
|
*/
|
|
293
|
-
function createDiscriminator(schema: SchemaObject) {
|
|
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
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
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
|
-
}
|
|
295
|
+
// function createDiscriminator(schema: SchemaObject) {
|
|
296
|
+
// const discriminator = schema.discriminator;
|
|
297
|
+
// const propertyName = discriminator?.propertyName;
|
|
298
|
+
// const propertyType = "string"; // should always be string
|
|
299
|
+
// const mapping: any = discriminator?.mapping;
|
|
300
|
+
|
|
301
|
+
// // Explicit mapping is required since we can't support implicit
|
|
302
|
+
// if (mapping === undefined) {
|
|
303
|
+
// return undefined;
|
|
304
|
+
// }
|
|
305
|
+
|
|
306
|
+
// // Attempt to get the property description we want to display
|
|
307
|
+
// // TODO: how to make it predictable when handling allOf
|
|
308
|
+
// let propertyDescription;
|
|
309
|
+
// const firstMappingSchema = mapping[Object.keys(mapping)[0]];
|
|
310
|
+
// if (firstMappingSchema.properties !== undefined) {
|
|
311
|
+
// propertyDescription =
|
|
312
|
+
// firstMappingSchema.properties![propertyName!].description;
|
|
313
|
+
// }
|
|
314
|
+
// if (firstMappingSchema.allOf !== undefined) {
|
|
315
|
+
// const { mergedSchemas }: { mergedSchemas: SchemaObject } = mergeAllOf(
|
|
316
|
+
// firstMappingSchema.allOf
|
|
317
|
+
// );
|
|
318
|
+
// if (mergedSchemas.properties !== undefined) {
|
|
319
|
+
// propertyDescription =
|
|
320
|
+
// mergedSchemas.properties[propertyName!]?.description;
|
|
321
|
+
// }
|
|
322
|
+
// }
|
|
323
|
+
|
|
324
|
+
// if (propertyDescription === undefined) {
|
|
325
|
+
// if (
|
|
326
|
+
// schema.properties !== undefined &&
|
|
327
|
+
// schema.properties![propertyName!] !== undefined
|
|
328
|
+
// ) {
|
|
329
|
+
// propertyDescription = schema.properties![propertyName!].description;
|
|
330
|
+
// }
|
|
331
|
+
// }
|
|
332
|
+
|
|
333
|
+
// return create("div", {
|
|
334
|
+
// className: "discriminatorItem",
|
|
335
|
+
// children: create("div", {
|
|
336
|
+
// children: [
|
|
337
|
+
// create("strong", {
|
|
338
|
+
// style: { paddingLeft: "1rem" },
|
|
339
|
+
// children: propertyName,
|
|
340
|
+
// }),
|
|
341
|
+
// guard(propertyType, (name) =>
|
|
342
|
+
// create("span", {
|
|
343
|
+
// style: { opacity: "0.6" },
|
|
344
|
+
// children: ` ${propertyType}`,
|
|
345
|
+
// })
|
|
346
|
+
// ),
|
|
347
|
+
// guard(getQualifierMessage(schema.discriminator as any), (message) =>
|
|
348
|
+
// create("div", {
|
|
349
|
+
// style: {
|
|
350
|
+
// paddingLeft: "1rem",
|
|
351
|
+
// },
|
|
352
|
+
// children: createDescription(message),
|
|
353
|
+
// })
|
|
354
|
+
// ),
|
|
355
|
+
// guard(propertyDescription, (description) =>
|
|
356
|
+
// create("div", {
|
|
357
|
+
// style: {
|
|
358
|
+
// paddingLeft: "1rem",
|
|
359
|
+
// },
|
|
360
|
+
// children: createDescription(description),
|
|
361
|
+
// })
|
|
362
|
+
// ),
|
|
363
|
+
// create("DiscriminatorTabs", {
|
|
364
|
+
// children: Object.keys(mapping!).map((key, index) => {
|
|
365
|
+
// if (mapping[key].allOf !== undefined) {
|
|
366
|
+
// const { mergedSchemas }: { mergedSchemas: SchemaObject } =
|
|
367
|
+
// mergeAllOf(mapping[key].allOf);
|
|
368
|
+
// // Cleanup duplicate property from mapping schema
|
|
369
|
+
// delete mergedSchemas.properties![propertyName!];
|
|
370
|
+
// mapping[key] = mergedSchemas;
|
|
371
|
+
// }
|
|
372
|
+
|
|
373
|
+
// if (mapping[key].properties !== undefined) {
|
|
374
|
+
// // Cleanup duplicate property from mapping schema
|
|
375
|
+
// delete mapping[key].properties![propertyName!];
|
|
376
|
+
// }
|
|
377
|
+
|
|
378
|
+
// const label = key;
|
|
379
|
+
// return create("TabItem", {
|
|
380
|
+
// label: label,
|
|
381
|
+
// value: `${index}-item-discriminator`,
|
|
382
|
+
// children: [
|
|
383
|
+
// create("div", {
|
|
384
|
+
// style: { marginLeft: "-4px" },
|
|
385
|
+
// children: createNodes(mapping[key]),
|
|
386
|
+
// }),
|
|
387
|
+
// ],
|
|
388
|
+
// });
|
|
389
|
+
// }),
|
|
390
|
+
// }),
|
|
391
|
+
// ],
|
|
392
|
+
// }),
|
|
393
|
+
// });
|
|
394
|
+
// }
|
|
393
395
|
|
|
394
396
|
function createDetailsNode(
|
|
395
397
|
name: string,
|
|
@@ -628,9 +630,9 @@ function createEdges({
|
|
|
628
630
|
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
629
631
|
*/
|
|
630
632
|
function createNodes(schema: SchemaObject): any {
|
|
631
|
-
if (schema.discriminator !== undefined) {
|
|
632
|
-
|
|
633
|
-
}
|
|
633
|
+
// if (schema.discriminator !== undefined) {
|
|
634
|
+
// return createDiscriminator(schema);
|
|
635
|
+
// }
|
|
634
636
|
|
|
635
637
|
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
636
638
|
return createAnyOneOf(schema);
|
|
@@ -638,7 +640,6 @@ function createNodes(schema: SchemaObject): any {
|
|
|
638
640
|
|
|
639
641
|
if (schema.allOf !== undefined) {
|
|
640
642
|
const { mergedSchemas } = mergeAllOf(schema.allOf);
|
|
641
|
-
|
|
642
643
|
// allOf seems to always result in properties
|
|
643
644
|
if (mergedSchemas.properties !== undefined) {
|
|
644
645
|
return createProperties(mergedSchemas);
|
|
@@ -803,8 +804,11 @@ export function createResponseSchema({ title, body, ...rest }: Props) {
|
|
|
803
804
|
}),
|
|
804
805
|
],
|
|
805
806
|
}),
|
|
806
|
-
|
|
807
|
-
|
|
807
|
+
firstBody && createExampleFromSchema(firstBody, mimeType),
|
|
808
|
+
responseExamples &&
|
|
809
|
+
createResponseExamples(responseExamples, mimeType),
|
|
810
|
+
responseExample &&
|
|
811
|
+
createResponseExample(responseExample, mimeType),
|
|
808
812
|
],
|
|
809
813
|
}),
|
|
810
814
|
],
|