Skip to content

Commit 4da5a49

Browse files
committed
Add support comments in JSON request body #599
1 parent 5245052 commit 4da5a49

File tree

5 files changed

+141
-58
lines changed

5 files changed

+141
-58
lines changed

lib/screens/home_page/editor_pane/details_card/request_pane/request_body.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:apidash/utils/convert_utils.dart';
12
import 'package:apidash_core/apidash_core.dart';
23
import 'package:apidash_design_system/apidash_design_system.dart';
34
import 'package:flutter/material.dart';
@@ -70,9 +71,10 @@ class EditRequestBody extends ConsumerWidget {
7071
initialValue: requestModel?.httpRequestModel?.body,
7172
onChanged: (String value) {
7273
// changeToPostMethod();
74+
7375
ref
7476
.read(collectionStateNotifierProvider.notifier)
75-
.update(body: value);
77+
.update(body: removeJsonComments(value));
7678
},
7779
hintText: kHintJson,
7880
),

lib/utils/convert_utils.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import 'dart:typed_data';
22
import 'dart:convert';
33
import 'package:apidash_core/apidash_core.dart';
4+
import 'package:flutter/material.dart';
45
import 'package:intl/intl.dart';
6+
import 'package:json5/json5.dart' as json5;
57

68
String humanizeDate(DateTime? date) {
79
if (date == null) {
@@ -82,3 +84,12 @@ Uint8List jsonMapToBytes(Map<String, dynamic>? map) {
8284
return bytes;
8385
}
8486
}
87+
88+
String removeJsonComments(String json) {
89+
try {
90+
var parsed = json5.json5Decode(json);
91+
return jsonEncode(parsed);
92+
} catch (e) {
93+
return json;
94+
}
95+
}

0 commit comments

Comments
 (0)