@publier/openapi 0.4.0 → 0.4.2
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@publier/openapi",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@publier/native": "8.0.
|
|
48
|
+
"@publier/native": "8.0.2",
|
|
49
49
|
"@readme/httpsnippet": "^11.1.0",
|
|
50
50
|
"openapi-sampler": "^1.7.3",
|
|
51
51
|
"yaml": "^2.9.0"
|
|
@@ -81,12 +81,17 @@ export class PublierApiPlayground extends HTMLElement {
|
|
|
81
81
|
const rawBody = String(data.get('body') ?? '');
|
|
82
82
|
if (!['GET', 'HEAD'].includes(method) && rawBody) {
|
|
83
83
|
const media = String(data.get('content-type') ?? 'application/json');
|
|
84
|
-
|
|
84
|
+
const mediaType = media.split(';', 1)[0]?.trim().toLowerCase();
|
|
85
|
+
if (
|
|
86
|
+
mediaType === 'multipart/form-data' ||
|
|
87
|
+
mediaType === 'application/x-www-form-urlencoded'
|
|
88
|
+
) {
|
|
85
89
|
const fields: unknown = JSON.parse(rawBody);
|
|
86
90
|
if (!fields || typeof fields !== 'object' || Array.isArray(fields)) {
|
|
87
91
|
throw new Error('Form bodies must be a JSON object of scalar fields.');
|
|
88
92
|
}
|
|
89
|
-
const encoded =
|
|
93
|
+
const encoded =
|
|
94
|
+
mediaType === 'multipart/form-data' ? new FormData() : new URLSearchParams();
|
|
90
95
|
for (const [key, value] of Object.entries(fields)) {
|
|
91
96
|
if (value !== null && typeof value === 'object')
|
|
92
97
|
throw new Error('Form fields must be scalar values.');
|
|
@@ -94,7 +99,7 @@ export class PublierApiPlayground extends HTMLElement {
|
|
|
94
99
|
}
|
|
95
100
|
body = encoded;
|
|
96
101
|
|
|
97
|
-
if (
|
|
102
|
+
if (mediaType === 'multipart/form-data') headers.delete('Content-Type');
|
|
98
103
|
else headers.set('Content-Type', media);
|
|
99
104
|
} else {
|
|
100
105
|
body = rawBody;
|