diff --git a/analysis_options.yaml b/analysis_options.yaml index 44006ea..4384ee7 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -3,4 +3,6 @@ analyzer: exclude: - "**/*.freezed.dart" - "**/*.g.dart" - - "example/misskey_dart_flutter_app_example/**" \ No newline at end of file + - "example/misskey_dart_flutter_app_example/**" + errors: + invalid_annotation_target: false \ No newline at end of file diff --git a/lib/src/data/i/i_notifications_request.g.dart b/lib/src/data/i/i_notifications_request.g.dart index ae689d1..b1bf0ab 100644 --- a/lib/src/data/i/i_notifications_request.g.dart +++ b/lib/src/data/i/i_notifications_request.g.dart @@ -61,4 +61,5 @@ const _$NotificationTypeEnumMap = { NotificationType.roleAssigned: 'roleAssigned', NotificationType.exportCompleted: 'exportCompleted', NotificationType.login: 'login', + NotificationType.unknown: 'unknown', }; diff --git a/lib/src/data/i/i_notifications_response.dart b/lib/src/data/i/i_notifications_response.dart index a25c4a4..ad2e3a8 100644 --- a/lib/src/data/i/i_notifications_response.dart +++ b/lib/src/data/i/i_notifications_response.dart @@ -11,6 +11,7 @@ class INotificationsResponse with _$INotificationsResponse { const factory INotificationsResponse({ required String id, @DateTimeConverter() required DateTime createdAt, + @JsonKey(unknownEnumValue: NotificationType.unknown) required NotificationType type, String? noteId, String? followRequestId, diff --git a/lib/src/data/i/i_notifications_response.freezed.dart b/lib/src/data/i/i_notifications_response.freezed.dart index 0ff64de..78bb2fc 100644 --- a/lib/src/data/i/i_notifications_response.freezed.dart +++ b/lib/src/data/i/i_notifications_response.freezed.dart @@ -24,6 +24,7 @@ mixin _$INotificationsResponse { String get id => throw _privateConstructorUsedError; @DateTimeConverter() DateTime get createdAt => throw _privateConstructorUsedError; + @JsonKey(unknownEnumValue: NotificationType.unknown) NotificationType get type => throw _privateConstructorUsedError; String? get noteId => throw _privateConstructorUsedError; String? get followRequestId => throw _privateConstructorUsedError; @@ -59,6 +60,7 @@ abstract class $INotificationsResponseCopyWith<$Res> { $Res call( {String id, @DateTimeConverter() DateTime createdAt, + @JsonKey(unknownEnumValue: NotificationType.unknown) NotificationType type, String? noteId, String? followRequestId, @@ -245,6 +247,7 @@ abstract class _$$INotificationsResponseImplCopyWith<$Res> $Res call( {String id, @DateTimeConverter() DateTime createdAt, + @JsonKey(unknownEnumValue: NotificationType.unknown) NotificationType type, String? noteId, String? followRequestId, @@ -391,7 +394,7 @@ class _$INotificationsResponseImpl implements _INotificationsResponse { const _$INotificationsResponseImpl( {required this.id, @DateTimeConverter() required this.createdAt, - required this.type, + @JsonKey(unknownEnumValue: NotificationType.unknown) required this.type, this.noteId, this.followRequestId, this.reaction, @@ -418,6 +421,7 @@ class _$INotificationsResponseImpl implements _INotificationsResponse { @DateTimeConverter() final DateTime createdAt; @override + @JsonKey(unknownEnumValue: NotificationType.unknown) final NotificationType type; @override final String? noteId; @@ -534,6 +538,7 @@ abstract class _INotificationsResponse implements INotificationsResponse { const factory _INotificationsResponse( {required final String id, @DateTimeConverter() required final DateTime createdAt, + @JsonKey(unknownEnumValue: NotificationType.unknown) required final NotificationType type, final String? noteId, final String? followRequestId, @@ -561,6 +566,7 @@ abstract class _INotificationsResponse implements INotificationsResponse { @DateTimeConverter() DateTime get createdAt; @override + @JsonKey(unknownEnumValue: NotificationType.unknown) NotificationType get type; @override String? get noteId; diff --git a/lib/src/data/i/i_notifications_response.g.dart b/lib/src/data/i/i_notifications_response.g.dart index ade3631..9aed4e2 100644 --- a/lib/src/data/i/i_notifications_response.g.dart +++ b/lib/src/data/i/i_notifications_response.g.dart @@ -12,7 +12,8 @@ _$INotificationsResponseImpl _$$INotificationsResponseImplFromJson( id: json['id'] as String, createdAt: const DateTimeConverter().fromJson(json['createdAt'] as String), - type: $enumDecode(_$NotificationTypeEnumMap, json['type']), + type: $enumDecode(_$NotificationTypeEnumMap, json['type'], + unknownValue: NotificationType.unknown), noteId: json['noteId'] as String?, followRequestId: json['followRequestId'] as String?, reaction: json['reaction'] as String?, @@ -85,6 +86,7 @@ const _$NotificationTypeEnumMap = { NotificationType.roleAssigned: 'roleAssigned', NotificationType.exportCompleted: 'exportCompleted', NotificationType.login: 'login', + NotificationType.unknown: 'unknown', }; Value? _$JsonConverterFromJson( diff --git a/lib/src/data/streaming/note_updated_event.g.dart b/lib/src/data/streaming/note_updated_event.g.dart index 9bd6b72..b175f35 100644 --- a/lib/src/data/streaming/note_updated_event.g.dart +++ b/lib/src/data/streaming/note_updated_event.g.dart @@ -28,4 +28,5 @@ const _$NoteUpdatedEventTypeEnumMap = { NoteUpdatedEventType.deleted: 'deleted', NoteUpdatedEventType.pollVoted: 'pollVoted', NoteUpdatedEventType.updated: 'updated', + NoteUpdatedEventType.unknown: 'unknown', }; diff --git a/lib/src/data/streaming/streaming_response.g.dart b/lib/src/data/streaming/streaming_response.g.dart index 676bb78..c0d0de6 100644 --- a/lib/src/data/streaming/streaming_response.g.dart +++ b/lib/src/data/streaming/streaming_response.g.dart @@ -215,6 +215,7 @@ const _$ChannelEventTypeEnumMap = { ChannelEventType.driveFileCreated: 'driveFileCreated', ChannelEventType.readAntenna: 'readAntenna', ChannelEventType.receiveFollowRequest: 'receiveFollowRequest', + ChannelEventType.unknown: 'unknown', }; _$StatsLogChannelEventImpl _$$StatsLogChannelEventImplFromJson( diff --git a/lib/src/enums/broadcast_event_type.dart b/lib/src/enums/broadcast_event_type.dart index 2c9e603..4947546 100644 --- a/lib/src/enums/broadcast_event_type.dart +++ b/lib/src/enums/broadcast_event_type.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; enum BroadcastEventType { @@ -5,6 +6,7 @@ enum BroadcastEventType { emojiUpdated, emojiDeleted, announcementCreated, + unknown, } class BroadcastEventTypeJsonConverter @@ -13,7 +15,8 @@ class BroadcastEventTypeJsonConverter @override BroadcastEventType? fromJson(String json) => - BroadcastEventType.values.firstWhere((e) => e.name == json); + BroadcastEventType.values.firstWhereOrNull((e) => e.name == json) ?? + BroadcastEventType.unknown; @override String toJson(BroadcastEventType? object) => object?.name ?? ""; diff --git a/lib/src/enums/channel_event_type.dart b/lib/src/enums/channel_event_type.dart index f25b00a..701ae62 100644 --- a/lib/src/enums/channel_event_type.dart +++ b/lib/src/enums/channel_event_type.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; enum ChannelEventType { @@ -38,6 +39,8 @@ enum ChannelEventType { driveFileCreated, readAntenna, receiveFollowRequest, + + unknown, } class ChannelEventTypeJsonConverter @@ -46,7 +49,8 @@ class ChannelEventTypeJsonConverter @override ChannelEventType? fromJson(String json) => - ChannelEventType.values.firstWhere((e) => e.name == json); + ChannelEventType.values.firstWhereOrNull((e) => e.name == json) ?? + ChannelEventType.unknown; @override String toJson(ChannelEventType? object) => object?.name ?? ""; diff --git a/lib/src/enums/note_updated_event_type.dart b/lib/src/enums/note_updated_event_type.dart index bf5439f..689ffd8 100644 --- a/lib/src/enums/note_updated_event_type.dart +++ b/lib/src/enums/note_updated_event_type.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; enum NoteUpdatedEventType { @@ -6,6 +7,7 @@ enum NoteUpdatedEventType { deleted, pollVoted, updated, + unknown, } class NoteUpdatedEventTypeJsonConverter @@ -14,7 +16,8 @@ class NoteUpdatedEventTypeJsonConverter @override NoteUpdatedEventType? fromJson(String json) => - NoteUpdatedEventType.values.firstWhere((e) => e.name == json); + NoteUpdatedEventType.values.firstWhereOrNull((e) => e.name == json) ?? + NoteUpdatedEventType.unknown; @override String toJson(NoteUpdatedEventType? object) => object?.name ?? ""; diff --git a/lib/src/enums/notification_type.dart b/lib/src/enums/notification_type.dart index 78eb7db..a61271c 100644 --- a/lib/src/enums/notification_type.dart +++ b/lib/src/enums/notification_type.dart @@ -23,4 +23,5 @@ enum NotificationType { roleAssigned, exportCompleted, login, + unknown, } diff --git a/lib/src/enums/streaming_response_type.dart b/lib/src/enums/streaming_response_type.dart index 8fe9a65..4ab5185 100644 --- a/lib/src/enums/streaming_response_type.dart +++ b/lib/src/enums/streaming_response_type.dart @@ -1,3 +1,4 @@ +import 'package:collection/collection.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; enum StreamingResponseType { @@ -7,6 +8,7 @@ enum StreamingResponseType { emojiUpdated, emojiDeleted, announcementCreated, + unknown, } class StreamingResponseTypeJsonConverter @@ -15,7 +17,8 @@ class StreamingResponseTypeJsonConverter @override StreamingResponseType? fromJson(String json) => - StreamingResponseType.values.firstWhere((e) => e.name == json); + StreamingResponseType.values.firstWhereOrNull((e) => e.name == json) ?? + StreamingResponseType.unknown; @override String toJson(StreamingResponseType? object) => object?.name ?? "";