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.
- package/LICENSE +21 -0
- package/babel.config.js +35 -0
- package/lib/index.js +48 -0
- package/lib/markdown/createDescription.js +20 -0
- package/lib/markdown/schema.js +121 -0
- package/lib/markdown/utils.js +45 -0
- package/lib/theme/ApiDemoPanel/Accept/index.js +41 -0
- package/lib/theme/ApiDemoPanel/Accept/slice.js +32 -0
- package/lib/theme/ApiDemoPanel/Authorization/auth-types.js +32 -0
- package/lib/theme/ApiDemoPanel/Authorization/index.js +174 -0
- package/lib/theme/ApiDemoPanel/Authorization/slice.js +137 -0
- package/lib/theme/ApiDemoPanel/Body/index.js +185 -0
- package/lib/theme/ApiDemoPanel/Body/slice.js +105 -0
- package/lib/theme/ApiDemoPanel/ContentType/index.js +41 -0
- package/lib/theme/ApiDemoPanel/ContentType/slice.js +32 -0
- package/lib/theme/ApiDemoPanel/Curl/index.js +236 -0
- package/lib/theme/ApiDemoPanel/Curl/styles.module.css +84 -0
- package/lib/theme/ApiDemoPanel/Execute/index.js +85 -0
- package/lib/theme/ApiDemoPanel/Execute/makeRequest.js +202 -0
- package/lib/theme/ApiDemoPanel/FloatingButton/index.js +32 -0
- package/lib/theme/ApiDemoPanel/FloatingButton/styles.module.css +26 -0
- package/lib/theme/ApiDemoPanel/FormFileUpload/index.js +97 -0
- package/lib/theme/ApiDemoPanel/FormFileUpload/styles.module.css +75 -0
- package/lib/theme/ApiDemoPanel/FormItem/index.js +35 -0
- package/lib/theme/ApiDemoPanel/FormItem/styles.module.css +7 -0
- package/lib/theme/ApiDemoPanel/FormMultiSelect/index.js +52 -0
- package/lib/theme/ApiDemoPanel/FormMultiSelect/styles.module.css +38 -0
- package/lib/theme/ApiDemoPanel/FormSelect/index.js +39 -0
- package/lib/theme/ApiDemoPanel/FormSelect/styles.module.css +51 -0
- package/lib/theme/ApiDemoPanel/FormTextInput/index.js +30 -0
- package/lib/theme/ApiDemoPanel/FormTextInput/styles.module.css +21 -0
- package/lib/theme/ApiDemoPanel/MethodEndpoint/index.js +60 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/index.js +248 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/slice.js +35 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/styles.module.css +180 -0
- package/lib/theme/ApiDemoPanel/Response/index.js +75 -0
- package/lib/theme/ApiDemoPanel/Response/slice.js +37 -0
- package/lib/theme/ApiDemoPanel/SecuritySchemes/index.js +51 -0
- package/lib/theme/ApiDemoPanel/Server/index.js +109 -0
- package/lib/theme/ApiDemoPanel/Server/slice.js +41 -0
- package/lib/theme/ApiDemoPanel/Server/styles.module.css +61 -0
- package/lib/theme/ApiDemoPanel/VSCode/index.js +252 -0
- package/lib/theme/ApiDemoPanel/VSCode/styles.module.css +19 -0
- package/lib/theme/ApiDemoPanel/buildPostmanRequest.js +329 -0
- package/lib/theme/ApiDemoPanel/hooks.js +20 -0
- package/lib/theme/ApiDemoPanel/index.js +134 -0
- package/lib/theme/ApiDemoPanel/persistanceMiddleware.js +44 -0
- package/lib/theme/ApiDemoPanel/postman-collection.d.ts +10 -0
- package/lib/theme/ApiDemoPanel/storage-utils.js +47 -0
- package/lib/theme/ApiDemoPanel/store.js +48 -0
- package/lib/theme/ApiDemoPanel/styles.module.css +44 -0
- package/lib/theme/ApiItem/index.js +160 -0
- package/lib/theme/ApiItem/styles.module.css +109 -0
- package/lib/theme/ParamsItem/index.js +68 -0
- package/lib/theme/ParamsItem/styles.module.css +24 -0
- package/lib/theme/SchemaItem/index.js +58 -0
- package/lib/theme/SchemaItem/styles.module.css +24 -0
- package/lib/theme/Tabs/index.js +258 -0
- package/lib/theme/Tabs/styles.module.css +118 -0
- package/lib/theme-classic.d.ts +8 -0
- package/lib/theme-openapi.d.ts +48 -0
- package/lib/theme-translations.d.ts +9 -0
- package/lib/types.js +1 -0
- package/lib-next/index.js +38 -0
- package/lib-next/markdown/createDescription.js +13 -0
- package/lib-next/markdown/schema.js +115 -0
- package/lib-next/markdown/utils.js +31 -0
- package/lib-next/theme/ApiDemoPanel/Accept/index.js +33 -0
- package/lib-next/theme/ApiDemoPanel/Accept/slice.js +19 -0
- package/lib-next/theme/ApiDemoPanel/Authorization/auth-types.js +22 -0
- package/lib-next/theme/ApiDemoPanel/Authorization/index.js +203 -0
- package/lib-next/theme/ApiDemoPanel/Authorization/slice.js +101 -0
- package/lib-next/theme/ApiDemoPanel/Body/index.js +210 -0
- package/lib-next/theme/ApiDemoPanel/Body/slice.js +89 -0
- package/lib-next/theme/ApiDemoPanel/ContentType/index.js +33 -0
- package/lib-next/theme/ApiDemoPanel/ContentType/slice.js +19 -0
- package/lib-next/theme/ApiDemoPanel/Curl/index.js +264 -0
- package/lib-next/theme/ApiDemoPanel/Curl/styles.module.css +84 -0
- package/lib-next/theme/ApiDemoPanel/Execute/index.js +74 -0
- package/lib-next/theme/ApiDemoPanel/Execute/makeRequest.js +183 -0
- package/lib-next/theme/ApiDemoPanel/FloatingButton/index.js +19 -0
- package/lib-next/theme/ApiDemoPanel/FloatingButton/styles.module.css +26 -0
- package/lib-next/theme/ApiDemoPanel/FormFileUpload/index.js +113 -0
- package/lib-next/theme/ApiDemoPanel/FormFileUpload/styles.module.css +75 -0
- package/lib-next/theme/ApiDemoPanel/FormItem/index.js +29 -0
- package/lib-next/theme/ApiDemoPanel/FormItem/styles.module.css +7 -0
- package/lib-next/theme/ApiDemoPanel/FormMultiSelect/index.js +49 -0
- package/lib-next/theme/ApiDemoPanel/FormMultiSelect/styles.module.css +38 -0
- package/lib-next/theme/ApiDemoPanel/FormSelect/index.js +28 -0
- package/lib-next/theme/ApiDemoPanel/FormSelect/styles.module.css +51 -0
- package/lib-next/theme/ApiDemoPanel/FormTextInput/index.js +23 -0
- package/lib-next/theme/ApiDemoPanel/FormTextInput/styles.module.css +21 -0
- package/lib-next/theme/ApiDemoPanel/MethodEndpoint/index.js +53 -0
- package/lib-next/theme/ApiDemoPanel/ParamOptions/index.js +284 -0
- package/lib-next/theme/ApiDemoPanel/ParamOptions/slice.js +22 -0
- package/lib-next/theme/ApiDemoPanel/ParamOptions/styles.module.css +180 -0
- package/lib-next/theme/ApiDemoPanel/Response/index.js +65 -0
- package/lib-next/theme/ApiDemoPanel/Response/slice.js +22 -0
- package/lib-next/theme/ApiDemoPanel/SecuritySchemes/index.js +48 -0
- package/lib-next/theme/ApiDemoPanel/Server/index.js +114 -0
- package/lib-next/theme/ApiDemoPanel/Server/slice.js +25 -0
- package/lib-next/theme/ApiDemoPanel/Server/styles.module.css +61 -0
- package/lib-next/theme/ApiDemoPanel/VSCode/index.js +265 -0
- package/lib-next/theme/ApiDemoPanel/VSCode/styles.module.css +19 -0
- package/lib-next/theme/ApiDemoPanel/buildPostmanRequest.js +310 -0
- package/lib-next/theme/ApiDemoPanel/hooks.js +9 -0
- package/lib-next/theme/ApiDemoPanel/index.js +110 -0
- package/lib-next/theme/ApiDemoPanel/persistanceMiddleware.js +38 -0
- package/lib-next/theme/ApiDemoPanel/postman-collection.d.ts +10 -0
- package/lib-next/theme/ApiDemoPanel/storage-utils.js +35 -0
- package/lib-next/theme/ApiDemoPanel/store.js +30 -0
- package/lib-next/theme/ApiDemoPanel/styles.module.css +44 -0
- package/lib-next/theme/ApiItem/index.js +171 -0
- package/lib-next/theme/ApiItem/styles.module.css +109 -0
- package/lib-next/theme/ParamsItem/index.js +68 -0
- package/lib-next/theme/ParamsItem/styles.module.css +24 -0
- package/lib-next/theme/SchemaItem/index.js +58 -0
- package/lib-next/theme/SchemaItem/styles.module.css +24 -0
- package/lib-next/theme/Tabs/index.js +258 -0
- package/lib-next/theme/Tabs/styles.module.css +118 -0
- package/lib-next/theme-classic.d.ts +8 -0
- package/lib-next/theme-openapi.d.ts +48 -0
- package/lib-next/theme-translations.d.ts +9 -0
- package/lib-next/types.js +1 -0
- package/package.json +68 -0
- package/src/index.ts +42 -0
- package/src/markdown/createDescription.ts +13 -0
- package/src/markdown/schema.ts +115 -0
- package/src/markdown/utils.ts +39 -0
- package/src/theme/ApiDemoPanel/Accept/index.tsx +35 -0
- package/src/theme/ApiDemoPanel/Accept/slice.ts +29 -0
- package/src/theme/ApiDemoPanel/Authorization/auth-types.ts +26 -0
- package/src/theme/ApiDemoPanel/Authorization/index.tsx +211 -0
- package/src/theme/ApiDemoPanel/Authorization/slice.ts +145 -0
- package/src/theme/ApiDemoPanel/Body/index.tsx +218 -0
- package/src/theme/ApiDemoPanel/Body/slice.ts +133 -0
- package/src/theme/ApiDemoPanel/ContentType/index.tsx +35 -0
- package/src/theme/ApiDemoPanel/ContentType/slice.ts +29 -0
- package/src/theme/ApiDemoPanel/Curl/index.tsx +280 -0
- package/src/theme/ApiDemoPanel/Curl/styles.module.css +84 -0
- package/src/theme/ApiDemoPanel/Execute/index.tsx +88 -0
- package/src/theme/ApiDemoPanel/Execute/makeRequest.ts +184 -0
- package/src/theme/ApiDemoPanel/FloatingButton/index.tsx +27 -0
- package/src/theme/ApiDemoPanel/FloatingButton/styles.module.css +26 -0
- package/src/theme/ApiDemoPanel/FormFileUpload/index.tsx +116 -0
- package/src/theme/ApiDemoPanel/FormFileUpload/styles.module.css +75 -0
- package/src/theme/ApiDemoPanel/FormItem/index.tsx +28 -0
- package/src/theme/ApiDemoPanel/FormItem/styles.module.css +7 -0
- package/src/theme/ApiDemoPanel/FormMultiSelect/index.tsx +54 -0
- package/src/theme/ApiDemoPanel/FormMultiSelect/styles.module.css +38 -0
- package/src/theme/ApiDemoPanel/FormSelect/index.tsx +36 -0
- package/src/theme/ApiDemoPanel/FormSelect/styles.module.css +51 -0
- package/src/theme/ApiDemoPanel/FormTextInput/index.tsx +32 -0
- package/src/theme/ApiDemoPanel/FormTextInput/styles.module.css +21 -0
- package/src/theme/ApiDemoPanel/MethodEndpoint/index.tsx +55 -0
- package/src/theme/ApiDemoPanel/ParamOptions/index.tsx +316 -0
- package/src/theme/ApiDemoPanel/ParamOptions/slice.ts +37 -0
- package/src/theme/ApiDemoPanel/ParamOptions/styles.module.css +180 -0
- package/src/theme/ApiDemoPanel/Response/index.tsx +66 -0
- package/src/theme/ApiDemoPanel/Response/slice.ts +31 -0
- package/src/theme/ApiDemoPanel/SecuritySchemes/index.tsx +49 -0
- package/src/theme/ApiDemoPanel/Server/index.tsx +103 -0
- package/src/theme/ApiDemoPanel/Server/slice.ts +40 -0
- package/src/theme/ApiDemoPanel/Server/styles.module.css +61 -0
- package/src/theme/ApiDemoPanel/VSCode/index.tsx +205 -0
- package/src/theme/ApiDemoPanel/VSCode/styles.module.css +19 -0
- package/src/theme/ApiDemoPanel/buildPostmanRequest.ts +307 -0
- package/src/theme/ApiDemoPanel/hooks.ts +13 -0
- package/src/theme/ApiDemoPanel/index.tsx +118 -0
- package/src/theme/ApiDemoPanel/persistanceMiddleware.ts +46 -0
- package/src/theme/ApiDemoPanel/postman-collection.d.ts +10 -0
- package/src/theme/ApiDemoPanel/storage-utils.ts +39 -0
- package/src/theme/ApiDemoPanel/store.ts +41 -0
- package/src/theme/ApiDemoPanel/styles.module.css +44 -0
- package/src/theme/ApiItem/index.tsx +171 -0
- package/src/theme/ApiItem/styles.module.css +109 -0
- package/src/theme/ParamsItem/index.js +68 -0
- package/src/theme/ParamsItem/styles.module.css +24 -0
- package/src/theme/SchemaItem/index.js +58 -0
- package/src/theme/SchemaItem/styles.module.css +24 -0
- package/src/theme/Tabs/index.js +258 -0
- package/src/theme/Tabs/styles.module.css +118 -0
- package/src/theme-classic.d.ts +8 -0
- package/src/theme-openapi.d.ts +48 -0
- package/src/theme-translations.d.ts +9 -0
- package/src/types.ts +70 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,307 @@
|
|
|
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 sdk from "@paloaltonetworks/postman-collection";
|
|
9
|
+
import {
|
|
10
|
+
ParameterObject,
|
|
11
|
+
ServerObject,
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
} from "docusaurus-plugin-openapi-docs/src/openapi/types";
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
import cloneDeep from "lodash/cloneDeep";
|
|
16
|
+
|
|
17
|
+
import { AuthState, Scheme } from "./Authorization/slice";
|
|
18
|
+
import { Body, Content } from "./Body/slice";
|
|
19
|
+
|
|
20
|
+
type Param = {
|
|
21
|
+
value?: string | string[];
|
|
22
|
+
} & ParameterObject;
|
|
23
|
+
|
|
24
|
+
function setQueryParams(postman: sdk.Request, queryParams: Param[]) {
|
|
25
|
+
postman.url.query.clear();
|
|
26
|
+
|
|
27
|
+
const qp = queryParams
|
|
28
|
+
.map((param) => {
|
|
29
|
+
if (!param.value) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (Array.isArray(param.value)) {
|
|
34
|
+
return new sdk.QueryParam({
|
|
35
|
+
key: param.name,
|
|
36
|
+
value: param.value.join(","),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Parameter allows empty value: "/hello?extended"
|
|
41
|
+
if (param.allowEmptyValue) {
|
|
42
|
+
if (param.value === "true") {
|
|
43
|
+
return new sdk.QueryParam({
|
|
44
|
+
key: param.name,
|
|
45
|
+
value: null,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return new sdk.QueryParam({
|
|
52
|
+
key: param.name,
|
|
53
|
+
value: param.value,
|
|
54
|
+
});
|
|
55
|
+
})
|
|
56
|
+
.filter((item): item is sdk.QueryParam => item !== undefined);
|
|
57
|
+
|
|
58
|
+
if (qp.length > 0) {
|
|
59
|
+
postman.addQueryParams(qp);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function setPathParams(postman: sdk.Request, queryParams: Param[]) {
|
|
64
|
+
const source = queryParams.map((param) => {
|
|
65
|
+
return new sdk.Variable({
|
|
66
|
+
key: param.name,
|
|
67
|
+
value: param.value || `:${param.name}`,
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
postman.url.variables.assimilate(source, false);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function buildCookie(cookieParams: Param[]) {
|
|
74
|
+
const cookies = cookieParams
|
|
75
|
+
.map((param) => {
|
|
76
|
+
if (param.value && !Array.isArray(param.value)) {
|
|
77
|
+
return new sdk.Cookie({
|
|
78
|
+
// TODO: Is this right?
|
|
79
|
+
path: "",
|
|
80
|
+
domain: "",
|
|
81
|
+
key: param.name,
|
|
82
|
+
value: param.value,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
86
|
+
})
|
|
87
|
+
.filter((item): item is sdk.Cookie => item !== undefined);
|
|
88
|
+
const list = new sdk.CookieList(null, cookies);
|
|
89
|
+
return list.toString();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function setHeaders(
|
|
93
|
+
postman: sdk.Request,
|
|
94
|
+
contentType: string,
|
|
95
|
+
accept: string,
|
|
96
|
+
cookie: string,
|
|
97
|
+
headerParams: Param[],
|
|
98
|
+
other: { key: string; value: string }[]
|
|
99
|
+
) {
|
|
100
|
+
postman.headers.clear();
|
|
101
|
+
if (contentType) {
|
|
102
|
+
postman.addHeader({ key: "Content-Type", value: contentType });
|
|
103
|
+
}
|
|
104
|
+
if (accept) {
|
|
105
|
+
postman.addHeader({ key: "Accept", value: accept });
|
|
106
|
+
}
|
|
107
|
+
headerParams.forEach((param) => {
|
|
108
|
+
if (param.value && !Array.isArray(param.value)) {
|
|
109
|
+
postman.addHeader({ key: param.name, value: param.value });
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
other.forEach((header) => {
|
|
114
|
+
postman.addHeader(header);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
if (cookie) {
|
|
118
|
+
postman.addHeader({ key: "Cookie", value: cookie });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// TODO: this is all a bit hacky
|
|
123
|
+
function setBody(clonedPostman: sdk.Request, body: Body) {
|
|
124
|
+
if (clonedPostman.body === undefined) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (body.type === "empty") {
|
|
129
|
+
clonedPostman.body = undefined;
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (body.type === "raw" && body.content?.type === "file") {
|
|
134
|
+
// treat it like file.
|
|
135
|
+
clonedPostman.body.mode = "file";
|
|
136
|
+
clonedPostman.body.file = { src: body.content.value.src };
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
switch (clonedPostman.body.mode) {
|
|
141
|
+
case "raw": {
|
|
142
|
+
// check file even though it should already be set from above
|
|
143
|
+
if (body.type !== "raw" || body.content?.type === "file") {
|
|
144
|
+
clonedPostman.body = undefined;
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
clonedPostman.body.raw = body.content?.value ?? "";
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
case "formdata": {
|
|
151
|
+
clonedPostman.body.formdata?.clear();
|
|
152
|
+
if (body.type !== "form") {
|
|
153
|
+
// treat it like raw.
|
|
154
|
+
clonedPostman.body.mode = "raw";
|
|
155
|
+
clonedPostman.body.raw = `${body.content?.value}`;
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const params = Object.entries(body.content)
|
|
159
|
+
.filter((entry): entry is [string, NonNullable<Content>] => !!entry[1])
|
|
160
|
+
.map(([key, content]) => {
|
|
161
|
+
if (content.type === "file") {
|
|
162
|
+
return new sdk.FormParam({ key: key, ...content });
|
|
163
|
+
}
|
|
164
|
+
return new sdk.FormParam({ key: key, value: content.value });
|
|
165
|
+
});
|
|
166
|
+
clonedPostman.body.formdata?.assimilate(params, false);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
case "urlencoded": {
|
|
170
|
+
clonedPostman.body.urlencoded?.clear();
|
|
171
|
+
if (body.type !== "form") {
|
|
172
|
+
// treat it like raw.
|
|
173
|
+
clonedPostman.body.mode = "raw";
|
|
174
|
+
clonedPostman.body.raw = `${body.content?.value}`;
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const params = Object.entries(body.content)
|
|
178
|
+
.filter((entry): entry is [string, NonNullable<Content>] => !!entry[1])
|
|
179
|
+
.map(([key, content]) => {
|
|
180
|
+
if (content.type !== "file" && content.value) {
|
|
181
|
+
return new sdk.QueryParam({ key: key, value: content.value });
|
|
182
|
+
}
|
|
183
|
+
return undefined;
|
|
184
|
+
})
|
|
185
|
+
.filter((item): item is sdk.QueryParam => item !== undefined);
|
|
186
|
+
clonedPostman.body.urlencoded?.assimilate(params, false);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
default:
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// TODO: finish these types
|
|
195
|
+
interface Options {
|
|
196
|
+
server?: ServerObject;
|
|
197
|
+
queryParams: Param[];
|
|
198
|
+
pathParams: Param[];
|
|
199
|
+
cookieParams: Param[];
|
|
200
|
+
headerParams: Param[];
|
|
201
|
+
contentType: string;
|
|
202
|
+
accept: string;
|
|
203
|
+
body: Body;
|
|
204
|
+
auth: AuthState;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function buildPostmanRequest(
|
|
208
|
+
postman: sdk.Request,
|
|
209
|
+
{
|
|
210
|
+
queryParams,
|
|
211
|
+
pathParams,
|
|
212
|
+
cookieParams,
|
|
213
|
+
contentType,
|
|
214
|
+
accept,
|
|
215
|
+
headerParams,
|
|
216
|
+
body,
|
|
217
|
+
server,
|
|
218
|
+
auth,
|
|
219
|
+
}: Options
|
|
220
|
+
) {
|
|
221
|
+
const clonedPostman = cloneDeep(postman);
|
|
222
|
+
|
|
223
|
+
clonedPostman.url.protocol = undefined;
|
|
224
|
+
clonedPostman.url.host = [window.location.origin];
|
|
225
|
+
|
|
226
|
+
if (server) {
|
|
227
|
+
let url = server.url.replace(/\/$/, "");
|
|
228
|
+
const variables = server.variables;
|
|
229
|
+
if (variables) {
|
|
230
|
+
Object.keys(variables).forEach((variable) => {
|
|
231
|
+
url = url.replace(`{${variable}}`, variables[variable].default);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
clonedPostman.url.host = [url];
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
setQueryParams(clonedPostman, queryParams);
|
|
238
|
+
setPathParams(clonedPostman, pathParams);
|
|
239
|
+
|
|
240
|
+
const cookie = buildCookie(cookieParams);
|
|
241
|
+
let otherHeaders = [];
|
|
242
|
+
|
|
243
|
+
let selectedAuth: Scheme[] = [];
|
|
244
|
+
if (auth.selected !== undefined) {
|
|
245
|
+
selectedAuth = auth.options[auth.selected];
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
for (const a of selectedAuth) {
|
|
249
|
+
// Bearer Auth
|
|
250
|
+
if (a.type === "http" && a.scheme === "bearer") {
|
|
251
|
+
const { token } = auth.data[a.key];
|
|
252
|
+
if (token === undefined) {
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
otherHeaders.push({
|
|
256
|
+
key: "Authorization",
|
|
257
|
+
value: `Bearer ${token}`,
|
|
258
|
+
});
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Basic Auth
|
|
263
|
+
if (a.type === "http" && a.scheme === "basic") {
|
|
264
|
+
const { username, password } = auth.data[a.key];
|
|
265
|
+
if (username === undefined || password === undefined) {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
otherHeaders.push({
|
|
269
|
+
key: "Authorization",
|
|
270
|
+
value: `Basic ${window.btoa(`${username}:${password}`)}`,
|
|
271
|
+
});
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// API Key
|
|
276
|
+
if (a.type === "apiKey" && a.in === "header") {
|
|
277
|
+
const { apikey } = auth.data[a.key];
|
|
278
|
+
if (apikey === undefined) {
|
|
279
|
+
otherHeaders.push({
|
|
280
|
+
key: a.name,
|
|
281
|
+
value: "API_KEY_VALUE",
|
|
282
|
+
});
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
otherHeaders.push({
|
|
286
|
+
key: a.name,
|
|
287
|
+
value: apikey,
|
|
288
|
+
});
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
setHeaders(
|
|
294
|
+
clonedPostman,
|
|
295
|
+
contentType,
|
|
296
|
+
accept,
|
|
297
|
+
cookie,
|
|
298
|
+
headerParams,
|
|
299
|
+
otherHeaders
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
setBody(clonedPostman, body);
|
|
303
|
+
|
|
304
|
+
return clonedPostman;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export default buildPostmanRequest;
|
|
@@ -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
|
+
|
|
8
|
+
import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux";
|
|
9
|
+
|
|
10
|
+
import type { RootState, AppDispatch } from "./store";
|
|
11
|
+
|
|
12
|
+
export const useTypedDispatch = () => useDispatch<AppDispatch>();
|
|
13
|
+
export const useTypedSelector: TypedUseSelectorHook<RootState> = useSelector;
|
|
@@ -0,0 +1,118 @@
|
|
|
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 React from "react";
|
|
9
|
+
|
|
10
|
+
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
import sdk from "@paloaltonetworks/postman-collection";
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
import { Metadata } from "@theme/ApiItem";
|
|
16
|
+
import { ParameterObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
|
|
17
|
+
import { Provider } from "react-redux";
|
|
18
|
+
|
|
19
|
+
import { ThemeConfig } from "../../types";
|
|
20
|
+
import Accept from "./Accept";
|
|
21
|
+
import { createAuth } from "./Authorization/slice";
|
|
22
|
+
import Body from "./Body";
|
|
23
|
+
import Curl from "./Curl";
|
|
24
|
+
import MethodEndpoint from "./MethodEndpoint";
|
|
25
|
+
import ParamOptions from "./ParamOptions";
|
|
26
|
+
import { createPersistanceMiddleware } from "./persistanceMiddleware";
|
|
27
|
+
import Response from "./Response";
|
|
28
|
+
import SecuritySchemes from "./SecuritySchemes";
|
|
29
|
+
import Server from "./Server";
|
|
30
|
+
import { createStoreWithState } from "./store";
|
|
31
|
+
import styles from "./styles.module.css";
|
|
32
|
+
|
|
33
|
+
function ApiDemoPanel({ item }: { item: NonNullable<Metadata["api"]> }) {
|
|
34
|
+
const { siteConfig } = useDocusaurusContext();
|
|
35
|
+
const themeConfig = siteConfig.themeConfig as ThemeConfig;
|
|
36
|
+
const options = themeConfig.api;
|
|
37
|
+
const postman = new sdk.Request(item.postman);
|
|
38
|
+
|
|
39
|
+
const acceptArray = Array.from(
|
|
40
|
+
new Set(
|
|
41
|
+
Object.values(item.responses ?? {})
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
.map((response) => Object.keys(response.content ?? {}))
|
|
44
|
+
.flat()
|
|
45
|
+
)
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const content = item.requestBody?.content ?? {};
|
|
49
|
+
|
|
50
|
+
const contentTypeArray = Object.keys(content);
|
|
51
|
+
|
|
52
|
+
const servers = item.servers ?? [];
|
|
53
|
+
|
|
54
|
+
const params = {
|
|
55
|
+
path: [] as ParameterObject[],
|
|
56
|
+
query: [] as ParameterObject[],
|
|
57
|
+
header: [] as ParameterObject[],
|
|
58
|
+
cookie: [] as ParameterObject[],
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
item.parameters?.forEach((param: { in: string | number }) => {
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
params[param.in].push(param);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const auth = createAuth({
|
|
67
|
+
security: item.security,
|
|
68
|
+
securitySchemes: item.securitySchemes,
|
|
69
|
+
options,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const persistanceMiddleware = createPersistanceMiddleware(options);
|
|
73
|
+
|
|
74
|
+
const store2 = createStoreWithState(
|
|
75
|
+
{
|
|
76
|
+
accept: { value: acceptArray[0], options: acceptArray },
|
|
77
|
+
contentType: { value: contentTypeArray[0], options: contentTypeArray },
|
|
78
|
+
server: { value: servers[0], options: servers },
|
|
79
|
+
response: { value: undefined },
|
|
80
|
+
body: { type: "empty" },
|
|
81
|
+
params,
|
|
82
|
+
auth,
|
|
83
|
+
},
|
|
84
|
+
[persistanceMiddleware]
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const { path, method } = item;
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<Provider store={store2}>
|
|
91
|
+
<div className={styles.apiDemoPanelContainer}>
|
|
92
|
+
<MethodEndpoint method={method} path={path} />
|
|
93
|
+
|
|
94
|
+
<SecuritySchemes />
|
|
95
|
+
|
|
96
|
+
<div className={styles.optionsPanel}>
|
|
97
|
+
<ParamOptions />
|
|
98
|
+
<Body
|
|
99
|
+
jsonRequestBodyExample={item.jsonRequestBodyExample}
|
|
100
|
+
requestBodyMetadata={item.requestBody}
|
|
101
|
+
/>
|
|
102
|
+
<Accept />
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<Server />
|
|
106
|
+
|
|
107
|
+
<Curl
|
|
108
|
+
postman={postman}
|
|
109
|
+
codeSamples={(item as any)["x-code-samples"] ?? []}
|
|
110
|
+
/>
|
|
111
|
+
|
|
112
|
+
<Response />
|
|
113
|
+
</div>
|
|
114
|
+
</Provider>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export default ApiDemoPanel;
|
|
@@ -0,0 +1,46 @@
|
|
|
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 { Middleware } from "@reduxjs/toolkit";
|
|
9
|
+
|
|
10
|
+
import { ThemeConfig } from "../../types";
|
|
11
|
+
import { setAuthData, setSelectedAuth } from "./Authorization/slice";
|
|
12
|
+
import { createStorage, hashArray } from "./storage-utils";
|
|
13
|
+
import { AppDispatch, RootState } from "./store";
|
|
14
|
+
|
|
15
|
+
export function createPersistanceMiddleware(options: ThemeConfig["api"]) {
|
|
16
|
+
const persistanceMiddleware: Middleware<{}, RootState, AppDispatch> =
|
|
17
|
+
(storeAPI) => (next) => (action) => {
|
|
18
|
+
const result = next(action);
|
|
19
|
+
|
|
20
|
+
const state = storeAPI.getState();
|
|
21
|
+
|
|
22
|
+
const storage = createStorage(options?.authPersistance);
|
|
23
|
+
|
|
24
|
+
if (action.type === setAuthData.type) {
|
|
25
|
+
for (const [key, value] of Object.entries(state.auth.data)) {
|
|
26
|
+
if (Object.values(value).filter(Boolean).length > 0) {
|
|
27
|
+
storage.setItem(key, JSON.stringify(value));
|
|
28
|
+
} else {
|
|
29
|
+
storage.removeItem(key);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (action.type === setSelectedAuth.type) {
|
|
35
|
+
if (state.auth.selected) {
|
|
36
|
+
storage.setItem(
|
|
37
|
+
hashArray(Object.keys(state.auth.options)),
|
|
38
|
+
state.auth.selected
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
return persistanceMiddleware;
|
|
46
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
declare module "@paloaltonetworks/postman-collection" {
|
|
9
|
+
export = Request.sdk;
|
|
10
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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 crypto from "crypto-js";
|
|
9
|
+
|
|
10
|
+
export function hashArray(arr: string[]) {
|
|
11
|
+
function hash(message: string) {
|
|
12
|
+
return crypto.SHA1(message).toString();
|
|
13
|
+
}
|
|
14
|
+
const hashed = arr.map((item) => hash(item));
|
|
15
|
+
hashed.sort();
|
|
16
|
+
const res = hashed.join();
|
|
17
|
+
return hash(res);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type Persistance = false | "localStorage" | "sessionStorage" | undefined;
|
|
21
|
+
|
|
22
|
+
export function createStorage(persistance: Persistance): Storage {
|
|
23
|
+
if (persistance === false) {
|
|
24
|
+
return {
|
|
25
|
+
getItem: () => null,
|
|
26
|
+
setItem: () => {},
|
|
27
|
+
clear: () => {},
|
|
28
|
+
key: () => null,
|
|
29
|
+
removeItem: () => {},
|
|
30
|
+
length: 0,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (persistance === "sessionStorage") {
|
|
35
|
+
return sessionStorage;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return localStorage;
|
|
39
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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 { configureStore, combineReducers } from "@reduxjs/toolkit";
|
|
9
|
+
|
|
10
|
+
import accept from "./Accept/slice";
|
|
11
|
+
import auth from "./Authorization/slice";
|
|
12
|
+
import body from "./Body/slice";
|
|
13
|
+
import contentType from "./ContentType/slice";
|
|
14
|
+
import params from "./ParamOptions/slice";
|
|
15
|
+
import response from "./Response/slice";
|
|
16
|
+
import server from "./Server/slice";
|
|
17
|
+
|
|
18
|
+
const rootReducer = combineReducers({
|
|
19
|
+
accept,
|
|
20
|
+
contentType,
|
|
21
|
+
response,
|
|
22
|
+
server,
|
|
23
|
+
body,
|
|
24
|
+
params,
|
|
25
|
+
auth,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export type RootState = ReturnType<typeof rootReducer>;
|
|
29
|
+
|
|
30
|
+
export const createStoreWithState = (
|
|
31
|
+
preloadedState: RootState,
|
|
32
|
+
middlewares: any[]
|
|
33
|
+
) =>
|
|
34
|
+
configureStore({
|
|
35
|
+
reducer: rootReducer,
|
|
36
|
+
preloadedState,
|
|
37
|
+
middleware: (getDefaultMiddleware) =>
|
|
38
|
+
getDefaultMiddleware().concat(...middlewares),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export type AppDispatch = ReturnType<typeof createStoreWithState>["dispatch"];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
/* VS Dark mode */
|
|
3
|
+
--openapi-monaco-background-color-dark: var(--ifm-color-gray-900);
|
|
4
|
+
--openapi-code-bright-dark: var(--ifm-color-secondary-lighter);
|
|
5
|
+
--openapi-code-dim-dark: var(--ifm-color-secondary-dark);
|
|
6
|
+
--openapi-code-blue-dark: var(--ifm-color-primary);
|
|
7
|
+
--openapi-code-green-dark: var(--ifm-color-success);
|
|
8
|
+
--openapi-code-select-dark: var(--ifm-color-secondary-lightest);
|
|
9
|
+
|
|
10
|
+
/* VS Light mode */
|
|
11
|
+
--openapi-monaco-background-color-light: var(--ifm-color-gray-100);
|
|
12
|
+
--openapi-code-bright-light: var(--ifm-color-black);
|
|
13
|
+
--openapi-code-dim-light: var(--ifm-color-black);
|
|
14
|
+
--openapi-code-blue-light: var(--ifm-color-primary);
|
|
15
|
+
--openapi-code-green-light: var(--ifm-color-success);
|
|
16
|
+
--openapi-code-select-light: var(--ifm-color-secondary-light);
|
|
17
|
+
|
|
18
|
+
--openapi-card-background-color: var(--ifm-color-gray-100);
|
|
19
|
+
--openapi-card-border-radius: var(--ifm-pre-border-radius);
|
|
20
|
+
--openapi-monaco-border-color: var(--openapi-card-background-color);
|
|
21
|
+
--openapi-input-border: var(--ifm-color-primary);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
[data-theme="dark"] {
|
|
25
|
+
--openapi-card-background-color: var(--ifm-color-gray-900) !important;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.optionsPanel:empty {
|
|
29
|
+
display: none;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.optionsPanel {
|
|
33
|
+
background: var(--openapi-card-background-color);
|
|
34
|
+
border-radius: var(--openapi-card-border-radius);
|
|
35
|
+
color: var(--ifm-pre-color);
|
|
36
|
+
line-height: var(--ifm-pre-line-height);
|
|
37
|
+
margin-bottom: var(--ifm-spacing-vertical);
|
|
38
|
+
margin-top: 0;
|
|
39
|
+
overflow: auto;
|
|
40
|
+
padding: var(--ifm-pre-padding);
|
|
41
|
+
|
|
42
|
+
/* hack for view calculation when monaco is hidden */
|
|
43
|
+
position: relative;
|
|
44
|
+
}
|