Skip to content

Commit

Permalink
Release 5.1.0 (master) (#374)
Browse files Browse the repository at this point in the history
* Fix Header Option Casting (#260)

Co-authored-by: Ivan Terekhin <i.terhin@gmail.com>

* Fix for #259 (#263)

* 4.0.1 fixes (#264)

* analyzer dependency upgraded (#296)

* fix(generator): fix PartValueFile value not nullable if arg is (#288) (#293)

* Chopper generator release 4.0.2 (#297)

* fix: fix this.body cast of null value when response body is null (#291) (#292)

* Interpolation fixes (#275)

* encodeQueryComponent now encodeComponent (#278)

* Prevent double call on token refreshment (#276)

* Fixes for #309 #308 (#310)

* Remove new keyword from interceptors.md (#312)

* Analyzer upgrade (#320)

Co-authored-by: István Juhos <stewemetal@gmail.com>

* Add unnecessary_brace_in_string_interps to lint ignores (#317)

* Extend pragma to quiet the linter (#318)

Co-authored-by: Ivan Terekhin <i.terhin@gmail.com>

* Fix converter getting called twice if using an authenticator with a JsonConverter on the request (#324)

* migrate example to nullsafety (#331)

* Resolve problem in main_json_serializable example (#328)

* Add @FiledMap @PartMap @PartFileMap (#335)

Co-authored-by: Meysam Karimi <mysmartapply.it4@gmail.com>

* Upgrade of analyzer (#340)

* Fix nullable QueryMap fails to compile (#344)

* Change return type of decodeJson to FutureOr in order to be able to support compute() (#345)

* Migrate from pedantic to lints ^2.0.0 with lints/recommended.yaml (#349)

* Version bumped for release (#352)

* Revert analyzer to ^4.1.0 and silence linters for Element.enclosingElement (#354)

* [chopper_generator] Update analyzer to ^4.4.0 and code_builde to ^4.3.0 and migrate deprecated code (#358)

* Add Makefiles to streamline development (#357)

* Add Bug Report Github issue template (#359)

* [chopper_generator] Add types to the generated variables (#360)

* Provide an example using an Isolate Worker Pool with Squadron (#361)

* mapToQuery changes (#364)

* Version bumped / changelog update (#367)

* Request extends http.BaseRequest (#370)

* Exclude null query vars by default and add new @method annotation includeNullQueryVars (#372)

* 5.1.0 (dev) (#373)

Co-authored-by: Ivan Terekhin <231950+JEuler@users.noreply.github.com>

Co-authored-by: Youssef Raafat <youssefraafatnasry@gmail.com>
Co-authored-by: luis901101 <luis901101@gmail.com>
Co-authored-by: melvspace <ratealt@gmail.com>
Co-authored-by: Michal Šrůtek <35694712+michalsrutek@users.noreply.github.com>
Co-authored-by: István Juhos <stewemetal@gmail.com>
Co-authored-by: Andre <andre.lipke@gmail.com>
Co-authored-by: John Wimer <john@wimer.org>
Co-authored-by: Max Röhrl <max.roehrl11@gmail.com>
Co-authored-by: ipcjs <gipcjs@gmail.com>
Co-authored-by: ibadin <exbatek@gmail.com>
Co-authored-by: Meysam Karimi <31154534+meysam1717@users.noreply.github.com>
Co-authored-by: Meysam Karimi <mysmartapply.it4@gmail.com>
Co-authored-by: Klemen Tusar <techouse@gmail.com>
Co-authored-by: Klemen Tusar <k.tusar@cmcmarkets.com>
Co-authored-by: Ivan Terekhin <231950+JEuler@users.noreply.github.com>
  • Loading branch information
16 people committed Oct 15, 2022
1 parent 28da5ef commit 0e5f986
Show file tree
Hide file tree
Showing 23 changed files with 1,117 additions and 261 deletions.
5 changes: 5 additions & 0 deletions chopper/CHANGELOG.md
@@ -1,5 +1,10 @@
# Changelog

## 5.1.0

- Base class changed for http.BaseRequest
- Annotation to include null vars in query

## 5.0.1

- mapToQuery changes
Expand Down
1 change: 1 addition & 0 deletions chopper/lib/chopper.dart
Expand Up @@ -7,6 +7,7 @@ export 'src/annotations.dart';
export 'src/authenticator.dart';
export 'src/base.dart';
export 'src/constants.dart';
export 'src/extensions.dart';
export 'src/interceptor.dart';
export 'src/request.dart';
export 'src/response.dart';
Expand Down
41 changes: 37 additions & 4 deletions chopper/lib/src/annotations.dart
@@ -1,11 +1,10 @@
import 'dart:async';

import 'package:chopper/src/constants.dart';
import 'package:chopper/src/request.dart';
import 'package:chopper/src/response.dart';
import 'package:meta/meta.dart';

import 'constants.dart';
import 'request.dart';
import 'response.dart';

/// Defines a Chopper API.
///
/// Must be used on an abstract class that extends the [ChopperService] class.
Expand Down Expand Up @@ -170,12 +169,39 @@ class Method {
/// hxxp://path/to/script?user[name]=john&user[surname]=doe&user[age]=21
final bool useBrackets;

/// Set to [true] to include query variables with null values. This includes nested maps.
/// The default is to exclude them.
///
/// NOTE: Empty strings are always included.
///
/// ```dart
/// @Get(
/// path: '/script',
/// includeNullQueryVars: true,
/// )
/// Future<Response<String>> getData({
/// @Query('foo') String? foo,
/// @Query('bar') String? bar,
/// @Query('baz') String? baz,
/// });
///
/// final response = await service.getData(
/// foo: 'foo_val',
/// bar: null, // omitting it would have the same effect
/// baz: 'baz_val',
/// );
/// ```
///
/// The above code produces hxxp://path/to/script&foo=foo_var&bar=&baz=baz_var
final bool includeNullQueryVars;

const Method(
this.method, {
this.optionalBody = false,
this.path = '',
this.headers = const {},
this.useBrackets = false,
this.includeNullQueryVars = false,
});
}

Expand All @@ -187,6 +213,7 @@ class Get extends Method {
super.path,
super.headers,
super.useBrackets,
super.includeNullQueryVars,
}) : super(HttpMethod.Get);
}

Expand All @@ -200,6 +227,7 @@ class Post extends Method {
super.path,
super.headers,
super.useBrackets,
super.includeNullQueryVars,
}) : super(HttpMethod.Post);
}

Expand All @@ -211,6 +239,7 @@ class Delete extends Method {
super.path,
super.headers,
super.useBrackets,
super.includeNullQueryVars,
}) : super(HttpMethod.Delete);
}

Expand All @@ -224,6 +253,7 @@ class Put extends Method {
super.path,
super.headers,
super.useBrackets,
super.includeNullQueryVars,
}) : super(HttpMethod.Put);
}

Expand All @@ -236,6 +266,7 @@ class Patch extends Method {
super.path,
super.headers,
super.useBrackets,
super.includeNullQueryVars,
}) : super(HttpMethod.Patch);
}

Expand All @@ -247,6 +278,7 @@ class Head extends Method {
super.path,
super.headers,
super.useBrackets,
super.includeNullQueryVars,
}) : super(HttpMethod.Head);
}

Expand All @@ -257,6 +289,7 @@ class Options extends Method {
super.path,
super.headers,
super.useBrackets,
super.includeNullQueryVars,
}) : super(HttpMethod.Options);
}

Expand Down
15 changes: 7 additions & 8 deletions chopper/lib/src/base.dart
@@ -1,16 +1,15 @@
import 'dart:async';

import 'package:chopper/src/annotations.dart';
import 'package:chopper/src/authenticator.dart';
import 'package:chopper/src/constants.dart';
import 'package:chopper/src/interceptor.dart';
import 'package:chopper/src/request.dart';
import 'package:chopper/src/response.dart';
import 'package:chopper/src/utils.dart';
import 'package:http/http.dart' as http;
import 'package:meta/meta.dart';

import 'annotations.dart';
import 'authenticator.dart';
import 'constants.dart';
import 'interceptor.dart';
import 'request.dart';
import 'response.dart';
import 'utils.dart';

Type _typeOf<T>() => T;

@visibleForTesting
Expand Down
2 changes: 1 addition & 1 deletion chopper/lib/src/constants.dart
Expand Up @@ -7,7 +7,7 @@ const String formEncodedHeaders = 'application/x-www-form-urlencoded';
// Represent the header for a json api response https://jsonapi.org/#mime-types
const String jsonApiHeaders = 'application/vnd.api+json';

class HttpMethod {
abstract class HttpMethod {
static const String Get = 'GET';
static const String Post = 'POST';
static const String Put = 'PUT';
Expand Down
27 changes: 27 additions & 0 deletions chopper/lib/src/extensions.dart
@@ -0,0 +1,27 @@
extension StripStringExtension on String {
/// The string without any leading whitespace and optional [character]
String leftStrip([String? character]) {
final String trimmed = trimLeft();

if (character != null && trimmed.startsWith(character)) {
return trimmed.substring(1);
}

return trimmed;
}

/// The string without any trailing whitespace and optional [character]
String rightStrip([String? character]) {
final String trimmed = trimRight();

if (character != null && trimmed.endsWith(character)) {
return trimmed.substring(0, trimmed.length - 1);
}

return trimmed;
}

/// The string without any leading and trailing whitespace and optional [character]
String strip([String? character]) =>
character != null ? leftStrip(character).rightStrip(character) : trim();
}
13 changes: 6 additions & 7 deletions chopper/lib/src/interceptor.dart
@@ -1,14 +1,13 @@
import 'dart:async';
import 'dart:convert';

import 'package:chopper/src/constants.dart';
import 'package:chopper/src/request.dart';
import 'package:chopper/src/response.dart';
import 'package:chopper/src/utils.dart';
import 'package:http/http.dart' as http;
import 'package:meta/meta.dart';

import 'constants.dart';
import 'request.dart';
import 'response.dart';
import 'utils.dart';

/// An interface for implementing response interceptors.
///
/// [ResponseInterceptor]s are called after [Converter.convertResponse].
Expand Down Expand Up @@ -172,7 +171,7 @@ class HttpLoggingInterceptor
@override
FutureOr<Request> onRequest(Request request) async {
final http.BaseRequest base = await request.toBaseRequest();
chopperLogger.info('--> ${base.method} ${base.url}');
chopperLogger.info('--> ${base.method} ${base.url.toString()}');
base.headers.forEach((k, v) => chopperLogger.info('$k: $v'));

String bytes = '';
Expand All @@ -192,7 +191,7 @@ class HttpLoggingInterceptor
@override
FutureOr<Response> onResponse(Response response) {
final http.BaseRequest? base = response.base.request;
chopperLogger.info('<-- ${response.statusCode} ${base!.url}');
chopperLogger.info('<-- ${response.statusCode} ${base!.url.toString()}');

response.base.headers.forEach((k, v) => chopperLogger.info('$k: $v'));

Expand Down

0 comments on commit 0e5f986

Please sign in to comment.