docusaurus-theme-openapi-docs 4.3.3 → 4.3.4
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/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.js +14 -1
- package/lib/theme/ApiExplorer/buildPostmanRequest.js +197 -15
- package/package.json +2 -2
- package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx +19 -1
- package/src/theme/ApiExplorer/buildPostmanRequest.ts +216 -17
|
@@ -78,7 +78,8 @@ const FormTextInput_1 = __importDefault(
|
|
|
78
78
|
const slice_1 = require("@theme/ApiExplorer/ParamOptions/slice");
|
|
79
79
|
const hooks_1 = require("@theme/ApiItem/hooks");
|
|
80
80
|
const react_hook_form_1 = require("react-hook-form");
|
|
81
|
-
function ArrayItem({ param, onChange }) {
|
|
81
|
+
function ArrayItem({ param, onChange, initialValue }) {
|
|
82
|
+
const [value, setValue] = (0, react_1.useState)(initialValue || "");
|
|
82
83
|
if (param.schema?.items?.type === "boolean") {
|
|
83
84
|
return react_1.default.createElement(FormSelect_1.default, {
|
|
84
85
|
options: ["---", "true", "false"],
|
|
@@ -90,7 +91,9 @@ function ArrayItem({ param, onChange }) {
|
|
|
90
91
|
}
|
|
91
92
|
return react_1.default.createElement(FormTextInput_1.default, {
|
|
92
93
|
placeholder: param.description || param.name,
|
|
94
|
+
value: value,
|
|
93
95
|
onChange: (e) => {
|
|
96
|
+
setValue(e.target.value);
|
|
94
97
|
onChange(e.target.value);
|
|
95
98
|
},
|
|
96
99
|
});
|
|
@@ -122,6 +125,15 @@ function ParamArrayFormItem({ param }) {
|
|
|
122
125
|
);
|
|
123
126
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
124
127
|
}, [items]);
|
|
128
|
+
(0, react_1.useEffect)(() => {
|
|
129
|
+
if (param.schema?.example?.length > 0) {
|
|
130
|
+
const examplesWithIds = param.schema.example.map((item) => ({
|
|
131
|
+
id: (0, toolkit_1.nanoid)(),
|
|
132
|
+
value: item.toString(),
|
|
133
|
+
}));
|
|
134
|
+
setItems(examplesWithIds);
|
|
135
|
+
}
|
|
136
|
+
}, [param.schema.example, param.schema.length]);
|
|
125
137
|
function handleDeleteItem(itemToDelete) {
|
|
126
138
|
return () => {
|
|
127
139
|
const newItems = items.filter((i) => i.id !== itemToDelete.id);
|
|
@@ -158,6 +170,7 @@ function ParamArrayFormItem({ param }) {
|
|
|
158
170
|
react_1.default.createElement(ArrayItem, {
|
|
159
171
|
param: param,
|
|
160
172
|
onChange: handleChangeItem(item, onChange),
|
|
173
|
+
initialValue: item.value,
|
|
161
174
|
}),
|
|
162
175
|
react_1.default.createElement(
|
|
163
176
|
"button",
|
|
@@ -20,15 +20,79 @@ function setQueryParams(postman, queryParams) {
|
|
|
20
20
|
if (!param.value) {
|
|
21
21
|
return undefined;
|
|
22
22
|
}
|
|
23
|
+
// Handle array values
|
|
23
24
|
if (Array.isArray(param.value)) {
|
|
25
|
+
if (param.style === "spaceDelimited") {
|
|
26
|
+
return new postman_collection_1.default.QueryParam({
|
|
27
|
+
key: param.name,
|
|
28
|
+
value: param.value.join(" "),
|
|
29
|
+
});
|
|
30
|
+
} else if (param.style === "pipeDelimited") {
|
|
31
|
+
return new postman_collection_1.default.QueryParam({
|
|
32
|
+
key: param.name,
|
|
33
|
+
value: param.value.join("|"),
|
|
34
|
+
});
|
|
35
|
+
} else if (param.explode) {
|
|
36
|
+
return param.value.map(
|
|
37
|
+
(val) =>
|
|
38
|
+
new postman_collection_1.default.QueryParam({
|
|
39
|
+
key: param.name,
|
|
40
|
+
value: val,
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
} else {
|
|
44
|
+
return new postman_collection_1.default.QueryParam({
|
|
45
|
+
key: param.name,
|
|
46
|
+
value: param.value.join(","),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const decodedValue = decodeURI(param.value);
|
|
51
|
+
const tryJson = () => {
|
|
52
|
+
try {
|
|
53
|
+
return JSON.parse(decodedValue);
|
|
54
|
+
} catch (e) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const jsonResult = tryJson();
|
|
59
|
+
// Handle object values
|
|
60
|
+
if (jsonResult && typeof jsonResult === "object") {
|
|
61
|
+
if (param.style === "deepObject") {
|
|
62
|
+
return Object.entries(jsonResult).map(
|
|
63
|
+
([key, val]) =>
|
|
64
|
+
new postman_collection_1.default.QueryParam({
|
|
65
|
+
key: `${param.name}[${key}]`,
|
|
66
|
+
value: val,
|
|
67
|
+
})
|
|
68
|
+
);
|
|
69
|
+
} else if (param.explode) {
|
|
70
|
+
return Object.entries(jsonResult).map(
|
|
71
|
+
([key, val]) =>
|
|
72
|
+
new postman_collection_1.default.QueryParam({
|
|
73
|
+
key: key,
|
|
74
|
+
value: val,
|
|
75
|
+
})
|
|
76
|
+
);
|
|
77
|
+
} else {
|
|
78
|
+
return new postman_collection_1.default.QueryParam({
|
|
79
|
+
key: param.name,
|
|
80
|
+
value: Object.entries(jsonResult)
|
|
81
|
+
.map(([key, val]) => `${key},${val}`)
|
|
82
|
+
.join(","),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Handle boolean values
|
|
87
|
+
if (typeof decodedValue === "boolean") {
|
|
24
88
|
return new postman_collection_1.default.QueryParam({
|
|
25
89
|
key: param.name,
|
|
26
|
-
value:
|
|
90
|
+
value: decodedValue ? "true" : "false",
|
|
27
91
|
});
|
|
28
92
|
}
|
|
29
93
|
// Parameter allows empty value: "/hello?extended"
|
|
30
94
|
if (param.allowEmptyValue) {
|
|
31
|
-
if (
|
|
95
|
+
if (decodedValue === "true") {
|
|
32
96
|
return new postman_collection_1.default.QueryParam({
|
|
33
97
|
key: param.name,
|
|
34
98
|
value: null,
|
|
@@ -41,16 +105,58 @@ function setQueryParams(postman, queryParams) {
|
|
|
41
105
|
value: param.value,
|
|
42
106
|
});
|
|
43
107
|
})
|
|
108
|
+
.flat() // Flatten the array in case of nested arrays from map
|
|
44
109
|
.filter((item) => item !== undefined);
|
|
45
110
|
if (qp.length > 0) {
|
|
46
111
|
postman.addQueryParams(qp);
|
|
47
112
|
}
|
|
48
113
|
}
|
|
49
|
-
function setPathParams(postman,
|
|
50
|
-
|
|
114
|
+
function setPathParams(postman, pathParams) {
|
|
115
|
+
// Map through the path parameters
|
|
116
|
+
const source = pathParams.map((param) => {
|
|
117
|
+
if (!param.value) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
let serializedValue;
|
|
121
|
+
// Handle different styles
|
|
122
|
+
if (Array.isArray(param.value)) {
|
|
123
|
+
if (param.style === "label") {
|
|
124
|
+
serializedValue = `.${param.value.join(".")}`;
|
|
125
|
+
} else if (param.style === "matrix") {
|
|
126
|
+
serializedValue = `;${param.name}=${param.value.join(";")}`;
|
|
127
|
+
} else {
|
|
128
|
+
serializedValue = param.value.join(",");
|
|
129
|
+
}
|
|
130
|
+
return new postman_collection_1.default.Variable({
|
|
131
|
+
key: param.name,
|
|
132
|
+
value: serializedValue,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
const decodedValue = decodeURI(param.value);
|
|
136
|
+
const tryJson = () => {
|
|
137
|
+
try {
|
|
138
|
+
return JSON.parse(decodedValue);
|
|
139
|
+
} catch (e) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const jsonResult = tryJson();
|
|
144
|
+
if (typeof jsonResult === "object") {
|
|
145
|
+
if (param.style === "matrix") {
|
|
146
|
+
serializedValue = Object.entries(jsonResult)
|
|
147
|
+
.map(([key, val]) => `;${key}=${val}`)
|
|
148
|
+
.join("");
|
|
149
|
+
} else {
|
|
150
|
+
serializedValue = Object.entries(jsonResult)
|
|
151
|
+
.map(([key, val]) => `${key}=${val}`)
|
|
152
|
+
.join(",");
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
serializedValue = decodedValue || `:${param.name}`;
|
|
156
|
+
}
|
|
51
157
|
return new postman_collection_1.default.Variable({
|
|
52
158
|
key: param.name,
|
|
53
|
-
value:
|
|
159
|
+
value: serializedValue,
|
|
54
160
|
});
|
|
55
161
|
});
|
|
56
162
|
postman.url.variables.assimilate(source, false);
|
|
@@ -58,17 +164,49 @@ function setPathParams(postman, queryParams) {
|
|
|
58
164
|
function buildCookie(cookieParams) {
|
|
59
165
|
const cookies = cookieParams
|
|
60
166
|
.map((param) => {
|
|
61
|
-
if (param.value
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
167
|
+
if (param.value) {
|
|
168
|
+
const decodedValue = decodeURI(param.value);
|
|
169
|
+
const tryJson = () => {
|
|
170
|
+
try {
|
|
171
|
+
return JSON.parse(decodedValue);
|
|
172
|
+
} catch (e) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
const jsonResult = tryJson();
|
|
177
|
+
if (typeof jsonResult === "object") {
|
|
178
|
+
if (param.style === "form") {
|
|
179
|
+
// Handle form style
|
|
180
|
+
if (param.explode) {
|
|
181
|
+
// Serialize each key-value pair as a separate cookie
|
|
182
|
+
return Object.entries(jsonResult).map(
|
|
183
|
+
([key, val]) =>
|
|
184
|
+
new postman_collection_1.default.Cookie({
|
|
185
|
+
key: key,
|
|
186
|
+
value: val,
|
|
187
|
+
})
|
|
188
|
+
);
|
|
189
|
+
} else {
|
|
190
|
+
// Serialize the object as a single cookie with key-value pairs joined by commas
|
|
191
|
+
return new postman_collection_1.default.Cookie({
|
|
192
|
+
key: param.name,
|
|
193
|
+
value: Object.entries(jsonResult)
|
|
194
|
+
.map(([key, val]) => `${key},${val}`)
|
|
195
|
+
.join(","),
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
// Handle scalar values
|
|
201
|
+
return new postman_collection_1.default.Cookie({
|
|
202
|
+
key: param.name,
|
|
203
|
+
value: param.value,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
69
206
|
}
|
|
70
207
|
return undefined;
|
|
71
208
|
})
|
|
209
|
+
.flat() // Flatten the array in case of nested arrays from map
|
|
72
210
|
.filter((item) => item !== undefined);
|
|
73
211
|
const list = new postman_collection_1.default.CookieList(null, cookies);
|
|
74
212
|
return list.toString();
|
|
@@ -82,8 +220,52 @@ function setHeaders(postman, contentType, accept, cookie, headerParams, other) {
|
|
|
82
220
|
postman.addHeader({ key: "Accept", value: accept });
|
|
83
221
|
}
|
|
84
222
|
headerParams.forEach((param) => {
|
|
85
|
-
if (param.value
|
|
86
|
-
|
|
223
|
+
if (param.value) {
|
|
224
|
+
const decodedValue = decodeURI(param.value);
|
|
225
|
+
const tryJson = () => {
|
|
226
|
+
try {
|
|
227
|
+
return JSON.parse(decodedValue);
|
|
228
|
+
} catch (e) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
const jsonResult = tryJson();
|
|
233
|
+
if (Array.isArray(param.value)) {
|
|
234
|
+
if (param.style === "simple") {
|
|
235
|
+
if (param.explode) {
|
|
236
|
+
// Each item in the array is a separate header
|
|
237
|
+
jsonResult.forEach((val) => {
|
|
238
|
+
postman.addHeader({ key: param.name, value: val });
|
|
239
|
+
});
|
|
240
|
+
} else {
|
|
241
|
+
// Array values are joined by commas
|
|
242
|
+
postman.addHeader({
|
|
243
|
+
key: param.name,
|
|
244
|
+
value: param.value.join(","),
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
} else if (typeof jsonResult === "object") {
|
|
249
|
+
if (param.style === "simple") {
|
|
250
|
+
if (param.explode) {
|
|
251
|
+
// Each key-value pair in the object is a separate header
|
|
252
|
+
Object.entries(jsonResult).forEach(([key, val]) => {
|
|
253
|
+
postman.addHeader({ key: param.name, value: `${key}=${val}` });
|
|
254
|
+
});
|
|
255
|
+
} else {
|
|
256
|
+
// Object is serialized as a single header with key-value pairs joined by commas
|
|
257
|
+
postman.addHeader({
|
|
258
|
+
key: param.name,
|
|
259
|
+
value: Object.entries(jsonResult)
|
|
260
|
+
.map(([key, val]) => `${key},${val}`)
|
|
261
|
+
.join(","),
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
} else {
|
|
266
|
+
// Handle scalar values
|
|
267
|
+
postman.addHeader({ key: param.name, value: param.value });
|
|
268
|
+
}
|
|
87
269
|
}
|
|
88
270
|
});
|
|
89
271
|
other.forEach((header) => {
|
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.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"engines": {
|
|
76
76
|
"node": ">=14"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "97d0fc7e9ed0f18f0cf02b8de3bc502b0cd52c34"
|
|
79
79
|
}
|
|
@@ -22,7 +22,10 @@ export interface ParamProps {
|
|
|
22
22
|
function ArrayItem({
|
|
23
23
|
param,
|
|
24
24
|
onChange,
|
|
25
|
-
|
|
25
|
+
initialValue,
|
|
26
|
+
}: ParamProps & { onChange(value?: string): any; initialValue?: string }) {
|
|
27
|
+
const [value, setValue] = useState(initialValue || "");
|
|
28
|
+
|
|
26
29
|
if (param.schema?.items?.type === "boolean") {
|
|
27
30
|
return (
|
|
28
31
|
<FormSelect
|
|
@@ -38,7 +41,9 @@ function ArrayItem({
|
|
|
38
41
|
return (
|
|
39
42
|
<FormTextInput
|
|
40
43
|
placeholder={param.description || param.name}
|
|
44
|
+
value={value}
|
|
41
45
|
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
46
|
+
setValue(e.target.value);
|
|
42
47
|
onChange(e.target.value);
|
|
43
48
|
}}
|
|
44
49
|
/>
|
|
@@ -77,9 +82,21 @@ export default function ParamArrayFormItem({ param }: ParamProps) {
|
|
|
77
82
|
value: values.length > 0 ? values : undefined,
|
|
78
83
|
})
|
|
79
84
|
);
|
|
85
|
+
|
|
80
86
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
81
87
|
}, [items]);
|
|
82
88
|
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
if (param.schema?.example?.length > 0) {
|
|
91
|
+
const examplesWithIds = param.schema.example.map((item: any) => ({
|
|
92
|
+
id: nanoid(),
|
|
93
|
+
value: item.toString(),
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
setItems(examplesWithIds);
|
|
97
|
+
}
|
|
98
|
+
}, [param.schema.example, param.schema.length]);
|
|
99
|
+
|
|
83
100
|
function handleDeleteItem(itemToDelete: { id: string }) {
|
|
84
101
|
return () => {
|
|
85
102
|
const newItems = items.filter((i) => i.id !== itemToDelete.id);
|
|
@@ -113,6 +130,7 @@ export default function ParamArrayFormItem({ param }: ParamProps) {
|
|
|
113
130
|
<ArrayItem
|
|
114
131
|
param={param}
|
|
115
132
|
onChange={handleChangeItem(item, onChange)}
|
|
133
|
+
initialValue={item.value}
|
|
116
134
|
/>
|
|
117
135
|
<button
|
|
118
136
|
className="openapi-explorer__delete-btn"
|
|
@@ -27,16 +27,84 @@ function setQueryParams(postman: sdk.Request, queryParams: Param[]) {
|
|
|
27
27
|
return undefined;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
// Handle array values
|
|
30
31
|
if (Array.isArray(param.value)) {
|
|
32
|
+
if (param.style === "spaceDelimited") {
|
|
33
|
+
return new sdk.QueryParam({
|
|
34
|
+
key: param.name,
|
|
35
|
+
value: param.value.join(" "),
|
|
36
|
+
});
|
|
37
|
+
} else if (param.style === "pipeDelimited") {
|
|
38
|
+
return new sdk.QueryParam({
|
|
39
|
+
key: param.name,
|
|
40
|
+
value: param.value.join("|"),
|
|
41
|
+
});
|
|
42
|
+
} else if (param.explode) {
|
|
43
|
+
return param.value.map(
|
|
44
|
+
(val) =>
|
|
45
|
+
new sdk.QueryParam({
|
|
46
|
+
key: param.name,
|
|
47
|
+
value: val,
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
} else {
|
|
51
|
+
return new sdk.QueryParam({
|
|
52
|
+
key: param.name,
|
|
53
|
+
value: param.value.join(","),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const decodedValue = decodeURI(param.value);
|
|
59
|
+
const tryJson = () => {
|
|
60
|
+
try {
|
|
61
|
+
return JSON.parse(decodedValue);
|
|
62
|
+
} catch (e) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const jsonResult = tryJson();
|
|
68
|
+
|
|
69
|
+
// Handle object values
|
|
70
|
+
if (jsonResult && typeof jsonResult === "object") {
|
|
71
|
+
if (param.style === "deepObject") {
|
|
72
|
+
return Object.entries(jsonResult).map(
|
|
73
|
+
([key, val]) =>
|
|
74
|
+
new sdk.QueryParam({
|
|
75
|
+
key: `${param.name}[${key}]`,
|
|
76
|
+
value: val,
|
|
77
|
+
})
|
|
78
|
+
);
|
|
79
|
+
} else if (param.explode) {
|
|
80
|
+
return Object.entries(jsonResult).map(
|
|
81
|
+
([key, val]) =>
|
|
82
|
+
new sdk.QueryParam({
|
|
83
|
+
key: key,
|
|
84
|
+
value: val,
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
} else {
|
|
88
|
+
return new sdk.QueryParam({
|
|
89
|
+
key: param.name,
|
|
90
|
+
value: Object.entries(jsonResult)
|
|
91
|
+
.map(([key, val]) => `${key},${val}`)
|
|
92
|
+
.join(","),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Handle boolean values
|
|
98
|
+
if (typeof decodedValue === "boolean") {
|
|
31
99
|
return new sdk.QueryParam({
|
|
32
100
|
key: param.name,
|
|
33
|
-
value:
|
|
101
|
+
value: decodedValue ? "true" : "false",
|
|
34
102
|
});
|
|
35
103
|
}
|
|
36
104
|
|
|
37
105
|
// Parameter allows empty value: "/hello?extended"
|
|
38
106
|
if (param.allowEmptyValue) {
|
|
39
|
-
if (
|
|
107
|
+
if (decodedValue === "true") {
|
|
40
108
|
return new sdk.QueryParam({
|
|
41
109
|
key: param.name,
|
|
42
110
|
value: null,
|
|
@@ -50,38 +118,121 @@ function setQueryParams(postman: sdk.Request, queryParams: Param[]) {
|
|
|
50
118
|
value: param.value,
|
|
51
119
|
});
|
|
52
120
|
})
|
|
53
|
-
.
|
|
121
|
+
.flat() // Flatten the array in case of nested arrays from map
|
|
122
|
+
.filter((item) => item !== undefined);
|
|
54
123
|
|
|
55
124
|
if (qp.length > 0) {
|
|
56
125
|
postman.addQueryParams(qp);
|
|
57
126
|
}
|
|
58
127
|
}
|
|
59
128
|
|
|
60
|
-
function setPathParams(postman: sdk.Request,
|
|
61
|
-
|
|
129
|
+
function setPathParams(postman: sdk.Request, pathParams: Param[]) {
|
|
130
|
+
// Map through the path parameters
|
|
131
|
+
const source = pathParams.map((param) => {
|
|
132
|
+
if (!param.value) {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
let serializedValue;
|
|
137
|
+
|
|
138
|
+
// Handle different styles
|
|
139
|
+
if (Array.isArray(param.value)) {
|
|
140
|
+
if (param.style === "label") {
|
|
141
|
+
serializedValue = `.${param.value.join(".")}`;
|
|
142
|
+
} else if (param.style === "matrix") {
|
|
143
|
+
serializedValue = `;${param.name}=${param.value.join(";")}`;
|
|
144
|
+
} else {
|
|
145
|
+
serializedValue = param.value.join(",");
|
|
146
|
+
}
|
|
147
|
+
return new sdk.Variable({
|
|
148
|
+
key: param.name,
|
|
149
|
+
value: serializedValue,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const decodedValue = decodeURI(param.value);
|
|
154
|
+
const tryJson = () => {
|
|
155
|
+
try {
|
|
156
|
+
return JSON.parse(decodedValue);
|
|
157
|
+
} catch (e) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const jsonResult = tryJson();
|
|
163
|
+
|
|
164
|
+
if (typeof jsonResult === "object") {
|
|
165
|
+
if (param.style === "matrix") {
|
|
166
|
+
serializedValue = Object.entries(jsonResult)
|
|
167
|
+
.map(([key, val]) => `;${key}=${val}`)
|
|
168
|
+
.join("");
|
|
169
|
+
} else {
|
|
170
|
+
serializedValue = Object.entries(jsonResult)
|
|
171
|
+
.map(([key, val]) => `${key}=${val}`)
|
|
172
|
+
.join(",");
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
serializedValue = decodedValue || `:${param.name}`;
|
|
176
|
+
}
|
|
177
|
+
|
|
62
178
|
return new sdk.Variable({
|
|
63
179
|
key: param.name,
|
|
64
|
-
value:
|
|
180
|
+
value: serializedValue,
|
|
65
181
|
});
|
|
66
182
|
});
|
|
183
|
+
|
|
67
184
|
postman.url.variables.assimilate(source, false);
|
|
68
185
|
}
|
|
69
186
|
|
|
70
187
|
function buildCookie(cookieParams: Param[]) {
|
|
71
188
|
const cookies = cookieParams
|
|
72
189
|
.map((param) => {
|
|
73
|
-
if (param.value
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
190
|
+
if (param.value) {
|
|
191
|
+
const decodedValue = decodeURI(param.value as string);
|
|
192
|
+
const tryJson = () => {
|
|
193
|
+
try {
|
|
194
|
+
return JSON.parse(decodedValue);
|
|
195
|
+
} catch (e) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const jsonResult = tryJson();
|
|
201
|
+
if (typeof jsonResult === "object") {
|
|
202
|
+
if (param.style === "form") {
|
|
203
|
+
// Handle form style
|
|
204
|
+
if (param.explode) {
|
|
205
|
+
// Serialize each key-value pair as a separate cookie
|
|
206
|
+
return Object.entries(jsonResult).map(
|
|
207
|
+
([key, val]) =>
|
|
208
|
+
new sdk.Cookie({
|
|
209
|
+
key: key,
|
|
210
|
+
value: val,
|
|
211
|
+
})
|
|
212
|
+
);
|
|
213
|
+
} else {
|
|
214
|
+
// Serialize the object as a single cookie with key-value pairs joined by commas
|
|
215
|
+
return new sdk.Cookie({
|
|
216
|
+
key: param.name,
|
|
217
|
+
value: Object.entries(jsonResult)
|
|
218
|
+
.map(([key, val]) => `${key},${val}`)
|
|
219
|
+
.join(","),
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
// Handle scalar values
|
|
225
|
+
return new sdk.Cookie({
|
|
226
|
+
key: param.name,
|
|
227
|
+
value: param.value,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
81
230
|
}
|
|
82
231
|
return undefined;
|
|
83
232
|
})
|
|
84
|
-
.
|
|
233
|
+
.flat() // Flatten the array in case of nested arrays from map
|
|
234
|
+
.filter((item) => item !== undefined);
|
|
235
|
+
|
|
85
236
|
const list = new sdk.CookieList(null, cookies);
|
|
86
237
|
return list.toString();
|
|
87
238
|
}
|
|
@@ -95,15 +246,63 @@ function setHeaders(
|
|
|
95
246
|
other: { key: string; value: string }[]
|
|
96
247
|
) {
|
|
97
248
|
postman.headers.clear();
|
|
249
|
+
|
|
98
250
|
if (contentType) {
|
|
99
251
|
postman.addHeader({ key: "Content-Type", value: contentType });
|
|
100
252
|
}
|
|
253
|
+
|
|
101
254
|
if (accept) {
|
|
102
255
|
postman.addHeader({ key: "Accept", value: accept });
|
|
103
256
|
}
|
|
257
|
+
|
|
104
258
|
headerParams.forEach((param) => {
|
|
105
|
-
if (param.value
|
|
106
|
-
|
|
259
|
+
if (param.value) {
|
|
260
|
+
const decodedValue = decodeURI(param.value as string);
|
|
261
|
+
const tryJson = () => {
|
|
262
|
+
try {
|
|
263
|
+
return JSON.parse(decodedValue);
|
|
264
|
+
} catch (e) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const jsonResult = tryJson();
|
|
270
|
+
if (Array.isArray(param.value)) {
|
|
271
|
+
if (param.style === "simple") {
|
|
272
|
+
if (param.explode) {
|
|
273
|
+
// Each item in the array is a separate header
|
|
274
|
+
jsonResult.forEach((val: any) => {
|
|
275
|
+
postman.addHeader({ key: param.name, value: val });
|
|
276
|
+
});
|
|
277
|
+
} else {
|
|
278
|
+
// Array values are joined by commas
|
|
279
|
+
postman.addHeader({
|
|
280
|
+
key: param.name,
|
|
281
|
+
value: param.value.join(","),
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
} else if (typeof jsonResult === "object") {
|
|
286
|
+
if (param.style === "simple") {
|
|
287
|
+
if (param.explode) {
|
|
288
|
+
// Each key-value pair in the object is a separate header
|
|
289
|
+
Object.entries(jsonResult).forEach(([key, val]) => {
|
|
290
|
+
postman.addHeader({ key: param.name, value: `${key}=${val}` });
|
|
291
|
+
});
|
|
292
|
+
} else {
|
|
293
|
+
// Object is serialized as a single header with key-value pairs joined by commas
|
|
294
|
+
postman.addHeader({
|
|
295
|
+
key: param.name,
|
|
296
|
+
value: Object.entries(jsonResult)
|
|
297
|
+
.map(([key, val]) => `${key},${val}`)
|
|
298
|
+
.join(","),
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
} else {
|
|
303
|
+
// Handle scalar values
|
|
304
|
+
postman.addHeader({ key: param.name, value: param.value });
|
|
305
|
+
}
|
|
107
306
|
}
|
|
108
307
|
});
|
|
109
308
|
|