Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions generator/lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class RetrofitGenerator extends GeneratorForAnnotation<retrofit.RestApi> {

/// Generates the implementation class code as a string.
String _implementClass(ClassElement2 element, ConstantReader annotation) {
// Reset hasCustomOptions for each class to avoid state leaking between classes
hasCustomOptions = false;
final className = globalOptions.className ?? '_${element.name3}';
final enumString = annotation.peek('parser')?.revive().accessor;
final parser = retrofit.Parser.values.firstWhereOrNull(
Expand Down
21 changes: 21 additions & 0 deletions generator/test/src/generator_test_src.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,27 @@ abstract class CustomOptions {
Future<void> testOptions(@DioOptions() Options options);
}

// Test that a service without @DioOptions does not get newRequestOptions method
// We check by verifying that the expected code pattern is generated without newRequestOptions
@ShouldGenerate(r'''
class _ServiceWithoutCustomOptions implements ServiceWithoutCustomOptions {
_ServiceWithoutCustomOptions(this._dio, {this.baseUrl, this.errorLogger});

final Dio _dio;

String? baseUrl;

final ParseErrorLogger? errorLogger;

@override
Future<String> getData() async {
''', contains: true)
@RestApi()
abstract class ServiceWithoutCustomOptions {
@GET('/data')
Future<String> getData();
}

@ShouldGenerate('''
late User _value;
try {
Expand Down
Loading