Skip to content

Commit 917bac4

Browse files
committed
refactor(dynamite): simplify mimetype resolving
Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
1 parent 688bba7 commit 917bac4

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

packages/dynamite/dynamite/lib/src/builder/resolve_mime_type.dart

+8-14
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,21 @@ void resolveMimeTypeEncode(
4848
output.writeln("_request.headers['Content-Type'] = '$mimeType';");
4949
final parameterName = toDartName(result.name);
5050

51+
if (result.nullable) {
52+
output.writeln('if ($parameterName != null) {');
53+
}
54+
5155
switch (mimeType) {
5256
case 'application/json':
5357
case 'application/x-www-form-urlencoded':
54-
if (result.nullable) {
55-
output.writeln('if ($parameterName != null) {');
56-
}
5758
output.writeln('_request.body = ${result.encode(parameterName, mimeType: mimeType)};');
58-
if (result.nullable) {
59-
output.writeln('}');
60-
}
61-
return;
6259
case 'application/octet-stream':
63-
if (result.nullable) {
64-
output.writeln('if ($parameterName != null) {');
65-
}
6660
output.writeln('_request.bodyBytes = ${result.encode(parameterName, mimeType: mimeType)};');
67-
if (result.nullable) {
68-
output.writeln('}');
69-
}
70-
return;
7161
case _:
7262
throw Exception('Can not parse any mime type of the Operation.');
7363
}
64+
65+
if (result.nullable) {
66+
output.writeln('}');
67+
}
7468
}

0 commit comments

Comments
 (0)