docusaurus-plugin-openapi-docs 0.0.0-345

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 (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +194 -0
  3. package/lib/index.d.ts +3 -0
  4. package/lib/index.js +194 -0
  5. package/lib/markdown/createDeprecationNotice.d.ts +6 -0
  6. package/lib/markdown/createDeprecationNotice.js +19 -0
  7. package/lib/markdown/createDescription.d.ts +1 -0
  8. package/lib/markdown/createDescription.js +16 -0
  9. package/lib/markdown/createDetails.d.ts +2 -0
  10. package/lib/markdown/createDetails.js +18 -0
  11. package/lib/markdown/createDetailsSummary.d.ts +2 -0
  12. package/lib/markdown/createDetailsSummary.js +18 -0
  13. package/lib/markdown/createFullWidthTable.d.ts +2 -0
  14. package/lib/markdown/createFullWidthTable.js +18 -0
  15. package/lib/markdown/createParamsDetails.d.ts +7 -0
  16. package/lib/markdown/createParamsDetails.js +44 -0
  17. package/lib/markdown/createParamsTable.d.ts +7 -0
  18. package/lib/markdown/createParamsTable.js +80 -0
  19. package/lib/markdown/createRequestBodyDetails.d.ts +6 -0
  20. package/lib/markdown/createRequestBodyDetails.js +14 -0
  21. package/lib/markdown/createRequestBodyTable.d.ts +6 -0
  22. package/lib/markdown/createRequestBodyTable.js +14 -0
  23. package/lib/markdown/createSchemaDetails.d.ts +14 -0
  24. package/lib/markdown/createSchemaDetails.js +241 -0
  25. package/lib/markdown/createSchemaTable.d.ts +14 -0
  26. package/lib/markdown/createSchemaTable.js +217 -0
  27. package/lib/markdown/createStatusCodes.d.ts +6 -0
  28. package/lib/markdown/createStatusCodes.js +47 -0
  29. package/lib/markdown/createVersionBadge.d.ts +1 -0
  30. package/lib/markdown/createVersionBadge.js +20 -0
  31. package/lib/markdown/index.d.ts +3 -0
  32. package/lib/markdown/index.js +43 -0
  33. package/lib/markdown/schema.d.ts +3 -0
  34. package/lib/markdown/schema.js +100 -0
  35. package/lib/markdown/schema.test.d.ts +1 -0
  36. package/lib/markdown/schema.test.js +171 -0
  37. package/lib/markdown/utils.d.ts +7 -0
  38. package/lib/markdown/utils.js +33 -0
  39. package/lib/openapi/createExample.d.ts +2 -0
  40. package/lib/openapi/createExample.js +113 -0
  41. package/lib/openapi/index.d.ts +1 -0
  42. package/lib/openapi/index.js +12 -0
  43. package/lib/openapi/openapi.d.ts +11 -0
  44. package/lib/openapi/openapi.js +231 -0
  45. package/lib/openapi/openapi.test.d.ts +1 -0
  46. package/lib/openapi/openapi.test.js +33 -0
  47. package/lib/openapi/types.d.ts +332 -0
  48. package/lib/openapi/types.js +8 -0
  49. package/lib/options.d.ts +4 -0
  50. package/lib/options.js +18 -0
  51. package/lib/sidebars/index.d.ts +3 -0
  52. package/lib/sidebars/index.js +89 -0
  53. package/lib/types.d.ts +68 -0
  54. package/lib/types.js +8 -0
  55. package/package.json +64 -0
  56. package/src/index.ts +244 -0
  57. package/src/markdown/createDeprecationNotice.ts +30 -0
  58. package/src/markdown/createDescription.ts +13 -0
  59. package/src/markdown/createDetails.ts +16 -0
  60. package/src/markdown/createDetailsSummary.ts +16 -0
  61. package/src/markdown/createFullWidthTable.ts +16 -0
  62. package/src/markdown/createParamsDetails.ts +53 -0
  63. package/src/markdown/createParamsTable.ts +102 -0
  64. package/src/markdown/createRequestBodyDetails.ts +17 -0
  65. package/src/markdown/createRequestBodyTable.ts +17 -0
  66. package/src/markdown/createSchemaDetails.ts +302 -0
  67. package/src/markdown/createSchemaTable.ts +275 -0
  68. package/src/markdown/createStatusCodes.ts +52 -0
  69. package/src/markdown/createVersionBadge.ts +18 -0
  70. package/src/markdown/index.ts +55 -0
  71. package/src/markdown/schema.test.ts +196 -0
  72. package/src/markdown/schema.ts +115 -0
  73. package/src/markdown/utils.ts +39 -0
  74. package/src/openapi/__fixtures__/examples/openapi.yaml +13 -0
  75. package/src/openapi/__fixtures__/examples/yogurtstore/_category_.json +4 -0
  76. package/src/openapi/__fixtures__/examples/yogurtstore/froyo.yaml +13 -0
  77. package/src/openapi/__fixtures__/examples/yogurtstore/nested/nested.yaml +13 -0
  78. package/src/openapi/createExample.ts +143 -0
  79. package/src/openapi/index.ts +8 -0
  80. package/src/openapi/openapi.test.ts +37 -0
  81. package/src/openapi/openapi.ts +292 -0
  82. package/src/openapi/types.ts +431 -0
  83. package/src/openapi-to-postmanv2.d.ts +10 -0
  84. package/src/options.ts +20 -0
  85. package/src/plugin-content-docs-types.d.ts +42 -0
  86. package/src/plugin-openapi.d.ts +87 -0
  87. package/src/postman-collection.d.ts +10 -0
  88. package/src/sidebars/index.ts +121 -0
  89. package/src/types.ts +96 -0
  90. package/tsconfig.json +7 -0
  91. package/yarn-error.log +15179 -0
@@ -0,0 +1,121 @@
1
+ /* ============================================================================
2
+ * Copyright (c) Palo Alto Networks
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ * ========================================================================== */
7
+
8
+ import {
9
+ ProcessedSidebar,
10
+ SidebarItemDoc,
11
+ } from "@docusaurus/plugin-content-docs/src/sidebars/types";
12
+ import clsx from "clsx";
13
+ import uniq from "lodash/uniq";
14
+
15
+ import type {
16
+ SidebarOptions,
17
+ APIOptions,
18
+ ApiPageMetadata,
19
+ ApiMetadata,
20
+ } from "../types";
21
+
22
+ function isApiItem(item: ApiMetadata): item is ApiMetadata {
23
+ return item.type === "api";
24
+ }
25
+
26
+ function groupByTags(
27
+ items: ApiPageMetadata[],
28
+ sidebarOptions: SidebarOptions,
29
+ options: APIOptions
30
+ ): ProcessedSidebar {
31
+ // TODO: Figure out how to handle these
32
+ // const intros = items.filter(isInfoItem).map((item) => {
33
+ // return {
34
+ // type: "link" as const,
35
+ // label: item.title,
36
+ // href: item.permalink,
37
+ // docId: item.id,
38
+ // };
39
+ // });
40
+
41
+ const { outputDir } = options;
42
+ const { sidebarCollapsed, sidebarCollapsible, customProps } = sidebarOptions;
43
+
44
+ const apiItems = items.filter(isApiItem);
45
+
46
+ // TODO: make sure we only take the first tag
47
+ const tags = uniq(
48
+ apiItems
49
+ .flatMap((item) => item.api.tags)
50
+ .filter((item): item is string => !!item)
51
+ );
52
+
53
+ // TODO: optimize this or make it a function
54
+ const basePath = outputDir
55
+ .slice(outputDir.indexOf("/", 1))
56
+ .replace(/^\/+/g, "");
57
+
58
+ function createDocItem(item: ApiPageMetadata): SidebarItemDoc {
59
+ const sidebar_label = item.frontMatter.sidebar_label;
60
+ const title = item.title;
61
+ const id = item.id;
62
+ return {
63
+ type: "doc" as const,
64
+ id: `${basePath}/${item.id}`,
65
+ label: (sidebar_label as string) ?? title ?? id,
66
+ customProps: customProps,
67
+ className: clsx(
68
+ {
69
+ "menu__list-item--deprecated": item.api.deprecated,
70
+ "api-method": !!item.api.method,
71
+ },
72
+ item.api.method
73
+ ),
74
+ };
75
+ }
76
+
77
+ const tagged = tags
78
+ .map((tag) => {
79
+ return {
80
+ type: "category" as const,
81
+ label: tag,
82
+ collapsible: sidebarCollapsible,
83
+ collapsed: sidebarCollapsed,
84
+ items: apiItems
85
+ .filter((item) => !!item.api.tags?.includes(tag))
86
+ .map(createDocItem),
87
+ };
88
+ })
89
+ .filter((item) => item.items.length > 0); // Filter out any categories with no items.
90
+
91
+ // const untagged = [
92
+ // // TODO: determine if needed and how
93
+ // {
94
+ // type: "category" as const,
95
+ // label: "UNTAGGED",
96
+ // // collapsible: options.sidebarCollapsible, TODO: add option
97
+ // // collapsed: options.sidebarCollapsed, TODO: add option
98
+ // items: apiItems
99
+ // //@ts-ignore
100
+ // .filter(({ api }) => api.tags === undefined || api.tags.length === 0)
101
+ // .map(createDocItem),
102
+ // },
103
+ // ];
104
+ return [...tagged];
105
+ }
106
+
107
+ export default function generateSidebarSlice(
108
+ sidebarOptions: SidebarOptions,
109
+ options: APIOptions,
110
+ api: ApiMetadata[]
111
+ ) {
112
+ let sidebarSlice: ProcessedSidebar = [];
113
+ if (sidebarOptions.groupPathsBy === "tags") {
114
+ sidebarSlice = groupByTags(
115
+ api as ApiPageMetadata[],
116
+ sidebarOptions,
117
+ options
118
+ );
119
+ }
120
+ return sidebarSlice;
121
+ }
package/src/types.ts ADDED
@@ -0,0 +1,96 @@
1
+ /* ============================================================================
2
+ * Copyright (c) Palo Alto Networks
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ * ========================================================================== */
7
+
8
+ import type Request from "@paloaltonetworks/postman-collection";
9
+
10
+ import {
11
+ InfoObject,
12
+ OperationObject,
13
+ SecuritySchemeObject,
14
+ } from "./openapi/types";
15
+
16
+ export type {
17
+ PropSidebarItemCategory,
18
+ SidebarItemLink,
19
+ PropSidebar,
20
+ PropSidebarItem,
21
+ } from "@docusaurus/plugin-content-docs-types";
22
+ export interface PluginOptions {
23
+ id?: string;
24
+ config: {
25
+ [key: string]: APIOptions;
26
+ };
27
+ }
28
+
29
+ export interface APIOptions {
30
+ specPath: string;
31
+ outputDir: string;
32
+ template?: string;
33
+ sidebarOptions?: SidebarOptions;
34
+ }
35
+
36
+ export interface LoadedContent {
37
+ loadedApi: ApiMetadata[];
38
+ // loadedDocs: DocPageMetadata[]; TODO: cleanup
39
+ }
40
+
41
+ export type ApiMetadata = ApiPageMetadata | InfoPageMetadata;
42
+
43
+ export interface ApiMetadataBase {
44
+ sidebar?: string;
45
+ previous?: ApiNavLink;
46
+ next?: ApiNavLink;
47
+ //
48
+ id: string; // TODO legacy versioned id => try to remove
49
+ unversionedId: string; // TODO new unversioned id => try to rename to "id"
50
+ title: string;
51
+ description: string;
52
+ source: string; // @site aliased source => "@site/docs/folder/subFolder/subSubFolder/myDoc.md"
53
+ sourceDirName: string; // relative to the versioned docs folder (can be ".") => "folder/subFolder/subSubFolder"
54
+ slug: string;
55
+ permalink: string;
56
+ sidebarPosition?: number;
57
+ frontMatter: Record<string, unknown>;
58
+ }
59
+
60
+ export interface ApiPageMetadata extends ApiMetadataBase {
61
+ json?: string;
62
+ type: "api";
63
+ api: ApiItem;
64
+ markdown?: string;
65
+ }
66
+
67
+ export interface ApiItem extends OperationObject {
68
+ method: string; // get, post, put, etc...
69
+ path: string; // The endpoint path => "/api/getPets"
70
+ jsonRequestBodyExample: string;
71
+ securitySchemes?: {
72
+ [key: string]: SecuritySchemeObject;
73
+ };
74
+ postman?: Request;
75
+ info: InfoObject;
76
+ }
77
+
78
+ export interface InfoPageMetadata extends ApiMetadataBase {
79
+ type: "info";
80
+ info: ApiInfo;
81
+ markdown?: string;
82
+ }
83
+
84
+ export type ApiInfo = InfoObject;
85
+
86
+ export interface ApiNavLink {
87
+ title: string;
88
+ permalink: string;
89
+ }
90
+
91
+ export interface SidebarOptions {
92
+ groupPathsBy?: string;
93
+ customProps?: { [key: string]: unknown };
94
+ sidebarCollapsible?: boolean;
95
+ sidebarCollapsed?: boolean;
96
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "lib"
5
+ },
6
+ "include": ["src"]
7
+ }