Browse Source

Merge pull request #90 from jld3103/fix/empty-objects

Fix empty objects
pull/91/head
jld3103 2 years ago committed by GitHub
parent
commit
deeb6c6225
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      packages/dynamite/lib/src/openapi_builder.dart
  2. 76
      packages/nextcloud/lib/src/nextcloud.openapi.dart
  3. 12
      packages/nextcloud/lib/src/nextcloud.openapi.g.dart
  4. 30
      packages/nextcloud/lib/src/nextcloud.openapi.json
  5. 8
      packages/nextcloud/test/notifications_test.dart
  6. 18
      specs/notifications.json
  7. 12
      specs/user_status.json

14
packages/dynamite/lib/src/openapi_builder.dart

@ -403,6 +403,14 @@ class OpenAPIBuilder implements Builder {
result = TypeResolveResult('dynamic');
break;
}
if (schema.properties!.isEmpty) {
result = TypeResolveResult(
'Map<String, dynamic>',
isBaseType: false,
isMap: true,
);
break;
}
if (!resolvedTypes.contains(identifier)) {
resolvedTypes.add(identifier);
@ -1218,6 +1226,7 @@ class TypeResolveResult {
this.typeName, {
this.isBaseType = true,
this.isList = false,
this.isMap = false,
this.isEnum = false,
this.subType,
});
@ -1225,6 +1234,7 @@ class TypeResolveResult {
final String typeName;
final bool isBaseType;
final bool isList;
final bool isMap;
final bool isEnum;
final TypeResolveResult? subType;
}
@ -1232,6 +1242,8 @@ class TypeResolveResult {
String _serializeFunctionForType(final String object, final TypeResolveResult result) {
if (result.isList) {
return '($object as ${result.typeName}).map((final e) => ${_serializeFunctionForType('e', result.subType!)}).toList()';
} else if (result.isMap) {
return '($object as ${result.typeName})';
} else if (result.isBaseType) {
return '$object.toString()';
} else if (result.isEnum) {
@ -1247,6 +1259,8 @@ String _deserializeFunctionForType(final String object, final TypeResolveResult
return '$object as List';
}
return '($object as List).map<${result.subType!.typeName}>((final e) => ${_deserializeFunctionForType('e', result.subType!)}).toList()';
} else if (result.isMap) {
return '$object as Map<String, dynamic>';
} else if (result.isBaseType) {
return '$object as ${result.typeName}';
} else if (result.isEnum) {

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

@ -2461,6 +2461,58 @@ class NotesClient {
}
}
class NotificationsNotificationSubjectRichParameters {
NotificationsNotificationSubjectRichParameters(
this._data, {
this.mapStringDynamic,
});
factory NotificationsNotificationSubjectRichParameters.fromJson(dynamic data) {
Map<String, dynamic>? mapStringDynamic;
try {
mapStringDynamic = data as Map<String, dynamic>;
} catch (_) {}
return NotificationsNotificationSubjectRichParameters(
data,
mapStringDynamic: mapStringDynamic,
);
}
final dynamic _data;
final Map<String, dynamic>? mapStringDynamic;
// coverage:ignore-start
dynamic toJson() => _data;
// coverage:ignore-end
}
class NotificationsNotificationMessageRichParameters {
NotificationsNotificationMessageRichParameters(
this._data, {
this.mapStringDynamic,
});
factory NotificationsNotificationMessageRichParameters.fromJson(dynamic data) {
Map<String, dynamic>? mapStringDynamic;
try {
mapStringDynamic = data as Map<String, dynamic>;
} catch (_) {}
return NotificationsNotificationMessageRichParameters(
data,
mapStringDynamic: mapStringDynamic,
);
}
final dynamic _data;
final Map<String, dynamic>? mapStringDynamic;
// coverage:ignore-start
dynamic toJson() => _data;
// coverage:ignore-end
}
@JsonSerializable()
class NotificationsNotificationAction {
NotificationsNotificationAction({
@ -2531,11 +2583,11 @@ class NotificationsNotification {
final String? subjectRich;
final List<String>? subjectRichParameters;
final NotificationsNotificationSubjectRichParameters? subjectRichParameters;
final String? messageRich;
final List<String>? messageRichParameters;
final NotificationsNotificationMessageRichParameters? messageRichParameters;
final String? icon;
@ -3317,7 +3369,6 @@ class UserStatusFindStatusOcsData {
UserStatusFindStatusOcsData(
this._data, {
this.userStatusPublicUserStatus,
this.list,
});
factory UserStatusFindStatusOcsData.fromJson(dynamic data) {
@ -3325,15 +3376,9 @@ class UserStatusFindStatusOcsData {
try {
userStatusPublicUserStatus = UserStatusPublicUserStatus.fromJson(data as Map<String, dynamic>);
} 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,
);
}
@ -3341,9 +3386,6 @@ class UserStatusFindStatusOcsData {
final UserStatusPublicUserStatus? userStatusPublicUserStatus;
/// Only happens when the user has never set a status
final List? list;
// coverage:ignore-start
dynamic toJson() => _data;
// coverage:ignore-end
@ -3420,7 +3462,6 @@ class UserStatusGetUserStatusOcsData {
UserStatusGetUserStatusOcsData(
this._data, {
this.userStatus,
this.list,
});
factory UserStatusGetUserStatusOcsData.fromJson(dynamic data) {
@ -3428,15 +3469,9 @@ class UserStatusGetUserStatusOcsData {
try {
userStatus = UserStatus.fromJson(data as Map<String, dynamic>);
} catch (_) {}
List? list;
try {
list = data as List;
} catch (_) {}
assert([userStatus, list].where((final x) => x != null).length == 1, 'Need oneOf');
return UserStatusGetUserStatusOcsData(
data,
userStatus: userStatus,
list: list,
);
}
@ -3444,9 +3479,6 @@ class UserStatusGetUserStatusOcsData {
final UserStatus? userStatus;
/// Only happens when the user has never set a status
final List? list;
// coverage:ignore-start
dynamic toJson() => _data;
// coverage:ignore-end

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

@ -1234,9 +1234,13 @@ NotificationsNotification _$NotificationsNotificationFromJson(Map<String, dynami
message: json['message'] as String?,
link: json['link'] as String?,
subjectRich: json['subjectRich'] as String?,
subjectRichParameters: (json['subjectRichParameters'] as List<dynamic>?)?.map((e) => e as String).toList(),
subjectRichParameters: json['subjectRichParameters'] == null
? null
: NotificationsNotificationSubjectRichParameters.fromJson(json['subjectRichParameters']),
messageRich: json['messageRich'] as String?,
messageRichParameters: (json['messageRichParameters'] as List<dynamic>?)?.map((e) => e as String).toList(),
messageRichParameters: json['messageRichParameters'] == null
? null
: NotificationsNotificationMessageRichParameters.fromJson(json['messageRichParameters']),
icon: json['icon'] as String?,
actions: (json['actions'] as List<dynamic>?)
?.map((e) => NotificationsNotificationAction.fromJson(e as Map<String, dynamic>))
@ -1254,9 +1258,9 @@ Map<String, dynamic> _$NotificationsNotificationToJson(NotificationsNotification
'message': instance.message,
'link': instance.link,
'subjectRich': instance.subjectRich,
'subjectRichParameters': instance.subjectRichParameters,
'subjectRichParameters': instance.subjectRichParameters?.toJson(),
'messageRich': instance.messageRich,
'messageRichParameters': instance.messageRichParameters,
'messageRichParameters': instance.messageRichParameters?.toJson(),
'icon': instance.icon,
'actions': instance.actions?.map((e) => e.toJson()).toList(),
};

30
packages/nextcloud/lib/src/nextcloud.openapi.json

@ -1057,21 +1057,23 @@
"type": "string"
},
"subjectRichParameters": {
"type": "array",
"items": {
"description": "TODO",
"type": "string"
"anyOf": [
{
"type": "object",
"properties": {}
}
]
},
"messageRich": {
"type": "string"
},
"messageRichParameters": {
"type": "array",
"items": {
"description": "TODO",
"type": "string"
"anyOf": [
{
"type": "object",
"properties": {}
}
]
},
"icon": {
"type": "string"
@ -1478,13 +1480,9 @@
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"oneOf": [
"anyOf": [
{
"$ref": "#/components/schemas/UserStatus"
},
{
"type": "array",
"description": "Only happens when the user has never set a status"
}
]
}
@ -1521,13 +1519,9 @@
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"oneOf": [
"anyOf": [
{
"$ref": "#/components/schemas/UserStatusPublicUserStatus"
},
{
"type": "array",
"description": "Only happens when the user has never set a status"
}
]
}

8
packages/nextcloud/test/notifications_test.dart

@ -49,9 +49,9 @@ Future main() async {
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, hasLength(0));
expect(response.ocs!.data![0].subjectRichParameters!.mapStringDynamic, null);
expect(response.ocs!.data![0].messageRich, '');
expect(response.ocs!.data![0].messageRichParameters, hasLength(0));
expect(response.ocs!.data![0].messageRichParameters!.mapStringDynamic, null);
expect(response.ocs!.data![0].icon, isNotEmpty);
expect(response.ocs!.data![0].actions, hasLength(0));
});
@ -71,9 +71,9 @@ Future main() async {
expect(response.ocs!.data!.message, '456');
expect(response.ocs!.data!.link, '');
expect(response.ocs!.data!.subjectRich, '');
expect(response.ocs!.data!.subjectRichParameters, hasLength(0));
expect(response.ocs!.data!.subjectRichParameters!.mapStringDynamic, null);
expect(response.ocs!.data!.messageRich, '');
expect(response.ocs!.data!.messageRichParameters, hasLength(0));
expect(response.ocs!.data!.messageRichParameters!.mapStringDynamic, null);
expect(response.ocs!.data!.icon, isNotEmpty);
expect(response.ocs!.data!.actions, hasLength(0));
});

18
specs/notifications.json

@ -107,21 +107,23 @@
"type": "string"
},
"subjectRichParameters": {
"type": "array",
"items": {
"description": "TODO",
"type": "string"
"anyOf": [
{
"type": "object",
"properties": {}
}
]
},
"messageRich": {
"type": "string"
},
"messageRichParameters": {
"type": "array",
"items": {
"description": "TODO",
"type": "string"
"anyOf": [
{
"type": "object",
"properties": {}
}
]
},
"icon": {
"type": "string"

12
specs/user_status.json

@ -148,13 +148,9 @@
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"oneOf": [
"anyOf": [
{
"$ref": "#/components/schemas/UserStatus"
},
{
"type": "array",
"description": "Only happens when the user has never set a status"
}
]
}
@ -191,13 +187,9 @@
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"oneOf": [
"anyOf": [
{
"$ref": "#/components/schemas/UserStatusPublicUserStatus"
},
{
"type": "array",
"description": "Only happens when the user has never set a status"
}
]
}

Loading…
Cancel
Save