Skip to content

Commit

Permalink
👽 deprecate all lower-case method annotations (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
techouse authored Feb 5, 2025
1 parent a59df12 commit fc60863
Show file tree
Hide file tree
Showing 11 changed files with 490 additions and 352 deletions.
200 changes: 169 additions & 31 deletions chopper/lib/src/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ final class QueryMap {
}

/// {@template Body}
/// Declares the Body of [Post], [Put], and [Patch] requests
/// Declares the Body of [POST], [PUT], and [PATCH] requests
///
/// ```dart
/// @Post()
/// @POST()
/// Future<Response> post(@Body() Map<String, dynamic> body);
/// ```
///
Expand Down Expand Up @@ -163,7 +163,7 @@ final class Header {
/// Must be used inside a [ChopperApi] definition.
///
/// Recommended:
/// [Get], [Post], [Put], [Delete], [Patch], or [Head] should be used instead.
/// [GET], [POST], [PUT], [DELETE], [PATCH], or [HEAD] should be used instead.
///
/// ```dart
/// @Get(headers: const {'foo': 'bar' })
Expand Down Expand Up @@ -251,12 +251,31 @@ sealed class Method {
});
}

/// {@template GET}
/// Defines a method as an HTTP GET request.
/// {@endtemplate}
@immutable
@Target({TargetKind.method})
final class GET extends Method {
/// {@macro GET}
const GET({
super.optionalBody = true,
super.path,
super.headers,
super.listFormat,
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Get);
}

/// {@template Get}
/// Defines a method as an HTTP GET request.
/// {@endtemplate}
@immutable
@Target({TargetKind.method})
final class Get extends Method {
@Deprecated('Use GET instead')
final class Get extends GET {
/// {@macro Get}
const Get({
super.optionalBody = true,
Expand All @@ -266,7 +285,27 @@ final class Get extends Method {
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Get);
});
}

/// {@template POST}
/// Defines a method as an HTTP POST request.
///
/// Use the [Body] annotation to pass data to send.
/// {@endtemplate}
@immutable
@Target({TargetKind.method})
final class POST extends Method {
/// {@macro POST}
const POST({
super.optionalBody,
super.path,
super.headers,
super.listFormat,
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Post);
}

/// {@template Post}
Expand All @@ -276,7 +315,8 @@ final class Get extends Method {
/// {@endtemplate}
@immutable
@Target({TargetKind.method})
final class Post extends Method {
@Deprecated('Use POST instead')
final class Post extends POST {
/// {@macro Post}
const Post({
super.optionalBody,
Expand All @@ -286,15 +326,34 @@ final class Post extends Method {
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Post);
});
}

/// {@template DELETE}
/// Defines a method as an HTTP DELETE request.
/// {@endtemplate}
@immutable
@Target({TargetKind.method})
final class DELETE extends Method {
/// {@macro DELETE}
const DELETE({
super.optionalBody = true,
super.path,
super.headers,
super.listFormat,
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Delete);
}

/// {@template Delete}
/// Defines a method as an HTTP DELETE request.
/// {@endtemplate}
@immutable
@Target({TargetKind.method})
final class Delete extends Method {
@Deprecated('Use DELETE instead')
final class Delete extends DELETE {
/// {@macro Delete}
const Delete({
super.optionalBody = true,
Expand All @@ -304,7 +363,27 @@ final class Delete extends Method {
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Delete);
});
}

/// {@template PUT}
/// Defines a method as an HTTP PUT request.
///
/// Use the [Body] annotation to pass data to send.
/// {@endtemplate}
@immutable
@Target({TargetKind.method})
final class PUT extends Method {
/// {@macro PUT}
const PUT({
super.optionalBody,
super.path,
super.headers,
super.listFormat,
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Put);
}

/// {@template Put}
Expand All @@ -314,7 +393,8 @@ final class Delete extends Method {
/// {@endtemplate}
@immutable
@Target({TargetKind.method})
final class Put extends Method {
@Deprecated('Use PUT instead')
final class Put extends PUT {
/// {@macro Put}
const Put({
super.optionalBody,
Expand All @@ -324,7 +404,26 @@ final class Put extends Method {
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Put);
});
}

/// {@template PATCH}
/// Defines a method as an HTTP PATCH request.
/// Use the [Body] annotation to pass data to send.
/// {@endtemplate}
@immutable
@Target({TargetKind.method})
final class PATCH extends Method {
/// {@macro PATCH}
const PATCH({
super.optionalBody,
super.path,
super.headers,
super.listFormat,
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Patch);
}

/// {@template Patch}
Expand All @@ -333,7 +432,8 @@ final class Put extends Method {
/// {@endtemplate}
@immutable
@Target({TargetKind.method})
final class Patch extends Method {
@Deprecated('Use PATCH instead')
final class Patch extends PATCH {
/// {@macro Patch}
const Patch({
super.optionalBody,
Expand All @@ -343,15 +443,34 @@ final class Patch extends Method {
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Patch);
});
}

/// {@template HEAD}
/// Defines a method as an HTTP HEAD request.
/// {@endtemplate}
@immutable
@Target({TargetKind.method})
final class HEAD extends Method {
/// {@macro HEAD}
const HEAD({
super.optionalBody = true,
super.path,
super.headers,
super.listFormat,
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Head);
}

/// {@template Head}
/// Defines a method as an HTTP HEAD request.
/// {@endtemplate}
@immutable
@Target({TargetKind.method})
final class Head extends Method {
@Deprecated('Use HEAD instead')
final class Head extends HEAD {
/// {@macro Head}
const Head({
super.optionalBody = true,
Expand All @@ -361,15 +480,34 @@ final class Head extends Method {
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Head);
});
}

/// {@template OPTIONS}
/// Defines a method as an HTTP OPTIONS request.
/// {@endtemplate}
@immutable
@Target({TargetKind.method})
final class OPTIONS extends Method {
/// {@macro OPTIONS}
const OPTIONS({
super.optionalBody = true,
super.path,
super.headers,
super.listFormat,
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Options);
}

/// {@template Options}
/// Defines a method as an HTTP OPTIONS request.
/// {@endtemplate}
@immutable
@Target({TargetKind.method})
final class Options extends Method {
@Deprecated('Use OPTIONS instead')
final class Options extends OPTIONS {
/// {@macro Options}
const Options({
super.optionalBody = true,
Expand All @@ -379,7 +517,7 @@ final class Options extends Method {
super.useBrackets,
super.includeNullQueryVars,
super.timeout,
}) : super(HttpMethod.Options);
});
}

/// A function that should convert the body of a [Request] to the HTTP representation.
Expand Down Expand Up @@ -626,26 +764,26 @@ const queryMap = QueryMap();
/// {@macro Header}
const header = Header();

/// {@macro Get}
const get = Get();
/// {@macro GET}
const get = GET();

/// {@macro Post}
const post = Post();
/// {@macro POST}
const post = POST();

/// {@macro Delete}
const delete = Delete();
/// {@macro DELETE}
const delete = DELETE();

/// {@macro Put}
const put = Put();
/// {@macro PUT}
const put = PUT();

/// {@macro Patch}
const patch = Patch();
/// {@macro PATCH}
const patch = PATCH();

/// {@macro Head}
const head = Head();
/// {@macro HEAD}
const head = HEAD();

/// {@macro Options}
const options = Options();
/// {@macro OPTIONS}
const options = OPTIONS();

/// {@macro FactoryConverter}
const factoryConverter = FactoryConverter();
Expand Down
Loading

0 comments on commit fc60863

Please sign in to comment.