docusaurus-plugin-openapi-docs 0.0.0-410 → 0.0.0-413

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.
package/README.md CHANGED
@@ -246,7 +246,7 @@ yarn docusaurus gen-api-docs:version petstore:all
246
246
  Run the following to bootstrap a Docsaurus v2 site (classic theme) with `docusaurus-openapi-docs`:
247
247
 
248
248
  ```bash
249
- npx create-docusaurus@2.0.0-rc.1 my-website --package-manager yarn
249
+ npx create-docusaurus@2.0.1 my-website --package-manager yarn
250
250
  ```
251
251
 
252
252
  > When prompted to select a template choose `Git repository`.
@@ -0,0 +1,2 @@
1
+ import { LogoObject } from "../openapi/types";
2
+ export declare function createLogo(logo: LogoObject | undefined, darkLogo: LogoObject | undefined): string;
@@ -0,0 +1,19 @@
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.createLogo = void 0;
10
+ const utils_1 = require("./utils");
11
+ function createLogo(logo, darkLogo) {
12
+ return (0, utils_1.guard)(logo || darkLogo, () => [
13
+ (0, utils_1.create)("ApiLogo", {
14
+ logo: logo,
15
+ darkLogo: darkLogo,
16
+ }),
17
+ ]);
18
+ }
19
+ exports.createLogo = createLogo;
@@ -53,6 +53,21 @@ function createResponseHeaders(responseHeaders) {
53
53
  ],
54
54
  }));
55
55
  }
56
+ function createResponseExamples(responseExamples) {
57
+ return Object.entries(responseExamples).map(([exampleName, exampleValue]) => {
58
+ const camelToSpaceName = exampleName.replace(/([A-Z])/g, " $1");
59
+ let finalFormattedName = camelToSpaceName.charAt(0).toUpperCase() + camelToSpaceName.slice(1);
60
+ return (0, utils_1.create)("TabItem", {
61
+ label: `${finalFormattedName}`,
62
+ value: `${finalFormattedName}`,
63
+ children: [
64
+ (0, utils_1.create)("ResponseSamples", {
65
+ responseExample: JSON.stringify(exampleValue.value, null, 2),
66
+ }),
67
+ ],
68
+ });
69
+ });
70
+ }
56
71
  function createStatusCodes({ responses }) {
57
72
  if (responses === undefined) {
58
73
  return undefined;
@@ -66,6 +81,9 @@ function createStatusCodes({ responses }) {
66
81
  (0, utils_1.create)("ApiTabs", {
67
82
  children: codes.map((code) => {
68
83
  const responseHeaders = responses[code].headers;
84
+ const responseContent = responses[code].content;
85
+ const responseContentKey = responseContent && Object.keys(responseContent)[0];
86
+ const responseExamples = responseContentKey && responseContent[responseContentKey].examples;
69
87
  return (0, utils_1.create)("TabItem", {
70
88
  label: code,
71
89
  value: code,
@@ -73,28 +91,62 @@ function createStatusCodes({ responses }) {
73
91
  (0, utils_1.create)("div", {
74
92
  children: (0, createDescription_1.createDescription)(responses[code].description),
75
93
  }),
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
- }),
90
- (0, utils_1.create)("div", {
94
+ (0, utils_2.guard)(responseExamples, () => (0, utils_1.create)("SchemaTabs", {
95
+ children: [
96
+ (0, utils_1.create)("TabTtem", {
97
+ label: "Schema",
98
+ value: "Schema",
99
+ children: [
100
+ responseHeaders &&
101
+ (0, createDetails_1.createDetails)({
102
+ "data-collaposed": false,
103
+ open: true,
104
+ style: { textAlign: "left" },
105
+ children: [
106
+ (0, createDetailsSummary_1.createDetailsSummary)({
107
+ children: [
108
+ (0, utils_1.create)("strong", {
109
+ children: "Response Headers",
110
+ }),
111
+ ],
112
+ }),
113
+ createResponseHeaders(responseHeaders),
114
+ ],
115
+ }),
116
+ (0, utils_1.create)("div", {
117
+ children: (0, createSchemaDetails_1.createSchemaDetails)({
118
+ title: "Schema",
119
+ body: {
120
+ content: responses[code].content,
121
+ },
122
+ }),
123
+ }),
124
+ ],
125
+ }),
126
+ createResponseExamples(responseExamples),
127
+ ],
128
+ })),
129
+ (0, utils_2.guard)(responseHeaders, () => (0, createDetails_1.createDetails)({
130
+ "data-collaposed": false,
131
+ open: true,
132
+ style: { textAlign: "left" },
133
+ children: [
134
+ (0, createDetailsSummary_1.createDetailsSummary)({
135
+ children: [
136
+ (0, utils_1.create)("strong", { children: "Response Headers" }),
137
+ ],
138
+ }),
139
+ createResponseHeaders(responseHeaders),
140
+ ],
141
+ })),
142
+ (0, utils_2.guard)(!responseExamples, () => (0, utils_1.create)("div", {
91
143
  children: (0, createSchemaDetails_1.createSchemaDetails)({
92
144
  title: "Schema",
93
145
  body: {
94
146
  content: responses[code].content,
95
147
  },
96
148
  }),
97
- }),
149
+ })),
98
150
  ],
99
151
  });
100
152
  }),
@@ -1,4 +1,4 @@
1
1
  import { ApiPageMetadata, InfoPageMetadata, TagPageMetadata } from "../types";
2
2
  export declare function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, parameters, requestBody, responses, }, }: ApiPageMetadata): string;
3
- export declare function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService }, securitySchemes, }: InfoPageMetadata): string;
3
+ export declare function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService, logo, darkLogo, }, securitySchemes, }: InfoPageMetadata): string;
4
4
  export declare function createTagPageMD({ tag: { description } }: TagPageMetadata): string;
@@ -13,6 +13,7 @@ const createContactInfo_1 = require("./createContactInfo");
13
13
  const createDeprecationNotice_1 = require("./createDeprecationNotice");
14
14
  const createDescription_1 = require("./createDescription");
15
15
  const createLicense_1 = require("./createLicense");
16
+ const createLogo_1 = require("./createLogo");
16
17
  const createParamsDetails_1 = require("./createParamsDetails");
17
18
  const createRequestBodyDetails_1 = require("./createRequestBodyDetails");
18
19
  const createStatusCodes_1 = require("./createStatusCodes");
@@ -21,9 +22,10 @@ const createVersionBadge_1 = require("./createVersionBadge");
21
22
  const utils_1 = require("./utils");
22
23
  function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, parameters, requestBody, responses, }, }) {
23
24
  return (0, utils_1.render)([
25
+ `import ApiTabs from "@theme/ApiTabs";\n`,
24
26
  `import ParamsItem from "@theme/ParamsItem";\n`,
27
+ `import ResponseSamples from "@theme/ResponseSamples";\n`,
25
28
  `import SchemaItem from "@theme/SchemaItem"\n`,
26
- `import ApiTabs from "@theme/ApiTabs";\n`,
27
29
  `import SchemaTabs from "@theme/SchemaTabs";\n`,
28
30
  `import DiscriminatorTabs from "@theme/DiscriminatorTabs";\n`,
29
31
  `import TabItem from "@theme/TabItem";\n\n`,
@@ -39,12 +41,14 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
39
41
  ]);
40
42
  }
41
43
  exports.createApiPageMD = createApiPageMD;
42
- function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService }, securitySchemes, }) {
44
+ function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService, logo, darkLogo, }, securitySchemes, }) {
43
45
  return (0, utils_1.render)([
46
+ `import ApiLogo from "@theme/ApiLogo";\n`,
44
47
  `import Tabs from "@theme/Tabs";\n`,
45
48
  `import TabItem from "@theme/TabItem";\n\n`,
46
49
  (0, createVersionBadge_1.createVersionBadge)(version),
47
50
  `# ${(0, lodash_1.escape)(title)}\n\n`,
51
+ (0, createLogo_1.createLogo)(logo, darkLogo),
48
52
  (0, createDescription_1.createDescription)(description),
49
53
  (0, createAuthentication_1.createAuthentication)(securitySchemes),
50
54
  (0, createContactInfo_1.createContactInfo)(contact),
@@ -102,6 +102,8 @@ function createItems(openapiData, sidebarOptions) {
102
102
  ...openapiData.info,
103
103
  tags: (_c = openapiData.tags) === null || _c === void 0 ? void 0 : _c.map((tagName) => { var _a; return getTagDisplayName(tagName.name, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []); }),
104
104
  title: (_d = openapiData.info.title) !== null && _d !== void 0 ? _d : "Introduction",
105
+ logo: openapiData.info["x-logo"],
106
+ darkLogo: openapiData.info["x-dark-logo"],
105
107
  },
106
108
  };
107
109
  items.push(infoPage);
@@ -31,6 +31,13 @@ export interface InfoObject {
31
31
  license?: LicenseObject;
32
32
  version: string;
33
33
  tags?: String[];
34
+ "x-logo"?: LogoObject;
35
+ "x-dark-logo"?: LogoObject;
36
+ logo?: LogoObject;
37
+ darkLogo?: LogoObject;
38
+ }
39
+ export interface LogoObject {
40
+ url?: string;
34
41
  }
35
42
  export interface ContactObject {
36
43
  name?: string;
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-410",
4
+ "version": "0.0.0-413",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -28,8 +28,8 @@
28
28
  "watch": "tsc --watch"
29
29
  },
30
30
  "devDependencies": {
31
- "@docusaurus/module-type-aliases": "2.0.0-rc.1",
32
- "@docusaurus/types": "2.0.0-rc.1",
31
+ "@docusaurus/module-type-aliases": "2.0.1",
32
+ "@docusaurus/types": "2.0.1",
33
33
  "@types/fs-extra": "^9.0.13",
34
34
  "@types/js-yaml": "^4.0.5",
35
35
  "@types/json-pointer": "^1.0.31",
@@ -40,10 +40,10 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@apidevtools/json-schema-ref-parser": "^9.0.9",
43
- "@docusaurus/mdx-loader": "2.0.0-rc.1",
44
- "@docusaurus/plugin-content-docs": "2.0.0-rc.1",
45
- "@docusaurus/utils": "2.0.0-rc.1",
46
- "@docusaurus/utils-validation": "2.0.0-rc.1",
43
+ "@docusaurus/mdx-loader": "2.0.1",
44
+ "@docusaurus/plugin-content-docs": "2.0.1",
45
+ "@docusaurus/utils": "2.0.1",
46
+ "@docusaurus/utils-validation": "2.0.1",
47
47
  "@paloaltonetworks/openapi-to-postmanv2": "3.1.0-hotfix.1",
48
48
  "@paloaltonetworks/postman-collection": "^4.1.0",
49
49
  "@redocly/openapi-core": "^1.0.0-beta.103",
@@ -67,5 +67,5 @@
67
67
  "engines": {
68
68
  "node": ">=14"
69
69
  },
70
- "gitHead": "a988ec527e7daefea40dfafa5b7bed404b7d2e0c"
70
+ "gitHead": "f2cafe5a93dc9b203fc039174c56dc7e8c8db8c4"
71
71
  }
@@ -0,0 +1,21 @@
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 { LogoObject } from "../openapi/types";
9
+ import { create, guard } from "./utils";
10
+
11
+ export function createLogo(
12
+ logo: LogoObject | undefined,
13
+ darkLogo: LogoObject | undefined
14
+ ) {
15
+ return guard(logo || darkLogo, () => [
16
+ create("ApiLogo", {
17
+ logo: logo,
18
+ darkLogo: darkLogo,
19
+ }),
20
+ ]);
21
+ }
@@ -67,6 +67,26 @@ function createResponseHeaders(responseHeaders: any) {
67
67
  );
68
68
  }
69
69
 
70
+ function createResponseExamples(responseExamples: any) {
71
+ return Object.entries(responseExamples).map(
72
+ ([exampleName, exampleValue]: any) => {
73
+ const camelToSpaceName = exampleName.replace(/([A-Z])/g, " $1");
74
+ let finalFormattedName =
75
+ camelToSpaceName.charAt(0).toUpperCase() + camelToSpaceName.slice(1);
76
+
77
+ return create("TabItem", {
78
+ label: `${finalFormattedName}`,
79
+ value: `${finalFormattedName}`,
80
+ children: [
81
+ create("ResponseSamples", {
82
+ responseExample: JSON.stringify(exampleValue.value, null, 2),
83
+ }),
84
+ ],
85
+ });
86
+ }
87
+ );
88
+ }
89
+
70
90
  export function createStatusCodes({ responses }: Props) {
71
91
  if (responses === undefined) {
72
92
  return undefined;
@@ -82,6 +102,12 @@ export function createStatusCodes({ responses }: Props) {
82
102
  create("ApiTabs", {
83
103
  children: codes.map((code) => {
84
104
  const responseHeaders: any = responses[code].headers;
105
+ const responseContent: any = responses[code].content;
106
+ const responseContentKey: any =
107
+ responseContent && Object.keys(responseContent)[0];
108
+ const responseExamples: any =
109
+ responseContentKey && responseContent[responseContentKey].examples;
110
+
85
111
  return create("TabItem", {
86
112
  label: code,
87
113
  value: code,
@@ -89,7 +115,44 @@ export function createStatusCodes({ responses }: Props) {
89
115
  create("div", {
90
116
  children: createDescription(responses[code].description),
91
117
  }),
92
- responseHeaders &&
118
+ guard(responseExamples, () =>
119
+ create("SchemaTabs", {
120
+ children: [
121
+ create("TabTtem", {
122
+ label: "Schema",
123
+ value: "Schema",
124
+ children: [
125
+ responseHeaders &&
126
+ createDetails({
127
+ "data-collaposed": false,
128
+ open: true,
129
+ style: { textAlign: "left" },
130
+ children: [
131
+ createDetailsSummary({
132
+ children: [
133
+ create("strong", {
134
+ children: "Response Headers",
135
+ }),
136
+ ],
137
+ }),
138
+ createResponseHeaders(responseHeaders),
139
+ ],
140
+ }),
141
+ create("div", {
142
+ children: createSchemaDetails({
143
+ title: "Schema",
144
+ body: {
145
+ content: responses[code].content,
146
+ },
147
+ }),
148
+ }),
149
+ ],
150
+ }),
151
+ createResponseExamples(responseExamples),
152
+ ],
153
+ })
154
+ ),
155
+ guard(responseHeaders, () =>
93
156
  createDetails({
94
157
  "data-collaposed": false,
95
158
  open: true,
@@ -102,15 +165,18 @@ export function createStatusCodes({ responses }: Props) {
102
165
  }),
103
166
  createResponseHeaders(responseHeaders),
104
167
  ],
105
- }),
106
- create("div", {
107
- children: createSchemaDetails({
108
- title: "Schema",
109
- body: {
110
- content: responses[code].content,
111
- },
112
- }),
113
- }),
168
+ })
169
+ ),
170
+ guard(!responseExamples, () =>
171
+ create("div", {
172
+ children: createSchemaDetails({
173
+ title: "Schema",
174
+ body: {
175
+ content: responses[code].content,
176
+ },
177
+ }),
178
+ })
179
+ ),
114
180
  ],
115
181
  });
116
182
  }),
@@ -18,6 +18,7 @@ import { createContactInfo } from "./createContactInfo";
18
18
  import { createDeprecationNotice } from "./createDeprecationNotice";
19
19
  import { createDescription } from "./createDescription";
20
20
  import { createLicense } from "./createLicense";
21
+ import { createLogo } from "./createLogo";
21
22
  import { createParamsDetails } from "./createParamsDetails";
22
23
  import { createRequestBodyDetails } from "./createRequestBodyDetails";
23
24
  import { createStatusCodes } from "./createStatusCodes";
@@ -37,9 +38,10 @@ export function createApiPageMD({
37
38
  },
38
39
  }: ApiPageMetadata) {
39
40
  return render([
41
+ `import ApiTabs from "@theme/ApiTabs";\n`,
40
42
  `import ParamsItem from "@theme/ParamsItem";\n`,
43
+ `import ResponseSamples from "@theme/ResponseSamples";\n`,
41
44
  `import SchemaItem from "@theme/SchemaItem"\n`,
42
- `import ApiTabs from "@theme/ApiTabs";\n`,
43
45
  `import SchemaTabs from "@theme/SchemaTabs";\n`,
44
46
  `import DiscriminatorTabs from "@theme/DiscriminatorTabs";\n`,
45
47
  `import TabItem from "@theme/TabItem";\n\n`,
@@ -56,14 +58,26 @@ export function createApiPageMD({
56
58
  }
57
59
 
58
60
  export function createInfoPageMD({
59
- info: { title, version, description, contact, license, termsOfService },
61
+ info: {
62
+ title,
63
+ version,
64
+ description,
65
+ contact,
66
+ license,
67
+ termsOfService,
68
+ logo,
69
+ darkLogo,
70
+ },
60
71
  securitySchemes,
61
72
  }: InfoPageMetadata) {
62
73
  return render([
74
+ `import ApiLogo from "@theme/ApiLogo";\n`,
63
75
  `import Tabs from "@theme/Tabs";\n`,
64
76
  `import TabItem from "@theme/TabItem";\n\n`,
77
+
65
78
  createVersionBadge(version),
66
79
  `# ${escape(title)}\n\n`,
80
+ createLogo(logo, darkLogo),
67
81
  createDescription(description),
68
82
  createAuthentication(securitySchemes as unknown as SecuritySchemeObject),
69
83
  createContactInfo(contact as ContactObject),
@@ -128,6 +128,8 @@ function createItems(
128
128
  getTagDisplayName(tagName.name!, openapiData.tags ?? [])
129
129
  ),
130
130
  title: openapiData.info.title ?? "Introduction",
131
+ logo: openapiData.info["x-logo"]! as any,
132
+ darkLogo: openapiData.info["x-dark-logo"]! as any,
131
133
  },
132
134
  };
133
135
  items.push(infoPage);
@@ -42,6 +42,14 @@ export interface InfoObject {
42
42
  license?: LicenseObject;
43
43
  version: string;
44
44
  tags?: String[];
45
+ "x-logo"?: LogoObject;
46
+ "x-dark-logo"?: LogoObject;
47
+ logo?: LogoObject;
48
+ darkLogo?: LogoObject;
49
+ }
50
+
51
+ export interface LogoObject {
52
+ url?: string;
45
53
  }
46
54
 
47
55
  export interface ContactObject {