diff --git a/generator/lib/src/generator.dart b/generator/lib/src/generator.dart index fac0d8670..f767e43dc 100644 --- a/generator/lib/src/generator.dart +++ b/generator/lib/src/generator.dart @@ -106,6 +106,8 @@ class RetrofitGenerator extends GeneratorForAnnotation { /// 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( diff --git a/generator/test/src/generator_test_src.dart b/generator/test/src/generator_test_src.dart index 77d12eb4e..a3d58364c 100644 --- a/generator/test/src/generator_test_src.dart +++ b/generator/test/src/generator_test_src.dart @@ -1433,6 +1433,27 @@ abstract class CustomOptions { Future 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 getData() async { +''', contains: true) +@RestApi() +abstract class ServiceWithoutCustomOptions { + @GET('/data') + Future getData(); +} + @ShouldGenerate(''' late User _value; try {