Browse Source

feat(nextcloud): Use generated OpenAPI notifications spec

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/710/head
jld3103 1 year ago
parent
commit
e8631bfad5
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 2
      external/nextcloud-notifications
  2. 6
      packages/nextcloud/lib/src/api/core.openapi.dart
  3. 60
      packages/nextcloud/lib/src/api/core.openapi.g.dart
  4. 6
      packages/nextcloud/lib/src/api/core.openapi.json
  5. 1525
      packages/nextcloud/lib/src/api/notifications.openapi.dart
  6. 4985
      packages/nextcloud/lib/src/api/notifications.openapi.g.dart
  7. 1460
      packages/nextcloud/lib/src/api/notifications.openapi.json
  8. 27
      packages/nextcloud/test/notifications_test.dart
  9. 22
      tool/generate-specs.sh

2
external/nextcloud-notifications vendored

@ -1 +1 @@
Subproject commit 09d3a1c9abcdd1c0ec4d8531907b56ac9f368666
Subproject commit 9e4bfdcf04d3a17402f4b22166e1afd4fc7ff833

6
packages/nextcloud/lib/src/api/core.openapi.dart

@ -4664,10 +4664,10 @@ abstract class CoreNotesCapabilities
@BuiltValue(instantiable: false)
abstract interface class CoreNotificationsCapabilities_NotificationsInterface {
@BuiltValueField(wireName: 'ocs-endpoints')
BuiltList<String>? get ocsEndpoints;
BuiltList<String>? get push;
BuiltList<String> get ocsEndpoints;
BuiltList<String> get push;
@BuiltValueField(wireName: 'admin-notifications')
BuiltList<String>? get adminNotifications;
BuiltList<String> get adminNotifications;
CoreNotificationsCapabilities_NotificationsInterface rebuild(
final void Function(CoreNotificationsCapabilities_NotificationsInterfaceBuilder) updates,
);

60
packages/nextcloud/lib/src/api/core.openapi.g.dart

@ -4077,26 +4077,15 @@ class _$CoreNotificationsCapabilities_NotificationsSerializer
@override
Iterable<Object?> serialize(Serializers serializers, CoreNotificationsCapabilities_Notifications object,
{FullType specifiedType = FullType.unspecified}) {
final result = <Object?>[];
Object? value;
value = object.ocsEndpoints;
if (value != null) {
result
..add('ocs-endpoints')
..add(serializers.serialize(value, specifiedType: const FullType(BuiltList, [FullType(String)])));
}
value = object.push;
if (value != null) {
result
..add('push')
..add(serializers.serialize(value, specifiedType: const FullType(BuiltList, [FullType(String)])));
}
value = object.adminNotifications;
if (value != null) {
result
..add('admin-notifications')
..add(serializers.serialize(value, specifiedType: const FullType(BuiltList, [FullType(String)])));
}
final result = <Object?>[
'ocs-endpoints',
serializers.serialize(object.ocsEndpoints, specifiedType: const FullType(BuiltList, [FullType(String)])),
'push',
serializers.serialize(object.push, specifiedType: const FullType(BuiltList, [FullType(String)])),
'admin-notifications',
serializers.serialize(object.adminNotifications, specifiedType: const FullType(BuiltList, [FullType(String)])),
];
return result;
}
@ -17095,17 +17084,24 @@ abstract mixin class CoreNotificationsCapabilities_NotificationsInterfaceBuilder
class _$CoreNotificationsCapabilities_Notifications extends CoreNotificationsCapabilities_Notifications {
@override
final BuiltList<String>? ocsEndpoints;
final BuiltList<String> ocsEndpoints;
@override
final BuiltList<String>? push;
final BuiltList<String> push;
@override
final BuiltList<String>? adminNotifications;
final BuiltList<String> adminNotifications;
factory _$CoreNotificationsCapabilities_Notifications(
[void Function(CoreNotificationsCapabilities_NotificationsBuilder)? updates]) =>
(CoreNotificationsCapabilities_NotificationsBuilder()..update(updates))._build();
_$CoreNotificationsCapabilities_Notifications._({this.ocsEndpoints, this.push, this.adminNotifications}) : super._();
_$CoreNotificationsCapabilities_Notifications._(
{required this.ocsEndpoints, required this.push, required this.adminNotifications})
: super._() {
BuiltValueNullFieldError.checkNotNull(ocsEndpoints, r'CoreNotificationsCapabilities_Notifications', 'ocsEndpoints');
BuiltValueNullFieldError.checkNotNull(push, r'CoreNotificationsCapabilities_Notifications', 'push');
BuiltValueNullFieldError.checkNotNull(
adminNotifications, r'CoreNotificationsCapabilities_Notifications', 'adminNotifications');
}
@override
CoreNotificationsCapabilities_Notifications rebuild(
@ -17169,9 +17165,9 @@ class CoreNotificationsCapabilities_NotificationsBuilder
CoreNotificationsCapabilities_NotificationsBuilder get _$this {
final $v = _$v;
if ($v != null) {
_ocsEndpoints = $v.ocsEndpoints?.toBuilder();
_push = $v.push?.toBuilder();
_adminNotifications = $v.adminNotifications?.toBuilder();
_ocsEndpoints = $v.ocsEndpoints.toBuilder();
_push = $v.push.toBuilder();
_adminNotifications = $v.adminNotifications.toBuilder();
_$v = null;
}
return this;
@ -17196,18 +17192,16 @@ class CoreNotificationsCapabilities_NotificationsBuilder
try {
_$result = _$v ??
_$CoreNotificationsCapabilities_Notifications._(
ocsEndpoints: _ocsEndpoints?.build(),
push: _push?.build(),
adminNotifications: _adminNotifications?.build());
ocsEndpoints: ocsEndpoints.build(), push: push.build(), adminNotifications: adminNotifications.build());
} catch (_) {
late String _$failedField;
try {
_$failedField = 'ocsEndpoints';
_ocsEndpoints?.build();
ocsEndpoints.build();
_$failedField = 'push';
_push?.build();
push.build();
_$failedField = 'adminNotifications';
_adminNotifications?.build();
adminNotifications.build();
} catch (e) {
throw BuiltValueNestedFieldError(r'CoreNotificationsCapabilities_Notifications', _$failedField, e.toString());
}

6
packages/nextcloud/lib/src/api/core.openapi.json

@ -898,7 +898,11 @@
"properties": {
"notifications": {
"type": "object",
"additionalProperties": true,
"required": [
"ocs-endpoints",
"push",
"admin-notifications"
],
"properties": {
"ocs-endpoints": {
"type": "array",

1525
packages/nextcloud/lib/src/api/notifications.openapi.dart

File diff suppressed because it is too large Load Diff

4985
packages/nextcloud/lib/src/api/notifications.openapi.g.dart

File diff suppressed because it is too large Load Diff

1460
packages/nextcloud/lib/src/api/notifications.openapi.json

File diff suppressed because it is too large Load Diff

27
packages/nextcloud/test/notifications_test.dart

@ -22,7 +22,7 @@ void main() {
tearDown(() => container.destroy());
Future sendTestNotification() async {
await client.notifications.sendAdminNotification(
await client.notifications.api.generateNotification(
userId: 'admin',
shortMessage: '123',
longMessage: '456',
@ -37,7 +37,7 @@ void main() {
await sendTestNotification();
final startTime = DateTime.now().toUtc();
final response = await client.notifications.listNotifications();
final response = (await client.notifications.endpoint.listNotifications()).data;
expect(response.ocs.data, hasLength(2));
expect(response.ocs.data[0].notificationId, 2);
expect(response.ocs.data[0].app, 'admin_notifications');
@ -49,9 +49,9 @@ void main() {
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?.asList, isEmpty);
expect(response.ocs.data[0].subjectRichParameters, isEmpty);
expect(response.ocs.data[0].messageRich, '');
expect(response.ocs.data[0].messageRichParameters?.asList, isEmpty);
expect(response.ocs.data[0].messageRichParameters, isEmpty);
expect(response.ocs.data[0].icon, isNotEmpty);
expect(response.ocs.data[0].actions, hasLength(0));
});
@ -60,7 +60,7 @@ void main() {
await sendTestNotification();
final startTime = DateTime.now().toUtc();
final response = await client.notifications.getNotification(id: 2);
final response = await client.notifications.endpoint.getNotification(id: 2);
expect(response.ocs.data.notificationId, 2);
expect(response.ocs.data.app, 'admin_notifications');
expect(response.ocs.data.user, 'admin');
@ -71,27 +71,27 @@ void main() {
expect(response.ocs.data.message, '456');
expect(response.ocs.data.link, '');
expect(response.ocs.data.subjectRich, '');
expect(response.ocs.data.subjectRichParameters?.asList, isEmpty);
expect(response.ocs.data.subjectRichParameters, isEmpty);
expect(response.ocs.data.messageRich, '');
expect(response.ocs.data.messageRichParameters?.asList, isEmpty);
expect(response.ocs.data.messageRichParameters, isEmpty);
expect(response.ocs.data.icon, isNotEmpty);
expect(response.ocs.data.actions, hasLength(0));
});
test('Delete notification', () async {
await sendTestNotification();
await client.notifications.deleteNotification(id: 2);
await client.notifications.endpoint.deleteNotification(id: 2);
final response = await client.notifications.listNotifications();
final response = (await client.notifications.endpoint.listNotifications()).data;
expect(response.ocs.data, hasLength(1));
});
test('Delete all notifications', () async {
await sendTestNotification();
await sendTestNotification();
await client.notifications.deleteAllNotifications();
await client.notifications.endpoint.deleteAllNotifications();
final response = await client.notifications.listNotifications();
final response = (await client.notifications.endpoint.listNotifications()).data;
expect(response.ocs.data, hasLength(0));
});
});
@ -121,7 +121,7 @@ void main() {
const pushToken = '789';
final keypair = generateKeypair();
final subscription = (await client.notifications.registerDevice(
final subscription = (await client.notifications.push.registerDevice(
pushTokenHash: generatePushTokenHash(pushToken),
devicePublicKey: keypair.publicKey.toFormattedPEM(),
proxyServer: 'https://example.com/',
@ -132,9 +132,8 @@ void main() {
RSAPublicKey.fromPEM(subscription.publicKey);
expect(subscription.deviceIdentifier, isNotEmpty);
expect(subscription.signature, isNotEmpty);
expect(subscription.message, isNull);
await client.notifications.removeDevice();
await client.notifications.push.removeDevice();
});
},
retry: retryCount,

22
tool/generate-specs.sh

@ -5,12 +5,20 @@ cd "$(dirname "$0")/.."
rm -rf /tmp/nextcloud-neon
mkdir -p /tmp/nextcloud-neon
(
cd external/nextcloud-server
function generate_spec() {
path="$1"
codename="$2"
composer exec generate-spec -- "$path" "../../packages/nextcloud/lib/src/api/$codename.openapi.json" --first-content-type --openapi-version 3.1.0
}
for dir in external/nextcloud-server external/nextcloud-notifications; do
(
cd "$dir"
composer update
composer install --no-dev
git checkout . # Remove changed files
)
)
done
for path in \
core \
@ -31,13 +39,17 @@ for path in \
apps/user_status \
apps/weather_status \
; do
codename="$(echo $path | sed "s/^apps\///")"
(
cd external/nextcloud-server
composer exec generate-spec -- "$path" "../../packages/nextcloud/lib/src/api/$codename.openapi.json" --first-content-type --openapi-version 3.1.0
generate_spec "$path" "$(basename $path)"
)
done
(
cd external/nextcloud-notifications
generate_spec "." "notifications"
)
(
cd external/nextcloud-server
composer exec merge-specs -- --core ../../packages/nextcloud/lib/src/api/core.openapi.json --merged /tmp/nextcloud-neon/merged.json ../../packages/nextcloud/lib/src/api/*.openapi.json --openapi-version 3.1.0

Loading…
Cancel
Save