diff --git a/.fvmrc b/.fvmrc index 0bcd1542..d3aed4c2 100644 --- a/.fvmrc +++ b/.fvmrc @@ -1,4 +1,4 @@ { - "flutter": "3.41.8", + "flutter": "3.41.9", "flavors": {} } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a2998a0..ad8abee3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 3.8.12 + +- Made `position` field nullable (`InboundPositionStructure?`) in `InboundStructure` and `InboundStructureInput` to support services without a position structure. +- Added `DynamicMapConverter` and `DynamicMapConverterNullable` converters to safely deserialize `Map` (e.g. Dart literal `{}`) into `Map`. +- Applied `@DynamicMapConverterNullable()` to `InboundService.credentials` and `@DynamicMapConverter()` to `InboundServiceInput.credentials` to fix deserialization failures when credentials arrive as an empty map literal. + ## 3.8.11 - Adjustments on `Model`, now `widget` is `List` instead of plain `RenderWidget`. diff --git a/devtools_options.yaml b/devtools_options.yaml index fa0b357c..032bdfd5 100644 --- a/devtools_options.yaml +++ b/devtools_options.yaml @@ -1,3 +1,5 @@ description: This file stores settings for Dart & Flutter DevTools. documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states extensions: + - drift: false + - shared_preferences: false \ No newline at end of file diff --git a/lib/src/builder/builder.freezed.dart b/lib/src/builder/builder.freezed.dart index b79318bc..a5cc414c 100644 --- a/lib/src/builder/builder.freezed.dart +++ b/lib/src/builder/builder.freezed.dart @@ -15,7 +15,7 @@ T _$identity(T value) => value; /// @nodoc mixin _$InboundStructure { - bool get hasPosition; InboundPositionStructure get position; bool get hasPayload; List get payload; + bool get hasPosition; InboundPositionStructure? get position; bool get hasPayload; List get payload; /// Create a copy of InboundStructure /// with the given fields replaced by the non-null parameter values. @JsonKey(includeFromJson: false, includeToJson: false) @@ -48,11 +48,11 @@ abstract mixin class $InboundStructureCopyWith<$Res> { factory $InboundStructureCopyWith(InboundStructure value, $Res Function(InboundStructure) _then) = _$InboundStructureCopyWithImpl; @useResult $Res call({ - bool hasPosition, InboundPositionStructure position, bool hasPayload, List payload + bool hasPosition, InboundPositionStructure? position, bool hasPayload, List payload }); -$InboundPositionStructureCopyWith<$Res> get position; +$InboundPositionStructureCopyWith<$Res>? get position; } /// @nodoc @@ -65,11 +65,11 @@ class _$InboundStructureCopyWithImpl<$Res> /// Create a copy of InboundStructure /// with the given fields replaced by the non-null parameter values. -@pragma('vm:prefer-inline') @override $Res call({Object? hasPosition = null,Object? position = null,Object? hasPayload = null,Object? payload = null,}) { +@pragma('vm:prefer-inline') @override $Res call({Object? hasPosition = null,Object? position = freezed,Object? hasPayload = null,Object? payload = null,}) { return _then(_self.copyWith( hasPosition: null == hasPosition ? _self.hasPosition : hasPosition // ignore: cast_nullable_to_non_nullable -as bool,position: null == position ? _self.position : position // ignore: cast_nullable_to_non_nullable -as InboundPositionStructure,hasPayload: null == hasPayload ? _self.hasPayload : hasPayload // ignore: cast_nullable_to_non_nullable +as bool,position: freezed == position ? _self.position : position // ignore: cast_nullable_to_non_nullable +as InboundPositionStructure?,hasPayload: null == hasPayload ? _self.hasPayload : hasPayload // ignore: cast_nullable_to_non_nullable as bool,payload: null == payload ? _self.payload : payload // ignore: cast_nullable_to_non_nullable as List, )); @@ -78,9 +78,12 @@ as List, /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') -$InboundPositionStructureCopyWith<$Res> get position { - - return $InboundPositionStructureCopyWith<$Res>(_self.position, (value) { +$InboundPositionStructureCopyWith<$Res>? get position { + if (_self.position == null) { + return null; + } + + return $InboundPositionStructureCopyWith<$Res>(_self.position!, (value) { return _then(_self.copyWith(position: value)); }); } @@ -165,7 +168,7 @@ return $default(_that);case _: /// } /// ``` -@optionalTypeArgs TResult maybeWhen(TResult Function( bool hasPosition, InboundPositionStructure position, bool hasPayload, List payload)? $default,{required TResult orElse(),}) {final _that = this; +@optionalTypeArgs TResult maybeWhen(TResult Function( bool hasPosition, InboundPositionStructure? position, bool hasPayload, List payload)? $default,{required TResult orElse(),}) {final _that = this; switch (_that) { case _InboundStructure() when $default != null: return $default(_that.hasPosition,_that.position,_that.hasPayload,_that.payload);case _: @@ -186,7 +189,7 @@ return $default(_that.hasPosition,_that.position,_that.hasPayload,_that.payload) /// } /// ``` -@optionalTypeArgs TResult when(TResult Function( bool hasPosition, InboundPositionStructure position, bool hasPayload, List payload) $default,) {final _that = this; +@optionalTypeArgs TResult when(TResult Function( bool hasPosition, InboundPositionStructure? position, bool hasPayload, List payload) $default,) {final _that = this; switch (_that) { case _InboundStructure(): return $default(_that.hasPosition,_that.position,_that.hasPayload,_that.payload);case _: @@ -206,7 +209,7 @@ return $default(_that.hasPosition,_that.position,_that.hasPayload,_that.payload) /// } /// ``` -@optionalTypeArgs TResult? whenOrNull(TResult? Function( bool hasPosition, InboundPositionStructure position, bool hasPayload, List payload)? $default,) {final _that = this; +@optionalTypeArgs TResult? whenOrNull(TResult? Function( bool hasPosition, InboundPositionStructure? position, bool hasPayload, List payload)? $default,) {final _that = this; switch (_that) { case _InboundStructure() when $default != null: return $default(_that.hasPosition,_that.position,_that.hasPayload,_that.payload);case _: @@ -225,7 +228,7 @@ class _InboundStructure implements InboundStructure { factory _InboundStructure.fromJson(Map json) => _$InboundStructureFromJson(json); @override final bool hasPosition; -@override final InboundPositionStructure position; +@override final InboundPositionStructure? position; @override final bool hasPayload; final List _payload; @override List get payload { @@ -268,11 +271,11 @@ abstract mixin class _$InboundStructureCopyWith<$Res> implements $InboundStructu factory _$InboundStructureCopyWith(_InboundStructure value, $Res Function(_InboundStructure) _then) = __$InboundStructureCopyWithImpl; @override @useResult $Res call({ - bool hasPosition, InboundPositionStructure position, bool hasPayload, List payload + bool hasPosition, InboundPositionStructure? position, bool hasPayload, List payload }); -@override $InboundPositionStructureCopyWith<$Res> get position; +@override $InboundPositionStructureCopyWith<$Res>? get position; } /// @nodoc @@ -285,11 +288,11 @@ class __$InboundStructureCopyWithImpl<$Res> /// Create a copy of InboundStructure /// with the given fields replaced by the non-null parameter values. -@override @pragma('vm:prefer-inline') $Res call({Object? hasPosition = null,Object? position = null,Object? hasPayload = null,Object? payload = null,}) { +@override @pragma('vm:prefer-inline') $Res call({Object? hasPosition = null,Object? position = freezed,Object? hasPayload = null,Object? payload = null,}) { return _then(_InboundStructure( hasPosition: null == hasPosition ? _self.hasPosition : hasPosition // ignore: cast_nullable_to_non_nullable -as bool,position: null == position ? _self.position : position // ignore: cast_nullable_to_non_nullable -as InboundPositionStructure,hasPayload: null == hasPayload ? _self.hasPayload : hasPayload // ignore: cast_nullable_to_non_nullable +as bool,position: freezed == position ? _self.position : position // ignore: cast_nullable_to_non_nullable +as InboundPositionStructure?,hasPayload: null == hasPayload ? _self.hasPayload : hasPayload // ignore: cast_nullable_to_non_nullable as bool,payload: null == payload ? _self._payload : payload // ignore: cast_nullable_to_non_nullable as List, )); @@ -299,9 +302,12 @@ as List, /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') -$InboundPositionStructureCopyWith<$Res> get position { - - return $InboundPositionStructureCopyWith<$Res>(_self.position, (value) { +$InboundPositionStructureCopyWith<$Res>? get position { + if (_self.position == null) { + return null; + } + + return $InboundPositionStructureCopyWith<$Res>(_self.position!, (value) { return _then(_self.copyWith(position: value)); }); } @@ -314,8 +320,8 @@ mixin _$InboundStructureInput { /// [hasPosition] defines if the structure has a position. bool get hasPosition;/// [hasPosition] defines if the structure has a position. set hasPosition(bool value);/// [position] defines the structure of the position. - InboundPositionStructureInput get position;/// [position] defines the structure of the position. - set position(InboundPositionStructureInput value);/// [hasPayload] defines if the structure has a payload. + InboundPositionStructureInput? get position;/// [position] defines the structure of the position. + set position(InboundPositionStructureInput? value);/// [hasPayload] defines if the structure has a payload. bool get hasPayload;/// [hasPayload] defines if the structure has a payload. set hasPayload(bool value);/// [payload] defines the structure of the payload. List get payload;/// [payload] defines the structure of the payload. @@ -345,11 +351,11 @@ abstract mixin class $InboundStructureInputCopyWith<$Res> { factory $InboundStructureInputCopyWith(InboundStructureInput value, $Res Function(InboundStructureInput) _then) = _$InboundStructureInputCopyWithImpl; @useResult $Res call({ - bool hasPosition, InboundPositionStructureInput position, bool hasPayload, List payload + bool hasPosition, InboundPositionStructureInput? position, bool hasPayload, List payload }); -$InboundPositionStructureInputCopyWith<$Res> get position; +$InboundPositionStructureInputCopyWith<$Res>? get position; } /// @nodoc @@ -362,11 +368,11 @@ class _$InboundStructureInputCopyWithImpl<$Res> /// Create a copy of InboundStructureInput /// with the given fields replaced by the non-null parameter values. -@pragma('vm:prefer-inline') @override $Res call({Object? hasPosition = null,Object? position = null,Object? hasPayload = null,Object? payload = null,}) { +@pragma('vm:prefer-inline') @override $Res call({Object? hasPosition = null,Object? position = freezed,Object? hasPayload = null,Object? payload = null,}) { return _then(_self.copyWith( hasPosition: null == hasPosition ? _self.hasPosition : hasPosition // ignore: cast_nullable_to_non_nullable -as bool,position: null == position ? _self.position : position // ignore: cast_nullable_to_non_nullable -as InboundPositionStructureInput,hasPayload: null == hasPayload ? _self.hasPayload : hasPayload // ignore: cast_nullable_to_non_nullable +as bool,position: freezed == position ? _self.position : position // ignore: cast_nullable_to_non_nullable +as InboundPositionStructureInput?,hasPayload: null == hasPayload ? _self.hasPayload : hasPayload // ignore: cast_nullable_to_non_nullable as bool,payload: null == payload ? _self.payload : payload // ignore: cast_nullable_to_non_nullable as List, )); @@ -375,9 +381,12 @@ as List, /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') -$InboundPositionStructureInputCopyWith<$Res> get position { - - return $InboundPositionStructureInputCopyWith<$Res>(_self.position, (value) { +$InboundPositionStructureInputCopyWith<$Res>? get position { + if (_self.position == null) { + return null; + } + + return $InboundPositionStructureInputCopyWith<$Res>(_self.position!, (value) { return _then(_self.copyWith(position: value)); }); } @@ -462,7 +471,7 @@ return $default(_that);case _: /// } /// ``` -@optionalTypeArgs TResult maybeWhen(TResult Function( bool hasPosition, InboundPositionStructureInput position, bool hasPayload, List payload)? $default,{required TResult orElse(),}) {final _that = this; +@optionalTypeArgs TResult maybeWhen(TResult Function( bool hasPosition, InboundPositionStructureInput? position, bool hasPayload, List payload)? $default,{required TResult orElse(),}) {final _that = this; switch (_that) { case _InboundStructureInput() when $default != null: return $default(_that.hasPosition,_that.position,_that.hasPayload,_that.payload);case _: @@ -483,7 +492,7 @@ return $default(_that.hasPosition,_that.position,_that.hasPayload,_that.payload) /// } /// ``` -@optionalTypeArgs TResult when(TResult Function( bool hasPosition, InboundPositionStructureInput position, bool hasPayload, List payload) $default,) {final _that = this; +@optionalTypeArgs TResult when(TResult Function( bool hasPosition, InboundPositionStructureInput? position, bool hasPayload, List payload) $default,) {final _that = this; switch (_that) { case _InboundStructureInput(): return $default(_that.hasPosition,_that.position,_that.hasPayload,_that.payload);case _: @@ -503,7 +512,7 @@ return $default(_that.hasPosition,_that.position,_that.hasPayload,_that.payload) /// } /// ``` -@optionalTypeArgs TResult? whenOrNull(TResult? Function( bool hasPosition, InboundPositionStructureInput position, bool hasPayload, List payload)? $default,) {final _that = this; +@optionalTypeArgs TResult? whenOrNull(TResult? Function( bool hasPosition, InboundPositionStructureInput? position, bool hasPayload, List payload)? $default,) {final _that = this; switch (_that) { case _InboundStructureInput() when $default != null: return $default(_that.hasPosition,_that.position,_that.hasPayload,_that.payload);case _: @@ -524,7 +533,7 @@ class _InboundStructureInput implements InboundStructureInput { /// [hasPosition] defines if the structure has a position. @override@JsonKey() bool hasPosition; /// [position] defines the structure of the position. -@override InboundPositionStructureInput position; +@override InboundPositionStructureInput? position; /// [hasPayload] defines if the structure has a payload. @override@JsonKey() bool hasPayload; /// [payload] defines the structure of the payload. @@ -556,11 +565,11 @@ abstract mixin class _$InboundStructureInputCopyWith<$Res> implements $InboundSt factory _$InboundStructureInputCopyWith(_InboundStructureInput value, $Res Function(_InboundStructureInput) _then) = __$InboundStructureInputCopyWithImpl; @override @useResult $Res call({ - bool hasPosition, InboundPositionStructureInput position, bool hasPayload, List payload + bool hasPosition, InboundPositionStructureInput? position, bool hasPayload, List payload }); -@override $InboundPositionStructureInputCopyWith<$Res> get position; +@override $InboundPositionStructureInputCopyWith<$Res>? get position; } /// @nodoc @@ -573,11 +582,11 @@ class __$InboundStructureInputCopyWithImpl<$Res> /// Create a copy of InboundStructureInput /// with the given fields replaced by the non-null parameter values. -@override @pragma('vm:prefer-inline') $Res call({Object? hasPosition = null,Object? position = null,Object? hasPayload = null,Object? payload = null,}) { +@override @pragma('vm:prefer-inline') $Res call({Object? hasPosition = null,Object? position = freezed,Object? hasPayload = null,Object? payload = null,}) { return _then(_InboundStructureInput( hasPosition: null == hasPosition ? _self.hasPosition : hasPosition // ignore: cast_nullable_to_non_nullable -as bool,position: null == position ? _self.position : position // ignore: cast_nullable_to_non_nullable -as InboundPositionStructureInput,hasPayload: null == hasPayload ? _self.hasPayload : hasPayload // ignore: cast_nullable_to_non_nullable +as bool,position: freezed == position ? _self.position : position // ignore: cast_nullable_to_non_nullable +as InboundPositionStructureInput?,hasPayload: null == hasPayload ? _self.hasPayload : hasPayload // ignore: cast_nullable_to_non_nullable as bool,payload: null == payload ? _self.payload : payload // ignore: cast_nullable_to_non_nullable as List, )); @@ -587,9 +596,12 @@ as List, /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') -$InboundPositionStructureInputCopyWith<$Res> get position { - - return $InboundPositionStructureInputCopyWith<$Res>(_self.position, (value) { +$InboundPositionStructureInputCopyWith<$Res>? get position { + if (_self.position == null) { + return null; + } + + return $InboundPositionStructureInputCopyWith<$Res>(_self.position!, (value) { return _then(_self.copyWith(position: value)); }); } diff --git a/lib/src/builder/builder.g.dart b/lib/src/builder/builder.g.dart index 785a9b89..a208a65f 100644 --- a/lib/src/builder/builder.g.dart +++ b/lib/src/builder/builder.g.dart @@ -9,9 +9,11 @@ part of 'builder.dart'; _InboundStructure _$InboundStructureFromJson(Map json) => _InboundStructure( hasPosition: json['hasPosition'] as bool, - position: InboundPositionStructure.fromJson( - json['position'] as Map, - ), + position: json['position'] == null + ? null + : InboundPositionStructure.fromJson( + json['position'] as Map, + ), hasPayload: json['hasPayload'] as bool, payload: (json['payload'] as List) .map( @@ -23,7 +25,7 @@ _InboundStructure _$InboundStructureFromJson(Map json) => Map _$InboundStructureToJson(_InboundStructure instance) => { 'hasPosition': instance.hasPosition, - 'position': instance.position.toJson(), + 'position': instance.position?.toJson(), 'hasPayload': instance.hasPayload, 'payload': instance.payload.map((e) => e.toJson()).toList(), }; @@ -32,9 +34,11 @@ _InboundStructureInput _$InboundStructureInputFromJson( Map json, ) => _InboundStructureInput( hasPosition: json['hasPosition'] as bool? ?? true, - position: InboundPositionStructureInput.fromJson( - json['position'] as Map, - ), + position: json['position'] == null + ? null + : InboundPositionStructureInput.fromJson( + json['position'] as Map, + ), hasPayload: json['hasPayload'] as bool? ?? false, payload: (json['payload'] as List?) @@ -51,7 +55,7 @@ Map _$InboundStructureInputToJson( _InboundStructureInput instance, ) => { 'hasPosition': instance.hasPosition, - 'position': instance.position.toJson(), + 'position': instance.position?.toJson(), 'hasPayload': instance.hasPayload, 'payload': instance.payload.map((e) => e.toJson()).toList(), }; diff --git a/lib/src/builder/src/inbound.dart b/lib/src/builder/src/inbound.dart index c8d611ab..c1aa1957 100644 --- a/lib/src/builder/src/inbound.dart +++ b/lib/src/builder/src/inbound.dart @@ -4,7 +4,7 @@ part of '../builder.dart'; abstract class InboundStructure with _$InboundStructure { const factory InboundStructure({ required bool hasPosition, - required InboundPositionStructure position, + required InboundPositionStructure? position, required bool hasPayload, required List payload, }) = _InboundStructure; @@ -19,7 +19,7 @@ abstract class InboundStructureInput with _$InboundStructureInput { @Default(true) bool hasPosition, /// [position] defines the structure of the position. - required InboundPositionStructureInput position, + required InboundPositionStructureInput? position, /// [hasPayload] defines if the structure has a payload. @Default(false) bool hasPayload, @@ -90,7 +90,8 @@ enum InboundPayloadStructureType { string, integer, boolean, - float; + float + ; @override String toString() => toJson(); diff --git a/lib/src/converters/converters.dart b/lib/src/converters/converters.dart index 3dc45d6d..4b5025ff 100644 --- a/lib/src/converters/converters.dart +++ b/lib/src/converters/converters.dart @@ -15,3 +15,4 @@ part 'src/time_of_day.dart'; part 'src/regex.dart'; part 'src/byte_list.dart'; part 'src/param_converter.dart'; +part 'src/dynamic_map.dart'; diff --git a/lib/src/converters/src/dynamic_map.dart b/lib/src/converters/src/dynamic_map.dart new file mode 100644 index 00000000..f4c37b91 --- /dev/null +++ b/lib/src/converters/src/dynamic_map.dart @@ -0,0 +1,35 @@ +part of '../converters.dart'; + +/// Safely converts any [Map] into [Map?]. +/// +/// A Dart literal `{}` inside a `Map` value slot is +/// `Map`, which fails the direct `as Map?` +/// cast that json_serializable emits. This converter handles both variants. +class DynamicMapConverterNullable implements JsonConverter?, Object?> { + const DynamicMapConverterNullable(); + + @override + Map? fromJson(Object? json) { + if (json == null) return null; + if (json is Map) return json; + if (json is Map) return json.map((key, value) => MapEntry(key.toString(), value)); + return null; + } + + @override + Object? toJson(Map? value) => value; +} + +class DynamicMapConverter implements JsonConverter, Object?> { + const DynamicMapConverter(); + + @override + Map fromJson(Object? json) { + if (json is Map) return json; + if (json is Map) return json.map((key, value) => MapEntry(key.toString(), value)); + return {}; + } + + @override + Object? toJson(Map value) => value; +} diff --git a/lib/src/inbound/inbound.freezed.dart b/lib/src/inbound/inbound.freezed.dart index 3cd6c816..a4b34435 100644 --- a/lib/src/inbound/inbound.freezed.dart +++ b/lib/src/inbound/inbound.freezed.dart @@ -1124,7 +1124,7 @@ mixin _$InboundService { /// IS the ID of the entity. This ID is unique. String get id;/// Is the Assigned service name, cannot be translated for other languages. String get name;/// Is the Credential object, check the documentation for more information. - Map? get credentials;/// Is the ID of the External Account. +@DynamicMapConverterNullable() Map? get credentials;/// Is the ID of the External Account. String? get externalAccountId;/// Is the update time of the service. @DurationOrNullConverter() Duration? get updateTime;/// Is the Protocol entity. InboundProtocol? get protocol;/// Is the Protocol ID. @@ -1166,7 +1166,7 @@ abstract mixin class $InboundServiceCopyWith<$Res> { factory $InboundServiceCopyWith(InboundService value, $Res Function(InboundService) _then) = _$InboundServiceCopyWithImpl; @useResult $Res call({ - String id, String name, Map? credentials, String? externalAccountId,@DurationOrNullConverter() Duration? updateTime, InboundProtocol? protocol, String? protocolId, bool? isEnabled, String? token, InboundStructure? structure, List? access, WebhookStructure? webhookStructure + String id, String name,@DynamicMapConverterNullable() Map? credentials, String? externalAccountId,@DurationOrNullConverter() Duration? updateTime, InboundProtocol? protocol, String? protocolId, bool? isEnabled, String? token, InboundStructure? structure, List? access, WebhookStructure? webhookStructure }); @@ -1318,7 +1318,7 @@ return $default(_that);case _: /// } /// ``` -@optionalTypeArgs TResult maybeWhen(TResult Function( String id, String name, Map? credentials, String? externalAccountId, @DurationOrNullConverter() Duration? updateTime, InboundProtocol? protocol, String? protocolId, bool? isEnabled, String? token, InboundStructure? structure, List? access, WebhookStructure? webhookStructure)? $default,{required TResult orElse(),}) {final _that = this; +@optionalTypeArgs TResult maybeWhen(TResult Function( String id, String name, @DynamicMapConverterNullable() Map? credentials, String? externalAccountId, @DurationOrNullConverter() Duration? updateTime, InboundProtocol? protocol, String? protocolId, bool? isEnabled, String? token, InboundStructure? structure, List? access, WebhookStructure? webhookStructure)? $default,{required TResult orElse(),}) {final _that = this; switch (_that) { case _InboundService() when $default != null: return $default(_that.id,_that.name,_that.credentials,_that.externalAccountId,_that.updateTime,_that.protocol,_that.protocolId,_that.isEnabled,_that.token,_that.structure,_that.access,_that.webhookStructure);case _: @@ -1339,7 +1339,7 @@ return $default(_that.id,_that.name,_that.credentials,_that.externalAccountId,_t /// } /// ``` -@optionalTypeArgs TResult when(TResult Function( String id, String name, Map? credentials, String? externalAccountId, @DurationOrNullConverter() Duration? updateTime, InboundProtocol? protocol, String? protocolId, bool? isEnabled, String? token, InboundStructure? structure, List? access, WebhookStructure? webhookStructure) $default,) {final _that = this; +@optionalTypeArgs TResult when(TResult Function( String id, String name, @DynamicMapConverterNullable() Map? credentials, String? externalAccountId, @DurationOrNullConverter() Duration? updateTime, InboundProtocol? protocol, String? protocolId, bool? isEnabled, String? token, InboundStructure? structure, List? access, WebhookStructure? webhookStructure) $default,) {final _that = this; switch (_that) { case _InboundService(): return $default(_that.id,_that.name,_that.credentials,_that.externalAccountId,_that.updateTime,_that.protocol,_that.protocolId,_that.isEnabled,_that.token,_that.structure,_that.access,_that.webhookStructure);case _: @@ -1359,7 +1359,7 @@ return $default(_that.id,_that.name,_that.credentials,_that.externalAccountId,_t /// } /// ``` -@optionalTypeArgs TResult? whenOrNull(TResult? Function( String id, String name, Map? credentials, String? externalAccountId, @DurationOrNullConverter() Duration? updateTime, InboundProtocol? protocol, String? protocolId, bool? isEnabled, String? token, InboundStructure? structure, List? access, WebhookStructure? webhookStructure)? $default,) {final _that = this; +@optionalTypeArgs TResult? whenOrNull(TResult? Function( String id, String name, @DynamicMapConverterNullable() Map? credentials, String? externalAccountId, @DurationOrNullConverter() Duration? updateTime, InboundProtocol? protocol, String? protocolId, bool? isEnabled, String? token, InboundStructure? structure, List? access, WebhookStructure? webhookStructure)? $default,) {final _that = this; switch (_that) { case _InboundService() when $default != null: return $default(_that.id,_that.name,_that.credentials,_that.externalAccountId,_that.updateTime,_that.protocol,_that.protocolId,_that.isEnabled,_that.token,_that.structure,_that.access,_that.webhookStructure);case _: @@ -1374,7 +1374,7 @@ return $default(_that.id,_that.name,_that.credentials,_that.externalAccountId,_t @JsonSerializable() class _InboundService implements InboundService { - const _InboundService({required this.id, required this.name, final Map? credentials, this.externalAccountId, @DurationOrNullConverter() this.updateTime, this.protocol, this.protocolId, this.isEnabled, this.token, this.structure, final List? access, this.webhookStructure}): _credentials = credentials,_access = access; + const _InboundService({required this.id, required this.name, @DynamicMapConverterNullable() final Map? credentials, this.externalAccountId, @DurationOrNullConverter() this.updateTime, this.protocol, this.protocolId, this.isEnabled, this.token, this.structure, final List? access, this.webhookStructure}): _credentials = credentials,_access = access; factory _InboundService.fromJson(Map json) => _$InboundServiceFromJson(json); /// IS the ID of the entity. This ID is unique. @@ -1384,7 +1384,7 @@ class _InboundService implements InboundService { /// Is the Credential object, check the documentation for more information. final Map? _credentials; /// Is the Credential object, check the documentation for more information. -@override Map? get credentials { +@override@DynamicMapConverterNullable() Map? get credentials { final value = _credentials; if (value == null) return null; if (_credentials is EqualUnmodifiableMapView) return _credentials; @@ -1453,7 +1453,7 @@ abstract mixin class _$InboundServiceCopyWith<$Res> implements $InboundServiceCo factory _$InboundServiceCopyWith(_InboundService value, $Res Function(_InboundService) _then) = __$InboundServiceCopyWithImpl; @override @useResult $Res call({ - String id, String name, Map? credentials, String? externalAccountId,@DurationOrNullConverter() Duration? updateTime, InboundProtocol? protocol, String? protocolId, bool? isEnabled, String? token, InboundStructure? structure, List? access, WebhookStructure? webhookStructure + String id, String name,@DynamicMapConverterNullable() Map? credentials, String? externalAccountId,@DurationOrNullConverter() Duration? updateTime, InboundProtocol? protocol, String? protocolId, bool? isEnabled, String? token, InboundStructure? structure, List? access, WebhookStructure? webhookStructure }); @@ -1536,8 +1536,8 @@ mixin _$InboundServiceInput { set id(String? value);/// [name] is the Assigned service name, cannot be translated for other languages. String get name;/// [name] is the Assigned service name, cannot be translated for other languages. set name(String value);/// [credentials] is the Credential object, check the documentation for more information. - Map get credentials;/// [credentials] is the Credential object, check the documentation for more information. - set credentials(Map value);/// [externalAccountId] is the ID of the External Account. +@DynamicMapConverter() Map get credentials;/// [credentials] is the Credential object, check the documentation for more information. +@DynamicMapConverter() set credentials(Map value);/// [externalAccountId] is the ID of the External Account. String? get externalAccountId;/// [externalAccountId] is the ID of the External Account. set externalAccountId(String? value);/// [protocolId] is the ID of the Protocol. String? get protocolId;/// [protocolId] is the ID of the Protocol. @@ -1569,7 +1569,7 @@ abstract mixin class $InboundServiceInputCopyWith<$Res> { factory $InboundServiceInputCopyWith(InboundServiceInput value, $Res Function(InboundServiceInput) _then) = _$InboundServiceInputCopyWithImpl; @useResult $Res call({ - String? id, String name, Map credentials, String? externalAccountId, String? protocolId, InboundStructureInput structure + String? id, String name,@DynamicMapConverter() Map credentials, String? externalAccountId, String? protocolId, InboundStructureInput structure }); @@ -1688,7 +1688,7 @@ return $default(_that);case _: /// } /// ``` -@optionalTypeArgs TResult maybeWhen(TResult Function( String? id, String name, Map credentials, String? externalAccountId, String? protocolId, InboundStructureInput structure)? $default,{required TResult orElse(),}) {final _that = this; +@optionalTypeArgs TResult maybeWhen(TResult Function( String? id, String name, @DynamicMapConverter() Map credentials, String? externalAccountId, String? protocolId, InboundStructureInput structure)? $default,{required TResult orElse(),}) {final _that = this; switch (_that) { case _InboundServiceInput() when $default != null: return $default(_that.id,_that.name,_that.credentials,_that.externalAccountId,_that.protocolId,_that.structure);case _: @@ -1709,7 +1709,7 @@ return $default(_that.id,_that.name,_that.credentials,_that.externalAccountId,_t /// } /// ``` -@optionalTypeArgs TResult when(TResult Function( String? id, String name, Map credentials, String? externalAccountId, String? protocolId, InboundStructureInput structure) $default,) {final _that = this; +@optionalTypeArgs TResult when(TResult Function( String? id, String name, @DynamicMapConverter() Map credentials, String? externalAccountId, String? protocolId, InboundStructureInput structure) $default,) {final _that = this; switch (_that) { case _InboundServiceInput(): return $default(_that.id,_that.name,_that.credentials,_that.externalAccountId,_that.protocolId,_that.structure);case _: @@ -1729,7 +1729,7 @@ return $default(_that.id,_that.name,_that.credentials,_that.externalAccountId,_t /// } /// ``` -@optionalTypeArgs TResult? whenOrNull(TResult? Function( String? id, String name, Map credentials, String? externalAccountId, String? protocolId, InboundStructureInput structure)? $default,) {final _that = this; +@optionalTypeArgs TResult? whenOrNull(TResult? Function( String? id, String name, @DynamicMapConverter() Map credentials, String? externalAccountId, String? protocolId, InboundStructureInput structure)? $default,) {final _that = this; switch (_that) { case _InboundServiceInput() when $default != null: return $default(_that.id,_that.name,_that.credentials,_that.externalAccountId,_that.protocolId,_that.structure);case _: @@ -1744,7 +1744,7 @@ return $default(_that.id,_that.name,_that.credentials,_that.externalAccountId,_t @JsonSerializable() class _InboundServiceInput implements InboundServiceInput { - _InboundServiceInput({this.id, this.name = '', this.credentials = const {}, this.externalAccountId, this.protocolId, required this.structure}); + _InboundServiceInput({this.id, this.name = '', @DynamicMapConverter() this.credentials = const {}, this.externalAccountId, this.protocolId, required this.structure}); factory _InboundServiceInput.fromJson(Map json) => _$InboundServiceInputFromJson(json); /// [id] is the ID of the entity. This ID is unique. Should be null when creating a new entity. @@ -1752,7 +1752,7 @@ class _InboundServiceInput implements InboundServiceInput { /// [name] is the Assigned service name, cannot be translated for other languages. @override@JsonKey() String name; /// [credentials] is the Credential object, check the documentation for more information. -@override@JsonKey() Map credentials; +@override@JsonKey()@DynamicMapConverter() Map credentials; /// [externalAccountId] is the ID of the External Account. @override String? externalAccountId; /// [protocolId] is the ID of the Protocol. @@ -1786,7 +1786,7 @@ abstract mixin class _$InboundServiceInputCopyWith<$Res> implements $InboundServ factory _$InboundServiceInputCopyWith(_InboundServiceInput value, $Res Function(_InboundServiceInput) _then) = __$InboundServiceInputCopyWithImpl; @override @useResult $Res call({ - String? id, String name, Map credentials, String? externalAccountId, String? protocolId, InboundStructureInput structure + String? id, String name,@DynamicMapConverter() Map credentials, String? externalAccountId, String? protocolId, InboundStructureInput structure }); diff --git a/lib/src/inbound/inbound.g.dart b/lib/src/inbound/inbound.g.dart index 42b35cef..975d8d10 100644 --- a/lib/src/inbound/inbound.g.dart +++ b/lib/src/inbound/inbound.g.dart @@ -260,7 +260,9 @@ _InboundService _$InboundServiceFromJson(Map json) => _InboundService( id: json['id'] as String, name: json['name'] as String, - credentials: json['credentials'] as Map?, + credentials: const DynamicMapConverterNullable().fromJson( + json['credentials'], + ), externalAccountId: json['externalAccountId'] as String?, updateTime: const DurationOrNullConverter().fromJson( json['updateTime'] as num?, @@ -290,7 +292,9 @@ Map _$InboundServiceToJson(_InboundService instance) => { 'id': instance.id, 'name': instance.name, - 'credentials': instance.credentials, + 'credentials': const DynamicMapConverterNullable().toJson( + instance.credentials, + ), 'externalAccountId': instance.externalAccountId, 'updateTime': const DurationOrNullConverter().toJson(instance.updateTime), 'protocol': instance.protocol?.toJson(), @@ -306,7 +310,9 @@ _InboundServiceInput _$InboundServiceInputFromJson(Map json) => _InboundServiceInput( id: json['id'] as String?, name: json['name'] as String? ?? '', - credentials: json['credentials'] as Map? ?? const {}, + credentials: json['credentials'] == null + ? const {} + : const DynamicMapConverter().fromJson(json['credentials']), externalAccountId: json['externalAccountId'] as String?, protocolId: json['protocolId'] as String?, structure: InboundStructureInput.fromJson( @@ -319,7 +325,7 @@ Map _$InboundServiceInputToJson( ) => { 'id': instance.id, 'name': instance.name, - 'credentials': instance.credentials, + 'credentials': const DynamicMapConverter().toJson(instance.credentials), 'externalAccountId': instance.externalAccountId, 'protocolId': instance.protocolId, 'structure': instance.structure.toJson(), diff --git a/lib/src/inbound/src/service.dart b/lib/src/inbound/src/service.dart index 69c9e1d5..279951fc 100644 --- a/lib/src/inbound/src/service.dart +++ b/lib/src/inbound/src/service.dart @@ -10,7 +10,7 @@ abstract class InboundService with _$InboundService { required String name, /// Is the Credential object, check the documentation for more information. - Map? credentials, + @DynamicMapConverterNullable() Map? credentials, /// Is the ID of the External Account. String? externalAccountId, @@ -54,7 +54,7 @@ abstract class InboundServiceInput with _$InboundServiceInput { @Default('') String name, /// [credentials] is the Credential object, check the documentation for more information. - @Default({}) Map credentials, + @Default({}) @DynamicMapConverter() Map credentials, /// [externalAccountId] is the ID of the External Account. String? externalAccountId, diff --git a/pubspec.yaml b/pubspec.yaml index 983d6a74..ad17b4db 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ description: Layrz API models for Dart/Flutter. This package contains the models used by the Layrz API. name: layrz_models -version: "3.8.11" +version: "3.8.12" repository: https://github.com/goldenm-software/layrz_models environment: @@ -28,7 +28,7 @@ dev_dependencies: sdk: flutter flutter_lints: ^6.0.0 build_runner: ^2.10.4 - freezed: ^3.2.3 + freezed: ^3.2.5 json_serializable: ^6.11.0 test: ^1.26.2 diff --git a/test/inbound_service_test.dart b/test/inbound_service_test.dart new file mode 100644 index 00000000..df182dd9 --- /dev/null +++ b/test/inbound_service_test.dart @@ -0,0 +1,52 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:layrz_models/layrz_models.dart'; + +void main() { + test('inbound service test', () { + final Map data = { + "id": "318", + "name": "testcrear2222233", + "credentials": {}, + "protocolId": "18", + "externalAccountId": null, + "structure": {"hasPosition": false, "position": null, "hasPayload": false, "payload": []}, + "isEnabled": true, + "token": null, + "access": [], + "webhookStructure": null, + }; + + final inboundService = InboundService.fromJson(data); + expect(inboundService.id, "318"); + expect(inboundService.name, "testcrear2222233"); + }); + + test('inbound service input test', () { + final inboundServiceInput = { + "id": "315", + "name": "TESTOMNI", + "credentials": {}, + "protocolId": "18", + "externalAccountId": null, + "structure": {"hasPosition": false, "position": null, "hasPayload": false, "payload": []}, + "isEnabled": true, + "token": null, + "access": [], + "webhookStructure": null, + "protocol": { + "id": "18", + "name": "omnilink", + "color": "blue darken-2", + "isEnabled": true, + "operationMode": "ASYNC", + "isImported": true, + "webhookStructure": null, + }, + }; + final result = InboundService.fromJson(inboundServiceInput); + + expect(result.name, "TESTOMNI"); + final resultInput = InboundServiceInput.fromJson(inboundServiceInput); + expect(resultInput.name, "TESTOMNI"); + }); +}