docusaurus-plugin-openapi-docs 2.0.1 → 2.0.3

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.
@@ -0,0 +1,6 @@
1
+ import { ApiItem } from "../types";
2
+ interface Props {
3
+ callbacks: ApiItem["callbacks"];
4
+ }
5
+ export declare function createCallbacks({ callbacks }: Props): string | undefined;
6
+ export {};
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Copyright (c) Palo Alto Networks
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ * ========================================================================== */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createCallbacks = void 0;
10
+ const createDescription_1 = require("./createDescription");
11
+ const createMethodEndpoint_1 = require("./createMethodEndpoint");
12
+ const createRequestBodyDetails_1 = require("./createRequestBodyDetails");
13
+ const createStatusCodes_1 = require("./createStatusCodes");
14
+ const utils_1 = require("./utils");
15
+ function createCallbacks({ callbacks }) {
16
+ if (callbacks === undefined) {
17
+ return undefined;
18
+ }
19
+ const callbacksNames = Object.keys(callbacks);
20
+ if (callbacksNames.length === 0) {
21
+ return undefined;
22
+ }
23
+ return (0, utils_1.create)("div", {
24
+ children: [
25
+ (0, utils_1.create)("div", {
26
+ className: "openapi__divider",
27
+ }),
28
+ (0, utils_1.create)("h2", {
29
+ children: "Callbacks",
30
+ id: "callbacks",
31
+ }),
32
+ (0, utils_1.create)("OperationTabs", {
33
+ className: "openapi-tabs__operation",
34
+ children: callbacksNames.flatMap((name) => {
35
+ const path = Object.keys(callbacks[name])[0];
36
+ const methods = new Map([
37
+ ["delete", callbacks[name][path].delete],
38
+ ["get", callbacks[name][path].get],
39
+ ["head", callbacks[name][path].head],
40
+ ["options", callbacks[name][path].options],
41
+ ["patch", callbacks[name][path].patch],
42
+ ["post", callbacks[name][path].post],
43
+ ["put", callbacks[name][path].put],
44
+ ["trace", callbacks[name][path].trace],
45
+ ]);
46
+ return Array.from(methods).flatMap(([method, operationObject]) => {
47
+ if (!operationObject)
48
+ return [];
49
+ const { description, requestBody, responses } = operationObject;
50
+ return [
51
+ (0, utils_1.create)("TabItem", {
52
+ label: `${method.toUpperCase()} ${name}`,
53
+ value: `${method}-${name}`,
54
+ children: [
55
+ (0, createMethodEndpoint_1.createMethodEndpoint)(method, path),
56
+ // TODO: add `deprecation notice` when markdown support is added
57
+ (0, createDescription_1.createDescription)(description),
58
+ (0, createRequestBodyDetails_1.createRequestBodyDetails)({
59
+ title: "Body",
60
+ body: requestBody,
61
+ }),
62
+ (0, createStatusCodes_1.createStatusCodes)({
63
+ id: "callbacks-responses",
64
+ label: "Callbacks Responses",
65
+ responses,
66
+ }),
67
+ ],
68
+ }),
69
+ ];
70
+ });
71
+ }),
72
+ }),
73
+ ],
74
+ });
75
+ }
76
+ exports.createCallbacks = createCallbacks;
@@ -9,5 +9,5 @@ interface Props {
9
9
  required?: boolean;
10
10
  };
11
11
  }
12
- export declare function createRequestBodyDetails({ title, body }: Props): any;
12
+ export declare function createRequestBodyDetails({ title, body }: Props): string | undefined;
13
13
  export {};
@@ -1,10 +1,12 @@
1
1
  import { ApiItem } from "../types";
2
2
  export default function json2xml(o: any, tab: any): string;
3
3
  interface Props {
4
+ id?: string;
5
+ label?: string;
4
6
  responses: ApiItem["responses"];
5
7
  }
6
8
  export declare function createResponseExamples(responseExamples: any, mimeType: string): string[];
7
9
  export declare function createResponseExample(responseExample: any, mimeType: string): string;
8
10
  export declare function createExampleFromSchema(schema: any, mimeType: string): string | undefined;
9
- export declare function createStatusCodes({ responses }: Props): string | undefined;
11
+ export declare function createStatusCodes({ label, id, responses }: Props): string | undefined;
10
12
  export {};
@@ -118,7 +118,7 @@ function createResponseExamples(responseExamples, mimeType) {
118
118
  value: `${exampleName}`,
119
119
  children: [
120
120
  (0, utils_2.guard)(exampleValue.summary, (summary) => [
121
- (0, utils_1.create)("p", {
121
+ (0, utils_1.create)("Markdown", {
122
122
  children: ` ${summary}`,
123
123
  }),
124
124
  ]),
@@ -134,7 +134,7 @@ function createResponseExamples(responseExamples, mimeType) {
134
134
  value: `${exampleName}`,
135
135
  children: [
136
136
  (0, utils_2.guard)(exampleValue.summary, (summary) => [
137
- (0, utils_1.create)("p", {
137
+ (0, utils_1.create)("Markdown", {
138
138
  children: ` ${summary}`,
139
139
  }),
140
140
  ]),
@@ -161,7 +161,7 @@ function createResponseExample(responseExample, mimeType) {
161
161
  value: `Example`,
162
162
  children: [
163
163
  (0, utils_2.guard)(responseExample.summary, (summary) => [
164
- (0, utils_1.create)("p", {
164
+ (0, utils_1.create)("Markdown", {
165
165
  children: ` ${summary}`,
166
166
  }),
167
167
  ]),
@@ -177,7 +177,7 @@ function createResponseExample(responseExample, mimeType) {
177
177
  value: `Example`,
178
178
  children: [
179
179
  (0, utils_2.guard)(responseExample.summary, (summary) => [
180
- (0, utils_1.create)("p", {
180
+ (0, utils_1.create)("Markdown", {
181
181
  children: ` ${summary}`,
182
182
  }),
183
183
  ]),
@@ -248,7 +248,7 @@ function createExampleFromSchema(schema, mimeType) {
248
248
  return undefined;
249
249
  }
250
250
  exports.createExampleFromSchema = createExampleFromSchema;
251
- function createStatusCodes({ responses }) {
251
+ function createStatusCodes({ label, id, responses }) {
252
252
  if (responses === undefined) {
253
253
  return undefined;
254
254
  }
@@ -261,6 +261,8 @@ function createStatusCodes({ responses }) {
261
261
  (0, utils_1.create)("div", {
262
262
  children: [
263
263
  (0, utils_1.create)("ApiTabs", {
264
+ label,
265
+ id,
264
266
  children: codes.map((code) => {
265
267
  const responseHeaders = responses[code].headers;
266
268
  return (0, utils_1.create)("TabItem", {
@@ -1,4 +1,4 @@
1
1
  import { ApiPageMetadata, InfoPageMetadata, TagPageMetadata } from "../types";
2
- export declare function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, method, path, extensions, parameters, requestBody, responses, }, infoPath, frontMatter, }: ApiPageMetadata): string;
2
+ export declare function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, method, path, extensions, parameters, requestBody, responses, callbacks, }, infoPath, frontMatter, }: ApiPageMetadata): string;
3
3
  export declare function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService, logo, darkLogo, }, securitySchemes, downloadUrl, }: InfoPageMetadata): string;
4
4
  export declare function createTagPageMD({ tag: { description } }: TagPageMetadata): string;
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.createTagPageMD = exports.createInfoPageMD = exports.createApiPageMD = void 0;
10
10
  const createAuthentication_1 = require("./createAuthentication");
11
11
  const createAuthorization_1 = require("./createAuthorization");
12
+ const createCallbacks_1 = require("./createCallbacks");
12
13
  const createContactInfo_1 = require("./createContactInfo");
13
14
  const createDeprecationNotice_1 = require("./createDeprecationNotice");
14
15
  const createDescription_1 = require("./createDescription");
@@ -25,7 +26,7 @@ const createTermsOfService_1 = require("./createTermsOfService");
25
26
  const createVendorExtensions_1 = require("./createVendorExtensions");
26
27
  const createVersionBadge_1 = require("./createVersionBadge");
27
28
  const utils_1 = require("./utils");
28
- function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, method, path, extensions, parameters, requestBody, responses, }, infoPath, frontMatter, }) {
29
+ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, method, path, extensions, parameters, requestBody, responses, callbacks, }, infoPath, frontMatter, }) {
29
30
  return (0, utils_1.render)([
30
31
  `import ApiTabs from "@theme/ApiTabs";\n`,
31
32
  `import DiscriminatorTabs from "@theme/DiscriminatorTabs";\n`,
@@ -36,11 +37,15 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
36
37
  `import ResponseSamples from "@theme/ResponseSamples";\n`,
37
38
  `import SchemaItem from "@theme/SchemaItem";\n`,
38
39
  `import SchemaTabs from "@theme/SchemaTabs";\n`,
40
+ `import Markdown from "@theme/Markdown";\n`,
41
+ `import OperationTabs from "@theme/OperationTabs";\n`,
39
42
  `import TabItem from "@theme/TabItem";\n\n`,
40
43
  (0, createHeading_1.createHeading)(title.replace(utils_1.lessThan, "<").replace(utils_1.greaterThan, ">")),
41
44
  (0, createMethodEndpoint_1.createMethodEndpoint)(method, path),
42
45
  infoPath && (0, createAuthorization_1.createAuthorization)(infoPath),
43
- frontMatter.show_extensions && (0, createVendorExtensions_1.createVendorExtensions)(extensions),
46
+ frontMatter.show_extensions
47
+ ? (0, createVendorExtensions_1.createVendorExtensions)(extensions)
48
+ : undefined,
44
49
  (0, createDeprecationNotice_1.createDeprecationNotice)({ deprecated, description: deprecatedDescription }),
45
50
  (0, createDescription_1.createDescription)(description),
46
51
  (0, createRequestHeader_1.createRequestHeader)("Request"),
@@ -53,6 +58,7 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
53
58
  body: requestBody,
54
59
  }),
55
60
  (0, createStatusCodes_1.createStatusCodes)({ responses }),
61
+ (0, createCallbacks_1.createCallbacks)({ callbacks }),
56
62
  ]);
57
63
  }
58
64
  exports.createApiPageMD = createApiPageMD;
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.1",
4
+ "version": "2.0.3",
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": "6f9eff64e6b32c63100daaa7f70431edc8cf455d"
63
+ "gitHead": "f6641c0ce01e3247a06ef8ddde7bafbe749d4ed1"
64
64
  }
@@ -0,0 +1,95 @@
1
+ /* ============================================================================
2
+ * Copyright (c) Palo Alto Networks
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ * ========================================================================== */
7
+
8
+ import { MediaTypeObject } from "../openapi/types";
9
+ import { ApiItem } from "../types";
10
+ import { createDescription } from "./createDescription";
11
+ import { createMethodEndpoint } from "./createMethodEndpoint";
12
+ import { createRequestBodyDetails } from "./createRequestBodyDetails";
13
+ import { createStatusCodes } from "./createStatusCodes";
14
+ import { create } from "./utils";
15
+
16
+ interface Props {
17
+ callbacks: ApiItem["callbacks"];
18
+ }
19
+
20
+ interface RequestBodyProps {
21
+ title: string;
22
+ body: {
23
+ content?: {
24
+ [key: string]: MediaTypeObject;
25
+ };
26
+ description?: string;
27
+ required?: boolean;
28
+ };
29
+ }
30
+
31
+ export function createCallbacks({ callbacks }: Props) {
32
+ if (callbacks === undefined) {
33
+ return undefined;
34
+ }
35
+
36
+ const callbacksNames = Object.keys(callbacks);
37
+ if (callbacksNames.length === 0) {
38
+ return undefined;
39
+ }
40
+
41
+ return create("div", {
42
+ children: [
43
+ create("div", {
44
+ className: "openapi__divider",
45
+ }),
46
+ create("h2", {
47
+ children: "Callbacks",
48
+ id: "callbacks",
49
+ }),
50
+ create("OperationTabs", {
51
+ className: "openapi-tabs__operation",
52
+ children: callbacksNames.flatMap((name) => {
53
+ const path = Object.keys(callbacks[name])[0];
54
+ const methods = new Map([
55
+ ["delete", callbacks[name][path].delete],
56
+ ["get", callbacks[name][path].get],
57
+ ["head", callbacks[name][path].head],
58
+ ["options", callbacks[name][path].options],
59
+ ["patch", callbacks[name][path].patch],
60
+ ["post", callbacks[name][path].post],
61
+ ["put", callbacks[name][path].put],
62
+ ["trace", callbacks[name][path].trace],
63
+ ]);
64
+
65
+ return Array.from(methods).flatMap(([method, operationObject]) => {
66
+ if (!operationObject) return [];
67
+
68
+ const { description, requestBody, responses } = operationObject;
69
+
70
+ return [
71
+ create("TabItem", {
72
+ label: `${method.toUpperCase()} ${name}`,
73
+ value: `${method}-${name}`,
74
+ children: [
75
+ createMethodEndpoint(method, path),
76
+ // TODO: add `deprecation notice` when markdown support is added
77
+ createDescription(description),
78
+ createRequestBodyDetails({
79
+ title: "Body",
80
+ body: requestBody,
81
+ } as RequestBodyProps),
82
+ createStatusCodes({
83
+ id: "callbacks-responses",
84
+ label: "Callbacks Responses",
85
+ responses,
86
+ }),
87
+ ],
88
+ }),
89
+ ];
90
+ });
91
+ }),
92
+ }),
93
+ ],
94
+ });
95
+ }
@@ -19,6 +19,6 @@ interface Props {
19
19
  };
20
20
  }
21
21
 
22
- export function createRequestBodyDetails({ title, body }: Props): any {
22
+ export function createRequestBodyDetails({ title, body }: Props) {
23
23
  return createRequestSchema({ title, body });
24
24
  }
@@ -54,6 +54,8 @@ export default function json2xml(o: any, tab: any) {
54
54
  }
55
55
 
56
56
  interface Props {
57
+ id?: string;
58
+ label?: string;
57
59
  responses: ApiItem["responses"];
58
60
  }
59
61
 
@@ -125,7 +127,7 @@ export function createResponseExamples(
125
127
  value: `${exampleName}`,
126
128
  children: [
127
129
  guard(exampleValue.summary, (summary) => [
128
- create("p", {
130
+ create("Markdown", {
129
131
  children: ` ${summary}`,
130
132
  }),
131
133
  ]),
@@ -141,7 +143,7 @@ export function createResponseExamples(
141
143
  value: `${exampleName}`,
142
144
  children: [
143
145
  guard(exampleValue.summary, (summary) => [
144
- create("p", {
146
+ create("Markdown", {
145
147
  children: ` ${summary}`,
146
148
  }),
147
149
  ]),
@@ -169,7 +171,7 @@ export function createResponseExample(responseExample: any, mimeType: string) {
169
171
  value: `Example`,
170
172
  children: [
171
173
  guard(responseExample.summary, (summary) => [
172
- create("p", {
174
+ create("Markdown", {
173
175
  children: ` ${summary}`,
174
176
  }),
175
177
  ]),
@@ -185,7 +187,7 @@ export function createResponseExample(responseExample: any, mimeType: string) {
185
187
  value: `Example`,
186
188
  children: [
187
189
  guard(responseExample.summary, (summary) => [
188
- create("p", {
190
+ create("Markdown", {
189
191
  children: ` ${summary}`,
190
192
  }),
191
193
  ]),
@@ -254,7 +256,7 @@ export function createExampleFromSchema(schema: any, mimeType: string) {
254
256
  return undefined;
255
257
  }
256
258
 
257
- export function createStatusCodes({ responses }: Props) {
259
+ export function createStatusCodes({ label, id, responses }: Props) {
258
260
  if (responses === undefined) {
259
261
  return undefined;
260
262
  }
@@ -269,6 +271,8 @@ export function createStatusCodes({ responses }: Props) {
269
271
  create("div", {
270
272
  children: [
271
273
  create("ApiTabs", {
274
+ label,
275
+ id,
272
276
  children: codes.map((code) => {
273
277
  const responseHeaders: any = responses[code].headers;
274
278
  return create("TabItem", {
@@ -14,6 +14,7 @@ import {
14
14
  import { ApiPageMetadata, InfoPageMetadata, TagPageMetadata } from "../types";
15
15
  import { createAuthentication } from "./createAuthentication";
16
16
  import { createAuthorization } from "./createAuthorization";
17
+ import { createCallbacks } from "./createCallbacks";
17
18
  import { createContactInfo } from "./createContactInfo";
18
19
  import { createDeprecationNotice } from "./createDeprecationNotice";
19
20
  import { createDescription } from "./createDescription";
@@ -31,7 +32,7 @@ import { createVendorExtensions } from "./createVendorExtensions";
31
32
  import { createVersionBadge } from "./createVersionBadge";
32
33
  import { greaterThan, lessThan, render } from "./utils";
33
34
 
34
- interface Props {
35
+ interface RequestBodyProps {
35
36
  title: string;
36
37
  body: {
37
38
  content?: {
@@ -54,6 +55,7 @@ export function createApiPageMD({
54
55
  parameters,
55
56
  requestBody,
56
57
  responses,
58
+ callbacks,
57
59
  },
58
60
  infoPath,
59
61
  frontMatter,
@@ -68,11 +70,15 @@ export function createApiPageMD({
68
70
  `import ResponseSamples from "@theme/ResponseSamples";\n`,
69
71
  `import SchemaItem from "@theme/SchemaItem";\n`,
70
72
  `import SchemaTabs from "@theme/SchemaTabs";\n`,
73
+ `import Markdown from "@theme/Markdown";\n`,
74
+ `import OperationTabs from "@theme/OperationTabs";\n`,
71
75
  `import TabItem from "@theme/TabItem";\n\n`,
72
76
  createHeading(title.replace(lessThan, "<").replace(greaterThan, ">")),
73
77
  createMethodEndpoint(method, path),
74
78
  infoPath && createAuthorization(infoPath),
75
- frontMatter.show_extensions && createVendorExtensions(extensions),
79
+ frontMatter.show_extensions
80
+ ? createVendorExtensions(extensions)
81
+ : undefined,
76
82
  createDeprecationNotice({ deprecated, description: deprecatedDescription }),
77
83
  createDescription(description),
78
84
  createRequestHeader("Request"),
@@ -83,8 +89,9 @@ export function createApiPageMD({
83
89
  createRequestBodyDetails({
84
90
  title: "Body",
85
91
  body: requestBody,
86
- } as Props),
92
+ } as RequestBodyProps),
87
93
  createStatusCodes({ responses }),
94
+ createCallbacks({ callbacks }),
88
95
  ]);
89
96
  }
90
97