diff --git a/generator/CHANGELOG.md b/generator/CHANGELOG.md index cb49f758..a541a839 100644 --- a/generator/CHANGELOG.md +++ b/generator/CHANGELOG.md @@ -1,6 +1,4 @@ -## 9.1.6 - -- Update `analyzer`, `dart_style` and `source_gen` dependencies to allow upper versions +# Changelog ## 9.1.5 diff --git a/generator/lib/src/generator.dart b/generator/lib/src/generator.dart index 495f1e08..936cb75c 100644 --- a/generator/lib/src/generator.dart +++ b/generator/lib/src/generator.dart @@ -131,7 +131,7 @@ class RetrofitGenerator extends GeneratorForAnnotation { }); final emitter = DartEmitter(useNullSafetySyntax: true); - return DartFormatter(languageVersion: DartFormatter.latestLanguageVersion) + return DartFormatter() .format([_analyzerIgnores, classBuilder.accept(emitter)].join('\n\n')); } @@ -1727,7 +1727,7 @@ if (T != dynamic && .assign(refer(bodyName.displayName)) .statement, ); - } else if (_missingSerialize(ele.enclosingElement3, bodyName.type)) { + } else if (_missingSerialize(ele.enclosingElement, bodyName.type)) { log.warning( '${_displayString(bodyName.type)} must provide a `serialize${_displayString(bodyName.type)}()` method which returns a Map.\n' "It is programmer's responsibility to make sure the ${_displayString(bodyName.type)} is properly serialized"); @@ -1911,7 +1911,7 @@ ${bodyName.displayName} == null blocks.add(returnCode); } if (p.type.isNullable) { - blocks.add(const Code('}')); + blocks.add(Code('}')); } } else if (_displayString(p.type) == 'List') { final optionalFile = m.parameters @@ -2278,18 +2278,10 @@ ${bodyName.displayName} == null } Object? _getFieldValue(ConstantReader? value) { - if (value?.isBool ?? false) { - return value?.boolValue; - } - if (value?.isDouble ?? false) { - return value?.doubleValue; - } - if (value?.isInt ?? false) { - return value?.intValue; - } - if (value?.isString ?? false) { - return value?.stringValue; - } + if (value?.isBool ?? false) return value?.boolValue; + if (value?.isDouble ?? false) return value?.doubleValue; + if (value?.isInt ?? false) return value?.intValue; + if (value?.isString ?? false) return value?.stringValue; if (value?.objectValue.isEnum ?? false) { return value?.objectValue.variable?.displayName; } @@ -2316,7 +2308,7 @@ ${bodyName.displayName} == null final fields = {}; final type = value!.objectValue.type; if (type is InterfaceType) { - for (final field in type.element.fields) { + for (var field in type.element.fields) { if (!field.isStatic) { final fieldValue = value.peek(field.name); fields[field.name] = _getFieldValue(fieldValue); diff --git a/generator/pubspec.yaml b/generator/pubspec.yaml index e1d0d771..7c3d276e 100644 --- a/generator/pubspec.yaml +++ b/generator/pubspec.yaml @@ -8,22 +8,22 @@ topics: - rest - retrofit - codegen -version: 9.1.6 +version: 9.1.5 environment: sdk: '>=3.3.0 <4.0.0' dependencies: - analyzer: '>=6.9.0 <8.0.0' + analyzer: ^6.5.0 build: ^2.4.1 built_collection: ^5.1.1 code_builder: ^4.10.0 - dart_style: '>=2.3.7 <4.0.0' + dart_style: ^2.3.0 dio: ^5.0.0 protobuf: ^3.1.0 - retrofit: ^4.4.1 - source_gen: '>=1.5.0 <3.0.0' + retrofit: ^4.4.0 + source_gen: ^1.5.0 dev_dependencies: - lints: any + lints: ^4.0.0 source_gen_test: ^1.0.6 test: ^1.25.0 diff --git a/generator/test/generator_test.dart b/generator/test/generator_test.dart index 3a46fdbb..7027d65c 100644 --- a/generator/test/generator_test.dart +++ b/generator/test/generator_test.dart @@ -17,7 +17,7 @@ Future main() async { RetrofitGenerator(RetrofitOptions()), defaultConfiguration: ['default'], additionalGenerators: { - 'use_result': RetrofitGenerator(RetrofitOptions(useResult: true)), + 'use_result': RetrofitGenerator(RetrofitOptions(useResult: true)) }, ); } diff --git a/generator/test/src/generator_test_src.dart b/generator/test/src/generator_test_src.dart index 5973af6d..40e28f04 100644 --- a/generator/test/src/generator_test_src.dart +++ b/generator/test/src/generator_test_src.dart @@ -9,20 +9,26 @@ import 'query.pb.dart'; enum FileType { mp4, mp3 } class Config { + final String date; + final String type; + final bool shouldReplace; + final Map subConfig; + const Config({ required this.date, required this.type, required this.shouldReplace, required this.subConfig, }); - - final String date; - final String type; - final bool shouldReplace; - final Map subConfig; } class DummyTypedExtras extends TypedExtras { + final String id; + final Config config; + final List fileTypes; + final Set sources; + final bool shouldProceed; + final bool? canFly; const DummyTypedExtras({ required this.id, required this.config, @@ -31,13 +37,6 @@ class DummyTypedExtras extends TypedExtras { required this.shouldProceed, this.canFly, }); - - final String id; - final Config config; - final List fileTypes; - final Set sources; - final bool shouldProceed; - final bool? canFly; } @ShouldGenerate( @@ -50,11 +49,17 @@ class DummyTypedExtras extends TypedExtras { 'shouldReplace': true, 'subConfig': {'date': '24-11-2025'}, }, - 'fileTypes': ['mp3', 'mp4'], - 'sources': {'internet', 'local'}, + 'fileTypes': [ + 'mp3', + 'mp4', + ], + 'sources': { + 'internet', + 'local', + }, 'shouldProceed': true, }; -''', + ''', contains: true, ) @RestApi() @@ -104,13 +109,19 @@ class AnotherDummyTypedExtras extends TypedExtras { 'shouldReplace': true, 'subConfig': {'date': '24-11-2025'}, }, - 'fileTypes': ['mp3', 'mp4'], - 'sources': {'internet', 'local'}, + 'fileTypes': [ + 'mp3', + 'mp4', + ], + 'sources': { + 'internet', + 'local', + }, 'shouldProceed': true, 'peanutButter': 'Jelly', 'mac': 'Cheese', }; -''', + ''', contains: true, ) @RestApi() @@ -148,7 +159,11 @@ abstract class MultipleTypedExtrasTest { // ignore_for_file: unnecessary_brace_in_string_interps,no_leading_underscores_for_local_identifiers,unused_element,unnecessary_string_interpolations class _RestClient implements RestClient { - _RestClient(this._dio, {this.baseUrl, this.errorLogger}); + _RestClient( + this._dio, { + this.baseUrl, + this.errorLogger, + }); final Dio _dio; @@ -164,7 +179,11 @@ abstract class RestClient {} @ShouldGenerate( ''' class _BaseUrl implements BaseUrl { - _BaseUrl(this._dio, {this.baseUrl, this.errorLogger}) { + _BaseUrl( + this._dio, { + this.baseUrl, + this.errorLogger, + }) { baseUrl ??= 'http://httpbin.org/'; } @@ -195,7 +214,7 @@ abstract class EmptyExtras { @ShouldGenerate( ''' final _extra = {'key': 'value'}; -''', + ''', contains: true, ) @RestApi() @@ -207,8 +226,11 @@ abstract class ExtrasWithPrimitiveValues { @ShouldGenerate( ''' - final _extra = {'key': 'value', 'key2': 'value2'}; -''', + final _extra = { + 'key': 'value', + 'key2': 'value2', + }; + ''', contains: true, ) @RestApi() @@ -249,7 +271,7 @@ abstract class TestExtrasWithNullable { ''' final _extra = {'key': 'value'}; _extra.addAll(extras); -''', + ''', contains: true, ) @RestApi() @@ -265,7 +287,7 @@ abstract class TestExtrasWithMap { ''' final _extra = {}; _extra.addAll(u.toJson()); -''', + ''', contains: true, ) @RestApi() @@ -308,8 +330,11 @@ abstract class HeadersWithPrimitiveValues { @ShouldGenerate( ''' - final _headers = {r'key': 'value', r'key2': 'value2'}; -''', + final _headers = { + r'key': 'value', + r'key2': 'value2', + }; + ''', contains: true, ) @RestApi() @@ -322,8 +347,9 @@ abstract class MultipleHeadersWithPrimitiveValues { @ShouldGenerate( ''' - Options(method: 'GET', headers: _headers, extra: _extra) -''', +Options( + method: 'GET', + ''', contains: true, ) @RestApi(baseUrl: 'https://httpbin.org/') @@ -334,8 +360,9 @@ abstract class HttpGetTest { @ShouldGenerate( ''' - Options(method: 'POST', headers: _headers, extra: _extra) -''', +Options( + method: 'POST', + ''', contains: true, ) @RestApi(baseUrl: 'https://httpbin.org/') @@ -346,8 +373,9 @@ abstract class HttpPostTest { @ShouldGenerate( ''' - Options(method: 'PUT', headers: _headers, extra: _extra) -''', +Options( + method: 'PUT', + ''', contains: true, ) @RestApi(baseUrl: 'https://httpbin.org/') @@ -358,8 +386,8 @@ abstract class HttpPutTest { @ShouldGenerate( ''' - Options(method: 'DELETE', headers: _headers, extra: _extra) -''', +Options( + method: 'DELETE',''', contains: true, ) @RestApi(baseUrl: 'https://httpbin.org/') @@ -370,7 +398,8 @@ abstract class HttpDeleteTest { @ShouldGenerate( ''' - Options(method: 'PATCH', headers: _headers, extra: _extra) +Options( + method: 'PATCH', ''', contains: true, ) @@ -429,15 +458,13 @@ enum ImageType { icon, large } @ShouldGenerate( ''' final _data = FormData(); - _data.files.add( - MapEntry( - 'image', - MultipartFile.fromFileSync( - image.path, - filename: image.path.split(Platform.pathSeparator).last, - ), + _data.files.add(MapEntry( + 'image', + MultipartFile.fromFileSync( + image.path, + filename: image.path.split(Platform.pathSeparator).last, ), - ); + )); ''', contains: true, ) @@ -450,15 +477,13 @@ abstract class FilePartTest { @ShouldGenerate( ''' final _data = FormData(); - _data.files.add( - MapEntry( - 'image', - MultipartFile.fromFileSync( - image.path, - filename: 'my_profile_image.jpg', - ), + _data.files.add(MapEntry( + 'image', + MultipartFile.fromFileSync( + image.path, + filename: 'my_profile_image.jpg', ), - ); + )); ''', contains: true, ) @@ -501,15 +526,13 @@ abstract class FilePartWithNullableMultipartListTest { @ShouldGenerate( ''' final _data = FormData(); - _data.files.add( - MapEntry( - 'image', - MultipartFile.fromFileSync( - image.path, - filename: image.path.split(Platform.pathSeparator).last, - ), + _data.files.add(MapEntry( + 'image', + MultipartFile.fromFileSync( + image.path, + filename: image.path.split(Platform.pathSeparator).last, ), - ); + )); ''', contains: true, ) @@ -579,21 +602,20 @@ abstract class StreamReturnType { enum TestEnum { A, B } @ShouldGenerate( - r''' + ''' late TestEnum _value; try { _value = TestEnum.values.firstWhere( (e) => e.name == _result.data, - orElse: - () => - throw ArgumentError( - 'TestEnum does not contain value ${_result.data}', - ), + orElse: () => throw ArgumentError( + 'TestEnum does not contain value \${_result.data}', + ), ); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, ) @@ -621,16 +643,11 @@ abstract class TestQueryParamEnum { } enum FromJsonEnum { - a('a'), - b('b'); - - const FromJsonEnum(this.json); - - factory FromJsonEnum.fromJson(String json) => values.firstWhere( - (e) => e.json == json, - ); + a, + b, + ; - final String json; + factory FromJsonEnum.fromJson(Map json) => FromJsonEnum.a; } @ShouldGenerate( @@ -689,10 +706,9 @@ abstract class StreamReturnModifier { } class User implements AbstractUser { - const User(); + User(); - // ignore: avoid_unused_constructor_parameters - factory User.fromJson(Map json) => const User(); + factory User.fromJson(Map json) => User(); @override Map toJson() => {}; @@ -729,7 +745,9 @@ mixin AbstractUserMixin { Map toJson(); } -abstract interface class AbstractUser with AbstractUserMixin { +abstract class AbstractUser with AbstractUserMixin { + factory AbstractUser() = User; + factory AbstractUser.fromJson(Map json) => User.fromJson(json); } @@ -896,20 +914,16 @@ abstract class TestCustomObjectBody { ''' late Map> _value; try { - _value = _result.data!.map( - (k, dynamic v) => MapEntry( + _value = _result.data!.map((k, dynamic v) => MapEntry( k, (v as List) .map((i) => User.fromJson(i as Map)) - .toList(), - ), - ); + .toList())); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } return _value; - } ''', contains: true, ) @@ -923,20 +937,16 @@ abstract class TestMapBody { ''' late Map>? _value; try { - _value = _result.data?.map( - (k, dynamic v) => MapEntry( + _value = _result.data?.map((k, dynamic v) => MapEntry( k, (v as List) .map((i) => User.fromJson(i as Map)) - .toList(), - ), - ); + .toList())); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } return _value; - } ''', contains: true, ) @@ -950,15 +960,13 @@ abstract class NullableTestMapBody { ''' late Map _value; try { - _value = _result.data!.map( - (k, dynamic v) => MapEntry(k, User.fromJson(v as Map)), - ); + _value = _result.data!.map((k, dynamic v) => + MapEntry(k, User.fromJson(v as Map))); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } return _value; - } ''', contains: true, ) @@ -972,15 +980,13 @@ abstract class TestMapBody2 { ''' late Map? _value; try { - _value = _result.data?.map( - (k, dynamic v) => MapEntry(k, User.fromJson(v as Map)), - ); + _value = _result.data?.map((k, dynamic v) => + MapEntry(k, User.fromJson(v as Map))); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } return _value; - } ''', contains: true, ) @@ -1183,8 +1189,8 @@ abstract class TestReceiveProgress { @ShouldGenerate( ''' - Options(method: 'HEAD', headers: _headers, extra: _extra) -''', +Options( + method: 'HEAD',''', contains: true, ) @RestApi(baseUrl: 'https://httpbin.org/') @@ -1195,8 +1201,8 @@ abstract class TestHeadMethod { @ShouldGenerate( ''' - Options(method: 'OPTIONS', headers: _headers, extra: _extra) -''', +Options( + method: 'OPTIONS',''', contains: true, ) @RestApi(baseUrl: 'https://httpbin.org/') @@ -1252,17 +1258,12 @@ abstract class TestHttpResponseArray { @ShouldGenerate( ''' final _data = FormData(); - _data.files.addAll( - files.map( - (i) => MapEntry( - 'files', - MultipartFile.fromFileSync( - i.path, - filename: i.path.split(Platform.pathSeparator).last, - ), - ), - ), - ); + _data.files.addAll(files.map((i) => MapEntry( + 'files', + MultipartFile.fromFileSync( + i.path, + filename: i.path.split(Platform.pathSeparator).last, + )))); ''', contains: true, ) @@ -1270,34 +1271,26 @@ abstract class TestHttpResponseArray { ''' final _data = FormData(); if (files != null) { - _data.files.addAll( - files.map( - (i) => MapEntry( - 'files', - MultipartFile.fromFileSync( - i.path, - filename: i.path.split(Platform.pathSeparator).last, - ), - ), - ), - ); + _data.files.addAll(files.map((i) => MapEntry( + 'files', + MultipartFile.fromFileSync( + i.path, + filename: i.path.split(Platform.pathSeparator).last, + )))); } ''', contains: true, ) @ShouldGenerate( ''' - final _data = FormData(); if (file != null) { - _data.files.add( - MapEntry( - 'file', - MultipartFile.fromFileSync( - file.path, - filename: file.path.split(Platform.pathSeparator).last, - ), + _data.files.add(MapEntry( + 'file', + MultipartFile.fromFileSync( + file.path, + filename: file.path.split(Platform.pathSeparator).last, ), - ); + )); } ''', contains: true, @@ -1316,41 +1309,59 @@ abstract class TestFileList { @ShouldGenerate( ''' - _data.fields.add(MapEntry('users', jsonEncode(users))); -''', + final _data = FormData(); + _data.fields.add(MapEntry( + 'users', + jsonEncode(users), + )); + ''', contains: true, ) @ShouldGenerate( ''' - _data.fields.add(MapEntry('item', jsonEncode(user))); -''', + final _data = FormData(); + _data.fields.add(MapEntry( + 'item', + jsonEncode(user), + )); + ''', contains: true, ) @ShouldGenerate( ''' - final _data = FormData(); mapList.forEach((i) { _data.fields.add(MapEntry('mapList', jsonEncode(i))); }); -''', + ''', contains: true, ) @ShouldGenerate( ''' final _data = FormData.fromMap(map); -''', - contains: true, -) -@ShouldGenerate( - ''' - final _data = FormData(); - _data.fields.add(MapEntry('a', a.toString())); - _data.fields.add(MapEntry('b', b.toString())); - if (c != null) { - _data.fields.add(MapEntry('c', c)); + ''', + contains: true, +) +@ShouldGenerate( + ''' + _data.fields.add(MapEntry( + 'a', + a.toString(), + )); + _data.fields.add(MapEntry( + 'b', + b.toString(), + )); + _data.fields.add(MapEntry( + 'c', + c.toString(), + )); + if (d != null) { + _data.fields.add(MapEntry( + 'd', + d, + )); } - _data.fields.add(MapEntry('d', d.toString())); -''', + ''', contains: true, ) @RestApi() @@ -1370,27 +1381,12 @@ abstract class TestModelList { @POST('/') Future testBasicType( @Part() int a, - @Part() double b, { - @Part() String? c, - @Part() bool d, + @Part() bool b, + @Part() double c, { + @Part() String? d, }); } -@ShouldGenerate( - ''' - final newOptions = newRequestOptions(options); - newOptions.extra.addAll(_extra); - newOptions.headers.addAll(_dio.options.headers); - newOptions.headers.addAll(_headers); - final _options = newOptions.copyWith( - method: 'GET', - baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl), - queryParameters: queryParameters, - path: '', - )..data = _data; -''', - contains: true, -) @ShouldGenerate( ''' RequestOptions newRequestOptions(Object? options) { @@ -1420,6 +1416,25 @@ abstract class TestModelList { ''', contains: true, ) +@ShouldGenerate( + ''' + final newOptions = newRequestOptions(options); + newOptions.extra.addAll(_extra); + newOptions.headers.addAll(_dio.options.headers); + newOptions.headers.addAll(_headers); + final _options = newOptions.copyWith( + method: 'GET', + baseUrl: _combineBaseUrls( + _dio.options.baseUrl, + baseUrl, + ), + queryParameters: queryParameters, + path: '', + )..data = _data; + await _dio.fetch(_options); + ''', + contains: true, +) @RestApi() abstract class CustomOptions { @GET('') @@ -1435,6 +1450,7 @@ abstract class CustomOptions { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, ) @@ -1451,14 +1467,14 @@ abstract class JsonMapperGenericCast { ''' late User? _value; try { - _value = - _result.data == null - ? null - : JsonMapper.fromMap(_result.data!)!; + _value = _result.data == null + ? null + : JsonMapper.fromMap(_result.data!)!; } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, ) @@ -1475,17 +1491,15 @@ abstract class NullableJsonMapperGenericCast { ''' late List _value; try { - _value = - _result.data! - .map( - (dynamic i) => - JsonMapper.fromMap(i as Map)!, - ) - .toList(); + _value = _result.data! + .map((dynamic i) => + JsonMapper.fromMap(i as Map)!) + .toList(); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, ) @@ -1502,18 +1516,16 @@ abstract class JsonMapperTestListBody { ''' late Map> _value; try { - _value = _result.data!.map( - (k, dynamic v) => MapEntry( + _value = _result.data!.map((k, dynamic v) => MapEntry( k, (v as List) .map((i) => JsonMapper.fromMap(i as Map)!) - .toList(), - ), - ); + .toList())); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, ) @@ -1530,14 +1542,13 @@ abstract class JsonMapperTestMapBody { ''' late Map _value; try { - _value = _result.data!.map( - (k, dynamic v) => - MapEntry(k, JsonMapper.fromMap(v as Map)!), - ); + _value = _result.data!.map((k, dynamic v) => + MapEntry(k, JsonMapper.fromMap(v as Map)!)); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, ) @@ -1559,6 +1570,7 @@ abstract class JsonMapperTestMapBody2 { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, ) @@ -1580,6 +1592,7 @@ abstract class MapSerializableGenericCast { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, ) @@ -1596,14 +1609,14 @@ abstract class NullableMapSerializableGenericCast { ''' late List _value; try { - _value = - _result.data! - .map((dynamic i) => User.fromMap(i as Map)) - .toList(); + _value = _result.data! + .map((dynamic i) => User.fromMap(i as Map)) + .toList(); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, ) @@ -1620,14 +1633,14 @@ abstract class MapSerializableTestListBody { ''' late List? _value; try { - _value = - _result.data - ?.map((dynamic i) => User.fromMap(i as Map)) - .toList(); + _value = _result.data + ?.map((dynamic i) => User.fromMap(i as Map)) + .toList(); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, ) @@ -1644,18 +1657,16 @@ abstract class NullableMapSerializableTestListBody { ''' late Map> _value; try { - _value = _result.data!.map( - (k, dynamic v) => MapEntry( + _value = _result.data!.map((k, dynamic v) => MapEntry( k, (v as List) .map((i) => User.fromMap(i as Map)) - .toList(), - ), - ); + .toList())); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, ) @@ -1672,18 +1683,16 @@ abstract class MapSerializableTestMapBody { ''' late Map>? _value; try { - _value = _result.data?.map( - (k, dynamic v) => MapEntry( + _value = _result.data?.map((k, dynamic v) => MapEntry( k, (v as List) .map((i) => User.fromMap(i as Map)) - .toList(), - ), - ); + .toList())); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, ) @@ -1700,13 +1709,13 @@ abstract class NullableMapSerializableTestMapBody { ''' late Map _value; try { - _value = _result.data!.map( - (k, dynamic v) => MapEntry(k, User.fromMap(v as Map)), - ); + _value = _result.data!.map((k, dynamic v) => + MapEntry(k, User.fromMap(v as Map))); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, ) @@ -1723,13 +1732,13 @@ abstract class MapSerializableTestMapBody2 { ''' late Map? _value; try { - _value = _result.data?.map( - (k, dynamic v) => MapEntry(k, User.fromMap(v as Map)), - ); + _value = _result.data?.map((k, dynamic v) => + MapEntry(k, User.fromMap(v as Map))); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, ) @@ -1750,6 +1759,7 @@ abstract class NullableMapSerializableTestMapBody2 { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, ) @@ -1766,14 +1776,14 @@ abstract class ComputeGenericCast { ''' late User? _value; try { - _value = - _result.data == null - ? null - : await compute(deserializeUser, _result.data!); + _value = _result.data == null + ? null + : await compute(deserializeUser, _result.data!); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, ) @@ -1797,6 +1807,7 @@ abstract class NullableComputeGenericCast { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, ) @@ -1813,17 +1824,17 @@ abstract class ComputeTestListBody { ''' late List? _value; try { - _value = - _result.data == null - ? null - : await compute( - deserializeUserList, - _result.data!.cast>(), - ); + _value = _result.data == null + ? null + : await compute( + deserializeUserList, + _result.data!.cast>(), + ); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, ) @@ -1838,25 +1849,17 @@ abstract class NullableComputeTestListBody { @ShouldGenerate( ''' - late Map> _value; try { - _value = Map.fromEntries( - await Future.wait( - _result.data!.entries.map( - (e) async => MapEntry( + _value = Map.fromEntries(await Future.wait(_result.data!.entries.map( + (e) async => MapEntry( e.key, - await compute( - deserializeUserList, - (e.value as List).cast>(), - ), - ), - ), - ), - ); + await compute(deserializeUserList, + (e.value as List).cast>()))))); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, expectedLogItems: [ @@ -1879,23 +1882,16 @@ abstract class ComputeTestMapBody { ''' late Map>? _value; try { - _value = Map.fromEntries( - await Future.wait( - _result.data!.entries.map( - (e) async => MapEntry( + _value = Map.fromEntries(await Future.wait(_result.data!.entries.map( + (e) async => MapEntry( e.key, - await compute( - deserializeUserList, - (e.value as List).cast>(), - ), - ), - ), - ), - ); + await compute(deserializeUserList, + (e.value as List).cast>()))))); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, expectedLogItems: [ @@ -1918,20 +1914,16 @@ abstract class NullableComputeTestMapBody { ''' late Map _value; try { - _value = Map.fromEntries( - await Future.wait( - _result.data!.entries.map( - (e) async => MapEntry( + _value = Map.fromEntries(await Future.wait(_result.data!.entries.map( + (e) async => MapEntry( e.key, - await compute(deserializeUser, e.value as Map), - ), - ), - ), - ); + await compute( + deserializeUser, e.value as Map))))); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, expectedLogItems: [ @@ -1954,26 +1946,18 @@ abstract class ComputeTestMapBody2 { ''' late Map? _value; try { - _value = - _result.data == null - ? null - : Map.fromEntries( - await Future.wait( - _result.data!.entries.map( - (e) async => MapEntry( - e.key, - await compute( - deserializeUser, - e.value as Map, - ), - ), - ), - ), - ); + _value = _result.data == null + ? null + : Map.fromEntries(await Future.wait(_result.data!.entries.map( + (e) async => MapEntry( + e.key, + await compute( + deserializeUser, e.value as Map))))); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } + return _value; ''', contains: true, expectedLogItems: [ @@ -1995,7 +1979,7 @@ abstract class NullableComputeTestMapBody2 { @ShouldGenerate( ''' final queryParameters = { - r'u': await compute(serializeUser, user), + r'u': await compute(serializeUser, user) }; ''', contains: true, @@ -2059,9 +2043,9 @@ abstract class TestComputeObjectListBody { @ShouldGenerate( ''' final _data = {}; - _data.addAll( - user == null ? {} : await compute(serializeUser, user), - ); + _data.addAll(user == null + ? {} + : await compute(serializeUser, user)); ''', contains: true, ) @@ -2097,11 +2081,10 @@ abstract class JsonSerializableBodyShouldBeCleanTest { @ShouldGenerate( ''' final _data = str; - final _options = _setStreamType( -''', + final _options = _setStreamType(Options(''', contains: true, expectedLogItems: [ - "String must provide a `toJson()` method which return a Map.\nIt is programmer's responsibility to make sure the String is properly serialized", + "String must provide a `toJson()` method which return a Map.\nIt is programmer's responsibility to make sure the String is properly serialized" ], ) @RestApi() @@ -2113,18 +2096,24 @@ abstract class NonJsonSerializableBodyShouldNotBeCleanTest { @ShouldGenerate( ''' final _data = users.map((e) => e.toJson()).toList(); - final _options = _setStreamType( - Options(method: 'PUT', headers: _headers, extra: _extra) - .compose( - _dio.options, - '/', - queryParameters: queryParameters, - data: _data, - ) - .copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)), - ); + final _options = _setStreamType(Options( + method: 'PUT', + headers: _headers, + extra: _extra, + ) + .compose( + _dio.options, + '/', + queryParameters: queryParameters, + data: _data, + ) + .copyWith( + baseUrl: _combineBaseUrls( + _dio.options.baseUrl, + baseUrl, + ))); await _dio.fetch(_options); -''', + ''', contains: true, ) @RestApi() @@ -2145,7 +2134,8 @@ abstract class ListBodyShouldNotBeCleanTest { errorLogger?.logError(e, s, _options); rethrow; } -''', + return _value; + ''', contains: true, ) @RestApi() @@ -2160,18 +2150,18 @@ abstract class DynamicInnerGenericTypeShouldBeCastedAsDynamic { try { _value = GenericUser>.fromJson( _result.data!, - (json) => - json is List - ? json - .map((i) => User.fromJson(i as Map)) - .toList() - : List.empty(), + (json) => json is List + ? json + .map((i) => User.fromJson(i as Map)) + .toList() + : List.empty(), ); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } -''', + return _value; + ''', contains: true, ) @RestApi() @@ -2184,25 +2174,23 @@ abstract class DynamicInnerListGenericTypeShouldBeCastedRecursively { ''' late GenericUser>? _value; try { - _value = - _result.data == null - ? null - : GenericUser>.fromJson( - _result.data!, - (json) => - json is List - ? json - .map( - (i) => User.fromJson(i as Map), - ) - .toList() - : List.empty(), - ); + _value = _result.data == null + ? null + : GenericUser>.fromJson( + _result.data!, + (json) => json is List + ? json + .map( + (i) => User.fromJson(i as Map)) + .toList() + : List.empty(), + ); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } -''', + return _value; + ''', contains: true, ) @RestApi() @@ -2213,7 +2201,7 @@ abstract class NullableDynamicInnerListGenericTypeShouldBeCastedRecursively { @ShouldGenerate( ''' - late GenericUser _value; +late GenericUser _value; try { _value = GenericUser.fromJson( _result.data!, @@ -2223,7 +2211,8 @@ abstract class NullableDynamicInnerListGenericTypeShouldBeCastedRecursively { errorLogger?.logError(e, s, _options); rethrow; } -''', + return _value; + ''', contains: true, ) @RestApi() @@ -2247,7 +2236,8 @@ abstract class DynamicInnerGenericTypeShouldBeCastedAsMap { errorLogger?.logError(e, s, _options); rethrow; } -''', + return _value; + ''', contains: true, ) @RestApi() @@ -2260,18 +2250,18 @@ abstract class NestGenericTypeShouldBeCastedRecursively { ''' late GenericUser? _value; try { - _value = - _result.data == null - ? null - : GenericUser.fromJson( - _result.data!, - (json) => User.fromJson(json as Map), - ); + _value = _result.data == null + ? null + : GenericUser.fromJson( + _result.data!, + (json) => User.fromJson(json as Map), + ); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } -''', + return _value; + ''', contains: true, ) @RestApi() @@ -2282,7 +2272,7 @@ abstract class NullableDynamicInnerGenericTypeShouldBeCastedAsMap { @ShouldGenerate( ''' - late GenericUser _value; +late GenericUser _value; try { _value = GenericUser.fromJson( _result.data!, @@ -2293,7 +2283,8 @@ abstract class NullableDynamicInnerGenericTypeShouldBeCastedAsMap { errorLogger?.logError(e, s, _options); rethrow; } -''', + return _value; + ''', contains: true, ) @RestApi() @@ -2306,21 +2297,20 @@ abstract class DynamicNullableInnerGenericTypeShouldBeCastedAsMap { ''' late GenericUser? _value; try { - _value = - _result.data == null - ? null - : GenericUser.fromJson( - _result.data!, - (json) => - json == null - ? null - : User.fromJson(json as Map), - ); + _value = _result.data == null + ? null + : GenericUser.fromJson( + _result.data!, + (json) => json == null + ? null + : User.fromJson(json as Map), + ); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } -''', + return _value; + ''', contains: true, ) @RestApi() @@ -2335,16 +2325,16 @@ abstract class NullableDynamicNullableInnerGenericTypeShouldBeCastedAsMap { try { _value = GenericUser>.fromJson( _result.data!, - (json) => - json is List - ? json.map((i) => i as double).toList() - : List.empty(), + (json) => json is List + ? json.map((i) => i as double).toList() + : List.empty(), ); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } -''', + return _value; + ''', contains: true, ) @RestApi() @@ -2357,21 +2347,20 @@ abstract class DynamicInnerListGenericPrimitiveTypeShouldBeCastedRecursively { ''' late GenericUser>? _value; try { - _value = - _result.data == null - ? null - : GenericUser>.fromJson( - _result.data!, - (json) => - json is List - ? json.map((i) => i as double).toList() - : List.empty(), - ); + _value = _result.data == null + ? null + : GenericUser>.fromJson( + _result.data!, + (json) => json is List + ? json.map((i) => i as double).toList() + : List.empty(), + ); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } -''', + return _value; + ''', contains: true, ) @RestApi() @@ -2385,13 +2374,13 @@ abstract class NullableDynamicInnerListGenericPrimitiveTypeShouldBeCastedRecursi late GenericUserWithoutGenericArgumentFactories _value; try { _value = GenericUserWithoutGenericArgumentFactories.fromJson( - _result.data!, - ); + _result.data!); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } -''', + return _value; + ''', contains: true, ) @RestApi() @@ -2404,17 +2393,16 @@ abstract class DynamicInnerGenericTypeShouldBeWithoutGenericArgumentType { ''' late GenericUserWithoutGenericArgumentFactories? _value; try { - _value = - _result.data == null - ? null - : GenericUserWithoutGenericArgumentFactories.fromJson( - _result.data!, - ); + _value = _result.data == null + ? null + : GenericUserWithoutGenericArgumentFactories.fromJson( + _result.data!); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; } -''', + return _value; + ''', contains: true, ) @RestApi() @@ -2445,14 +2433,14 @@ mixin MethodInMixin { ''' @override Future someGet() async { -''', + ''', contains: true, ) @RestApi() abstract class NoMethods with MethodInMixin {} @ShouldGenerate( - 'await _dio.fetch?>', + '''await _dio.fetch?>''', contains: true, ) @RestApi() @@ -2462,7 +2450,7 @@ abstract class NullableGenericCastFetch { } @ShouldGenerate( - 'await _dio.fetch>', + '''await _dio.fetch>''', contains: true, ) @RestApi() @@ -2472,7 +2460,13 @@ abstract class GenericCastFetch { } @ShouldGenerate( - '''.copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)),''', + ''' + .copyWith( + baseUrl: _combineBaseUrls( + _dio.options.baseUrl, + baseUrl, + ))); + ''', contains: true, ) @RestApi() @@ -2482,32 +2476,24 @@ abstract class CombineBaseUrls { } @ShouldGenerate( - r''' - final _headers = { + '''final _data = params.writeToBuffer();''', + contains: true, +) +@ShouldGenerate( + ''' r'accept': - 'application/x-protobuf; ${Result.getDefault().info_.qualifiedMessageName == "" ? "" : "messageType=${Result.getDefault().info_.qualifiedMessageName}"}', - }; - _headers.removeWhere((k, v) => v == null); - final _data = params.writeToBuffer(); - final _options = _setStreamType( - Options( - method: 'GET', - headers: _headers, - extra: _extra, - contentType: - 'application/x-protobuf; ${params.info_.qualifiedMessageName == "" ? "" : "messageType=${params.info_.qualifiedMessageName}"}', - ) - .compose( - _dio.options, - '/', - queryParameters: queryParameters, - data: _data, - ) - .copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)), - ); - final _result = await _dio.fetch>(_options); - final _value = await compute(Result.fromBuffer, _result.data!); -''', + 'application/x-protobuf; \${Result.getDefault().info_.qualifiedMessageName == "" ? "" : "messageType=\${Result.getDefault().info_.qualifiedMessageName}"}' + ''', + contains: true, +) +@ShouldGenerate( + ''' + contentType: + 'application/x-protobuf; \${params.info_.qualifiedMessageName == "" ? "" : "messageType=\${params.info_.qualifiedMessageName}"}\'''', + contains: true, +) +@ShouldGenerate( + '''await compute(Result.fromBuffer, _result.data!);''', contains: true, ) @RestApi() @@ -2517,32 +2503,24 @@ abstract class ProtoSupportParserJsonSerializable { } @ShouldGenerate( - r''' - final _headers = { + '''final _data = params.writeToBuffer();''', + contains: true, +) +@ShouldGenerate( + ''' r'accept': - 'application/x-protobuf; ${Result.getDefault().info_.qualifiedMessageName == "" ? "" : "messageType=${Result.getDefault().info_.qualifiedMessageName}"}', - }; - _headers.removeWhere((k, v) => v == null); - final _data = params.writeToBuffer(); - final _options = _setStreamType( - Options( - method: 'GET', - headers: _headers, - extra: _extra, - contentType: - 'application/x-protobuf; ${params.info_.qualifiedMessageName == "" ? "" : "messageType=${params.info_.qualifiedMessageName}"}', - ) - .compose( - _dio.options, - '/', - queryParameters: queryParameters, - data: _data, - ) - .copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)), - ); - final _result = await _dio.fetch>(_options); - final _value = await compute(Result.fromBuffer, _result.data!); -''', + 'application/x-protobuf; \${Result.getDefault().info_.qualifiedMessageName == "" ? "" : "messageType=\${Result.getDefault().info_.qualifiedMessageName}"}' + ''', + contains: true, +) +@ShouldGenerate( + ''' + contentType: + 'application/x-protobuf; \${params.info_.qualifiedMessageName == "" ? "" : "messageType=\${params.info_.qualifiedMessageName}"}\'''', + contains: true, +) +@ShouldGenerate( + '''await compute(Result.fromBuffer, _result.data!);''', contains: true, ) @RestApi(parser: Parser.DartJsonMapper) @@ -2552,32 +2530,24 @@ abstract class ProtoSupportParserDartJsonMapper { } @ShouldGenerate( - r''' - final _headers = { + '''final _data = params.writeToBuffer();''', + contains: true, +) +@ShouldGenerate( + ''' r'accept': - 'application/x-protobuf; ${Result.getDefault().info_.qualifiedMessageName == "" ? "" : "messageType=${Result.getDefault().info_.qualifiedMessageName}"}', - }; - _headers.removeWhere((k, v) => v == null); - final _data = params.writeToBuffer(); - final _options = _setStreamType( - Options( - method: 'GET', - headers: _headers, - extra: _extra, - contentType: - 'application/x-protobuf; ${params.info_.qualifiedMessageName == "" ? "" : "messageType=${params.info_.qualifiedMessageName}"}', - ) - .compose( - _dio.options, - '/', - queryParameters: queryParameters, - data: _data, - ) - .copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)), - ); - final _result = await _dio.fetch>(_options); - final _value = await compute(Result.fromBuffer, _result.data!); -''', + 'application/x-protobuf; \${Result.getDefault().info_.qualifiedMessageName == "" ? "" : "messageType=\${Result.getDefault().info_.qualifiedMessageName}"}' + ''', + contains: true, +) +@ShouldGenerate( + ''' + contentType: + 'application/x-protobuf; \${params.info_.qualifiedMessageName == "" ? "" : "messageType=\${params.info_.qualifiedMessageName}"}\'''', + contains: true, +) +@ShouldGenerate( + '''await compute(Result.fromBuffer, _result.data!);''', contains: true, ) @RestApi(parser: Parser.MapSerializable) @@ -2587,32 +2557,24 @@ abstract class ProtoSupportParserMapSerializable { } @ShouldGenerate( - r''' - final _headers = { + '''final _data = params.writeToBuffer();''', + contains: true, +) +@ShouldGenerate( + ''' r'accept': - 'application/x-protobuf; ${Result.getDefault().info_.qualifiedMessageName == "" ? "" : "messageType=${Result.getDefault().info_.qualifiedMessageName}"}', - }; - _headers.removeWhere((k, v) => v == null); - final _data = params.writeToBuffer(); - final _options = _setStreamType( - Options( - method: 'GET', - headers: _headers, - extra: _extra, - contentType: - 'application/x-protobuf; ${params.info_.qualifiedMessageName == "" ? "" : "messageType=${params.info_.qualifiedMessageName}"}', - ) - .compose( - _dio.options, - '/', - queryParameters: queryParameters, - data: _data, - ) - .copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)), - ); - final _result = await _dio.fetch>(_options); - final _value = await compute(Result.fromBuffer, _result.data!); -''', + 'application/x-protobuf; \${Result.getDefault().info_.qualifiedMessageName == "" ? "" : "messageType=\${Result.getDefault().info_.qualifiedMessageName}"}' + ''', + contains: true, +) +@ShouldGenerate( + ''' + contentType: + 'application/x-protobuf; \${params.info_.qualifiedMessageName == "" ? "" : "messageType=\${params.info_.qualifiedMessageName}"}\'''', + contains: true, +) +@ShouldGenerate( + '''await compute(Result.fromBuffer, _result.data!);''', contains: true, ) @RestApi(parser: Parser.FlutterCompute) @@ -2632,8 +2594,8 @@ abstract class MultipartWithMultplePathParams { @MultiPart() @POST('post/{id}/comments/{commentId}') Future multipartBodyWithMultiplePathParameter( - @Path('id') String id, - @Path('commentId') String commentId, + @Path("id") String id, + @Path("commentId") String commentId, @Part() Map body, ); } @@ -2649,7 +2611,7 @@ abstract class MultipartWithSinglePathParams { @MultiPart() @POST('post/{id}/comments') Future multipartBodyWithSinglePathParameter( - @Path('id') String id, + @Path("id") String id, @Part() Map body, ); } @@ -2665,8 +2627,8 @@ abstract class MultipartWithMultiplePathParamsPUT { @MultiPart() @PUT('post/{id}/comments/{commentId}') Future multipartBodyWithMultiplePathParameter( - @Path('id') String id, - @Path('commentId') String commentId, + @Path("id") String id, + @Path("commentId") String commentId, @Part() Map body, ); }