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,101 @@
|
|
|
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
|
+
import { createStorage, hashArray } from "../storage-utils";
|
|
9
|
+
import { getAuthDataKeys } from "./auth-types"; // The global definitions
|
|
10
|
+
// "securitySchemes": {
|
|
11
|
+
// "BearerAuth": { "type": "http", "scheme": "BeAreR" },
|
|
12
|
+
// "BasicAuth": { "type": "http", "scheme": "basic" }
|
|
13
|
+
// },
|
|
14
|
+
// The operation level requirements
|
|
15
|
+
// "security": [
|
|
16
|
+
// { "BearerAuth": [] },
|
|
17
|
+
// { "BearerAuth": [], "BasicAuth": [] }
|
|
18
|
+
// ],
|
|
19
|
+
// SLICE_STATE
|
|
20
|
+
// data:
|
|
21
|
+
// BearerAuth:
|
|
22
|
+
// token=xxx
|
|
23
|
+
// BasicAuth:
|
|
24
|
+
// username=xxx
|
|
25
|
+
// password=xxx
|
|
26
|
+
//
|
|
27
|
+
// options:
|
|
28
|
+
// "BearerAuth": [{ key: "BearerAuth", scopes: [], ...rest }]
|
|
29
|
+
// "BearerAuth and BasicAuth": [{ key: "BearerAuth", scopes: [], ...rest }, { key: "BasicAuth", scopes: [], ...rest }]
|
|
30
|
+
//
|
|
31
|
+
// selected: "BearerAuth and BasicAuth"
|
|
32
|
+
// LOCAL_STORAGE
|
|
33
|
+
// hash(SLICE_STATE.options) -> "BearerAuth and BasicAuth"
|
|
34
|
+
// BearerAuth -> { token: xxx }
|
|
35
|
+
// BasicAuth -> { username: xxx, password: xxx }
|
|
36
|
+
|
|
37
|
+
export function createAuth({ security, securitySchemes, options: opts }) {
|
|
38
|
+
const storage = createStorage(opts?.authPersistance);
|
|
39
|
+
let data = {};
|
|
40
|
+
let options = {};
|
|
41
|
+
|
|
42
|
+
for (const option of security ?? []) {
|
|
43
|
+
const id = Object.keys(option).join(" and ");
|
|
44
|
+
|
|
45
|
+
for (const [schemeID, scopes] of Object.entries(option)) {
|
|
46
|
+
const scheme = securitySchemes?.[schemeID];
|
|
47
|
+
|
|
48
|
+
if (scheme) {
|
|
49
|
+
if (options[id] === undefined) {
|
|
50
|
+
options[id] = [];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const dataKeys = getAuthDataKeys(scheme);
|
|
54
|
+
|
|
55
|
+
for (const key of dataKeys) {
|
|
56
|
+
if (data[schemeID] === undefined) {
|
|
57
|
+
data[schemeID] = {};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let persisted = undefined;
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
persisted = JSON.parse(storage.getItem(schemeID) ?? "")[key];
|
|
64
|
+
} catch {}
|
|
65
|
+
|
|
66
|
+
data[schemeID][key] = persisted;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
options[id].push({ ...scheme, key: schemeID, scopes });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let persisted = undefined;
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
persisted = storage.getItem(hashArray(Object.keys(options))) ?? undefined;
|
|
78
|
+
} catch {}
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
data,
|
|
82
|
+
options,
|
|
83
|
+
selected: persisted ?? Object.keys(options)[0],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const initialState = {};
|
|
87
|
+
export const slice = createSlice({
|
|
88
|
+
name: "auth",
|
|
89
|
+
initialState,
|
|
90
|
+
reducers: {
|
|
91
|
+
setAuthData: (state, action) => {
|
|
92
|
+
const { scheme, key, value } = action.payload;
|
|
93
|
+
state.data[scheme][key] = value;
|
|
94
|
+
},
|
|
95
|
+
setSelectedAuth: (state, action) => {
|
|
96
|
+
state.selected = action.payload;
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
export const { setAuthData, setSelectedAuth } = slice.actions;
|
|
101
|
+
export default slice.reducer;
|
|
@@ -0,0 +1,210 @@
|
|
|
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 ContentType from "../ContentType";
|
|
9
|
+
import FormSelect from "../FormSelect";
|
|
10
|
+
import { useTypedDispatch, useTypedSelector } from "../hooks";
|
|
11
|
+
import FormFileUpload from "./../FormFileUpload";
|
|
12
|
+
import FormItem from "./../FormItem";
|
|
13
|
+
import FormTextInput from "./../FormTextInput";
|
|
14
|
+
import VSCode from "./../VSCode";
|
|
15
|
+
import {
|
|
16
|
+
clearFormBodyKey,
|
|
17
|
+
clearRawBody,
|
|
18
|
+
setFileFormBody,
|
|
19
|
+
setFileRawBody,
|
|
20
|
+
setStringFormBody,
|
|
21
|
+
setStringRawBody,
|
|
22
|
+
} from "./slice";
|
|
23
|
+
|
|
24
|
+
function BodyWrap({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
25
|
+
const contentType = useTypedSelector((state) => state.contentType.value); // NOTE: We used to check if body was required, but opted to always show the request body
|
|
26
|
+
// to reduce confusion, see: https://github.com/cloud-annotations/docusaurus-openapi/issues/145
|
|
27
|
+
// No body
|
|
28
|
+
|
|
29
|
+
if (contentType === undefined) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<>
|
|
35
|
+
<ContentType />
|
|
36
|
+
<Body
|
|
37
|
+
requestBodyMetadata={requestBodyMetadata}
|
|
38
|
+
jsonRequestBodyExample={jsonRequestBodyExample}
|
|
39
|
+
/>
|
|
40
|
+
</>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function Body({ requestBodyMetadata, jsonRequestBodyExample }) {
|
|
45
|
+
const contentType = useTypedSelector((state) => state.contentType.value);
|
|
46
|
+
const dispatch = useTypedDispatch(); // Lot's of possible content-types:
|
|
47
|
+
// - application/json
|
|
48
|
+
// - application/xml
|
|
49
|
+
// - text/plain
|
|
50
|
+
// - text/css
|
|
51
|
+
// - text/html
|
|
52
|
+
// - text/javascript
|
|
53
|
+
// - application/javascript
|
|
54
|
+
// - multipart/form-data
|
|
55
|
+
// - application/x-www-form-urlencoded
|
|
56
|
+
// - image/svg+xml;charset=US-ASCII
|
|
57
|
+
// Show editor:
|
|
58
|
+
// - application/json
|
|
59
|
+
// - application/xml
|
|
60
|
+
// - */*
|
|
61
|
+
// Show form:
|
|
62
|
+
// - multipart/form-data
|
|
63
|
+
// - application/x-www-form-urlencoded
|
|
64
|
+
|
|
65
|
+
const schema = requestBodyMetadata?.content?.[contentType]?.schema;
|
|
66
|
+
|
|
67
|
+
if (schema?.format === "binary") {
|
|
68
|
+
return (
|
|
69
|
+
<FormItem label="Body">
|
|
70
|
+
<FormFileUpload
|
|
71
|
+
placeholder={schema.description || "Body"}
|
|
72
|
+
onChange={(file) => {
|
|
73
|
+
if (file === undefined) {
|
|
74
|
+
dispatch(clearRawBody());
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
dispatch(
|
|
79
|
+
setFileRawBody({
|
|
80
|
+
src: `/path/to/${file.name}`,
|
|
81
|
+
content: file,
|
|
82
|
+
})
|
|
83
|
+
);
|
|
84
|
+
}}
|
|
85
|
+
/>
|
|
86
|
+
</FormItem>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (
|
|
91
|
+
(contentType === "multipart/form-data" ||
|
|
92
|
+
contentType === "application/x-www-form-urlencoded") &&
|
|
93
|
+
schema?.type === "object"
|
|
94
|
+
) {
|
|
95
|
+
return (
|
|
96
|
+
<FormItem label="Body">
|
|
97
|
+
<div
|
|
98
|
+
style={{
|
|
99
|
+
marginTop: "calc(var(--ifm-pre-padding) / 2)",
|
|
100
|
+
borderRadius: "4px",
|
|
101
|
+
padding: "var(--ifm-pre-padding)",
|
|
102
|
+
border: "1px solid var(--openapi-monaco-border-color)",
|
|
103
|
+
}}
|
|
104
|
+
>
|
|
105
|
+
{Object.entries(schema.properties ?? {}).map(([key, val]) => {
|
|
106
|
+
if (val.format === "binary") {
|
|
107
|
+
return (
|
|
108
|
+
<FormItem key={key} label={key}>
|
|
109
|
+
<FormFileUpload
|
|
110
|
+
placeholder={val.description || key}
|
|
111
|
+
onChange={(file) => {
|
|
112
|
+
if (file === undefined) {
|
|
113
|
+
dispatch(clearFormBodyKey(key));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
dispatch(
|
|
118
|
+
setFileFormBody({
|
|
119
|
+
key: key,
|
|
120
|
+
value: {
|
|
121
|
+
src: `/path/to/${file.name}`,
|
|
122
|
+
content: file,
|
|
123
|
+
},
|
|
124
|
+
})
|
|
125
|
+
);
|
|
126
|
+
}}
|
|
127
|
+
/>
|
|
128
|
+
</FormItem>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (val.enum) {
|
|
133
|
+
return (
|
|
134
|
+
<FormItem key={key} label={key}>
|
|
135
|
+
<FormSelect
|
|
136
|
+
options={["---", ...val.enum]}
|
|
137
|
+
onChange={(e) => {
|
|
138
|
+
const val = e.target.value;
|
|
139
|
+
|
|
140
|
+
if (val === "---") {
|
|
141
|
+
dispatch(clearFormBodyKey(key));
|
|
142
|
+
} else {
|
|
143
|
+
dispatch(
|
|
144
|
+
setStringFormBody({
|
|
145
|
+
key: key,
|
|
146
|
+
value: val,
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
}}
|
|
151
|
+
/>
|
|
152
|
+
</FormItem>
|
|
153
|
+
);
|
|
154
|
+
} // TODO: support all the other types.
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<FormItem key={key} label={key}>
|
|
158
|
+
<FormTextInput
|
|
159
|
+
placeholder={val.description || key}
|
|
160
|
+
onChange={(e) => {
|
|
161
|
+
dispatch(
|
|
162
|
+
setStringFormBody({
|
|
163
|
+
key: key,
|
|
164
|
+
value: e.target.value,
|
|
165
|
+
})
|
|
166
|
+
);
|
|
167
|
+
}}
|
|
168
|
+
/>
|
|
169
|
+
</FormItem>
|
|
170
|
+
);
|
|
171
|
+
})}
|
|
172
|
+
</div>
|
|
173
|
+
</FormItem>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
let language = "plaintext";
|
|
178
|
+
let exampleBodyString = ""; //"body content";
|
|
179
|
+
|
|
180
|
+
if (contentType === "application/json") {
|
|
181
|
+
if (jsonRequestBodyExample) {
|
|
182
|
+
exampleBodyString = JSON.stringify(jsonRequestBodyExample, null, 2);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
language = "json";
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (contentType === "application/xml") {
|
|
189
|
+
language = "xml";
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<FormItem label="Body">
|
|
194
|
+
<VSCode
|
|
195
|
+
value={exampleBodyString}
|
|
196
|
+
language={language}
|
|
197
|
+
onChange={(value) => {
|
|
198
|
+
if (value.trim() === "") {
|
|
199
|
+
dispatch(clearRawBody());
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
dispatch(setStringRawBody(value));
|
|
204
|
+
}}
|
|
205
|
+
/>
|
|
206
|
+
</FormItem>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export default BodyWrap;
|
|
@@ -0,0 +1,89 @@
|
|
|
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: "body",
|
|
11
|
+
initialState,
|
|
12
|
+
reducers: {
|
|
13
|
+
clearRawBody: (_state) => {
|
|
14
|
+
return {
|
|
15
|
+
type: "empty",
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
setStringRawBody: (_state, action) => {
|
|
19
|
+
return {
|
|
20
|
+
type: "raw",
|
|
21
|
+
content: {
|
|
22
|
+
type: "string",
|
|
23
|
+
value: action.payload,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
setFileRawBody: (_state, action) => {
|
|
28
|
+
return {
|
|
29
|
+
type: "raw",
|
|
30
|
+
content: {
|
|
31
|
+
type: "file",
|
|
32
|
+
value: action.payload,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
clearFormBodyKey: (state, action) => {
|
|
37
|
+
if (state?.type === "form") {
|
|
38
|
+
delete state.content[action.payload];
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
setStringFormBody: (state, action) => {
|
|
42
|
+
if (state?.type !== "form") {
|
|
43
|
+
return {
|
|
44
|
+
type: "form",
|
|
45
|
+
content: {
|
|
46
|
+
[action.payload.key]: {
|
|
47
|
+
type: "string",
|
|
48
|
+
value: action.payload.value,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
state.content[action.payload.key] = {
|
|
55
|
+
type: "string",
|
|
56
|
+
value: action.payload.value,
|
|
57
|
+
};
|
|
58
|
+
return state;
|
|
59
|
+
},
|
|
60
|
+
setFileFormBody: (state, action) => {
|
|
61
|
+
if (state?.type !== "form") {
|
|
62
|
+
return {
|
|
63
|
+
type: "form",
|
|
64
|
+
content: {
|
|
65
|
+
[action.payload.key]: {
|
|
66
|
+
type: "file",
|
|
67
|
+
value: action.payload.value,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
state.content[action.payload.key] = {
|
|
74
|
+
type: "file",
|
|
75
|
+
value: action.payload.value,
|
|
76
|
+
};
|
|
77
|
+
return state;
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
export const {
|
|
82
|
+
clearRawBody,
|
|
83
|
+
setStringRawBody,
|
|
84
|
+
setFileRawBody,
|
|
85
|
+
clearFormBodyKey,
|
|
86
|
+
setStringFormBody,
|
|
87
|
+
setFileFormBody,
|
|
88
|
+
} = slice.actions;
|
|
89
|
+
export default slice.reducer;
|
|
@@ -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 { setContentType } from "./slice";
|
|
12
|
+
|
|
13
|
+
function ContentType() {
|
|
14
|
+
const value = useTypedSelector((state) => state.contentType.value);
|
|
15
|
+
const options = useTypedSelector((state) => state.contentType.options);
|
|
16
|
+
const dispatch = useTypedDispatch();
|
|
17
|
+
|
|
18
|
+
if (options.length <= 1) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<FormItem label="Content-Type">
|
|
24
|
+
<FormSelect
|
|
25
|
+
value={value}
|
|
26
|
+
options={options}
|
|
27
|
+
onChange={(e) => dispatch(setContentType(e.target.value))}
|
|
28
|
+
/>
|
|
29
|
+
</FormItem>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default ContentType;
|
|
@@ -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: "contentType",
|
|
11
|
+
initialState,
|
|
12
|
+
reducers: {
|
|
13
|
+
setContentType: (state, action) => {
|
|
14
|
+
state.value = action.payload;
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
export const { setContentType } = slice.actions;
|
|
19
|
+
export default slice.reducer;
|