docusaurus-plugin-openapi-docs 2.1.3 → 2.2.0

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.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { LoadContext, Plugin } from "@docusaurus/types";
2
2
  import type { PluginOptions, LoadedContent } from "./types";
3
3
  export declare function isURL(str: string): boolean;
4
- export declare function getDocsPluginConfig(presetsPlugins: any[], pluginId: string): Object | undefined;
4
+ export declare function getDocsPluginConfig(presetsPlugins: any[], plugin: string, pluginId: string): Object | undefined;
5
5
  declare function pluginOpenAPIDocs(context: LoadContext, options: PluginOptions): Plugin<LoadedContent>;
6
6
  declare namespace pluginOpenAPIDocs {
7
7
  var validateOptions: ({ options, validate }: any) => any;
package/lib/index.js CHANGED
@@ -24,7 +24,7 @@ function isURL(str) {
24
24
  return /^(https?:)\/\//m.test(str);
25
25
  }
26
26
  exports.isURL = isURL;
27
- function getDocsPluginConfig(presetsPlugins, pluginId) {
27
+ function getDocsPluginConfig(presetsPlugins, plugin, pluginId) {
28
28
  // eslint-disable-next-line array-callback-return
29
29
  const filteredConfig = presetsPlugins.filter((data) => {
30
30
  // Search presets
@@ -33,8 +33,7 @@ function getDocsPluginConfig(presetsPlugins, pluginId) {
33
33
  return data[1];
34
34
  }
35
35
  // Search plugin-content-docs instances
36
- if (typeof data[0] === "string" &&
37
- data[0] === "@docusaurus/plugin-content-docs") {
36
+ if (typeof data[0] === "string" && data[0] === plugin) {
38
37
  const configPluginId = data[1].id ? data[1].id : "default";
39
38
  if (configPluginId === pluginId) {
40
39
  return data[1];
@@ -48,7 +47,7 @@ function getDocsPluginConfig(presetsPlugins, pluginId) {
48
47
  return filteredConfig[1].docs;
49
48
  }
50
49
  // Search plugin-content-docs instances
51
- if (filteredConfig[0] === "@docusaurus/plugin-content-docs") {
50
+ if (filteredConfig[0] === plugin) {
52
51
  const configPluginId = filteredConfig[1].id
53
52
  ? filteredConfig[1].id
54
53
  : "default";
@@ -67,23 +66,23 @@ function getPluginInstances(plugins) {
67
66
  return plugins.filter((data) => data[0] === "docusaurus-plugin-openapi-docs");
68
67
  }
69
68
  function pluginOpenAPIDocs(context, options) {
70
- const { config, docsPluginId } = options;
69
+ const { config, docsPlugin = "@docusaurus/plugin-content-docs", docsPluginId, } = options;
71
70
  const { siteDir, siteConfig } = context;
72
71
  // Get routeBasePath and path from plugin-content-docs or preset
73
72
  const presets = siteConfig.presets;
74
73
  const plugins = siteConfig.plugins;
75
74
  const presetsPlugins = presets.concat(plugins);
76
- let docData = getDocsPluginConfig(presetsPlugins, docsPluginId);
75
+ let docData = getDocsPluginConfig(presetsPlugins, docsPlugin, docsPluginId);
77
76
  let docRouteBasePath = docData ? docData.routeBasePath : undefined;
78
77
  let docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
79
78
  async function generateApiDocs(options, pluginId) {
80
79
  var _a, _b, _c, _d;
81
- let { specPath, outputDir, template, markdownGenerators, downloadUrl, sidebarOptions, } = options;
80
+ let { specPath, outputDir, template, markdownGenerators, downloadUrl, sidebarOptions, disableCompression, } = options;
82
81
  // Remove trailing slash before proceeding
83
82
  outputDir = outputDir.replace(/\/$/, "");
84
83
  // Override docPath if pluginId provided
85
84
  if (pluginId) {
86
- docData = getDocsPluginConfig(presetsPlugins, pluginId);
85
+ docData = getDocsPluginConfig(presetsPlugins, docsPlugin, pluginId);
87
86
  docRouteBasePath = docData ? docData.routeBasePath : undefined;
88
87
  docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
89
88
  }
@@ -219,7 +218,7 @@ custom_edit_url: null
219
218
  };
220
219
  loadedApi.map(async (item) => {
221
220
  if (item.type === "info") {
222
- if (downloadUrl && isURL(downloadUrl)) {
221
+ if (downloadUrl) {
223
222
  item.downloadUrl = downloadUrl;
224
223
  }
225
224
  }
@@ -233,9 +232,11 @@ custom_edit_url: null
233
232
  // const deserialize = (s: any) => {
234
233
  // return zlib.inflateSync(Buffer.from(s, "base64")).toString();
235
234
  // };
236
- item.json = zlib_1.default
237
- .deflateSync(JSON.stringify(item.api))
238
- .toString("base64");
235
+ disableCompression === true
236
+ ? (item.json = JSON.stringify(item.api))
237
+ : (item.json = zlib_1.default
238
+ .deflateSync(JSON.stringify(item.api))
239
+ .toString("base64"));
239
240
  let infoBasePath = `${outputDir}/${item.infoId}`;
240
241
  if (docRouteBasePath) {
241
242
  infoBasePath = `${docRouteBasePath}/${outputDir
@@ -335,7 +336,7 @@ custom_edit_url: null
335
336
  cwd: path_1.default.resolve(apiDir, "schemas"),
336
337
  deep: 1,
337
338
  });
338
- const sidebarFile = await (0, utils_1.Globby)(["sidebar.js"], {
339
+ const sidebarFile = await (0, utils_1.Globby)(["sidebar.{js,ts}"], {
339
340
  cwd: path_1.default.resolve(apiDir),
340
341
  deep: 1,
341
342
  });
@@ -371,6 +372,7 @@ custom_edit_url: null
371
372
  version: version,
372
373
  label: metadata.label,
373
374
  baseUrl: metadata.baseUrl,
375
+ downloadUrl: metadata.downloadUrl,
374
376
  });
375
377
  }
376
378
  const versionsJson = JSON.stringify(versionsArray, null, 2);
@@ -490,6 +492,7 @@ custom_edit_url: null
490
492
  delete parentConfig.version;
491
493
  delete parentConfig.label;
492
494
  delete parentConfig.baseUrl;
495
+ delete parentConfig.downloadUrl;
493
496
  // TODO: handle when no versions are defined by version command is passed
494
497
  if (versionId === "all") {
495
498
  if (versions[id]) {
@@ -88,12 +88,6 @@ function createRequestSchema({ title, body, ...rest }) {
88
88
  if (firstBody === undefined) {
89
89
  return undefined;
90
90
  }
91
- // we don't show the table if there is no properties to show
92
- if (firstBody.properties !== undefined) {
93
- if (Object.keys(firstBody.properties).length === 0) {
94
- return undefined;
95
- }
96
- }
97
91
  return (0, utils_1.create)("MimeTabs", {
98
92
  className: "openapi-tabs__mime",
99
93
  children: [
@@ -36,11 +36,6 @@ function createResponseSchema({ title, body, ...rest }) {
36
36
  responseExamples === undefined) {
37
37
  return undefined;
38
38
  }
39
- if ((firstBody === null || firstBody === void 0 ? void 0 : firstBody.properties) !== undefined) {
40
- if (Object.keys(firstBody === null || firstBody === void 0 ? void 0 : firstBody.properties).length === 0) {
41
- return undefined;
42
- }
43
- }
44
39
  return (0, utils_1.create)("TabItem", {
45
40
  label: `${mimeType}`,
46
41
  value: `${mimeType}`,
@@ -116,6 +116,16 @@ function createAnyOneOf(schema) {
116
116
  */
117
117
  function createProperties(schema) {
118
118
  const discriminator = schema.discriminator;
119
+ if (Object.keys(schema.properties).length === 0) {
120
+ return (0, utils_1.create)("SchemaItem", {
121
+ collapsible: false,
122
+ name: "",
123
+ required: false,
124
+ schemaName: "object",
125
+ qualifierMessage: undefined,
126
+ schema: {},
127
+ });
128
+ }
119
129
  return Object.entries(schema.properties).map(([key, val]) => {
120
130
  return createEdges({
121
131
  name: key,
@@ -483,6 +493,16 @@ function createPropertyDiscriminator(name, schemaName, schema, discriminator, re
483
493
  */
484
494
  function createEdges({ name, schema, required, discriminator, }) {
485
495
  var _a, _b, _c, _d;
496
+ if (SCHEMA_TYPE === "request") {
497
+ if (schema.readOnly && schema.readOnly === true) {
498
+ return undefined;
499
+ }
500
+ }
501
+ if (SCHEMA_TYPE === "response") {
502
+ if (schema.writeOnly && schema.writeOnly === true) {
503
+ return undefined;
504
+ }
505
+ }
486
506
  const schemaName = (0, schema_1.getSchemaName)(schema);
487
507
  if (discriminator !== undefined && discriminator.propertyName === name) {
488
508
  return createPropertyDiscriminator(name, "string", schema, discriminator, required);
@@ -492,6 +512,16 @@ function createEdges({ name, schema, required, discriminator, }) {
492
512
  }
493
513
  if (schema.allOf !== undefined) {
494
514
  const { mergedSchemas } = mergeAllOf(schema.allOf);
515
+ if (SCHEMA_TYPE === "request") {
516
+ if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
517
+ return undefined;
518
+ }
519
+ }
520
+ if (SCHEMA_TYPE === "response") {
521
+ if (mergedSchemas.writeOnly && mergedSchemas.writeOnly === true) {
522
+ return undefined;
523
+ }
524
+ }
495
525
  const mergedSchemaName = (0, schema_1.getSchemaName)(mergedSchemas);
496
526
  if (mergedSchemas.oneOf !== undefined ||
497
527
  mergedSchemas.anyOf !== undefined) {
@@ -507,16 +537,6 @@ function createEdges({ name, schema, required, discriminator, }) {
507
537
  if (((_a = mergedSchemas.items) === null || _a === void 0 ? void 0 : _a.properties) !== undefined) {
508
538
  return createDetailsNode(name, mergedSchemaName, mergedSchemas, required, schema.nullable);
509
539
  }
510
- if (SCHEMA_TYPE === "request") {
511
- if (mergedSchemas.readOnly && mergedSchemas.readOnly === true) {
512
- return undefined;
513
- }
514
- }
515
- if (SCHEMA_TYPE === "response") {
516
- if (mergedSchemas.writeOnly && mergedSchemas.writeOnly === true) {
517
- return undefined;
518
- }
519
- }
520
540
  return (0, utils_1.create)("SchemaItem", {
521
541
  collapsible: false,
522
542
  name,
@@ -539,16 +559,6 @@ function createEdges({ name, schema, required, discriminator, }) {
539
559
  if (((_c = schema.items) === null || _c === void 0 ? void 0 : _c.anyOf) !== undefined || ((_d = schema.items) === null || _d === void 0 ? void 0 : _d.oneOf) !== undefined) {
540
560
  return createDetailsNode(name, schemaName, schema, required, schema.nullable);
541
561
  }
542
- if (SCHEMA_TYPE === "request") {
543
- if (schema.readOnly && schema.readOnly === true) {
544
- return undefined;
545
- }
546
- }
547
- if (SCHEMA_TYPE === "response") {
548
- if (schema.writeOnly && schema.writeOnly === true) {
549
- return undefined;
550
- }
551
- }
552
562
  // primitives and array of non-objects
553
563
  return (0, utils_1.create)("SchemaItem", {
554
564
  collapsible: false,
@@ -564,6 +574,16 @@ function createEdges({ name, schema, required, discriminator, }) {
564
574
  */
565
575
  function createNodes(schema, schemaType) {
566
576
  SCHEMA_TYPE = schemaType;
577
+ if (SCHEMA_TYPE === "request") {
578
+ if (schema.readOnly && schema.readOnly === true) {
579
+ return undefined;
580
+ }
581
+ }
582
+ if (SCHEMA_TYPE === "response") {
583
+ if (schema.writeOnly && schema.writeOnly === true) {
584
+ return undefined;
585
+ }
586
+ }
567
587
  const nodes = [];
568
588
  // if (schema.discriminator !== undefined) {
569
589
  // return createDiscriminator(schema);
@@ -34,6 +34,7 @@ const createSchema_1 = require("./createSchema");
34
34
  describe("createNodes", () => {
35
35
  it("should create readable MODs for oneOf primitive properties", () => {
36
36
  const schema = {
37
+ "x-tags": ["clown"],
37
38
  type: "object",
38
39
  properties: {
39
40
  oneOfProperty: {
@@ -275,7 +275,7 @@ function createStatusCodes({ label, id, responses }) {
275
275
  responseHeaders &&
276
276
  (0, createDetails_1.createDetails)({
277
277
  className: "openapi-markdown__details",
278
- "data-collaposed": true,
278
+ "data-collapsed": true,
279
279
  open: false,
280
280
  style: { textAlign: "left", marginBottom: "1rem" },
281
281
  children: [
@@ -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 = "";
@@ -38,3 +38,24 @@ exports.render = render;
38
38
  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;
39
39
  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;
40
40
  exports.codeFence = /`{1,3}[\s\S]*?`{1,3}/g;
41
+ exports.curlyBrackets = /([{}])/g;
42
+ exports.codeBlock = /(^```.*[\s\S]*?```$|`[^`].+?`)/gm;
43
+ function clean(value) {
44
+ if (!value) {
45
+ return "";
46
+ }
47
+ let sections = value.split(exports.codeBlock);
48
+ for (let sectionIndex in sections) {
49
+ if (!sections[sectionIndex].startsWith("`")) {
50
+ sections[sectionIndex] = sections[sectionIndex]
51
+ .replace(exports.lessThan, "&lt;")
52
+ .replace(exports.greaterThan, "&gt;")
53
+ .replace(exports.codeFence, function (match) {
54
+ return match.replace(/\\>/g, ">");
55
+ })
56
+ .replace(exports.curlyBrackets, "\\$1");
57
+ }
58
+ }
59
+ return sections.join("");
60
+ }
61
+ exports.clean = clean;
@@ -12,14 +12,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getTagDisplayName = exports.processOpenapiFile = exports.processOpenapiFiles = exports.readOpenapiFiles = void 0;
13
13
  const path_1 = __importDefault(require("path"));
14
14
  const utils_1 = require("@docusaurus/utils");
15
- const openapi_to_postmanv2_1 = __importDefault(require("@paloaltonetworks/openapi-to-postmanv2"));
16
- const postman_collection_1 = __importDefault(require("@paloaltonetworks/postman-collection"));
17
15
  const chalk_1 = __importDefault(require("chalk"));
18
16
  const fs_extra_1 = __importDefault(require("fs-extra"));
19
17
  const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
20
18
  const kebabCase_1 = __importDefault(require("lodash/kebabCase"));
21
19
  const unionBy_1 = __importDefault(require("lodash/unionBy"));
22
20
  const uniq_1 = __importDefault(require("lodash/uniq"));
21
+ const openapi_to_postmanv2_1 = __importDefault(require("openapi-to-postmanv2"));
22
+ const postman_collection_1 = __importDefault(require("postman-collection"));
23
23
  const createRequestExample_1 = require("./createRequestExample");
24
24
  const loadAndResolveSpec_1 = require("./utils/loadAndResolveSpec");
25
25
  const index_1 = require("../index");
@@ -61,7 +61,7 @@ async function createPostmanCollection(openapiData) {
61
61
  return await jsonToCollection(data);
62
62
  }
63
63
  function createItems(openapiData, options, sidebarOptions) {
64
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
64
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6;
65
65
  // TODO: Find a better way to handle this
66
66
  let items = [];
67
67
  const infoIdSpaces = openapiData.info.title.replace(" ", "-").toLowerCase();
@@ -324,42 +324,47 @@ function createItems(openapiData, options, sidebarOptions) {
324
324
  items.push(apiPage);
325
325
  }
326
326
  }
327
- if ((options === null || options === void 0 ? void 0 : options.showSchemas) === true) {
327
+ if ((options === null || options === void 0 ? void 0 : options.showSchemas) === true ||
328
+ Object.entries((_1 = (_0 = openapiData === null || openapiData === void 0 ? void 0 : openapiData.components) === null || _0 === void 0 ? void 0 : _0.schemas) !== null && _1 !== void 0 ? _1 : {})
329
+ .flatMap(([_, s]) => s["x-tags"])
330
+ .filter((item) => !!item).length > 0) {
328
331
  // Gather schemas
329
- for (let [schema, schemaObject] of Object.entries((_1 = (_0 = openapiData === null || openapiData === void 0 ? void 0 : openapiData.components) === null || _0 === void 0 ? void 0 : _0.schemas) !== null && _1 !== void 0 ? _1 : {})) {
330
- const baseIdSpaces = (_3 = (_2 = schemaObject === null || schemaObject === void 0 ? void 0 : schemaObject.title) === null || _2 === void 0 ? void 0 : _2.replace(" ", "-").toLowerCase()) !== null && _3 !== void 0 ? _3 : "";
331
- const baseId = (0, kebabCase_1.default)(baseIdSpaces);
332
- const schemaDescription = schemaObject.description;
333
- let splitDescription;
334
- if (schemaDescription) {
335
- splitDescription = schemaDescription.match(/[^\r\n]+/g);
336
- }
337
- const schemaPage = {
338
- type: "schema",
339
- id: baseId,
340
- infoId: infoId !== null && infoId !== void 0 ? infoId : "",
341
- unversionedId: baseId,
342
- title: schemaObject.title
343
- ? schemaObject.title.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
344
- : schema,
345
- description: schemaObject.description
346
- ? schemaObject.description.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
347
- : "",
348
- frontMatter: {
349
- description: splitDescription
350
- ? splitDescription[0]
351
- .replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
352
- .replace(/\s+$/, "")
332
+ for (let [schema, schemaObject] of Object.entries((_3 = (_2 = openapiData === null || openapiData === void 0 ? void 0 : openapiData.components) === null || _2 === void 0 ? void 0 : _2.schemas) !== null && _3 !== void 0 ? _3 : {})) {
333
+ if ((options === null || options === void 0 ? void 0 : options.showSchemas) === true || schemaObject["x-tags"]) {
334
+ const baseIdSpaces = (_5 = (_4 = schemaObject === null || schemaObject === void 0 ? void 0 : schemaObject.title) === null || _4 === void 0 ? void 0 : _4.replace(" ", "-").toLowerCase()) !== null && _5 !== void 0 ? _5 : "";
335
+ const baseId = (0, kebabCase_1.default)(baseIdSpaces);
336
+ const schemaDescription = schemaObject.description;
337
+ let splitDescription;
338
+ if (schemaDescription) {
339
+ splitDescription = schemaDescription.match(/[^\r\n]+/g);
340
+ }
341
+ const schemaPage = {
342
+ type: "schema",
343
+ id: baseId,
344
+ infoId: infoId !== null && infoId !== void 0 ? infoId : "",
345
+ unversionedId: baseId,
346
+ title: schemaObject.title
347
+ ? schemaObject.title.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
348
+ : schema,
349
+ description: schemaObject.description
350
+ ? schemaObject.description.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
353
351
  : "",
354
- },
355
- schema: schemaObject,
356
- };
357
- items.push(schemaPage);
352
+ frontMatter: {
353
+ description: splitDescription
354
+ ? splitDescription[0]
355
+ .replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
356
+ .replace(/\s+$/, "")
357
+ : "",
358
+ },
359
+ schema: schemaObject,
360
+ };
361
+ items.push(schemaPage);
362
+ }
358
363
  }
359
364
  }
360
365
  if ((sidebarOptions === null || sidebarOptions === void 0 ? void 0 : sidebarOptions.categoryLinkSource) === "tag") {
361
366
  // Get global tags
362
- const tags = (_4 = openapiData.tags) !== null && _4 !== void 0 ? _4 : [];
367
+ const tags = (_6 = openapiData.tags) !== null && _6 !== void 0 ? _6 : [];
363
368
  // Get operation tags
364
369
  const apiItems = items.filter((item) => {
365
370
  return item.type === "api";
@@ -17,6 +17,7 @@ const _1 = require(".");
17
17
  describe("openapi", () => {
18
18
  describe("readOpenapiFiles", () => {
19
19
  it("readOpenapiFiles", async () => {
20
+ var _a, _b;
20
21
  const results = await (0, _1.readOpenapiFiles)((0, utils_1.posixPath)(path_1.default.join(__dirname, "__fixtures__/examples")));
21
22
  const categoryMeta = results.find((x) => x.source.endsWith("_category_.json"));
22
23
  expect(categoryMeta).toBeFalsy();
@@ -26,6 +27,7 @@ describe("openapi", () => {
26
27
  expect(yaml === null || yaml === void 0 ? void 0 : yaml.sourceDirName).toBe(".");
27
28
  expect(yaml === null || yaml === void 0 ? void 0 : yaml.data.tags).toBeDefined();
28
29
  expect(yaml === null || yaml === void 0 ? void 0 : yaml.data["x-tagGroups"]).toBeDefined();
30
+ expect((_b = (_a = yaml === null || yaml === void 0 ? void 0 : yaml.data.components) === null || _a === void 0 ? void 0 : _a.schemas) === null || _b === void 0 ? void 0 : _b.HelloString["x-tags"]).toBeDefined();
29
31
  });
30
32
  });
31
33
  });
@@ -278,6 +278,7 @@ export type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf"
278
278
  externalDocs?: ExternalDocumentationObject;
279
279
  example?: any;
280
280
  deprecated?: boolean;
281
+ "x-tags"?: string[];
281
282
  };
282
283
  export type SchemaObjectWithRef = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
283
284
  type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
package/lib/options.js CHANGED
@@ -22,6 +22,7 @@ const markdownGenerators = utils_validation_1.Joi.object({
22
22
  });
23
23
  exports.OptionsSchema = utils_validation_1.Joi.object({
24
24
  id: utils_validation_1.Joi.string().required(),
25
+ docsPlugin: utils_validation_1.Joi.string(),
25
26
  docsPluginId: utils_validation_1.Joi.string().required(),
26
27
  config: utils_validation_1.Joi.object()
27
28
  .pattern(/^/, utils_validation_1.Joi.object({
@@ -35,6 +36,7 @@ exports.OptionsSchema = utils_validation_1.Joi.object({
35
36
  sidebarOptions: sidebarOptions,
36
37
  markdownGenerators: markdownGenerators,
37
38
  showSchemas: utils_validation_1.Joi.boolean(),
39
+ disableCompression: utils_validation_1.Joi.boolean(),
38
40
  version: utils_validation_1.Joi.string().when("versions", {
39
41
  is: utils_validation_1.Joi.exist(),
40
42
  then: utils_validation_1.Joi.required(),
@@ -52,6 +54,7 @@ exports.OptionsSchema = utils_validation_1.Joi.object({
52
54
  outputDir: utils_validation_1.Joi.string().required(),
53
55
  label: utils_validation_1.Joi.string().required(),
54
56
  baseUrl: utils_validation_1.Joi.string().required(),
57
+ downloadUrl: utils_validation_1.Joi.string(),
55
58
  })),
56
59
  }))
57
60
  .required(),
@@ -24,7 +24,7 @@ function isSchemaItem(item) {
24
24
  return item.type === "schema";
25
25
  }
26
26
  function groupByTags(items, sidebarOptions, options, tags, docPath) {
27
- let { outputDir, label } = options;
27
+ let { outputDir, label, showSchemas } = options;
28
28
  // Remove trailing slash before proceeding
29
29
  outputDir = outputDir.replace(/\/$/, "");
30
30
  const { sidebarCollapsed, sidebarCollapsible, customProps, categoryLinkSource, } = sidebarOptions;
@@ -43,16 +43,21 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
43
43
  const operationTags = (0, uniq_1.default)(apiItems
44
44
  .flatMap((item) => item.api.tags)
45
45
  .filter((item) => !!item));
46
- // Combine globally defined tags with operation tags
47
- // Only include global tag if referenced in operation tags
46
+ const schemaTags = (0, uniq_1.default)(schemaItems
47
+ .flatMap((item) => item.schema["x-tags"])
48
+ .filter((item) => !!item));
49
+ // Combine globally defined tags with operation and schema tags
50
+ // Only include global tag if referenced in operation/schema tags
48
51
  let apiTags = [];
49
52
  tags.flat().forEach((tag) => {
50
53
  // Should we also check x-displayName?
51
- if (operationTags.includes(tag.name)) {
54
+ if (operationTags.includes(tag.name) || schemaTags.includes(tag.name)) {
52
55
  apiTags.push(tag.name);
53
56
  }
54
57
  });
55
- apiTags = (0, uniq_1.default)(apiTags.concat(operationTags));
58
+ if (sidebarOptions.groupPathsBy !== "tagGroup") {
59
+ apiTags = (0, uniq_1.default)(apiTags.concat(operationTags, schemaTags));
60
+ }
56
61
  const basePath = docPath
57
62
  ? outputDir.split(docPath)[1].replace(/^\/+/g, "")
58
63
  : outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
@@ -68,7 +73,7 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
68
73
  }, item.api.method)
69
74
  : (0, clsx_1.default)({
70
75
  "menu__list-item--deprecated": item.schema.deprecated,
71
- });
76
+ }, "schema");
72
77
  return {
73
78
  type: "doc",
74
79
  id: basePath === "" || undefined ? `${id}` : `${basePath}/${id}`,
@@ -126,15 +131,15 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
126
131
  : (0, utils_1.posixPath)(path_1.default.join("/category", basePath, (0, lodash_1.kebabCase)(tag))),
127
132
  };
128
133
  }
134
+ const taggedApiItems = apiItems.filter((item) => { var _a; return !!((_a = item.api.tags) === null || _a === void 0 ? void 0 : _a.includes(tag)); });
135
+ const taggedSchemaItems = schemaItems.filter((item) => { var _a; return !!((_a = item.schema["x-tags"]) === null || _a === void 0 ? void 0 : _a.includes(tag)); });
129
136
  return {
130
137
  type: "category",
131
138
  label: (_a = tagObject === null || tagObject === void 0 ? void 0 : tagObject["x-displayName"]) !== null && _a !== void 0 ? _a : tag,
132
139
  link: linkConfig,
133
140
  collapsible: sidebarCollapsible,
134
141
  collapsed: sidebarCollapsed,
135
- items: apiItems
136
- .filter((item) => { var _a; return !!((_a = item.api.tags) === null || _a === void 0 ? void 0 : _a.includes(tag)); })
137
- .map(createDocItem),
142
+ items: [...taggedSchemaItems, ...taggedApiItems].map(createDocItem),
138
143
  };
139
144
  })
140
145
  .filter((item) => item.items.length > 0); // Filter out any categories with no items.
@@ -157,14 +162,16 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
157
162
  ];
158
163
  }
159
164
  let schemas = [];
160
- if (schemaItems.length > 0) {
165
+ if (showSchemas && schemaItems.length > 0) {
161
166
  schemas = [
162
167
  {
163
168
  type: "category",
164
169
  label: "Schemas",
165
170
  collapsible: sidebarCollapsible,
166
171
  collapsed: sidebarCollapsed,
167
- items: schemaItems.map(createDocItem),
172
+ items: schemaItems
173
+ .filter(({ schema }) => !schema["x-tags"])
174
+ .map(createDocItem),
168
175
  },
169
176
  ];
170
177
  }
@@ -178,7 +185,9 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
178
185
  function generateSidebarSlice(sidebarOptions, options, api, tags, docPath, tagGroups) {
179
186
  let sidebarSlice = [];
180
187
  if (sidebarOptions.groupPathsBy === "tagGroup") {
188
+ let schemasGroup = [];
181
189
  tagGroups === null || tagGroups === void 0 ? void 0 : tagGroups.forEach((tagGroup) => {
190
+ var _a;
182
191
  //filter tags only included in group
183
192
  const filteredTags = [];
184
193
  tags[0].forEach((tag) => {
@@ -193,8 +202,18 @@ function generateSidebarSlice(sidebarOptions, options, api, tags, docPath, tagGr
193
202
  collapsed: true,
194
203
  items: groupByTags(api, sidebarOptions, options, [filteredTags], docPath),
195
204
  };
205
+ if (options.showSchemas) {
206
+ // For the first tagGroup, save the generated "Schemas" category for later.
207
+ if (schemasGroup.length === 0) {
208
+ schemasGroup = (_a = groupCategory.items) === null || _a === void 0 ? void 0 : _a.filter((item) => item.type === "category" && item.label === "Schemas");
209
+ }
210
+ // Remove the "Schemas" category from every `groupCategory`.
211
+ groupCategory.items = groupCategory.items.filter((item) => "label" in item ? item.label !== "Schemas" : true);
212
+ }
196
213
  sidebarSlice.push(groupCategory);
197
214
  });
215
+ // Add `schemasGroup` to the end of the sidebar.
216
+ sidebarSlice.push(...schemasGroup);
198
217
  }
199
218
  else if (sidebarOptions.groupPathsBy === "tag") {
200
219
  sidebarSlice = groupByTags(api, sidebarOptions, options, tags, docPath);
package/lib/types.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import type Request from "@paloaltonetworks/postman-collection";
1
+ import type Request from "postman-collection";
2
2
  import { InfoObject, OperationObject, SchemaObject, SecuritySchemeObject, TagObject } from "./openapi/types";
3
3
  export type { PropSidebarItemCategory, SidebarItemLink, PropSidebar, PropSidebarItem, } from "@docusaurus/plugin-content-docs-types";
4
4
  export interface PluginOptions {
5
5
  id?: string;
6
+ docsPlugin?: string;
6
7
  docsPluginId: string;
7
8
  config: {
8
9
  [key: string]: APIOptions;
@@ -25,6 +26,7 @@ export interface APIOptions {
25
26
  proxy?: string;
26
27
  markdownGenerators?: MarkdownGenerator;
27
28
  showSchemas?: boolean;
29
+ disableCompression?: boolean;
28
30
  }
29
31
  export interface MarkdownGenerator {
30
32
  createApiPageMD?: (pageData: ApiPageMetadata) => string;
@@ -46,6 +48,7 @@ export interface APIVersionOptions {
46
48
  outputDir: string;
47
49
  label: string;
48
50
  baseUrl: string;
51
+ downloadUrl?: string;
49
52
  }
50
53
  export interface LoadedContent {
51
54
  loadedApi: ApiMetadata[];
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": "2.1.3",
4
+ "version": "2.2.0",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -40,8 +40,6 @@
40
40
  "@docusaurus/plugin-content-docs": ">=2.4.1 <=2.4.3",
41
41
  "@docusaurus/utils": ">=2.4.1 <=2.4.3",
42
42
  "@docusaurus/utils-validation": ">=2.4.1 <=2.4.3",
43
- "@paloaltonetworks/openapi-to-postmanv2": "3.1.0-hotfix.1",
44
- "@paloaltonetworks/postman-collection": "^4.1.0",
45
43
  "@redocly/openapi-core": "^1.10.5",
46
44
  "chalk": "^4.1.2",
47
45
  "clsx": "^1.1.1",
@@ -50,6 +48,8 @@
50
48
  "json-schema-merge-allof": "^0.8.1",
51
49
  "lodash": "^4.17.20",
52
50
  "mustache": "^4.2.0",
51
+ "openapi-to-postmanv2": "^4.21.0",
52
+ "postman-collection": "^4.4.0",
53
53
  "slugify": "^1.6.5",
54
54
  "swagger2openapi": "^7.0.8",
55
55
  "xml-formatter": "^2.6.1"
@@ -60,5 +60,5 @@
60
60
  "engines": {
61
61
  "node": ">=14"
62
62
  },
63
- "gitHead": "3bca23ffd3bc51c3d7f4ebb3916e2ece8c823961"
63
+ "gitHead": "060b5777c783abc23cd3744a6d43deb4df80cebd"
64
64
  }