diff --git a/lib/src/code_generators/swagger_requests_generator.dart b/lib/src/code_generators/swagger_requests_generator.dart index 798650b3..38d429da 100644 --- a/lib/src/code_generators/swagger_requests_generator.dart +++ b/lib/src/code_generators/swagger_requests_generator.dart @@ -173,9 +173,11 @@ class SwaggerRequestsGenerator extends SwaggerGeneratorBase { method: requestType, modelPostfix: options.modelPostfix, swaggerRoot: swaggerRoot, - overridenResponses: options.responseOverrideValueMap - .asMap() - .map((key, value) => MapEntry(value.url, value)), + overridenResponses: Map.fromEntries( + options.responseOverrideValueMap + .where((v) => v.method.isEmpty || v.method == requestType) + .map((v) => MapEntry(v.url, v)), + ), ); final String returns; diff --git a/test/generator_tests/requests_generator_test.dart b/test/generator_tests/requests_generator_test.dart index 6f3102f9..f786180e 100644 --- a/test/generator_tests/requests_generator_test.dart +++ b/test/generator_tests/requests_generator_test.dart @@ -19,7 +19,12 @@ void main() { method: 'get', url: '/cars/schemaRefBody', overriddenValue: 'String', - ) + ), + ResponseOverrideValueMap( + method: '', + url: '/cars/returnTypeTests', + overriddenValue: 'int', + ), ], )).generate( swaggerRoot: root, @@ -47,6 +52,11 @@ void main() { ); expect(result2, contains('Future>')); + expect(result, contains('Future> carsSchemaRefBodyGet')); + expect(result, contains('Future> carsSchemaRefBodyPost')); + expect(result, contains('Future> carsReturnTypeTestsGet')); + expect(result, contains('Future> carsReturnTypeTestsPost')); + expect(result, contains('Future> carsReturnTypeTestsPut')); expect(result, contains('Future> carsGet')); expect(result, contains('Future> carsPost')); expect(result,