docusaurus-theme-openapi-docs 0.0.0-346 → 0.0.0-350

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.
@@ -1,200 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- /* ============================================================================
9
- * Copyright (c) Palo Alto Networks
10
- *
11
- * This source code is licensed under the MIT license found in the
12
- * LICENSE file in the root directory of this source tree.
13
- * ========================================================================== */
14
- async function loadImage(content) {
15
- return new Promise((accept, reject) => {
16
- const reader = new FileReader();
17
-
18
- reader.onabort = () => {
19
- console.log("file reading was aborted");
20
- reject();
21
- };
22
-
23
- reader.onerror = () => {
24
- console.log("file reading has failed");
25
- reject();
26
- };
27
-
28
- reader.onload = () => {
29
- // Do whatever you want with the file contents
30
- const binaryStr = reader.result;
31
- accept(binaryStr);
32
- };
33
-
34
- reader.readAsArrayBuffer(content);
35
- });
36
- }
37
-
38
- async function makeRequest(request, proxy, _body) {
39
- var _request$body;
40
-
41
- const headers = request.toJSON().header;
42
- let myHeaders = new Headers();
43
-
44
- if (headers) {
45
- headers.forEach(header => {
46
- if (header.key && header.value) {
47
- myHeaders.append(header.key, header.value);
48
- }
49
- });
50
- } // The following code handles multiple files in the same formdata param.
51
- // It removes the form data params where the src property is an array of filepath strings
52
- // Splits that array into different form data params with src set as a single filepath string
53
- // TODO:
54
- // if (request.body && request.body.mode === 'formdata') {
55
- // let formdata = request.body.formdata,
56
- // formdataArray = [];
57
- // formdata.members.forEach((param) => {
58
- // let key = param.key,
59
- // type = param.type,
60
- // disabled = param.disabled,
61
- // contentType = param.contentType;
62
- // // check if type is file or text
63
- // if (type === 'file') {
64
- // // if src is not of type string we check for array(multiple files)
65
- // if (typeof param.src !== 'string') {
66
- // // if src is an array(not empty), iterate over it and add files as separate form fields
67
- // if (Array.isArray(param.src) && param.src.length) {
68
- // param.src.forEach((filePath) => {
69
- // addFormParam(
70
- // formdataArray,
71
- // key,
72
- // param.type,
73
- // filePath,
74
- // disabled,
75
- // contentType
76
- // );
77
- // });
78
- // }
79
- // // if src is not an array or string, or is an empty array, add a placeholder for file path(no files case)
80
- // else {
81
- // addFormParam(
82
- // formdataArray,
83
- // key,
84
- // param.type,
85
- // '/path/to/file',
86
- // disabled,
87
- // contentType
88
- // );
89
- // }
90
- // }
91
- // // if src is string, directly add the param with src as filepath
92
- // else {
93
- // addFormParam(
94
- // formdataArray,
95
- // key,
96
- // param.type,
97
- // param.src,
98
- // disabled,
99
- // contentType
100
- // );
101
- // }
102
- // }
103
- // // if type is text, directly add it to formdata array
104
- // else {
105
- // addFormParam(
106
- // formdataArray,
107
- // key,
108
- // param.type,
109
- // param.value,
110
- // disabled,
111
- // contentType
112
- // );
113
- // }
114
- // });
115
- // request.body.update({
116
- // mode: 'formdata',
117
- // formdata: formdataArray,
118
- // });
119
- // }
120
-
121
-
122
- const body = (_request$body = request.body) === null || _request$body === void 0 ? void 0 : _request$body.toJSON();
123
- let myBody = undefined;
124
-
125
- if (body !== undefined && Object.keys(body).length > 0) {
126
- switch (body.mode) {
127
- case "urlencoded":
128
- {
129
- myBody = new URLSearchParams();
130
-
131
- if (Array.isArray(body.urlencoded)) {
132
- for (const data of body.urlencoded) {
133
- if (data.key && data.value) {
134
- myBody.append(data.key, data.value);
135
- }
136
- }
137
- }
138
-
139
- break;
140
- }
141
-
142
- case "raw":
143
- {
144
- var _body$raw;
145
-
146
- myBody = ((_body$raw = body.raw) !== null && _body$raw !== void 0 ? _body$raw : "").toString();
147
- break;
148
- }
149
-
150
- case "formdata":
151
- {
152
- myBody = new FormData();
153
-
154
- if (Array.isArray(body.formdata)) {
155
- for (const data of body.formdata) {
156
- if (data.key && data.value) {
157
- myBody.append(data.key, data.value);
158
- }
159
- }
160
- }
161
-
162
- break;
163
- }
164
-
165
- case "file":
166
- {
167
- var _body$content;
168
-
169
- if (_body.type === "raw" && ((_body$content = _body.content) === null || _body$content === void 0 ? void 0 : _body$content.type) === "file") {
170
- myBody = await loadImage(_body.content.value.content);
171
- }
172
-
173
- break;
174
- }
175
-
176
- default:
177
- break;
178
- }
179
- }
180
-
181
- const requestOptions = {
182
- method: request.method,
183
- headers: myHeaders,
184
- body: myBody
185
- };
186
- let finalUrl = request.url.toString();
187
-
188
- if (proxy) {
189
- // Ensure the proxy ends with a slash.
190
- let normalizedProxy = proxy.replace(/\/$/, "") + "/";
191
- finalUrl = normalizedProxy + request.url.toString();
192
- }
193
-
194
- return await fetch(finalUrl, requestOptions).then(response => {
195
- return response.text();
196
- });
197
- }
198
-
199
- var _default = makeRequest;
200
- exports.default = _default;
@@ -1,203 +0,0 @@
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;
@@ -1,73 +0,0 @@
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 { setResponse } from "../Response/slice";
10
- import buildPostmanRequest from "./../buildPostmanRequest";
11
- import makeRequest from "./makeRequest";
12
-
13
- function validateRequest(params) {
14
- for (let paramList of Object.values(params)) {
15
- for (let param of paramList) {
16
- if (param.required && !param.value) {
17
- return false;
18
- }
19
- }
20
- }
21
-
22
- return true;
23
- }
24
-
25
- function Execute({ postman, proxy }) {
26
- const pathParams = useTypedSelector((state) => state.params.path);
27
- const queryParams = useTypedSelector((state) => state.params.query);
28
- const cookieParams = useTypedSelector((state) => state.params.cookie);
29
- const headerParams = useTypedSelector((state) => state.params.header);
30
- const contentType = useTypedSelector((state) => state.contentType.value);
31
- const body = useTypedSelector((state) => state.body);
32
- const accept = useTypedSelector((state) => state.accept.value);
33
- const server = useTypedSelector((state) => state.server.value);
34
- const params = useTypedSelector((state) => state.params);
35
- const auth = useTypedSelector((state) => state.auth);
36
- const isValidRequest = validateRequest(params);
37
- const dispatch = useTypedDispatch();
38
- const postmanRequest = buildPostmanRequest(postman, {
39
- queryParams,
40
- pathParams,
41
- cookieParams,
42
- contentType,
43
- accept,
44
- headerParams,
45
- body,
46
- server,
47
- auth,
48
- });
49
- return (
50
- <button
51
- className="button button--block button--primary"
52
- style={{
53
- height: "48px",
54
- marginBottom: "var(--ifm-spacing-vertical)",
55
- }}
56
- disabled={!isValidRequest}
57
- onClick={async () => {
58
- dispatch(setResponse("loading..."));
59
-
60
- try {
61
- const res = await makeRequest(postmanRequest, proxy, body);
62
- dispatch(setResponse(res));
63
- } catch (e) {
64
- dispatch(setResponse(e.message ?? "Error fetching."));
65
- }
66
- }}
67
- >
68
- Execute
69
- </button>
70
- );
71
- }
72
-
73
- export default Execute;
@@ -1,181 +0,0 @@
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
- async function loadImage(content) {
8
- return new Promise((accept, reject) => {
9
- const reader = new FileReader();
10
-
11
- reader.onabort = () => {
12
- console.log("file reading was aborted");
13
- reject();
14
- };
15
-
16
- reader.onerror = () => {
17
- console.log("file reading has failed");
18
- reject();
19
- };
20
-
21
- reader.onload = () => {
22
- // Do whatever you want with the file contents
23
- const binaryStr = reader.result;
24
- accept(binaryStr);
25
- };
26
-
27
- reader.readAsArrayBuffer(content);
28
- });
29
- }
30
-
31
- async function makeRequest(request, proxy, _body) {
32
- const headers = request.toJSON().header;
33
- let myHeaders = new Headers();
34
-
35
- if (headers) {
36
- headers.forEach((header) => {
37
- if (header.key && header.value) {
38
- myHeaders.append(header.key, header.value);
39
- }
40
- });
41
- } // The following code handles multiple files in the same formdata param.
42
- // It removes the form data params where the src property is an array of filepath strings
43
- // Splits that array into different form data params with src set as a single filepath string
44
- // TODO:
45
- // if (request.body && request.body.mode === 'formdata') {
46
- // let formdata = request.body.formdata,
47
- // formdataArray = [];
48
- // formdata.members.forEach((param) => {
49
- // let key = param.key,
50
- // type = param.type,
51
- // disabled = param.disabled,
52
- // contentType = param.contentType;
53
- // // check if type is file or text
54
- // if (type === 'file') {
55
- // // if src is not of type string we check for array(multiple files)
56
- // if (typeof param.src !== 'string') {
57
- // // if src is an array(not empty), iterate over it and add files as separate form fields
58
- // if (Array.isArray(param.src) && param.src.length) {
59
- // param.src.forEach((filePath) => {
60
- // addFormParam(
61
- // formdataArray,
62
- // key,
63
- // param.type,
64
- // filePath,
65
- // disabled,
66
- // contentType
67
- // );
68
- // });
69
- // }
70
- // // if src is not an array or string, or is an empty array, add a placeholder for file path(no files case)
71
- // else {
72
- // addFormParam(
73
- // formdataArray,
74
- // key,
75
- // param.type,
76
- // '/path/to/file',
77
- // disabled,
78
- // contentType
79
- // );
80
- // }
81
- // }
82
- // // if src is string, directly add the param with src as filepath
83
- // else {
84
- // addFormParam(
85
- // formdataArray,
86
- // key,
87
- // param.type,
88
- // param.src,
89
- // disabled,
90
- // contentType
91
- // );
92
- // }
93
- // }
94
- // // if type is text, directly add it to formdata array
95
- // else {
96
- // addFormParam(
97
- // formdataArray,
98
- // key,
99
- // param.type,
100
- // param.value,
101
- // disabled,
102
- // contentType
103
- // );
104
- // }
105
- // });
106
- // request.body.update({
107
- // mode: 'formdata',
108
- // formdata: formdataArray,
109
- // });
110
- // }
111
-
112
- const body = request.body?.toJSON();
113
- let myBody = undefined;
114
-
115
- if (body !== undefined && Object.keys(body).length > 0) {
116
- switch (body.mode) {
117
- case "urlencoded": {
118
- myBody = new URLSearchParams();
119
-
120
- if (Array.isArray(body.urlencoded)) {
121
- for (const data of body.urlencoded) {
122
- if (data.key && data.value) {
123
- myBody.append(data.key, data.value);
124
- }
125
- }
126
- }
127
-
128
- break;
129
- }
130
-
131
- case "raw": {
132
- myBody = (body.raw ?? "").toString();
133
- break;
134
- }
135
-
136
- case "formdata": {
137
- myBody = new FormData();
138
-
139
- if (Array.isArray(body.formdata)) {
140
- for (const data of body.formdata) {
141
- if (data.key && data.value) {
142
- myBody.append(data.key, data.value);
143
- }
144
- }
145
- }
146
-
147
- break;
148
- }
149
-
150
- case "file": {
151
- if (_body.type === "raw" && _body.content?.type === "file") {
152
- myBody = await loadImage(_body.content.value.content);
153
- }
154
-
155
- break;
156
- }
157
-
158
- default:
159
- break;
160
- }
161
- }
162
-
163
- const requestOptions = {
164
- method: request.method,
165
- headers: myHeaders,
166
- body: myBody,
167
- };
168
- let finalUrl = request.url.toString();
169
-
170
- if (proxy) {
171
- // Ensure the proxy ends with a slash.
172
- let normalizedProxy = proxy.replace(/\/$/, "") + "/";
173
- finalUrl = normalizedProxy + request.url.toString();
174
- }
175
-
176
- return await fetch(finalUrl, requestOptions).then((response) => {
177
- return response.text();
178
- });
179
- }
180
-
181
- export default makeRequest;