docusaurus-theme-openapi-docs 4.3.3 → 4.3.5

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/index.js CHANGED
@@ -11,7 +11,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.default = docusaurusThemeOpenAPI;
13
13
  const path_1 = __importDefault(require("path"));
14
- const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
15
14
  function docusaurusThemeOpenAPI() {
16
15
  return {
17
16
  name: "docusaurus-theme-openapi",
@@ -36,7 +35,19 @@ function docusaurusThemeOpenAPI() {
36
35
  // Avoid conflicts with docusaurus-plugin-sass
37
36
  if (sassLoaderRule.length === 0) {
38
37
  return {
39
- plugins: [new NodePolyfillPlugin()],
38
+ resolve: {
39
+ fallback: {
40
+ buffer: require.resolve("buffer/"),
41
+ url: require.resolve("url/"),
42
+ },
43
+ },
44
+ plugins: [
45
+ new utils.currentBundler.instance.ProvidePlugin({
46
+ process: require.resolve("process/browser"),
47
+ Buffer: ["buffer", "Buffer"],
48
+ URL: ["url", "URL"],
49
+ }),
50
+ ],
40
51
  module: {
41
52
  rules: [
42
53
  {
@@ -55,7 +66,19 @@ function docusaurusThemeOpenAPI() {
55
66
  };
56
67
  }
57
68
  return {
58
- plugins: [new NodePolyfillPlugin()],
69
+ resolve: {
70
+ fallback: {
71
+ buffer: require.resolve("buffer/"),
72
+ url: require.resolve("url/"),
73
+ },
74
+ },
75
+ plugins: [
76
+ new utils.currentBundler.instance.ProvidePlugin({
77
+ process: require.resolve("process/browser"),
78
+ Buffer: ["buffer", "Buffer"],
79
+ URL: ["url", "URL"],
80
+ }),
81
+ ],
59
82
  };
60
83
  },
61
84
  };
@@ -88,8 +88,8 @@ function getQualifierMessage(schema) {
88
88
  }
89
89
  qualifierGroups.push(lengthQualifier);
90
90
  }
91
- if (schema.minimum ||
92
- schema.maximum ||
91
+ if (schema.minimum != null ||
92
+ schema.maximum != null ||
93
93
  typeof schema.exclusiveMinimum === "number" ||
94
94
  typeof schema.exclusiveMaximum === "number") {
95
95
  let minmaxQualifier = "";
@@ -98,19 +98,19 @@ function getQualifierMessage(schema) {
98
98
  if (typeof schema.exclusiveMinimum === "number") {
99
99
  minimum = `\`> ${schema.exclusiveMinimum}\``;
100
100
  }
101
- else if (schema.minimum && !schema.exclusiveMinimum) {
101
+ else if (schema.minimum != null && !schema.exclusiveMinimum) {
102
102
  minimum = `\`>= ${schema.minimum}\``;
103
103
  }
104
- else if (schema.minimum && schema.exclusiveMinimum === true) {
104
+ else if (schema.minimum != null && schema.exclusiveMinimum === true) {
105
105
  minimum = `\`> ${schema.minimum}\``;
106
106
  }
107
107
  if (typeof schema.exclusiveMaximum === "number") {
108
108
  maximum = `\`< ${schema.exclusiveMaximum}\``;
109
109
  }
110
- else if (schema.maximum && !schema.exclusiveMaximum) {
110
+ else if (schema.maximum != null && !schema.exclusiveMaximum) {
111
111
  maximum = `\`<= ${schema.maximum}\``;
112
112
  }
113
- else if (schema.maximum && schema.exclusiveMaximum === true) {
113
+ else if (schema.maximum != null && schema.exclusiveMaximum === true) {
114
114
  maximum = `\`< ${schema.maximum}\``;
115
115
  }
116
116
  if (minimum && !maximum) {
@@ -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: param.value.join(","),
90
+ value: decodedValue ? "true" : "false",
27
91
  });
28
92
  }
29
93
  // Parameter allows empty value: "/hello?extended"
30
94
  if (param.allowEmptyValue) {
31
- if (param.value === "true") {
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, queryParams) {
50
- const source = queryParams.map((param) => {
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: param.value || `:${param.name}`,
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 && !Array.isArray(param.value)) {
62
- return new postman_collection_1.default.Cookie({
63
- // TODO: Is this right?
64
- path: "",
65
- domain: "",
66
- key: param.name,
67
- value: param.value,
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 && !Array.isArray(param.value)) {
86
- postman.addHeader({ key: param.name, value: param.value });
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) => {
@@ -12,7 +12,6 @@ var __importDefault =
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.default = ApiItem;
15
- const zlib_1 = __importDefault(require("zlib"));
16
15
  const react_1 = __importDefault(require("react"));
17
16
  const BrowserOnly_1 = __importDefault(require("@docusaurus/BrowserOnly"));
18
17
  const ExecutionEnvironment_1 = __importDefault(
@@ -31,12 +30,22 @@ const CodeBlock_1 = __importDefault(require("@theme/CodeBlock"));
31
30
  const Metadata_1 = __importDefault(require("@theme/DocItem/Metadata"));
32
31
  const SkeletonLoader_1 = __importDefault(require("@theme/SkeletonLoader"));
33
32
  const clsx_1 = __importDefault(require("clsx"));
33
+ const pako_1 = require("pako");
34
34
  const react_redux_1 = require("react-redux");
35
35
  const store_1 = require("./store");
36
36
  let ApiExplorer = (_) => react_1.default.createElement("div", null);
37
37
  if (ExecutionEnvironment_1.default.canUseDOM) {
38
38
  ApiExplorer = require("@theme/ApiExplorer").default;
39
39
  }
40
+ function base64ToUint8Array(base64) {
41
+ const binary = atob(base64);
42
+ const len = binary.length;
43
+ const bytes = new Uint8Array(len);
44
+ for (let i = 0; i < len; i++) {
45
+ bytes[i] = binary.charCodeAt(i);
46
+ }
47
+ return bytes;
48
+ }
40
49
  // @ts-ignore
41
50
  function ApiItem(props) {
42
51
  const docHtmlClassName = `docs-doc-id-${props.content.metadata.id}`;
@@ -50,7 +59,7 @@ function ApiItem(props) {
50
59
  if (api) {
51
60
  try {
52
61
  api = JSON.parse(
53
- zlib_1.default.inflateSync(Buffer.from(api, "base64")).toString()
62
+ new TextDecoder().decode((0, pako_1.ungzip)(base64ToUint8Array(api)))
54
63
  );
55
64
  } catch {}
56
65
  }
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.3",
4
+ "version": "4.3.5",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -33,8 +33,9 @@
33
33
  "@types/crypto-js": "^4.1.0",
34
34
  "@types/file-saver": "^2.0.5",
35
35
  "@types/lodash": "^4.14.176",
36
+ "@types/pako": "^2.0.3",
36
37
  "concurrently": "^5.2.0",
37
- "docusaurus-plugin-openapi-docs": "^4.3.3",
38
+ "docusaurus-plugin-openapi-docs": "^4.3.5",
38
39
  "docusaurus-plugin-sass": "^0.2.3",
39
40
  "eslint-plugin-prettier": "^5.0.1"
40
41
  },
@@ -42,15 +43,17 @@
42
43
  "@hookform/error-message": "^2.0.1",
43
44
  "@reduxjs/toolkit": "^1.7.1",
44
45
  "allof-merge": "^0.6.6",
46
+ "buffer": "^6.0.3",
45
47
  "clsx": "^1.1.1",
46
48
  "copy-text-to-clipboard": "^3.1.0",
47
49
  "crypto-js": "^4.1.1",
48
50
  "file-saver": "^2.0.5",
49
51
  "lodash": "^4.17.20",
50
- "node-polyfill-webpack-plugin": "^3.0.0",
52
+ "pako": "^2.1.0",
51
53
  "postman-code-generators": "^1.10.1",
52
54
  "postman-collection": "^4.4.0",
53
55
  "prism-react-renderer": "^2.3.0",
56
+ "process": "^0.11.10",
54
57
  "react-hook-form": "^7.43.8",
55
58
  "react-live": "^4.0.0",
56
59
  "react-magic-dropzone": "^1.0.1",
@@ -62,7 +65,7 @@
62
65
  "sass": "^1.80.4",
63
66
  "sass-loader": "^16.0.2",
64
67
  "unist-util-visit": "^5.0.0",
65
- "webpack": "^5.61.0",
68
+ "url": "^0.11.1",
66
69
  "xml-formatter": "^2.6.1"
67
70
  },
68
71
  "peerDependencies": {
@@ -75,5 +78,5 @@
75
78
  "engines": {
76
79
  "node": ">=14"
77
80
  },
78
- "gitHead": "4ec42960414d640952c235afc3757fd3245fb2d2"
81
+ "gitHead": "6b5c10430f8ae45faff3a01ca13b485a77d0742a"
79
82
  }
package/src/index.ts CHANGED
@@ -9,8 +9,6 @@ import path from "path";
9
9
 
10
10
  import type { Plugin } from "@docusaurus/types";
11
11
 
12
- const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
13
-
14
12
  export default function docusaurusThemeOpenAPI(): Plugin<void> {
15
13
  return {
16
14
  name: "docusaurus-theme-openapi",
@@ -41,7 +39,19 @@ export default function docusaurusThemeOpenAPI(): Plugin<void> {
41
39
  // Avoid conflicts with docusaurus-plugin-sass
42
40
  if (sassLoaderRule.length === 0) {
43
41
  return {
44
- plugins: [new NodePolyfillPlugin()],
42
+ resolve: {
43
+ fallback: {
44
+ buffer: require.resolve("buffer/"),
45
+ url: require.resolve("url/"),
46
+ },
47
+ },
48
+ plugins: [
49
+ new utils.currentBundler.instance.ProvidePlugin({
50
+ process: require.resolve("process/browser"),
51
+ Buffer: ["buffer", "Buffer"],
52
+ URL: ["url", "URL"],
53
+ }),
54
+ ],
45
55
  module: {
46
56
  rules: [
47
57
  {
@@ -60,7 +70,19 @@ export default function docusaurusThemeOpenAPI(): Plugin<void> {
60
70
  };
61
71
  }
62
72
  return {
63
- plugins: [new NodePolyfillPlugin()],
73
+ resolve: {
74
+ fallback: {
75
+ buffer: require.resolve("buffer/"),
76
+ url: require.resolve("url/"),
77
+ },
78
+ },
79
+ plugins: [
80
+ new utils.currentBundler.instance.ProvidePlugin({
81
+ process: require.resolve("process/browser"),
82
+ Buffer: ["buffer", "Buffer"],
83
+ URL: ["url", "URL"],
84
+ }),
85
+ ],
64
86
  };
65
87
  },
66
88
  };
@@ -112,8 +112,8 @@ export function getQualifierMessage(schema?: SchemaObject): string | undefined {
112
112
  }
113
113
 
114
114
  if (
115
- schema.minimum ||
116
- schema.maximum ||
115
+ schema.minimum != null ||
116
+ schema.maximum != null ||
117
117
  typeof schema.exclusiveMinimum === "number" ||
118
118
  typeof schema.exclusiveMaximum === "number"
119
119
  ) {
@@ -122,16 +122,16 @@ export function getQualifierMessage(schema?: SchemaObject): string | undefined {
122
122
  let maximum;
123
123
  if (typeof schema.exclusiveMinimum === "number") {
124
124
  minimum = `\`> ${schema.exclusiveMinimum}\``;
125
- } else if (schema.minimum && !schema.exclusiveMinimum) {
125
+ } else if (schema.minimum != null && !schema.exclusiveMinimum) {
126
126
  minimum = `\`>= ${schema.minimum}\``;
127
- } else if (schema.minimum && schema.exclusiveMinimum === true) {
127
+ } else if (schema.minimum != null && schema.exclusiveMinimum === true) {
128
128
  minimum = `\`> ${schema.minimum}\``;
129
129
  }
130
130
  if (typeof schema.exclusiveMaximum === "number") {
131
131
  maximum = `\`< ${schema.exclusiveMaximum}\``;
132
- } else if (schema.maximum && !schema.exclusiveMaximum) {
132
+ } else if (schema.maximum != null && !schema.exclusiveMaximum) {
133
133
  maximum = `\`<= ${schema.maximum}\``;
134
- } else if (schema.maximum && schema.exclusiveMaximum === true) {
134
+ } else if (schema.maximum != null && schema.exclusiveMaximum === true) {
135
135
  maximum = `\`< ${schema.maximum}\``;
136
136
  }
137
137
 
@@ -22,7 +22,10 @@ export interface ParamProps {
22
22
  function ArrayItem({
23
23
  param,
24
24
  onChange,
25
- }: ParamProps & { onChange(value?: string): any }) {
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: param.value.join(","),
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 (param.value === "true") {
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
- .filter((item): item is sdk.QueryParam => item !== undefined);
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, queryParams: Param[]) {
61
- const source = queryParams.map((param) => {
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: param.value || `:${param.name}`,
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 && !Array.isArray(param.value)) {
74
- return new sdk.Cookie({
75
- // TODO: Is this right?
76
- path: "",
77
- domain: "",
78
- key: param.name,
79
- value: param.value,
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
- .filter((item): item is sdk.Cookie => item !== undefined);
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 && !Array.isArray(param.value)) {
106
- postman.addHeader({ key: param.name, value: param.value });
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
 
@@ -5,8 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import zlib from "zlib";
9
-
10
8
  import React from "react";
11
9
 
12
10
  import BrowserOnly from "@docusaurus/BrowserOnly";
@@ -23,13 +21,16 @@ import type { Props } from "@theme/DocItem";
23
21
  import DocItemMetadata from "@theme/DocItem/Metadata";
24
22
  import SkeletonLoader from "@theme/SkeletonLoader";
25
23
  import clsx from "clsx";
26
- import { ServerObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
27
- import { ParameterObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
24
+ import {
25
+ ParameterObject,
26
+ ServerObject,
27
+ } from "docusaurus-plugin-openapi-docs/src/openapi/types";
28
28
  import type { ApiItem as ApiItemType } from "docusaurus-plugin-openapi-docs/src/types";
29
29
  import type {
30
30
  DocFrontMatter,
31
31
  ThemeConfig,
32
32
  } from "docusaurus-theme-openapi-docs/src/types";
33
+ import { ungzip } from "pako";
33
34
  import { Provider } from "react-redux";
34
35
 
35
36
  import { createStoreWithoutState, createStoreWithState } from "./store";
@@ -52,6 +53,16 @@ interface SampleFrontMatter extends DocFrontMatter {
52
53
  readonly sample?: any;
53
54
  }
54
55
 
56
+ function base64ToUint8Array(base64: string) {
57
+ const binary = atob(base64);
58
+ const len = binary.length;
59
+ const bytes = new Uint8Array(len);
60
+ for (let i = 0; i < len; i++) {
61
+ bytes[i] = binary.charCodeAt(i);
62
+ }
63
+ return bytes;
64
+ }
65
+
55
66
  // @ts-ignore
56
67
  export default function ApiItem(props: Props): JSX.Element {
57
68
  const docHtmlClassName = `docs-doc-id-${props.content.metadata.id}`;
@@ -65,7 +76,7 @@ export default function ApiItem(props: Props): JSX.Element {
65
76
  if (api) {
66
77
  try {
67
78
  api = JSON.parse(
68
- zlib.inflateSync(Buffer.from(api as any, "base64") as any).toString()
79
+ new TextDecoder().decode(ungzip(base64ToUint8Array(api as any)))
69
80
  );
70
81
  } catch {}
71
82
  }