Browse Source

Merge pull request #870 from nextcloud/feat/dynamite/multiple_responses

gracefully handle multiple mimeTypes and default responses
pull/585/head
Nikolas Rimikis 1 year ago committed by GitHub
parent
commit
56489f9da9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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>>{}; var responses = <openapi.Response, List<int>>{};
if (operation.responses != null) { if (operation.responses != null) {
for (final responseEntry in operation.responses!.entries) { 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; final response = responseEntry.value;
responses[response] ??= []; 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 != null) {
if (response.content!.length > 1) { 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) { for (final content in response.content!.entries) {
@ -35,10 +35,9 @@ TypeResult? resolveMimeTypeDecode(
return TypeResultBase('String'); return TypeResultBase('String');
} else if (mimeType == 'application/json') { } else if (mimeType == 'application/json') {
return result; return result;
} else {
throw Exception('Can not parse mime type "$mimeType"');
} }
} }
throw Exception('Can not parse any mime type of Operation: "$identifier"');
} }
return null; return null;
} }
@ -52,7 +51,7 @@ Iterable<String> resolveMimeTypeEncode(
) sync* { ) sync* {
if (operation.requestBody != null) { if (operation.requestBody != null) {
if (operation.requestBody!.content!.length > 1) { 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) { for (final content in operation.requestBody!.content!.entries) {
final mimeType = content.key; final mimeType = content.key;
@ -121,9 +120,9 @@ Iterable<String> resolveMimeTypeEncode(
yield '}'; yield '}';
} }
return; return;
default:
throw Exception('Can not parse mime type "$mimeType"');
} }
} }
throw Exception('Can not parse any mime type of Operation: "$identifier"');
} }
} }

Loading…
Cancel
Save