docusaurus-plugin-openapi-docs 1.1.8 → 1.1.9

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.
@@ -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
- var _a;
240
- const discriminator = schema.discriminator;
241
- const propertyName = discriminator === null || discriminator === void 0 ? void 0 : discriminator.propertyName;
242
- const propertyType = "string"; // should always be string
243
- const mapping = discriminator === null || discriminator === void 0 ? void 0 : 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 } = mergeAllOf(firstMappingSchema.allOf);
258
- if (mergedSchemas.properties !== undefined) {
259
- propertyDescription =
260
- (_a = mergedSchemas.properties[propertyName]) === null || _a === void 0 ? void 0 : _a.description;
261
- }
262
- }
263
- if (propertyDescription === undefined) {
264
- if (schema.properties !== undefined &&
265
- schema.properties[propertyName] !== undefined) {
266
- propertyDescription = schema.properties[propertyName].description;
267
- }
268
- }
269
- return (0, utils_1.create)("div", {
270
- className: "discriminatorItem",
271
- children: (0, utils_1.create)("div", {
272
- children: [
273
- (0, utils_1.create)("strong", {
274
- style: { paddingLeft: "1rem" },
275
- children: propertyName,
276
- }),
277
- (0, utils_1.guard)(propertyType, (name) => (0, utils_1.create)("span", {
278
- style: { opacity: "0.6" },
279
- children: ` ${propertyType}`,
280
- })),
281
- (0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema.discriminator), (message) => (0, utils_1.create)("div", {
282
- style: {
283
- paddingLeft: "1rem",
284
- },
285
- children: (0, createDescription_1.createDescription)(message),
286
- })),
287
- (0, utils_1.guard)(propertyDescription, (description) => (0, utils_1.create)("div", {
288
- style: {
289
- paddingLeft: "1rem",
290
- },
291
- children: (0, createDescription_1.createDescription)(description),
292
- })),
293
- (0, utils_1.create)("DiscriminatorTabs", {
294
- children: Object.keys(mapping).map((key, index) => {
295
- if (mapping[key].allOf !== undefined) {
296
- const { mergedSchemas } = mergeAllOf(mapping[key].allOf);
297
- // Cleanup duplicate property from mapping schema
298
- delete mergedSchemas.properties[propertyName];
299
- mapping[key] = mergedSchemas;
300
- }
301
- if (mapping[key].properties !== undefined) {
302
- // Cleanup duplicate property from mapping schema
303
- delete mapping[key].properties[propertyName];
304
- }
305
- const label = key;
306
- return (0, utils_1.create)("TabItem", {
307
- label: label,
308
- value: `${index}-item-discriminator`,
309
- children: [
310
- (0, utils_1.create)("div", {
311
- style: { marginLeft: "-4px" },
312
- children: createNodes(mapping[key]),
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
- return createDiscriminator(schema);
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
- var _a;
240
- const discriminator = schema.discriminator;
241
- const propertyName = discriminator === null || discriminator === void 0 ? void 0 : discriminator.propertyName;
242
- const propertyType = "string"; // should always be string
243
- const mapping = discriminator === null || discriminator === void 0 ? void 0 : 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 } = mergeAllOf(firstMappingSchema.allOf);
258
- if (mergedSchemas.properties !== undefined) {
259
- propertyDescription =
260
- (_a = mergedSchemas.properties[propertyName]) === null || _a === void 0 ? void 0 : _a.description;
261
- }
262
- }
263
- if (propertyDescription === undefined) {
264
- if (schema.properties !== undefined &&
265
- schema.properties[propertyName] !== undefined) {
266
- propertyDescription = schema.properties[propertyName].description;
267
- }
268
- }
269
- return (0, utils_1.create)("div", {
270
- className: "discriminatorItem",
271
- children: (0, utils_1.create)("div", {
272
- children: [
273
- (0, utils_1.create)("strong", {
274
- style: { paddingLeft: "1rem" },
275
- children: propertyName,
276
- }),
277
- (0, utils_1.guard)(propertyType, (name) => (0, utils_1.create)("span", {
278
- style: { opacity: "0.6" },
279
- children: ` ${propertyType}`,
280
- })),
281
- (0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema.discriminator), (message) => (0, utils_1.create)("div", {
282
- style: {
283
- paddingLeft: "1rem",
284
- },
285
- children: (0, createDescription_1.createDescription)(message),
286
- })),
287
- (0, utils_1.guard)(propertyDescription, (description) => (0, utils_1.create)("div", {
288
- style: {
289
- paddingLeft: "1rem",
290
- },
291
- children: (0, createDescription_1.createDescription)(description),
292
- })),
293
- (0, utils_1.create)("DiscriminatorTabs", {
294
- children: Object.keys(mapping).map((key, index) => {
295
- if (mapping[key].allOf !== undefined) {
296
- const { mergedSchemas } = mergeAllOf(mapping[key].allOf);
297
- // Cleanup duplicate property from mapping schema
298
- delete mergedSchemas.properties[propertyName];
299
- mapping[key] = mergedSchemas;
300
- }
301
- if (mapping[key].properties !== undefined) {
302
- // Cleanup duplicate property from mapping schema
303
- delete mapping[key].properties[propertyName];
304
- }
305
- const label = key;
306
- return (0, utils_1.create)("TabItem", {
307
- label: label,
308
- value: `${index}-item-discriminator`,
309
- children: [
310
- (0, utils_1.create)("div", {
311
- style: { marginLeft: "-4px" },
312
- children: createNodes(mapping[key]),
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
- return createDiscriminator(schema);
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
  }
@@ -627,8 +639,11 @@ function createResponseSchema({ title, body, ...rest }) {
627
639
  }),
628
640
  ],
629
641
  }),
630
- responseExamples && (0, createStatusCodes_1.createResponseExamples)(responseExamples),
631
- responseExample && (0, createStatusCodes_1.createResponseExample)(responseExample),
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 {};