docusaurus-theme-openapi-docs 0.0.0-1046 → 0.0.0-1050

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.
@@ -103,18 +103,10 @@ function setQueryParams(postman, queryParams) {
103
103
  });
104
104
  }
105
105
  }
106
- const decodedValue = decodeURI(param.value);
107
- const tryJson = () => {
108
- try {
109
- return JSON.parse(decodedValue);
110
- } catch (e) {
111
- return false;
112
- }
113
- };
114
- const jsonResult = tryJson();
115
106
  // Handle object values
116
- if (jsonResult && typeof jsonResult === "object") {
117
- if (param.style === "deepObject") {
107
+ if (param.style === "deepObject") {
108
+ const jsonResult = tryDecodeJsonParam(param.value);
109
+ if (jsonResult && typeof jsonResult === "object") {
118
110
  return Object.entries(jsonResult).map(
119
111
  ([key, val]) =>
120
112
  new sdk.QueryParam({
@@ -122,7 +114,10 @@ function setQueryParams(postman, queryParams) {
122
114
  value: String(val),
123
115
  })
124
116
  );
125
- } else if (param.explode) {
117
+ }
118
+ } else if (param.explode) {
119
+ const jsonResult = tryDecodeJsonParam(param.value);
120
+ if (jsonResult && typeof jsonResult === "object") {
126
121
  return Object.entries(jsonResult).map(
127
122
  ([key, val]) =>
128
123
  new sdk.QueryParam({
@@ -139,16 +134,9 @@ function setQueryParams(postman, queryParams) {
139
134
  });
140
135
  }
141
136
  }
142
- // Handle boolean values
143
- if (typeof decodedValue === "boolean") {
144
- return new sdk.QueryParam({
145
- key: param.name,
146
- value: decodedValue ? "true" : "false",
147
- });
148
- }
149
137
  // Parameter allows empty value: "/hello?extended"
150
138
  if (param.allowEmptyValue) {
151
- if (decodedValue === "true") {
139
+ if (param.value === "true") {
152
140
  return new sdk.QueryParam({
153
141
  key: param.name,
154
142
  value: null,
@@ -188,16 +176,8 @@ function setPathParams(postman, pathParams) {
188
176
  value: serializedValue,
189
177
  });
190
178
  }
191
- const decodedValue = decodeURI(param.value);
192
- const tryJson = () => {
193
- try {
194
- return JSON.parse(decodedValue);
195
- } catch (e) {
196
- return false;
197
- }
198
- };
199
- const jsonResult = tryJson();
200
- if (typeof jsonResult === "object") {
179
+ const jsonResult = tryDecodeJsonParam(param.value);
180
+ if (jsonResult && typeof jsonResult === "object") {
201
181
  if (param.style === "matrix") {
202
182
  serializedValue = Object.entries(jsonResult)
203
183
  .map(([key, val]) => `;${key}=${val}`)
@@ -208,7 +188,7 @@ function setPathParams(postman, pathParams) {
208
188
  .join(",");
209
189
  }
210
190
  } else {
211
- serializedValue = decodedValue || `:${param.name}`;
191
+ serializedValue = param.value;
212
192
  }
213
193
  return new sdk.Variable({
214
194
  key: param.name,
@@ -224,16 +204,8 @@ function buildCookie(cookieParams) {
224
204
  const cookies = cookieParams
225
205
  .map((param) => {
226
206
  if (param.value) {
227
- const decodedValue = decodeURI(param.value);
228
- const tryJson = () => {
229
- try {
230
- return JSON.parse(decodedValue);
231
- } catch (e) {
232
- return false;
233
- }
234
- };
235
- const jsonResult = tryJson();
236
- if (typeof jsonResult === "object") {
207
+ const jsonResult = tryDecodeJsonParam(param.value);
208
+ if (jsonResult && typeof jsonResult === "object") {
237
209
  if (param.style === "form") {
238
210
  // Handle form style
239
211
  if (param.explode) {
@@ -286,15 +258,9 @@ function setHeaders(postman, contentType, accept, cookie, headerParams, other) {
286
258
  }
287
259
  headerParams.forEach((param) => {
288
260
  if (param.value) {
289
- const decodedValue = decodeURI(param.value);
290
- const tryJson = () => {
291
- try {
292
- return JSON.parse(decodedValue);
293
- } catch (e) {
294
- return false;
295
- }
296
- };
297
- const jsonResult = tryJson();
261
+ const jsonResult = Array.isArray(param.value)
262
+ ? param.value.map(tryDecodeJsonParam)
263
+ : tryDecodeJsonParam(param.value);
298
264
  if (Array.isArray(param.value)) {
299
265
  if (param.style === "simple") {
300
266
  if (param.explode) {
@@ -340,6 +306,13 @@ function setHeaders(postman, contentType, accept, cookie, headerParams, other) {
340
306
  postman.addHeader({ key: "Cookie", value: cookie });
341
307
  }
342
308
  }
309
+ function tryDecodeJsonParam(value) {
310
+ try {
311
+ return JSON.parse(decodeURI(value));
312
+ } catch (e) {
313
+ return false;
314
+ }
315
+ }
343
316
  // TODO: this is all a bit hacky
344
317
  function setBody(clonedPostman, body) {
345
318
  if (clonedPostman.body === undefined) {
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": "0.0.0-1046",
4
+ "version": "0.0.0-1050",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -38,7 +38,7 @@
38
38
  "@types/postman-collection": "^3.5.11",
39
39
  "@types/react-modal": "^3.16.3",
40
40
  "concurrently": "^9.2.0",
41
- "docusaurus-plugin-openapi-docs": "0.0.0-1046",
41
+ "docusaurus-plugin-openapi-docs": "0.0.0-1050",
42
42
  "docusaurus-plugin-sass": "^0.2.6",
43
43
  "eslint-plugin-prettier": "^5.5.1"
44
44
  },
@@ -81,5 +81,5 @@
81
81
  "engines": {
82
82
  "node": ">=14"
83
83
  },
84
- "gitHead": "1d302ddba2690d6e43186c46fd03f1da8ca7f9dd"
84
+ "gitHead": "33f10237ae33c3b720cc8003de8502d48cbdb2fb"
85
85
  }
@@ -55,20 +55,10 @@ function setQueryParams(postman: sdk.Request, queryParams: Param[]) {
55
55
  }
56
56
  }
57
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
58
  // Handle object values
70
- if (jsonResult && typeof jsonResult === "object") {
71
- if (param.style === "deepObject") {
59
+ if (param.style === "deepObject") {
60
+ const jsonResult = tryDecodeJsonParam(param.value);
61
+ if (jsonResult && typeof jsonResult === "object") {
72
62
  return Object.entries(jsonResult).map(
73
63
  ([key, val]) =>
74
64
  new sdk.QueryParam({
@@ -76,7 +66,10 @@ function setQueryParams(postman: sdk.Request, queryParams: Param[]) {
76
66
  value: String(val),
77
67
  })
78
68
  );
79
- } else if (param.explode) {
69
+ }
70
+ } else if (param.explode) {
71
+ const jsonResult = tryDecodeJsonParam(param.value);
72
+ if (jsonResult && typeof jsonResult === "object") {
80
73
  return Object.entries(jsonResult).map(
81
74
  ([key, val]) =>
82
75
  new sdk.QueryParam({
@@ -94,17 +87,9 @@ function setQueryParams(postman: sdk.Request, queryParams: Param[]) {
94
87
  }
95
88
  }
96
89
 
97
- // Handle boolean values
98
- if (typeof decodedValue === "boolean") {
99
- return new sdk.QueryParam({
100
- key: param.name,
101
- value: decodedValue ? "true" : "false",
102
- });
103
- }
104
-
105
90
  // Parameter allows empty value: "/hello?extended"
106
91
  if (param.allowEmptyValue) {
107
- if (decodedValue === "true") {
92
+ if (param.value === "true") {
108
93
  return new sdk.QueryParam({
109
94
  key: param.name,
110
95
  value: null,
@@ -150,18 +135,9 @@ function setPathParams(postman: sdk.Request, pathParams: Param[]) {
150
135
  });
151
136
  }
152
137
 
153
- const decodedValue = decodeURI(param.value);
154
- const tryJson = () => {
155
- try {
156
- return JSON.parse(decodedValue);
157
- } catch (e) {
158
- return false;
159
- }
160
- };
138
+ const jsonResult = tryDecodeJsonParam(param.value);
161
139
 
162
- const jsonResult = tryJson();
163
-
164
- if (typeof jsonResult === "object") {
140
+ if (jsonResult && typeof jsonResult === "object") {
165
141
  if (param.style === "matrix") {
166
142
  serializedValue = Object.entries(jsonResult)
167
143
  .map(([key, val]) => `;${key}=${val}`)
@@ -172,7 +148,7 @@ function setPathParams(postman: sdk.Request, pathParams: Param[]) {
172
148
  .join(",");
173
149
  }
174
150
  } else {
175
- serializedValue = decodedValue || `:${param.name}`;
151
+ serializedValue = param.value;
176
152
  }
177
153
 
178
154
  return new sdk.Variable({
@@ -191,17 +167,8 @@ function buildCookie(cookieParams: Param[]) {
191
167
  const cookies = cookieParams
192
168
  .map((param) => {
193
169
  if (param.value) {
194
- const decodedValue = decodeURI(param.value as string);
195
- const tryJson = () => {
196
- try {
197
- return JSON.parse(decodedValue);
198
- } catch (e) {
199
- return false;
200
- }
201
- };
202
-
203
- const jsonResult = tryJson();
204
- if (typeof jsonResult === "object") {
170
+ const jsonResult = tryDecodeJsonParam(param.value as string);
171
+ if (jsonResult && typeof jsonResult === "object") {
205
172
  if (param.style === "form") {
206
173
  // Handle form style
207
174
  if (param.explode) {
@@ -266,16 +233,9 @@ function setHeaders(
266
233
 
267
234
  headerParams.forEach((param) => {
268
235
  if (param.value) {
269
- const decodedValue = decodeURI(param.value as string);
270
- const tryJson = () => {
271
- try {
272
- return JSON.parse(decodedValue);
273
- } catch (e) {
274
- return false;
275
- }
276
- };
277
-
278
- const jsonResult = tryJson();
236
+ const jsonResult = Array.isArray(param.value)
237
+ ? param.value.map(tryDecodeJsonParam)
238
+ : tryDecodeJsonParam(param.value);
279
239
  if (Array.isArray(param.value)) {
280
240
  if (param.style === "simple") {
281
241
  if (param.explode) {
@@ -324,6 +284,14 @@ function setHeaders(
324
284
  }
325
285
  }
326
286
 
287
+ function tryDecodeJsonParam(value: string): any {
288
+ try {
289
+ return JSON.parse(decodeURI(value));
290
+ } catch (e) {
291
+ return false;
292
+ }
293
+ }
294
+
327
295
  // TODO: this is all a bit hacky
328
296
  function setBody(clonedPostman: sdk.Request, body: Body) {
329
297
  if (clonedPostman.body === undefined) {