Merge remote-tracking branch 'upstream/main' into add-rust-ureq-codegen

- Merged upstream
- Made required changes with respect to upstream
- Fixed tests
This commit is contained in:
Tanish2002
2024-03-12 18:19:30 +05:30
69 changed files with 2644 additions and 1266 deletions

View File

@ -109,9 +109,9 @@ multipart/form-data; boundary={{boundary}}''';
""";
String? getCode(
RequestModel requestModel,
String defaultUriScheme,
) {
RequestModel requestModel, {
String? boundary,
}) {
try {
String result = "";
bool hasBody = false;
@ -119,9 +119,6 @@ multipart/form-data; boundary={{boundary}}''';
String uuid = getNewUuid();
String url = requestModel.url;
if (!url.contains("://") && url.isNotEmpty) {
url = "$defaultUriScheme://$url";
}
var rec = getValidRequestUri(
url,
@ -132,7 +129,7 @@ multipart/form-data; boundary={{boundary}}''';
var templateStartUrl = jj.Template(kTemplateStart);
result += templateStartUrl.render({
"url": stripUriParams(uri),
'isFormDataRequest': requestModel.isFormDataRequest,
'isFormDataRequest': requestModel.hasFormData,
"method": requestModel.method.name.toLowerCase()
});
@ -145,7 +142,7 @@ multipart/form-data; boundary={{boundary}}''';
hasJsonBody = true;
var templateBody = jj.Template(kTemplateJson);
result += templateBody.render({"body": requestBody});
} else if (!requestModel.isFormDataRequest) {
} else if (!requestModel.hasFormData) {
hasBody = true;
var templateBody = jj.Template(kTemplateBody);
result += templateBody.render({"body": requestBody});
@ -153,12 +150,12 @@ multipart/form-data; boundary={{boundary}}''';
}
}
if (requestModel.isFormDataRequest) {
if (requestModel.hasFormData) {
var formDataBodyData = jj.Template(kStringFormDataBody);
result += formDataBodyData.render(
{
"fields_list": requestModel.formDataMapList,
"boundary": uuid,
"boundary": boundary ?? uuid,
},
);
}
@ -176,13 +173,13 @@ multipart/form-data; boundary={{boundary}}''';
}
var headersList = requestModel.enabledRequestHeaders;
if (headersList != null || hasBody || requestModel.isFormDataRequest) {
if (headersList != null || hasBody || requestModel.hasFormData) {
var headers = requestModel.enabledHeadersMap;
if (requestModel.isFormDataRequest) {
if (requestModel.hasFormData) {
var formHeaderTemplate =
jj.Template(kTemplateFormHeaderContentType);
headers[HttpHeaders.contentTypeHeader] = formHeaderTemplate.render({
"boundary": uuid,
"boundary": boundary ?? uuid,
});
} else if (hasBody) {
headers[HttpHeaders.contentTypeHeader] =
@ -194,7 +191,7 @@ multipart/form-data; boundary={{boundary}}''';
result += templateHeaders.render({"headers": headers});
}
}
if (requestModel.isFormDataRequest) {
if (requestModel.hasFormData) {
result += kStringRequestForm;
} else if (hasBody) {
result += kStringRequestBody;