@@ -761,22 +761,52 @@ class QueryListComp extends QueryListTmpComp implements BottomResListComp {
761
761
762
762
// If this is a REST API created from cURL, pre-populate the HTTP query fields
763
763
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 } ) )
766
773
: [ { 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 } ) )
769
777
: [ { key : "" , value : "" } ] ;
770
778
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
+
771
798
payload = {
772
799
...payload ,
773
800
comp : {
774
801
httpMethod : curlData . method || "GET" ,
775
- path : curlData . url || "" ,
802
+ path : curlData . url || curlData . path || "" ,
776
803
headers : headersArr ,
777
804
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 || "" ,
780
810
bodyFormData : [ { key : "" , value : "" , type : "text" } ] ,
781
811
} ,
782
812
} ;
0 commit comments