From 41b1bef6b06ba8a74806f636f99a89f85b1c1444 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Tue, 28 Feb 2023 16:01:40 +0100 Subject: [PATCH] dynamite: Handle more response mime types and in a better way --- .../dynamite/lib/src/openapi_builder.dart | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/packages/dynamite/lib/src/openapi_builder.dart b/packages/dynamite/lib/src/openapi_builder.dart index fe22beca..eb15f326 100644 --- a/packages/dynamite/lib/src/openapi_builder.dart +++ b/packages/dynamite/lib/src/openapi_builder.dart @@ -810,25 +810,21 @@ class OpenAPIBuilder implements Builder { ), mediaType.schema!, ); - switch (mimeType) { - case 'application/json': - dataType = result.name; - if (result.name == 'dynamic') { - dataValue = ''; - } else { - dataValue = result.deserialize(result.decode('utf8.decode(response.body)')); - } - break; - case 'image/png': - dataType = 'Uint8List'; - dataValue = 'response.body'; - break; - case 'text/plain': - dataType = 'String'; - dataValue = 'utf8.decode(response.body)'; - break; - default: - throw Exception('Can not parse mime type "$mimeType"'); + if (mimeType == '*/*' || mimeType.startsWith('image/')) { + dataType = 'Uint8List'; + dataValue = 'response.body'; + } else if (mimeType.startsWith('text/')) { + dataType = 'String'; + dataValue = 'utf8.decode(response.body)'; + } else if (mimeType == 'application/json') { + dataType = result.name; + if (result.name == 'dynamic') { + dataValue = ''; + } else { + dataValue = result.deserialize(result.decode('utf8.decode(response.body)')); + } + } else { + throw Exception('Can not parse mime type "$mimeType"'); } } }