Skip to content

Commit

Permalink
Fixed 'method' property in 'response_override_value_map' being ignored (
Browse files Browse the repository at this point in the history
epam-cross-platform-lab#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
  • Loading branch information
dan3988 authored and AnnaKandel committed Nov 3, 2024
1 parent 8d307ab commit d1f6c7f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/src/code_generators/swagger_requests_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion test/generator_tests/requests_generator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ void main() {
method: 'get',
url: '/cars/schemaRefBody',
overriddenValue: 'String',
)
),
ResponseOverrideValueMap(
method: '',
url: '/cars/returnTypeTests',
overriddenValue: 'int',
),
],
)).generate(
swaggerRoot: root,
Expand Down Expand Up @@ -47,6 +52,11 @@ void main() {
);

expect(result2, contains('Future<chopper.Response<CarModel>>'));
expect(result, contains('Future<chopper.Response<String>> carsSchemaRefBodyGet'));
expect(result, contains('Future<chopper.Response<CarModel>> carsSchemaRefBodyPost'));
expect(result, contains('Future<chopper.Response<int>> carsReturnTypeTestsGet'));
expect(result, contains('Future<chopper.Response<int>> carsReturnTypeTestsPost'));
expect(result, contains('Future<chopper.Response<int>> carsReturnTypeTestsPut'));
expect(result, contains('Future<chopper.Response<CarModel>> carsGet'));
expect(result, contains('Future<chopper.Response<CarModel>> carsPost'));
expect(result,
Expand Down

0 comments on commit d1f6c7f

Please sign in to comment.