Skip to content

Commit 3eb71bb

Browse files
authored
Merge branch 'main' into resolve-issue-136
2 parents b9750ef + 3148c5a commit 3eb71bb

File tree

70 files changed

+10961
-1969
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+10961
-1969
lines changed

.github/pull_request_template.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ _We encourage you to add relevant test cases._
1616

1717
- [ ] Yes
1818
- [ ] No, and this is why: _please replace this line with details on why tests have not been included_
19-
- [ ] I need help with writing tests

CONTRIBUTING.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,23 @@ flutter test test/widgets/codegen_previewer_test.dart
128128
### How to add a new package to pubspec.yaml?
129129

130130
Instead of copy pasting from pub.dev, it is recommended that you use `flutter pub add package_name` to add a new package to `pubspec.yaml`. You can read more [here](https://docs.flutter.dev/packages-and-plugins/using-packages#adding-a-package-dependency-to-an-app-using-flutter-pub-add).
131+
132+
## Troubleshooting Common Issues
133+
134+
### Network Connection Issues on macOS
135+
136+
If you encounter a network connection error similar to the following while running your Flutter app on macOS:
137+
138+
```
139+
ClientException with SocketException: Connection failed (OS Error: Operation not permitted, errno = 1)
140+
```
141+
Add below key to `macos/Runner/DebugProfile.entitlements` and `macos/Runner/Release.entitlements`.
142+
143+
```
144+
<key>com.apple.security.network.client</key>
145+
<true/>
146+
```
147+
148+
You can read more [here](https://docs.flutter.dev/platform-integration/macos/building#setting-up-entitlements)
149+
150+

README.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22

33
[![Discord Server Invite](https://img.shields.io/badge/DISCORD-JOIN%20SERVER-5663F7?style=for-the-badge&logo=discord&logoColor=white)](https://bit.ly/heyfoss)
44

5-
We are participating in GSoC 2024 🎉 [More Details ...](https://summerofcode.withgoogle.com/programs/2024/organizations/api-dash)
5+
🚨 We are participating in GSoC 2024 🎉
6+
7+
<img src="https://github.com/foss42/apidash/assets/615622/493ce57f-06c3-4789-b7ae-9fa63bca8183" alt="GSoC" width="500">
8+
9+
| | Link |
10+
|--|--|
11+
| Learn about GSoC | [Link](https://summerofcode.withgoogle.com) |
12+
| Organization page on GSoC | [Link](https://summerofcode.withgoogle.com/programs/2024/organizations/api-dash) |
13+
| Project Ideas List | [Link](https://github.com/foss42/apidash/discussions/112) |
14+
| Application Guide | [Link](https://github.com/foss42/apidash/discussions/111) |
15+
| Discord Channel | [Link](https://discord.com/invite/2s49SCNfyJ) |
616

717
### Please support this initiative by giving this project a Star ⭐️
818

@@ -125,6 +135,7 @@ API Dash currently supports API integration code generation for the following la
125135
| Python | `http.client` |
126136
| Python | `requests` |
127137
| Kotlin | `okhttp3` |
138+
| Java | `okhttp3` |
128139

129140
We welcome contributions to support other programming languages/libraries/frameworks. Please check out more details [here](https://github.com/foss42/apidash/discussions/80).
130141

@@ -137,6 +148,7 @@ Here is the complete list of mimetypes that can be directly previewed in API Das
137148
| File Type | Mimetype | Extension | Comment |
138149
| --------- | -------------------------- | ----------------- | -------- |
139150
| PDF | `application/pdf` | `.pdf` | |
151+
| CSV | `text/csv` | `.csv` | Can be improved |
140152
| Image | `image/apng` | `.apng` | Animated |
141153
| Image | `image/avif` | `.avif` | |
142154
| Image | `image/bmp` | `.bmp` | |
@@ -177,14 +189,14 @@ Here is the complete list of mimetypes that are syntax highlighted in API Dash:
177189
| ------------------ | --------- | ------------------------------------------------------------------------------------------------------------------ |
178190
| `application/json` | `.json` | Other mimetypes like `application/geo+json`, `application/vcard+json` that are based on `json` are also supported. |
179191
| `application/xml` | `.xml` | Other mimetypes like `application/xhtml+xml`, `application/vcard+xml` that are based on `xml` are also supported. |
180-
| `text/xml` | `.xml` | |
181-
| `application/yaml` | `.yaml` | Others - `application/x-yaml` or `application/x-yml` |
182-
| `text/yaml` | `.yaml` | Others - `text/yml` |
183-
| `application/sql` | `.sql` | |
184-
| `text/css` | `.css` | |
185-
| `text/html` | `.html` | Only syntax highlighting, no web preview. |
186-
| `text/javascript` | `.js` | |
187-
| `text/markdown` | `.md` | |
192+
| `text/xml` | `.xml` | |
193+
| `application/yaml` | `.yaml` | Others - `application/x-yaml` or `application/x-yml` |
194+
| `text/yaml` | `.yaml` | Others - `text/yml` |
195+
| `application/sql` | `.sql` | |
196+
| `text/css` | `.css` | |
197+
| `text/html` | `.html` | Only syntax highlighting, no web preview. |
198+
| `text/javascript` | `.js` | |
199+
| `text/markdown` | `.md` | |
188200

189201
## What's new in v0.3.0?
190202

lib/codegen/codegen.dart

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,78 @@
11
import 'package:apidash/models/models.dart' show RequestModel;
22
import 'package:apidash/consts.dart';
3+
import 'package:apidash/utils/utils.dart' show getNewUuid;
34
import 'dart/http.dart';
45
import 'dart/dio.dart';
6+
import 'go/http.dart';
57
import 'kotlin/okhttp.dart';
68
import 'python/http_client.dart';
79
import 'python/requests.dart';
8-
import 'java/async_http_client.dart';
10+
import 'rust/actix.dart';
11+
import 'rust/reqwest.dart';
12+
import 'rust/ureq.dart';
913
import 'js/axios.dart';
1014
import 'js/fetch.dart';
1115
import 'others/har.dart';
1216
import 'others/curl.dart';
17+
import 'julia/http.dart';
18+
import 'java/okhttp.dart';
19+
import 'java/async_http_client.dart';
1320

1421
class Codegen {
1522
String? getCode(
1623
CodegenLanguage codegenLanguage,
1724
RequestModel requestModel,
18-
String defaultUriScheme,
19-
) {
25+
String defaultUriScheme, {
26+
String? boundary,
27+
}) {
28+
String url = requestModel.url;
29+
30+
if (url.isEmpty) {
31+
url = kDefaultUri;
32+
}
33+
if (!url.contains("://") && url.isNotEmpty) {
34+
url = "$defaultUriScheme://$url";
35+
}
36+
var rM = requestModel.copyWith(url: url);
37+
2038
switch (codegenLanguage) {
2139
case CodegenLanguage.curl:
22-
return cURLCodeGen().getCode(requestModel, defaultUriScheme);
40+
return cURLCodeGen().getCode(rM);
2341
case CodegenLanguage.har:
24-
return HARCodeGen().getCode(requestModel, defaultUriScheme);
42+
return HARCodeGen().getCode(rM, defaultUriScheme, boundary: boundary);
2543
case CodegenLanguage.dartHttp:
26-
return DartHttpCodeGen().getCode(requestModel, defaultUriScheme);
44+
return DartHttpCodeGen().getCode(rM);
2745
case CodegenLanguage.dartDio:
28-
return DartDioCodeGen().getCode(requestModel, defaultUriScheme);
46+
return DartDioCodeGen().getCode(rM);
2947
case CodegenLanguage.jsAxios:
30-
return AxiosCodeGen().getCode(requestModel, defaultUriScheme);
48+
return AxiosCodeGen().getCode(rM);
3149
case CodegenLanguage.jsFetch:
32-
return FetchCodeGen().getCode(requestModel, defaultUriScheme);
50+
return FetchCodeGen().getCode(rM);
3351
case CodegenLanguage.nodejsAxios:
34-
return AxiosCodeGen(isNodeJs: true)
35-
.getCode(requestModel, defaultUriScheme);
52+
return AxiosCodeGen(isNodeJs: true).getCode(rM);
3653
case CodegenLanguage.nodejsFetch:
37-
return FetchCodeGen(isNodeJs: true)
38-
.getCode(requestModel, defaultUriScheme);
54+
return FetchCodeGen(isNodeJs: true).getCode(rM);
3955
case CodegenLanguage.kotlinOkHttp:
40-
return KotlinOkHttpCodeGen().getCode(requestModel, defaultUriScheme);
56+
return KotlinOkHttpCodeGen().getCode(rM);
57+
case CodegenLanguage.javaOkHttp:
58+
return JavaOkHttpCodeGen().getCode(rM);
4159
case CodegenLanguage.pythonHttpClient:
4260
return PythonHttpClientCodeGen()
43-
.getCode(requestModel, defaultUriScheme);
61+
.getCode(rM, boundary: boundary ?? getNewUuid());
4462
case CodegenLanguage.pythonRequests:
45-
return PythonRequestsCodeGen().getCode(requestModel, defaultUriScheme);
63+
return PythonRequestsCodeGen().getCode(rM, boundary: boundary);
64+
case CodegenLanguage.rustActix:
65+
return RustActixCodeGen().getCode(rM, boundary: boundary);
66+
case CodegenLanguage.rustReqwest:
67+
return RustReqwestCodeGen().getCode(rM);
68+
case CodegenLanguage.rustUreq:
69+
return RustUreqCodeGen().getCode(rM, boundary: boundary);
70+
case CodegenLanguage.goHttp:
71+
return GoHttpCodeGen().getCode(rM);
72+
case CodegenLanguage.juliaHttp:
73+
return JuliaHttpClientCodeGen().getCode(rM);
4674
case CodegenLanguage.javaAsyncHttpClient:
47-
return JavaAsyncHttpClientGen().getCode(requestModel, defaultUriScheme);
75+
return JavaAsyncHttpClientGen().getCode(rM);
4876
}
4977
}
5078
}

lib/codegen/codegen_utils.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
String jsonToPyDict(String jsonString) {
2+
Map<String, String> replaceWithMap = {
3+
"null": "None",
4+
"true": "True",
5+
"false": "False"
6+
};
7+
String pyDict = jsonString;
8+
for (var k in replaceWithMap.keys) {
9+
RegExp regExp = RegExp(k + r'(?=([^"]*"[^"]*")*[^"]*$)');
10+
pyDict = pyDict.replaceAllMapped(regExp, (match) {
11+
return replaceWithMap[match.group(0)] ?? match.group(0)!;
12+
});
13+
}
14+
return pyDict;
15+
}

lib/codegen/dart/dio.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,10 @@ import 'shared.dart';
88
class DartDioCodeGen {
99
String? getCode(
1010
RequestModel requestModel,
11-
String defaultUriScheme,
1211
) {
1312
try {
14-
String url = requestModel.url;
15-
if (!url.contains("://") && url.isNotEmpty) {
16-
url = "$defaultUriScheme://$url";
17-
}
1813
final next = generatedDartCode(
19-
url: url,
14+
url: requestModel.url,
2015
method: requestModel.method,
2116
queryParams: requestModel.enabledParamsMap,
2217
headers: requestModel.enabledHeadersMap,
@@ -60,12 +55,17 @@ class DartDioCodeGen {
6055
final List<Map<String,String>> formDataList = ${json.encode(formData)};
6156
for (var formField in formDataList) {
6257
if (formField['type'] == 'file') {
63-
formData.files.add(MapEntry(
64-
formField['name'],
65-
await MultipartFile.fromFile(formField['value'], filename: formField['value']),
58+
if (formField['value'] != null) {
59+
data.files.add(MapEntry(
60+
formField['name']!,
61+
await dio.MultipartFile.fromFile(formField['value']!,
62+
filename: formField['value']!),
6663
));
64+
}
6765
} else {
68-
formData.fields.add(MapEntry(formField['name'], formField['value']));
66+
if (formField['value'] != null) {
67+
data.fields.add(MapEntry(formField['name']!, formField['value']!));
68+
}
6969
}
7070
}
7171
''');
@@ -84,16 +84,16 @@ class DartDioCodeGen {
8484
dataExp = declareFinal('data').assign(strContent);
8585
// when add new type of [ContentType], need update [dataExp].
8686
case ContentType.formdata:
87-
dataExp = declareFinal('data').assign(refer('FormData()'));
87+
dataExp = declareFinal('data').assign(refer('dio.FormData()'));
8888
}
8989
}
9090
final responseExp = declareFinal('response').assign(InvokeExpression.newOf(
91-
refer('dio.Dio'),
91+
refer('dio.Dio()'),
9292
[literalString(url)],
9393
{
9494
if (queryParamExp != null) 'queryParameters': refer('queryParams'),
9595
if (headerExp != null)
96-
'options': refer('Options').newInstance(
96+
'options': refer('dio.Options').newInstance(
9797
[],
9898
{'headers': refer('headers')},
9999
),
@@ -117,7 +117,7 @@ class DartDioCodeGen {
117117
refer('print').call([refer('response').property('data')]),
118118
],
119119
onError: {
120-
'DioException': [
120+
'dio.DioException': [
121121
refer('print').call([
122122
refer('e').property('response').nullSafeProperty('statusCode'),
123123
]),

lib/codegen/dart/http.dart

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,10 @@ import 'shared.dart';
99
class DartHttpCodeGen {
1010
String? getCode(
1111
RequestModel requestModel,
12-
String defaultUriScheme,
1312
) {
1413
try {
15-
String url = requestModel.url;
16-
if (!url.contains("://") && url.isNotEmpty) {
17-
url = "$defaultUriScheme://$url";
18-
}
1914
final next = generatedDartCode(
20-
url: url,
15+
url: requestModel.url,
2116
method: requestModel.method,
2217
queryParams: requestModel.enabledParamsMap,
2318
headers: {...requestModel.enabledHeadersMap},
@@ -53,7 +48,9 @@ class DartHttpCodeGen {
5348
declareVar('uri').assign(refer('Uri.parse').call([literalString(url)]));
5449

5550
Expression? dataExp;
56-
if (kMethodsWithBody.contains(method) && (body?.isNotEmpty ?? false)) {
51+
if (kMethodsWithBody.contains(method) &&
52+
(body?.isNotEmpty ?? false) &&
53+
contentType != ContentType.formdata) {
5754
final strContent = CodeExpression(Code('r\'\'\'$body\'\'\''));
5855
dataExp = declareVar('body', type: refer('String')).assign(strContent);
5956
if (!hasContentTypeHeader) {
@@ -125,17 +122,29 @@ class DartHttpCodeGen {
125122

126123
final addHeaders = refer('request.headers.addAll').call([refer('headers')]);
127124
const multiPartList = Code('''
128-
for (Map<String, String> formData in formDataList){
129-
if (formData['type'] == 'text') {
130-
request.fields.addAll({formData['name']: formData['value']});
131-
} else {
132-
request.files.add(
133-
await http.MultipartFile.fromPath(
134-
formData['name'],
135-
formData['value'],
136-
),
137-
);
138-
}
125+
for (var formData in formDataList) {
126+
if (formData != null) {
127+
final name = formData['name'];
128+
final value = formData['value'];
129+
final type = formData['type'];
130+
131+
if (name != null && value != null && type != null) {
132+
if (type == 'text') {
133+
request.fields.addAll({name: value});
134+
} else {
135+
request.files.add(
136+
await http.MultipartFile.fromPath(
137+
name,
138+
value,
139+
),
140+
);
141+
}
142+
} else {
143+
print('Error: formData has null name, value, or type.');
144+
}
145+
} else {
146+
print('Error: formData is null.');
147+
}
139148
}
140149
''');
141150
var multiPartRequestSend =

0 commit comments

Comments
 (0)