From c3c2ba4bdbe5376edaff499b42f8a2e1440faa7d Mon Sep 17 00:00:00 2001 From: jld3103 Date: Wed, 27 Sep 2023 17:15:43 +0200 Subject: [PATCH] fix(nextcloud): Fix autocomplete Signed-off-by: jld3103 --- external/nextcloud-server | 2 +- .../nextcloud/lib/src/api/core.openapi.dart | 106 ++++- .../nextcloud/lib/src/api/core.openapi.g.dart | 371 +++++++++++++++++- .../nextcloud/lib/src/api/core.openapi.json | 33 +- packages/nextcloud/test/core_test.dart | 60 +-- 5 files changed, 508 insertions(+), 64 deletions(-) diff --git a/external/nextcloud-server b/external/nextcloud-server index 69a05099..c88b02ab 160000 --- a/external/nextcloud-server +++ b/external/nextcloud-server @@ -1 +1 @@ -Subproject commit 69a050991bd580c0fef0c10a27fcadae701a9338 +Subproject commit c88b02abff69ff25262b1760bc0beacca23c61ac diff --git a/packages/nextcloud/lib/src/api/core.openapi.dart b/packages/nextcloud/lib/src/api/core.openapi.dart index 317a6241..b46e5760 100644 --- a/packages/nextcloud/lib/src/api/core.openapi.dart +++ b/packages/nextcloud/lib/src/api/core.openapi.dart @@ -4732,13 +4732,113 @@ abstract class CoreAppPasswordDeleteAppPasswordResponseApplicationJson _$coreAppPasswordDeleteAppPasswordResponseApplicationJsonSerializer; } +@BuiltValue(instantiable: false) +abstract interface class CoreAutocompleteResult_Status0Interface { + String get status; + String? get message; + String? get icon; + int? get clearAt; + CoreAutocompleteResult_Status0Interface rebuild( + final void Function(CoreAutocompleteResult_Status0InterfaceBuilder) updates, + ); + CoreAutocompleteResult_Status0InterfaceBuilder toBuilder(); +} + +abstract class CoreAutocompleteResult_Status0 + implements + CoreAutocompleteResult_Status0Interface, + Built { + factory CoreAutocompleteResult_Status0([final void Function(CoreAutocompleteResult_Status0Builder)? b]) = + _$CoreAutocompleteResult_Status0; + + // coverage:ignore-start + const CoreAutocompleteResult_Status0._(); + // coverage:ignore-end + + // coverage:ignore-start + factory CoreAutocompleteResult_Status0.fromJson(final Map json) => + _jsonSerializers.deserializeWith(serializer, json)!; + // coverage:ignore-end + + // coverage:ignore-start + Map toJson() => _jsonSerializers.serializeWith(serializer, this)! as Map; + // coverage:ignore-end + + static Serializer get serializer => _$coreAutocompleteResultStatus0Serializer; +} + +abstract class CoreAutocompleteResult_Status + implements Built { + factory CoreAutocompleteResult_Status([final void Function(CoreAutocompleteResult_StatusBuilder)? b]) = + _$CoreAutocompleteResult_Status; + + // coverage:ignore-start + const CoreAutocompleteResult_Status._(); + // coverage:ignore-end + + // coverage:ignore-start + factory CoreAutocompleteResult_Status.fromJson(final Map json) => + _jsonSerializers.deserializeWith(serializer, json)!; + // coverage:ignore-end + + // coverage:ignore-start + Map toJson() => _jsonSerializers.serializeWith(serializer, this)! as Map; + // coverage:ignore-end + + JsonObject get data; + CoreAutocompleteResult_Status0? get autocompleteResultStatus0; + String? get string; + @BuiltValueSerializer(custom: true) + static Serializer get serializer => _$CoreAutocompleteResult_StatusSerializer(); +} + +class _$CoreAutocompleteResult_StatusSerializer implements PrimitiveSerializer { + @override + final Iterable types = const [CoreAutocompleteResult_Status, _$CoreAutocompleteResult_Status]; + + @override + final String wireName = 'CoreAutocompleteResult_Status'; + + @override + Object serialize( + final Serializers serializers, + final CoreAutocompleteResult_Status object, { + final FullType specifiedType = FullType.unspecified, + }) => + object.data.value; + + @override + CoreAutocompleteResult_Status deserialize( + final Serializers serializers, + final Object data, { + final FullType specifiedType = FullType.unspecified, + }) { + final result = CoreAutocompleteResult_StatusBuilder()..data = JsonObject(data); + try { + result._autocompleteResultStatus0 = (_jsonSerializers.deserialize( + data, + specifiedType: const FullType(CoreAutocompleteResult_Status0), + )! as CoreAutocompleteResult_Status0) + .toBuilder(); + } catch (_) {} + try { + result._string = _jsonSerializers.deserialize(data, specifiedType: const FullType(String))! as String; + } catch (_) {} + assert( + [result._autocompleteResultStatus0, result._string].where((final x) => x != null).isNotEmpty, + 'Need oneOf for ${result._data}', + ); + return result.build(); + } +} + @BuiltValue(instantiable: false) abstract interface class CoreAutocompleteResultInterface { String get id; String get label; String get icon; String get source; - String get status; + CoreAutocompleteResult_Status get status; String get subline; String get shareWithDisplayNameUnique; CoreAutocompleteResultInterface rebuild(final void Function(CoreAutocompleteResultInterfaceBuilder) updates); @@ -10259,6 +10359,10 @@ final Serializers _serializers = (Serializers().toBuilder() ..add(CoreAutoCompleteGetResponseApplicationJson_Ocs.serializer) ..addBuilderFactory(const FullType(CoreAutocompleteResult), CoreAutocompleteResult.new) ..add(CoreAutocompleteResult.serializer) + ..addBuilderFactory(const FullType(CoreAutocompleteResult_Status), CoreAutocompleteResult_Status.new) + ..add(CoreAutocompleteResult_Status.serializer) + ..addBuilderFactory(const FullType(CoreAutocompleteResult_Status0), CoreAutocompleteResult_Status0.new) + ..add(CoreAutocompleteResult_Status0.serializer) ..addBuilderFactory( const FullType(BuiltList, [FullType(CoreAutocompleteResult)]), ListBuilder.new, diff --git a/packages/nextcloud/lib/src/api/core.openapi.g.dart b/packages/nextcloud/lib/src/api/core.openapi.g.dart index 633ad258..f00b689d 100644 --- a/packages/nextcloud/lib/src/api/core.openapi.g.dart +++ b/packages/nextcloud/lib/src/api/core.openapi.g.dart @@ -32,6 +32,8 @@ Serializer Serializer _$coreAppPasswordDeleteAppPasswordResponseApplicationJsonSerializer = _$CoreAppPasswordDeleteAppPasswordResponseApplicationJsonSerializer(); +Serializer _$coreAutocompleteResultStatus0Serializer = + _$CoreAutocompleteResult_Status0Serializer(); Serializer _$coreAutocompleteResultSerializer = _$CoreAutocompleteResultSerializer(); Serializer _$coreAutoCompleteGetResponseApplicationJsonOcsSerializer = _$CoreAutoCompleteGetResponseApplicationJson_OcsSerializer(); @@ -897,6 +899,71 @@ class _$CoreAppPasswordDeleteAppPasswordResponseApplicationJsonSerializer } } +class _$CoreAutocompleteResult_Status0Serializer implements StructuredSerializer { + @override + final Iterable types = const [CoreAutocompleteResult_Status0, _$CoreAutocompleteResult_Status0]; + @override + final String wireName = 'CoreAutocompleteResult_Status0'; + + @override + Iterable serialize(Serializers serializers, CoreAutocompleteResult_Status0 object, + {FullType specifiedType = FullType.unspecified}) { + final result = [ + 'status', + serializers.serialize(object.status, specifiedType: const FullType(String)), + ]; + Object? value; + value = object.message; + if (value != null) { + result + ..add('message') + ..add(serializers.serialize(value, specifiedType: const FullType(String))); + } + value = object.icon; + if (value != null) { + result + ..add('icon') + ..add(serializers.serialize(value, specifiedType: const FullType(String))); + } + value = object.clearAt; + if (value != null) { + result + ..add('clearAt') + ..add(serializers.serialize(value, specifiedType: const FullType(int))); + } + return result; + } + + @override + CoreAutocompleteResult_Status0 deserialize(Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = CoreAutocompleteResult_Status0Builder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final Object? value = iterator.current; + switch (key) { + case 'status': + result.status = serializers.deserialize(value, specifiedType: const FullType(String))! as String; + break; + case 'message': + result.message = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; + break; + case 'icon': + result.icon = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; + break; + case 'clearAt': + result.clearAt = serializers.deserialize(value, specifiedType: const FullType(int)) as int?; + break; + } + } + + return result.build(); + } +} + class _$CoreAutocompleteResultSerializer implements StructuredSerializer { @override final Iterable types = const [CoreAutocompleteResult, _$CoreAutocompleteResult]; @@ -916,7 +983,7 @@ class _$CoreAutocompleteResultSerializer implements StructuredSerializer + (CoreAutocompleteResult_Status0Builder()..update(updates))._build(); + + _$CoreAutocompleteResult_Status0._({required this.status, this.message, this.icon, this.clearAt}) : super._() { + BuiltValueNullFieldError.checkNotNull(status, r'CoreAutocompleteResult_Status0', 'status'); + } + + @override + CoreAutocompleteResult_Status0 rebuild(void Function(CoreAutocompleteResult_Status0Builder) updates) => + (toBuilder()..update(updates)).build(); + + @override + CoreAutocompleteResult_Status0Builder toBuilder() => CoreAutocompleteResult_Status0Builder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is CoreAutocompleteResult_Status0 && + status == other.status && + message == other.message && + icon == other.icon && + clearAt == other.clearAt; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, status.hashCode); + _$hash = $jc(_$hash, message.hashCode); + _$hash = $jc(_$hash, icon.hashCode); + _$hash = $jc(_$hash, clearAt.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'CoreAutocompleteResult_Status0') + ..add('status', status) + ..add('message', message) + ..add('icon', icon) + ..add('clearAt', clearAt)) + .toString(); + } +} + +class CoreAutocompleteResult_Status0Builder + implements + Builder, + CoreAutocompleteResult_Status0InterfaceBuilder { + _$CoreAutocompleteResult_Status0? _$v; + + String? _status; + String? get status => _$this._status; + set status(covariant String? status) => _$this._status = status; + + String? _message; + String? get message => _$this._message; + set message(covariant String? message) => _$this._message = message; + + String? _icon; + String? get icon => _$this._icon; + set icon(covariant String? icon) => _$this._icon = icon; + + int? _clearAt; + int? get clearAt => _$this._clearAt; + set clearAt(covariant int? clearAt) => _$this._clearAt = clearAt; + + CoreAutocompleteResult_Status0Builder(); + + CoreAutocompleteResult_Status0Builder get _$this { + final $v = _$v; + if ($v != null) { + _status = $v.status; + _message = $v.message; + _icon = $v.icon; + _clearAt = $v.clearAt; + _$v = null; + } + return this; + } + + @override + void replace(covariant CoreAutocompleteResult_Status0 other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$CoreAutocompleteResult_Status0; + } + + @override + void update(void Function(CoreAutocompleteResult_Status0Builder)? updates) { + if (updates != null) updates(this); + } + + @override + CoreAutocompleteResult_Status0 build() => _build(); + + _$CoreAutocompleteResult_Status0 _build() { + final _$result = _$v ?? + _$CoreAutocompleteResult_Status0._( + status: BuiltValueNullFieldError.checkNotNull(status, r'CoreAutocompleteResult_Status0', 'status'), + message: message, + icon: icon, + clearAt: clearAt); + replace(_$result); + return _$result; + } +} + +class _$CoreAutocompleteResult_Status extends CoreAutocompleteResult_Status { + @override + final JsonObject data; + @override + final CoreAutocompleteResult_Status0? autocompleteResultStatus0; + @override + final String? string; + + factory _$CoreAutocompleteResult_Status([void Function(CoreAutocompleteResult_StatusBuilder)? updates]) => + (CoreAutocompleteResult_StatusBuilder()..update(updates))._build(); + + _$CoreAutocompleteResult_Status._({required this.data, this.autocompleteResultStatus0, this.string}) : super._() { + BuiltValueNullFieldError.checkNotNull(data, r'CoreAutocompleteResult_Status', 'data'); + } + + @override + CoreAutocompleteResult_Status rebuild(void Function(CoreAutocompleteResult_StatusBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + CoreAutocompleteResult_StatusBuilder toBuilder() => CoreAutocompleteResult_StatusBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is CoreAutocompleteResult_Status && + data == other.data && + autocompleteResultStatus0 == other.autocompleteResultStatus0 && + string == other.string; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, data.hashCode); + _$hash = $jc(_$hash, autocompleteResultStatus0.hashCode); + _$hash = $jc(_$hash, string.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'CoreAutocompleteResult_Status') + ..add('data', data) + ..add('autocompleteResultStatus0', autocompleteResultStatus0) + ..add('string', string)) + .toString(); + } +} + +class CoreAutocompleteResult_StatusBuilder + implements Builder { + _$CoreAutocompleteResult_Status? _$v; + + JsonObject? _data; + JsonObject? get data => _$this._data; + set data(JsonObject? data) => _$this._data = data; + + CoreAutocompleteResult_Status0Builder? _autocompleteResultStatus0; + CoreAutocompleteResult_Status0Builder get autocompleteResultStatus0 => + _$this._autocompleteResultStatus0 ??= CoreAutocompleteResult_Status0Builder(); + set autocompleteResultStatus0(CoreAutocompleteResult_Status0Builder? autocompleteResultStatus0) => + _$this._autocompleteResultStatus0 = autocompleteResultStatus0; + + String? _string; + String? get string => _$this._string; + set string(String? string) => _$this._string = string; + + CoreAutocompleteResult_StatusBuilder(); + + CoreAutocompleteResult_StatusBuilder get _$this { + final $v = _$v; + if ($v != null) { + _data = $v.data; + _autocompleteResultStatus0 = $v.autocompleteResultStatus0?.toBuilder(); + _string = $v.string; + _$v = null; + } + return this; + } + + @override + void replace(CoreAutocompleteResult_Status other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$CoreAutocompleteResult_Status; + } + + @override + void update(void Function(CoreAutocompleteResult_StatusBuilder)? updates) { + if (updates != null) updates(this); + } + + @override + CoreAutocompleteResult_Status build() => _build(); + + _$CoreAutocompleteResult_Status _build() { + _$CoreAutocompleteResult_Status _$result; + try { + _$result = _$v ?? + _$CoreAutocompleteResult_Status._( + data: BuiltValueNullFieldError.checkNotNull(data, r'CoreAutocompleteResult_Status', 'data'), + autocompleteResultStatus0: _autocompleteResultStatus0?.build(), + string: string); + } catch (_) { + late String _$failedField; + try { + _$failedField = 'autocompleteResultStatus0'; + _autocompleteResultStatus0?.build(); + } catch (e) { + throw BuiltValueNestedFieldError(r'CoreAutocompleteResult_Status', _$failedField, e.toString()); + } + rethrow; + } + replace(_$result); + return _$result; + } +} + abstract mixin class CoreAutocompleteResultInterfaceBuilder { void replace(CoreAutocompleteResultInterface other); void update(void Function(CoreAutocompleteResultInterfaceBuilder) updates); @@ -9260,8 +9581,8 @@ abstract mixin class CoreAutocompleteResultInterfaceBuilder { String? get source; set source(String? source); - String? get status; - set status(String? status); + CoreAutocompleteResult_StatusBuilder get status; + set status(CoreAutocompleteResult_StatusBuilder? status); String? get subline; set subline(String? subline); @@ -9280,7 +9601,7 @@ class _$CoreAutocompleteResult extends CoreAutocompleteResult { @override final String source; @override - final String status; + final CoreAutocompleteResult_Status status; @override final String subline; @override @@ -9376,9 +9697,9 @@ class CoreAutocompleteResultBuilder String? get source => _$this._source; set source(covariant String? source) => _$this._source = source; - String? _status; - String? get status => _$this._status; - set status(covariant String? status) => _$this._status = status; + CoreAutocompleteResult_StatusBuilder? _status; + CoreAutocompleteResult_StatusBuilder get status => _$this._status ??= CoreAutocompleteResult_StatusBuilder(); + set status(covariant CoreAutocompleteResult_StatusBuilder? status) => _$this._status = status; String? _subline; String? get subline => _$this._subline; @@ -9398,7 +9719,7 @@ class CoreAutocompleteResultBuilder _label = $v.label; _icon = $v.icon; _source = $v.source; - _status = $v.status; + _status = $v.status.toBuilder(); _subline = $v.subline; _shareWithDisplayNameUnique = $v.shareWithDisplayNameUnique; _$v = null; @@ -9421,16 +9742,28 @@ class CoreAutocompleteResultBuilder CoreAutocompleteResult build() => _build(); _$CoreAutocompleteResult _build() { - final _$result = _$v ?? - _$CoreAutocompleteResult._( - id: BuiltValueNullFieldError.checkNotNull(id, r'CoreAutocompleteResult', 'id'), - label: BuiltValueNullFieldError.checkNotNull(label, r'CoreAutocompleteResult', 'label'), - icon: BuiltValueNullFieldError.checkNotNull(icon, r'CoreAutocompleteResult', 'icon'), - source: BuiltValueNullFieldError.checkNotNull(source, r'CoreAutocompleteResult', 'source'), - status: BuiltValueNullFieldError.checkNotNull(status, r'CoreAutocompleteResult', 'status'), - subline: BuiltValueNullFieldError.checkNotNull(subline, r'CoreAutocompleteResult', 'subline'), - shareWithDisplayNameUnique: BuiltValueNullFieldError.checkNotNull( - shareWithDisplayNameUnique, r'CoreAutocompleteResult', 'shareWithDisplayNameUnique')); + _$CoreAutocompleteResult _$result; + try { + _$result = _$v ?? + _$CoreAutocompleteResult._( + id: BuiltValueNullFieldError.checkNotNull(id, r'CoreAutocompleteResult', 'id'), + label: BuiltValueNullFieldError.checkNotNull(label, r'CoreAutocompleteResult', 'label'), + icon: BuiltValueNullFieldError.checkNotNull(icon, r'CoreAutocompleteResult', 'icon'), + source: BuiltValueNullFieldError.checkNotNull(source, r'CoreAutocompleteResult', 'source'), + status: status.build(), + subline: BuiltValueNullFieldError.checkNotNull(subline, r'CoreAutocompleteResult', 'subline'), + shareWithDisplayNameUnique: BuiltValueNullFieldError.checkNotNull( + shareWithDisplayNameUnique, r'CoreAutocompleteResult', 'shareWithDisplayNameUnique')); + } catch (_) { + late String _$failedField; + try { + _$failedField = 'status'; + status.build(); + } catch (e) { + throw BuiltValueNestedFieldError(r'CoreAutocompleteResult', _$failedField, e.toString()); + } + rethrow; + } replace(_$result); return _$result; } diff --git a/packages/nextcloud/lib/src/api/core.openapi.json b/packages/nextcloud/lib/src/api/core.openapi.json index f29b2179..3a3528d5 100644 --- a/packages/nextcloud/lib/src/api/core.openapi.json +++ b/packages/nextcloud/lib/src/api/core.openapi.json @@ -46,7 +46,38 @@ "type": "string" }, "status": { - "type": "string" + "oneOf": [ + { + "type": "object", + "required": [ + "status", + "message", + "icon", + "clearAt" + ], + "properties": { + "status": { + "type": "string" + }, + "message": { + "type": "string", + "nullable": true + }, + "icon": { + "type": "string", + "nullable": true + }, + "clearAt": { + "type": "integer", + "format": "int64", + "nullable": true + } + } + }, + { + "type": "string" + } + ] }, "subline": { "type": "string" diff --git a/packages/nextcloud/test/core_test.dart b/packages/nextcloud/test/core_test.dart index 561fc1b5..38fedb7b 100644 --- a/packages/nextcloud/test/core_test.dart +++ b/packages/nextcloud/test/core_test.dart @@ -87,48 +87,24 @@ void main() { expect(response.body.ocs.data[5].id, 'news'); }); - test( - 'Autocomplete', - () async { - final response = await client.core.autoComplete.$get( - search: '', - itemType: 'call', - itemId: 'new', - shareTypes: [ - ShareType.user.index, - ShareType.group.index, - ], - ); - expect(response.statusCode, 200); - expect(() => response.headers, isA()); - expect(response.body.ocs.data, hasLength(3)); - - expect(response.body.ocs.data[0].id, 'admin'); - expect(response.body.ocs.data[0].label, 'admin'); - expect(response.body.ocs.data[0].icon, 'icon-user'); - expect(response.body.ocs.data[0].source, 'users'); - expect(response.body.ocs.data[0].status, isEmpty); - expect(response.body.ocs.data[0].subline, ''); - expect(response.body.ocs.data[0].shareWithDisplayNameUnique, 'admin@example.com'); - - expect(response.body.ocs.data[1].id, 'user2'); - expect(response.body.ocs.data[1].label, 'User Two'); - expect(response.body.ocs.data[1].icon, 'icon-user'); - expect(response.body.ocs.data[1].source, 'users'); - expect(response.body.ocs.data[1].status, isEmpty); - expect(response.body.ocs.data[1].subline, ''); - expect(response.body.ocs.data[1].shareWithDisplayNameUnique, 'user2'); - - expect(response.body.ocs.data[2].id, 'admin'); - expect(response.body.ocs.data[2].label, 'admin'); - expect(response.body.ocs.data[2].icon, ''); - expect(response.body.ocs.data[2].source, 'groups'); - expect(response.body.ocs.data[2].status, isEmpty); - expect(response.body.ocs.data[2].subline, ''); - expect(response.body.ocs.data[2].shareWithDisplayNameUnique, ''); - }, - skip: true, // TODO: This test only works on 28+ due to a bug fix with the status - ); + test('Autocomplete', () async { + final response = await client.core.autoComplete.$get( + search: '', + itemType: 'call', + itemId: 'new', + shareTypes: [ShareType.group.index], + ); + expect(response.body.ocs.data, hasLength(1)); + + expect(response.body.ocs.data[0].id, 'admin'); + expect(response.body.ocs.data[0].label, 'admin'); + expect(response.body.ocs.data[0].icon, ''); + expect(response.body.ocs.data[0].source, 'groups'); + expect(response.body.ocs.data[0].status.autocompleteResultStatus0, isNull); + expect(response.body.ocs.data[0].status.string, isEmpty); + expect(response.body.ocs.data[0].subline, ''); + expect(response.body.ocs.data[0].shareWithDisplayNameUnique, ''); + }); test('Get preview', () async { final response = await client.core.preview.getPreview(file: 'Nextcloud.png');