Skip to content

Commit 1e0295f

Browse files
committed
fix body issue
1 parent 850ccda commit 1e0295f

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

client/packages/lowcoder/src/comps/queries/queryComp.tsx

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -761,22 +761,52 @@ class QueryListComp extends QueryListTmpComp implements BottomResListComp {
761761

762762
// If this is a REST API created from cURL, pre-populate the HTTP query fields
763763
if (compType === "restApi" && curlData) {
764-
const headersArr = curlData.header
765-
? Object.entries(curlData.header).map(([key, value]) => ({ key, value }))
764+
// Normalize possible field names returned by different curl parsers
765+
const rawHeaders: Record<string, any> | undefined =
766+
curlData.header || curlData.headers;
767+
const rawParams: Record<string, any> | undefined =
768+
curlData.params || curlData.parameters || curlData.query;
769+
770+
// Convert headers & params objects to the key/value array expected by the UI controls
771+
const headersArr = rawHeaders
772+
? Object.entries(rawHeaders).map(([key, value]) => ({ key, value }))
766773
: [{ key: "", value: "" }];
767-
const paramsArr = curlData.params
768-
? Object.entries(curlData.params).map(([key, value]) => ({ key, value }))
774+
775+
const paramsArr = rawParams
776+
? Object.entries(rawParams).map(([key, value]) => ({ key, value }))
769777
: [{ key: "", value: "" }];
770778

779+
// Detect request body – different parsers may expose it under various keys
780+
const bodyContent: any =
781+
curlData.body ?? curlData.data ?? curlData.postData ?? undefined;
782+
783+
// Determine body type – prefer the Content-Type header if present
784+
let bodyType: string = "none";
785+
if (bodyContent !== undefined && bodyContent !== "") {
786+
const contentTypeHeader =
787+
(rawHeaders && (rawHeaders["Content-Type"] || rawHeaders["content-type"])) ||
788+
"";
789+
if (contentTypeHeader) {
790+
bodyType = contentTypeHeader;
791+
} else if (typeof bodyContent === "object") {
792+
bodyType = "application/json";
793+
} else {
794+
bodyType = "text/plain";
795+
}
796+
}
797+
771798
payload = {
772799
...payload,
773800
comp: {
774801
httpMethod: curlData.method || "GET",
775-
path: curlData.url || "",
802+
path: curlData.url || curlData.path || "",
776803
headers: headersArr,
777804
params: paramsArr,
778-
bodyType: curlData.body ? "application/json" : "none",
779-
body: curlData.body ? JSON.stringify(curlData.body, null, 2) : "",
805+
bodyType: bodyType,
806+
body:
807+
typeof bodyContent === "object"
808+
? JSON.stringify(bodyContent, null, 2)
809+
: bodyContent || "",
780810
bodyFormData: [{ key: "", value: "", type: "text" }],
781811
},
782812
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy