From 097b7374aacd7743ef27a465e276c14ad9352b7d Mon Sep 17 00:00:00 2001 From: jld3103 Date: Sat, 24 Sep 2022 11:14:44 +0200 Subject: [PATCH] specs, nextcloud: Fix finding user status --- .../nextcloud/lib/src/nextcloud.openapi.dart | 36 ++++++++++++++++++- .../lib/src/nextcloud.openapi.g.dart | 2 +- .../nextcloud/lib/src/nextcloud.openapi.json | 10 +++++- packages/nextcloud/test/user_status_test.dart | 10 +++--- specs/user_status.json | 10 +++++- 5 files changed, 59 insertions(+), 9 deletions(-) diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.dart b/packages/nextcloud/lib/src/nextcloud.openapi.dart index 364458a4..593fc021 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.dart +++ b/packages/nextcloud/lib/src/nextcloud.openapi.dart @@ -3113,6 +3113,40 @@ class UserStatusFindAllStatuses { Map toJson() => _$UserStatusFindAllStatusesToJson(this); } +class UserStatusFindStatusOcsData { + UserStatusFindStatusOcsData( + this._data, { + this.userStatusPublicUserStatus, + this.list, + }); + + factory UserStatusFindStatusOcsData.fromJson(dynamic data) { + UserStatusPublicUserStatus? userStatusPublicUserStatus; + 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, + ); + } + + final dynamic _data; + + final UserStatusPublicUserStatus? userStatusPublicUserStatus; + + /// Only happens when the user has never set a status + final List? list; + + dynamic toJson() => _data; +} + @JsonSerializable() class UserStatusFindStatusOcs { UserStatusFindStatusOcs({ @@ -3124,7 +3158,7 @@ class UserStatusFindStatusOcs { final OCSMeta? meta; - final UserStatusPublicUserStatus? data; + final UserStatusFindStatusOcsData? data; Map toJson() => _$UserStatusFindStatusOcsToJson(this); } diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.g.dart b/packages/nextcloud/lib/src/nextcloud.openapi.g.dart index 55fb754e..84e60386 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.g.dart +++ b/packages/nextcloud/lib/src/nextcloud.openapi.g.dart @@ -1558,7 +1558,7 @@ Map _$UserStatusFindAllStatusesToJson(UserStatusFindAllStatuses UserStatusFindStatusOcs _$UserStatusFindStatusOcsFromJson(Map json) => UserStatusFindStatusOcs( meta: json['meta'] == null ? null : OCSMeta.fromJson(json['meta'] as Map), - data: json['data'] == null ? null : UserStatusPublicUserStatus.fromJson(json['data'] as Map), + data: json['data'] == null ? null : UserStatusFindStatusOcsData.fromJson(json['data']), ); Map _$UserStatusFindStatusOcsToJson(UserStatusFindStatusOcs instance) => { diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.json b/packages/nextcloud/lib/src/nextcloud.openapi.json index a5c263a1..1249ec74 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.json +++ b/packages/nextcloud/lib/src/nextcloud.openapi.json @@ -1521,7 +1521,15 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "$ref": "#/components/schemas/UserStatusPublicUserStatus" + "oneOf": [ + { + "$ref": "#/components/schemas/UserStatusPublicUserStatus" + }, + { + "type": "array", + "description": "Only happens when the user has never set a status" + } + ] } } } diff --git a/packages/nextcloud/test/user_status_test.dart b/packages/nextcloud/test/user_status_test.dart index 2ab0cbe1..54f4cf06 100644 --- a/packages/nextcloud/test/user_status_test.dart +++ b/packages/nextcloud/test/user_status_test.dart @@ -93,11 +93,11 @@ Future main() async { await client.userStatus.setStatus(statusType: UserStatusType.online); final response = await client.userStatus.findStatus(userId: 'test'); - expect(response.ocs!.data!.userId, 'test'); - expect(response.ocs!.data!.message, null); - expect(response.ocs!.data!.icon, null); - expect(response.ocs!.data!.clearAt, null); - expect(response.ocs!.data!.status, UserStatusType.online); + expect(response.ocs!.data!.userStatusPublicUserStatus!.userId, 'test'); + expect(response.ocs!.data!.userStatusPublicUserStatus!.message, null); + expect(response.ocs!.data!.userStatusPublicUserStatus!.icon, null); + expect(response.ocs!.data!.userStatusPublicUserStatus!.clearAt, null); + expect(response.ocs!.data!.userStatusPublicUserStatus!.status, UserStatusType.online); }); test('Set predefined message', () async { diff --git a/specs/user_status.json b/specs/user_status.json index 2631f771..670c9bf7 100644 --- a/specs/user_status.json +++ b/specs/user_status.json @@ -191,7 +191,15 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "$ref": "#/components/schemas/UserStatusPublicUserStatus" + "oneOf": [ + { + "$ref": "#/components/schemas/UserStatusPublicUserStatus" + }, + { + "type": "array", + "description": "Only happens when the user has never set a status" + } + ] } } }