docusaurus-theme-openapi-docs 0.0.0-989 → 0.0.0-996

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.
@@ -13,7 +13,8 @@
13
13
 
14
14
  &:hover {
15
15
  border: 2px dashed var(--ifm-color-primary);
16
- background: linear-gradient(
16
+ background:
17
+ linear-gradient(
17
18
  var(--openapi-dropzone-hover-shim),
18
19
  var(--openapi-dropzone-hover-shim)
19
20
  ),
@@ -38,7 +39,8 @@
38
39
  font-size: var(--ifm-code-font-size);
39
40
  border: 2px dashed var(--ifm-color-primary);
40
41
 
41
- background: linear-gradient(
42
+ background:
43
+ linear-gradient(
42
44
  var(--openapi-dropzone-hover-shim),
43
45
  var(--openapi-dropzone-hover-shim)
44
46
  ),
@@ -45,8 +45,8 @@
45
45
  line-height: 1.5;
46
46
 
47
47
  transition-property: color, background, border-color, box-shadow;
48
- transition-duration: 100ms, 100ms, 100ms,
49
- var(--ifm-button-transition-duration);
48
+ transition-duration:
49
+ 100ms, 100ms, 100ms, var(--ifm-button-transition-duration);
50
50
  transition-timing-function: cubic-bezier(0.08, 0.52, 0.52, 1);
51
51
 
52
52
  -webkit-user-select: none;
@@ -85,8 +85,8 @@
85
85
  padding: 0.5rem 1rem;
86
86
  font-size: 12px;
87
87
  transition-property: color, background, border-color, box-shadow;
88
- transition-duration: 100ms, 100ms, 100ms,
89
- var(--ifm-button-transition-duration);
88
+ transition-duration:
89
+ 100ms, 100ms, 100ms, var(--ifm-button-transition-duration);
90
90
  transition-timing-function: cubic-bezier(0.08, 0.52, 0.52, 1);
91
91
  user-select: none;
92
92
  white-space: nowrap;
@@ -158,15 +158,36 @@ function Request({ item }) {
158
158
  paramsArray.push(param);
159
159
  });
160
160
  const methods = (0, react_hook_form_1.useForm)({ shouldFocusError: false });
161
+ const handleEventStream = async (res) => {
162
+ res.headers &&
163
+ dispatch((0, slice_1.setHeaders)(Object.fromEntries(res.headers)));
164
+ dispatch((0, slice_1.setCode)(res.status));
165
+ const reader = res.body.getReader();
166
+ const decoder = new TextDecoder();
167
+ let result = "";
168
+ while (true) {
169
+ const { done, value } = await reader.read();
170
+ if (done) break;
171
+ result += decoder.decode(value, { stream: true });
172
+ dispatch((0, slice_1.setResponse)(result));
173
+ }
174
+ };
175
+ const handleResponse = async (res) => {
176
+ dispatch((0, slice_1.setResponse)(await res.text()));
177
+ dispatch((0, slice_1.setCode)(res.status));
178
+ res.headers &&
179
+ dispatch((0, slice_1.setHeaders)(Object.fromEntries(res.headers)));
180
+ };
161
181
  const onSubmit = async (data) => {
162
182
  dispatch((0, slice_1.setResponse)("Fetching..."));
163
183
  try {
164
184
  await delay(1200);
165
185
  const res = await (0, makeRequest_1.default)(postmanRequest, proxy, body);
166
- dispatch((0, slice_1.setResponse)(await res.text()));
167
- dispatch((0, slice_1.setCode)(res.status));
168
- res.headers &&
169
- dispatch((0, slice_1.setHeaders)(Object.fromEntries(res.headers)));
186
+ if (res.headers.get("content-type")?.includes("text/event-stream")) {
187
+ await handleEventStream(res);
188
+ } else {
189
+ await handleResponse(res);
190
+ }
170
191
  } catch (e) {
171
192
  console.log(e);
172
193
  dispatch((0, slice_1.setResponse)("Connection failed"));
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-989",
4
+ "version": "0.0.0-996",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -36,7 +36,7 @@
36
36
  "@types/lodash": "^4.14.176",
37
37
  "@types/pako": "^2.0.3",
38
38
  "concurrently": "^5.2.0",
39
- "docusaurus-plugin-openapi-docs": "0.0.0-989",
39
+ "docusaurus-plugin-openapi-docs": "0.0.0-996",
40
40
  "docusaurus-plugin-sass": "^0.2.3",
41
41
  "eslint-plugin-prettier": "^5.0.1"
42
42
  },
@@ -79,5 +79,5 @@
79
79
  "engines": {
80
80
  "node": ">=14"
81
81
  },
82
- "gitHead": "c6aa1f9066187180826016bc9ebe19b1bd3ff9f8"
82
+ "gitHead": "b6caef9cf6765bef67b15261222df6730f578a3d"
83
83
  }
@@ -237,8 +237,7 @@ function Body({
237
237
  try {
238
238
  // If the value is already valid JSON we shouldn't double encode the value
239
239
  JSON.parse(example.value);
240
- }
241
- catch (e) {
240
+ } catch (e) {
242
241
  body = JSON.stringify(example.value, null, 2);
243
242
  }
244
243
 
@@ -13,7 +13,8 @@
13
13
 
14
14
  &:hover {
15
15
  border: 2px dashed var(--ifm-color-primary);
16
- background: linear-gradient(
16
+ background:
17
+ linear-gradient(
17
18
  var(--openapi-dropzone-hover-shim),
18
19
  var(--openapi-dropzone-hover-shim)
19
20
  ),
@@ -38,7 +39,8 @@
38
39
  font-size: var(--ifm-code-font-size);
39
40
  border: 2px dashed var(--ifm-color-primary);
40
41
 
41
- background: linear-gradient(
42
+ background:
43
+ linear-gradient(
42
44
  var(--openapi-dropzone-hover-shim),
43
45
  var(--openapi-dropzone-hover-shim)
44
46
  ),
@@ -45,8 +45,8 @@
45
45
  line-height: 1.5;
46
46
 
47
47
  transition-property: color, background, border-color, box-shadow;
48
- transition-duration: 100ms, 100ms, 100ms,
49
- var(--ifm-button-transition-duration);
48
+ transition-duration:
49
+ 100ms, 100ms, 100ms, var(--ifm-button-transition-duration);
50
50
  transition-timing-function: cubic-bezier(0.08, 0.52, 0.52, 1);
51
51
 
52
52
  -webkit-user-select: none;
@@ -85,8 +85,8 @@
85
85
  padding: 0.5rem 1rem;
86
86
  font-size: 12px;
87
87
  transition-property: color, background, border-color, box-shadow;
88
- transition-duration: 100ms, 100ms, 100ms,
89
- var(--ifm-button-transition-duration);
88
+ transition-duration:
89
+ 100ms, 100ms, 100ms, var(--ifm-button-transition-duration);
90
90
  transition-timing-function: cubic-bezier(0.08, 0.52, 0.52, 1);
91
91
  user-select: none;
92
92
  white-space: nowrap;
@@ -95,14 +95,37 @@ function Request({ item }: { item: ApiItem }) {
95
95
 
96
96
  const methods = useForm({ shouldFocusError: false });
97
97
 
98
+ const handleEventStream = async (res) => {
99
+ res.headers && dispatch(setHeaders(Object.fromEntries(res.headers)));
100
+ dispatch(setCode(res.status));
101
+
102
+ const reader = res.body.getReader();
103
+ const decoder = new TextDecoder();
104
+ let result = "";
105
+ while (true) {
106
+ const { done, value } = await reader.read();
107
+ if (done) break;
108
+ result += decoder.decode(value, { stream: true });
109
+ dispatch(setResponse(result));
110
+ }
111
+ };
112
+
113
+ const handleResponse = async (res) => {
114
+ dispatch(setResponse(await res.text()));
115
+ dispatch(setCode(res.status));
116
+ res.headers && dispatch(setHeaders(Object.fromEntries(res.headers)));
117
+ };
118
+
98
119
  const onSubmit = async (data) => {
99
120
  dispatch(setResponse("Fetching..."));
100
121
  try {
101
122
  await delay(1200);
102
123
  const res = await makeRequest(postmanRequest, proxy, body);
103
- dispatch(setResponse(await res.text()));
104
- dispatch(setCode(res.status));
105
- res.headers && dispatch(setHeaders(Object.fromEntries(res.headers)));
124
+ if (res.headers.get("content-type")?.includes("text/event-stream")) {
125
+ await handleEventStream(res);
126
+ } else {
127
+ await handleResponse(res);
128
+ }
106
129
  } catch (e: any) {
107
130
  console.log(e);
108
131
  dispatch(setResponse("Connection failed"));