Skip to content

Commit

Permalink
refactor(dynamite): do not generate _body when not needed
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolas Rimikis <[email protected]>
  • Loading branch information
Leptopoda committed Dec 20, 2023
1 parent b2773b6 commit 738a93f
Show file tree
Hide file tree
Showing 25 changed files with 347 additions and 699 deletions.
11 changes: 6 additions & 5 deletions packages/dynamite/dynamite/lib/src/builder/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,11 @@ Iterable<Method> buildTags(
} else if (acceptHeader.isEmpty) {
code.writeln('final _headers = <String, String>{};');
}

code.writeln('''
Uint8List? _body;
''');
if (operation.requestBody != null) {
code.writeln('Uint8List? _body;');
}
// Separate the declarations from the assignments
code.writeln();

if (hasAuthentication) {
buildAuthCheck(
Expand Down Expand Up @@ -393,7 +394,7 @@ Iterable<Method> buildTags(
'$httpMethod',
_path,
_headers,
_body,
${operation.requestBody != null ? '_body' : 'null'},
''');

if (responses.values.isNotEmpty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,14 @@ class Client extends DynamiteClient {
@experimental
DynamiteRawResponse<void, GetHeaders> $getRaw() {
final _headers = <String, String>{};
Uint8List? _body;

const _path = '/';
return DynamiteRawResponse<void, GetHeaders>(
response: executeRequest(
'get',
_path,
_headers,
_body,
null,
const {200},
),
bodyType: null,
Expand Down Expand Up @@ -105,15 +104,14 @@ class Client extends DynamiteClient {
@experimental
DynamiteRawResponse<void, WithContentOperationIdHeaders> withContentOperationIdRaw() {
final _headers = <String, String>{};
Uint8List? _body;

const _path = '/with_content/operation_id';
return DynamiteRawResponse<void, WithContentOperationIdHeaders>(
response: executeRequest(
'get',
_path,
_headers,
_body,
null,
const {200},
),
bodyType: null,
Expand Down Expand Up @@ -151,15 +149,14 @@ class Client extends DynamiteClient {
const _headers = <String, String>{
'Accept': 'application/octet-stream',
};
Uint8List? _body;

const _path = '/with_content';
return DynamiteRawResponse<Uint8List, GetWithContentHeaders>(
response: executeRequest(
'get',
_path,
_headers,
_body,
null,
const {200},
),
bodyType: const FullType(Uint8List),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ class Client extends DynamiteClient {
const _headers = <String, String>{
'Accept': 'application/json',
};
Uint8List? _body;

final $contentString = jsonSerializers.serialize(
contentString,
Expand Down Expand Up @@ -201,7 +200,7 @@ class Client extends DynamiteClient {
'get',
_path,
_headers,
_body,
null,
const {200},
),
bodyType: const FullType(JsonObject),
Expand Down Expand Up @@ -276,7 +275,6 @@ class Client extends DynamiteClient {
final _headers = <String, String>{
'Accept': 'application/json',
};
Uint8List? _body;

final $array = jsonSerializers.serialize(array, specifiedType: const FullType(BuiltList, [FullType(String)]));
if ($array != null) {
Expand Down Expand Up @@ -314,7 +312,7 @@ class Client extends DynamiteClient {
'get',
_path,
_headers,
_body,
null,
const {200},
),
bodyType: const FullType(JsonObject),
Expand Down Expand Up @@ -355,7 +353,6 @@ class Client extends DynamiteClient {
const _headers = <String, String>{
'Accept': 'application/json',
};
Uint8List? _body;

final $pathParameter = jsonSerializers.serialize(pathParameter, specifiedType: const FullType(String));
_parameters['path_parameter'] = $pathParameter;
Expand All @@ -366,7 +363,7 @@ class Client extends DynamiteClient {
'get',
_path,
_headers,
_body,
null,
const {200},
),
bodyType: const FullType(JsonObject),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// ignore_for_file: unreachable_switch_case
// ignore_for_file: unused_element
// ignore_for_file: no_leading_underscores_for_local_identifiers
import 'dart:typed_data';

import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart';
Expand Down Expand Up @@ -60,15 +59,14 @@ class Client extends DynamiteClient {
const _headers = <String, String>{
'Accept': 'application/json',
};
Uint8List? _body;

const _path = '/';
return DynamiteRawResponse<String, void>(
response: executeRequest(
'get',
_path,
_headers,
_body,
null,
null,
),
bodyType: const FullType(String),
Expand Down Expand Up @@ -108,15 +106,14 @@ class Client extends DynamiteClient {
const _headers = <String, String>{
'Accept': 'application/json',
};
Uint8List? _body;

const _path = '/';
return DynamiteRawResponse<String, void>(
response: executeRequest(
'put',
_path,
_headers,
_body,
null,
const {200},
),
bodyType: const FullType(String),
Expand Down Expand Up @@ -158,15 +155,14 @@ class Client extends DynamiteClient {
const _headers = <String, String>{
'Accept': 'application/json',
};
Uint8List? _body;

const _path = '/';
return DynamiteRawResponse<String, void>(
response: executeRequest(
'post',
_path,
_headers,
_body,
null,
null,
),
bodyType: const FullType(String),
Expand Down Expand Up @@ -206,15 +202,14 @@ class Client extends DynamiteClient {
const _headers = <String, String>{
'Accept': 'application/json',
};
Uint8List? _body;

const _path = '/';
return DynamiteRawResponse<String, void>(
response: executeRequest(
'patch',
_path,
_headers,
_body,
null,
const {200, 201},
),
bodyType: const FullType(String),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ class Client extends DynamiteClient {
const _headers = <String, String>{
'Accept': 'application/json',
};
Uint8List? _body;

var $tags = jsonSerializers.serialize(tags, specifiedType: const FullType(BuiltList, [FullType(String)]));
_parameters['tags'] = $tags;
Expand All @@ -111,7 +110,7 @@ class Client extends DynamiteClient {
'get',
_path,
_headers,
_body,
null,
const {200},
),
bodyType: FullType(BuiltList, [FullType(Pet)]),
Expand Down Expand Up @@ -220,7 +219,6 @@ class Client extends DynamiteClient {
const _headers = <String, String>{
'Accept': 'application/json',
};
Uint8List? _body;

var $id = jsonSerializers.serialize(id, specifiedType: const FullType(int));
_parameters['id'] = $id;
Expand All @@ -231,7 +229,7 @@ class Client extends DynamiteClient {
'get',
_path,
_headers,
_body,
null,
const {200},
),
bodyType: FullType(Pet),
Expand Down Expand Up @@ -282,7 +280,6 @@ class Client extends DynamiteClient {
DynamiteRawResponse<void, void> deletePetRaw({required int id}) {
final _parameters = <String, dynamic>{};
final _headers = <String, String>{};
Uint8List? _body;

var $id = jsonSerializers.serialize(id, specifiedType: const FullType(int));
_parameters['id'] = $id;
Expand All @@ -293,7 +290,7 @@ class Client extends DynamiteClient {
'delete',
_path,
_headers,
_body,
null,
const {204},
),
bodyType: null,
Expand Down
Loading

0 comments on commit 738a93f

Please sign in to comment.