From 825558eabe1b14be990f418252a64192004badeb Mon Sep 17 00:00:00 2001 From: jld3103 Date: Fri, 16 Dec 2022 12:47:42 +0100 Subject: [PATCH] specs,nextcloud: Add autocomplete API --- packages/nextcloud/lib/src/helpers.dart | 20 +++ .../nextcloud/lib/src/nextcloud.openapi.dart | 161 ++++++++++++++++++ .../lib/src/nextcloud.openapi.g.dart | 59 +++++++ .../nextcloud/lib/src/nextcloud.openapi.json | 137 +++++++++++++++ packages/nextcloud/test/core_test.dart | 37 +++- specs/core.json | 137 +++++++++++++++ 6 files changed, 548 insertions(+), 3 deletions(-) diff --git a/packages/nextcloud/lib/src/helpers.dart b/packages/nextcloud/lib/src/helpers.dart index 2cb18cca..e117d972 100644 --- a/packages/nextcloud/lib/src/helpers.dart +++ b/packages/nextcloud/lib/src/helpers.dart @@ -81,3 +81,23 @@ enum NewsListType { final int code; } + +enum ShareType { + user(0), + group(1), + usergroup(2), + link(3), + email(4), + // 5 was contact, is no longer used + remote(6), + circle(7), + guest(8), + remoteGroup(9), + room(10), + // 11 is userroom, but it's only used internally + deck(12), + deckUser(13); + + const ShareType(this.code); + final int code; +} diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.dart b/packages/nextcloud/lib/src/nextcloud.openapi.dart index 0648a418..82d5ebad 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.dart +++ b/packages/nextcloud/lib/src/nextcloud.openapi.dart @@ -335,6 +335,40 @@ class CoreClient { } throw ApiException.fromResponse(response); // coverage:ignore-line } + + Future autocomplete({ + required String search, + required String itemType, + required String itemId, + String? sorter, + required List shareTypes, + int limit = 10, + }) async { + var path = '/ocs/v2.php/core/autocomplete/get'; + final queryParameters = {}; + final headers = {}; + Uint8List? body; + queryParameters['search'] = search; + queryParameters['itemType'] = itemType; + queryParameters['itemId'] = itemId; + if (sorter != null) { + queryParameters['sorter'] = sorter; + } + queryParameters['shareTypes[]'] = shareTypes.map((final e) => e).toList().map((final e) => e.toString()).toList(); + if (limit != 10) { + queryParameters['limit'] = limit.toString(); + } + final response = await rootClient.doRequest( + 'get', + Uri(path: path, queryParameters: queryParameters.isNotEmpty ? queryParameters : null).toString(), + headers, + body, + ); + if (response.statusCode == 200) { + return CoreAutocompleteResult.fromJson(json.decode(utf8.decode(response.body) as String) as Map); + } + throw ApiException.fromResponse(response); // coverage:ignore-line + } } class NewsClient { @@ -3063,6 +3097,117 @@ class CoreLoginFlowResult { static String toJsonString(CoreLoginFlowResult data) => json.encode(data.toJson()); } +class CoreAutocompleteResult_Ocs_Data_Status { + CoreAutocompleteResult_Ocs_Data_Status( + this._data, { + this.string, + }); + + factory CoreAutocompleteResult_Ocs_Data_Status.fromJson(dynamic data) { + String? string; + try { + string = (data as String); + } catch (_) {} + return CoreAutocompleteResult_Ocs_Data_Status( + data, + string: string, + ); + } + + factory CoreAutocompleteResult_Ocs_Data_Status.fromJsonString(String data) => + CoreAutocompleteResult_Ocs_Data_Status.fromJson(json.decode(data)); + + final dynamic _data; + + final String? string; + + // coverage:ignore-start + dynamic toJson() => _data; + // coverage:ignore-end + + static String toJsonString(dynamic data) => json.encode(data); +} + +@JsonSerializable() +class CoreAutocompleteResult_Ocs_Data { + CoreAutocompleteResult_Ocs_Data({ + required this.id, + required this.label, + required this.icon, + required this.source, + required this.status, + required this.subline, + required this.shareWithDisplayNameUnique, + }); + + factory CoreAutocompleteResult_Ocs_Data.fromJson(Map json) => + _$CoreAutocompleteResult_Ocs_DataFromJson(json); + + factory CoreAutocompleteResult_Ocs_Data.fromJsonString(String data) => + CoreAutocompleteResult_Ocs_Data.fromJson(json.decode(data) as Map); + + final String id; + + final String label; + + final String icon; + + final String source; + + final CoreAutocompleteResult_Ocs_Data_Status status; + + final String subline; + + final String shareWithDisplayNameUnique; + + // coverage:ignore-start + Map toJson() => _$CoreAutocompleteResult_Ocs_DataToJson(this); + // coverage:ignore-end + + static String toJsonString(CoreAutocompleteResult_Ocs_Data data) => json.encode(data.toJson()); +} + +@JsonSerializable() +class CoreAutocompleteResult_Ocs { + CoreAutocompleteResult_Ocs({ + required this.meta, + required this.data, + }); + + factory CoreAutocompleteResult_Ocs.fromJson(Map json) => _$CoreAutocompleteResult_OcsFromJson(json); + + factory CoreAutocompleteResult_Ocs.fromJsonString(String data) => + CoreAutocompleteResult_Ocs.fromJson(json.decode(data) as Map); + + final OCSMeta meta; + + final List data; + + // coverage:ignore-start + Map toJson() => _$CoreAutocompleteResult_OcsToJson(this); + // coverage:ignore-end + + static String toJsonString(CoreAutocompleteResult_Ocs data) => json.encode(data.toJson()); +} + +@JsonSerializable() +class CoreAutocompleteResult { + CoreAutocompleteResult({required this.ocs}); + + factory CoreAutocompleteResult.fromJson(Map json) => _$CoreAutocompleteResultFromJson(json); + + factory CoreAutocompleteResult.fromJsonString(String data) => + CoreAutocompleteResult.fromJson(json.decode(data) as Map); + + final CoreAutocompleteResult_Ocs ocs; + + // coverage:ignore-start + Map toJson() => _$CoreAutocompleteResultToJson(this); + // coverage:ignore-end + + static String toJsonString(CoreAutocompleteResult data) => json.encode(data.toJson()); +} + @JsonSerializable() class GetSupportedApiVersions { GetSupportedApiVersions({this.apiLevels}); @@ -4950,6 +5095,16 @@ final _deserializers = { CoreLoginFlowResult: (final data) => CoreLoginFlowResult.fromJson(data as Map), List: (final data) => (data as List).map((final e) => CoreLoginFlowResult.fromJson(e as Map)).toList(), + CoreAutocompleteResult: (final data) => CoreAutocompleteResult.fromJson(data as Map), + List: (final data) => + (data as List).map((final e) => CoreAutocompleteResult.fromJson(e as Map)).toList(), + CoreAutocompleteResult_Ocs: (final data) => CoreAutocompleteResult_Ocs.fromJson(data as Map), + List: (final data) => + (data as List).map((final e) => CoreAutocompleteResult_Ocs.fromJson(e as Map)).toList(), + CoreAutocompleteResult_Ocs_Data: (final data) => + CoreAutocompleteResult_Ocs_Data.fromJson(data as Map), + List: (final data) => + (data as List).map((final e) => CoreAutocompleteResult_Ocs_Data.fromJson(e as Map)).toList(), GetSupportedApiVersions: (final data) => GetSupportedApiVersions.fromJson(data as Map), List: (final data) => (data as List).map((final e) => GetSupportedApiVersions.fromJson(e as Map)).toList(), @@ -5240,6 +5395,12 @@ final _serializers = { List: (final data) => data.map((final e) => e.toJson()).toList(), CoreLoginFlowResult: (final data) => data.toJson(), List: (final data) => data.map((final e) => e.toJson()).toList(), + CoreAutocompleteResult: (final data) => data.toJson(), + List: (final data) => data.map((final e) => e.toJson()).toList(), + CoreAutocompleteResult_Ocs: (final data) => data.toJson(), + List: (final data) => data.map((final e) => e.toJson()).toList(), + CoreAutocompleteResult_Ocs_Data: (final data) => data.toJson(), + List: (final data) => data.map((final e) => e.toJson()).toList(), GetSupportedApiVersions: (final data) => data.toJson(), List: (final data) => data.map((final e) => e.toJson()).toList(), NewsListFolders: (final data) => data.toJson(), diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.g.dart b/packages/nextcloud/lib/src/nextcloud.openapi.g.dart index 240f0d2d..978348df 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.g.dart +++ b/packages/nextcloud/lib/src/nextcloud.openapi.g.dart @@ -1139,6 +1139,65 @@ Map _$CoreLoginFlowResultToJson(CoreLoginFlowResult instance) = 'appPassword': instance.appPassword, }; +CoreAutocompleteResult_Ocs_Data _$CoreAutocompleteResult_Ocs_DataFromJson(Map json) { + $checkKeys( + json, + allowedKeys: const ['id', 'label', 'icon', 'source', 'status', 'subline', 'shareWithDisplayNameUnique'], + ); + return CoreAutocompleteResult_Ocs_Data( + id: json['id'] as String, + label: json['label'] as String, + icon: json['icon'] as String, + source: json['source'] as String, + status: CoreAutocompleteResult_Ocs_Data_Status.fromJson(json['status']), + subline: json['subline'] as String, + shareWithDisplayNameUnique: json['shareWithDisplayNameUnique'] as String, + ); +} + +Map _$CoreAutocompleteResult_Ocs_DataToJson(CoreAutocompleteResult_Ocs_Data instance) => + { + 'id': instance.id, + 'label': instance.label, + 'icon': instance.icon, + 'source': instance.source, + 'status': instance.status.toJson(), + 'subline': instance.subline, + 'shareWithDisplayNameUnique': instance.shareWithDisplayNameUnique, + }; + +CoreAutocompleteResult_Ocs _$CoreAutocompleteResult_OcsFromJson(Map json) { + $checkKeys( + json, + allowedKeys: const ['meta', 'data'], + ); + return CoreAutocompleteResult_Ocs( + meta: OCSMeta.fromJson(json['meta'] as Map), + data: (json['data'] as List) + .map((e) => CoreAutocompleteResult_Ocs_Data.fromJson(e as Map)) + .toList(), + ); +} + +Map _$CoreAutocompleteResult_OcsToJson(CoreAutocompleteResult_Ocs instance) => { + 'meta': instance.meta.toJson(), + 'data': instance.data.map((e) => e.toJson()).toList(), + }; + +CoreAutocompleteResult _$CoreAutocompleteResultFromJson(Map json) { + $checkKeys( + json, + allowedKeys: const ['ocs'], + ); + return CoreAutocompleteResult( + ocs: CoreAutocompleteResult_Ocs.fromJson(json['ocs'] as Map), + ); +} + +Map _$CoreAutocompleteResultToJson(CoreAutocompleteResult instance) => { + 'ocs': instance.ocs.toJson(), + }; + GetSupportedApiVersions _$GetSupportedApiVersionsFromJson(Map json) { $checkKeys( json, diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.json b/packages/nextcloud/lib/src/nextcloud.openapi.json index 9acac440..a4c105e1 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.json +++ b/packages/nextcloud/lib/src/nextcloud.openapi.json @@ -917,6 +917,68 @@ } } }, + "CoreAutocompleteResult": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": { + "type": "array", + "items": { + "type": "object", + "required": [ + "id", + "label", + "icon", + "source", + "status", + "subline", + "shareWithDisplayNameUnique" + ], + "properties": { + "id": { + "type": "string" + }, + "label": { + "type": "string" + }, + "icon": { + "type": "string" + }, + "source": { + "type": "string" + }, + "status": { + "anyOf": [ + { + "type": "string" + } + ] + }, + "subline": { + "type": "string" + }, + "shareWithDisplayNameUnique": { + "type": "string" + } + } + } + } + } + } + } + }, "NewsListFeeds": { "type": "object", "required": [ @@ -2200,6 +2262,81 @@ } } }, + "/ocs/v2.php/core/autocomplete/get": { + "get": { + "operationId": "autocomplete", + "tags": [ + "core" + ], + "parameters": [ + { + "name": "search", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "itemType", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "itemId", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "sorter", + "in": "query", + "description": "can be piped, top prio first, e.g.: \"commenters|share-recipients\"", + "required": false, + "schema": { + "type": "string" + } + }, + { + "name": "shareTypes", + "in": "query", + "required": true, + "schema": { + "type": "array", + "items": { + "type": "integer" + } + } + }, + { + "name": "limit", + "in": "query", + "required": false, + "schema": { + "type": "integer", + "default": 10 + } + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CoreAutocompleteResult" + } + } + } + } + } + } + }, "/index.php/apps/news/api": { "get": { "operationId": "get-supported-api-versions", diff --git a/packages/nextcloud/test/core_test.dart b/packages/nextcloud/test/core_test.dart index 1696bd6b..475f455b 100644 --- a/packages/nextcloud/test/core_test.dart +++ b/packages/nextcloud/test/core_test.dart @@ -8,6 +8,7 @@ Future main() async { apps: [ 'news', 'notes', + 'spreed', ], ); @@ -56,13 +57,43 @@ Future main() async { test('Get navigation apps', () async { final navigationApps = await client.core.getNavigationApps(); - expect(navigationApps.ocs.data, hasLength(6)); + expect(navigationApps.ocs.data, hasLength(7)); expect(navigationApps.ocs.data[0].id, 'dashboard'); expect(navigationApps.ocs.data[1].id, 'files'); expect(navigationApps.ocs.data[2].id, 'photos'); expect(navigationApps.ocs.data[3].id, 'activity'); - expect(navigationApps.ocs.data[4].id, 'notes'); - expect(navigationApps.ocs.data[5].id, 'news'); + expect(navigationApps.ocs.data[4].id, 'spreed'); + expect(navigationApps.ocs.data[5].id, 'notes'); + expect(navigationApps.ocs.data[6].id, 'news'); + }); + + test('Autocomplete', () async { + final response = await client.core.autocomplete( + search: '', + itemType: 'call', + itemId: 'new', + shareTypes: [ + ShareType.user.code, + ShareType.group.code, + ], + ); + expect(response.ocs.data, hasLength(2)); + + expect(response.ocs.data[0].id, 'admin'); + expect(response.ocs.data[0].label, 'admin'); + expect(response.ocs.data[0].icon, 'icon-user'); + expect(response.ocs.data[0].source, 'users'); + expect(response.ocs.data[0].status.string, isNull); + expect(response.ocs.data[0].subline, ''); + expect(response.ocs.data[0].shareWithDisplayNameUnique, 'admin@example.com'); + + expect(response.ocs.data[1].id, 'admin'); + expect(response.ocs.data[1].label, 'admin'); + expect(response.ocs.data[1].icon, ''); + expect(response.ocs.data[1].source, 'groups'); + expect(response.ocs.data[1].status.string, isEmpty); + expect(response.ocs.data[1].subline, ''); + expect(response.ocs.data[1].shareWithDisplayNameUnique, ''); }); }); } diff --git a/specs/core.json b/specs/core.json index f0ab9210..94b475f6 100644 --- a/specs/core.json +++ b/specs/core.json @@ -902,6 +902,68 @@ "type": "string" } } + }, + "CoreAutocompleteResult": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": { + "type": "array", + "items": { + "type": "object", + "required": [ + "id", + "label", + "icon", + "source", + "status", + "subline", + "shareWithDisplayNameUnique" + ], + "properties": { + "id": { + "type": "string" + }, + "label": { + "type": "string" + }, + "icon": { + "type": "string" + }, + "source": { + "type": "string" + }, + "status": { + "anyOf": [ + { + "type": "string" + } + ] + }, + "subline": { + "type": "string" + }, + "shareWithDisplayNameUnique": { + "type": "string" + } + } + } + } + } + } + } } }, "securitySchemes": { @@ -1176,6 +1238,81 @@ } } } + }, + "/ocs/v2.php/core/autocomplete/get": { + "get": { + "operationId": "autocomplete", + "tags": [ + "core" + ], + "parameters": [ + { + "name": "search", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "itemType", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "itemId", + "in": "query", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "sorter", + "in": "query", + "description": "can be piped, top prio first, e.g.: \"commenters|share-recipients\"", + "required": false, + "schema": { + "type": "string" + } + }, + { + "name": "shareTypes", + "in": "query", + "required": true, + "schema": { + "type": "array", + "items": { + "type": "integer" + } + } + }, + { + "name": "limit", + "in": "query", + "required": false, + "schema": { + "type": "integer", + "default": 10 + } + } + ], + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CoreAutocompleteResult" + } + } + } + } + } + } } } }