diff --git a/swagger_parser/lib/src/generator/models/universal_request.dart b/swagger_parser/lib/src/generator/models/universal_request.dart index ee2e9290..89dfb347 100644 --- a/swagger_parser/lib/src/generator/models/universal_request.dart +++ b/swagger_parser/lib/src/generator/models/universal_request.dart @@ -59,6 +59,7 @@ final class UniversalRequest { runtimeType == other.runtimeType && name == other.name && requestType == other.requestType && + contentType == other.contentType && route == other.route && returnType == other.returnType && const DeepCollectionEquality().equals(parameters, other.parameters) && @@ -71,6 +72,7 @@ final class UniversalRequest { requestType.hashCode ^ route.hashCode ^ returnType.hashCode ^ + contentType.hashCode ^ parameters.hashCode ^ isMultiPart.hashCode ^ isFormUrlEncoded.hashCode; diff --git a/swagger_parser/lib/src/parser/parser.dart b/swagger_parser/lib/src/parser/parser.dart index 9df30e00..f4f0b4d1 100644 --- a/swagger_parser/lib/src/parser/parser.dart +++ b/swagger_parser/lib/src/parser/parser.dart @@ -398,6 +398,8 @@ class OpenApiParser { resultContentType = _multipartFormDataConst; } else if (consumes.contains(_formUrlEncodedConst)) { resultContentType = _formUrlEncodedConst; + } else if (consumes.isNotEmpty && consumes.first != null) { + resultContentType = consumes.first as String; } } for (final parameter in map[_parametersConst] as List) { diff --git a/swagger_parser/test/parser/requests_test.dart b/swagger_parser/test/parser/requests_test.dart index 5f3cd65a..3805c593 100644 --- a/swagger_parser/test/parser/requests_test.dart +++ b/swagger_parser/test/parser/requests_test.dart @@ -26,6 +26,7 @@ void main() { requestType: HttpRequestType.post, route: '/api/Auth/register', returnType: UniversalType(type: 'string'), + contentType: 'text/json', parameters: [ UniversalRequestType( parameterType: HttpParameterType.body, @@ -110,7 +111,7 @@ void main() { ), ]; for (var i = 0; i < actualRestClients.length; i++) { - expect(actualRestClients.last, expectedRestClients.last); + expect(actualRestClients[i], expectedRestClients[i]); } }); diff --git a/swagger_parser/test/parser/schemas/basic_requests.2.0.json b/swagger_parser/test/parser/schemas/basic_requests.2.0.json index 1cf80b42..62e043b9 100644 --- a/swagger_parser/test/parser/schemas/basic_requests.2.0.json +++ b/swagger_parser/test/parser/schemas/basic_requests.2.0.json @@ -7,8 +7,8 @@ "Auth" ], "consumes": [ - "application/json", "text/json", + "application/json", "application/*+json" ], "produces": [