Skip to content

Commit

Permalink
refactor(dynamite): simplify mimetype resolving
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
  • Loading branch information
Leptopoda committed Apr 29, 2024
1 parent 688bba7 commit 917bac4
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions packages/dynamite/dynamite/lib/src/builder/resolve_mime_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,21 @@ void resolveMimeTypeEncode(
output.writeln("_request.headers['Content-Type'] = '$mimeType';");
final parameterName = toDartName(result.name);

if (result.nullable) {
output.writeln('if ($parameterName != null) {');
}

switch (mimeType) {
case 'application/json':
case 'application/x-www-form-urlencoded':
if (result.nullable) {
output.writeln('if ($parameterName != null) {');
}
output.writeln('_request.body = ${result.encode(parameterName, mimeType: mimeType)};');
if (result.nullable) {
output.writeln('}');
}
return;
case 'application/octet-stream':
if (result.nullable) {
output.writeln('if ($parameterName != null) {');
}
output.writeln('_request.bodyBytes = ${result.encode(parameterName, mimeType: mimeType)};');
if (result.nullable) {
output.writeln('}');
}
return;
case _:
throw Exception('Can not parse any mime type of the Operation.');
}

if (result.nullable) {
output.writeln('}');
}
}

0 comments on commit 917bac4

Please sign in to comment.