Browse Source

feat(dynamite): gracefully handle multiple mimeTypes and default responses

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/870/head
Nikolas Rimikis 1 year ago
parent
commit
d0af01067b
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 6
      packages/dynamite/dynamite/lib/src/builder/client.dart
  2. 11
      packages/dynamite/dynamite/lib/src/builder/resolve_mime_type.dart

6
packages/dynamite/dynamite/lib/src/builder/client.dart

@ -193,7 +193,11 @@ Iterable<Method> buildTags(
var responses = <openapi.Response, List<int>>{};
if (operation.responses != null) {
for (final responseEntry in operation.responses!.entries) {
final statusCode = int.parse(responseEntry.key);
final statusCode = int.tryParse(responseEntry.key);
if (statusCode == null) {
print('Default responses are not supported right now. Skipping it for $operationId');
continue;
}
final response = responseEntry.value;
responses[response] ??= [];

11
packages/dynamite/dynamite/lib/src/builder/resolve_mime_type.dart

@ -15,7 +15,7 @@ TypeResult? resolveMimeTypeDecode(
) {
if (response.content != null) {
if (response.content!.length > 1) {
throw Exception('Can not work with multiple mime types right now');
print('Can not work with multiple mime types right now. Using the first supported.');
}
for (final content in response.content!.entries) {
@ -35,10 +35,9 @@ TypeResult? resolveMimeTypeDecode(
return TypeResultBase('String');
} else if (mimeType == 'application/json') {
return result;
} else {
throw Exception('Can not parse mime type "$mimeType"');
}
}
throw Exception('Can not parse any mime type of Operation: "$identifier"');
}
return null;
}
@ -52,7 +51,7 @@ Iterable<String> resolveMimeTypeEncode(
) sync* {
if (operation.requestBody != null) {
if (operation.requestBody!.content!.length > 1) {
throw Exception('Can not work with multiple mime types right now');
print('Can not work with multiple mime types right now. Using the first supported.');
}
for (final content in operation.requestBody!.content!.entries) {
final mimeType = content.key;
@ -121,9 +120,9 @@ Iterable<String> resolveMimeTypeEncode(
yield '}';
}
return;
default:
throw Exception('Can not parse mime type "$mimeType"');
}
}
throw Exception('Can not parse any mime type of Operation: "$identifier"');
}
}

Loading…
Cancel
Save