Skip to content

Commit

Permalink
fix(core): Fix curl import error when no data
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-radency authored Mar 31, 2023
1 parent 0da3b96 commit 085660d
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions packages/cli/src/CurlConverterHelper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import curlconverter from 'curlconverter';
import get from 'lodash.get';
import type { IDataObject } from 'n8n-workflow';
import { jsonParse } from 'n8n-workflow';

interface CurlJson {
Expand Down Expand Up @@ -195,8 +196,7 @@ const extractQueries = (queries: CurlJson['queries'] = {}): HttpNodeQueries => {
};

const extractJson = (body: CurlJson['data']) =>
//@ts-ignore
jsonParse<{ [key: string]: string }>(Object.keys(body)[0]);
jsonParse<{ [key: string]: string }>(Object.keys(body as IDataObject)[0]);

const jsonBodyToNodeParameters = (body: CurlJson['data'] = {}): Parameter[] | [] => {
const data = extractJson(body);
Expand Down Expand Up @@ -410,22 +410,24 @@ export const toHttpNodeParameters = (curlCommand: string): HttpNodeParameters =>
sendBody: true,
});

const json = extractJson(curlJson.data);
if (curlJson.data) {
const json = extractJson(curlJson.data);

if (jsonHasNestedObjects(json)) {
// json body
Object.assign(httpNodeParameters, {
specifyBody: 'json',
jsonBody: JSON.stringify(json),
});
} else {
// key-value body
Object.assign(httpNodeParameters, {
specifyBody: 'keypair',
bodyParameters: {
parameters: jsonBodyToNodeParameters(curlJson.data),
},
});
if (jsonHasNestedObjects(json)) {
// json body
Object.assign(httpNodeParameters, {
specifyBody: 'json',
jsonBody: JSON.stringify(json),
});
} else {
// key-value body
Object.assign(httpNodeParameters, {
specifyBody: 'keypair',
bodyParameters: {
parameters: jsonBodyToNodeParameters(curlJson.data),
},
});
}
}
} else if (isFormUrlEncodedRequest(curlJson)) {
Object.assign(httpNodeParameters, {
Expand Down

0 comments on commit 085660d

Please sign in to comment.