docusaurus-plugin-openapi-docs 1.1.7 → 1.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/lib/markdown/createRequestSchema.js +98 -87
- package/lib/markdown/createResponseSchema.d.ts +8 -1
- package/lib/markdown/createResponseSchema.js +106 -91
- 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 +5 -3
- package/src/markdown/createRequestSchema.ts +104 -103
- package/src/markdown/createResponseSchema.ts +112 -108
- 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/markdown/createSchemaDetails.d.ts +0 -14
- package/lib/markdown/createSchemaDetails.js +0 -674
- package/lib/openapi/createExample.d.ts +0 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Palo Alto Networks
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -25,6 +25,7 @@ function mergeAllOf(allOf) {
|
|
|
25
25
|
example: function () {
|
|
26
26
|
return true;
|
|
27
27
|
},
|
|
28
|
+
ignoreAdditionalProperties: true,
|
|
28
29
|
},
|
|
29
30
|
});
|
|
30
31
|
const required = allOf.reduce((acc, cur) => {
|
|
@@ -235,90 +236,100 @@ function createItems(schema) {
|
|
|
235
236
|
/**
|
|
236
237
|
* For handling discriminators that do not map to a same-level property
|
|
237
238
|
*/
|
|
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
|
-
}
|
|
239
|
+
// function createDiscriminator(schema: SchemaObject) {
|
|
240
|
+
// const discriminator = schema.discriminator;
|
|
241
|
+
// const propertyName = discriminator?.propertyName;
|
|
242
|
+
// const propertyType = "string"; // should always be string
|
|
243
|
+
// const mapping: any = discriminator?.mapping;
|
|
244
|
+
// // Explicit mapping is required since we can't support implicit
|
|
245
|
+
// if (mapping === undefined) {
|
|
246
|
+
// return undefined;
|
|
247
|
+
// }
|
|
248
|
+
// // Attempt to get the property description we want to display
|
|
249
|
+
// // TODO: how to make it predictable when handling allOf
|
|
250
|
+
// let propertyDescription;
|
|
251
|
+
// const firstMappingSchema = mapping[Object.keys(mapping)[0]];
|
|
252
|
+
// if (firstMappingSchema.properties !== undefined) {
|
|
253
|
+
// propertyDescription =
|
|
254
|
+
// firstMappingSchema.properties![propertyName!].description;
|
|
255
|
+
// }
|
|
256
|
+
// if (firstMappingSchema.allOf !== undefined) {
|
|
257
|
+
// const { mergedSchemas }: { mergedSchemas: SchemaObject } = mergeAllOf(
|
|
258
|
+
// firstMappingSchema.allOf
|
|
259
|
+
// );
|
|
260
|
+
// if (mergedSchemas.properties !== undefined) {
|
|
261
|
+
// propertyDescription =
|
|
262
|
+
// mergedSchemas.properties[propertyName!]?.description;
|
|
263
|
+
// }
|
|
264
|
+
// }
|
|
265
|
+
// if (propertyDescription === undefined) {
|
|
266
|
+
// if (
|
|
267
|
+
// schema.properties !== undefined &&
|
|
268
|
+
// schema.properties![propertyName!] !== undefined
|
|
269
|
+
// ) {
|
|
270
|
+
// propertyDescription = schema.properties![propertyName!].description;
|
|
271
|
+
// }
|
|
272
|
+
// }
|
|
273
|
+
// return create("div", {
|
|
274
|
+
// className: "discriminatorItem",
|
|
275
|
+
// children: create("div", {
|
|
276
|
+
// children: [
|
|
277
|
+
// create("strong", {
|
|
278
|
+
// style: { paddingLeft: "1rem" },
|
|
279
|
+
// children: propertyName,
|
|
280
|
+
// }),
|
|
281
|
+
// guard(propertyType, (name) =>
|
|
282
|
+
// create("span", {
|
|
283
|
+
// style: { opacity: "0.6" },
|
|
284
|
+
// children: ` ${propertyType}`,
|
|
285
|
+
// })
|
|
286
|
+
// ),
|
|
287
|
+
// guard(getQualifierMessage(schema.discriminator as any), (message) =>
|
|
288
|
+
// create("div", {
|
|
289
|
+
// style: {
|
|
290
|
+
// paddingLeft: "1rem",
|
|
291
|
+
// },
|
|
292
|
+
// children: createDescription(message),
|
|
293
|
+
// })
|
|
294
|
+
// ),
|
|
295
|
+
// guard(propertyDescription, (description) =>
|
|
296
|
+
// create("div", {
|
|
297
|
+
// style: {
|
|
298
|
+
// paddingLeft: "1rem",
|
|
299
|
+
// },
|
|
300
|
+
// children: createDescription(description),
|
|
301
|
+
// })
|
|
302
|
+
// ),
|
|
303
|
+
// create("DiscriminatorTabs", {
|
|
304
|
+
// children: Object.keys(mapping!).map((key, index) => {
|
|
305
|
+
// if (mapping[key].allOf !== undefined) {
|
|
306
|
+
// const { mergedSchemas }: { mergedSchemas: SchemaObject } =
|
|
307
|
+
// mergeAllOf(mapping[key].allOf);
|
|
308
|
+
// // Cleanup duplicate property from mapping schema
|
|
309
|
+
// delete mergedSchemas.properties![propertyName!];
|
|
310
|
+
// mapping[key] = mergedSchemas;
|
|
311
|
+
// }
|
|
312
|
+
// if (mapping[key].properties !== undefined) {
|
|
313
|
+
// // Cleanup duplicate property from mapping schema
|
|
314
|
+
// delete mapping[key].properties![propertyName!];
|
|
315
|
+
// }
|
|
316
|
+
// const label = key;
|
|
317
|
+
// return create("TabItem", {
|
|
318
|
+
// label: label,
|
|
319
|
+
// value: `${index}-item-discriminator`,
|
|
320
|
+
// children: [
|
|
321
|
+
// create("div", {
|
|
322
|
+
// style: { marginLeft: "-4px" },
|
|
323
|
+
// children: createNodes(mapping[key]),
|
|
324
|
+
// }),
|
|
325
|
+
// ],
|
|
326
|
+
// });
|
|
327
|
+
// }),
|
|
328
|
+
// }),
|
|
329
|
+
// ],
|
|
330
|
+
// }),
|
|
331
|
+
// });
|
|
332
|
+
// }
|
|
322
333
|
function createDetailsNode(name, schemaName, schema, required) {
|
|
323
334
|
return (0, utils_1.create)("SchemaItem", {
|
|
324
335
|
collapsible: true,
|
|
@@ -493,9 +504,9 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
493
504
|
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
494
505
|
*/
|
|
495
506
|
function createNodes(schema) {
|
|
496
|
-
if (schema.discriminator !== undefined) {
|
|
497
|
-
|
|
498
|
-
}
|
|
507
|
+
// if (schema.discriminator !== undefined) {
|
|
508
|
+
// return createDiscriminator(schema);
|
|
509
|
+
// }
|
|
499
510
|
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
500
511
|
return createAnyOneOf(schema);
|
|
501
512
|
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import { MediaTypeObject } from "../openapi/types";
|
|
1
|
+
import { MediaTypeObject, SchemaObject } from "../openapi/types";
|
|
2
|
+
/**
|
|
3
|
+
* Returns a merged representation of allOf array of schemas.
|
|
4
|
+
*/
|
|
5
|
+
export declare function mergeAllOf(allOf: SchemaObject[]): {
|
|
6
|
+
mergedSchemas: any;
|
|
7
|
+
required: any;
|
|
8
|
+
};
|
|
2
9
|
interface Props {
|
|
3
10
|
style?: any;
|
|
4
11
|
title: string;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
* ========================================================================== */
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.createResponseSchema = void 0;
|
|
9
|
+
exports.createResponseSchema = exports.mergeAllOf = void 0;
|
|
10
10
|
const createDescription_1 = require("./createDescription");
|
|
11
11
|
const createDetails_1 = require("./createDetails");
|
|
12
12
|
const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
@@ -27,6 +27,7 @@ function mergeAllOf(allOf) {
|
|
|
27
27
|
return true;
|
|
28
28
|
},
|
|
29
29
|
},
|
|
30
|
+
ignoreAdditionalProperties: true,
|
|
30
31
|
});
|
|
31
32
|
const required = allOf.reduce((acc, cur) => {
|
|
32
33
|
if (Array.isArray(cur.required)) {
|
|
@@ -37,6 +38,7 @@ function mergeAllOf(allOf) {
|
|
|
37
38
|
}, []);
|
|
38
39
|
return { mergedSchemas, required };
|
|
39
40
|
}
|
|
41
|
+
exports.mergeAllOf = mergeAllOf;
|
|
40
42
|
/**
|
|
41
43
|
* For handling nested anyOf/oneOf.
|
|
42
44
|
*/
|
|
@@ -235,90 +237,100 @@ function createItems(schema) {
|
|
|
235
237
|
/**
|
|
236
238
|
* For handling discriminators that do not map to a same-level property
|
|
237
239
|
*/
|
|
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
|
-
}
|
|
240
|
+
// function createDiscriminator(schema: SchemaObject) {
|
|
241
|
+
// const discriminator = schema.discriminator;
|
|
242
|
+
// const propertyName = discriminator?.propertyName;
|
|
243
|
+
// const propertyType = "string"; // should always be string
|
|
244
|
+
// const mapping: any = discriminator?.mapping;
|
|
245
|
+
// // Explicit mapping is required since we can't support implicit
|
|
246
|
+
// if (mapping === undefined) {
|
|
247
|
+
// return undefined;
|
|
248
|
+
// }
|
|
249
|
+
// // Attempt to get the property description we want to display
|
|
250
|
+
// // TODO: how to make it predictable when handling allOf
|
|
251
|
+
// let propertyDescription;
|
|
252
|
+
// const firstMappingSchema = mapping[Object.keys(mapping)[0]];
|
|
253
|
+
// if (firstMappingSchema.properties !== undefined) {
|
|
254
|
+
// propertyDescription =
|
|
255
|
+
// firstMappingSchema.properties![propertyName!].description;
|
|
256
|
+
// }
|
|
257
|
+
// if (firstMappingSchema.allOf !== undefined) {
|
|
258
|
+
// const { mergedSchemas }: { mergedSchemas: SchemaObject } = mergeAllOf(
|
|
259
|
+
// firstMappingSchema.allOf
|
|
260
|
+
// );
|
|
261
|
+
// if (mergedSchemas.properties !== undefined) {
|
|
262
|
+
// propertyDescription =
|
|
263
|
+
// mergedSchemas.properties[propertyName!]?.description;
|
|
264
|
+
// }
|
|
265
|
+
// }
|
|
266
|
+
// if (propertyDescription === undefined) {
|
|
267
|
+
// if (
|
|
268
|
+
// schema.properties !== undefined &&
|
|
269
|
+
// schema.properties![propertyName!] !== undefined
|
|
270
|
+
// ) {
|
|
271
|
+
// propertyDescription = schema.properties![propertyName!].description;
|
|
272
|
+
// }
|
|
273
|
+
// }
|
|
274
|
+
// return create("div", {
|
|
275
|
+
// className: "discriminatorItem",
|
|
276
|
+
// children: create("div", {
|
|
277
|
+
// children: [
|
|
278
|
+
// create("strong", {
|
|
279
|
+
// style: { paddingLeft: "1rem" },
|
|
280
|
+
// children: propertyName,
|
|
281
|
+
// }),
|
|
282
|
+
// guard(propertyType, (name) =>
|
|
283
|
+
// create("span", {
|
|
284
|
+
// style: { opacity: "0.6" },
|
|
285
|
+
// children: ` ${propertyType}`,
|
|
286
|
+
// })
|
|
287
|
+
// ),
|
|
288
|
+
// guard(getQualifierMessage(schema.discriminator as any), (message) =>
|
|
289
|
+
// create("div", {
|
|
290
|
+
// style: {
|
|
291
|
+
// paddingLeft: "1rem",
|
|
292
|
+
// },
|
|
293
|
+
// children: createDescription(message),
|
|
294
|
+
// })
|
|
295
|
+
// ),
|
|
296
|
+
// guard(propertyDescription, (description) =>
|
|
297
|
+
// create("div", {
|
|
298
|
+
// style: {
|
|
299
|
+
// paddingLeft: "1rem",
|
|
300
|
+
// },
|
|
301
|
+
// children: createDescription(description),
|
|
302
|
+
// })
|
|
303
|
+
// ),
|
|
304
|
+
// create("DiscriminatorTabs", {
|
|
305
|
+
// children: Object.keys(mapping!).map((key, index) => {
|
|
306
|
+
// if (mapping[key].allOf !== undefined) {
|
|
307
|
+
// const { mergedSchemas }: { mergedSchemas: SchemaObject } =
|
|
308
|
+
// mergeAllOf(mapping[key].allOf);
|
|
309
|
+
// // Cleanup duplicate property from mapping schema
|
|
310
|
+
// delete mergedSchemas.properties![propertyName!];
|
|
311
|
+
// mapping[key] = mergedSchemas;
|
|
312
|
+
// }
|
|
313
|
+
// if (mapping[key].properties !== undefined) {
|
|
314
|
+
// // Cleanup duplicate property from mapping schema
|
|
315
|
+
// delete mapping[key].properties![propertyName!];
|
|
316
|
+
// }
|
|
317
|
+
// const label = key;
|
|
318
|
+
// return create("TabItem", {
|
|
319
|
+
// label: label,
|
|
320
|
+
// value: `${index}-item-discriminator`,
|
|
321
|
+
// children: [
|
|
322
|
+
// create("div", {
|
|
323
|
+
// style: { marginLeft: "-4px" },
|
|
324
|
+
// children: createNodes(mapping[key]),
|
|
325
|
+
// }),
|
|
326
|
+
// ],
|
|
327
|
+
// });
|
|
328
|
+
// }),
|
|
329
|
+
// }),
|
|
330
|
+
// ],
|
|
331
|
+
// }),
|
|
332
|
+
// });
|
|
333
|
+
// }
|
|
322
334
|
function createDetailsNode(name, schemaName, schema, required) {
|
|
323
335
|
return (0, utils_1.create)("SchemaItem", {
|
|
324
336
|
collapsible: true,
|
|
@@ -493,9 +505,9 @@ function createEdges({ name, schema, required, discriminator, }) {
|
|
|
493
505
|
* Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
|
|
494
506
|
*/
|
|
495
507
|
function createNodes(schema) {
|
|
496
|
-
if (schema.discriminator !== undefined) {
|
|
497
|
-
|
|
498
|
-
}
|
|
508
|
+
// if (schema.discriminator !== undefined) {
|
|
509
|
+
// return createDiscriminator(schema);
|
|
510
|
+
// }
|
|
499
511
|
if (schema.oneOf !== undefined || schema.anyOf !== undefined) {
|
|
500
512
|
return createAnyOneOf(schema);
|
|
501
513
|
}
|
|
@@ -577,7 +589,7 @@ function createResponseSchema({ title, body, ...rest }) {
|
|
|
577
589
|
groupId: "schema-tabs",
|
|
578
590
|
children: [
|
|
579
591
|
firstBody &&
|
|
580
|
-
(0, utils_1.create)("
|
|
592
|
+
(0, utils_1.create)("TabItem", {
|
|
581
593
|
label: `${title}`,
|
|
582
594
|
value: `${title}`,
|
|
583
595
|
children: [
|
|
@@ -627,8 +639,11 @@ function createResponseSchema({ title, body, ...rest }) {
|
|
|
627
639
|
}),
|
|
628
640
|
],
|
|
629
641
|
}),
|
|
630
|
-
|
|
631
|
-
|
|
642
|
+
firstBody && (0, createStatusCodes_1.createExampleFromSchema)(firstBody, mimeType),
|
|
643
|
+
responseExamples &&
|
|
644
|
+
(0, createStatusCodes_1.createResponseExamples)(responseExamples, mimeType),
|
|
645
|
+
responseExample &&
|
|
646
|
+
(0, createStatusCodes_1.createResponseExample)(responseExample, mimeType),
|
|
632
647
|
],
|
|
633
648
|
}),
|
|
634
649
|
],
|
|
@@ -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 {};
|