docusaurus-plugin-openapi-docs 0.0.0-403 → 0.0.0-406

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.
@@ -8,8 +8,51 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.createStatusCodes = void 0;
10
10
  const createDescription_1 = require("./createDescription");
11
+ const createDetails_1 = require("./createDetails");
12
+ const createDetailsSummary_1 = require("./createDetailsSummary");
11
13
  const createSchemaDetails_1 = require("./createSchemaDetails");
12
14
  const utils_1 = require("./utils");
15
+ const utils_2 = require("./utils");
16
+ function createResponseHeaders(responseHeaders) {
17
+ return (0, utils_2.guard)(responseHeaders, () => (0, utils_1.create)("ul", {
18
+ style: { marginLeft: "1rem" },
19
+ children: [
20
+ Object.entries(responseHeaders).map(([headerName, headerObj]) => {
21
+ const { description, schema: { type }, example, } = headerObj;
22
+ return (0, utils_1.create)("li", {
23
+ class: "schemaItem",
24
+ children: [
25
+ (0, createDetailsSummary_1.createDetailsSummary)({
26
+ children: [
27
+ (0, utils_1.create)("strong", { children: headerName }),
28
+ (0, utils_2.guard)(type, () => [
29
+ (0, utils_1.create)("span", {
30
+ style: { opacity: "0.6" },
31
+ children: ` ${type}`,
32
+ }),
33
+ ]),
34
+ ],
35
+ }),
36
+ (0, utils_1.create)("div", {
37
+ children: [
38
+ (0, utils_2.guard)(description, (description) => (0, utils_1.create)("div", {
39
+ style: {
40
+ marginTop: ".5rem",
41
+ marginBottom: ".5rem",
42
+ },
43
+ children: [
44
+ (0, utils_2.guard)(example, () => `Example: ${example}`),
45
+ (0, createDescription_1.createDescription)(description),
46
+ ],
47
+ })),
48
+ ],
49
+ }),
50
+ ],
51
+ });
52
+ }),
53
+ ],
54
+ }));
55
+ }
13
56
  function createStatusCodes({ responses }) {
14
57
  if (responses === undefined) {
15
58
  return undefined;
@@ -22,6 +65,7 @@ function createStatusCodes({ responses }) {
22
65
  children: [
23
66
  (0, utils_1.create)("ApiTabs", {
24
67
  children: codes.map((code) => {
68
+ const responseHeaders = responses[code].headers;
25
69
  return (0, utils_1.create)("TabItem", {
26
70
  label: code,
27
71
  value: code,
@@ -29,6 +73,20 @@ function createStatusCodes({ responses }) {
29
73
  (0, utils_1.create)("div", {
30
74
  children: (0, createDescription_1.createDescription)(responses[code].description),
31
75
  }),
76
+ responseHeaders &&
77
+ (0, createDetails_1.createDetails)({
78
+ "data-collaposed": false,
79
+ open: true,
80
+ style: { textAlign: "left" },
81
+ children: [
82
+ (0, createDetailsSummary_1.createDetailsSummary)({
83
+ children: [
84
+ (0, utils_1.create)("strong", { children: "Response Headers" }),
85
+ ],
86
+ }),
87
+ createResponseHeaders(responseHeaders),
88
+ ],
89
+ }),
32
90
  (0, utils_1.create)("div", {
33
91
  children: (0, createSchemaDetails_1.createSchemaDetails)({
34
92
  title: "Schema",
@@ -40,7 +40,8 @@ function jsonToCollection(data) {
40
40
  */
41
41
  async function createPostmanCollection(openapiData) {
42
42
  var _a, _b, _c, _d, _e, _f, _g, _h;
43
- const data = openapiData;
43
+ // Create copy of openapiData
44
+ const data = Object.assign({}, openapiData);
44
45
  // Including `servers` breaks postman, so delete all of them.
45
46
  delete data.servers;
46
47
  for (let pathItemObject of Object.values(data.paths)) {
@@ -114,7 +115,9 @@ function createItems(openapiData, sidebarOptions) {
114
115
  operationObject.description =
115
116
  (_h = (_g = operationObject.summary) !== null && _g !== void 0 ? _g : operationObject.operationId) !== null && _h !== void 0 ? _h : "";
116
117
  }
117
- const baseId = (0, lodash_1.kebabCase)(title);
118
+ const baseId = operationObject.operationId
119
+ ? (0, lodash_1.kebabCase)(operationObject.operationId)
120
+ : (0, lodash_1.kebabCase)(operationObject.summary);
118
121
  const servers = (_k = (_j = operationObject.servers) !== null && _j !== void 0 ? _j : pathObject.servers) !== null && _k !== void 0 ? _k : openapiData.servers;
119
122
  const security = (_l = operationObject.security) !== null && _l !== void 0 ? _l : openapiData.security;
120
123
  // Add security schemes so we know how to handle security.
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": "0.0.0-403",
4
+ "version": "0.0.0-406",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -67,5 +67,5 @@
67
67
  "engines": {
68
68
  "node": ">=14"
69
69
  },
70
- "gitHead": "e23091951747b00753116a1ba3b1ea6a6d7c2080"
70
+ "gitHead": "16858c4b489fc024973a4ffe42fc57ecc0c4f1a3"
71
71
  }
@@ -7,13 +7,66 @@
7
7
 
8
8
  import { ApiItem } from "../types";
9
9
  import { createDescription } from "./createDescription";
10
+ import { createDetails } from "./createDetails";
11
+ import { createDetailsSummary } from "./createDetailsSummary";
10
12
  import { createSchemaDetails } from "./createSchemaDetails";
11
13
  import { create } from "./utils";
14
+ import { guard } from "./utils";
12
15
 
13
16
  interface Props {
14
17
  responses: ApiItem["responses"];
15
18
  }
16
19
 
20
+ function createResponseHeaders(responseHeaders: any) {
21
+ return guard(responseHeaders, () =>
22
+ create("ul", {
23
+ style: { marginLeft: "1rem" },
24
+ children: [
25
+ Object.entries(responseHeaders).map(([headerName, headerObj]) => {
26
+ const {
27
+ description,
28
+ schema: { type },
29
+ example,
30
+ }: any = headerObj;
31
+
32
+ return create("li", {
33
+ class: "schemaItem",
34
+ children: [
35
+ createDetailsSummary({
36
+ children: [
37
+ create("strong", { children: headerName }),
38
+ guard(type, () => [
39
+ create("span", {
40
+ style: { opacity: "0.6" },
41
+ children: ` ${type}`,
42
+ }),
43
+ ]),
44
+ ],
45
+ }),
46
+ create("div", {
47
+ children: [
48
+ guard(description, (description) =>
49
+ create("div", {
50
+ style: {
51
+ marginTop: ".5rem",
52
+ marginBottom: ".5rem",
53
+ },
54
+ children: [
55
+ guard(example, () => `Example: ${example}`),
56
+ createDescription(description),
57
+ ],
58
+ })
59
+ ),
60
+ ],
61
+ }),
62
+ ],
63
+ });
64
+ }),
65
+ ],
66
+ })
67
+ );
68
+ }
69
+
17
70
  export function createStatusCodes({ responses }: Props) {
18
71
  if (responses === undefined) {
19
72
  return undefined;
@@ -28,6 +81,7 @@ export function createStatusCodes({ responses }: Props) {
28
81
  children: [
29
82
  create("ApiTabs", {
30
83
  children: codes.map((code) => {
84
+ const responseHeaders: any = responses[code].headers;
31
85
  return create("TabItem", {
32
86
  label: code,
33
87
  value: code,
@@ -35,6 +89,20 @@ export function createStatusCodes({ responses }: Props) {
35
89
  create("div", {
36
90
  children: createDescription(responses[code].description),
37
91
  }),
92
+ responseHeaders &&
93
+ createDetails({
94
+ "data-collaposed": false,
95
+ open: true,
96
+ style: { textAlign: "left" },
97
+ children: [
98
+ createDetailsSummary({
99
+ children: [
100
+ create("strong", { children: "Response Headers" }),
101
+ ],
102
+ }),
103
+ createResponseHeaders(responseHeaders),
104
+ ],
105
+ }),
38
106
  create("div", {
39
107
  children: createSchemaDetails({
40
108
  title: "Schema",
@@ -53,7 +53,8 @@ function jsonToCollection(data: OpenApiObject): Promise<Collection> {
53
53
  async function createPostmanCollection(
54
54
  openapiData: OpenApiObject
55
55
  ): Promise<Collection> {
56
- const data = openapiData as OpenApiObject;
56
+ // Create copy of openapiData
57
+ const data = Object.assign({}, openapiData) as OpenApiObject;
57
58
 
58
59
  // Including `servers` breaks postman, so delete all of them.
59
60
  delete data.servers;
@@ -146,7 +147,9 @@ function createItems(
146
147
  operationObject.summary ?? operationObject.operationId ?? "";
147
148
  }
148
149
 
149
- const baseId = kebabCase(title);
150
+ const baseId = operationObject.operationId
151
+ ? kebabCase(operationObject.operationId)
152
+ : kebabCase(operationObject.summary);
150
153
 
151
154
  const servers =
152
155
  operationObject.servers ?? pathObject.servers ?? openapiData.servers;