docusaurus-plugin-openapi-docs 3.0.0-beta.3 → 3.0.0-beta.5

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.
Files changed (34) hide show
  1. package/lib/index.js +6 -5
  2. package/lib/markdown/createCallbacks.d.ts +6 -0
  3. package/lib/markdown/createCallbacks.js +76 -0
  4. package/lib/markdown/createRequestBodyDetails.d.ts +1 -1
  5. package/lib/markdown/createStatusCodes.d.ts +3 -1
  6. package/lib/markdown/createStatusCodes.js +8 -6
  7. package/lib/markdown/index.d.ts +1 -1
  8. package/lib/markdown/index.js +8 -2
  9. package/lib/markdown/utils.js +4 -4
  10. package/lib/openapi/openapi.d.ts +1 -1
  11. package/lib/openapi/openapi.js +1 -1
  12. package/lib/openapi/utils/services/OpenAPIParser.js +2 -1
  13. package/package.json +3 -2
  14. package/src/index.ts +13 -5
  15. package/src/markdown/createAuthentication.ts +1 -1
  16. package/src/markdown/createCallbacks.ts +95 -0
  17. package/src/markdown/createContactInfo.ts +1 -1
  18. package/src/markdown/createLicense.ts +1 -1
  19. package/src/markdown/createLogo.ts +1 -1
  20. package/src/markdown/createParamsDetails.ts +1 -1
  21. package/src/markdown/createRequestBodyDetails.ts +2 -2
  22. package/src/markdown/createRequestSchema.ts +1 -1
  23. package/src/markdown/createResponseSchema.ts +1 -1
  24. package/src/markdown/createSchema.test.ts +1 -1
  25. package/src/markdown/createSchema.ts +1 -1
  26. package/src/markdown/createStatusCodes.ts +11 -7
  27. package/src/markdown/index.ts +17 -10
  28. package/src/markdown/utils.ts +4 -4
  29. package/src/openapi/createRequestExample.ts +1 -1
  30. package/src/openapi/createResponseExample.ts +1 -1
  31. package/src/openapi/openapi.ts +3 -3
  32. package/src/openapi/utils/loadAndResolveSpec.ts +1 -1
  33. package/src/openapi/utils/services/OpenAPIParser.ts +1 -1
  34. package/src/openapi/utils/utils/openapi.ts +7 -7
package/lib/index.js CHANGED
@@ -15,6 +15,7 @@ const path_1 = __importDefault(require("path"));
15
15
  const zlib_1 = __importDefault(require("zlib"));
16
16
  const utils_1 = require("@docusaurus/utils");
17
17
  const chalk_1 = __importDefault(require("chalk"));
18
+ const json5_1 = __importDefault(require("json5"));
18
19
  const mustache_1 = require("mustache");
19
20
  const markdown_1 = require("./markdown");
20
21
  const openapi_1 = require("./openapi");
@@ -105,11 +106,11 @@ function pluginOpenAPIDocs(context, options) {
105
106
  // TODO: figure out better way to set default
106
107
  if (Object.keys(sidebarOptions !== null && sidebarOptions !== void 0 ? sidebarOptions : {}).length > 0) {
107
108
  const sidebarSlice = (0, sidebars_1.default)(sidebarOptions, options, loadedApi, tags, docPath);
108
- let sidebarSliceTemplate = `import {SidebarConfig} from "@docusaurus/plugin-content-docs/src/sidebars/types";\n\n`;
109
- sidebarSliceTemplate += `const sidebar: SidebarConfig = {{{slice}}};\n\n`;
110
- sidebarSliceTemplate += `export default sidebar;`;
109
+ let sidebarSliceTemplate = `import type { SidebarsConfig } from "@docusaurus/plugin-content-docs";\n\n`;
110
+ sidebarSliceTemplate += `const sidebar: SidebarsConfig = {{{slice}}};\n\n`;
111
+ sidebarSliceTemplate += `export default sidebar.apisidebar;\n`;
111
112
  const view = (0, mustache_1.render)(sidebarSliceTemplate, {
112
- slice: JSON.stringify(sidebarSlice, null, 2),
113
+ slice: json5_1.default.stringify({ apisidebar: sidebarSlice }, { space: 2, quote: '"' }),
113
114
  });
114
115
  if (!fs_1.default.existsSync(`${outputDir}/sidebar.ts`)) {
115
116
  try {
@@ -324,7 +325,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
324
325
  }
325
326
  const versionsJson = JSON.stringify(versionsArray, null, 2);
326
327
  try {
327
- fs_1.default.writeFileSync(`${outputDir}/versions.json`, versionsJson, "utf8");
328
+ fs_1.default.writeFileSync(`${outputDir}/versions.json`, versionsJson + "\n", "utf8");
328
329
  console.log(chalk_1.default.green(`Successfully created "${outputDir}/versions.json"`));
329
330
  }
330
331
  catch (err) {
@@ -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 {};
@@ -11,13 +11,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.createStatusCodes = exports.createExampleFromSchema = exports.createResponseExample = exports.createResponseExamples = void 0;
13
13
  const xml_formatter_1 = __importDefault(require("xml-formatter"));
14
- const createResponseExample_1 = require("../openapi/createResponseExample");
15
14
  const createDescription_1 = require("./createDescription");
16
15
  const createDetails_1 = require("./createDetails");
17
16
  const createDetailsSummary_1 = require("./createDetailsSummary");
18
17
  const createResponseSchema_1 = require("./createResponseSchema");
19
18
  const utils_1 = require("./utils");
20
19
  const utils_2 = require("./utils");
20
+ const createResponseExample_1 = require("../openapi/createResponseExample");
21
21
  function json2xml(o, tab) {
22
22
  var toXml = function (v, name, ind) {
23
23
  var xml = "";
@@ -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),
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;
@@ -41,22 +41,22 @@ exports.render = render;
41
41
  exports.lessThan = /<=?(?!(=|button|\s?\/button|code|\s?\/code|details|\s?\/details|summary|\s?\/summary|hr|\s?\/hr|br|\s?\/br|span|\s?\/span|strong|\s?\/strong|small|\s?\/small|table|\s?\/table|thead|\s?\/thead|tbody|\s?\/tbody|td|\s?\/td|tr|\s?\/tr|th|\s?\/th|h1|\s?\/h1|h2|\s?\/h2|h3|\s?\/h3|h4|\s?\/h4|h5|\s?\/h5|h6|\s?\/h6|title|\s?\/title|p|\s?\/p|em|\s?\/em|b|\s?\/b|i|\s?\/i|u|\s?\/u|strike|\s?\/strike|bold|\s?\/bold|a|\s?\/a|table|\s?\/table|li|\s?\/li|ol|\s?\/ol|ul|\s?\/ul|img|\s?\/img|svg|\s?\/svg|div|\s?\/div|center|\s?\/center))/gu;
42
42
  exports.greaterThan = /(?<!(button|code|details|summary|hr|br|span|strong|small|table|thead|tbody|td|tr|th|h1|h2|h3|h4|h5|h6|title|p|em|b|i|u|strike|bold|a|li|ol|ul|img|svg|div|center|\/|\s|"|'))>/gu;
43
43
  exports.codeFence = /`{1,3}[\s\S]*?`{1,3}/g;
44
- exports.curlyBrackets = /\{(.*)}/g;
45
- exports.codeBlock = /^(```.*[\s\S]*?```)$/gm;
44
+ exports.curlyBrackets = /([{|}])/g;
45
+ exports.codeBlock = /(^```.*[\s\S]*?```$|`[^`].+?`)/gm;
46
46
  function clean(value) {
47
47
  if (!value) {
48
48
  return "";
49
49
  }
50
50
  let sections = value.split(exports.codeBlock);
51
51
  for (let sectionIndex in sections) {
52
- if (!sections[sectionIndex].startsWith("```")) {
52
+ if (!sections[sectionIndex].startsWith("`")) {
53
53
  sections[sectionIndex] = sections[sectionIndex]
54
54
  .replace(exports.lessThan, "&lt;")
55
55
  .replace(exports.greaterThan, "&gt;")
56
56
  .replace(exports.codeFence, function (match) {
57
57
  return match.replace(/\\>/g, ">");
58
58
  })
59
- .replace(exports.curlyBrackets, "\\{$1\\}");
59
+ .replace(exports.curlyBrackets, "\\$1");
60
60
  }
61
61
  }
62
62
  return sections.join("");
@@ -1,5 +1,5 @@
1
- import { ApiMetadata, APIOptions, SidebarOptions } from "../types";
2
1
  import { OpenApiObject, TagObject } from "./types";
2
+ import { ApiMetadata, APIOptions, SidebarOptions } from "../types";
3
3
  interface OpenApiFiles {
4
4
  source: string;
5
5
  sourceDirName: string;
@@ -20,9 +20,9 @@ const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
20
20
  const kebabCase_1 = __importDefault(require("lodash/kebabCase"));
21
21
  const unionBy_1 = __importDefault(require("lodash/unionBy"));
22
22
  const uniq_1 = __importDefault(require("lodash/uniq"));
23
- const index_1 = require("../index");
24
23
  const createRequestExample_1 = require("./createRequestExample");
25
24
  const loadAndResolveSpec_1 = require("./utils/loadAndResolveSpec");
25
+ const index_1 = require("../index");
26
26
  /**
27
27
  * Convenience function for converting raw JSON to a Postman Collection object.
28
28
  */
@@ -7,10 +7,11 @@
7
7
  * ========================================================================== */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.OpenAPIParser = void 0;
10
+ // @ts-nocheck
11
+ const RedocNormalizedOptions_1 = require("./RedocNormalizedOptions");
10
12
  const helpers_1 = require("../utils/helpers");
11
13
  const JsonPointer_1 = require("../utils/JsonPointer");
12
14
  const openapi_1 = require("../utils/openapi");
13
- const RedocNormalizedOptions_1 = require("./RedocNormalizedOptions");
14
15
  /**
15
16
  * Helper class to keep track of visited references to avoid
16
17
  * endless recursion because of circular refs
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": "3.0.0-beta.3",
4
+ "version": "3.0.0-beta.5",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -49,6 +49,7 @@
49
49
  "fs-extra": "^9.0.1",
50
50
  "json-pointer": "^0.6.2",
51
51
  "json-schema-merge-allof": "^0.8.1",
52
+ "json5": "^2.2.3",
52
53
  "lodash": "^4.17.20",
53
54
  "mustache": "^4.2.0",
54
55
  "slugify": "^1.6.5",
@@ -61,5 +62,5 @@
61
62
  "engines": {
62
63
  "node": ">=14"
63
64
  },
64
- "gitHead": "4836267b8bcc01d496449e6d531663a00dfdb4ed"
65
+ "gitHead": "1f9c9fa811c1e9d42f3c3740a8f7407e3659d629"
65
66
  }
package/src/index.ts CHANGED
@@ -12,6 +12,7 @@ import zlib from "zlib";
12
12
  import type { LoadContext, Plugin } from "@docusaurus/types";
13
13
  import { Globby, posixPath } from "@docusaurus/utils";
14
14
  import chalk from "chalk";
15
+ import JSON5 from "json5";
15
16
  import { render } from "mustache";
16
17
 
17
18
  import { createApiPageMD, createInfoPageMD, createTagPageMD } from "./markdown";
@@ -144,12 +145,15 @@ export default function pluginOpenAPIDocs(
144
145
  docPath
145
146
  );
146
147
 
147
- let sidebarSliceTemplate = `import {SidebarConfig} from "@docusaurus/plugin-content-docs/src/sidebars/types";\n\n`;
148
- sidebarSliceTemplate += `const sidebar: SidebarConfig = {{{slice}}};\n\n`;
149
- sidebarSliceTemplate += `export default sidebar;`;
148
+ let sidebarSliceTemplate = `import type { SidebarsConfig } from "@docusaurus/plugin-content-docs";\n\n`;
149
+ sidebarSliceTemplate += `const sidebar: SidebarsConfig = {{{slice}}};\n\n`;
150
+ sidebarSliceTemplate += `export default sidebar.apisidebar;\n`;
150
151
 
151
152
  const view = render(sidebarSliceTemplate, {
152
- slice: JSON.stringify(sidebarSlice, null, 2),
153
+ slice: JSON5.stringify(
154
+ { apisidebar: sidebarSlice },
155
+ { space: 2, quote: '"' }
156
+ ),
153
157
  });
154
158
 
155
159
  if (!fs.existsSync(`${outputDir}/sidebar.ts`)) {
@@ -427,7 +431,11 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
427
431
 
428
432
  const versionsJson = JSON.stringify(versionsArray, null, 2);
429
433
  try {
430
- fs.writeFileSync(`${outputDir}/versions.json`, versionsJson, "utf8");
434
+ fs.writeFileSync(
435
+ `${outputDir}/versions.json`,
436
+ versionsJson + "\n",
437
+ "utf8"
438
+ );
431
439
  console.log(
432
440
  chalk.green(`Successfully created "${outputDir}/versions.json"`)
433
441
  );
@@ -5,9 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import { OAuthFlowObject, SecuritySchemeObject } from "../openapi/types";
9
8
  import { createDescription } from "./createDescription";
10
9
  import { create, guard } from "./utils";
10
+ import { OAuthFlowObject, SecuritySchemeObject } from "../openapi/types";
11
11
 
12
12
  export function createAuthentication(securitySchemes: SecuritySchemeObject) {
13
13
  if (!securitySchemes || !Object.keys(securitySchemes).length) return "";
@@ -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 { createDescription } from "./createDescription";
9
+ import { createMethodEndpoint } from "./createMethodEndpoint";
10
+ import { createRequestBodyDetails } from "./createRequestBodyDetails";
11
+ import { createStatusCodes } from "./createStatusCodes";
12
+ import { create } from "./utils";
13
+ import { MediaTypeObject } from "../openapi/types";
14
+ import { ApiItem } from "../types";
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
+ }
@@ -5,8 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import { ContactObject } from "../openapi/types";
9
8
  import { create, guard } from "./utils";
9
+ import { ContactObject } from "../openapi/types";
10
10
 
11
11
  export function createContactInfo(contact: ContactObject) {
12
12
  if (!contact || !Object.keys(contact).length) return "";
@@ -5,8 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import { LicenseObject } from "../openapi/types";
9
8
  import { create, guard } from "./utils";
9
+ import { LicenseObject } from "../openapi/types";
10
10
 
11
11
  export function createLicense(license: LicenseObject) {
12
12
  if (!license || !Object.keys(license).length) return "";
@@ -5,8 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import { LogoObject } from "../openapi/types";
9
8
  import { create, guard } from "./utils";
9
+ import { LogoObject } from "../openapi/types";
10
10
 
11
11
  export function createLogo(
12
12
  logo: LogoObject | undefined,
@@ -5,10 +5,10 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import { ApiItem } from "../types";
9
8
  import { createDetails } from "./createDetails";
10
9
  import { createDetailsSummary } from "./createDetailsSummary";
11
10
  import { create } from "./utils";
11
+ import { ApiItem } from "../types";
12
12
 
13
13
  interface Props {
14
14
  parameters: ApiItem["parameters"];
@@ -5,8 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import { MediaTypeObject } from "../openapi/types";
9
8
  import { createRequestSchema } from "./createRequestSchema";
9
+ import { MediaTypeObject } from "../openapi/types";
10
10
 
11
11
  interface Props {
12
12
  title: string;
@@ -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
  }
@@ -5,12 +5,12 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import { MediaTypeObject } from "../openapi/types";
9
8
  import { createDescription } from "./createDescription";
10
9
  import { createDetails } from "./createDetails";
11
10
  import { createDetailsSummary } from "./createDetailsSummary";
12
11
  import { createNodes } from "./createSchema";
13
12
  import { create, guard } from "./utils";
13
+ import { MediaTypeObject } from "../openapi/types";
14
14
 
15
15
  interface Props {
16
16
  style?: any;
@@ -5,7 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import { MediaTypeObject } from "../openapi/types";
9
8
  import { createDescription } from "./createDescription";
10
9
  import { createDetails } from "./createDetails";
11
10
  import { createDetailsSummary } from "./createDetailsSummary";
@@ -16,6 +15,7 @@ import {
16
15
  createResponseExamples,
17
16
  } from "./createStatusCodes";
18
17
  import { create, guard } from "./utils";
18
+ import { MediaTypeObject } from "../openapi/types";
19
19
 
20
20
  interface Props {
21
21
  style?: any;
@@ -7,8 +7,8 @@
7
7
 
8
8
  import * as prettier from "prettier";
9
9
 
10
- import { SchemaObject } from "../openapi/types";
11
10
  import { createNodes } from "./createSchema";
11
+ import { SchemaObject } from "../openapi/types";
12
12
 
13
13
  describe("createNodes", () => {
14
14
  it("should create readable MODs for oneOf primitive properties", async () => {
@@ -7,7 +7,6 @@
7
7
 
8
8
  import clsx from "clsx";
9
9
 
10
- import { SchemaObject } from "../openapi/types";
11
10
  import {
12
11
  createClosingArrayBracket,
13
12
  createOpeningArrayBracket,
@@ -17,6 +16,7 @@ import { createDetails } from "./createDetails";
17
16
  import { createDetailsSummary } from "./createDetailsSummary";
18
17
  import { getQualifierMessage, getSchemaName } from "./schema";
19
18
  import { create, guard } from "./utils";
19
+ import { SchemaObject } from "../openapi/types";
20
20
 
21
21
  const jsonSchemaMergeAllOf = require("json-schema-merge-allof");
22
22
 
@@ -7,14 +7,14 @@
7
7
 
8
8
  import format from "xml-formatter";
9
9
 
10
- import { sampleResponseFromSchema } from "../openapi/createResponseExample";
11
- import { ApiItem } from "../types";
12
10
  import { createDescription } from "./createDescription";
13
11
  import { createDetails } from "./createDetails";
14
12
  import { createDetailsSummary } from "./createDetailsSummary";
15
13
  import { createResponseSchema } from "./createResponseSchema";
16
14
  import { create } from "./utils";
17
15
  import { guard } from "./utils";
16
+ import { sampleResponseFromSchema } from "../openapi/createResponseExample";
17
+ import { ApiItem } from "../types";
18
18
 
19
19
  export default function json2xml(o: any, tab: any) {
20
20
  var toXml = function (v: any, name: string, ind: any) {
@@ -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", {
@@ -5,15 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import {
9
- ContactObject,
10
- LicenseObject,
11
- MediaTypeObject,
12
- SecuritySchemeObject,
13
- } from "../openapi/types";
14
- import { ApiPageMetadata, InfoPageMetadata, TagPageMetadata } from "../types";
15
8
  import { createAuthentication } from "./createAuthentication";
16
9
  import { createAuthorization } from "./createAuthorization";
10
+ import { createCallbacks } from "./createCallbacks";
17
11
  import { createContactInfo } from "./createContactInfo";
18
12
  import { createDeprecationNotice } from "./createDeprecationNotice";
19
13
  import { createDescription } from "./createDescription";
@@ -30,8 +24,15 @@ import { createTermsOfService } from "./createTermsOfService";
30
24
  import { createVendorExtensions } from "./createVendorExtensions";
31
25
  import { createVersionBadge } from "./createVersionBadge";
32
26
  import { render } from "./utils";
27
+ import {
28
+ ContactObject,
29
+ LicenseObject,
30
+ MediaTypeObject,
31
+ SecuritySchemeObject,
32
+ } from "../openapi/types";
33
+ import { ApiPageMetadata, InfoPageMetadata, TagPageMetadata } from "../types";
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),
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
 
@@ -50,8 +50,8 @@ export const lessThan =
50
50
  export const greaterThan =
51
51
  /(?<!(button|code|details|summary|hr|br|span|strong|small|table|thead|tbody|td|tr|th|h1|h2|h3|h4|h5|h6|title|p|em|b|i|u|strike|bold|a|li|ol|ul|img|svg|div|center|\/|\s|"|'))>/gu;
52
52
  export const codeFence = /`{1,3}[\s\S]*?`{1,3}/g;
53
- export const curlyBrackets = /\{(.*)}/g;
54
- export const codeBlock = /^(```.*[\s\S]*?```)$/gm;
53
+ export const curlyBrackets = /([{|}])/g;
54
+ export const codeBlock = /(^```.*[\s\S]*?```$|`[^`].+?`)/gm;
55
55
 
56
56
  export function clean(value: string | undefined): string {
57
57
  if (!value) {
@@ -60,14 +60,14 @@ export function clean(value: string | undefined): string {
60
60
 
61
61
  let sections = value.split(codeBlock);
62
62
  for (let sectionIndex in sections) {
63
- if (!sections[sectionIndex].startsWith("```")) {
63
+ if (!sections[sectionIndex].startsWith("`")) {
64
64
  sections[sectionIndex] = sections[sectionIndex]
65
65
  .replace(lessThan, "&lt;")
66
66
  .replace(greaterThan, "&gt;")
67
67
  .replace(codeFence, function (match) {
68
68
  return match.replace(/\\>/g, ">");
69
69
  })
70
- .replace(curlyBrackets, "\\{$1\\}");
70
+ .replace(curlyBrackets, "\\$1");
71
71
  }
72
72
  }
73
73
  return sections.join("");
@@ -8,8 +8,8 @@
8
8
  import chalk from "chalk";
9
9
  import merge from "lodash/merge";
10
10
 
11
- import { mergeAllOf } from "../markdown/createSchema";
12
11
  import { SchemaObject } from "./types";
12
+ import { mergeAllOf } from "../markdown/createSchema";
13
13
 
14
14
  interface OASTypeToTypeMap {
15
15
  string: string;
@@ -8,8 +8,8 @@
8
8
  import chalk from "chalk";
9
9
  import merge from "lodash/merge";
10
10
 
11
- import { mergeAllOf } from "../markdown/createSchema";
12
11
  import { SchemaObject } from "./types";
12
+ import { mergeAllOf } from "../markdown/createSchema";
13
13
 
14
14
  interface OASTypeToTypeMap {
15
15
  string: string;
@@ -18,6 +18,9 @@ import kebabCase from "lodash/kebabCase";
18
18
  import unionBy from "lodash/unionBy";
19
19
  import uniq from "lodash/uniq";
20
20
 
21
+ import { sampleRequestFromSchema } from "./createRequestExample";
22
+ import { OpenApiObject, TagObject } from "./types";
23
+ import { loadAndResolveSpec } from "./utils/loadAndResolveSpec";
21
24
  import { isURL } from "../index";
22
25
  import {
23
26
  ApiMetadata,
@@ -27,9 +30,6 @@ import {
27
30
  SidebarOptions,
28
31
  TagPageMetadata,
29
32
  } from "../types";
30
- import { sampleRequestFromSchema } from "./createRequestExample";
31
- import { OpenApiObject, TagObject } from "./types";
32
- import { loadAndResolveSpec } from "./utils/loadAndResolveSpec";
33
33
 
34
34
  /**
35
35
  * Convenience function for converting raw JSON to a Postman Collection object.
@@ -13,8 +13,8 @@ import chalk from "chalk";
13
13
  // @ts-ignore
14
14
  import { convertObj } from "swagger2openapi";
15
15
 
16
- import { OpenApiObject } from "../types";
17
16
  import { OpenAPIParser } from "./services/OpenAPIParser";
17
+ import { OpenApiObject } from "../types";
18
18
 
19
19
  function serializer(replacer: any, cycleReplacer: any) {
20
20
  var stack: any = [],
@@ -7,11 +7,11 @@
7
7
 
8
8
  // @ts-nocheck
9
9
 
10
+ import { RedocNormalizedOptions } from "./RedocNormalizedOptions";
10
11
  import { OpenAPIRef, OpenAPISchema, OpenAPISpec, Referenced } from "../types";
11
12
  import { isArray, isBoolean } from "../utils/helpers";
12
13
  import { JsonPointer } from "../utils/JsonPointer";
13
14
  import { getDefinitionName, isNamedDefinition } from "../utils/openapi";
14
- import { RedocNormalizedOptions } from "./RedocNormalizedOptions";
15
15
 
16
16
  export type MergedOpenAPISchema = OpenAPISchema & { parentRefs?: string[] };
17
17
 
@@ -9,6 +9,13 @@
9
9
 
10
10
  import { dirname } from "path";
11
11
 
12
+ import {
13
+ isNumeric,
14
+ removeQueryString,
15
+ resolveUrl,
16
+ isArray,
17
+ isBoolean,
18
+ } from "./helpers";
12
19
  import { OpenAPIParser } from "../services/OpenAPIParser";
13
20
  import {
14
21
  OpenAPIEncoding,
@@ -21,13 +28,6 @@ import {
21
28
  OpenAPIServer,
22
29
  Referenced,
23
30
  } from "../types";
24
- import {
25
- isNumeric,
26
- removeQueryString,
27
- resolveUrl,
28
- isArray,
29
- isBoolean,
30
- } from "./helpers";
31
31
 
32
32
  function isWildcardStatusCode(
33
33
  statusCode: string | number