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. 20
      packages/dynamite/lib/src/openapi_builder.dart

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

@ -816,24 +816,20 @@ class OpenAPIBuilder implements Builder {
),
mediaType.schema!,
);
switch (mimeType) {
case 'application/json':
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)'));
}
break;
case 'image/png':
dataType = 'Uint8List';
dataValue = 'response.body';
break;
case 'text/plain':
dataType = 'String';
dataValue = 'utf8.decode(response.body)';
break;
default:
} else {
throw Exception('Can not parse mime type "$mimeType"');
}
}

Loading…
Cancel
Save