This commit is contained in:
Ankit Mahato
2024-03-15 04:50:32 +05:30
parent 5b28debd35
commit 3e2cc90263
2 changed files with 5 additions and 4 deletions

View File

@ -12,7 +12,7 @@ class FetchCodeGen {
String kStringImportNode = """
import fetch from 'node-fetch'
{% if hasFormData -%}
import { fileFromSync, FormData } from 'node-fetch'
import { {% if hasFileInFormData %}fileFromSync, {% endif %}FormData } from 'node-fetch'
{% endif %}
""";
@ -57,6 +57,7 @@ fetch(url, options)
jj.Template kNodejsImportTemplate = jj.Template(kStringImportNode);
String importsData = kNodejsImportTemplate.render({
"hasFormData": requestModel.hasFormData,
"hasFileInFormData": requestModel.hasFileInFormData,
});
String result = isNodeJs

View File

@ -502,7 +502,7 @@ fetch(url, options)
});
test('POST 4', () {
const expectedCode = r"""import fetch from 'node-fetch'
import { fileFromSync, FormData } from 'node-fetch'
import { FormData } from 'node-fetch'
const payload = new FormData();
payload.append("text", "API")
@ -537,7 +537,7 @@ fetch(url, options)
test('POST 5', () {
const expectedCode = r"""import fetch from 'node-fetch'
import { fileFromSync, FormData } from 'node-fetch'
import { FormData } from 'node-fetch'
const payload = new FormData();
payload.append("text", "API")
@ -640,7 +640,7 @@ fetch(url, options)
});
test('POST 8', () {
const expectedCode = r"""import fetch from 'node-fetch'
import { fileFromSync, FormData } from 'node-fetch'
import { FormData } from 'node-fetch'
const payload = new FormData();
payload.append("text", "API")