Browse Source

feat(dynamite,nextcloud): use serializer for serializing base types

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/846/head
Nikolas Rimikis 1 year ago
parent
commit
4cd65a0d01
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 42
      packages/dynamite/dynamite/lib/src/models/type_result/base.dart
  2. 2
      packages/dynamite/dynamite/lib/src/models/type_result/type_result.dart
  3. 29
      packages/nextcloud/lib/src/api/core.openapi.dart
  4. 12
      packages/nextcloud/lib/src/api/files_sharing.openapi.dart
  5. 14
      packages/nextcloud/lib/src/api/provisioning_api.openapi.dart
  6. 4
      packages/nextcloud/lib/src/api/user_status.openapi.dart

42
packages/dynamite/dynamite/lib/src/models/type_result/base.dart

@ -21,37 +21,29 @@ class TypeResultBase extends TypeResult {
final String object, {
final bool onlyChildren = false,
final String? mimeType,
}) =>
name == 'String' ? object : '$object.toString()';
@override
String deserialize(final String object, {final bool toBuilder = false}) => '($object as $nullableName)';
@override
String decode(final String object) {
switch (name) {
case 'String':
return '($object as String)';
case 'int':
return 'int.parse($object as String)';
case 'bool':
return "($object as String == 'true')";
case 'JsonObject':
return 'JsonObject($object)';
}) {
switch (mimeType) {
case null:
case 'application/json':
case 'application/x-www-form-urlencoded':
if (className == 'String') {
return object;
} else {
return '$object.toString()';
}
case 'application/octet-stream':
return 'utf8.encode($object) as Uint8List';
default:
throw Exception('Can not decode "$name" from String');
throw Exception('Can not encode mime type "$mimeType"');
}
}
@override
TypeResultBase get dartType {
final String dartName;
switch (name) {
case 'JsonObject':
dartName = 'dynamic';
default:
dartName = name;
}
final dartName = switch (name) {
'JsonObject' => 'dynamic',
_ => name,
};
return TypeResultBase(dartName, nullable: nullable);
}

2
packages/dynamite/dynamite/lib/src/models/type_result/type_result.dart

@ -8,7 +8,7 @@ part 'map.dart';
part 'object.dart';
@immutable
abstract class TypeResult {
sealed class TypeResult {
TypeResult(
this.className, {
this.generics = const [],

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

@ -1,5 +1,6 @@
// ignore_for_file: camel_case_types
// ignore_for_file: public_member_api_docs
import 'dart:convert';
import 'dart:typed_data';
import 'package:built_collection/built_collection.dart';
@ -2111,7 +2112,10 @@ class CoreWipeClient {
body,
);
if (response.statusCode == 200 || response.statusCode == 404) {
return JsonObject(await response.body);
return _jsonSerializers.deserialize(
json.decode(await response.body),
specifiedType: const FullType(JsonObject),
)! as JsonObject;
}
throw await CoreApiException.fromResponse(response); // coverage:ignore-line
}
@ -2630,7 +2634,8 @@ class _$CoreAvatarAvatarGetAvatarDarkHeadersSerializer
final value = iterator.current! as String;
switch (key) {
case 'x-nc-iscustomavatar':
result.xNcIscustomavatar = int.parse(value);
result.xNcIscustomavatar =
_jsonSerializers.deserialize(json.decode(value), specifiedType: const FullType(int))! as int;
}
}
@ -2703,7 +2708,8 @@ class _$CoreAvatarAvatarGetAvatarHeadersSerializer implements StructuredSerializ
final value = iterator.current! as String;
switch (key) {
case 'x-nc-iscustomavatar':
result.xNcIscustomavatar = int.parse(value);
result.xNcIscustomavatar =
_jsonSerializers.deserialize(json.decode(value), specifiedType: const FullType(int))! as int;
}
}
@ -3587,10 +3593,10 @@ class _$CoreNavigationEntry_OrderSerializer implements PrimitiveSerializer<CoreN
}) {
final result = CoreNavigationEntry_OrderBuilder()..data = JsonObject(data);
try {
result._$int = data as int?;
result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {}
try {
result._string = data as String?;
result._string = _jsonSerializers.deserialize(data, specifiedType: const FullType(String))! as String;
} catch (_) {}
assert([result._$int, result._string].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}');
return result.build();
@ -3837,7 +3843,10 @@ class _$CoreOcmOcmDiscoveryHeadersSerializer implements StructuredSerializer<Cor
final value = iterator.current! as String;
switch (key) {
case 'x-nextcloud-ocm-providers':
result.xNextcloudOcmProviders = (value == 'true');
result.xNextcloudOcmProviders = _jsonSerializers.deserialize(
json.decode(value),
specifiedType: const FullType(bool),
)! as bool;
}
}
@ -7473,10 +7482,10 @@ class _$CoreUnifiedSearchSearchCursorSerializer implements PrimitiveSerializer<C
}) {
final result = CoreUnifiedSearchSearchCursorBuilder()..data = JsonObject(data);
try {
result._$int = data as int?;
result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {}
try {
result._string = data as String?;
result._string = _jsonSerializers.deserialize(data, specifiedType: const FullType(String))! as String;
} catch (_) {}
assert([result._$int, result._string].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}');
return result.build();
@ -7569,10 +7578,10 @@ class _$CoreUnifiedSearchResult_CursorSerializer implements PrimitiveSerializer<
}) {
final result = CoreUnifiedSearchResult_CursorBuilder()..data = JsonObject(data);
try {
result._$int = data as int?;
result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {}
try {
result._string = data as String?;
result._string = _jsonSerializers.deserialize(data, specifiedType: const FullType(String))! as String;
} catch (_) {}
assert([result._$int, result._string].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}');
return result.build();

12
packages/nextcloud/lib/src/api/files_sharing.openapi.dart

@ -1876,10 +1876,10 @@ class _$FilesSharingShareInfo_SizeSerializer implements PrimitiveSerializer<File
}) {
final result = FilesSharingShareInfo_SizeBuilder()..data = JsonObject(data);
try {
result._$int = data as int?;
result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {}
try {
result._$num = data as num?;
result._$num = _jsonSerializers.deserialize(data, specifiedType: const FullType(num))! as num;
} catch (_) {}
assert([result._$int, result._$num].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}');
return result.build();
@ -1970,10 +1970,10 @@ class _$FilesSharingShare_ItemSizeSerializer implements PrimitiveSerializer<File
}) {
final result = FilesSharingShare_ItemSizeBuilder()..data = JsonObject(data);
try {
result._$num = data as num?;
result._$num = _jsonSerializers.deserialize(data, specifiedType: const FullType(num))! as num;
} catch (_) {}
try {
result._$int = data as int?;
result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {}
assert([result._$num, result._$int].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}');
return result.build();
@ -2739,7 +2739,7 @@ class _$FilesSharingShareesapiSearchShareTypeSerializer
}) {
final result = FilesSharingShareesapiSearchShareTypeBuilder()..data = JsonObject(data);
try {
result._$int = data as int?;
result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {}
try {
result._builtListInt = (_jsonSerializers.deserialize(
@ -3540,7 +3540,7 @@ class _$FilesSharingShareesapiFindRecommendedShareTypeSerializer
}) {
final result = FilesSharingShareesapiFindRecommendedShareTypeBuilder()..data = JsonObject(data);
try {
result._$int = data as int?;
result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {}
try {
result._builtListInt = (_jsonSerializers.deserialize(

14
packages/nextcloud/lib/src/api/provisioning_api.openapi.dart

@ -3190,10 +3190,10 @@ class _$ProvisioningApiGroupDetails_UsercountSerializer
}) {
final result = ProvisioningApiGroupDetails_UsercountBuilder()..data = JsonObject(data);
try {
result._$bool = data as bool?;
result._$bool = _jsonSerializers.deserialize(data, specifiedType: const FullType(bool))! as bool;
} catch (_) {}
try {
result._$int = data as int?;
result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {}
assert([result._$bool, result._$int].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}');
return result.build();
@ -3250,10 +3250,10 @@ class _$ProvisioningApiGroupDetails_DisabledSerializer
}) {
final result = ProvisioningApiGroupDetails_DisabledBuilder()..data = JsonObject(data);
try {
result._$bool = data as bool?;
result._$bool = _jsonSerializers.deserialize(data, specifiedType: const FullType(bool))! as bool;
} catch (_) {}
try {
result._$int = data as int?;
result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {}
assert([result._$bool, result._$int].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}');
return result.build();
@ -3600,13 +3600,13 @@ class _$ProvisioningApiUserDetailsQuota_QuotaSerializer
}) {
final result = ProvisioningApiUserDetailsQuota_QuotaBuilder()..data = JsonObject(data);
try {
result._$num = data as num?;
result._$num = _jsonSerializers.deserialize(data, specifiedType: const FullType(num))! as num;
} catch (_) {}
try {
result._$int = data as int?;
result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {}
try {
result._string = data as String?;
result._string = _jsonSerializers.deserialize(data, specifiedType: const FullType(String))! as String;
} catch (_) {}
assert(
[result._$num, result._$int, result._string].where((final x) => x != null).isNotEmpty,

4
packages/nextcloud/lib/src/api/user_status.openapi.dart

@ -766,7 +766,7 @@ class _$UserStatusClearAt_TimeSerializer implements PrimitiveSerializer<UserStat
}) {
final result = UserStatusClearAt_TimeBuilder()..data = JsonObject(data);
try {
result._$int = data as int?;
result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {}
try {
result._clearAtTimeType = _jsonSerializers.deserialize(
@ -1471,7 +1471,7 @@ class _$UserStatusUserStatusRevertStatusResponseApplicationJson_Ocs_DataSerializ
.toBuilder();
} catch (_) {}
try {
result._jsonObject = data as JsonObject?;
result._jsonObject = _jsonSerializers.deserialize(data, specifiedType: const FullType(JsonObject))! as JsonObject;
} catch (_) {}
assert(
[result._private, result._jsonObject].where((final x) => x != null).isNotEmpty,

Loading…
Cancel
Save