From 0aefba1f2a493c633d8726d92c1708f3b9002d40 Mon Sep 17 00:00:00 2001 From: dan3988 <40858622+dan3988@users.noreply.github.com> Date: Thu, 22 Aug 2024 11:03:57 +0100 Subject: [PATCH 1/2] Fixed 'method' property in 'response_override_value_map'values being ignored --- lib/src/code_generators/swagger_requests_generator.dart | 8 +++++--- test/generator_tests/requests_generator_test.dart | 2 ++ 2 files changed, 7 insertions(+), 3 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..da1f9f7f 100644 --- a/test/generator_tests/requests_generator_test.dart +++ b/test/generator_tests/requests_generator_test.dart @@ -47,6 +47,8 @@ void main() { ); expect(result2, contains('Future>')); + expect(result, contains('Future> carsSchemaRefBodyGet')); + expect(result, contains('Future> carsSchemaRefBodyPost')); expect(result, contains('Future> carsGet')); expect(result, contains('Future> carsPost')); expect(result, From 198e3d550ce42eb17cc61b98b50c065c60b0faed Mon Sep 17 00:00:00 2001 From: dan3988 <40858622+dan3988@users.noreply.github.com> Date: Thu, 22 Aug 2024 11:09:22 +0100 Subject: [PATCH 2/2] Added test to check the return type of all methods are overridden when no HTTP method is specified --- test/generator_tests/requests_generator_test.dart | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/generator_tests/requests_generator_test.dart b/test/generator_tests/requests_generator_test.dart index da1f9f7f..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, @@ -49,6 +54,9 @@ 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,