docusaurus-theme-openapi-docs 4.3.0 → 4.3.1
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.
|
@@ -56,12 +56,6 @@ var __importDefault =
|
|
|
56
56
|
};
|
|
57
57
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
58
58
|
exports.languageSet = void 0;
|
|
59
|
-
/* ============================================================================
|
|
60
|
-
* Copyright (c) Palo Alto Networks
|
|
61
|
-
*
|
|
62
|
-
* This source code is licensed under the MIT license found in the
|
|
63
|
-
* LICENSE file in the root directory of this source tree.
|
|
64
|
-
* ========================================================================== */
|
|
65
59
|
const react_1 = __importStar(require("react"));
|
|
66
60
|
const useDocusaurusContext_1 = __importDefault(
|
|
67
61
|
require("@docusaurus/useDocusaurusContext")
|
|
@@ -74,6 +68,7 @@ const buildPostmanRequest_1 = __importDefault(
|
|
|
74
68
|
);
|
|
75
69
|
const CodeTabs_1 = __importDefault(require("@theme/ApiExplorer/CodeTabs"));
|
|
76
70
|
const hooks_1 = require("@theme/ApiItem/hooks");
|
|
71
|
+
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
77
72
|
const postman_code_generators_1 = __importDefault(
|
|
78
73
|
require("postman-code-generators")
|
|
79
74
|
);
|
|
@@ -107,6 +102,40 @@ function CodeSnippets({ postman, codeSamples }) {
|
|
|
107
102
|
(state) => state.params.header
|
|
108
103
|
);
|
|
109
104
|
const auth = (0, hooks_1.useTypedSelector)((state) => state.auth);
|
|
105
|
+
const clonedAuth = (0, cloneDeep_1.default)(auth);
|
|
106
|
+
let placeholder;
|
|
107
|
+
function cleanCredentials(obj) {
|
|
108
|
+
for (const key in obj) {
|
|
109
|
+
if (typeof obj[key] === "object" && obj[key] !== null) {
|
|
110
|
+
// use name as placeholder if exists
|
|
111
|
+
const comboAuthId = Object.keys(obj).join(" and ");
|
|
112
|
+
const authOptions =
|
|
113
|
+
clonedAuth?.options?.[key] ?? clonedAuth?.options?.[comboAuthId];
|
|
114
|
+
placeholder = authOptions?.[0]?.name;
|
|
115
|
+
obj[key] = cleanCredentials(obj[key]);
|
|
116
|
+
} else {
|
|
117
|
+
obj[key] = `<${placeholder ?? key}>`;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return obj;
|
|
121
|
+
}
|
|
122
|
+
// scrub credentials from code snippets
|
|
123
|
+
const cleanedAuth = {
|
|
124
|
+
...clonedAuth,
|
|
125
|
+
data: cleanCredentials(clonedAuth.data),
|
|
126
|
+
};
|
|
127
|
+
// Create a Postman request object using cleanedAuth
|
|
128
|
+
const cleanedPostmanRequest = (0, buildPostmanRequest_1.default)(postman, {
|
|
129
|
+
queryParams,
|
|
130
|
+
pathParams,
|
|
131
|
+
cookieParams,
|
|
132
|
+
contentType,
|
|
133
|
+
accept,
|
|
134
|
+
headerParams,
|
|
135
|
+
body,
|
|
136
|
+
server,
|
|
137
|
+
auth: cleanedAuth,
|
|
138
|
+
});
|
|
110
139
|
// User-defined languages array
|
|
111
140
|
// Can override languageSet, change order of langs, override options and variants
|
|
112
141
|
const userDefinedLanguageSet =
|
|
@@ -151,21 +180,10 @@ function CodeSnippets({ postman, codeSamples }) {
|
|
|
151
180
|
);
|
|
152
181
|
}
|
|
153
182
|
if (language && !!language.options) {
|
|
154
|
-
const postmanRequest = (0, buildPostmanRequest_1.default)(postman, {
|
|
155
|
-
queryParams,
|
|
156
|
-
pathParams,
|
|
157
|
-
cookieParams,
|
|
158
|
-
contentType,
|
|
159
|
-
accept,
|
|
160
|
-
headerParams,
|
|
161
|
-
body,
|
|
162
|
-
server,
|
|
163
|
-
auth,
|
|
164
|
-
});
|
|
165
183
|
postman_code_generators_1.default.convert(
|
|
166
184
|
language.language,
|
|
167
185
|
language.variant,
|
|
168
|
-
|
|
186
|
+
cleanedPostmanRequest,
|
|
169
187
|
language.options,
|
|
170
188
|
(error, snippet) => {
|
|
171
189
|
if (error) {
|
|
@@ -182,21 +200,10 @@ function CodeSnippets({ postman, codeSamples }) {
|
|
|
182
200
|
// This allows users to define only the minimal properties necessary in languageTabs
|
|
183
201
|
// User-defined properties should override languageSet properties
|
|
184
202
|
const mergedLanguage = { ...langSource[0], ...language };
|
|
185
|
-
const postmanRequest = (0, buildPostmanRequest_1.default)(postman, {
|
|
186
|
-
queryParams,
|
|
187
|
-
pathParams,
|
|
188
|
-
cookieParams,
|
|
189
|
-
contentType,
|
|
190
|
-
accept,
|
|
191
|
-
headerParams,
|
|
192
|
-
body,
|
|
193
|
-
server,
|
|
194
|
-
auth,
|
|
195
|
-
});
|
|
196
203
|
postman_code_generators_1.default.convert(
|
|
197
204
|
mergedLanguage.language,
|
|
198
205
|
mergedLanguage.variant,
|
|
199
|
-
|
|
206
|
+
cleanedPostmanRequest,
|
|
200
207
|
mergedLanguage.options,
|
|
201
208
|
(error, snippet) => {
|
|
202
209
|
if (error) {
|
|
@@ -219,27 +226,16 @@ function CodeSnippets({ postman, codeSamples }) {
|
|
|
219
226
|
postman,
|
|
220
227
|
queryParams,
|
|
221
228
|
server,
|
|
222
|
-
|
|
229
|
+
cleanedPostmanRequest,
|
|
223
230
|
mergedLangs,
|
|
224
231
|
]);
|
|
225
|
-
// no dependencies was
|
|
232
|
+
// no dependencies was intentionally set for this particular hook. it's safe as long as if conditions are set
|
|
226
233
|
(0, react_1.useEffect)(function onSelectedVariantUpdate() {
|
|
227
234
|
if (selectedVariant && selectedVariant !== language?.variant) {
|
|
228
|
-
const postmanRequest = (0, buildPostmanRequest_1.default)(postman, {
|
|
229
|
-
queryParams,
|
|
230
|
-
pathParams,
|
|
231
|
-
cookieParams,
|
|
232
|
-
contentType,
|
|
233
|
-
accept,
|
|
234
|
-
headerParams,
|
|
235
|
-
body,
|
|
236
|
-
server,
|
|
237
|
-
auth,
|
|
238
|
-
});
|
|
239
235
|
postman_code_generators_1.default.convert(
|
|
240
236
|
language.language,
|
|
241
237
|
selectedVariant,
|
|
242
|
-
|
|
238
|
+
cleanedPostmanRequest,
|
|
243
239
|
language.options,
|
|
244
240
|
(error, snippet) => {
|
|
245
241
|
if (error) {
|
|
@@ -250,7 +246,7 @@ function CodeSnippets({ postman, codeSamples }) {
|
|
|
250
246
|
);
|
|
251
247
|
}
|
|
252
248
|
});
|
|
253
|
-
// no dependencies was
|
|
249
|
+
// no dependencies was intentionally set for this particular hook. it's safe as long as if conditions are set
|
|
254
250
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
255
251
|
(0, react_1.useEffect)(function onSelectedSampleUpdate() {
|
|
256
252
|
if (
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docusaurus-theme-openapi-docs",
|
|
3
3
|
"description": "OpenAPI theme for Docusaurus.",
|
|
4
|
-
"version": "4.3.
|
|
4
|
+
"version": "4.3.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@types/file-saver": "^2.0.5",
|
|
35
35
|
"@types/lodash": "^4.14.176",
|
|
36
36
|
"concurrently": "^5.2.0",
|
|
37
|
-
"docusaurus-plugin-openapi-docs": "^4.3.
|
|
37
|
+
"docusaurus-plugin-openapi-docs": "^4.3.1",
|
|
38
38
|
"docusaurus-plugin-sass": "^0.2.3",
|
|
39
39
|
"eslint-plugin-prettier": "^5.0.1"
|
|
40
40
|
},
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"engines": {
|
|
76
76
|
"node": ">=14"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "78bfd444c557f94a67344d6276025f4958a921bd"
|
|
79
79
|
}
|
|
@@ -5,13 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
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
|
-
|
|
15
8
|
import React, { useState, useEffect } from "react";
|
|
16
9
|
|
|
17
10
|
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
|
|
@@ -19,6 +12,7 @@ import ApiCodeBlock from "@theme/ApiExplorer/ApiCodeBlock";
|
|
|
19
12
|
import buildPostmanRequest from "@theme/ApiExplorer/buildPostmanRequest";
|
|
20
13
|
import CodeTabs from "@theme/ApiExplorer/CodeTabs";
|
|
21
14
|
import { useTypedSelector } from "@theme/ApiItem/hooks";
|
|
15
|
+
import cloneDeep from "lodash/cloneDeep";
|
|
22
16
|
import codegen from "postman-code-generators";
|
|
23
17
|
import sdk from "postman-collection";
|
|
24
18
|
|
|
@@ -59,6 +53,44 @@ function CodeSnippets({ postman, codeSamples }: Props) {
|
|
|
59
53
|
const headerParams = useTypedSelector((state: any) => state.params.header);
|
|
60
54
|
|
|
61
55
|
const auth = useTypedSelector((state: any) => state.auth);
|
|
56
|
+
const clonedAuth = cloneDeep(auth);
|
|
57
|
+
let placeholder: string;
|
|
58
|
+
|
|
59
|
+
function cleanCredentials(obj: any) {
|
|
60
|
+
for (const key in obj) {
|
|
61
|
+
if (typeof obj[key] === "object" && obj[key] !== null) {
|
|
62
|
+
// use name as placeholder if exists
|
|
63
|
+
const comboAuthId = Object.keys(obj).join(" and ");
|
|
64
|
+
const authOptions =
|
|
65
|
+
clonedAuth?.options?.[key] ?? clonedAuth?.options?.[comboAuthId];
|
|
66
|
+
placeholder = authOptions?.[0]?.name;
|
|
67
|
+
obj[key] = cleanCredentials(obj[key]);
|
|
68
|
+
} else {
|
|
69
|
+
obj[key] = `<${placeholder ?? key}>`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return obj;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// scrub credentials from code snippets
|
|
77
|
+
const cleanedAuth = {
|
|
78
|
+
...clonedAuth,
|
|
79
|
+
data: cleanCredentials(clonedAuth.data),
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// Create a Postman request object using cleanedAuth
|
|
83
|
+
const cleanedPostmanRequest = buildPostmanRequest(postman, {
|
|
84
|
+
queryParams,
|
|
85
|
+
pathParams,
|
|
86
|
+
cookieParams,
|
|
87
|
+
contentType,
|
|
88
|
+
accept,
|
|
89
|
+
headerParams,
|
|
90
|
+
body,
|
|
91
|
+
server,
|
|
92
|
+
auth: cleanedAuth,
|
|
93
|
+
});
|
|
62
94
|
|
|
63
95
|
// User-defined languages array
|
|
64
96
|
// Can override languageSet, change order of langs, override options and variants
|
|
@@ -105,21 +137,10 @@ function CodeSnippets({ postman, codeSamples }: Props) {
|
|
|
105
137
|
}
|
|
106
138
|
|
|
107
139
|
if (language && !!language.options) {
|
|
108
|
-
const postmanRequest = buildPostmanRequest(postman, {
|
|
109
|
-
queryParams,
|
|
110
|
-
pathParams,
|
|
111
|
-
cookieParams,
|
|
112
|
-
contentType,
|
|
113
|
-
accept,
|
|
114
|
-
headerParams,
|
|
115
|
-
body,
|
|
116
|
-
server,
|
|
117
|
-
auth,
|
|
118
|
-
});
|
|
119
140
|
codegen.convert(
|
|
120
141
|
language.language,
|
|
121
142
|
language.variant,
|
|
122
|
-
|
|
143
|
+
cleanedPostmanRequest,
|
|
123
144
|
language.options,
|
|
124
145
|
(error: any, snippet: string) => {
|
|
125
146
|
if (error) {
|
|
@@ -137,22 +158,10 @@ function CodeSnippets({ postman, codeSamples }: Props) {
|
|
|
137
158
|
// This allows users to define only the minimal properties necessary in languageTabs
|
|
138
159
|
// User-defined properties should override languageSet properties
|
|
139
160
|
const mergedLanguage = { ...langSource[0], ...language };
|
|
140
|
-
const postmanRequest = buildPostmanRequest(postman, {
|
|
141
|
-
queryParams,
|
|
142
|
-
pathParams,
|
|
143
|
-
cookieParams,
|
|
144
|
-
contentType,
|
|
145
|
-
accept,
|
|
146
|
-
headerParams,
|
|
147
|
-
body,
|
|
148
|
-
server,
|
|
149
|
-
auth,
|
|
150
|
-
});
|
|
151
|
-
|
|
152
161
|
codegen.convert(
|
|
153
162
|
mergedLanguage.language,
|
|
154
163
|
mergedLanguage.variant,
|
|
155
|
-
|
|
164
|
+
cleanedPostmanRequest,
|
|
156
165
|
mergedLanguage.options,
|
|
157
166
|
(error: any, snippet: string) => {
|
|
158
167
|
if (error) {
|
|
@@ -175,27 +184,16 @@ function CodeSnippets({ postman, codeSamples }: Props) {
|
|
|
175
184
|
postman,
|
|
176
185
|
queryParams,
|
|
177
186
|
server,
|
|
178
|
-
|
|
187
|
+
cleanedPostmanRequest,
|
|
179
188
|
mergedLangs,
|
|
180
189
|
]);
|
|
181
|
-
// no dependencies was
|
|
190
|
+
// no dependencies was intentionally set for this particular hook. it's safe as long as if conditions are set
|
|
182
191
|
useEffect(function onSelectedVariantUpdate() {
|
|
183
192
|
if (selectedVariant && selectedVariant !== language?.variant) {
|
|
184
|
-
const postmanRequest = buildPostmanRequest(postman, {
|
|
185
|
-
queryParams,
|
|
186
|
-
pathParams,
|
|
187
|
-
cookieParams,
|
|
188
|
-
contentType,
|
|
189
|
-
accept,
|
|
190
|
-
headerParams,
|
|
191
|
-
body,
|
|
192
|
-
server,
|
|
193
|
-
auth,
|
|
194
|
-
});
|
|
195
193
|
codegen.convert(
|
|
196
194
|
language.language,
|
|
197
195
|
selectedVariant,
|
|
198
|
-
|
|
196
|
+
cleanedPostmanRequest,
|
|
199
197
|
language.options,
|
|
200
198
|
(error: any, snippet: string) => {
|
|
201
199
|
if (error) {
|
|
@@ -207,7 +205,7 @@ function CodeSnippets({ postman, codeSamples }: Props) {
|
|
|
207
205
|
}
|
|
208
206
|
});
|
|
209
207
|
|
|
210
|
-
// no dependencies was
|
|
208
|
+
// no dependencies was intentionally set for this particular hook. it's safe as long as if conditions are set
|
|
211
209
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
212
210
|
useEffect(function onSelectedSampleUpdate() {
|
|
213
211
|
if (
|