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. 34
      packages/nextcloud/lib/src/nextcloud.openapi.json
  5. 8
      packages/nextcloud/test/notifications_test.dart
  6. 22
      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'); result = TypeResolveResult('dynamic');
break; break;
} }
if (schema.properties!.isEmpty) {
result = TypeResolveResult(
'Map<String, dynamic>',
isBaseType: false,
isMap: true,
);
break;
}
if (!resolvedTypes.contains(identifier)) { if (!resolvedTypes.contains(identifier)) {
resolvedTypes.add(identifier); resolvedTypes.add(identifier);
@ -1218,6 +1226,7 @@ class TypeResolveResult {
this.typeName, { this.typeName, {
this.isBaseType = true, this.isBaseType = true,
this.isList = false, this.isList = false,
this.isMap = false,
this.isEnum = false, this.isEnum = false,
this.subType, this.subType,
}); });
@ -1225,6 +1234,7 @@ class TypeResolveResult {
final String typeName; final String typeName;
final bool isBaseType; final bool isBaseType;
final bool isList; final bool isList;
final bool isMap;
final bool isEnum; final bool isEnum;
final TypeResolveResult? subType; final TypeResolveResult? subType;
} }
@ -1232,6 +1242,8 @@ class TypeResolveResult {
String _serializeFunctionForType(final String object, final TypeResolveResult result) { String _serializeFunctionForType(final String object, final TypeResolveResult result) {
if (result.isList) { if (result.isList) {
return '($object as ${result.typeName}).map((final e) => ${_serializeFunctionForType('e', result.subType!)}).toList()'; 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) { } else if (result.isBaseType) {
return '$object.toString()'; return '$object.toString()';
} else if (result.isEnum) { } else if (result.isEnum) {
@ -1247,6 +1259,8 @@ String _deserializeFunctionForType(final String object, final TypeResolveResult
return '$object as List'; return '$object as List';
} }
return '($object as List).map<${result.subType!.typeName}>((final e) => ${_deserializeFunctionForType('e', result.subType!)}).toList()'; 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) { } else if (result.isBaseType) {
return '$object as ${result.typeName}'; return '$object as ${result.typeName}';
} else if (result.isEnum) { } 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() @JsonSerializable()
class NotificationsNotificationAction { class NotificationsNotificationAction {
NotificationsNotificationAction({ NotificationsNotificationAction({
@ -2531,11 +2583,11 @@ class NotificationsNotification {
final String? subjectRich; final String? subjectRich;
final List<String>? subjectRichParameters; final NotificationsNotificationSubjectRichParameters? subjectRichParameters;
final String? messageRich; final String? messageRich;
final List<String>? messageRichParameters; final NotificationsNotificationMessageRichParameters? messageRichParameters;
final String? icon; final String? icon;
@ -3317,7 +3369,6 @@ class UserStatusFindStatusOcsData {
UserStatusFindStatusOcsData( UserStatusFindStatusOcsData(
this._data, { this._data, {
this.userStatusPublicUserStatus, this.userStatusPublicUserStatus,
this.list,
}); });
factory UserStatusFindStatusOcsData.fromJson(dynamic data) { factory UserStatusFindStatusOcsData.fromJson(dynamic data) {
@ -3325,15 +3376,9 @@ class UserStatusFindStatusOcsData {
try { try {
userStatusPublicUserStatus = UserStatusPublicUserStatus.fromJson(data as Map<String, dynamic>); userStatusPublicUserStatus = UserStatusPublicUserStatus.fromJson(data as Map<String, dynamic>);
} catch (_) {} } catch (_) {}
List? list;
try {
list = data as List;
} catch (_) {}
assert([userStatusPublicUserStatus, list].where((final x) => x != null).length == 1, 'Need oneOf');
return UserStatusFindStatusOcsData( return UserStatusFindStatusOcsData(
data, data,
userStatusPublicUserStatus: userStatusPublicUserStatus, userStatusPublicUserStatus: userStatusPublicUserStatus,
list: list,
); );
} }
@ -3341,9 +3386,6 @@ class UserStatusFindStatusOcsData {
final UserStatusPublicUserStatus? userStatusPublicUserStatus; final UserStatusPublicUserStatus? userStatusPublicUserStatus;
/// Only happens when the user has never set a status
final List? list;
// coverage:ignore-start // coverage:ignore-start
dynamic toJson() => _data; dynamic toJson() => _data;
// coverage:ignore-end // coverage:ignore-end
@ -3420,7 +3462,6 @@ class UserStatusGetUserStatusOcsData {
UserStatusGetUserStatusOcsData( UserStatusGetUserStatusOcsData(
this._data, { this._data, {
this.userStatus, this.userStatus,
this.list,
}); });
factory UserStatusGetUserStatusOcsData.fromJson(dynamic data) { factory UserStatusGetUserStatusOcsData.fromJson(dynamic data) {
@ -3428,15 +3469,9 @@ class UserStatusGetUserStatusOcsData {
try { try {
userStatus = UserStatus.fromJson(data as Map<String, dynamic>); userStatus = UserStatus.fromJson(data as Map<String, dynamic>);
} catch (_) {} } catch (_) {}
List? list;
try {
list = data as List;
} catch (_) {}
assert([userStatus, list].where((final x) => x != null).length == 1, 'Need oneOf');
return UserStatusGetUserStatusOcsData( return UserStatusGetUserStatusOcsData(
data, data,
userStatus: userStatus, userStatus: userStatus,
list: list,
); );
} }
@ -3444,9 +3479,6 @@ class UserStatusGetUserStatusOcsData {
final UserStatus? userStatus; final UserStatus? userStatus;
/// Only happens when the user has never set a status
final List? list;
// coverage:ignore-start // coverage:ignore-start
dynamic toJson() => _data; dynamic toJson() => _data;
// coverage:ignore-end // 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?, message: json['message'] as String?,
link: json['link'] as String?, link: json['link'] as String?,
subjectRich: json['subjectRich'] 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?, 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?, icon: json['icon'] as String?,
actions: (json['actions'] as List<dynamic>?) actions: (json['actions'] as List<dynamic>?)
?.map((e) => NotificationsNotificationAction.fromJson(e as Map<String, dynamic>)) ?.map((e) => NotificationsNotificationAction.fromJson(e as Map<String, dynamic>))
@ -1254,9 +1258,9 @@ Map<String, dynamic> _$NotificationsNotificationToJson(NotificationsNotification
'message': instance.message, 'message': instance.message,
'link': instance.link, 'link': instance.link,
'subjectRich': instance.subjectRich, 'subjectRich': instance.subjectRich,
'subjectRichParameters': instance.subjectRichParameters, 'subjectRichParameters': instance.subjectRichParameters?.toJson(),
'messageRich': instance.messageRich, 'messageRich': instance.messageRich,
'messageRichParameters': instance.messageRichParameters, 'messageRichParameters': instance.messageRichParameters?.toJson(),
'icon': instance.icon, 'icon': instance.icon,
'actions': instance.actions?.map((e) => e.toJson()).toList(), 'actions': instance.actions?.map((e) => e.toJson()).toList(),
}; };

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

@ -1057,21 +1057,23 @@
"type": "string" "type": "string"
}, },
"subjectRichParameters": { "subjectRichParameters": {
"type": "array", "anyOf": [
"items": { {
"description": "TODO", "type": "object",
"type": "string" "properties": {}
} }
]
}, },
"messageRich": { "messageRich": {
"type": "string" "type": "string"
}, },
"messageRichParameters": { "messageRichParameters": {
"type": "array", "anyOf": [
"items": { {
"description": "TODO", "type": "object",
"type": "string" "properties": {}
} }
]
}, },
"icon": { "icon": {
"type": "string" "type": "string"
@ -1478,13 +1480,9 @@
"$ref": "#/components/schemas/OCSMeta" "$ref": "#/components/schemas/OCSMeta"
}, },
"data": { "data": {
"oneOf": [ "anyOf": [
{ {
"$ref": "#/components/schemas/UserStatus" "$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" "$ref": "#/components/schemas/OCSMeta"
}, },
"data": { "data": {
"oneOf": [ "anyOf": [
{ {
"$ref": "#/components/schemas/UserStatusPublicUserStatus" "$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].message, '456');
expect(response.ocs!.data![0].link, ''); expect(response.ocs!.data![0].link, '');
expect(response.ocs!.data![0].subjectRich, ''); 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].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].icon, isNotEmpty);
expect(response.ocs!.data![0].actions, hasLength(0)); 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!.message, '456');
expect(response.ocs!.data!.link, ''); expect(response.ocs!.data!.link, '');
expect(response.ocs!.data!.subjectRich, ''); 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!.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!.icon, isNotEmpty);
expect(response.ocs!.data!.actions, hasLength(0)); expect(response.ocs!.data!.actions, hasLength(0));
}); });

22
specs/notifications.json

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

12
specs/user_status.json

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

Loading…
Cancel
Save