docusaurus-plugin-openapi-docs 0.0.0-689 → 0.0.0-690

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 {};
@@ -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,14 @@ 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 OperationTabs from "@theme/OperationTabs";\n`,
39
41
  `import TabItem from "@theme/TabItem";\n\n`,
40
42
  (0, createHeading_1.createHeading)(title.replace(utils_1.lessThan, "<").replace(utils_1.greaterThan, ">")),
41
43
  (0, createMethodEndpoint_1.createMethodEndpoint)(method, path),
42
44
  infoPath && (0, createAuthorization_1.createAuthorization)(infoPath),
43
- frontMatter.show_extensions && (0, createVendorExtensions_1.createVendorExtensions)(extensions),
45
+ frontMatter.show_extensions
46
+ ? (0, createVendorExtensions_1.createVendorExtensions)(extensions)
47
+ : undefined,
44
48
  (0, createDeprecationNotice_1.createDeprecationNotice)({ deprecated, description: deprecatedDescription }),
45
49
  (0, createDescription_1.createDescription)(description),
46
50
  (0, createRequestHeader_1.createRequestHeader)("Request"),
@@ -53,6 +57,7 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
53
57
  body: requestBody,
54
58
  }),
55
59
  (0, createStatusCodes_1.createStatusCodes)({ responses }),
60
+ (0, createCallbacks_1.createCallbacks)({ callbacks }),
56
61
  ]);
57
62
  }
58
63
  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": "0.0.0-689",
4
+ "version": "0.0.0-690",
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": "54be8d8d7ac320e75c1e1e06f9756b7cd36f88f8"
63
+ "gitHead": "68d6bc5c3e39aba589cdebe0189820179be60c18"
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
 
@@ -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,14 @@ 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 OperationTabs from "@theme/OperationTabs";\n`,
71
74
  `import TabItem from "@theme/TabItem";\n\n`,
72
75
  createHeading(title.replace(lessThan, "<").replace(greaterThan, ">")),
73
76
  createMethodEndpoint(method, path),
74
77
  infoPath && createAuthorization(infoPath),
75
- frontMatter.show_extensions && createVendorExtensions(extensions),
78
+ frontMatter.show_extensions
79
+ ? createVendorExtensions(extensions)
80
+ : undefined,
76
81
  createDeprecationNotice({ deprecated, description: deprecatedDescription }),
77
82
  createDescription(description),
78
83
  createRequestHeader("Request"),
@@ -83,8 +88,9 @@ export function createApiPageMD({
83
88
  createRequestBodyDetails({
84
89
  title: "Body",
85
90
  body: requestBody,
86
- } as Props),
91
+ } as RequestBodyProps),
87
92
  createStatusCodes({ responses }),
93
+ createCallbacks({ callbacks }),
88
94
  ]);
89
95
  }
90
96