* fixes rght body type not selected after curlimport * added apiContentType key in ActionConfiguration formData property This commit fixes the bug https://github.com/appsmithorg/appsmith/issues/13978 and changes two files: * appsmith-server/src/test/java/com/appsmith/server/services/CurlImporterServiceTest.java * appsmith-server/src/main/java/com/appsmith/server/services/ce/CurlImporterServiceCEImpl.java additionaly this commit fixes the Body type detection for REST APIs with GET method when imported from cURL. * Made changes to the casing of Header key 'content-type', now it is HTTPHeader.CONTENT_TYPE standard -> 'Content-Type'. changed test cases accordingly. * Made header-key check in assertHeader functions case insensitive in CurlImporterServiceTest.java * removed wildcard imports and changed some comments * changes according to PR review comments * updated imports for APIPaneUtils Co-authored-by: “sneha122” <“sneha@appsmith.com”> Co-authored-by: manish kumar <manish@appsmith.com>
61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
import { CONTENT_TYPE_HEADER_KEY } from "constants/ApiEditorConstants/CommonApiConstants";
|
|
|
|
/**
|
|
* This function updates the header at a given index.
|
|
* If headerIndexToUpdate is -1, i.e the header we are looking for is not present, then
|
|
* update the header key-value pair in the first non-empty row
|
|
* @param headers
|
|
* @param headerIndexToUpdate
|
|
* @returns
|
|
*/
|
|
export const getIndextoUpdate = (headers: any, headerIndexToUpdate: number) => {
|
|
const firstEmptyHeaderRowIndex: number = headers.findIndex(
|
|
(element: { key: string; value: string }) =>
|
|
element && element.key === "" && element.value === "",
|
|
);
|
|
const newHeaderIndex =
|
|
firstEmptyHeaderRowIndex > -1 ? firstEmptyHeaderRowIndex : headers.length;
|
|
const indexToUpdate =
|
|
headerIndexToUpdate > -1 ? headerIndexToUpdate : newHeaderIndex;
|
|
return indexToUpdate;
|
|
};
|
|
|
|
export const queryParamsRegEx = /([\s\S]*?)(\?(?![^{]*})[\s\S]*)?$/;
|
|
|
|
export function parseUrlForQueryParams(url: string) {
|
|
const padQueryParams = { key: "", value: "" };
|
|
let params = Array(2).fill(padQueryParams);
|
|
const matchGroup = url.match(queryParamsRegEx) || [];
|
|
const parsedUrlWithQueryParams = matchGroup[2] || "";
|
|
if (parsedUrlWithQueryParams.indexOf("?") > -1) {
|
|
const paramsString = parsedUrlWithQueryParams.slice(
|
|
parsedUrlWithQueryParams.indexOf("?") + 1,
|
|
);
|
|
params = paramsString.split("&").map((p) => {
|
|
const firstEqualPos = p.indexOf("=");
|
|
const keyValue =
|
|
firstEqualPos > -1
|
|
? [p.substring(0, firstEqualPos), p.substring(firstEqualPos + 1)]
|
|
: [];
|
|
return { key: keyValue[0] || "", value: keyValue[1] || "" };
|
|
});
|
|
}
|
|
return params;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param headers Array of key value pairs
|
|
* @returns string body type of API request
|
|
*/
|
|
export function getContentTypeHeaderValue(
|
|
headers: Array<{ key: string; value: string }>,
|
|
): string {
|
|
return (
|
|
headers.find(
|
|
(h: { key: string; value: string }) =>
|
|
h.key?.trim().toLowerCase() === CONTENT_TYPE_HEADER_KEY,
|
|
)?.value || ""
|
|
);
|
|
}
|