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.
@@ -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
- const discriminator = schema.discriminator;
291
- const propertyName = discriminator?.propertyName;
292
- const propertyType = "string"; // should always be string
293
- const mapping: any = discriminator?.mapping;
294
-
295
- // Explicit mapping is required since we can't support implicit
296
- if (mapping === undefined) {
297
- return undefined;
298
- }
299
-
300
- // Attempt to get the property description we want to display
301
- // TODO: how to make it predictable when handling allOf
302
- let propertyDescription;
303
- const firstMappingSchema = mapping[Object.keys(mapping)[0]];
304
- if (firstMappingSchema.properties !== undefined) {
305
- propertyDescription =
306
- firstMappingSchema.properties![propertyName!].description;
307
- }
308
- if (firstMappingSchema.allOf !== undefined) {
309
- const { mergedSchemas }: { mergedSchemas: SchemaObject } = mergeAllOf(
310
- firstMappingSchema.allOf
311
- );
312
- if (mergedSchemas.properties !== undefined) {
313
- propertyDescription =
314
- mergedSchemas.properties[propertyName!]?.description;
315
- }
316
- }
317
-
318
- if (propertyDescription === undefined) {
319
- if (
320
- schema.properties !== undefined &&
321
- schema.properties![propertyName!] !== undefined
322
- ) {
323
- propertyDescription = schema.properties![propertyName!].description;
324
- }
325
- }
326
-
327
- return create("div", {
328
- className: "discriminatorItem",
329
- children: create("div", {
330
- children: [
331
- create("strong", {
332
- style: { paddingLeft: "1rem" },
333
- children: propertyName,
334
- }),
335
- guard(propertyType, (name) =>
336
- create("span", {
337
- style: { opacity: "0.6" },
338
- children: ` ${propertyType}`,
339
- })
340
- ),
341
- guard(getQualifierMessage(schema.discriminator as any), (message) =>
342
- create("div", {
343
- style: {
344
- paddingLeft: "1rem",
345
- },
346
- children: createDescription(message),
347
- })
348
- ),
349
- guard(propertyDescription, (description) =>
350
- create("div", {
351
- style: {
352
- paddingLeft: "1rem",
353
- },
354
- children: createDescription(description),
355
- })
356
- ),
357
- create("DiscriminatorTabs", {
358
- children: Object.keys(mapping!).map((key, index) => {
359
- if (mapping[key].allOf !== undefined) {
360
- const { mergedSchemas }: { mergedSchemas: SchemaObject } =
361
- mergeAllOf(mapping[key].allOf);
362
- // Cleanup duplicate property from mapping schema
363
- delete mergedSchemas.properties![propertyName!];
364
- mapping[key] = mergedSchemas;
365
- }
366
-
367
- if (mapping[key].properties !== undefined) {
368
- // Cleanup duplicate property from mapping schema
369
- delete mapping[key].properties![propertyName!];
370
- }
371
-
372
- const label = key;
373
- return create("TabItem", {
374
- label: label,
375
- value: `${index}-item-discriminator`,
376
- children: [
377
- create("div", {
378
- style: { marginLeft: "-4px" },
379
- children: createNodes(mapping[key]),
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
- return createDiscriminator(schema);
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
- const discriminator = schema.discriminator;
295
- const propertyName = discriminator?.propertyName;
296
- const propertyType = "string"; // should always be string
297
- const mapping: any = discriminator?.mapping;
298
-
299
- // Explicit mapping is required since we can't support implicit
300
- if (mapping === undefined) {
301
- return undefined;
302
- }
303
-
304
- // Attempt to get the property description we want to display
305
- // TODO: how to make it predictable when handling allOf
306
- let propertyDescription;
307
- const firstMappingSchema = mapping[Object.keys(mapping)[0]];
308
- if (firstMappingSchema.properties !== undefined) {
309
- propertyDescription =
310
- firstMappingSchema.properties![propertyName!].description;
311
- }
312
- if (firstMappingSchema.allOf !== undefined) {
313
- const { mergedSchemas }: { mergedSchemas: SchemaObject } = mergeAllOf(
314
- firstMappingSchema.allOf
315
- );
316
- if (mergedSchemas.properties !== undefined) {
317
- propertyDescription =
318
- mergedSchemas.properties[propertyName!]?.description;
319
- }
320
- }
321
-
322
- if (propertyDescription === undefined) {
323
- if (
324
- schema.properties !== undefined &&
325
- schema.properties![propertyName!] !== undefined
326
- ) {
327
- propertyDescription = schema.properties![propertyName!].description;
328
- }
329
- }
330
-
331
- return create("div", {
332
- className: "discriminatorItem",
333
- children: create("div", {
334
- children: [
335
- create("strong", {
336
- style: { paddingLeft: "1rem" },
337
- children: propertyName,
338
- }),
339
- guard(propertyType, (name) =>
340
- create("span", {
341
- style: { opacity: "0.6" },
342
- children: ` ${propertyType}`,
343
- })
344
- ),
345
- guard(getQualifierMessage(schema.discriminator as any), (message) =>
346
- create("div", {
347
- style: {
348
- paddingLeft: "1rem",
349
- },
350
- children: createDescription(message),
351
- })
352
- ),
353
- guard(propertyDescription, (description) =>
354
- create("div", {
355
- style: {
356
- paddingLeft: "1rem",
357
- },
358
- children: createDescription(description),
359
- })
360
- ),
361
- create("DiscriminatorTabs", {
362
- children: Object.keys(mapping!).map((key, index) => {
363
- if (mapping[key].allOf !== undefined) {
364
- const { mergedSchemas }: { mergedSchemas: SchemaObject } =
365
- mergeAllOf(mapping[key].allOf);
366
- // Cleanup duplicate property from mapping schema
367
- delete mergedSchemas.properties![propertyName!];
368
- mapping[key] = mergedSchemas;
369
- }
370
-
371
- if (mapping[key].properties !== undefined) {
372
- // Cleanup duplicate property from mapping schema
373
- delete mapping[key].properties![propertyName!];
374
- }
375
-
376
- const label = key;
377
- return create("TabItem", {
378
- label: label,
379
- value: `${index}-item-discriminator`,
380
- children: [
381
- create("div", {
382
- style: { marginLeft: "-4px" },
383
- children: createNodes(mapping[key]),
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
- return createDiscriminator(schema);
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
- responseExamples && createResponseExamples(responseExamples),
807
- responseExample && createResponseExample(responseExample),
807
+ firstBody && createExampleFromSchema(firstBody, mimeType),
808
+ responseExamples &&
809
+ createResponseExamples(responseExamples, mimeType),
810
+ responseExample &&
811
+ createResponseExample(responseExample, mimeType),
808
812
  ],
809
813
  }),
810
814
  ],