docusaurus-theme-openapi-docs 1.0.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 (187) hide show
  1. package/LICENSE +21 -0
  2. package/babel.config.js +35 -0
  3. package/lib/index.js +48 -0
  4. package/lib/markdown/createDescription.js +20 -0
  5. package/lib/markdown/schema.js +121 -0
  6. package/lib/markdown/utils.js +45 -0
  7. package/lib/theme/ApiDemoPanel/Accept/index.js +41 -0
  8. package/lib/theme/ApiDemoPanel/Accept/slice.js +32 -0
  9. package/lib/theme/ApiDemoPanel/Authorization/auth-types.js +32 -0
  10. package/lib/theme/ApiDemoPanel/Authorization/index.js +174 -0
  11. package/lib/theme/ApiDemoPanel/Authorization/slice.js +137 -0
  12. package/lib/theme/ApiDemoPanel/Body/index.js +185 -0
  13. package/lib/theme/ApiDemoPanel/Body/slice.js +105 -0
  14. package/lib/theme/ApiDemoPanel/ContentType/index.js +41 -0
  15. package/lib/theme/ApiDemoPanel/ContentType/slice.js +32 -0
  16. package/lib/theme/ApiDemoPanel/Curl/index.js +236 -0
  17. package/lib/theme/ApiDemoPanel/Curl/styles.module.css +84 -0
  18. package/lib/theme/ApiDemoPanel/Execute/index.js +85 -0
  19. package/lib/theme/ApiDemoPanel/Execute/makeRequest.js +202 -0
  20. package/lib/theme/ApiDemoPanel/FloatingButton/index.js +32 -0
  21. package/lib/theme/ApiDemoPanel/FloatingButton/styles.module.css +26 -0
  22. package/lib/theme/ApiDemoPanel/FormFileUpload/index.js +97 -0
  23. package/lib/theme/ApiDemoPanel/FormFileUpload/styles.module.css +75 -0
  24. package/lib/theme/ApiDemoPanel/FormItem/index.js +35 -0
  25. package/lib/theme/ApiDemoPanel/FormItem/styles.module.css +7 -0
  26. package/lib/theme/ApiDemoPanel/FormMultiSelect/index.js +52 -0
  27. package/lib/theme/ApiDemoPanel/FormMultiSelect/styles.module.css +38 -0
  28. package/lib/theme/ApiDemoPanel/FormSelect/index.js +39 -0
  29. package/lib/theme/ApiDemoPanel/FormSelect/styles.module.css +51 -0
  30. package/lib/theme/ApiDemoPanel/FormTextInput/index.js +30 -0
  31. package/lib/theme/ApiDemoPanel/FormTextInput/styles.module.css +21 -0
  32. package/lib/theme/ApiDemoPanel/MethodEndpoint/index.js +60 -0
  33. package/lib/theme/ApiDemoPanel/ParamOptions/index.js +248 -0
  34. package/lib/theme/ApiDemoPanel/ParamOptions/slice.js +35 -0
  35. package/lib/theme/ApiDemoPanel/ParamOptions/styles.module.css +180 -0
  36. package/lib/theme/ApiDemoPanel/Response/index.js +75 -0
  37. package/lib/theme/ApiDemoPanel/Response/slice.js +37 -0
  38. package/lib/theme/ApiDemoPanel/SecuritySchemes/index.js +51 -0
  39. package/lib/theme/ApiDemoPanel/Server/index.js +109 -0
  40. package/lib/theme/ApiDemoPanel/Server/slice.js +41 -0
  41. package/lib/theme/ApiDemoPanel/Server/styles.module.css +61 -0
  42. package/lib/theme/ApiDemoPanel/VSCode/index.js +252 -0
  43. package/lib/theme/ApiDemoPanel/VSCode/styles.module.css +19 -0
  44. package/lib/theme/ApiDemoPanel/buildPostmanRequest.js +329 -0
  45. package/lib/theme/ApiDemoPanel/hooks.js +20 -0
  46. package/lib/theme/ApiDemoPanel/index.js +134 -0
  47. package/lib/theme/ApiDemoPanel/persistanceMiddleware.js +44 -0
  48. package/lib/theme/ApiDemoPanel/postman-collection.d.ts +10 -0
  49. package/lib/theme/ApiDemoPanel/storage-utils.js +47 -0
  50. package/lib/theme/ApiDemoPanel/store.js +48 -0
  51. package/lib/theme/ApiDemoPanel/styles.module.css +44 -0
  52. package/lib/theme/ApiItem/index.js +160 -0
  53. package/lib/theme/ApiItem/styles.module.css +109 -0
  54. package/lib/theme/ParamsItem/index.js +68 -0
  55. package/lib/theme/ParamsItem/styles.module.css +24 -0
  56. package/lib/theme/SchemaItem/index.js +58 -0
  57. package/lib/theme/SchemaItem/styles.module.css +24 -0
  58. package/lib/theme/Tabs/index.js +258 -0
  59. package/lib/theme/Tabs/styles.module.css +118 -0
  60. package/lib/theme-classic.d.ts +8 -0
  61. package/lib/theme-openapi.d.ts +48 -0
  62. package/lib/theme-translations.d.ts +9 -0
  63. package/lib/types.js +1 -0
  64. package/lib-next/index.js +38 -0
  65. package/lib-next/markdown/createDescription.js +13 -0
  66. package/lib-next/markdown/schema.js +115 -0
  67. package/lib-next/markdown/utils.js +31 -0
  68. package/lib-next/theme/ApiDemoPanel/Accept/index.js +33 -0
  69. package/lib-next/theme/ApiDemoPanel/Accept/slice.js +19 -0
  70. package/lib-next/theme/ApiDemoPanel/Authorization/auth-types.js +22 -0
  71. package/lib-next/theme/ApiDemoPanel/Authorization/index.js +203 -0
  72. package/lib-next/theme/ApiDemoPanel/Authorization/slice.js +101 -0
  73. package/lib-next/theme/ApiDemoPanel/Body/index.js +210 -0
  74. package/lib-next/theme/ApiDemoPanel/Body/slice.js +89 -0
  75. package/lib-next/theme/ApiDemoPanel/ContentType/index.js +33 -0
  76. package/lib-next/theme/ApiDemoPanel/ContentType/slice.js +19 -0
  77. package/lib-next/theme/ApiDemoPanel/Curl/index.js +264 -0
  78. package/lib-next/theme/ApiDemoPanel/Curl/styles.module.css +84 -0
  79. package/lib-next/theme/ApiDemoPanel/Execute/index.js +74 -0
  80. package/lib-next/theme/ApiDemoPanel/Execute/makeRequest.js +183 -0
  81. package/lib-next/theme/ApiDemoPanel/FloatingButton/index.js +19 -0
  82. package/lib-next/theme/ApiDemoPanel/FloatingButton/styles.module.css +26 -0
  83. package/lib-next/theme/ApiDemoPanel/FormFileUpload/index.js +113 -0
  84. package/lib-next/theme/ApiDemoPanel/FormFileUpload/styles.module.css +75 -0
  85. package/lib-next/theme/ApiDemoPanel/FormItem/index.js +29 -0
  86. package/lib-next/theme/ApiDemoPanel/FormItem/styles.module.css +7 -0
  87. package/lib-next/theme/ApiDemoPanel/FormMultiSelect/index.js +49 -0
  88. package/lib-next/theme/ApiDemoPanel/FormMultiSelect/styles.module.css +38 -0
  89. package/lib-next/theme/ApiDemoPanel/FormSelect/index.js +28 -0
  90. package/lib-next/theme/ApiDemoPanel/FormSelect/styles.module.css +51 -0
  91. package/lib-next/theme/ApiDemoPanel/FormTextInput/index.js +23 -0
  92. package/lib-next/theme/ApiDemoPanel/FormTextInput/styles.module.css +21 -0
  93. package/lib-next/theme/ApiDemoPanel/MethodEndpoint/index.js +53 -0
  94. package/lib-next/theme/ApiDemoPanel/ParamOptions/index.js +284 -0
  95. package/lib-next/theme/ApiDemoPanel/ParamOptions/slice.js +22 -0
  96. package/lib-next/theme/ApiDemoPanel/ParamOptions/styles.module.css +180 -0
  97. package/lib-next/theme/ApiDemoPanel/Response/index.js +65 -0
  98. package/lib-next/theme/ApiDemoPanel/Response/slice.js +22 -0
  99. package/lib-next/theme/ApiDemoPanel/SecuritySchemes/index.js +48 -0
  100. package/lib-next/theme/ApiDemoPanel/Server/index.js +114 -0
  101. package/lib-next/theme/ApiDemoPanel/Server/slice.js +25 -0
  102. package/lib-next/theme/ApiDemoPanel/Server/styles.module.css +61 -0
  103. package/lib-next/theme/ApiDemoPanel/VSCode/index.js +265 -0
  104. package/lib-next/theme/ApiDemoPanel/VSCode/styles.module.css +19 -0
  105. package/lib-next/theme/ApiDemoPanel/buildPostmanRequest.js +310 -0
  106. package/lib-next/theme/ApiDemoPanel/hooks.js +9 -0
  107. package/lib-next/theme/ApiDemoPanel/index.js +110 -0
  108. package/lib-next/theme/ApiDemoPanel/persistanceMiddleware.js +38 -0
  109. package/lib-next/theme/ApiDemoPanel/postman-collection.d.ts +10 -0
  110. package/lib-next/theme/ApiDemoPanel/storage-utils.js +35 -0
  111. package/lib-next/theme/ApiDemoPanel/store.js +30 -0
  112. package/lib-next/theme/ApiDemoPanel/styles.module.css +44 -0
  113. package/lib-next/theme/ApiItem/index.js +171 -0
  114. package/lib-next/theme/ApiItem/styles.module.css +109 -0
  115. package/lib-next/theme/ParamsItem/index.js +68 -0
  116. package/lib-next/theme/ParamsItem/styles.module.css +24 -0
  117. package/lib-next/theme/SchemaItem/index.js +58 -0
  118. package/lib-next/theme/SchemaItem/styles.module.css +24 -0
  119. package/lib-next/theme/Tabs/index.js +258 -0
  120. package/lib-next/theme/Tabs/styles.module.css +118 -0
  121. package/lib-next/theme-classic.d.ts +8 -0
  122. package/lib-next/theme-openapi.d.ts +48 -0
  123. package/lib-next/theme-translations.d.ts +9 -0
  124. package/lib-next/types.js +1 -0
  125. package/package.json +68 -0
  126. package/src/index.ts +42 -0
  127. package/src/markdown/createDescription.ts +13 -0
  128. package/src/markdown/schema.ts +115 -0
  129. package/src/markdown/utils.ts +39 -0
  130. package/src/theme/ApiDemoPanel/Accept/index.tsx +35 -0
  131. package/src/theme/ApiDemoPanel/Accept/slice.ts +29 -0
  132. package/src/theme/ApiDemoPanel/Authorization/auth-types.ts +26 -0
  133. package/src/theme/ApiDemoPanel/Authorization/index.tsx +211 -0
  134. package/src/theme/ApiDemoPanel/Authorization/slice.ts +145 -0
  135. package/src/theme/ApiDemoPanel/Body/index.tsx +218 -0
  136. package/src/theme/ApiDemoPanel/Body/slice.ts +133 -0
  137. package/src/theme/ApiDemoPanel/ContentType/index.tsx +35 -0
  138. package/src/theme/ApiDemoPanel/ContentType/slice.ts +29 -0
  139. package/src/theme/ApiDemoPanel/Curl/index.tsx +280 -0
  140. package/src/theme/ApiDemoPanel/Curl/styles.module.css +84 -0
  141. package/src/theme/ApiDemoPanel/Execute/index.tsx +88 -0
  142. package/src/theme/ApiDemoPanel/Execute/makeRequest.ts +184 -0
  143. package/src/theme/ApiDemoPanel/FloatingButton/index.tsx +27 -0
  144. package/src/theme/ApiDemoPanel/FloatingButton/styles.module.css +26 -0
  145. package/src/theme/ApiDemoPanel/FormFileUpload/index.tsx +116 -0
  146. package/src/theme/ApiDemoPanel/FormFileUpload/styles.module.css +75 -0
  147. package/src/theme/ApiDemoPanel/FormItem/index.tsx +28 -0
  148. package/src/theme/ApiDemoPanel/FormItem/styles.module.css +7 -0
  149. package/src/theme/ApiDemoPanel/FormMultiSelect/index.tsx +54 -0
  150. package/src/theme/ApiDemoPanel/FormMultiSelect/styles.module.css +38 -0
  151. package/src/theme/ApiDemoPanel/FormSelect/index.tsx +36 -0
  152. package/src/theme/ApiDemoPanel/FormSelect/styles.module.css +51 -0
  153. package/src/theme/ApiDemoPanel/FormTextInput/index.tsx +32 -0
  154. package/src/theme/ApiDemoPanel/FormTextInput/styles.module.css +21 -0
  155. package/src/theme/ApiDemoPanel/MethodEndpoint/index.tsx +55 -0
  156. package/src/theme/ApiDemoPanel/ParamOptions/index.tsx +316 -0
  157. package/src/theme/ApiDemoPanel/ParamOptions/slice.ts +37 -0
  158. package/src/theme/ApiDemoPanel/ParamOptions/styles.module.css +180 -0
  159. package/src/theme/ApiDemoPanel/Response/index.tsx +66 -0
  160. package/src/theme/ApiDemoPanel/Response/slice.ts +31 -0
  161. package/src/theme/ApiDemoPanel/SecuritySchemes/index.tsx +49 -0
  162. package/src/theme/ApiDemoPanel/Server/index.tsx +103 -0
  163. package/src/theme/ApiDemoPanel/Server/slice.ts +40 -0
  164. package/src/theme/ApiDemoPanel/Server/styles.module.css +61 -0
  165. package/src/theme/ApiDemoPanel/VSCode/index.tsx +205 -0
  166. package/src/theme/ApiDemoPanel/VSCode/styles.module.css +19 -0
  167. package/src/theme/ApiDemoPanel/buildPostmanRequest.ts +307 -0
  168. package/src/theme/ApiDemoPanel/hooks.ts +13 -0
  169. package/src/theme/ApiDemoPanel/index.tsx +118 -0
  170. package/src/theme/ApiDemoPanel/persistanceMiddleware.ts +46 -0
  171. package/src/theme/ApiDemoPanel/postman-collection.d.ts +10 -0
  172. package/src/theme/ApiDemoPanel/storage-utils.ts +39 -0
  173. package/src/theme/ApiDemoPanel/store.ts +41 -0
  174. package/src/theme/ApiDemoPanel/styles.module.css +44 -0
  175. package/src/theme/ApiItem/index.tsx +171 -0
  176. package/src/theme/ApiItem/styles.module.css +109 -0
  177. package/src/theme/ParamsItem/index.js +68 -0
  178. package/src/theme/ParamsItem/styles.module.css +24 -0
  179. package/src/theme/SchemaItem/index.js +58 -0
  180. package/src/theme/SchemaItem/styles.module.css +24 -0
  181. package/src/theme/Tabs/index.js +258 -0
  182. package/src/theme/Tabs/styles.module.css +118 -0
  183. package/src/theme-classic.d.ts +8 -0
  184. package/src/theme-openapi.d.ts +48 -0
  185. package/src/theme-translations.d.ts +9 -0
  186. package/src/types.ts +70 -0
  187. package/tsconfig.json +10 -0
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
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
+ .tabItem {
9
+ display: flex;
10
+ align-items: center;
11
+ justify-content: center;
12
+ height: 2.5rem;
13
+ margin-top: 0 !important;
14
+ margin-right: 0.5rem;
15
+ border: 1px solid var(--openapi-code-dim-dark);
16
+ border-radius: var(--ifm-global-radius);
17
+ font-weight: var(--ifm-font-weight-normal);
18
+ color: var(--openapi-code-dim-dark);
19
+ }
20
+
21
+ .tabItem:hover {
22
+ color: var(--ifm-color-emphasis-500) !important;
23
+ }
24
+
25
+ .tabItem:last-child {
26
+ margin-right: 0 !important;
27
+ }
28
+
29
+ /* Open API Response Code Tabs */
30
+ .responseTabsTopSection {
31
+ margin-top: 2rem;
32
+ display: flex;
33
+ justify-content: space-between;
34
+ align-items: center;
35
+ }
36
+
37
+ .responseTabsContainer {
38
+ display: flex;
39
+ align-items: center;
40
+ max-width: 390px;
41
+ padding-left: 1rem;
42
+ overflow: hidden;
43
+ }
44
+
45
+ .responseTabsListContainer {
46
+ padding: 0 0.25rem;
47
+ overflow-y: hidden;
48
+ overflow-x: scroll;
49
+ scroll-behavior: smooth;
50
+ }
51
+
52
+ .responseTabsListContainer::-webkit-scrollbar {
53
+ display: none;
54
+ }
55
+
56
+ /* Response Code Tabs - Colored Dots */
57
+ .responseTabDot {
58
+ width: 12.5px;
59
+ height: 12.5px;
60
+ margin-right: 5px;
61
+ border-radius: 50%;
62
+ }
63
+
64
+ .responseTabDotSuccess {
65
+ background-color: var(--ifm-color-success);
66
+ }
67
+
68
+ .responseTabDotDanger {
69
+ background-color: var(--ifm-color-danger);
70
+ }
71
+
72
+ .responseTabDotInfo {
73
+ background-color: var(--ifm-color-info);
74
+ }
75
+
76
+ .responseTabActive {
77
+ border: 1px solid var(--ifm-color-primary);
78
+ color: var(--ifm-color-primary);
79
+ }
80
+
81
+ .responseSchemaContainer {
82
+ max-width: 600px;
83
+ }
84
+
85
+ /* Tab Arrows */
86
+ .tabArrow {
87
+ content: "";
88
+ height: 1.25rem;
89
+ width: 1.25rem;
90
+ padding: 0 0.75rem;
91
+ border: none;
92
+ min-width: 1.25rem;
93
+ background: var(--ifm-menu-link-sublist-icon) 50% / 2rem 2rem;
94
+ filter: var(--ifm-menu-link-sublist-icon-filter);
95
+ }
96
+
97
+ .tabArrow:hover {
98
+ cursor: pointer;
99
+ }
100
+ .tabArrowLeft {
101
+ transform: rotate(270deg);
102
+ }
103
+ .tabArrowRight {
104
+ transform: rotate(90deg);
105
+ }
106
+
107
+ @media screen and (max-width: 500px) {
108
+ .responseTabsTopSection {
109
+ flex-direction: column;
110
+ align-items: flex-start;
111
+ }
112
+
113
+ .responseTabsContainer {
114
+ width: 100%;
115
+ margin-top: var(--ifm-spacing-vertical);
116
+ padding: 0;
117
+ }
118
+ }
@@ -0,0 +1,8 @@
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
+ /// <reference types="@docusaurus/theme-classic" />
@@ -0,0 +1,48 @@
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
+ /// <reference types="docusaurus-plugin-openapi-docs" />
9
+
10
+ declare module "@docusaurus/plugin-content-docs-types" {
11
+ // Makes all properties visible when hovering over the type
12
+ type Expand<T extends Record<string, unknown>> = { [P in keyof T]: T[P] };
13
+
14
+ export type SidebarItemBase = {
15
+ className?: string;
16
+ customProps?: Record<string, unknown>;
17
+ };
18
+
19
+ export type SidebarItemLink = SidebarItemBase & {
20
+ type: "link";
21
+ href: string;
22
+ label: string;
23
+ docId: string;
24
+ };
25
+
26
+ type SidebarItemCategoryBase = SidebarItemBase & {
27
+ type: "category";
28
+ label: string;
29
+ collapsed: boolean;
30
+ collapsible: boolean;
31
+ };
32
+
33
+ export type PropSidebarItemCategory = Expand<
34
+ SidebarItemCategoryBase & {
35
+ items: PropSidebarItem[];
36
+ }
37
+ >;
38
+
39
+ export type PropSidebarItem = SidebarItemLink | PropSidebarItemCategory;
40
+ export type PropSidebar = PropSidebarItem[];
41
+ export type PropSidebars = {
42
+ [sidebarId: string]: PropSidebar;
43
+ };
44
+ }
45
+
46
+ declare module "docusaurus-theme-openapi-docs" {
47
+ export type ThemeConfig = Partial<import("./types").ThemeConfig>;
48
+ }
@@ -0,0 +1,9 @@
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
+ // TODO: Remove this when https://github.com/facebook/docusaurus/issues/6087 is resolved.
9
+ declare module "@docusaurus/theme-translations";
package/lib/types.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,38 @@
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
+ import path from "path";
8
+ import { ProvidePlugin } from "webpack";
9
+ export default function docusaurusThemeOpenAPI() {
10
+ return {
11
+ name: "docusaurus-theme-openapi",
12
+
13
+ getThemePath() {
14
+ return path.join(__dirname, "..", "lib-next", "theme");
15
+ },
16
+
17
+ getTypeScriptThemePath() {
18
+ return path.resolve(__dirname, "..", "src", "theme");
19
+ },
20
+
21
+ configureWebpack() {
22
+ return {
23
+ plugins: [
24
+ new ProvidePlugin({
25
+ Buffer: [require.resolve("buffer/"), "Buffer"],
26
+ process: require.resolve("process/browser"),
27
+ }),
28
+ ],
29
+ resolve: {
30
+ fallback: {
31
+ buffer: require.resolve("buffer/"),
32
+ process: require.resolve("process/browser"),
33
+ },
34
+ },
35
+ };
36
+ },
37
+ };
38
+ }
@@ -0,0 +1,13 @@
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
+ export function createDescription(description) {
8
+ if (!description) {
9
+ return "";
10
+ }
11
+
12
+ return `\n\n${description}\n\n`;
13
+ }
@@ -0,0 +1,115 @@
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
+ function prettyName(schema, circular) {
8
+ if (schema.$ref) {
9
+ return schema.$ref.replace("#/components/schemas/", "") + circular
10
+ ? " (circular)"
11
+ : "";
12
+ }
13
+
14
+ if (schema.format) {
15
+ return schema.format;
16
+ }
17
+
18
+ if (schema.allOf) {
19
+ return "object";
20
+ }
21
+
22
+ if (schema.type === "object") {
23
+ return schema.xml?.name ?? schema.type;
24
+ }
25
+
26
+ return schema.title ?? schema.type;
27
+ }
28
+
29
+ export function getSchemaName(schema, circular) {
30
+ if (schema.items) {
31
+ return prettyName(schema.items, circular) + "[]";
32
+ }
33
+
34
+ return prettyName(schema, circular) ?? "";
35
+ }
36
+ export function getQualifierMessage(schema) {
37
+ // TODO:
38
+ // - maxItems
39
+ // - minItems
40
+ // - uniqueItems
41
+ // - maxProperties
42
+ // - minProperties
43
+ // - multipleOf
44
+ if (!schema) {
45
+ return undefined;
46
+ }
47
+
48
+ if (schema.items) {
49
+ return getQualifierMessage(schema.items);
50
+ }
51
+
52
+ let message = "**Possible values:** ";
53
+ let qualifierGroups = [];
54
+
55
+ if (schema.minLength || schema.maxLength) {
56
+ let lengthQualifier = "";
57
+
58
+ if (schema.minLength) {
59
+ lengthQualifier += `${schema.minLength} ≤ `;
60
+ }
61
+
62
+ lengthQualifier += "length";
63
+
64
+ if (schema.maxLength) {
65
+ lengthQualifier += ` ≤ ${schema.maxLength}`;
66
+ }
67
+
68
+ qualifierGroups.push(lengthQualifier);
69
+ }
70
+
71
+ if (
72
+ schema.minimum ||
73
+ schema.maximum ||
74
+ typeof schema.exclusiveMinimum === "number" ||
75
+ typeof schema.exclusiveMaximum === "number"
76
+ ) {
77
+ let minmaxQualifier = "";
78
+
79
+ if (typeof schema.exclusiveMinimum === "number") {
80
+ minmaxQualifier += `${schema.exclusiveMinimum} < `;
81
+ } else if (schema.minimum && !schema.exclusiveMinimum) {
82
+ minmaxQualifier += `${schema.minimum} ≤ `;
83
+ } else if (schema.minimum && schema.exclusiveMinimum === true) {
84
+ minmaxQualifier += `${schema.minimum} < `;
85
+ }
86
+
87
+ minmaxQualifier += "value";
88
+
89
+ if (typeof schema.exclusiveMaximum === "number") {
90
+ minmaxQualifier += ` < ${schema.exclusiveMaximum}`;
91
+ } else if (schema.maximum && !schema.exclusiveMaximum) {
92
+ minmaxQualifier += ` ≤ ${schema.maximum}`;
93
+ } else if (schema.maximum && schema.exclusiveMaximum === true) {
94
+ minmaxQualifier += ` < ${schema.maximum}`;
95
+ }
96
+
97
+ qualifierGroups.push(minmaxQualifier);
98
+ }
99
+
100
+ if (schema.pattern) {
101
+ qualifierGroups.push(
102
+ `Value must match regular expression \`${schema.pattern}\``
103
+ );
104
+ }
105
+
106
+ if (schema.enum) {
107
+ qualifierGroups.push(`[${schema.enum.map((e) => `\`${e}\``).join(", ")}]`);
108
+ }
109
+
110
+ if (qualifierGroups.length === 0) {
111
+ return undefined;
112
+ }
113
+
114
+ return message + qualifierGroups.join(", ");
115
+ }
@@ -0,0 +1,31 @@
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
+ export function create(tag, props) {
8
+ const { children, ...rest } = props;
9
+ let propString = "";
10
+
11
+ for (const [key, value] of Object.entries(rest)) {
12
+ propString += ` ${key}={${JSON.stringify(value)}}`;
13
+ }
14
+
15
+ return `<${tag}${propString}>${render(children)}</${tag}>`;
16
+ }
17
+ export function guard(value, cb) {
18
+ if (value) {
19
+ const children = cb(value);
20
+ return render(children);
21
+ }
22
+
23
+ return "";
24
+ }
25
+ export function render(children) {
26
+ if (Array.isArray(children)) {
27
+ return children.filter((c) => c !== undefined).join("");
28
+ }
29
+
30
+ return children ?? "";
31
+ }
@@ -0,0 +1,33 @@
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
+ import React from "react";
8
+ import { useTypedDispatch, useTypedSelector } from "../hooks";
9
+ import FormItem from "./../FormItem";
10
+ import FormSelect from "./../FormSelect";
11
+ import { setAccept } from "./slice";
12
+
13
+ function Accept() {
14
+ const value = useTypedSelector((state) => state.accept.value);
15
+ const options = useTypedSelector((state) => state.accept.options);
16
+ const dispatch = useTypedDispatch();
17
+
18
+ if (options.length <= 1) {
19
+ return null;
20
+ }
21
+
22
+ return (
23
+ <FormItem label="Accept">
24
+ <FormSelect
25
+ value={value}
26
+ options={options}
27
+ onChange={(e) => dispatch(setAccept(e.target.value))}
28
+ />
29
+ </FormItem>
30
+ );
31
+ }
32
+
33
+ export default Accept;
@@ -0,0 +1,19 @@
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
+ import { createSlice } from "@reduxjs/toolkit";
8
+ const initialState = {};
9
+ export const slice = createSlice({
10
+ name: "accept",
11
+ initialState,
12
+ reducers: {
13
+ setAccept: (state, action) => {
14
+ state.value = action.payload;
15
+ },
16
+ },
17
+ });
18
+ export const { setAccept } = slice.actions;
19
+ export default slice.reducer;
@@ -0,0 +1,22 @@
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
+ export function getAuthDataKeys(security) {
8
+ // Bearer Auth
9
+ if (security.type === "http" && security.scheme === "bearer") {
10
+ return ["token"];
11
+ } // Basic Auth
12
+
13
+ if (security.type === "http" && security.scheme === "basic") {
14
+ return ["username", "password"];
15
+ } // API Auth
16
+
17
+ if (security.type === "apiKey") {
18
+ return ["apiKey"];
19
+ } // none
20
+
21
+ return [];
22
+ }
@@ -0,0 +1,203 @@
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
+ import React, { useState } from "react";
8
+ import clsx from "clsx";
9
+ import FormItem from "../FormItem";
10
+ import FormSelect from "../FormSelect";
11
+ import FormTextInput from "../FormTextInput";
12
+ import { useTypedDispatch, useTypedSelector } from "../hooks";
13
+ import styles from "../styles.module.css";
14
+ import { setAuthData, setSelectedAuth } from "./slice";
15
+
16
+ function LockButton({ mode, children, style, ...rest }) {
17
+ return (
18
+ <button
19
+ className={clsx("button", "button--primary", {
20
+ "button--outline": mode !== "locked",
21
+ })}
22
+ style={{
23
+ marginLeft: "auto",
24
+ display: "flex",
25
+ alignItems: "center",
26
+ marginBottom: "var(--ifm-spacing-vertical)",
27
+ ...style,
28
+ }}
29
+ {...rest}
30
+ >
31
+ <span>{children}</span>
32
+
33
+ <svg
34
+ style={{
35
+ marginLeft: "12px",
36
+ width: "18px",
37
+ height: "18px",
38
+ fill: "currentColor",
39
+ }}
40
+ viewBox="0 0 20 20"
41
+ id={mode}
42
+ >
43
+ {mode === "locked" ? (
44
+ <path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"></path>
45
+ ) : (
46
+ <path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
47
+ )}
48
+ </svg>
49
+ </button>
50
+ );
51
+ }
52
+
53
+ function validateData(selectedAuth, data) {
54
+ for (const scheme of selectedAuth) {
55
+ if (data[scheme.key] === undefined) {
56
+ return false;
57
+ }
58
+
59
+ const hasMissingKeys = Object.values(data[scheme.key]).includes(undefined);
60
+
61
+ if (hasMissingKeys) {
62
+ return false;
63
+ }
64
+ }
65
+
66
+ return true;
67
+ }
68
+
69
+ function Authorization() {
70
+ const [editing, setEditing] = useState(false);
71
+ const data = useTypedSelector((state) => state.auth.data);
72
+ const options = useTypedSelector((state) => state.auth.options);
73
+ const selected = useTypedSelector((state) => state.auth.selected);
74
+ const dispatch = useTypedDispatch();
75
+
76
+ if (selected === undefined) {
77
+ return null;
78
+ }
79
+
80
+ const selectedAuth = options[selected];
81
+ const authenticated = validateData(selectedAuth, data);
82
+ const optionKeys = Object.keys(options);
83
+
84
+ if (editing) {
85
+ return (
86
+ <div className={styles.optionsPanel}>
87
+ {optionKeys.length > 1 && (
88
+ <FormItem label="Security Scheme">
89
+ <FormSelect
90
+ options={optionKeys}
91
+ value={selected}
92
+ onChange={(e) => {
93
+ dispatch(setSelectedAuth(e.target.value));
94
+ }}
95
+ />
96
+ </FormItem>
97
+ )}
98
+ {selectedAuth.map((a) => {
99
+ if (a.type === "http" && a.scheme === "bearer") {
100
+ return (
101
+ <FormItem label="Bearer Token" key={selected + "-bearer"}>
102
+ <FormTextInput
103
+ placeholder="Bearer Token"
104
+ value={data[a.key].token ?? ""}
105
+ onChange={(e) => {
106
+ const value = e.target.value.trim();
107
+ dispatch(
108
+ setAuthData({
109
+ scheme: a.key,
110
+ key: "token",
111
+ value: value ? value : undefined,
112
+ })
113
+ );
114
+ }}
115
+ />
116
+ </FormItem>
117
+ );
118
+ }
119
+
120
+ if (a.type === "http" && a.scheme === "basic") {
121
+ return (
122
+ <React.Fragment key={selected + "-basic"}>
123
+ <FormItem label="Username">
124
+ <FormTextInput
125
+ placeholder="Username"
126
+ value={data[a.key].username ?? ""}
127
+ onChange={(e) => {
128
+ const value = e.target.value.trim();
129
+ dispatch(
130
+ setAuthData({
131
+ scheme: a.key,
132
+ key: "username",
133
+ value: value ? value : undefined,
134
+ })
135
+ );
136
+ }}
137
+ />
138
+ </FormItem>
139
+ <FormItem label="Password">
140
+ <FormTextInput
141
+ placeholder="Password"
142
+ password
143
+ value={data[a.key].password ?? ""}
144
+ onChange={(e) => {
145
+ const value = e.target.value.trim();
146
+ dispatch(
147
+ setAuthData({
148
+ scheme: a.key,
149
+ key: "password",
150
+ value: value ? value : undefined,
151
+ })
152
+ );
153
+ }}
154
+ />
155
+ </FormItem>
156
+ </React.Fragment>
157
+ );
158
+ }
159
+
160
+ return null;
161
+ })}
162
+ <LockButton
163
+ mode="unlocked"
164
+ style={{
165
+ marginTop: "var(--ifm-spacing-vertical)",
166
+ marginBottom: 0,
167
+ }}
168
+ onClick={() => {
169
+ setEditing(false);
170
+ }}
171
+ >
172
+ Save
173
+ </LockButton>
174
+ </div>
175
+ );
176
+ }
177
+
178
+ if (authenticated) {
179
+ return (
180
+ <LockButton
181
+ mode="locked"
182
+ onClick={() => {
183
+ setEditing(true);
184
+ }}
185
+ >
186
+ Authorized
187
+ </LockButton>
188
+ );
189
+ }
190
+
191
+ return (
192
+ <LockButton
193
+ mode="unlocked"
194
+ onClick={() => {
195
+ setEditing(true);
196
+ }}
197
+ >
198
+ Authorize
199
+ </LockButton>
200
+ );
201
+ }
202
+
203
+ export default Authorization;