From 4461b0ceb4f2a84ef2a76235ee8d6f5119162ec7 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Fri, 14 Oct 2022 00:26:51 +0200 Subject: [PATCH] specs,nextcloud: Fix empty objects --- .../nextcloud/lib/src/nextcloud.openapi.dart | 76 +++++++++++++------ .../lib/src/nextcloud.openapi.g.dart | 12 ++- .../nextcloud/lib/src/nextcloud.openapi.json | 34 ++++----- .../nextcloud/test/notifications_test.dart | 8 +- specs/notifications.json | 22 +++--- specs/user_status.json | 12 +-- 6 files changed, 94 insertions(+), 70 deletions(-) diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.dart b/packages/nextcloud/lib/src/nextcloud.openapi.dart index c1830c0b..39b20a09 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.dart +++ b/packages/nextcloud/lib/src/nextcloud.openapi.dart @@ -2461,6 +2461,58 @@ class NotesClient { } } +class NotificationsNotificationSubjectRichParameters { + NotificationsNotificationSubjectRichParameters( + this._data, { + this.mapStringDynamic, + }); + + factory NotificationsNotificationSubjectRichParameters.fromJson(dynamic data) { + Map? mapStringDynamic; + try { + mapStringDynamic = data as Map; + } catch (_) {} + return NotificationsNotificationSubjectRichParameters( + data, + mapStringDynamic: mapStringDynamic, + ); + } + + final dynamic _data; + + final Map? mapStringDynamic; + + // coverage:ignore-start + dynamic toJson() => _data; + // coverage:ignore-end +} + +class NotificationsNotificationMessageRichParameters { + NotificationsNotificationMessageRichParameters( + this._data, { + this.mapStringDynamic, + }); + + factory NotificationsNotificationMessageRichParameters.fromJson(dynamic data) { + Map? mapStringDynamic; + try { + mapStringDynamic = data as Map; + } catch (_) {} + return NotificationsNotificationMessageRichParameters( + data, + mapStringDynamic: mapStringDynamic, + ); + } + + final dynamic _data; + + final Map? mapStringDynamic; + + // coverage:ignore-start + dynamic toJson() => _data; + // coverage:ignore-end +} + @JsonSerializable() class NotificationsNotificationAction { NotificationsNotificationAction({ @@ -2531,11 +2583,11 @@ class NotificationsNotification { final String? subjectRich; - final List? subjectRichParameters; + final NotificationsNotificationSubjectRichParameters? subjectRichParameters; final String? messageRich; - final List? messageRichParameters; + final NotificationsNotificationMessageRichParameters? messageRichParameters; final String? icon; @@ -3317,7 +3369,6 @@ class UserStatusFindStatusOcsData { UserStatusFindStatusOcsData( this._data, { this.userStatusPublicUserStatus, - this.list, }); factory UserStatusFindStatusOcsData.fromJson(dynamic data) { @@ -3325,15 +3376,9 @@ class UserStatusFindStatusOcsData { try { userStatusPublicUserStatus = UserStatusPublicUserStatus.fromJson(data as Map); } catch (_) {} - List? list; - try { - list = data as List; - } catch (_) {} - assert([userStatusPublicUserStatus, list].where((final x) => x != null).length == 1, 'Need oneOf'); return UserStatusFindStatusOcsData( data, userStatusPublicUserStatus: userStatusPublicUserStatus, - list: list, ); } @@ -3341,9 +3386,6 @@ class UserStatusFindStatusOcsData { final UserStatusPublicUserStatus? userStatusPublicUserStatus; - /// Only happens when the user has never set a status - final List? list; - // coverage:ignore-start dynamic toJson() => _data; // coverage:ignore-end @@ -3420,7 +3462,6 @@ class UserStatusGetUserStatusOcsData { UserStatusGetUserStatusOcsData( this._data, { this.userStatus, - this.list, }); factory UserStatusGetUserStatusOcsData.fromJson(dynamic data) { @@ -3428,15 +3469,9 @@ class UserStatusGetUserStatusOcsData { try { userStatus = UserStatus.fromJson(data as Map); } catch (_) {} - List? list; - try { - list = data as List; - } catch (_) {} - assert([userStatus, list].where((final x) => x != null).length == 1, 'Need oneOf'); return UserStatusGetUserStatusOcsData( data, userStatus: userStatus, - list: list, ); } @@ -3444,9 +3479,6 @@ class UserStatusGetUserStatusOcsData { final UserStatus? userStatus; - /// Only happens when the user has never set a status - final List? list; - // coverage:ignore-start dynamic toJson() => _data; // coverage:ignore-end diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.g.dart b/packages/nextcloud/lib/src/nextcloud.openapi.g.dart index f3a750b3..4f09c96e 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.g.dart +++ b/packages/nextcloud/lib/src/nextcloud.openapi.g.dart @@ -1234,9 +1234,13 @@ NotificationsNotification _$NotificationsNotificationFromJson(Map?)?.map((e) => e as String).toList(), + subjectRichParameters: json['subjectRichParameters'] == null + ? null + : NotificationsNotificationSubjectRichParameters.fromJson(json['subjectRichParameters']), messageRich: json['messageRich'] as String?, - messageRichParameters: (json['messageRichParameters'] as List?)?.map((e) => e as String).toList(), + messageRichParameters: json['messageRichParameters'] == null + ? null + : NotificationsNotificationMessageRichParameters.fromJson(json['messageRichParameters']), icon: json['icon'] as String?, actions: (json['actions'] as List?) ?.map((e) => NotificationsNotificationAction.fromJson(e as Map)) @@ -1254,9 +1258,9 @@ Map _$NotificationsNotificationToJson(NotificationsNotification 'message': instance.message, 'link': instance.link, 'subjectRich': instance.subjectRich, - 'subjectRichParameters': instance.subjectRichParameters, + 'subjectRichParameters': instance.subjectRichParameters?.toJson(), 'messageRich': instance.messageRich, - 'messageRichParameters': instance.messageRichParameters, + 'messageRichParameters': instance.messageRichParameters?.toJson(), 'icon': instance.icon, 'actions': instance.actions?.map((e) => e.toJson()).toList(), }; diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.json b/packages/nextcloud/lib/src/nextcloud.openapi.json index d772ecdd..10bbc25c 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.json +++ b/packages/nextcloud/lib/src/nextcloud.openapi.json @@ -1057,21 +1057,23 @@ "type": "string" }, "subjectRichParameters": { - "type": "array", - "items": { - "description": "TODO", - "type": "string" - } + "anyOf": [ + { + "type": "object", + "properties": {} + } + ] }, "messageRich": { "type": "string" }, "messageRichParameters": { - "type": "array", - "items": { - "description": "TODO", - "type": "string" - } + "anyOf": [ + { + "type": "object", + "properties": {} + } + ] }, "icon": { "type": "string" @@ -1478,13 +1480,9 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "oneOf": [ + "anyOf": [ { "$ref": "#/components/schemas/UserStatus" - }, - { - "type": "array", - "description": "Only happens when the user has never set a status" } ] } @@ -1521,13 +1519,9 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "oneOf": [ + "anyOf": [ { "$ref": "#/components/schemas/UserStatusPublicUserStatus" - }, - { - "type": "array", - "description": "Only happens when the user has never set a status" } ] } diff --git a/packages/nextcloud/test/notifications_test.dart b/packages/nextcloud/test/notifications_test.dart index d176f1c0..00d85500 100644 --- a/packages/nextcloud/test/notifications_test.dart +++ b/packages/nextcloud/test/notifications_test.dart @@ -49,9 +49,9 @@ Future main() async { expect(response.ocs!.data![0].message, '456'); expect(response.ocs!.data![0].link, ''); expect(response.ocs!.data![0].subjectRich, ''); - expect(response.ocs!.data![0].subjectRichParameters, hasLength(0)); + expect(response.ocs!.data![0].subjectRichParameters!.mapStringDynamic, null); expect(response.ocs!.data![0].messageRich, ''); - expect(response.ocs!.data![0].messageRichParameters, hasLength(0)); + expect(response.ocs!.data![0].messageRichParameters!.mapStringDynamic, null); expect(response.ocs!.data![0].icon, isNotEmpty); expect(response.ocs!.data![0].actions, hasLength(0)); }); @@ -71,9 +71,9 @@ Future main() async { expect(response.ocs!.data!.message, '456'); expect(response.ocs!.data!.link, ''); expect(response.ocs!.data!.subjectRich, ''); - expect(response.ocs!.data!.subjectRichParameters, hasLength(0)); + expect(response.ocs!.data!.subjectRichParameters!.mapStringDynamic, null); expect(response.ocs!.data!.messageRich, ''); - expect(response.ocs!.data!.messageRichParameters, hasLength(0)); + expect(response.ocs!.data!.messageRichParameters!.mapStringDynamic, null); expect(response.ocs!.data!.icon, isNotEmpty); expect(response.ocs!.data!.actions, hasLength(0)); }); diff --git a/specs/notifications.json b/specs/notifications.json index a9dc5e31..7764de0a 100644 --- a/specs/notifications.json +++ b/specs/notifications.json @@ -107,21 +107,23 @@ "type": "string" }, "subjectRichParameters": { - "type": "array", - "items": { - "description": "TODO", - "type": "string" - } + "anyOf": [ + { + "type": "object", + "properties": {} + } + ] }, "messageRich": { "type": "string" }, "messageRichParameters": { - "type": "array", - "items": { - "description": "TODO", - "type": "string" - } + "anyOf": [ + { + "type": "object", + "properties": {} + } + ] }, "icon": { "type": "string" diff --git a/specs/user_status.json b/specs/user_status.json index 670c9bf7..d99a97b8 100644 --- a/specs/user_status.json +++ b/specs/user_status.json @@ -148,13 +148,9 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "oneOf": [ + "anyOf": [ { "$ref": "#/components/schemas/UserStatus" - }, - { - "type": "array", - "description": "Only happens when the user has never set a status" } ] } @@ -191,13 +187,9 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "oneOf": [ + "anyOf": [ { "$ref": "#/components/schemas/UserStatusPublicUserStatus" - }, - { - "type": "array", - "description": "Only happens when the user has never set a status" } ] }