docusaurus-plugin-openapi-docs 0.0.0-409 → 0.0.0-412

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,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),
@@ -16,7 +16,8 @@ const openapi_to_postmanv2_1 = __importDefault(require("@paloaltonetworks/openap
16
16
  const postman_collection_1 = __importDefault(require("@paloaltonetworks/postman-collection"));
17
17
  const chalk_1 = __importDefault(require("chalk"));
18
18
  const fs_extra_1 = __importDefault(require("fs-extra"));
19
- const lodash_1 = require("lodash");
19
+ const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
20
+ const kebabCase_1 = __importDefault(require("lodash/kebabCase"));
20
21
  const index_1 = require("../index");
21
22
  const createExample_1 = require("./createExample");
22
23
  const loadAndResolveSpec_1 = require("./utils/loadAndResolveSpec");
@@ -41,7 +42,7 @@ function jsonToCollection(data) {
41
42
  async function createPostmanCollection(openapiData) {
42
43
  var _a, _b, _c, _d, _e, _f, _g, _h;
43
44
  // Create copy of openapiData
44
- const data = Object.assign({}, openapiData);
45
+ const data = (0, cloneDeep_1.default)(openapiData);
45
46
  // Including `servers` breaks postman, so delete all of them.
46
47
  delete data.servers;
47
48
  for (let pathItemObject of Object.values(data.paths)) {
@@ -61,7 +62,7 @@ function createItems(openapiData, sidebarOptions) {
61
62
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
62
63
  // TODO: Find a better way to handle this
63
64
  let items = [];
64
- const infoId = (0, lodash_1.kebabCase)(openapiData.info.title);
65
+ const infoId = (0, kebabCase_1.default)(openapiData.info.title);
65
66
  if ((sidebarOptions === null || sidebarOptions === void 0 ? void 0 : sidebarOptions.categoryLinkSource) === "tag") {
66
67
  // Only create an tag pages if categoryLinkSource set to tag.
67
68
  const tags = (_a = openapiData.tags) !== null && _a !== void 0 ? _a : [];
@@ -72,7 +73,7 @@ function createItems(openapiData, sidebarOptions) {
72
73
  .map((tag) => {
73
74
  var _a;
74
75
  const description = getTagDisplayName(tag.name, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []);
75
- const tagId = (0, lodash_1.kebabCase)(tag.name);
76
+ const tagId = (0, kebabCase_1.default)(tag.name);
76
77
  const tagPage = {
77
78
  type: "tag",
78
79
  id: tagId,
@@ -101,6 +102,8 @@ function createItems(openapiData, sidebarOptions) {
101
102
  ...openapiData.info,
102
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 : []); }),
103
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"],
104
107
  },
105
108
  };
106
109
  items.push(infoPage);
@@ -114,8 +117,8 @@ function createItems(openapiData, sidebarOptions) {
114
117
  (_h = (_g = operationObject.summary) !== null && _g !== void 0 ? _g : operationObject.operationId) !== null && _h !== void 0 ? _h : "";
115
118
  }
116
119
  const baseId = operationObject.operationId
117
- ? (0, lodash_1.kebabCase)(operationObject.operationId)
118
- : (0, lodash_1.kebabCase)(operationObject.summary);
120
+ ? (0, kebabCase_1.default)(operationObject.operationId)
121
+ : (0, kebabCase_1.default)(operationObject.summary);
119
122
  const servers = (_k = (_j = operationObject.servers) !== null && _j !== void 0 ? _j : pathObject.servers) !== null && _k !== void 0 ? _k : openapiData.servers;
120
123
  const security = (_l = operationObject.security) !== null && _l !== void 0 ? _l : openapiData.security;
121
124
  // Add security schemes so we know how to handle security.
@@ -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-409",
4
+ "version": "0.0.0-412",
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": "6cfbade709c0e80f79e91b3e4fa11dbf416490b5"
70
+ "gitHead": "6e093b9e84f83993a01f0922aaddb27d367d7485"
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),
@@ -13,7 +13,8 @@ import sdk from "@paloaltonetworks/postman-collection";
13
13
  import Collection from "@paloaltonetworks/postman-collection";
14
14
  import chalk from "chalk";
15
15
  import fs from "fs-extra";
16
- import { kebabCase } from "lodash";
16
+ import cloneDeep from "lodash/cloneDeep";
17
+ import kebabCase from "lodash/kebabCase";
17
18
 
18
19
  import { isURL } from "../index";
19
20
  import {
@@ -54,7 +55,7 @@ async function createPostmanCollection(
54
55
  openapiData: OpenApiObject
55
56
  ): Promise<Collection> {
56
57
  // Create copy of openapiData
57
- const data = Object.assign({}, openapiData) as OpenApiObject;
58
+ const data = cloneDeep(openapiData) as OpenApiObject;
58
59
 
59
60
  // Including `servers` breaks postman, so delete all of them.
60
61
  delete data.servers;
@@ -127,6 +128,8 @@ function createItems(
127
128
  getTagDisplayName(tagName.name!, openapiData.tags ?? [])
128
129
  ),
129
130
  title: openapiData.info.title ?? "Introduction",
131
+ logo: openapiData.info["x-logo"]! as any,
132
+ darkLogo: openapiData.info["x-dark-logo"]! as any,
130
133
  },
131
134
  };
132
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 {