Skip to content

Commit

Permalink
fixes: form data & curl
Browse files Browse the repository at this point in the history
  • Loading branch information
animator committed Mar 16, 2024
1 parent 09c572c commit 9f8a745
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/codegen/others/curl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class cURLCodeGen {
} else if (requestModel.hasFormData) {
for (var formData in requestModel.formDataList) {
var templateFormData = jj.Template(kTemplateFormData);
if (formData.name.isNotEmpty && formData.value.isNotEmpty) {
if (formData.name.isNotEmpty) {
result += templateFormData.render({
"name": formData.name,
"value":
Expand Down
7 changes: 4 additions & 3 deletions lib/models/request_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ class RequestModel {
bool get hasFormData =>
kMethodsWithBody.contains(method) &&
hasFormDataContentType &&
(requestFormDataList ?? <FormDataModel>[]).isNotEmpty;
formDataMapList.isNotEmpty;
List<FormDataModel> get formDataList =>
requestFormDataList ?? <FormDataModel>[];
List<Map<String, dynamic>> get formDataMapList =>
List<Map<String, String>> get formDataMapList =>
rowsToFormDataMapList(requestFormDataList) ?? [];
bool get hasFileInFormData => formDataList
.map((e) => e.type == FormDataType.file)
Expand Down Expand Up @@ -137,6 +137,7 @@ class RequestModel {
var params = requestParams ?? this.requestParams;
var enabledHeaders = isHeaderEnabledList ?? this.isHeaderEnabledList;
var enabledParams = isParamEnabledList ?? this.isParamEnabledList;
var formDataList = requestFormDataList ?? this.requestFormDataList;
return RequestModel(
id: id ?? this.id,
method: method ?? this.method,
Expand All @@ -151,7 +152,7 @@ class RequestModel {
requestBodyContentType:
requestBodyContentType ?? this.requestBodyContentType,
requestBody: requestBody ?? this.requestBody,
requestFormDataList: requestFormDataList ?? this.requestFormDataList,
requestFormDataList: formDataList != null ? [...formDataList] : null,
responseStatus: responseStatus ?? this.responseStatus,
message: message ?? this.message,
responseModel: responseModel ?? this.responseModel,
Expand Down
19 changes: 12 additions & 7 deletions lib/utils/convert_utils.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:typed_data';
import 'dart:convert';
import 'package:collection/collection.dart';
import '../models/models.dart';
import '../consts.dart';
import 'package:http/http.dart' as http;
Expand Down Expand Up @@ -90,18 +91,22 @@ List<NameValueModel>? mapToRows(Map<String, String>? kvMap) {
return finalRows;
}

List<Map<String, dynamic>>? rowsToFormDataMapList(
List<Map<String, String>>? rowsToFormDataMapList(
List<FormDataModel>? kvRows,
) {
if (kvRows == null) {
return null;
}
List<Map<String, dynamic>> finalMap = kvRows
.map((FormDataModel formData) => {
"name": formData.name,
"value": formData.value,
"type": formData.type.name,
})
List<Map<String, String>> finalMap = kvRows
.map((FormDataModel formData) =>
(formData.name.trim().isEmpty && formData.value.trim().isEmpty)
? null
: {
"name": formData.name,
"value": formData.value,
"type": formData.type.name,
})
.whereNotNull()
.toList();
return finalMap;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/file_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ String getShortPath(String path) {

String getFilenameFromPath(String path) {
var f = p.split(path);
return f.last;
return f.lastOrNull ?? "";
}

String getTempFileName() {
Expand Down

0 comments on commit 9f8a745

Please sign in to comment.