From d1f6c7f2cc38de9fe6e2a381dc1f7cb5de9a9b8b Mon Sep 17 00:00:00 2001 From: Daniel Pickett <40858622+dan3988@users.noreply.github.com> Date: Wed, 18 Sep 2024 10:44:07 +0100 Subject: [PATCH] Fixed 'method' property in 'response_override_value_map' being ignored (#765) * Fixed 'method' property in 'response_override_value_map'values being ignored * Added test to check the return type of all methods are overridden when no HTTP method is specified --- .../code_generators/swagger_requests_generator.dart | 8 +++++--- test/generator_tests/requests_generator_test.dart | 12 +++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) 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,