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 String object, {
final bool onlyChildren = false, final bool onlyChildren = false,
final String? mimeType, final String? mimeType,
}) => }) {
name == 'String' ? object : '$object.toString()'; switch (mimeType) {
case null:
@override case 'application/json':
String deserialize(final String object, {final bool toBuilder = false}) => '($object as $nullableName)'; case 'application/x-www-form-urlencoded':
if (className == 'String') {
@override return object;
String decode(final String object) { } else {
switch (name) { return '$object.toString()';
case 'String': }
return '($object as String)'; case 'application/octet-stream':
case 'int': return 'utf8.encode($object) as Uint8List';
return 'int.parse($object as String)';
case 'bool':
return "($object as String == 'true')";
case 'JsonObject':
return 'JsonObject($object)';
default: default:
throw Exception('Can not decode "$name" from String'); throw Exception('Can not encode mime type "$mimeType"');
} }
} }
@override @override
TypeResultBase get dartType { TypeResultBase get dartType {
final String dartName; final dartName = switch (name) {
switch (name) { 'JsonObject' => 'dynamic',
case 'JsonObject': _ => name,
dartName = 'dynamic'; };
default:
dartName = name;
}
return TypeResultBase(dartName, nullable: nullable); 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'; part 'object.dart';
@immutable @immutable
abstract class TypeResult { sealed class TypeResult {
TypeResult( TypeResult(
this.className, { this.className, {
this.generics = const [], 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: camel_case_types
// ignore_for_file: public_member_api_docs // ignore_for_file: public_member_api_docs
import 'dart:convert';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:built_collection/built_collection.dart'; import 'package:built_collection/built_collection.dart';
@ -2111,7 +2112,10 @@ class CoreWipeClient {
body, body,
); );
if (response.statusCode == 200 || response.statusCode == 404) { 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 throw await CoreApiException.fromResponse(response); // coverage:ignore-line
} }
@ -2630,7 +2634,8 @@ class _$CoreAvatarAvatarGetAvatarDarkHeadersSerializer
final value = iterator.current! as String; final value = iterator.current! as String;
switch (key) { switch (key) {
case 'x-nc-iscustomavatar': 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; final value = iterator.current! as String;
switch (key) { switch (key) {
case 'x-nc-iscustomavatar': 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); final result = CoreNavigationEntry_OrderBuilder()..data = JsonObject(data);
try { try {
result._$int = data as int?; result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {} } catch (_) {}
try { try {
result._string = data as String?; result._string = _jsonSerializers.deserialize(data, specifiedType: const FullType(String))! as String;
} catch (_) {} } catch (_) {}
assert([result._$int, result._string].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}'); assert([result._$int, result._string].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}');
return result.build(); return result.build();
@ -3837,7 +3843,10 @@ class _$CoreOcmOcmDiscoveryHeadersSerializer implements StructuredSerializer<Cor
final value = iterator.current! as String; final value = iterator.current! as String;
switch (key) { switch (key) {
case 'x-nextcloud-ocm-providers': 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); final result = CoreUnifiedSearchSearchCursorBuilder()..data = JsonObject(data);
try { try {
result._$int = data as int?; result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {} } catch (_) {}
try { try {
result._string = data as String?; result._string = _jsonSerializers.deserialize(data, specifiedType: const FullType(String))! as String;
} catch (_) {} } catch (_) {}
assert([result._$int, result._string].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}'); assert([result._$int, result._string].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}');
return result.build(); return result.build();
@ -7569,10 +7578,10 @@ class _$CoreUnifiedSearchResult_CursorSerializer implements PrimitiveSerializer<
}) { }) {
final result = CoreUnifiedSearchResult_CursorBuilder()..data = JsonObject(data); final result = CoreUnifiedSearchResult_CursorBuilder()..data = JsonObject(data);
try { try {
result._$int = data as int?; result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {} } catch (_) {}
try { try {
result._string = data as String?; result._string = _jsonSerializers.deserialize(data, specifiedType: const FullType(String))! as String;
} catch (_) {} } catch (_) {}
assert([result._$int, result._string].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}'); assert([result._$int, result._string].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}');
return result.build(); 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); final result = FilesSharingShareInfo_SizeBuilder()..data = JsonObject(data);
try { try {
result._$int = data as int?; result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {} } catch (_) {}
try { try {
result._$num = data as num?; result._$num = _jsonSerializers.deserialize(data, specifiedType: const FullType(num))! as num;
} catch (_) {} } catch (_) {}
assert([result._$int, result._$num].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}'); assert([result._$int, result._$num].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}');
return result.build(); return result.build();
@ -1970,10 +1970,10 @@ class _$FilesSharingShare_ItemSizeSerializer implements PrimitiveSerializer<File
}) { }) {
final result = FilesSharingShare_ItemSizeBuilder()..data = JsonObject(data); final result = FilesSharingShare_ItemSizeBuilder()..data = JsonObject(data);
try { try {
result._$num = data as num?; result._$num = _jsonSerializers.deserialize(data, specifiedType: const FullType(num))! as num;
} catch (_) {} } catch (_) {}
try { try {
result._$int = data as int?; result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {} } catch (_) {}
assert([result._$num, result._$int].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}'); assert([result._$num, result._$int].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}');
return result.build(); return result.build();
@ -2739,7 +2739,7 @@ class _$FilesSharingShareesapiSearchShareTypeSerializer
}) { }) {
final result = FilesSharingShareesapiSearchShareTypeBuilder()..data = JsonObject(data); final result = FilesSharingShareesapiSearchShareTypeBuilder()..data = JsonObject(data);
try { try {
result._$int = data as int?; result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {} } catch (_) {}
try { try {
result._builtListInt = (_jsonSerializers.deserialize( result._builtListInt = (_jsonSerializers.deserialize(
@ -3540,7 +3540,7 @@ class _$FilesSharingShareesapiFindRecommendedShareTypeSerializer
}) { }) {
final result = FilesSharingShareesapiFindRecommendedShareTypeBuilder()..data = JsonObject(data); final result = FilesSharingShareesapiFindRecommendedShareTypeBuilder()..data = JsonObject(data);
try { try {
result._$int = data as int?; result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {} } catch (_) {}
try { try {
result._builtListInt = (_jsonSerializers.deserialize( 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); final result = ProvisioningApiGroupDetails_UsercountBuilder()..data = JsonObject(data);
try { try {
result._$bool = data as bool?; result._$bool = _jsonSerializers.deserialize(data, specifiedType: const FullType(bool))! as bool;
} catch (_) {} } catch (_) {}
try { try {
result._$int = data as int?; result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {} } catch (_) {}
assert([result._$bool, result._$int].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}'); assert([result._$bool, result._$int].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}');
return result.build(); return result.build();
@ -3250,10 +3250,10 @@ class _$ProvisioningApiGroupDetails_DisabledSerializer
}) { }) {
final result = ProvisioningApiGroupDetails_DisabledBuilder()..data = JsonObject(data); final result = ProvisioningApiGroupDetails_DisabledBuilder()..data = JsonObject(data);
try { try {
result._$bool = data as bool?; result._$bool = _jsonSerializers.deserialize(data, specifiedType: const FullType(bool))! as bool;
} catch (_) {} } catch (_) {}
try { try {
result._$int = data as int?; result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {} } catch (_) {}
assert([result._$bool, result._$int].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}'); assert([result._$bool, result._$int].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}');
return result.build(); return result.build();
@ -3600,13 +3600,13 @@ class _$ProvisioningApiUserDetailsQuota_QuotaSerializer
}) { }) {
final result = ProvisioningApiUserDetailsQuota_QuotaBuilder()..data = JsonObject(data); final result = ProvisioningApiUserDetailsQuota_QuotaBuilder()..data = JsonObject(data);
try { try {
result._$num = data as num?; result._$num = _jsonSerializers.deserialize(data, specifiedType: const FullType(num))! as num;
} catch (_) {} } catch (_) {}
try { try {
result._$int = data as int?; result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {} } catch (_) {}
try { try {
result._string = data as String?; result._string = _jsonSerializers.deserialize(data, specifiedType: const FullType(String))! as String;
} catch (_) {} } catch (_) {}
assert( assert(
[result._$num, result._$int, result._string].where((final x) => x != null).isNotEmpty, [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); final result = UserStatusClearAt_TimeBuilder()..data = JsonObject(data);
try { try {
result._$int = data as int?; result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int;
} catch (_) {} } catch (_) {}
try { try {
result._clearAtTimeType = _jsonSerializers.deserialize( result._clearAtTimeType = _jsonSerializers.deserialize(
@ -1471,7 +1471,7 @@ class _$UserStatusUserStatusRevertStatusResponseApplicationJson_Ocs_DataSerializ
.toBuilder(); .toBuilder();
} catch (_) {} } catch (_) {}
try { try {
result._jsonObject = data as JsonObject?; result._jsonObject = _jsonSerializers.deserialize(data, specifiedType: const FullType(JsonObject))! as JsonObject;
} catch (_) {} } catch (_) {}
assert( assert(
[result._private, result._jsonObject].where((final x) => x != null).isNotEmpty, [result._private, result._jsonObject].where((final x) => x != null).isNotEmpty,

Loading…
Cancel
Save