trevorwang / retrofit.dart

retrofit.dart is an dio client generator using source_gen and inspired by Chopper and Retrofit.
https://mings.in/retrofit.dart/
MIT License
1.06k stars 241 forks source link

Nullable Body not null checked #662

Open dickermoshe opened 4 months ago

dickermoshe commented 4 months ago

Describe the bug If you use a nullable property it is not type checked

To Reproduce

import 'dart:io';

import 'package:dio/dio.dart';
import 'package:retrofit/retrofit.dart';

part 'client_client.g.dart';

@RestApi()
abstract class ClientClient {
  factory ClientClient(Dio dio, {String? baseUrl}) = _ClientClient;

  /// test upload.
  ///
  /// upload test.
  @POST('/test/upload')
  Future<void> testUpload({
    @Body() required File requiredBody,
  });
}

Results in:

  @override
  Future<void> testUpload({File? nullableBody}) async {
    final _extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    queryParameters.removeWhere((k, v) => v == null);
    final _headers = <String, dynamic>{};
    final _data =
        Stream.fromIterable(nullableBody.readAsBytesSync().map((i) => [i])); // This should be checked for null !!
    await _dio.fetch<void>(_setStreamType<void>(Options(
      method: 'POST',
      headers: _headers,
      extra: _extra,
    )
        .compose(
          _dio.options,
          '/test/upload',
          queryParameters: queryParameters,
          data: _data,
        )
        .copyWith(
            baseUrl: _combineBaseUrls(
          _dio.options.baseUrl,
          baseUrl,
        ))));
  }

Expected behavior Should check for null