Browse Source

Merge pull request #204 from provokateurin/feature/better-mime-types-handling

dynamite: Handle more response mime types and in a better way
pull/205/head
Kate 2 years ago committed by GitHub
parent
commit
f05e23c389
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      packages/dynamite/lib/src/openapi_builder.dart

34
packages/dynamite/lib/src/openapi_builder.dart

@ -816,25 +816,21 @@ class OpenAPIBuilder implements Builder {
), ),
mediaType.schema!, mediaType.schema!,
); );
switch (mimeType) { if (mimeType == '*/*' || mimeType.startsWith('image/')) {
case 'application/json': dataType = 'Uint8List';
dataType = result.name; dataValue = 'response.body';
if (result.name == 'dynamic') { } else if (mimeType.startsWith('text/')) {
dataValue = ''; dataType = 'String';
} else { dataValue = 'utf8.decode(response.body)';
dataValue = result.deserialize(result.decode('utf8.decode(response.body)')); } else if (mimeType == 'application/json') {
} dataType = result.name;
break; if (result.name == 'dynamic') {
case 'image/png': dataValue = '';
dataType = 'Uint8List'; } else {
dataValue = 'response.body'; dataValue = result.deserialize(result.decode('utf8.decode(response.body)'));
break; }
case 'text/plain': } else {
dataType = 'String'; throw Exception('Can not parse mime type "$mimeType"');
dataValue = 'utf8.decode(response.body)';
break;
default:
throw Exception('Can not parse mime type "$mimeType"');
} }
} }
} }

Loading…
Cancel
Save