Merge branch 'main' into add-feature-scripts

This commit is contained in:
Ankit Mahato
2025-06-21 20:39:25 +05:30
committed by GitHub
27 changed files with 314 additions and 60 deletions

View File

@@ -30,6 +30,8 @@ final kSupportedUriSchemes =
SupportedUriSchemes.values.map((i) => i.name).toList();
const kDefaultUriScheme = SupportedUriSchemes.https;
final kLocalhostRegex = RegExp(r'^localhost(:\d+)?(/.*)?$');
final kIPHostRegex =
RegExp(r'^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}(:\d+)?(/.*)?$');
const kMethodsWithBody = [
HTTPVerb.post,

View File

@@ -2,6 +2,7 @@ import 'package:apidash_core/consts.dart';
import 'package:seed/seed.dart';
import '../models/models.dart';
import 'graphql_utils.dart';
import 'package:json5/json5.dart' as json5;
Map<String, String>? rowsToMap(
List<NameValueModel>? kvRows, {
@@ -100,3 +101,14 @@ String? getRequestBody(APIType type, HttpRequestModel httpRequestModel) {
APIType.graphql => getGraphQLBody(httpRequestModel),
};
}
// TODO: Expose this function to remove JSON comments
String? removeJsonComments(String? json) {
try {
if (json == null) return null;
var parsed = json5.json5Decode(json);
return kJsonEncoder.convert(parsed);
} catch (e) {
return json;
}
}

View File

@@ -30,9 +30,10 @@ String stripUrlParams(String url) {
return (null, "URL is missing!");
}
if (kLocalhostRegex.hasMatch(url)) {
if (kLocalhostRegex.hasMatch(url) || kIPHostRegex.hasMatch(url)) {
url = '${SupportedUriSchemes.http.name}://$url';
}
Uri? uri = Uri.tryParse(url);
if (uri == null) {
return (null, "Check URL (malformed)");