Skip to content

Commit

Permalink
📝 Added dartdoc @template to share docs between class and constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
Guldem committed Jan 5, 2024
1 parent 4ff9bbc commit 77565a6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chopper/lib/src/http_logging_interceptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ enum Level {
body,
}

/// {@template http_logging_interceptor}
/// A [RequestInterceptor] and [ResponseInterceptor] implementation which logs
/// HTTP request and response data.
///
Expand All @@ -70,9 +71,11 @@ enum Level {
/// leak sensitive information, such as `Authorization` headers and user data
/// in response bodies. This interceptor should only be used in a controlled way
/// or in a non-production environment.
/// {@endtemplate}
@immutable
class HttpLoggingInterceptor
implements RequestInterceptor, ResponseInterceptor {
/// {@macro http_logging_interceptor}
HttpLoggingInterceptor({this.level = Level.body, Logger? logger})
: _logger = logger ?? chopperLogger,
_logBody = level == Level.body,
Expand Down
9 changes: 9 additions & 0 deletions chopper/lib/src/interceptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,17 @@ abstract interface class ErrorConverter {
FutureOr<Response> convertError<BodyType, InnerType>(Response response);
}

/// {@template HeadersInterceptor}
/// A [RequestInterceptor] that adds [headers] to every request.
///
/// Note that this interceptor will overwrite existing headers having the same
/// keys as [headers].
/// {@endtemplate}
@immutable
class HeadersInterceptor implements RequestInterceptor {
final Map<String, String> headers;

/// {@macro HeadersInterceptor}
const HeadersInterceptor(this.headers);

@override
Expand Down Expand Up @@ -163,6 +166,7 @@ class CurlInterceptor implements RequestInterceptor {
}
}

/// {@template JsonConverter}
/// A [Converter] implementation that calls [json.encode] on [Request]s and
/// [json.decode] on [Response]s using the [dart:convert](https://api.dart.dev/stable/2.10.3/dart-convert/dart-convert-library.html)
/// package's [utf8] and [json] utilities.
Expand All @@ -176,8 +180,10 @@ class CurlInterceptor implements RequestInterceptor {
/// If content type header is modified (for example by using
/// `@Post(headers: {'content-type': '...'})`), `JsonConverter` won't add the
/// header and it won't call json.encode if content type is not JSON.
/// {@endtemplate}
@immutable
class JsonConverter implements Converter, ErrorConverter {
/// {@macro JsonConverter}
const JsonConverter();

@override
Expand Down Expand Up @@ -270,13 +276,16 @@ class JsonConverter implements Converter, ErrorConverter {
}
}

/// {@template FormUrlEncodedConverter}
/// A [Converter] implementation that converts only [Request]s having a [Map] as their body.
///
/// This `Converter` also adds the `content-type: application/x-www-form-urlencoded`
/// header to each request, but only if the `content-type` header is not set in
/// the original request.
/// {@endtemplate}
@immutable
class FormUrlEncodedConverter implements Converter, ErrorConverter {
/// {@macro FormUrlEncodedConverter}
const FormUrlEncodedConverter();

@override
Expand Down
3 changes: 3 additions & 0 deletions chopper/lib/src/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import 'package:equatable/equatable.dart' show EquatableMixin;
import 'package:http/http.dart' as http;
import 'package:meta/meta.dart';

/// {@template request}
/// This class represents an HTTP request that can be made with Chopper.
/// {@endtemplate}
base class Request extends http.BaseRequest with EquatableMixin {
final Uri uri;
final Uri baseUri;
Expand All @@ -17,6 +19,7 @@ base class Request extends http.BaseRequest with EquatableMixin {
final bool useBrackets;
final bool includeNullQueryVars;

/// {@macro request}
Request(
String method,
this.uri,
Expand Down
3 changes: 3 additions & 0 deletions chopper/lib/src/response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:equatable/equatable.dart' show EquatableMixin;
import 'package:http/http.dart' as http;
import 'package:meta/meta.dart';

/// {@template response}
/// A [http.BaseResponse] wrapper representing a response of a Chopper network call.
///
/// ```dart
Expand All @@ -16,6 +17,7 @@ import 'package:meta/meta.dart';
/// @Get(path: '/items/{id}')
/// Future<Response<Item>> fetchItem();
/// ```
/// {@endtemplate}
@immutable
base class Response<BodyType> with EquatableMixin {
/// The [http.BaseResponse] from `package:http` that this [Response] wraps.
Expand All @@ -31,6 +33,7 @@ base class Response<BodyType> with EquatableMixin {
/// The body of the response if [isSuccessful] is false.
final Object? error;

/// {@macro response}
const Response(this.base, this.body, {this.error});

/// Makes a copy of this Response, replacing original values with the given ones.
Expand Down

0 comments on commit 77565a6

Please sign in to comment.