Skip to content

Commit

Permalink
Fix/multipart duplicated params (#244)
Browse files Browse the repository at this point in the history
* fix: send list params duplicatedly in multipart

* chore: bump version to 1.3.8

* fix: fix generator test

* chore: revert sdk requirement to 2.6

* ci: upgrade sdk requirement to 2.7

* chore: pin analyzer version to 0.39.14

* ci: remove test for dart 26

* ci: pin dart_style to 1.3.6
  • Loading branch information
trevorwang authored Sep 16, 2020
1 parent eafa30e commit d8061c4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 19 deletions.
16 changes: 8 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
command: |
./tool/travis.sh dartanalyzer
environment:
PKGS: "example annotation generator"
PKGS: 'example annotation generator'
- run:
command: |
cd generator
Expand All @@ -26,22 +26,22 @@ jobs:
pub get
pub run test
test_dart26:
<<: *common_test
environment:
DART_VERSION: "2.6"
test_dart27:
<<: *common_test
environment:
DART_VERSION: "2.7"
DART_VERSION: '2.7'
test_dart28:
<<: *common_test
environment:
DART_VERSION: "2.8"
DART_VERSION: '2.8'
test_dart29:
<<: *common_test
environment:
DART_VERSION: '2.9'
workflows:
version: 2
build_and_test:
jobs:
- test_dart26
- test_dart27
- test_dart28
- test_dart29
4 changes: 3 additions & 1 deletion example/lib/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ abstract class RestClient {
Future<String> postFormData(@Part() Task task, {@Part() File file});

@POST("/post")
Future<String> postFormData2(@Part() List<Map<String, dynamic>> task,
Future<String> postFormData2(
@Part() List<Map<String, dynamic>> task,
@Part() List<String> tags,
@Part(contentType: 'application/json') File file);

@POST("/post")
Expand Down
12 changes: 10 additions & 2 deletions example/lib/example.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions generator/lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -813,10 +813,12 @@ class RetrofitGenerator extends GeneratorForAnnotation<retrofit.RestApi> {
_typeChecker(BuiltMap).isExactlyType(innnerType) ||
_typeChecker(List).isExactlyType(innnerType) ||
_typeChecker(BuiltList).isExactlyType(innnerType)) {
blocks.add(refer(_dataVar).property('fields').property("add").call([
refer("MapEntry").newInstance(
[literal(fieldName), refer("jsonEncode(${p.displayName})")])
]).statement);
var value = _isBasicType(innnerType) ? 'i' : 'jsonEncode(i)';
blocks.add(refer('''
${p.displayName}?.forEach((i){
${_dataVar}.fields.add(MapEntry(${literal(fieldName)},${value}));
})
''').statement);
} else if (_typeChecker(File).isExactlyType(innnerType)) {
final conType = contentType == null
? ""
Expand Down
8 changes: 6 additions & 2 deletions generator/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: retrofit_generator
description: retrofit generator is an dio client generator using source_gen and inspired by Chopper and Retrofit.
version: 1.3.7+5
version: 1.3.8

homepage: https://mings.in/retrofit.dart/
repository: https://github.com/trevorwang/retrofit.dart/

environment:
sdk: '>=2.6.0 <3.0.0'
sdk: '>=2.7.0 <3.0.0'

dependencies:
dio: ^3.0.1
Expand All @@ -22,3 +22,7 @@ dev_dependencies:
test:
source_gen_test: any
resource:

dependency_overrides:
analyzer: '0.39.14'
dart_style: '1.3.6'
5 changes: 3 additions & 2 deletions generator/test/src/generator_test_src.dart
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,9 @@ abstract class TestFileList {
_data.fields.add(MapEntry('item', jsonEncode(user ?? <String, dynamic>{})));
''', contains: true)
@ShouldGenerate(r'''
final _data = FormData();
_data.fields.add(MapEntry('mapList', jsonEncode(mapList)));
mapList?.forEach((i) {
_data.fields.add(MapEntry('mapList', jsonEncode(i)));
});
''', contains: true)
@ShouldGenerate(r'''
final _data = FormData();
Expand Down

0 comments on commit d8061c4

Please sign in to comment.