docusaurus-plugin-openapi-docs 1.0.1 → 1.0.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.
Files changed (66) hide show
  1. package/README.md +110 -21
  2. package/lib/index.d.ts +7 -1
  3. package/lib/index.js +257 -22
  4. package/lib/markdown/createAuthentication.d.ts +2 -0
  5. package/lib/markdown/createAuthentication.js +139 -0
  6. package/lib/markdown/createContactInfo.d.ts +2 -0
  7. package/lib/markdown/createContactInfo.js +49 -0
  8. package/lib/markdown/createLicense.d.ts +2 -0
  9. package/lib/markdown/createLicense.js +33 -0
  10. package/lib/markdown/createParamsDetails.js +2 -0
  11. package/lib/markdown/createSchemaDetails.js +6 -1
  12. package/lib/markdown/createStatusCodes.js +1 -1
  13. package/lib/markdown/createTermsOfService.d.ts +1 -0
  14. package/lib/markdown/createTermsOfService.js +32 -0
  15. package/lib/markdown/index.d.ts +3 -2
  16. package/lib/markdown/index.js +17 -3
  17. package/lib/openapi/createExample.js +59 -49
  18. package/lib/openapi/openapi.d.ts +5 -4
  19. package/lib/openapi/openapi.js +94 -50
  20. package/lib/openapi/openapi.test.js +0 -6
  21. package/lib/openapi/types.d.ts +5 -1
  22. package/lib/openapi/utils/loadAndBundleSpec.d.ts +3 -0
  23. package/lib/openapi/utils/loadAndBundleSpec.js +44 -0
  24. package/lib/openapi/utils/types.d.ts +306 -0
  25. package/lib/{markdown/createRequestBodyTable.js → openapi/utils/types.js} +0 -6
  26. package/lib/options.d.ts +0 -2
  27. package/lib/options.js +36 -7
  28. package/lib/sidebars/index.d.ts +2 -1
  29. package/lib/sidebars/index.js +91 -35
  30. package/lib/sidebars/utils.d.ts +2 -0
  31. package/lib/sidebars/utils.js +31 -0
  32. package/lib/types.d.ts +35 -11
  33. package/package.json +10 -9
  34. package/src/index.ts +332 -25
  35. package/src/markdown/createAuthentication.ts +160 -0
  36. package/src/markdown/createContactInfo.ts +52 -0
  37. package/src/markdown/createLicense.ts +34 -0
  38. package/src/markdown/createParamsDetails.ts +2 -0
  39. package/src/markdown/createSchemaDetails.ts +8 -2
  40. package/src/markdown/createStatusCodes.ts +1 -1
  41. package/src/markdown/createTermsOfService.ts +30 -0
  42. package/src/markdown/index.ts +23 -3
  43. package/src/openapi/createExample.ts +59 -50
  44. package/src/openapi/openapi.test.ts +0 -6
  45. package/src/openapi/openapi.ts +115 -53
  46. package/src/openapi/types.ts +5 -1
  47. package/src/openapi/utils/loadAndBundleSpec.ts +62 -0
  48. package/src/openapi/utils/types.ts +303 -0
  49. package/src/options.ts +41 -8
  50. package/src/{markdown/createRequestBodyTable.ts → postman-collection.d.ts} +2 -9
  51. package/src/sidebars/index.ts +116 -36
  52. package/src/sidebars/utils.ts +29 -0
  53. package/src/types.ts +36 -10
  54. package/lib/markdown/createFullWidthTable.d.ts +0 -2
  55. package/lib/markdown/createFullWidthTable.js +0 -18
  56. package/lib/markdown/createParamsTable.d.ts +0 -7
  57. package/lib/markdown/createParamsTable.js +0 -80
  58. package/lib/markdown/createRequestBodyTable.d.ts +0 -6
  59. package/lib/markdown/createSchemaTable.d.ts +0 -14
  60. package/lib/markdown/createSchemaTable.js +0 -217
  61. package/src/markdown/createFullWidthTable.ts +0 -16
  62. package/src/markdown/createParamsTable.ts +0 -102
  63. package/src/markdown/createSchemaTable.ts +0 -275
  64. package/src/openapi/__fixtures__/examples/yogurtstore/_category_.json +0 -4
  65. package/src/openapi/__fixtures__/examples/yogurtstore/froyo.yaml +0 -13
  66. package/src/openapi/__fixtures__/examples/yogurtstore/nested/nested.yaml +0 -13
package/lib/options.js CHANGED
@@ -6,13 +6,42 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  * ========================================================================== */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.OptionsSchema = exports.DEFAULT_OPTIONS = void 0;
9
+ exports.OptionsSchema = void 0;
10
10
  const utils_validation_1 = require("@docusaurus/utils-validation");
11
- exports.DEFAULT_OPTIONS = {
12
- id: "default",
13
- config: {},
14
- };
11
+ const sidebarOptions = utils_validation_1.Joi.object({
12
+ groupPathsBy: utils_validation_1.Joi.string().valid("tag"),
13
+ categoryLinkSource: utils_validation_1.Joi.string().valid("tag", "info"),
14
+ customProps: utils_validation_1.Joi.object(),
15
+ sidebarCollapsible: utils_validation_1.Joi.boolean(),
16
+ sidebarCollapsed: utils_validation_1.Joi.boolean(),
17
+ });
15
18
  exports.OptionsSchema = utils_validation_1.Joi.object({
16
- id: utils_validation_1.Joi.string().default(exports.DEFAULT_OPTIONS.id),
17
- config: utils_validation_1.Joi.object().default(exports.DEFAULT_OPTIONS.config),
19
+ id: utils_validation_1.Joi.string().required(),
20
+ docPluginId: utils_validation_1.Joi.string().required(),
21
+ config: utils_validation_1.Joi.object()
22
+ .pattern(/^/, utils_validation_1.Joi.object({
23
+ specPath: utils_validation_1.Joi.string().required(),
24
+ outputDir: utils_validation_1.Joi.string().required(),
25
+ template: utils_validation_1.Joi.string(),
26
+ sidebarOptions: sidebarOptions,
27
+ version: utils_validation_1.Joi.string().when("versions", {
28
+ is: utils_validation_1.Joi.exist(),
29
+ then: utils_validation_1.Joi.required(),
30
+ }),
31
+ label: utils_validation_1.Joi.string().when("versions", {
32
+ is: utils_validation_1.Joi.exist(),
33
+ then: utils_validation_1.Joi.required(),
34
+ }),
35
+ baseUrl: utils_validation_1.Joi.string().when("versions", {
36
+ is: utils_validation_1.Joi.exist(),
37
+ then: utils_validation_1.Joi.required(),
38
+ }),
39
+ versions: utils_validation_1.Joi.object().pattern(/^/, utils_validation_1.Joi.object({
40
+ specPath: utils_validation_1.Joi.string().required(),
41
+ outputDir: utils_validation_1.Joi.string().required(),
42
+ label: utils_validation_1.Joi.string().required(),
43
+ baseUrl: utils_validation_1.Joi.string().required(),
44
+ })),
45
+ }))
46
+ .required(),
18
47
  });
@@ -1,3 +1,4 @@
1
1
  import { ProcessedSidebar } from "@docusaurus/plugin-content-docs/src/sidebars/types";
2
+ import { TagObject } from "../openapi/types";
2
3
  import type { SidebarOptions, APIOptions, ApiMetadata } from "../types";
3
- export default function generateSidebarSlice(sidebarOptions: SidebarOptions, options: APIOptions, api: ApiMetadata[]): ProcessedSidebar;
4
+ export default function generateSidebarSlice(sidebarOptions: SidebarOptions, options: APIOptions, api: ApiMetadata[], tags: TagObject[], docPath: string): ProcessedSidebar;
@@ -10,31 +10,34 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const clsx_1 = __importDefault(require("clsx"));
13
+ const lodash_1 = require("lodash");
13
14
  const uniq_1 = __importDefault(require("lodash/uniq"));
14
15
  function isApiItem(item) {
15
16
  return item.type === "api";
16
17
  }
17
- function groupByTags(items, sidebarOptions, options) {
18
- // TODO: Figure out how to handle these
19
- // const intros = items.filter(isInfoItem).map((item) => {
20
- // return {
21
- // type: "link" as const,
22
- // label: item.title,
23
- // href: item.permalink,
24
- // docId: item.id,
25
- // };
26
- // });
18
+ function isInfoItem(item) {
19
+ return item.type === "info";
20
+ }
21
+ function groupByTags(items, sidebarOptions, options, tags, docPath) {
27
22
  const { outputDir } = options;
28
- const { sidebarCollapsed, sidebarCollapsible, customProps } = sidebarOptions;
23
+ const { sidebarCollapsed, sidebarCollapsible, customProps, categoryLinkSource, } = sidebarOptions;
29
24
  const apiItems = items.filter(isApiItem);
25
+ const infoItems = items.filter(isInfoItem);
26
+ const intros = infoItems.map((item) => {
27
+ return {
28
+ id: item.id,
29
+ title: item.title,
30
+ description: item.description,
31
+ tags: item.info.tags,
32
+ };
33
+ });
30
34
  // TODO: make sure we only take the first tag
31
- const tags = (0, uniq_1.default)(apiItems
35
+ const apiTags = (0, uniq_1.default)(apiItems
32
36
  .flatMap((item) => item.api.tags)
33
37
  .filter((item) => !!item));
34
- // TODO: optimize this or make it a function
35
- const basePath = outputDir
36
- .slice(outputDir.indexOf("/", 1))
37
- .replace(/^\/+/g, "");
38
+ const basePath = docPath
39
+ ? outputDir.split(docPath)[1].replace(/^\/+/g, "")
40
+ : outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
38
41
  function createDocItem(item) {
39
42
  var _a, _b;
40
43
  const sidebar_label = item.frontMatter.sidebar_label;
@@ -42,7 +45,7 @@ function groupByTags(items, sidebarOptions, options) {
42
45
  const id = item.id;
43
46
  return {
44
47
  type: "doc",
45
- id: `${basePath}/${item.id}`,
48
+ id: basePath === "" || undefined ? `${item.id}` : `${basePath}/${item.id}`,
46
49
  label: (_b = (_a = sidebar_label) !== null && _a !== void 0 ? _a : title) !== null && _b !== void 0 ? _b : id,
47
50
  customProps: customProps,
48
51
  className: (0, clsx_1.default)({
@@ -51,11 +54,54 @@ function groupByTags(items, sidebarOptions, options) {
51
54
  }, item.api.method),
52
55
  };
53
56
  }
54
- const tagged = tags
57
+ let rootIntroDoc = undefined;
58
+ if (infoItems.length === 1) {
59
+ const infoItem = infoItems[0];
60
+ const id = infoItem.id;
61
+ rootIntroDoc = {
62
+ type: "doc",
63
+ id: `${basePath}/${id}`,
64
+ };
65
+ }
66
+ const tagged = apiTags
55
67
  .map((tag) => {
68
+ // Map info object to tag
69
+ const taggedInfoObject = intros.find((i) => i.tags ? i.tags.includes(tag) : undefined);
70
+ const tagObject = tags.flat().find((t) => {
71
+ var _a;
72
+ return (_a = (tag === t.name || tag === t["x-displayName"])) !== null && _a !== void 0 ? _a : {
73
+ name: tag,
74
+ description: `${tag} Index`,
75
+ };
76
+ });
77
+ // TODO: perhaps move this into a getLinkConfig() function
78
+ let linkConfig = undefined;
79
+ if (taggedInfoObject !== undefined && categoryLinkSource === "info") {
80
+ linkConfig = {
81
+ type: "doc",
82
+ id: `${basePath}/${taggedInfoObject.id}`,
83
+ };
84
+ }
85
+ // TODO: perhaps move this into a getLinkConfig() function
86
+ if (tagObject !== undefined && categoryLinkSource === "tag") {
87
+ const tagId = (0, lodash_1.kebabCase)(tagObject.name);
88
+ linkConfig = {
89
+ type: "doc",
90
+ id: `${basePath}/${tagId}`,
91
+ };
92
+ }
93
+ // Default behavior
94
+ if (categoryLinkSource === undefined) {
95
+ linkConfig = {
96
+ type: "generated-index",
97
+ title: tag,
98
+ slug: "/category/" + (0, lodash_1.kebabCase)(tag),
99
+ };
100
+ }
56
101
  return {
57
102
  type: "category",
58
103
  label: tag,
104
+ link: linkConfig,
59
105
  collapsible: sidebarCollapsible,
60
106
  collapsed: sidebarCollapsed,
61
107
  items: apiItems
@@ -64,25 +110,35 @@ function groupByTags(items, sidebarOptions, options) {
64
110
  };
65
111
  })
66
112
  .filter((item) => item.items.length > 0); // Filter out any categories with no items.
67
- // const untagged = [
68
- // // TODO: determine if needed and how
69
- // {
70
- // type: "category" as const,
71
- // label: "UNTAGGED",
72
- // // collapsible: options.sidebarCollapsible, TODO: add option
73
- // // collapsed: options.sidebarCollapsed, TODO: add option
74
- // items: apiItems
75
- // //@ts-ignore
76
- // .filter(({ api }) => api.tags === undefined || api.tags.length === 0)
77
- // .map(createDocItem),
78
- // },
79
- // ];
80
- return [...tagged];
113
+ // Handle items with no tag
114
+ const untaggedItems = apiItems
115
+ .filter(({ api }) => api.tags === undefined || api.tags.length === 0)
116
+ .map(createDocItem);
117
+ let untagged = [];
118
+ if (untaggedItems.length > 0) {
119
+ untagged = [
120
+ {
121
+ type: "category",
122
+ label: "UNTAGGED",
123
+ collapsible: sidebarCollapsible,
124
+ collapsed: sidebarCollapsed,
125
+ items: apiItems
126
+ .filter(({ api }) => api.tags === undefined || api.tags.length === 0)
127
+ .map(createDocItem),
128
+ },
129
+ ];
130
+ }
131
+ // Shift root intro doc to top of sidebar
132
+ // TODO: Add input validation for categoryLinkSource options
133
+ if (rootIntroDoc && categoryLinkSource !== "info") {
134
+ tagged.unshift(rootIntroDoc);
135
+ }
136
+ return [...tagged, ...untagged];
81
137
  }
82
- function generateSidebarSlice(sidebarOptions, options, api) {
138
+ function generateSidebarSlice(sidebarOptions, options, api, tags, docPath) {
83
139
  let sidebarSlice = [];
84
- if (sidebarOptions.groupPathsBy === "tags") {
85
- sidebarSlice = groupByTags(api, sidebarOptions, options);
140
+ if (sidebarOptions.groupPathsBy === "tag") {
141
+ sidebarSlice = groupByTags(api, sidebarOptions, options, tags, docPath);
86
142
  }
87
143
  return sidebarSlice;
88
144
  }
@@ -0,0 +1,2 @@
1
+ export declare function versionSelector(versions: object[]): string;
2
+ export declare function versionCrumb(version: string): string;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Copyright (c) Palo Alto Networks
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ * ========================================================================== */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.versionCrumb = exports.versionSelector = void 0;
10
+ const mustache_1 = require("mustache");
11
+ function versionSelector(versions) {
12
+ const template = `<div class="dropdown dropdown--hoverable dropdown--right">
13
+ <button class="button button--block button--sm button--secondary"><span>Select API Version</span></button>
14
+ <ul class="dropdown__menu">
15
+ {{#.}}<li><a class="dropdown__link" href="{{{baseUrl}}}">{{{label}}}</a></li>{{/.}}
16
+ </ul>
17
+ </div>
18
+ `;
19
+ const view = (0, mustache_1.render)(template, versions);
20
+ return view;
21
+ }
22
+ exports.versionSelector = versionSelector;
23
+ function versionCrumb(version) {
24
+ const template = `<ul style="display: flex;" class="breadcrumbs breadcrumbs--sm">
25
+ <li style="margin-left: auto; margin-right: 0;" class="breadcrumbs__item breadcrumbs__item--active">
26
+ <a class="breadcrumbs__link"><span>{{{.}}}</span></a></li></ul>
27
+ `;
28
+ const view = (0, mustache_1.render)(template, version);
29
+ return view;
30
+ }
31
+ exports.versionCrumb = versionCrumb;
package/lib/types.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import type { Request } from "@paloaltonetworks/postman-collection";
2
- import { InfoObject, OperationObject, SecuritySchemeObject } from "./openapi/types";
1
+ import type Request from "@paloaltonetworks/postman-collection";
2
+ import { InfoObject, OperationObject, 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
+ docPluginId: string;
6
7
  config: {
7
8
  [key: string]: APIOptions;
8
9
  };
@@ -12,17 +13,40 @@ export interface APIOptions {
12
13
  outputDir: string;
13
14
  template?: string;
14
15
  sidebarOptions?: SidebarOptions;
16
+ version?: string;
17
+ label?: string;
18
+ baseUrl?: string;
19
+ versions?: {
20
+ [key: string]: APIVersionOptions;
21
+ };
22
+ }
23
+ export interface SidebarOptions {
24
+ groupPathsBy?: string;
25
+ categoryLinkSource?: string;
26
+ customProps?: {
27
+ [key: string]: unknown;
28
+ };
29
+ sidebarCollapsible?: boolean;
30
+ sidebarCollapsed?: boolean;
31
+ }
32
+ export interface APIVersionOptions {
33
+ specPath: string;
34
+ outputDir: string;
35
+ label: string;
36
+ baseUrl: string;
15
37
  }
16
38
  export interface LoadedContent {
17
39
  loadedApi: ApiMetadata[];
18
40
  }
19
- export declare type ApiMetadata = ApiPageMetadata | InfoPageMetadata;
41
+ export declare type ApiMetadata = ApiPageMetadata | InfoPageMetadata | TagPageMetadata;
20
42
  export interface ApiMetadataBase {
21
43
  sidebar?: string;
22
44
  previous?: ApiNavLink;
23
45
  next?: ApiNavLink;
24
46
  id: string;
25
47
  unversionedId: string;
48
+ infoId?: string;
49
+ infoPath?: string;
26
50
  title: string;
27
51
  description: string;
28
52
  source: string;
@@ -52,17 +76,17 @@ export interface InfoPageMetadata extends ApiMetadataBase {
52
76
  type: "info";
53
77
  info: ApiInfo;
54
78
  markdown?: string;
79
+ securitySchemes?: {
80
+ [key: string]: SecuritySchemeObject;
81
+ };
82
+ }
83
+ export interface TagPageMetadata extends ApiMetadataBase {
84
+ type: "tag";
85
+ tag: TagObject;
86
+ markdown?: string;
55
87
  }
56
88
  export declare type ApiInfo = InfoObject;
57
89
  export interface ApiNavLink {
58
90
  title: string;
59
91
  permalink: string;
60
92
  }
61
- export interface SidebarOptions {
62
- groupPathsBy?: string;
63
- customProps?: {
64
- [key: string]: unknown;
65
- };
66
- sidebarCollapsible?: boolean;
67
- sidebarCollapsed?: boolean;
68
- }
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": "1.0.1",
4
+ "version": "1.0.4",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -28,21 +28,21 @@
28
28
  "watch": "tsc --watch"
29
29
  },
30
30
  "devDependencies": {
31
- "@docusaurus/module-type-aliases": "2.0.0-beta.18",
32
- "@docusaurus/types": "2.0.0-beta.18",
31
+ "@docusaurus/module-type-aliases": "2.0.0-beta.21",
32
+ "@docusaurus/types": "2.0.0-beta.21",
33
33
  "@types/fs-extra": "^9.0.13",
34
34
  "@types/json-schema": "^7.0.9",
35
35
  "@types/lodash": "^4.14.176",
36
- "@types/postman-collection": "^3.5.7",
37
36
  "utility-types": "^3.10.0"
38
37
  },
39
38
  "dependencies": {
40
- "@docusaurus/mdx-loader": "2.0.0-beta.18",
41
- "@docusaurus/plugin-content-docs": "2.0.0-beta.18",
42
- "@docusaurus/utils": "2.0.0-beta.18",
43
- "@docusaurus/utils-validation": "2.0.0-beta.18",
39
+ "@docusaurus/mdx-loader": "2.0.0-beta.21",
40
+ "@docusaurus/plugin-content-docs": "2.0.0-beta.21",
41
+ "@docusaurus/utils": "2.0.0-beta.21",
42
+ "@docusaurus/utils-validation": "2.0.0-beta.21",
44
43
  "@paloaltonetworks/openapi-to-postmanv2": "3.1.0-hotfix.1",
45
44
  "@paloaltonetworks/postman-collection": "^4.1.0",
45
+ "@redocly/openapi-core": "^1.0.0-beta.100",
46
46
  "@types/js-yaml": "^4.0.5",
47
47
  "@types/mustache": "^4.1.2",
48
48
  "chalk": "^4.1.2",
@@ -53,6 +53,7 @@
53
53
  "json-schema-merge-allof": "^0.8.1",
54
54
  "lodash": "^4.17.20",
55
55
  "mustache": "^4.2.0",
56
+ "swagger2openapi": "^7.0.8",
56
57
  "webpack": "^5.61.0"
57
58
  },
58
59
  "peerDependencies": {
@@ -61,5 +62,5 @@
61
62
  "engines": {
62
63
  "node": ">=14"
63
64
  },
64
- "gitHead": "27f594d26440ffe6f890b35c79847e065a96723e"
65
+ "gitHead": "0a590e8aaaff087d13adb7b4be75aa0112b9a2b5"
65
66
  }