diff --git a/build.yaml b/build.yaml index fe1f152b..110a39f2 100644 --- a/build.yaml +++ b/build.yaml @@ -5,15 +5,18 @@ targets: options: # Options configure how source code is generated for every # `@JsonSerializable`-annotated class in the package. + any_map: false checked: false create_factory: true create_to_json: true disallow_unrecognized_keys: false - # If true, generated toJson methods will explicitly call toJson on nested objects. - explicit_to_json: true - field_rename: none - generic_argument_factories: false ignore_unannotated: false include_if_null: true nullable: true + field_rename: none + generic_argument_factories: false + + # If true, generated toJson methods will explicitly call toJson on nested objects. + explicit_to_json: true + diff --git a/lib/src/response/response.dart b/lib/src/response/response.dart new file mode 100644 index 00000000..f0ab1514 --- /dev/null +++ b/lib/src/response/response.dart @@ -0,0 +1,28 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:tdproto_dart/tdproto_dart.dart'; + +part 'response.freezed.dart'; +part 'response.g.dart'; + +/// Response +@freezed +abstract class Response with _$Response { + const factory Response({ + /// Debug time + @JsonKey(name: '_time') String time, + + /// Whether http status code is 200 or not + @JsonKey(name: 'ok') @required bool ok, + + /// Requested data + @JsonKey(name: 'result') dynamic result, + + /// Error code + @JsonKey(name: 'error') String error, + + /// Details about the error + @JsonKey(name: 'details') Map details, + }) = _Response; + + factory Response.fromJson(Map json) => _$ResponseFromJson(json); +} diff --git a/lib/src/response/response.freezed.dart b/lib/src/response/response.freezed.dart new file mode 100644 index 00000000..815d034e --- /dev/null +++ b/lib/src/response/response.freezed.dart @@ -0,0 +1,257 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies + +part of 'response.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; +Response _$ResponseFromJson(Map json) { + return _Response.fromJson(json); +} + +/// @nodoc +class _$ResponseTearOff { + const _$ResponseTearOff(); + +// ignore: unused_element + _Response call( + {@JsonKey(name: '_time') String time, + @required @JsonKey(name: 'ok') bool ok, + @JsonKey(name: 'result') dynamic result, + @JsonKey(name: 'error') String error, + @JsonKey(name: 'details') Map details}) { + return _Response( + time: time, + ok: ok, + result: result, + error: error, + details: details, + ); + } + +// ignore: unused_element + Response fromJson(Map json) { + return Response.fromJson(json); + } +} + +/// @nodoc +// ignore: unused_element +const $Response = _$ResponseTearOff(); + +/// @nodoc +mixin _$Response { + /// Debug time + @JsonKey(name: '_time') + String get time; + + /// Whether http status code is 200 or not + @JsonKey(name: 'ok') + bool get ok; + + /// Requested data + @JsonKey(name: 'result') + dynamic get result; + + /// Error code + @JsonKey(name: 'error') + String get error; + + /// Details about the error + @JsonKey(name: 'details') + Map get details; + + Map toJson(); + $ResponseCopyWith get copyWith; +} + +/// @nodoc +abstract class $ResponseCopyWith<$Res> { + factory $ResponseCopyWith(Response value, $Res Function(Response) then) = _$ResponseCopyWithImpl<$Res>; + $Res call( + {@JsonKey(name: '_time') String time, + @JsonKey(name: 'ok') bool ok, + @JsonKey(name: 'result') dynamic result, + @JsonKey(name: 'error') String error, + @JsonKey(name: 'details') Map details}); +} + +/// @nodoc +class _$ResponseCopyWithImpl<$Res> implements $ResponseCopyWith<$Res> { + _$ResponseCopyWithImpl(this._value, this._then); + + final Response _value; + // ignore: unused_field + final $Res Function(Response) _then; + + @override + $Res call({ + Object time = freezed, + Object ok = freezed, + Object result = freezed, + Object error = freezed, + Object details = freezed, + }) { + return _then(_value.copyWith( + time: time == freezed ? _value.time : time as String, + ok: ok == freezed ? _value.ok : ok as bool, + result: result == freezed ? _value.result : result as dynamic, + error: error == freezed ? _value.error : error as String, + details: details == freezed ? _value.details : details as Map, + )); + } +} + +/// @nodoc +abstract class _$ResponseCopyWith<$Res> implements $ResponseCopyWith<$Res> { + factory _$ResponseCopyWith(_Response value, $Res Function(_Response) then) = __$ResponseCopyWithImpl<$Res>; + @override + $Res call( + {@JsonKey(name: '_time') String time, + @JsonKey(name: 'ok') bool ok, + @JsonKey(name: 'result') dynamic result, + @JsonKey(name: 'error') String error, + @JsonKey(name: 'details') Map details}); +} + +/// @nodoc +class __$ResponseCopyWithImpl<$Res> extends _$ResponseCopyWithImpl<$Res> implements _$ResponseCopyWith<$Res> { + __$ResponseCopyWithImpl(_Response _value, $Res Function(_Response) _then) + : super(_value, (v) => _then(v as _Response)); + + @override + _Response get _value => super._value as _Response; + + @override + $Res call({ + Object time = freezed, + Object ok = freezed, + Object result = freezed, + Object error = freezed, + Object details = freezed, + }) { + return _then(_Response( + time: time == freezed ? _value.time : time as String, + ok: ok == freezed ? _value.ok : ok as bool, + result: result == freezed ? _value.result : result as dynamic, + error: error == freezed ? _value.error : error as String, + details: details == freezed ? _value.details : details as Map, + )); + } +} + +@JsonSerializable() + +/// @nodoc +class _$_Response implements _Response { + const _$_Response( + {@JsonKey(name: '_time') this.time, + @required @JsonKey(name: 'ok') this.ok, + @JsonKey(name: 'result') this.result, + @JsonKey(name: 'error') this.error, + @JsonKey(name: 'details') this.details}) + : assert(ok != null); + + factory _$_Response.fromJson(Map json) => _$_$_ResponseFromJson(json); + + @override + + /// Debug time + @JsonKey(name: '_time') + final String time; + @override + + /// Whether http status code is 200 or not + @JsonKey(name: 'ok') + final bool ok; + @override + + /// Requested data + @JsonKey(name: 'result') + final dynamic result; + @override + + /// Error code + @JsonKey(name: 'error') + final String error; + @override + + /// Details about the error + @JsonKey(name: 'details') + final Map details; + + @override + String toString() { + return 'Response(time: $time, ok: $ok, result: $result, error: $error, details: $details)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _Response && + (identical(other.time, time) || const DeepCollectionEquality().equals(other.time, time)) && + (identical(other.ok, ok) || const DeepCollectionEquality().equals(other.ok, ok)) && + (identical(other.result, result) || const DeepCollectionEquality().equals(other.result, result)) && + (identical(other.error, error) || const DeepCollectionEquality().equals(other.error, error)) && + (identical(other.details, details) || const DeepCollectionEquality().equals(other.details, details))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(time) ^ + const DeepCollectionEquality().hash(ok) ^ + const DeepCollectionEquality().hash(result) ^ + const DeepCollectionEquality().hash(error) ^ + const DeepCollectionEquality().hash(details); + + @override + _$ResponseCopyWith<_Response> get copyWith => __$ResponseCopyWithImpl<_Response>(this, _$identity); + + @override + Map toJson() { + return _$_$_ResponseToJson(this); + } +} + +abstract class _Response implements Response { + const factory _Response( + {@JsonKey(name: '_time') String time, + @required @JsonKey(name: 'ok') bool ok, + @JsonKey(name: 'result') dynamic result, + @JsonKey(name: 'error') String error, + @JsonKey(name: 'details') Map details}) = _$_Response; + + factory _Response.fromJson(Map json) = _$_Response.fromJson; + + @override + + /// Debug time + @JsonKey(name: '_time') + String get time; + @override + + /// Whether http status code is 200 or not + @JsonKey(name: 'ok') + bool get ok; + @override + + /// Requested data + @JsonKey(name: 'result') + dynamic get result; + @override + + /// Error code + @JsonKey(name: 'error') + String get error; + @override + + /// Details about the error + @JsonKey(name: 'details') + Map get details; + @override + _$ResponseCopyWith<_Response> get copyWith; +} diff --git a/lib/src/response/response.g.dart b/lib/src/response/response.g.dart new file mode 100644 index 00000000..92f86615 --- /dev/null +++ b/lib/src/response/response.g.dart @@ -0,0 +1,25 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'response.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_Response _$_$_ResponseFromJson(Map json) { + return _$_Response( + time: json['_time'] as String, + ok: json['ok'] as bool, + result: json['result'], + error: json['error'] as String, + details: json['details'] as Map, + ); +} + +Map _$_$_ResponseToJson(_$_Response instance) => { + '_time': instance.time, + 'ok': instance.ok, + 'result': instance.result, + 'error': instance.error, + 'details': instance.details, + }; diff --git a/test/test_utils/mocks/mock_message.freezed.dart b/test/test_utils/mocks/mock_message.freezed.dart index 3f155d6c..ed17776b 100644 --- a/test/test_utils/mocks/mock_message.freezed.dart +++ b/test/test_utils/mocks/mock_message.freezed.dart @@ -18,8 +18,7 @@ class _$MockMessageTearOff { // ignore: unused_element _MockMessage call( - {@JsonKey(name: 'text') String text, - @required @JsonKey(name: 'markup') List markup}) { + {@JsonKey(name: 'text') String text, @required @JsonKey(name: 'markup') List markup}) { return _MockMessage( text: text, markup: markup, @@ -49,12 +48,8 @@ mixin _$MockMessage { /// @nodoc abstract class $MockMessageCopyWith<$Res> { - factory $MockMessageCopyWith( - MockMessage value, $Res Function(MockMessage) then) = - _$MockMessageCopyWithImpl<$Res>; - $Res call( - {@JsonKey(name: 'text') String text, - @JsonKey(name: 'markup') List markup}); + factory $MockMessageCopyWith(MockMessage value, $Res Function(MockMessage) then) = _$MockMessageCopyWithImpl<$Res>; + $Res call({@JsonKey(name: 'text') String text, @JsonKey(name: 'markup') List markup}); } /// @nodoc @@ -78,22 +73,16 @@ class _$MockMessageCopyWithImpl<$Res> implements $MockMessageCopyWith<$Res> { } /// @nodoc -abstract class _$MockMessageCopyWith<$Res> - implements $MockMessageCopyWith<$Res> { - factory _$MockMessageCopyWith( - _MockMessage value, $Res Function(_MockMessage) then) = +abstract class _$MockMessageCopyWith<$Res> implements $MockMessageCopyWith<$Res> { + factory _$MockMessageCopyWith(_MockMessage value, $Res Function(_MockMessage) then) = __$MockMessageCopyWithImpl<$Res>; @override - $Res call( - {@JsonKey(name: 'text') String text, - @JsonKey(name: 'markup') List markup}); + $Res call({@JsonKey(name: 'text') String text, @JsonKey(name: 'markup') List markup}); } /// @nodoc -class __$MockMessageCopyWithImpl<$Res> extends _$MockMessageCopyWithImpl<$Res> - implements _$MockMessageCopyWith<$Res> { - __$MockMessageCopyWithImpl( - _MockMessage _value, $Res Function(_MockMessage) _then) +class __$MockMessageCopyWithImpl<$Res> extends _$MockMessageCopyWithImpl<$Res> implements _$MockMessageCopyWith<$Res> { + __$MockMessageCopyWithImpl(_MockMessage _value, $Res Function(_MockMessage) _then) : super(_value, (v) => _then(v as _MockMessage)); @override @@ -115,13 +104,10 @@ class __$MockMessageCopyWithImpl<$Res> extends _$MockMessageCopyWithImpl<$Res> /// @nodoc class _$_MockMessage implements _MockMessage { - const _$_MockMessage( - {@JsonKey(name: 'text') this.text, - @required @JsonKey(name: 'markup') this.markup}) + const _$_MockMessage({@JsonKey(name: 'text') this.text, @required @JsonKey(name: 'markup') this.markup}) : assert(markup != null); - factory _$_MockMessage.fromJson(Map json) => - _$_$_MockMessageFromJson(json); + factory _$_MockMessage.fromJson(Map json) => _$_$_MockMessageFromJson(json); @override @JsonKey(name: 'text') @@ -139,21 +125,16 @@ class _$_MockMessage implements _MockMessage { bool operator ==(dynamic other) { return identical(this, other) || (other is _MockMessage && - (identical(other.text, text) || - const DeepCollectionEquality().equals(other.text, text)) && - (identical(other.markup, markup) || - const DeepCollectionEquality().equals(other.markup, markup))); + (identical(other.text, text) || const DeepCollectionEquality().equals(other.text, text)) && + (identical(other.markup, markup) || const DeepCollectionEquality().equals(other.markup, markup))); } @override int get hashCode => - runtimeType.hashCode ^ - const DeepCollectionEquality().hash(text) ^ - const DeepCollectionEquality().hash(markup); + runtimeType.hashCode ^ const DeepCollectionEquality().hash(text) ^ const DeepCollectionEquality().hash(markup); @override - _$MockMessageCopyWith<_MockMessage> get copyWith => - __$MockMessageCopyWithImpl<_MockMessage>(this, _$identity); + _$MockMessageCopyWith<_MockMessage> get copyWith => __$MockMessageCopyWithImpl<_MockMessage>(this, _$identity); @override Map toJson() { @@ -163,12 +144,10 @@ class _$_MockMessage implements _MockMessage { abstract class _MockMessage implements MockMessage { const factory _MockMessage( - {@JsonKey(name: 'text') String text, - @required @JsonKey(name: 'markup') List markup}) = - _$_MockMessage; + {@JsonKey(name: 'text') String text, + @required @JsonKey(name: 'markup') List markup}) = _$_MockMessage; - factory _MockMessage.fromJson(Map json) = - _$_MockMessage.fromJson; + factory _MockMessage.fromJson(Map json) = _$_MockMessage.fromJson; @override @JsonKey(name: 'text') diff --git a/test/test_utils/mocks/mock_message.g.dart b/test/test_utils/mocks/mock_message.g.dart index 1d3031f6..7590454f 100644 --- a/test/test_utils/mocks/mock_message.g.dart +++ b/test/test_utils/mocks/mock_message.g.dart @@ -10,14 +10,12 @@ _$_MockMessage _$_$_MockMessageFromJson(Map json) { return _$_MockMessage( text: json['text'] as String, markup: (json['markup'] as List) - ?.map((e) => - e == null ? null : MarkupEntity.fromJson(e as Map)) + ?.map((e) => e == null ? null : MarkupEntity.fromJson(e as Map)) ?.toList(), ); } -Map _$_$_MockMessageToJson(_$_MockMessage instance) => - { +Map _$_$_MockMessageToJson(_$_MockMessage instance) => { 'text': instance.text, 'markup': instance.markup?.map((e) => e?.toJson())?.toList(), };