docusaurus-plugin-openapi-docs 2.0.4 → 2.1.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.
Files changed (47) hide show
  1. package/README.md +2 -0
  2. package/lib/index.js +61 -8
  3. package/lib/markdown/createStatusCodes.js +1 -1
  4. package/lib/markdown/index.d.ts +2 -1
  5. package/lib/markdown/index.js +18 -2
  6. package/lib/markdown/utils.d.ts +2 -2
  7. package/lib/openapi/openapi.d.ts +3 -3
  8. package/lib/openapi/openapi.js +60 -7
  9. package/lib/openapi/openapi.test.js +2 -0
  10. package/lib/openapi/types.d.ts +18 -13
  11. package/lib/openapi/utils/services/OpenAPIParser.d.ts +1 -1
  12. package/lib/openapi/utils/services/OpenAPIParser.js +2 -1
  13. package/lib/openapi/utils/services/RedocNormalizedOptions.js +49 -49
  14. package/lib/openapi/utils/types/index.d.ts +1 -1
  15. package/lib/openapi/utils/types/open-api.d.ts +4 -4
  16. package/lib/openapi/utils/types.d.ts +5 -5
  17. package/lib/options.js +2 -1
  18. package/lib/sidebars/index.d.ts +2 -2
  19. package/lib/sidebars/index.js +50 -10
  20. package/lib/types.d.ts +16 -3
  21. package/package.json +2 -2
  22. package/src/index.ts +113 -10
  23. package/src/markdown/createAuthentication.ts +1 -1
  24. package/src/markdown/createCallbacks.ts +2 -2
  25. package/src/markdown/createContactInfo.ts +1 -1
  26. package/src/markdown/createLicense.ts +1 -1
  27. package/src/markdown/createLogo.ts +1 -1
  28. package/src/markdown/createParamsDetails.ts +1 -1
  29. package/src/markdown/createRequestBodyDetails.ts +1 -1
  30. package/src/markdown/createRequestSchema.ts +1 -1
  31. package/src/markdown/createResponseSchema.ts +1 -1
  32. package/src/markdown/createSchema.test.ts +1 -1
  33. package/src/markdown/createSchema.ts +1 -1
  34. package/src/markdown/createStatusCodes.ts +2 -2
  35. package/src/markdown/index.ts +30 -9
  36. package/src/openapi/__fixtures__/examples/openapi.yaml +29 -0
  37. package/src/openapi/createRequestExample.ts +1 -1
  38. package/src/openapi/createResponseExample.ts +1 -1
  39. package/src/openapi/openapi.test.ts +3 -0
  40. package/src/openapi/openapi.ts +77 -9
  41. package/src/openapi/types.ts +6 -0
  42. package/src/openapi/utils/loadAndResolveSpec.ts +1 -1
  43. package/src/openapi/utils/services/OpenAPIParser.ts +1 -1
  44. package/src/openapi/utils/utils/openapi.ts +7 -7
  45. package/src/options.ts +2 -1
  46. package/src/sidebars/index.ts +71 -16
  47. package/src/types.ts +21 -1
package/README.md CHANGED
@@ -31,6 +31,7 @@ Key Features:
31
31
 
32
32
  | Docusaurus OpenAPI Docs | Docusaurus |
33
33
  | ----------------------- | --------------- |
34
+ | 3.0.0-beta.x (beta) | `3.0.1 - 3.1.1` |
34
35
  | 2.0.x (current) | `2.4.1 - 2.4.3` |
35
36
  | 1.7.3 (legacy) | `2.0.1 - 2.2.0` |
36
37
 
@@ -159,6 +160,7 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
159
160
  | `baseUrl` | `string` | `null` | _Optional:_ Version base URL used when generating version selector dropdown menu. |
160
161
  | `versions` | `object` | `null` | _Optional:_ Set of options for versioning configuration. See below for a list of supported options. |
161
162
  | `markdownGenerators` | `object` | `null` | _Optional:_ Customize MDX content with a set of options for specifying markdown generator functions. See below for a list of supported options. |
163
+ | `showSchemas` | `boolean` | `null` | _Optional:_ If set to `true`, generates schema pages and adds them to the sidebar. |
162
164
 
163
165
  `sidebarOptions` can be configured with the following options:
164
166
 
package/lib/index.js CHANGED
@@ -77,7 +77,7 @@ function pluginOpenAPIDocs(context, options) {
77
77
  let docRouteBasePath = docData ? docData.routeBasePath : undefined;
78
78
  let docPath = docData ? (docData.path ? docData.path : "docs") : undefined;
79
79
  async function generateApiDocs(options, pluginId) {
80
- var _a, _b, _c;
80
+ var _a, _b, _c, _d;
81
81
  let { specPath, outputDir, template, markdownGenerators, downloadUrl, sidebarOptions, } = options;
82
82
  // Remove trailing slash before proceeding
83
83
  outputDir = outputDir.replace(/\/$/, "");
@@ -92,7 +92,7 @@ function pluginOpenAPIDocs(context, options) {
92
92
  : path_1.default.resolve(siteDir, specPath);
93
93
  try {
94
94
  const openapiFiles = await (0, openapi_1.readOpenapiFiles)(contentPath);
95
- const [loadedApi, tags] = await (0, openapi_1.processOpenapiFiles)(openapiFiles, options, sidebarOptions);
95
+ const [loadedApi, tags, tagGroups] = await (0, openapi_1.processOpenapiFiles)(openapiFiles, options, sidebarOptions);
96
96
  if (!fs_1.default.existsSync(outputDir)) {
97
97
  try {
98
98
  fs_1.default.mkdirSync(outputDir, { recursive: true });
@@ -104,7 +104,7 @@ function pluginOpenAPIDocs(context, options) {
104
104
  }
105
105
  // TODO: figure out better way to set default
106
106
  if (Object.keys(sidebarOptions !== null && sidebarOptions !== void 0 ? sidebarOptions : {}).length > 0) {
107
- const sidebarSlice = (0, sidebars_1.default)(sidebarOptions, options, loadedApi, tags, docPath);
107
+ const sidebarSlice = (0, sidebars_1.default)(sidebarOptions, options, loadedApi, tags, docPath, tagGroups);
108
108
  const sidebarSliceTemplate = `module.exports = {{{slice}}};`;
109
109
  const view = (0, mustache_1.render)(sidebarSliceTemplate, {
110
110
  slice: JSON.stringify(sidebarSlice),
@@ -195,20 +195,35 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
195
195
  <DocCardList items={useCurrentSidebarCategory().items}/>
196
196
  \`\`\`
197
197
  `;
198
+ const schemaMdTemplate = `---
199
+ id: {{{id}}}
200
+ title: "{{{title}}}"
201
+ description: "{{{frontMatter.description}}}"
202
+ sidebar_label: "{{{title}}}"
203
+ hide_title: true
204
+ schema: true
205
+ custom_edit_url: null
206
+ ---
207
+
208
+ {{{markdown}}}
209
+ `;
198
210
  const apiPageGenerator = (_a = markdownGenerators === null || markdownGenerators === void 0 ? void 0 : markdownGenerators.createApiPageMD) !== null && _a !== void 0 ? _a : markdown_1.createApiPageMD;
199
211
  const infoPageGenerator = (_b = markdownGenerators === null || markdownGenerators === void 0 ? void 0 : markdownGenerators.createInfoPageMD) !== null && _b !== void 0 ? _b : markdown_1.createInfoPageMD;
200
212
  const tagPageGenerator = (_c = markdownGenerators === null || markdownGenerators === void 0 ? void 0 : markdownGenerators.createTagPageMD) !== null && _c !== void 0 ? _c : markdown_1.createTagPageMD;
213
+ const schemaPageGenerator = (_d = markdownGenerators === null || markdownGenerators === void 0 ? void 0 : markdownGenerators.createSchemaPageMD) !== null && _d !== void 0 ? _d : markdown_1.createSchemaPageMD;
214
+ const pageGeneratorByType = {
215
+ api: apiPageGenerator,
216
+ info: infoPageGenerator,
217
+ tag: tagPageGenerator,
218
+ schema: schemaPageGenerator,
219
+ };
201
220
  loadedApi.map(async (item) => {
202
221
  if (item.type === "info") {
203
222
  if (downloadUrl && isURL(downloadUrl)) {
204
223
  item.downloadUrl = downloadUrl;
205
224
  }
206
225
  }
207
- const markdown = item.type === "api"
208
- ? apiPageGenerator(item)
209
- : item.type === "info"
210
- ? infoPageGenerator(item)
211
- : tagPageGenerator(item);
226
+ const markdown = pageGeneratorByType[item.type](item);
212
227
  item.markdown = markdown;
213
228
  if (item.type === "api") {
214
229
  // opportunity to compress JSON
@@ -274,6 +289,32 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
274
289
  }
275
290
  }
276
291
  }
292
+ if (item.type === "schema") {
293
+ if (!fs_1.default.existsSync(`${outputDir}/schemas/${item.id}.schema.mdx`)) {
294
+ if (!fs_1.default.existsSync(`${outputDir}/schemas`)) {
295
+ try {
296
+ fs_1.default.mkdirSync(`${outputDir}/schemas`, { recursive: true });
297
+ console.log(chalk_1.default.green(`Successfully created "${outputDir}/schemas"`));
298
+ }
299
+ catch (err) {
300
+ console.error(chalk_1.default.red(`Failed to create "${outputDir}/schemas"`), chalk_1.default.yellow(err));
301
+ }
302
+ }
303
+ try {
304
+ // kebabCase(arg) returns 0-length string when arg is undefined
305
+ if (item.id.length === 0) {
306
+ throw Error("Schema must have title defined");
307
+ }
308
+ // eslint-disable-next-line testing-library/render-result-naming-convention
309
+ const schemaView = (0, mustache_1.render)(schemaMdTemplate, item);
310
+ fs_1.default.writeFileSync(`${outputDir}/schemas/${item.id}.schema.mdx`, schemaView, "utf8");
311
+ console.log(chalk_1.default.green(`Successfully created "${outputDir}/${item.id}.schema.mdx"`));
312
+ }
313
+ catch (err) {
314
+ console.error(chalk_1.default.red(`Failed to write "${outputDir}/${item.id}.schema.mdx"`), chalk_1.default.yellow(err));
315
+ }
316
+ }
317
+ }
277
318
  return;
278
319
  });
279
320
  return;
@@ -290,6 +331,10 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
290
331
  cwd: path_1.default.resolve(apiDir),
291
332
  deep: 1,
292
333
  });
334
+ const schemaMdxFiles = await (0, utils_1.Globby)(["*.schema.mdx"], {
335
+ cwd: path_1.default.resolve(apiDir, "schemas"),
336
+ deep: 1,
337
+ });
293
338
  const sidebarFile = await (0, utils_1.Globby)(["sidebar.js"], {
294
339
  cwd: path_1.default.resolve(apiDir),
295
340
  deep: 1,
@@ -302,6 +347,14 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
302
347
  console.log(chalk_1.default.green(`Cleanup succeeded for "${apiDir}/${mdx}"`));
303
348
  }
304
349
  }));
350
+ schemaMdxFiles.map((mdx) => fs_1.default.unlink(`${apiDir}/schemas/${mdx}`, (err) => {
351
+ if (err) {
352
+ console.error(chalk_1.default.red(`Cleanup failed for "${apiDir}/schemas/${mdx}"`), chalk_1.default.yellow(err));
353
+ }
354
+ else {
355
+ console.log(chalk_1.default.green(`Cleanup succeeded for "${apiDir}/schemas/${mdx}"`));
356
+ }
357
+ }));
305
358
  sidebarFile.map((sidebar) => fs_1.default.unlink(`${apiDir}/${sidebar}`, (err) => {
306
359
  if (err) {
307
360
  console.error(chalk_1.default.red(`Cleanup failed for "${apiDir}/${sidebar}"`), chalk_1.default.yellow(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 = "";
@@ -1,4 +1,5 @@
1
- import { ApiPageMetadata, InfoPageMetadata, TagPageMetadata } from "../types";
1
+ import { ApiPageMetadata, InfoPageMetadata, SchemaPageMetadata, TagPageMetadata } from "../types";
2
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;
5
+ export declare function createSchemaPageMD({ schema }: SchemaPageMetadata): 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.createTagPageMD = exports.createInfoPageMD = exports.createApiPageMD = void 0;
9
+ exports.createSchemaPageMD = exports.createTagPageMD = exports.createInfoPageMD = exports.createApiPageMD = void 0;
10
10
  const createAuthentication_1 = require("./createAuthentication");
11
11
  const createAuthorization_1 = require("./createAuthorization");
12
12
  const createCallbacks_1 = require("./createCallbacks");
@@ -21,6 +21,7 @@ const createMethodEndpoint_1 = require("./createMethodEndpoint");
21
21
  const createParamsDetails_1 = require("./createParamsDetails");
22
22
  const createRequestBodyDetails_1 = require("./createRequestBodyDetails");
23
23
  const createRequestHeader_1 = require("./createRequestHeader");
24
+ const createSchema_1 = require("./createSchema");
24
25
  const createStatusCodes_1 = require("./createStatusCodes");
25
26
  const createTermsOfService_1 = require("./createTermsOfService");
26
27
  const createVendorExtensions_1 = require("./createVendorExtensions");
@@ -48,7 +49,7 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
48
49
  : undefined,
49
50
  (0, createDeprecationNotice_1.createDeprecationNotice)({ deprecated, description: deprecatedDescription }),
50
51
  (0, createDescription_1.createDescription)(description),
51
- (0, createRequestHeader_1.createRequestHeader)("Request"),
52
+ requestBody || parameters ? (0, createRequestHeader_1.createRequestHeader)("Request") : undefined,
52
53
  (0, createParamsDetails_1.createParamsDetails)({ parameters, type: "path" }),
53
54
  (0, createParamsDetails_1.createParamsDetails)({ parameters, type: "query" }),
54
55
  (0, createParamsDetails_1.createParamsDetails)({ parameters, type: "header" }),
@@ -84,3 +85,18 @@ function createTagPageMD({ tag: { description } }) {
84
85
  return (0, utils_1.render)([(0, createDescription_1.createDescription)(description)]);
85
86
  }
86
87
  exports.createTagPageMD = createTagPageMD;
88
+ function createSchemaPageMD({ schema }) {
89
+ const { title = "", description } = schema;
90
+ return (0, utils_1.render)([
91
+ `import DiscriminatorTabs from "@theme/DiscriminatorTabs";\n`,
92
+ `import SchemaItem from "@theme/SchemaItem";\n`,
93
+ `import SchemaTabs from "@theme/SchemaTabs";\n`,
94
+ `import TabItem from "@theme/TabItem";\n\n`,
95
+ (0, createHeading_1.createHeading)(title.replace(utils_1.lessThan, "&lt;").replace(utils_1.greaterThan, "&gt;")),
96
+ (0, createDescription_1.createDescription)(description),
97
+ (0, utils_1.create)("ul", {
98
+ children: (0, createSchema_1.createNodes)(schema, "response"),
99
+ }),
100
+ ]);
101
+ }
102
+ exports.createSchemaPageMD = createSchemaPageMD;
@@ -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;
@@ -1,12 +1,12 @@
1
+ import { OpenApiObject, TagGroupObject, TagObject } from "./types";
1
2
  import { ApiMetadata, APIOptions, SidebarOptions } from "../types";
2
- import { OpenApiObject, TagObject } from "./types";
3
3
  interface OpenApiFiles {
4
4
  source: string;
5
5
  sourceDirName: string;
6
6
  data: OpenApiObject;
7
7
  }
8
8
  export declare function readOpenapiFiles(openapiPath: string): Promise<OpenApiFiles[]>;
9
- export declare function processOpenapiFiles(files: OpenApiFiles[], options: APIOptions, sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[][]]>;
10
- export declare function processOpenapiFile(openapiData: OpenApiObject, options: APIOptions, sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[]]>;
9
+ export declare function processOpenapiFiles(files: OpenApiFiles[], options: APIOptions, sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[][], TagGroupObject[]]>;
10
+ export declare function processOpenapiFile(openapiData: OpenApiObject, options: APIOptions, sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[], TagGroupObject[]]>;
11
11
  export declare function getTagDisplayName(tagName: string, tags: TagObject[]): string;
12
12
  export {};
@@ -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
  */
@@ -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;
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;
65
65
  // TODO: Find a better way to handle this
66
66
  let items = [];
67
67
  const infoIdSpaces = openapiData.info.title.replace(" ", "-").toLowerCase();
@@ -324,9 +324,42 @@ 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) {
328
+ // 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+$/, "")
353
+ : "",
354
+ },
355
+ schema: schemaObject,
356
+ };
357
+ items.push(schemaPage);
358
+ }
359
+ }
327
360
  if ((sidebarOptions === null || sidebarOptions === void 0 ? void 0 : sidebarOptions.categoryLinkSource) === "tag") {
328
361
  // Get global tags
329
- const tags = (_0 = openapiData.tags) !== null && _0 !== void 0 ? _0 : [];
362
+ const tags = (_4 = openapiData.tags) !== null && _4 !== void 0 ? _4 : [];
330
363
  // Get operation tags
331
364
  const apiItems = items.filter((item) => {
332
365
  return item.type === "api";
@@ -375,7 +408,9 @@ function bindCollectionToApiItems(items, postmanCollection) {
375
408
  .getPath({ unresolved: true }) // unresolved returns "/:variableName" instead of "/<type>"
376
409
  .replace(/(?<![a-z0-9-_]+):([a-z0-9-_]+)/gi, "{$1}"); // replace "/:variableName" with "/{variableName}"
377
410
  const apiItem = items.find((item) => {
378
- if (item.type === "info" || item.type === "tag") {
411
+ if (item.type === "info" ||
412
+ item.type === "tag" ||
413
+ item.type === "schema") {
379
414
  return false;
380
415
  }
381
416
  return item.api.path === path && item.api.method === method;
@@ -426,7 +461,8 @@ async function processOpenapiFiles(files, options, sidebarOptions) {
426
461
  ...item,
427
462
  }));
428
463
  const tags = processedFile[1];
429
- return [itemsObjectsArray, tags];
464
+ const tagGroups = processedFile[2];
465
+ return [itemsObjectsArray, tags, tagGroups];
430
466
  }
431
467
  console.warn(chalk_1.default.yellow(`WARNING: the following OpenAPI spec returned undefined: ${file.source}`));
432
468
  return [];
@@ -449,7 +485,20 @@ async function processOpenapiFiles(files, options, sidebarOptions) {
449
485
  // Remove undefined tags due to transient parsing errors
450
486
  return x !== undefined;
451
487
  });
452
- return [items, tags];
488
+ const tagGroups = metadata
489
+ .map(function (x) {
490
+ return x[2];
491
+ })
492
+ .flat()
493
+ .filter(function (x) {
494
+ // Remove undefined tags due to transient parsing errors
495
+ return x !== undefined;
496
+ });
497
+ return [
498
+ items,
499
+ tags,
500
+ tagGroups,
501
+ ];
453
502
  }
454
503
  exports.processOpenapiFiles = processOpenapiFiles;
455
504
  async function processOpenapiFile(openapiData, options, sidebarOptions) {
@@ -460,7 +509,11 @@ async function processOpenapiFile(openapiData, options, sidebarOptions) {
460
509
  if (openapiData.tags !== undefined) {
461
510
  tags = openapiData.tags;
462
511
  }
463
- return [items, tags];
512
+ let tagGroups = [];
513
+ if (openapiData["x-tagGroups"] !== undefined) {
514
+ tagGroups = openapiData["x-tagGroups"];
515
+ }
516
+ return [items, tags, tagGroups];
464
517
  }
465
518
  exports.processOpenapiFile = processOpenapiFile;
466
519
  // order for picking items as a display name of tags
@@ -24,6 +24,8 @@ describe("openapi", () => {
24
24
  const yaml = results.find((x) => x.source.endsWith("openapi.yaml"));
25
25
  expect(yaml).toBeTruthy();
26
26
  expect(yaml === null || yaml === void 0 ? void 0 : yaml.sourceDirName).toBe(".");
27
+ expect(yaml === null || yaml === void 0 ? void 0 : yaml.data.tags).toBeDefined();
28
+ expect(yaml === null || yaml === void 0 ? void 0 : yaml.data["x-tagGroups"]).toBeDefined();
27
29
  });
28
30
  });
29
31
  });
@@ -13,6 +13,7 @@ export interface OpenApiObject {
13
13
  externalDocs?: ExternalDocumentationObject;
14
14
  swagger?: string;
15
15
  "x-webhooks"?: PathsObject;
16
+ "x-tagGroups"?: TagGroupObject[];
16
17
  }
17
18
  export interface OpenApiObjectWithRef {
18
19
  openapi: string;
@@ -81,8 +82,8 @@ export interface ComponentsObjectWithRef {
81
82
  links?: Map<LinkObject | ReferenceObject>;
82
83
  callbacks?: Map<CallbackObjectWithRef | ReferenceObject>;
83
84
  }
84
- export declare type PathsObject = Map<PathItemObject>;
85
- export declare type PathsObjectWithRef = Map<PathItemObjectWithRef>;
85
+ export type PathsObject = Map<PathItemObject>;
86
+ export type PathsObjectWithRef = Map<PathItemObjectWithRef>;
86
87
  export interface PathItemObject {
87
88
  $ref?: string;
88
89
  summary?: string;
@@ -214,8 +215,8 @@ export interface EncodingObjectWithRef {
214
215
  explode?: boolean;
215
216
  allowReserved?: boolean;
216
217
  }
217
- export declare type ResponsesObject = Map<ResponseObject>;
218
- export declare type ResponsesObjectWithRef = Map<ResponseObjectWithRef | ReferenceObject>;
218
+ export type ResponsesObject = Map<ResponseObject>;
219
+ export type ResponsesObjectWithRef = Map<ResponseObjectWithRef | ReferenceObject>;
219
220
  export interface ResponseObject {
220
221
  description: string;
221
222
  headers?: Map<HeaderObject>;
@@ -228,8 +229,8 @@ export interface ResponseObjectWithRef {
228
229
  content?: Map<MediaTypeObjectWithRef>;
229
230
  links?: Map<LinkObject | ReferenceObject>;
230
231
  }
231
- export declare type CallbackObject = Map<PathItemObject>;
232
- export declare type CallbackObjectWithRef = Map<PathItemObjectWithRef>;
232
+ export type CallbackObject = Map<PathItemObject>;
233
+ export type CallbackObjectWithRef = Map<PathItemObjectWithRef>;
233
234
  export interface ExampleObject {
234
235
  summary?: string;
235
236
  description?: string;
@@ -244,19 +245,23 @@ export interface LinkObject {
244
245
  description?: string;
245
246
  server?: ServerObject;
246
247
  }
247
- export declare type HeaderObject = Omit<ParameterObject, "name" | "in">;
248
- export declare type HeaderObjectWithRef = Omit<ParameterObjectWithRef, "name" | "in">;
248
+ export type HeaderObject = Omit<ParameterObject, "name" | "in">;
249
+ export type HeaderObjectWithRef = Omit<ParameterObjectWithRef, "name" | "in">;
249
250
  export interface TagObject {
250
251
  name?: string;
251
252
  description?: string;
252
253
  externalDocs?: ExternalDocumentationObject;
253
254
  "x-displayName"?: string;
254
255
  }
256
+ export interface TagGroupObject {
257
+ name: string;
258
+ tags: string[];
259
+ }
255
260
  export interface ReferenceObject {
256
261
  $ref: string;
257
262
  }
258
- export declare type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
259
- export declare type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
263
+ export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
264
+ export type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
260
265
  type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
261
266
  allOf?: SchemaObject[];
262
267
  oneOf?: SchemaObject[];
@@ -274,7 +279,7 @@ export declare type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" |
274
279
  example?: any;
275
280
  deprecated?: boolean;
276
281
  };
277
- export declare type SchemaObjectWithRef = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
282
+ export type SchemaObjectWithRef = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
278
283
  type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
279
284
  allOf?: (SchemaObject | ReferenceObject)[];
280
285
  oneOf?: (SchemaObject | ReferenceObject)[];
@@ -303,7 +308,7 @@ export interface XMLObject {
303
308
  attribute?: boolean;
304
309
  wrapped?: boolean;
305
310
  }
306
- export declare type SecuritySchemeObject = ApiKeySecuritySchemeObject | HttpSecuritySchemeObject | Oauth2SecuritySchemeObject | OpenIdConnectSecuritySchemeObject;
311
+ export type SecuritySchemeObject = ApiKeySecuritySchemeObject | HttpSecuritySchemeObject | Oauth2SecuritySchemeObject | OpenIdConnectSecuritySchemeObject;
307
312
  export interface ApiKeySecuritySchemeObject {
308
313
  type: "apiKey";
309
314
  description?: string;
@@ -340,5 +345,5 @@ export interface OAuthFlowObject {
340
345
  refreshUrl?: string;
341
346
  scopes: Map<string>;
342
347
  }
343
- export declare type SecurityRequirementObject = Map<string[]>;
348
+ export type SecurityRequirementObject = Map<string[]>;
344
349
  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
  /**
@@ -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
@@ -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
  }