docusaurus-plugin-openapi-docs 2.0.0 → 2.0.2

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.
@@ -74,7 +74,7 @@ function createRequestSchema({ title, body, ...rest }) {
74
74
  }),
75
75
  (0, utils_1.create)("ul", {
76
76
  style: { marginLeft: "1rem" },
77
- children: (0, createSchema_1.createNodes)(firstBody),
77
+ children: (0, createSchema_1.createNodes)(firstBody, "request"),
78
78
  }),
79
79
  ],
80
80
  }),
@@ -139,7 +139,7 @@ function createRequestSchema({ title, body, ...rest }) {
139
139
  }),
140
140
  (0, utils_1.create)("ul", {
141
141
  style: { marginLeft: "1rem" },
142
- children: (0, createSchema_1.createNodes)(firstBody),
142
+ children: (0, createSchema_1.createNodes)(firstBody, "request"),
143
143
  }),
144
144
  ],
145
145
  }),
@@ -89,7 +89,7 @@ function createResponseSchema({ title, body, ...rest }) {
89
89
  }),
90
90
  (0, utils_1.create)("ul", {
91
91
  style: { marginLeft: "1rem" },
92
- children: (0, createSchema_1.createNodes)(firstBody),
92
+ children: (0, createSchema_1.createNodes)(firstBody, "response"),
93
93
  }),
94
94
  ],
95
95
  }),
@@ -9,4 +9,4 @@ export declare function mergeAllOf(allOf: SchemaObject[]): {
9
9
  /**
10
10
  * Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
11
11
  */
12
- export declare function createNodes(schema: SchemaObject): any;
12
+ export declare function createNodes(schema: SchemaObject, schemaType: "request" | "response"): any;
@@ -18,6 +18,7 @@ const createDetailsSummary_1 = require("./createDetailsSummary");
18
18
  const schema_1 = require("./schema");
19
19
  const utils_1 = require("./utils");
20
20
  const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
21
+ let SCHEMA_TYPE;
21
22
  /**
22
23
  * Returns a merged representation of allOf array of schemas.
23
24
  */
@@ -27,6 +28,9 @@ function mergeAllOf(allOf) {
27
28
  readOnly: function () {
28
29
  return true;
29
30
  },
31
+ writeOnly: function () {
32
+ return true;
33
+ },
30
34
  example: function () {
31
35
  return true;
32
36
  },
@@ -68,7 +72,7 @@ function createAnyOneOf(schema) {
68
72
  delete anyOneSchema.properties;
69
73
  }
70
74
  if (anyOneSchema.allOf !== undefined) {
71
- anyOneChildren.push(createNodes(anyOneSchema));
75
+ anyOneChildren.push(createNodes(anyOneSchema, SCHEMA_TYPE));
72
76
  delete anyOneSchema.allOf;
73
77
  }
74
78
  if (anyOneSchema.items !== undefined) {
@@ -79,7 +83,7 @@ function createAnyOneOf(schema) {
79
83
  anyOneSchema.type === "number" ||
80
84
  anyOneSchema.type === "integer" ||
81
85
  anyOneSchema.type === "boolean") {
82
- anyOneChildren.push(createNodes(anyOneSchema));
86
+ anyOneChildren.push(createNodes(anyOneSchema, SCHEMA_TYPE));
83
87
  }
84
88
  if (anyOneChildren.length) {
85
89
  if (schema.type === "array") {
@@ -257,7 +261,7 @@ function createItems(schema) {
257
261
  ((_l = schema.items) === null || _l === void 0 ? void 0 : _l.type) === "object") {
258
262
  return [
259
263
  (0, createArrayBracket_1.createOpeningArrayBracket)(),
260
- createNodes(schema.items),
264
+ createNodes(schema.items, SCHEMA_TYPE),
261
265
  (0, createArrayBracket_1.createClosingArrayBracket)(),
262
266
  ].flat();
263
267
  }
@@ -344,7 +348,7 @@ function createDetailsNode(name, schemaName, schema, required, nullable) {
344
348
  style: { marginTop: ".5rem", marginBottom: ".5rem" },
345
349
  children: (0, createDescription_1.createDescription)(description),
346
350
  })),
347
- createNodes(schema),
351
+ createNodes(schema, SCHEMA_TYPE),
348
352
  ],
349
353
  }),
350
354
  ],
@@ -466,7 +470,7 @@ function createPropertyDiscriminator(name, schemaName, schema, discriminator, re
466
470
  // className: "openapi-tabs__discriminator-item",
467
471
  label: label,
468
472
  value: `${index}-item-discriminator`,
469
- children: [createNodes(discriminator === null || discriminator === void 0 ? void 0 : discriminator.mapping[key])],
473
+ children: [createNodes(discriminator === null || discriminator === void 0 ? void 0 : discriminator.mapping[key], SCHEMA_TYPE)],
470
474
  });
471
475
  }),
472
476
  }),
@@ -503,8 +507,15 @@ function createEdges({ name, schema, required, discriminator, }) {
503
507
  if (((_a = mergedSchemas.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
504
508
  return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
505
509
  }
506
- if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
507
- return undefined;
510
+ if (SCHEMA_TYPE === "request") {
511
+ if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
512
+ return undefined;
513
+ }
514
+ }
515
+ if (SCHEMA_TYPE === "response") {
516
+ if (mergedSchemas.writeOnly && mergedSchemas.writeOnly === true) {
517
+ return undefined;
518
+ }
508
519
  }
509
520
  return (0, utils_1.create)("SchemaItem", {
510
521
  collapsible: false,
@@ -528,8 +539,15 @@ function createEdges({ name, schema, required, discriminator, }) {
528
539
  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) {
529
540
  return createDetailsNode(name, schemaName, schema, required, schema.nullable);
530
541
  }
531
- if (schema.readOnly && schema.readOnly === true) {
532
- return undefined;
542
+ if (SCHEMA_TYPE === "request") {
543
+ if (schema.readOnly && schema.readOnly === true) {
544
+ return undefined;
545
+ }
546
+ }
547
+ if (SCHEMA_TYPE === "response") {
548
+ if (schema.writeOnly && schema.writeOnly === true) {
549
+ return undefined;
550
+ }
533
551
  }
534
552
  // primitives and array of non-objects
535
553
  return (0, utils_1.create)("SchemaItem", {
@@ -544,7 +562,8 @@ function createEdges({ name, schema, required, discriminator, }) {
544
562
  /**
545
563
  * Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
546
564
  */
547
- function createNodes(schema) {
565
+ function createNodes(schema, schemaType) {
566
+ SCHEMA_TYPE = schemaType;
548
567
  const nodes = [];
549
568
  // if (schema.discriminator !== undefined) {
550
569
  // return createDiscriminator(schema);
@@ -68,6 +68,6 @@ describe("createNodes", () => {
68
68
  },
69
69
  },
70
70
  };
71
- expect((0, createSchema_1.createNodes)(schema).map((md) => prettier.format(md, { parser: "babel" }))).toMatchSnapshot();
71
+ expect((0, createSchema_1.createNodes)(schema, "request").map((md) => prettier.format(md, { parser: "babel" }))).toMatchSnapshot();
72
72
  });
73
73
  });
@@ -373,7 +373,7 @@ function bindCollectionToApiItems(items, postmanCollection) {
373
373
  const method = item.request.method.toLowerCase();
374
374
  const path = item.request.url
375
375
  .getPath({ unresolved: true }) // unresolved returns "/:variableName" instead of "/<type>"
376
- .replace(/:([a-z0-9-_]+)/gi, "{$1}"); // replace "/:variableName" with "/{variableName}"
376
+ .replace(/(?<![a-z0-9-_]+):([a-z0-9-_]+)/gi, "{$1}"); // replace "/:variableName" with "/{variableName}"
377
377
  const apiItem = items.find((item) => {
378
378
  if (item.type === "info" || item.type === "tag") {
379
379
  return false;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-openapi-docs",
3
3
  "description": "OpenAPI plugin for Docusaurus.",
4
- "version": "2.0.0",
4
+ "version": "2.0.2",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -60,5 +60,5 @@
60
60
  "engines": {
61
61
  "node": ">=14"
62
62
  },
63
- "gitHead": "ec57fe9cac964cff00f5433fb829ce2d6219da7e"
63
+ "gitHead": "7f9528595b373f7691fd63845d84870549e6895c"
64
64
  }
@@ -90,7 +90,7 @@ export function createRequestSchema({ title, body, ...rest }: Props) {
90
90
  }),
91
91
  create("ul", {
92
92
  style: { marginLeft: "1rem" },
93
- children: createNodes(firstBody),
93
+ children: createNodes(firstBody, "request"),
94
94
  }),
95
95
  ],
96
96
  }),
@@ -161,7 +161,7 @@ export function createRequestSchema({ title, body, ...rest }: Props) {
161
161
  }),
162
162
  create("ul", {
163
163
  style: { marginLeft: "1rem" },
164
- children: createNodes(firstBody),
164
+ children: createNodes(firstBody, "request"),
165
165
  }),
166
166
  ],
167
167
  }),
@@ -118,7 +118,7 @@ export function createResponseSchema({ title, body, ...rest }: Props) {
118
118
  }),
119
119
  create("ul", {
120
120
  style: { marginLeft: "1rem" },
121
- children: createNodes(firstBody!),
121
+ children: createNodes(firstBody!, "response"),
122
122
  }),
123
123
  ],
124
124
  }),
@@ -48,7 +48,7 @@ describe("createNodes", () => {
48
48
  },
49
49
  };
50
50
  expect(
51
- createNodes(schema).map((md: any) =>
51
+ createNodes(schema, "request").map((md: any) =>
52
52
  prettier.format(md, { parser: "babel" })
53
53
  )
54
54
  ).toMatchSnapshot();
@@ -20,6 +20,8 @@ import { create, guard } from "./utils";
20
20
 
21
21
  const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
22
22
 
23
+ let SCHEMA_TYPE: "request" | "response";
24
+
23
25
  /**
24
26
  * Returns a merged representation of allOf array of schemas.
25
27
  */
@@ -29,6 +31,9 @@ export function mergeAllOf(allOf: SchemaObject[]) {
29
31
  readOnly: function () {
30
32
  return true;
31
33
  },
34
+ writeOnly: function () {
35
+ return true;
36
+ },
32
37
  example: function () {
33
38
  return true;
34
39
  },
@@ -74,7 +79,7 @@ function createAnyOneOf(schema: SchemaObject): any {
74
79
  }
75
80
 
76
81
  if (anyOneSchema.allOf !== undefined) {
77
- anyOneChildren.push(createNodes(anyOneSchema));
82
+ anyOneChildren.push(createNodes(anyOneSchema, SCHEMA_TYPE));
78
83
  delete anyOneSchema.allOf;
79
84
  }
80
85
 
@@ -89,7 +94,7 @@ function createAnyOneOf(schema: SchemaObject): any {
89
94
  anyOneSchema.type === "integer" ||
90
95
  anyOneSchema.type === "boolean"
91
96
  ) {
92
- anyOneChildren.push(createNodes(anyOneSchema));
97
+ anyOneChildren.push(createNodes(anyOneSchema, SCHEMA_TYPE));
93
98
  }
94
99
  if (anyOneChildren.length) {
95
100
  if (schema.type === "array") {
@@ -304,7 +309,7 @@ function createItems(schema: SchemaObject) {
304
309
  ) {
305
310
  return [
306
311
  createOpeningArrayBracket(),
307
- createNodes(schema.items),
312
+ createNodes(schema.items, SCHEMA_TYPE),
308
313
  createClosingArrayBracket(),
309
314
  ].flat();
310
315
  }
@@ -411,7 +416,7 @@ function createDetailsNode(
411
416
  children: createDescription(description),
412
417
  })
413
418
  ),
414
- createNodes(schema),
419
+ createNodes(schema, SCHEMA_TYPE),
415
420
  ],
416
421
  }),
417
422
  ],
@@ -565,7 +570,7 @@ function createPropertyDiscriminator(
565
570
  // className: "openapi-tabs__discriminator-item",
566
571
  label: label,
567
572
  value: `${index}-item-discriminator`,
568
- children: [createNodes(discriminator?.mapping[key])],
573
+ children: [createNodes(discriminator?.mapping[key], SCHEMA_TYPE)],
569
574
  });
570
575
  }),
571
576
  }),
@@ -664,8 +669,16 @@ function createEdges({
664
669
  );
665
670
  }
666
671
 
667
- if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
668
- return undefined;
672
+ if (SCHEMA_TYPE === "request") {
673
+ if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
674
+ return undefined;
675
+ }
676
+ }
677
+
678
+ if (SCHEMA_TYPE === "response") {
679
+ if (mergedSchemas.writeOnly && mergedSchemas.writeOnly === true) {
680
+ return undefined;
681
+ }
669
682
  }
670
683
 
671
684
  return create("SchemaItem", {
@@ -719,8 +732,16 @@ function createEdges({
719
732
  );
720
733
  }
721
734
 
722
- if (schema.readOnly && schema.readOnly === true) {
723
- return undefined;
735
+ if (SCHEMA_TYPE === "request") {
736
+ if (schema.readOnly && schema.readOnly === true) {
737
+ return undefined;
738
+ }
739
+ }
740
+
741
+ if (SCHEMA_TYPE === "response") {
742
+ if (schema.writeOnly && schema.writeOnly === true) {
743
+ return undefined;
744
+ }
724
745
  }
725
746
 
726
747
  // primitives and array of non-objects
@@ -737,7 +758,11 @@ function createEdges({
737
758
  /**
738
759
  * Creates a hierarchical level of a schema tree. Nodes produce edges that can branch into sub-nodes with edges, recursively.
739
760
  */
740
- export function createNodes(schema: SchemaObject): any {
761
+ export function createNodes(
762
+ schema: SchemaObject,
763
+ schemaType: "request" | "response"
764
+ ): any {
765
+ SCHEMA_TYPE = schemaType;
741
766
  const nodes = [];
742
767
  // if (schema.discriminator !== undefined) {
743
768
  // return createDiscriminator(schema);
@@ -469,8 +469,7 @@ function bindCollectionToApiItems(
469
469
  const method = item.request.method.toLowerCase();
470
470
  const path = item.request.url
471
471
  .getPath({ unresolved: true }) // unresolved returns "/:variableName" instead of "/<type>"
472
- .replace(/:([a-z0-9-_]+)/gi, "{$1}"); // replace "/:variableName" with "/{variableName}"
473
-
472
+ .replace(/(?<![a-z0-9-_]+):([a-z0-9-_]+)/gi, "{$1}"); // replace "/:variableName" with "/{variableName}"
474
473
  const apiItem = items.find((item) => {
475
474
  if (item.type === "info" || item.type === "tag") {
476
475
  return false;