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

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
@@ -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) {
@@ -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 = "";
@@ -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.4",
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": "1207af7a96b5d5a033f87e4a94b94f9b263c1f36"
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 "";
@@ -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;
@@ -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) {
@@ -5,13 +5,6 @@
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";
17
10
  import { createContactInfo } from "./createContactInfo";
@@ -30,6 +23,13 @@ import { createTermsOfService } from "./createTermsOfService";
30
23
  import { createVendorExtensions } from "./createVendorExtensions";
31
24
  import { createVersionBadge } from "./createVersionBadge";
32
25
  import { render } from "./utils";
26
+ import {
27
+ ContactObject,
28
+ LicenseObject,
29
+ MediaTypeObject,
30
+ SecuritySchemeObject,
31
+ } from "../openapi/types";
32
+ import { ApiPageMetadata, InfoPageMetadata, TagPageMetadata } from "../types";
33
33
 
34
34
  interface Props {
35
35
  title: string;
@@ -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