Browse Source

Merge pull request #159 from provokateurin/feature/autocomplete

specs,nextcloud: Add autocomplete API
pull/160/head
Kate 2 years ago committed by GitHub
parent
commit
aa0649247e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      packages/nextcloud/lib/src/helpers.dart
  2. 161
      packages/nextcloud/lib/src/nextcloud.openapi.dart
  3. 59
      packages/nextcloud/lib/src/nextcloud.openapi.g.dart
  4. 137
      packages/nextcloud/lib/src/nextcloud.openapi.json
  5. 37
      packages/nextcloud/test/core_test.dart
  6. 137
      specs/core.json

20
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;
}

161
packages/nextcloud/lib/src/nextcloud.openapi.dart

@ -335,6 +335,40 @@ class CoreClient {
}
throw ApiException.fromResponse(response); // coverage:ignore-line
}
Future<CoreAutocompleteResult> autocomplete({
required String search,
required String itemType,
required String itemId,
String? sorter,
required List<int> shareTypes,
int limit = 10,
}) async {
var path = '/ocs/v2.php/core/autocomplete/get';
final queryParameters = <String, dynamic>{};
final headers = <String, String>{};
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<String, dynamic>);
}
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<String, dynamic> json) =>
_$CoreAutocompleteResult_Ocs_DataFromJson(json);
factory CoreAutocompleteResult_Ocs_Data.fromJsonString(String data) =>
CoreAutocompleteResult_Ocs_Data.fromJson(json.decode(data) as Map<String, dynamic>);
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<String, dynamic> 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<String, dynamic> json) => _$CoreAutocompleteResult_OcsFromJson(json);
factory CoreAutocompleteResult_Ocs.fromJsonString(String data) =>
CoreAutocompleteResult_Ocs.fromJson(json.decode(data) as Map<String, dynamic>);
final OCSMeta meta;
final List<CoreAutocompleteResult_Ocs_Data> data;
// coverage:ignore-start
Map<String, dynamic> 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<String, dynamic> json) => _$CoreAutocompleteResultFromJson(json);
factory CoreAutocompleteResult.fromJsonString(String data) =>
CoreAutocompleteResult.fromJson(json.decode(data) as Map<String, dynamic>);
final CoreAutocompleteResult_Ocs ocs;
// coverage:ignore-start
Map<String, dynamic> 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 = <Type, dynamic Function(dynamic)>{
CoreLoginFlowResult: (final data) => CoreLoginFlowResult.fromJson(data as Map<String, dynamic>),
List<CoreLoginFlowResult>: (final data) =>
(data as List).map((final e) => CoreLoginFlowResult.fromJson(e as Map<String, dynamic>)).toList(),
CoreAutocompleteResult: (final data) => CoreAutocompleteResult.fromJson(data as Map<String, dynamic>),
List<CoreAutocompleteResult>: (final data) =>
(data as List).map((final e) => CoreAutocompleteResult.fromJson(e as Map<String, dynamic>)).toList(),
CoreAutocompleteResult_Ocs: (final data) => CoreAutocompleteResult_Ocs.fromJson(data as Map<String, dynamic>),
List<CoreAutocompleteResult_Ocs>: (final data) =>
(data as List).map((final e) => CoreAutocompleteResult_Ocs.fromJson(e as Map<String, dynamic>)).toList(),
CoreAutocompleteResult_Ocs_Data: (final data) =>
CoreAutocompleteResult_Ocs_Data.fromJson(data as Map<String, dynamic>),
List<CoreAutocompleteResult_Ocs_Data>: (final data) =>
(data as List).map((final e) => CoreAutocompleteResult_Ocs_Data.fromJson(e as Map<String, dynamic>)).toList(),
GetSupportedApiVersions: (final data) => GetSupportedApiVersions.fromJson(data as Map<String, dynamic>),
List<GetSupportedApiVersions>: (final data) =>
(data as List).map((final e) => GetSupportedApiVersions.fromJson(e as Map<String, dynamic>)).toList(),
@ -5240,6 +5395,12 @@ final _serializers = <Type, dynamic Function(dynamic)>{
List<CoreLoginFlowInit_Poll>: (final data) => data.map((final e) => e.toJson()).toList(),
CoreLoginFlowResult: (final data) => data.toJson(),
List<CoreLoginFlowResult>: (final data) => data.map((final e) => e.toJson()).toList(),
CoreAutocompleteResult: (final data) => data.toJson(),
List<CoreAutocompleteResult>: (final data) => data.map((final e) => e.toJson()).toList(),
CoreAutocompleteResult_Ocs: (final data) => data.toJson(),
List<CoreAutocompleteResult_Ocs>: (final data) => data.map((final e) => e.toJson()).toList(),
CoreAutocompleteResult_Ocs_Data: (final data) => data.toJson(),
List<CoreAutocompleteResult_Ocs_Data>: (final data) => data.map((final e) => e.toJson()).toList(),
GetSupportedApiVersions: (final data) => data.toJson(),
List<GetSupportedApiVersions>: (final data) => data.map((final e) => e.toJson()).toList(),
NewsListFolders: (final data) => data.toJson(),

59
packages/nextcloud/lib/src/nextcloud.openapi.g.dart

@ -1139,6 +1139,65 @@ Map<String, dynamic> _$CoreLoginFlowResultToJson(CoreLoginFlowResult instance) =
'appPassword': instance.appPassword,
};
CoreAutocompleteResult_Ocs_Data _$CoreAutocompleteResult_Ocs_DataFromJson(Map<String, dynamic> 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<String, dynamic> _$CoreAutocompleteResult_Ocs_DataToJson(CoreAutocompleteResult_Ocs_Data instance) =>
<String, dynamic>{
'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<String, dynamic> json) {
$checkKeys(
json,
allowedKeys: const ['meta', 'data'],
);
return CoreAutocompleteResult_Ocs(
meta: OCSMeta.fromJson(json['meta'] as Map<String, dynamic>),
data: (json['data'] as List<dynamic>)
.map((e) => CoreAutocompleteResult_Ocs_Data.fromJson(e as Map<String, dynamic>))
.toList(),
);
}
Map<String, dynamic> _$CoreAutocompleteResult_OcsToJson(CoreAutocompleteResult_Ocs instance) => <String, dynamic>{
'meta': instance.meta.toJson(),
'data': instance.data.map((e) => e.toJson()).toList(),
};
CoreAutocompleteResult _$CoreAutocompleteResultFromJson(Map<String, dynamic> json) {
$checkKeys(
json,
allowedKeys: const ['ocs'],
);
return CoreAutocompleteResult(
ocs: CoreAutocompleteResult_Ocs.fromJson(json['ocs'] as Map<String, dynamic>),
);
}
Map<String, dynamic> _$CoreAutocompleteResultToJson(CoreAutocompleteResult instance) => <String, dynamic>{
'ocs': instance.ocs.toJson(),
};
GetSupportedApiVersions _$GetSupportedApiVersionsFromJson(Map<String, dynamic> json) {
$checkKeys(
json,

137
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",

37
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, '');
});
});
}

137
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"
}
}
}
}
}
}
}
}
}

Loading…
Cancel
Save