Bug/body missing onimport (#2048)
Co-authored-by: liyasthomas <liyascthomas@gmail.com>
This commit is contained in:
@@ -277,6 +277,7 @@ const createCollectionGist = async () => {
|
|||||||
|
|
||||||
const fileImported = () => {
|
const fileImported = () => {
|
||||||
toast.success(t("state.file_imported").toString())
|
toast.success(t("state.file_imported").toString())
|
||||||
|
hideModal()
|
||||||
}
|
}
|
||||||
|
|
||||||
const failedImport = () => {
|
const failedImport = () => {
|
||||||
@@ -403,6 +404,10 @@ const parsePostmanRequest = ({
|
|||||||
headers: [] as { name?: string; type?: string }[],
|
headers: [] as { name?: string; type?: string }[],
|
||||||
params: [] as { disabled?: boolean }[],
|
params: [] as { disabled?: boolean }[],
|
||||||
bodyParams: [] as { type?: string }[],
|
bodyParams: [] as { type?: string }[],
|
||||||
|
body: {
|
||||||
|
body: "",
|
||||||
|
contentType: "application/json",
|
||||||
|
},
|
||||||
rawParams: "",
|
rawParams: "",
|
||||||
rawInput: false,
|
rawInput: false,
|
||||||
contentType: "",
|
contentType: "",
|
||||||
@@ -418,31 +423,40 @@ const parsePostmanRequest = ({
|
|||||||
if (requestObjectUrl) {
|
if (requestObjectUrl) {
|
||||||
pwRequest.url = requestObjectUrl[1]
|
pwRequest.url = requestObjectUrl[1]
|
||||||
pwRequest.path = requestObjectUrl[2] ? requestObjectUrl[2] : ""
|
pwRequest.path = requestObjectUrl[2] ? requestObjectUrl[2] : ""
|
||||||
|
} else {
|
||||||
|
pwRequest.url = request.url.raw
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pwRequest.method = request.method
|
pwRequest.method = request.method
|
||||||
const itemAuth = request.auth ? request.auth : ""
|
const itemAuth = request.auth ? request.auth : ""
|
||||||
const authType = itemAuth ? itemAuth.type : ""
|
const authType = itemAuth ? itemAuth.type : ""
|
||||||
if (authType === "basic") {
|
|
||||||
pwRequest.auth = "Basic Auth"
|
try {
|
||||||
pwRequest.httpUser =
|
if (authType === "basic") {
|
||||||
itemAuth.basic[0].key === "username"
|
pwRequest.auth = "Basic Auth"
|
||||||
? itemAuth.basic[0].value
|
pwRequest.httpUser =
|
||||||
: itemAuth.basic[1].value
|
itemAuth.basic[0].key === "username"
|
||||||
pwRequest.httpPassword =
|
? itemAuth.basic[0].value
|
||||||
itemAuth.basic[0].key === "password"
|
: itemAuth.basic[1].value
|
||||||
? itemAuth.basic[0].value
|
pwRequest.httpPassword =
|
||||||
: itemAuth.basic[1].value
|
itemAuth.basic[0].key === "password"
|
||||||
} else if (authType === "oauth2") {
|
? itemAuth.basic[0].value
|
||||||
pwRequest.auth = "OAuth 2.0"
|
: itemAuth.basic[1].value
|
||||||
pwRequest.bearerToken =
|
} else if (authType === "oauth2") {
|
||||||
itemAuth.oauth2[0].key === "accessToken"
|
pwRequest.auth = "OAuth 2.0"
|
||||||
? itemAuth.oauth2[0].value
|
pwRequest.bearerToken =
|
||||||
: itemAuth.oauth2[1].value
|
itemAuth.oauth2[0].key === "accessToken"
|
||||||
} else if (authType === "bearer") {
|
? itemAuth.oauth2[0].value
|
||||||
pwRequest.auth = "Bearer Token"
|
: itemAuth.oauth2[1].value
|
||||||
pwRequest.bearerToken = itemAuth.bearer[0].value
|
} else if (authType === "bearer") {
|
||||||
|
pwRequest.auth = "Bearer Token"
|
||||||
|
pwRequest.bearerToken = itemAuth.bearer[0].value
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestObjectHeaders = request.header
|
const requestObjectHeaders = request.header
|
||||||
if (requestObjectHeaders) {
|
if (requestObjectHeaders) {
|
||||||
pwRequest.headers = requestObjectHeaders
|
pwRequest.headers = requestObjectHeaders
|
||||||
@@ -470,6 +484,12 @@ const parsePostmanRequest = ({
|
|||||||
} else if (request.body.mode === "raw") {
|
} else if (request.body.mode === "raw") {
|
||||||
pwRequest.rawInput = true
|
pwRequest.rawInput = true
|
||||||
pwRequest.rawParams = request.body.raw
|
pwRequest.rawParams = request.body.raw
|
||||||
|
try {
|
||||||
|
const body = JSON.parse(request.body.raw)
|
||||||
|
pwRequest.body.body = JSON.stringify(body, null, 2)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return translateToNewRequest(pwRequest)
|
return translateToNewRequest(pwRequest)
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ const handleImport = () => {
|
|||||||
const endpoint = origin + pathname
|
const endpoint = origin + pathname
|
||||||
const headers: HoppRESTHeader[] = []
|
const headers: HoppRESTHeader[] = []
|
||||||
const params: HoppRESTParam[] = []
|
const params: HoppRESTParam[] = []
|
||||||
|
const body = parsedCurl.body
|
||||||
if (parsedCurl.query) {
|
if (parsedCurl.query) {
|
||||||
for (const key of Object.keys(parsedCurl.query)) {
|
for (const key of Object.keys(parsedCurl.query)) {
|
||||||
const val = parsedCurl.query[key]!
|
const val = parsedCurl.query[key]!
|
||||||
@@ -114,6 +115,7 @@ const handleImport = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const method = parsedCurl.method.toUpperCase()
|
const method = parsedCurl.method.toUpperCase()
|
||||||
|
|
||||||
setRESTRequest(
|
setRESTRequest(
|
||||||
@@ -131,7 +133,7 @@ const handleImport = () => {
|
|||||||
},
|
},
|
||||||
body: {
|
body: {
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
body: "",
|
body,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ const parseCurlCommand = (curlCommand: string) => {
|
|||||||
curlCommand = curlCommand.replace(/--request /, "-X ")
|
curlCommand = curlCommand.replace(/--request /, "-X ")
|
||||||
curlCommand = curlCommand.replace(/--header /, "-H ")
|
curlCommand = curlCommand.replace(/--header /, "-H ")
|
||||||
curlCommand = curlCommand.replace(/--url /, " ")
|
curlCommand = curlCommand.replace(/--url /, " ")
|
||||||
|
curlCommand = curlCommand.replace(/-d /, "--data ")
|
||||||
|
|
||||||
// yargs parses -XPOST as separate arguments. just prescreen for it.
|
// yargs parses -XPOST as separate arguments. just prescreen for it.
|
||||||
curlCommand = curlCommand.replace(/ -XPOST/, " -X POST")
|
curlCommand = curlCommand.replace(/ -XPOST/, " -X POST")
|
||||||
@@ -82,6 +83,12 @@ const parseCurlCommand = (curlCommand: string) => {
|
|||||||
curlCommand = curlCommand.replace(/ -XDELETE/, " -X DELETE")
|
curlCommand = curlCommand.replace(/ -XDELETE/, " -X DELETE")
|
||||||
curlCommand = curlCommand.trim()
|
curlCommand = curlCommand.trim()
|
||||||
const parsedArguments = parser(curlCommand)
|
const parsedArguments = parser(curlCommand)
|
||||||
|
|
||||||
|
const rawData =
|
||||||
|
parsedArguments.data ||
|
||||||
|
parsedArguments.dataRaw ||
|
||||||
|
parsedArguments["data-raw"]
|
||||||
|
|
||||||
let cookieString
|
let cookieString
|
||||||
let cookies
|
let cookies
|
||||||
let url = parsedArguments._[1]
|
let url = parsedArguments._[1]
|
||||||
@@ -187,6 +194,21 @@ const parseCurlCommand = (curlCommand: string) => {
|
|||||||
method = "get"
|
method = "get"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let body = ""
|
||||||
|
|
||||||
|
if (rawData) {
|
||||||
|
try {
|
||||||
|
const tempBody = JSON.parse(rawData)
|
||||||
|
if (tempBody) {
|
||||||
|
body = JSON.stringify(tempBody, null, 2)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(
|
||||||
|
"Error parsing JSON data. Please ensure that the data is valid JSON."
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const compressed = !!parsedArguments.compressed
|
const compressed = !!parsedArguments.compressed
|
||||||
let urlObject = URL.parse(url) // eslint-disable-line
|
let urlObject = URL.parse(url) // eslint-disable-line
|
||||||
|
|
||||||
@@ -227,6 +249,7 @@ const parseCurlCommand = (curlCommand: string) => {
|
|||||||
query,
|
query,
|
||||||
headers,
|
headers,
|
||||||
method,
|
method,
|
||||||
|
body,
|
||||||
cookies,
|
cookies,
|
||||||
cookieString: cookieString?.replace("Cookie: ", ""),
|
cookieString: cookieString?.replace("Cookie: ", ""),
|
||||||
multipartUploads,
|
multipartUploads,
|
||||||
|
|||||||
Reference in New Issue
Block a user