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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -105,17 +105,19 @@ function pluginOpenAPIDocs(context, options) {
105
105
  // TODO: figure out better way to set default
106
106
  if (Object.keys(sidebarOptions !== null && sidebarOptions !== void 0 ? sidebarOptions : {}).length > 0) {
107
107
  const sidebarSlice = (0, sidebars_1.default)(sidebarOptions, options, loadedApi, tags, docPath);
108
- const sidebarSliceTemplate = `module.exports = {{{slice}}};`;
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
111
  const view = (0, mustache_1.render)(sidebarSliceTemplate, {
110
- slice: JSON.stringify(sidebarSlice),
112
+ slice: JSON.stringify(sidebarSlice, null, 2),
111
113
  });
112
- if (!fs_1.default.existsSync(`${outputDir}/sidebar.js`)) {
114
+ if (!fs_1.default.existsSync(`${outputDir}/sidebar.ts`)) {
113
115
  try {
114
- fs_1.default.writeFileSync(`${outputDir}/sidebar.js`, view, "utf8");
115
- console.log(chalk_1.default.green(`Successfully created "${outputDir}/sidebar.js"`));
116
+ fs_1.default.writeFileSync(`${outputDir}/sidebar.ts`, view, "utf8");
117
+ console.log(chalk_1.default.green(`Successfully created "${outputDir}/sidebar.ts"`));
116
118
  }
117
119
  catch (err) {
118
- console.error(chalk_1.default.red(`Failed to write "${outputDir}/sidebar.js"`), chalk_1.default.yellow(err));
120
+ console.error(chalk_1.default.red(`Failed to write "${outputDir}/sidebar.ts"`), chalk_1.default.yellow(err));
119
121
  }
120
122
  }
121
123
  }
@@ -290,7 +292,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
290
292
  cwd: path_1.default.resolve(apiDir),
291
293
  deep: 1,
292
294
  });
293
- const sidebarFile = await (0, utils_1.Globby)(["sidebar.js"], {
295
+ const sidebarFile = await (0, utils_1.Globby)(["sidebar.ts"], {
294
296
  cwd: path_1.default.resolve(apiDir),
295
297
  deep: 1,
296
298
  });
@@ -346,7 +348,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
346
348
  extendCli(cli) {
347
349
  cli
348
350
  .command(`gen-api-docs`)
349
- .description(`Generates OpenAPI docs in MDX file format and sidebar.js (if enabled).`)
351
+ .description(`Generates OpenAPI docs in MDX file format and sidebar.ts (if enabled).`)
350
352
  .usage("<id>")
351
353
  .arguments("<id>")
352
354
  .option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
@@ -394,7 +396,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
394
396
  });
395
397
  cli
396
398
  .command(`gen-api-docs:version`)
397
- .description(`Generates versioned OpenAPI docs in MDX file format, versions.js and sidebar.js (if enabled).`)
399
+ .description(`Generates versioned OpenAPI docs in MDX file format, versions.js and sidebar.ts (if enabled).`)
398
400
  .usage("<id:version>")
399
401
  .arguments("<id:version>")
400
402
  .option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
@@ -469,7 +471,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
469
471
  });
470
472
  cli
471
473
  .command(`clean-api-docs`)
472
- .description(`Clears the generated OpenAPI docs MDX files and sidebar.js (if enabled).`)
474
+ .description(`Clears the generated OpenAPI docs MDX files and sidebar.ts (if enabled).`)
473
475
  .usage("<id>")
474
476
  .arguments("<id>")
475
477
  .option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
@@ -512,7 +514,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
512
514
  });
513
515
  cli
514
516
  .command(`clean-api-docs:version`)
515
- .description(`Clears the versioned, generated OpenAPI docs MDX files, versions.json and sidebar.js (if enabled).`)
517
+ .description(`Clears the versioned, generated OpenAPI docs MDX files, versions.json and sidebar.ts (if enabled).`)
516
518
  .usage("<id:version>")
517
519
  .arguments("<id:version>")
518
520
  .option("-p, --plugin-id <plugin>", "OpenAPI docs plugin ID.")
@@ -12,8 +12,11 @@ function createAdmonition({ children }) {
12
12
  return `:::caution deprecated\n\n${(0, utils_1.render)(children)}\n\n:::`;
13
13
  }
14
14
  function createDeprecationNotice({ deprecated, description, }) {
15
- return (0, utils_1.guard)(deprecated, () => createAdmonition({
16
- children: description !== null && description !== void 0 ? description : "This endpoint has been deprecated and may be replaced or removed in future versions of the API.",
17
- }));
15
+ return (0, utils_1.guard)(deprecated, () => {
16
+ var _a;
17
+ return createAdmonition({
18
+ children: (_a = (0, utils_1.clean)(description)) !== null && _a !== void 0 ? _a : "This endpoint has been deprecated and may be replaced or removed in future versions of the API.",
19
+ });
20
+ });
18
21
  }
19
22
  exports.createDeprecationNotice = createDeprecationNotice;
@@ -9,14 +9,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.createDescription = void 0;
10
10
  const utils_1 = require("./utils");
11
11
  function createDescription(description) {
12
- if (!description) {
13
- return "";
14
- }
15
- return `\n\n${description
16
- .replace(utils_1.lessThan, "&lt;")
17
- .replace(utils_1.greaterThan, "&gt;")
18
- .replace(utils_1.codeFence, function (match) {
19
- return match.replace(/\\>/g, ">");
20
- })}\n\n`;
12
+ return `\n\n${(0, utils_1.clean)(description)}\n\n`;
21
13
  }
22
14
  exports.createDescription = createDescription;
@@ -12,9 +12,7 @@ function createHeading(heading) {
12
12
  return [
13
13
  (0, utils_1.create)("h1", {
14
14
  className: "openapi__heading",
15
- children: `${heading
16
- .replace(utils_1.lessThan, "&lt;")
17
- .replace(utils_1.greaterThan, "&gt;")}`,
15
+ children: (0, utils_1.clean)(heading),
18
16
  }),
19
17
  `\n\n`,
20
18
  ];
@@ -32,7 +32,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
32
32
  const prettier = __importStar(require("prettier"));
33
33
  const createSchema_1 = require("./createSchema");
34
34
  describe("createNodes", () => {
35
- it("should create readable MODs for oneOf primitive properties", () => {
35
+ it("should create readable MODs for oneOf primitive properties", async () => {
36
36
  const schema = {
37
37
  type: "object",
38
38
  properties: {
@@ -68,6 +68,6 @@ describe("createNodes", () => {
68
68
  },
69
69
  },
70
70
  };
71
- expect((0, createSchema_1.createNodes)(schema, "request").map((md) => prettier.format(md, { parser: "babel" }))).toMatchSnapshot();
71
+ expect(await Promise.all((0, createSchema_1.createNodes)(schema, "request").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
72
72
  });
73
73
  });
@@ -37,7 +37,7 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
37
37
  `import SchemaItem from "@theme/SchemaItem";\n`,
38
38
  `import SchemaTabs from "@theme/SchemaTabs";\n`,
39
39
  `import TabItem from "@theme/TabItem";\n\n`,
40
- (0, createHeading_1.createHeading)(title.replace(utils_1.lessThan, "&lt;").replace(utils_1.greaterThan, "&gt;")),
40
+ (0, createHeading_1.createHeading)(title),
41
41
  (0, createMethodEndpoint_1.createMethodEndpoint)(method, path),
42
42
  infoPath && (0, createAuthorization_1.createAuthorization)(infoPath),
43
43
  frontMatter.show_extensions && (0, createVendorExtensions_1.createVendorExtensions)(extensions),
@@ -64,7 +64,7 @@ function createInfoPageMD({ info: { title, version, description, contact, licens
64
64
  `import Export from "@theme/ApiExplorer/Export";\n\n`,
65
65
  (0, createVersionBadge_1.createVersionBadge)(version),
66
66
  (0, createDownload_1.createDownload)(downloadUrl),
67
- (0, createHeading_1.createHeading)(title.replace(utils_1.lessThan, "&lt;").replace(utils_1.greaterThan, "&gt;")),
67
+ (0, createHeading_1.createHeading)(title),
68
68
  (0, createLogo_1.createLogo)(logo, darkLogo),
69
69
  (0, createDescription_1.createDescription)(description),
70
70
  (0, createAuthentication_1.createAuthentication)(securitySchemes),
@@ -1,5 +1,5 @@
1
- export declare type Children = string | undefined | (string | string[] | undefined)[];
2
- export declare type Props = Record<string, any> & {
1
+ export type Children = string | undefined | (string | string[] | undefined)[];
2
+ export type Props = Record<string, any> & {
3
3
  children?: Children;
4
4
  };
5
5
  export declare function create(tag: string, props: Props): string;
@@ -8,3 +8,6 @@ export declare function render(children: Children): string;
8
8
  export declare const lessThan: RegExp;
9
9
  export declare const greaterThan: RegExp;
10
10
  export declare const codeFence: RegExp;
11
+ export declare const curlyBrackets: RegExp;
12
+ export declare const codeBlock: RegExp;
13
+ export declare function clean(value: string | undefined): string;
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  * ========================================================================== */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.codeFence = exports.greaterThan = exports.lessThan = exports.render = exports.guard = exports.create = void 0;
9
+ exports.clean = exports.codeBlock = exports.curlyBrackets = exports.codeFence = exports.greaterThan = exports.lessThan = exports.render = exports.guard = exports.create = void 0;
10
10
  function create(tag, props) {
11
11
  const { children, ...rest } = props;
12
12
  let propString = "";
@@ -41,3 +41,24 @@ 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;
46
+ function clean(value) {
47
+ if (!value) {
48
+ return "";
49
+ }
50
+ let sections = value.split(exports.codeBlock);
51
+ for (let sectionIndex in sections) {
52
+ if (!sections[sectionIndex].startsWith("```")) {
53
+ sections[sectionIndex] = sections[sectionIndex]
54
+ .replace(exports.lessThan, "&lt;")
55
+ .replace(exports.greaterThan, "&gt;")
56
+ .replace(exports.codeFence, function (match) {
57
+ return match.replace(/\\>/g, ">");
58
+ })
59
+ .replace(exports.curlyBrackets, "\\{$1\\}");
60
+ }
61
+ }
62
+ return sections.join("");
63
+ }
64
+ exports.clean = clean;
@@ -81,8 +81,8 @@ export interface ComponentsObjectWithRef {
81
81
  links?: Map<LinkObject | ReferenceObject>;
82
82
  callbacks?: Map<CallbackObjectWithRef | ReferenceObject>;
83
83
  }
84
- export declare type PathsObject = Map<PathItemObject>;
85
- export declare type PathsObjectWithRef = Map<PathItemObjectWithRef>;
84
+ export type PathsObject = Map<PathItemObject>;
85
+ export type PathsObjectWithRef = Map<PathItemObjectWithRef>;
86
86
  export interface PathItemObject {
87
87
  $ref?: string;
88
88
  summary?: string;
@@ -214,8 +214,8 @@ export interface EncodingObjectWithRef {
214
214
  explode?: boolean;
215
215
  allowReserved?: boolean;
216
216
  }
217
- export declare type ResponsesObject = Map<ResponseObject>;
218
- export declare type ResponsesObjectWithRef = Map<ResponseObjectWithRef | ReferenceObject>;
217
+ export type ResponsesObject = Map<ResponseObject>;
218
+ export type ResponsesObjectWithRef = Map<ResponseObjectWithRef | ReferenceObject>;
219
219
  export interface ResponseObject {
220
220
  description: string;
221
221
  headers?: Map<HeaderObject>;
@@ -228,8 +228,8 @@ export interface ResponseObjectWithRef {
228
228
  content?: Map<MediaTypeObjectWithRef>;
229
229
  links?: Map<LinkObject | ReferenceObject>;
230
230
  }
231
- export declare type CallbackObject = Map<PathItemObject>;
232
- export declare type CallbackObjectWithRef = Map<PathItemObjectWithRef>;
231
+ export type CallbackObject = Map<PathItemObject>;
232
+ export type CallbackObjectWithRef = Map<PathItemObjectWithRef>;
233
233
  export interface ExampleObject {
234
234
  summary?: string;
235
235
  description?: string;
@@ -244,8 +244,8 @@ export interface LinkObject {
244
244
  description?: string;
245
245
  server?: ServerObject;
246
246
  }
247
- export declare type HeaderObject = Omit<ParameterObject, "name" | "in">;
248
- export declare type HeaderObjectWithRef = Omit<ParameterObjectWithRef, "name" | "in">;
247
+ export type HeaderObject = Omit<ParameterObject, "name" | "in">;
248
+ export type HeaderObjectWithRef = Omit<ParameterObjectWithRef, "name" | "in">;
249
249
  export interface TagObject {
250
250
  name?: string;
251
251
  description?: string;
@@ -255,8 +255,8 @@ export interface TagObject {
255
255
  export interface ReferenceObject {
256
256
  $ref: string;
257
257
  }
258
- export declare type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
259
- export declare type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
258
+ export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
259
+ export type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
260
260
  type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
261
261
  allOf?: SchemaObject[];
262
262
  oneOf?: SchemaObject[];
@@ -274,7 +274,7 @@ export declare type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" |
274
274
  example?: any;
275
275
  deprecated?: boolean;
276
276
  };
277
- export declare type SchemaObjectWithRef = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
277
+ export type SchemaObjectWithRef = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
278
278
  type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
279
279
  allOf?: (SchemaObject | ReferenceObject)[];
280
280
  oneOf?: (SchemaObject | ReferenceObject)[];
@@ -303,7 +303,7 @@ export interface XMLObject {
303
303
  attribute?: boolean;
304
304
  wrapped?: boolean;
305
305
  }
306
- export declare type SecuritySchemeObject = ApiKeySecuritySchemeObject | HttpSecuritySchemeObject | Oauth2SecuritySchemeObject | OpenIdConnectSecuritySchemeObject;
306
+ export type SecuritySchemeObject = ApiKeySecuritySchemeObject | HttpSecuritySchemeObject | Oauth2SecuritySchemeObject | OpenIdConnectSecuritySchemeObject;
307
307
  export interface ApiKeySecuritySchemeObject {
308
308
  type: "apiKey";
309
309
  description?: string;
@@ -340,5 +340,5 @@ export interface OAuthFlowObject {
340
340
  refreshUrl?: string;
341
341
  scopes: Map<string>;
342
342
  }
343
- export declare type SecurityRequirementObject = Map<string[]>;
343
+ export type SecurityRequirementObject = Map<string[]>;
344
344
  export {};
@@ -1,5 +1,5 @@
1
1
  import { OpenAPIRef, OpenAPISchema, OpenAPISpec, Referenced } from "../types";
2
- export declare type MergedOpenAPISchema = OpenAPISchema & {
2
+ export type MergedOpenAPISchema = OpenAPISchema & {
3
3
  parentRefs?: string[];
4
4
  };
5
5
  /**
@@ -39,55 +39,6 @@ function argValueToExpandLevel(value, defaultValue = 0) {
39
39
  return argValueToNumber(value) || defaultValue;
40
40
  }
41
41
  class RedocNormalizedOptions {
42
- constructor(raw, defaults = {}) {
43
- var _a;
44
- raw = { ...defaults, ...raw };
45
- this.hideHostname = RedocNormalizedOptions.normalizeHideHostname(raw.hideHostname);
46
- this.expandResponses = RedocNormalizedOptions.normalizeExpandResponses(raw.expandResponses);
47
- this.requiredPropsFirst = argValueToBoolean(raw.requiredPropsFirst);
48
- this.sortPropsAlphabetically = argValueToBoolean(raw.sortPropsAlphabetically);
49
- this.sortEnumValuesAlphabetically = argValueToBoolean(raw.sortEnumValuesAlphabetically);
50
- this.sortOperationsAlphabetically = argValueToBoolean(raw.sortOperationsAlphabetically);
51
- this.sortTagsAlphabetically = argValueToBoolean(raw.sortTagsAlphabetically);
52
- this.nativeScrollbars = argValueToBoolean(raw.nativeScrollbars);
53
- this.pathInMiddlePanel = argValueToBoolean(raw.pathInMiddlePanel);
54
- this.untrustedSpec = argValueToBoolean(raw.untrustedSpec);
55
- this.hideDownloadButton = argValueToBoolean(raw.hideDownloadButton);
56
- this.downloadFileName = raw.downloadFileName;
57
- this.downloadDefinitionUrl = raw.downloadDefinitionUrl;
58
- this.disableSearch = argValueToBoolean(raw.disableSearch);
59
- this.onlyRequiredInSamples = argValueToBoolean(raw.onlyRequiredInSamples);
60
- this.showExtensions = RedocNormalizedOptions.normalizeShowExtensions(raw.showExtensions);
61
- this.sideNavStyle = RedocNormalizedOptions.normalizeSideNavStyle(raw.sideNavStyle);
62
- this.hideSingleRequestSampleTab = argValueToBoolean(raw.hideSingleRequestSampleTab);
63
- this.menuToggle = argValueToBoolean(raw.menuToggle, true);
64
- this.jsonSampleExpandLevel =
65
- RedocNormalizedOptions.normalizeJsonSampleExpandLevel(raw.jsonSampleExpandLevel);
66
- this.enumSkipQuotes = argValueToBoolean(raw.enumSkipQuotes);
67
- this.hideSchemaTitles = argValueToBoolean(raw.hideSchemaTitles);
68
- this.simpleOneOfTypeLabel = argValueToBoolean(raw.simpleOneOfTypeLabel);
69
- this.payloadSampleIdx = RedocNormalizedOptions.normalizePayloadSampleIdx(raw.payloadSampleIdx);
70
- this.expandSingleSchemaField = argValueToBoolean(raw.expandSingleSchemaField);
71
- this.schemaExpansionLevel = argValueToExpandLevel(raw.schemaExpansionLevel);
72
- this.showObjectSchemaExamples = argValueToBoolean(raw.showObjectSchemaExamples);
73
- this.showSecuritySchemeType = argValueToBoolean(raw.showSecuritySchemeType);
74
- this.hideSecuritySection = argValueToBoolean(raw.hideSecuritySection);
75
- this.unstable_ignoreMimeParameters = argValueToBoolean(raw.unstable_ignoreMimeParameters);
76
- this.expandDefaultServerVariables = argValueToBoolean(raw.expandDefaultServerVariables);
77
- this.maxDisplayedEnumValues = argValueToNumber(raw.maxDisplayedEnumValues);
78
- const ignoreNamedSchemas = (0, helpers_1.isArray)(raw.ignoreNamedSchemas)
79
- ? raw.ignoreNamedSchemas
80
- : (_a = raw.ignoreNamedSchemas) === null || _a === void 0 ? void 0 : _a.split(",").map((s) => s.trim());
81
- this.ignoreNamedSchemas = new Set(ignoreNamedSchemas);
82
- this.hideSchemaPattern = argValueToBoolean(raw.hideSchemaPattern);
83
- this.generatedPayloadSamplesMaxDepth =
84
- RedocNormalizedOptions.normalizeGeneratedPayloadSamplesMaxDepth(raw.generatedPayloadSamplesMaxDepth);
85
- this.nonce = raw.nonce;
86
- this.hideFab = argValueToBoolean(raw.hideFab);
87
- this.minCharacterLengthToInitSearch =
88
- argValueToNumber(raw.minCharacterLengthToInitSearch) || 3;
89
- this.showWebhookVerb = argValueToBoolean(raw.showWebhookVerb);
90
- }
91
42
  static normalizeExpandResponses(value) {
92
43
  if (value === "all") {
93
44
  return "all";
@@ -166,5 +117,54 @@ class RedocNormalizedOptions {
166
117
  }
167
118
  return 10;
168
119
  }
120
+ constructor(raw, defaults = {}) {
121
+ var _a;
122
+ raw = { ...defaults, ...raw };
123
+ this.hideHostname = RedocNormalizedOptions.normalizeHideHostname(raw.hideHostname);
124
+ this.expandResponses = RedocNormalizedOptions.normalizeExpandResponses(raw.expandResponses);
125
+ this.requiredPropsFirst = argValueToBoolean(raw.requiredPropsFirst);
126
+ this.sortPropsAlphabetically = argValueToBoolean(raw.sortPropsAlphabetically);
127
+ this.sortEnumValuesAlphabetically = argValueToBoolean(raw.sortEnumValuesAlphabetically);
128
+ this.sortOperationsAlphabetically = argValueToBoolean(raw.sortOperationsAlphabetically);
129
+ this.sortTagsAlphabetically = argValueToBoolean(raw.sortTagsAlphabetically);
130
+ this.nativeScrollbars = argValueToBoolean(raw.nativeScrollbars);
131
+ this.pathInMiddlePanel = argValueToBoolean(raw.pathInMiddlePanel);
132
+ this.untrustedSpec = argValueToBoolean(raw.untrustedSpec);
133
+ this.hideDownloadButton = argValueToBoolean(raw.hideDownloadButton);
134
+ this.downloadFileName = raw.downloadFileName;
135
+ this.downloadDefinitionUrl = raw.downloadDefinitionUrl;
136
+ this.disableSearch = argValueToBoolean(raw.disableSearch);
137
+ this.onlyRequiredInSamples = argValueToBoolean(raw.onlyRequiredInSamples);
138
+ this.showExtensions = RedocNormalizedOptions.normalizeShowExtensions(raw.showExtensions);
139
+ this.sideNavStyle = RedocNormalizedOptions.normalizeSideNavStyle(raw.sideNavStyle);
140
+ this.hideSingleRequestSampleTab = argValueToBoolean(raw.hideSingleRequestSampleTab);
141
+ this.menuToggle = argValueToBoolean(raw.menuToggle, true);
142
+ this.jsonSampleExpandLevel =
143
+ RedocNormalizedOptions.normalizeJsonSampleExpandLevel(raw.jsonSampleExpandLevel);
144
+ this.enumSkipQuotes = argValueToBoolean(raw.enumSkipQuotes);
145
+ this.hideSchemaTitles = argValueToBoolean(raw.hideSchemaTitles);
146
+ this.simpleOneOfTypeLabel = argValueToBoolean(raw.simpleOneOfTypeLabel);
147
+ this.payloadSampleIdx = RedocNormalizedOptions.normalizePayloadSampleIdx(raw.payloadSampleIdx);
148
+ this.expandSingleSchemaField = argValueToBoolean(raw.expandSingleSchemaField);
149
+ this.schemaExpansionLevel = argValueToExpandLevel(raw.schemaExpansionLevel);
150
+ this.showObjectSchemaExamples = argValueToBoolean(raw.showObjectSchemaExamples);
151
+ this.showSecuritySchemeType = argValueToBoolean(raw.showSecuritySchemeType);
152
+ this.hideSecuritySection = argValueToBoolean(raw.hideSecuritySection);
153
+ this.unstable_ignoreMimeParameters = argValueToBoolean(raw.unstable_ignoreMimeParameters);
154
+ this.expandDefaultServerVariables = argValueToBoolean(raw.expandDefaultServerVariables);
155
+ this.maxDisplayedEnumValues = argValueToNumber(raw.maxDisplayedEnumValues);
156
+ const ignoreNamedSchemas = (0, helpers_1.isArray)(raw.ignoreNamedSchemas)
157
+ ? raw.ignoreNamedSchemas
158
+ : (_a = raw.ignoreNamedSchemas) === null || _a === void 0 ? void 0 : _a.split(",").map((s) => s.trim());
159
+ this.ignoreNamedSchemas = new Set(ignoreNamedSchemas);
160
+ this.hideSchemaPattern = argValueToBoolean(raw.hideSchemaPattern);
161
+ this.generatedPayloadSamplesMaxDepth =
162
+ RedocNormalizedOptions.normalizeGeneratedPayloadSamplesMaxDepth(raw.generatedPayloadSamplesMaxDepth);
163
+ this.nonce = raw.nonce;
164
+ this.hideFab = argValueToBoolean(raw.hideFab);
165
+ this.minCharacterLengthToInitSearch =
166
+ argValueToNumber(raw.minCharacterLengthToInitSearch) || 3;
167
+ this.showWebhookVerb = argValueToBoolean(raw.showWebhookVerb);
168
+ }
169
169
  }
170
170
  exports.RedocNormalizedOptions = RedocNormalizedOptions;
@@ -1,2 +1,2 @@
1
1
  export * from "./open-api";
2
- export declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
2
+ export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
@@ -38,7 +38,7 @@ export interface OpenAPIPaths {
38
38
  export interface OpenAPIRef {
39
39
  $ref: string;
40
40
  }
41
- export declare type Referenced<T> = OpenAPIRef | T;
41
+ export type Referenced<T> = OpenAPIRef | T;
42
42
  export interface OpenAPIPath {
43
43
  summary?: string;
44
44
  description?: string;
@@ -182,8 +182,8 @@ export interface OpenAPIEncoding {
182
182
  explode: boolean;
183
183
  allowReserved: boolean;
184
184
  }
185
- export declare type OpenAPIParameterLocation = "query" | "header" | "path" | "cookie";
186
- export declare type OpenAPIParameterStyle = "matrix" | "label" | "form" | "simple" | "spaceDelimited" | "pipeDelimited" | "deepObject";
185
+ export type OpenAPIParameterLocation = "query" | "header" | "path" | "cookie";
186
+ export type OpenAPIParameterStyle = "matrix" | "label" | "form" | "simple" | "spaceDelimited" | "pipeDelimited" | "deepObject";
187
187
  export interface OpenAPIRequestBody {
188
188
  description?: string;
189
189
  required?: boolean;
@@ -216,7 +216,7 @@ export interface OpenAPIResponse extends Pick<OpenAPIRequestBody, "description"
216
216
  export interface OpenAPILink {
217
217
  $ref?: string;
218
218
  }
219
- export declare type OpenAPIHeader = Omit<OpenAPIParameter, "in" | "name">;
219
+ export type OpenAPIHeader = Omit<OpenAPIParameter, "in" | "name">;
220
220
  export interface OpenAPICallback {
221
221
  [name: string]: OpenAPIPath;
222
222
  }
@@ -1,4 +1,4 @@
1
- declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
1
+ type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
2
2
  export interface OpenAPISpec {
3
3
  openapi: string;
4
4
  info: OpenAPIInfo;
@@ -38,7 +38,7 @@ export interface OpenAPIPaths {
38
38
  export interface OpenAPIRef {
39
39
  $ref: string;
40
40
  }
41
- export declare type Referenced<T> = OpenAPIRef | T;
41
+ export type Referenced<T> = OpenAPIRef | T;
42
42
  export interface OpenAPIPath {
43
43
  summary?: string;
44
44
  description?: string;
@@ -182,8 +182,8 @@ export interface OpenAPIEncoding {
182
182
  explode: boolean;
183
183
  allowReserved: boolean;
184
184
  }
185
- export declare type OpenAPIParameterLocation = "query" | "header" | "path" | "cookie";
186
- export declare type OpenAPIParameterStyle = "matrix" | "label" | "form" | "simple" | "spaceDelimited" | "pipeDelimited" | "deepObject";
185
+ export type OpenAPIParameterLocation = "query" | "header" | "path" | "cookie";
186
+ export type OpenAPIParameterStyle = "matrix" | "label" | "form" | "simple" | "spaceDelimited" | "pipeDelimited" | "deepObject";
187
187
  export interface OpenAPIRequestBody {
188
188
  description?: string;
189
189
  required?: boolean;
@@ -216,7 +216,7 @@ export interface OpenAPIResponse extends Pick<OpenAPIRequestBody, "description"
216
216
  export interface OpenAPILink {
217
217
  $ref?: string;
218
218
  }
219
- export declare type OpenAPIHeader = Omit<OpenAPIParameter, "in" | "name">;
219
+ export type OpenAPIHeader = Omit<OpenAPIParameter, "in" | "name">;
220
220
  export interface OpenAPICallback {
221
221
  [name: string]: OpenAPIPath;
222
222
  }
@@ -534,7 +534,7 @@ exports.setSecuritySchemePrefix = setSecuritySchemePrefix;
534
534
  const shortenHTTPVerb = (verb) => ({
535
535
  delete: "del",
536
536
  options: "opts",
537
- }[verb] || verb);
537
+ })[verb] || verb;
538
538
  exports.shortenHTTPVerb = shortenHTTPVerb;
539
539
  function isRedocExtension(key) {
540
540
  const redocExtensions = {
package/lib/types.d.ts CHANGED
@@ -48,7 +48,7 @@ export interface APIVersionOptions {
48
48
  export interface LoadedContent {
49
49
  loadedApi: ApiMetadata[];
50
50
  }
51
- export declare type ApiMetadata = ApiPageMetadata | InfoPageMetadata | TagPageMetadata;
51
+ export type ApiMetadata = ApiPageMetadata | InfoPageMetadata | TagPageMetadata;
52
52
  export interface ApiMetadataBase {
53
53
  sidebar?: string;
54
54
  previous?: ApiNavLink;
@@ -100,7 +100,7 @@ export interface TagPageMetadata extends ApiMetadataBase {
100
100
  tag: TagObject;
101
101
  markdown?: string;
102
102
  }
103
- export declare type ApiInfo = InfoObject;
103
+ export type ApiInfo = InfoObject;
104
104
  export interface ApiNavLink {
105
105
  title: string;
106
106
  permalink: 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": "3.0.0-beta.2",
4
+ "version": "3.0.0-beta.3",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -28,18 +28,19 @@
28
28
  "watch": "tsc --watch"
29
29
  },
30
30
  "devDependencies": {
31
- "@docusaurus/types": "^3.0.0",
31
+ "@docusaurus/types": "^3.0.1",
32
32
  "@types/fs-extra": "^9.0.13",
33
33
  "@types/json-pointer": "^1.0.31",
34
34
  "@types/json-schema": "^7.0.9",
35
35
  "@types/lodash": "^4.14.176",
36
- "@types/mustache": "^4.1.2"
36
+ "@types/mustache": "^4.1.2",
37
+ "eslint-plugin-prettier": "^5.0.1"
37
38
  },
38
39
  "dependencies": {
39
40
  "@apidevtools/json-schema-ref-parser": "^10.1.0",
40
- "@docusaurus/plugin-content-docs": "^3.0.0",
41
- "@docusaurus/utils": "^3.0.0",
42
- "@docusaurus/utils-validation": "^3.0.0",
41
+ "@docusaurus/plugin-content-docs": "^3.0.1",
42
+ "@docusaurus/utils": "^3.0.1",
43
+ "@docusaurus/utils-validation": "^3.0.1",
43
44
  "@paloaltonetworks/openapi-to-postmanv2": "3.1.0-hotfix.1",
44
45
  "@paloaltonetworks/postman-collection": "^4.1.0",
45
46
  "@redocly/openapi-core": "^1.0.0-beta.125",
@@ -60,5 +61,5 @@
60
61
  "engines": {
61
62
  "node": ">=14"
62
63
  },
63
- "gitHead": "9e573198abcfbdd4af3b89f92658d0bf94648cfa"
64
+ "gitHead": "4836267b8bcc01d496449e6d531663a00dfdb4ed"
64
65
  }
package/src/index.ts CHANGED
@@ -144,21 +144,23 @@ export default function pluginOpenAPIDocs(
144
144
  docPath
145
145
  );
146
146
 
147
- const sidebarSliceTemplate = `module.exports = {{{slice}}};`;
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
150
 
149
151
  const view = render(sidebarSliceTemplate, {
150
- slice: JSON.stringify(sidebarSlice),
152
+ slice: JSON.stringify(sidebarSlice, null, 2),
151
153
  });
152
154
 
153
- if (!fs.existsSync(`${outputDir}/sidebar.js`)) {
155
+ if (!fs.existsSync(`${outputDir}/sidebar.ts`)) {
154
156
  try {
155
- fs.writeFileSync(`${outputDir}/sidebar.js`, view, "utf8");
157
+ fs.writeFileSync(`${outputDir}/sidebar.ts`, view, "utf8");
156
158
  console.log(
157
- chalk.green(`Successfully created "${outputDir}/sidebar.js"`)
159
+ chalk.green(`Successfully created "${outputDir}/sidebar.ts"`)
158
160
  );
159
161
  } catch (err) {
160
162
  console.error(
161
- chalk.red(`Failed to write "${outputDir}/sidebar.js"`),
163
+ chalk.red(`Failed to write "${outputDir}/sidebar.ts"`),
162
164
  chalk.yellow(err)
163
165
  );
164
166
  }
@@ -261,8 +263,8 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
261
263
  item.type === "api"
262
264
  ? apiPageGenerator(item)
263
265
  : item.type === "info"
264
- ? infoPageGenerator(item)
265
- : tagPageGenerator(item);
266
+ ? infoPageGenerator(item)
267
+ : tagPageGenerator(item);
266
268
  item.markdown = markdown;
267
269
  if (item.type === "api") {
268
270
  // opportunity to compress JSON
@@ -380,7 +382,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
380
382
  cwd: path.resolve(apiDir),
381
383
  deep: 1,
382
384
  });
383
- const sidebarFile = await Globby(["sidebar.js"], {
385
+ const sidebarFile = await Globby(["sidebar.ts"], {
384
386
  cwd: path.resolve(apiDir),
385
387
  deep: 1,
386
388
  });
@@ -461,7 +463,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
461
463
  cli
462
464
  .command(`gen-api-docs`)
463
465
  .description(
464
- `Generates OpenAPI docs in MDX file format and sidebar.js (if enabled).`
466
+ `Generates OpenAPI docs in MDX file format and sidebar.ts (if enabled).`
465
467
  )
466
468
  .usage("<id>")
467
469
  .arguments("<id>")
@@ -519,7 +521,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
519
521
  cli
520
522
  .command(`gen-api-docs:version`)
521
523
  .description(
522
- `Generates versioned OpenAPI docs in MDX file format, versions.js and sidebar.js (if enabled).`
524
+ `Generates versioned OpenAPI docs in MDX file format, versions.js and sidebar.ts (if enabled).`
523
525
  )
524
526
  .usage("<id:version>")
525
527
  .arguments("<id:version>")
@@ -610,7 +612,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
610
612
  cli
611
613
  .command(`clean-api-docs`)
612
614
  .description(
613
- `Clears the generated OpenAPI docs MDX files and sidebar.js (if enabled).`
615
+ `Clears the generated OpenAPI docs MDX files and sidebar.ts (if enabled).`
614
616
  )
615
617
  .usage("<id>")
616
618
  .arguments("<id>")
@@ -661,7 +663,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
661
663
  cli
662
664
  .command(`clean-api-docs:version`)
663
665
  .description(
664
- `Clears the versioned, generated OpenAPI docs MDX files, versions.json and sidebar.js (if enabled).`
666
+ `Clears the versioned, generated OpenAPI docs MDX files, versions.json and sidebar.ts (if enabled).`
665
667
  )
666
668
  .usage("<id:version>")
667
669
  .arguments("<id:version>")
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import { guard, Props, render } from "./utils";
8
+ import { clean, guard, Props, render } from "./utils";
9
9
 
10
10
  function createAdmonition({ children }: Props) {
11
11
  return `:::caution deprecated\n\n${render(children)}\n\n:::`;
@@ -23,7 +23,7 @@ export function createDeprecationNotice({
23
23
  return guard(deprecated, () =>
24
24
  createAdmonition({
25
25
  children:
26
- description ??
26
+ clean(description) ??
27
27
  "This endpoint has been deprecated and may be replaced or removed in future versions of the API.",
28
28
  })
29
29
  );
@@ -5,16 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import { greaterThan, codeFence, lessThan } from "./utils";
8
+ import { clean } from "./utils";
9
9
 
10
10
  export function createDescription(description: string | undefined) {
11
- if (!description) {
12
- return "";
13
- }
14
- return `\n\n${description
15
- .replace(lessThan, "&lt;")
16
- .replace(greaterThan, "&gt;")
17
- .replace(codeFence, function (match) {
18
- return match.replace(/\\>/g, ">");
19
- })}\n\n`;
11
+ return `\n\n${clean(description)}\n\n`;
20
12
  }
@@ -5,15 +5,13 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import { create, greaterThan, lessThan } from "./utils";
8
+ import { clean, create } from "./utils";
9
9
 
10
10
  export function createHeading(heading: string) {
11
11
  return [
12
12
  create("h1", {
13
13
  className: "openapi__heading",
14
- children: `${heading
15
- .replace(lessThan, "&lt;")
16
- .replace(greaterThan, "&gt;")}`,
14
+ children: clean(heading),
17
15
  }),
18
16
  `\n\n`,
19
17
  ];
@@ -11,7 +11,7 @@ import { SchemaObject } from "../openapi/types";
11
11
  import { createNodes } from "./createSchema";
12
12
 
13
13
  describe("createNodes", () => {
14
- it("should create readable MODs for oneOf primitive properties", () => {
14
+ it("should create readable MODs for oneOf primitive properties", async () => {
15
15
  const schema: SchemaObject = {
16
16
  type: "object",
17
17
  properties: {
@@ -48,8 +48,10 @@ describe("createNodes", () => {
48
48
  },
49
49
  };
50
50
  expect(
51
- createNodes(schema, "request").map((md: any) =>
52
- prettier.format(md, { parser: "babel" })
51
+ await Promise.all(
52
+ createNodes(schema, "request").map(
53
+ async (md: any) => await prettier.format(md, { parser: "babel" })
54
+ )
53
55
  )
54
56
  ).toMatchSnapshot();
55
57
  });
@@ -29,7 +29,7 @@ import { createStatusCodes } from "./createStatusCodes";
29
29
  import { createTermsOfService } from "./createTermsOfService";
30
30
  import { createVendorExtensions } from "./createVendorExtensions";
31
31
  import { createVersionBadge } from "./createVersionBadge";
32
- import { greaterThan, lessThan, render } from "./utils";
32
+ import { render } from "./utils";
33
33
 
34
34
  interface Props {
35
35
  title: string;
@@ -69,7 +69,7 @@ export function createApiPageMD({
69
69
  `import SchemaItem from "@theme/SchemaItem";\n`,
70
70
  `import SchemaTabs from "@theme/SchemaTabs";\n`,
71
71
  `import TabItem from "@theme/TabItem";\n\n`,
72
- createHeading(title.replace(lessThan, "&lt;").replace(greaterThan, "&gt;")),
72
+ createHeading(title),
73
73
  createMethodEndpoint(method, path),
74
74
  infoPath && createAuthorization(infoPath),
75
75
  frontMatter.show_extensions && createVendorExtensions(extensions),
@@ -110,7 +110,7 @@ export function createInfoPageMD({
110
110
 
111
111
  createVersionBadge(version),
112
112
  createDownload(downloadUrl),
113
- createHeading(title.replace(lessThan, "&lt;").replace(greaterThan, "&gt;")),
113
+ createHeading(title),
114
114
  createLogo(logo, darkLogo),
115
115
  createDescription(description),
116
116
  createAuthentication(securitySchemes as unknown as SecuritySchemeObject),
@@ -50,3 +50,25 @@ 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;
55
+
56
+ export function clean(value: string | undefined): string {
57
+ if (!value) {
58
+ return "";
59
+ }
60
+
61
+ let sections = value.split(codeBlock);
62
+ for (let sectionIndex in sections) {
63
+ if (!sections[sectionIndex].startsWith("```")) {
64
+ sections[sectionIndex] = sections[sectionIndex]
65
+ .replace(lessThan, "&lt;")
66
+ .replace(greaterThan, "&gt;")
67
+ .replace(codeFence, function (match) {
68
+ return match.replace(/\\>/g, ">");
69
+ })
70
+ .replace(curlyBrackets, "\\{$1\\}");
71
+ }
72
+ }
73
+ return sections.join("");
74
+ }
@@ -326,8 +326,8 @@ export class OpenAPIParser {
326
326
  const receiverItems = isBoolean(receiver.items)
327
327
  ? { items: receiver.items }
328
328
  : receiver.items
329
- ? (Object.assign({}, receiver.items) as OpenAPISchema)
330
- : {};
329
+ ? (Object.assign({}, receiver.items) as OpenAPISchema)
330
+ : {};
331
331
  const subSchemaItems = isBoolean(items)
332
332
  ? { items }
333
333
  : (Object.assign({}, items) as OpenAPISchema);
@@ -689,7 +689,7 @@ export const shortenHTTPVerb = (verb) =>
689
689
  ({
690
690
  delete: "del",
691
691
  options: "opts",
692
- }[verb] || verb);
692
+ })[verb] || verb;
693
693
 
694
694
  export function isRedocExtension(key: string): boolean {
695
695
  const redocExtensions = {
@@ -228,5 +228,6 @@ export default function generateSidebarSlice(
228
228
  docPath
229
229
  );
230
230
  }
231
+
231
232
  return sidebarSlice;
232
233
  }