Skip to content

Commit

Permalink
Fixed getting first available content type for parametersV2 method (#133
Browse files Browse the repository at this point in the history
)

Co-authored-by: Elena Ferro <[email protected]>
  • Loading branch information
elenaferr0 and Elena Ferro authored Oct 31, 2023
1 parent a9c4b4f commit 4e5eaf6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand All @@ -71,6 +72,7 @@ final class UniversalRequest {
requestType.hashCode ^
route.hashCode ^
returnType.hashCode ^
contentType.hashCode ^
parameters.hashCode ^
isMultiPart.hashCode ^
isFormUrlEncoded.hashCode;
Expand Down
2 changes: 2 additions & 0 deletions swagger_parser/lib/src/parser/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<dynamic>) {
Expand Down
3 changes: 2 additions & 1 deletion swagger_parser/test/parser/requests_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -110,7 +111,7 @@ void main() {
),
];
for (var i = 0; i < actualRestClients.length; i++) {
expect(actualRestClients.last, expectedRestClients.last);
expect(actualRestClients[i], expectedRestClients[i]);
}
});

Expand Down
2 changes: 1 addition & 1 deletion swagger_parser/test/parser/schemas/basic_requests.2.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"Auth"
],
"consumes": [
"application/json",
"text/json",
"application/json",
"application/*+json"
],
"produces": [
Expand Down

0 comments on commit 4e5eaf6

Please sign in to comment.