docusaurus-theme-openapi-docs 1.0.1 → 1.0.2

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