From 93899cd65b0a3361faaeea631dcb05a31aa19272 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Thu, 19 Oct 2023 22:22:05 +0200 Subject: [PATCH] fix(dynamite,nextcloud): make oneOf and anyOf throw at build time rather then on deserialization Signed-off-by: Nikolas Rimikis --- .../dynamite/lib/src/builder/ofs_builder.dart | 356 ++++++++++-------- .../dynamite/lib/src/helpers/built_value.dart | 5 + .../nextcloud/lib/src/api/core.openapi.dart | 106 ++++-- .../nextcloud/lib/src/api/core.openapi.g.dart | 5 + .../lib/src/api/files_sharing.openapi.dart | 66 +++- .../lib/src/api/files_sharing.openapi.g.dart | 4 + .../lib/src/api/provisioning_api.openapi.dart | 88 ++++- .../src/api/provisioning_api.openapi.g.dart | 5 + .../lib/src/api/user_status.openapi.dart | 34 +- .../lib/src/api/user_status.openapi.g.dart | 2 + 10 files changed, 455 insertions(+), 216 deletions(-) diff --git a/packages/dynamite/dynamite/lib/src/builder/ofs_builder.dart b/packages/dynamite/dynamite/lib/src/builder/ofs_builder.dart index 8cc41f33323..978d67cd7f7 100644 --- a/packages/dynamite/dynamite/lib/src/builder/ofs_builder.dart +++ b/packages/dynamite/dynamite/lib/src/builder/ofs_builder.dart @@ -101,181 +101,215 @@ TypeResult resolveOfs( fields[result.name] = toFieldName(dartName, result.name); } - state.output.addAll([ - buildInterface( - identifier, - methods: BuiltList.build((final b) { + final interface = buildInterface( + identifier, + methods: BuiltList.build((final b) { + b.add( + Method( + (final b) { + b + ..name = 'data' + ..returns = refer('JsonObject') + ..type = MethodType.getter; + }, + ), + ); + + for (final result in results) { b.add( Method( (final b) { + final s = schema.ofs![results.indexOf(result)]; b - ..name = 'data' - ..returns = refer('JsonObject') - ..type = MethodType.getter; + ..name = fields[result.name] + ..returns = refer(result.nullableName) + ..type = MethodType.getter + ..docs.addAll(s.formattedDescription); }, ), ); + } + }), + ); - for (final result in results) { - b.add( - Method( - (final b) { - final s = schema.ofs![results.indexOf(result)]; - b - ..name = fields[result.name] - ..returns = refer(result.nullableName) - ..type = MethodType.getter - ..docs.addAll(s.formattedDescription); - }, - ), - ); - } - }), - ), - buildBuiltClass( - identifier, - customSerializer: true, - ), - Class( - (final b) => b - ..name = '_\$${identifier}Serializer' - ..implements.add(refer('PrimitiveSerializer<$identifier>')) - ..fields.addAll([ - Field( - (final b) => b - ..name = 'types' - ..modifier = FieldModifier.final$ - ..type = refer('Iterable') - ..annotations.add(refer('override')) - ..assignment = Code('const [$identifier, _\$$identifier]'), - ), - Field( - (final b) => b - ..name = 'wireName' - ..modifier = FieldModifier.final$ - ..type = refer('String') - ..annotations.add(refer('override')) - ..assignment = Code("r'$identifier'"), - ), - ]) - ..methods.addAll([ - Method((final b) { - b - ..name = 'serialize' - ..returns = refer('Object') - ..annotations.add(refer('override')) - ..requiredParameters.addAll([ - Parameter( - (final b) => b - ..name = 'serializers' - ..type = refer('Serializers'), - ), - Parameter( - (final b) => b - ..name = 'object' - ..type = refer(identifier), - ), - ]) - ..optionalParameters.add( - Parameter( - (final b) => b - ..name = 'specifiedType' - ..type = refer('FullType') - ..named = true - ..defaultTo = const Code('FullType.unspecified'), - ), - ) - ..body = const Code('return object.data.value;'); - }), - Method((final b) { - b - ..name = 'deserialize' - ..returns = refer(identifier) - ..annotations.add(refer('override')) - ..requiredParameters.addAll([ - Parameter( - (final b) => b - ..name = 'serializers' - ..type = refer('Serializers'), - ), - Parameter( - (final b) => b - ..name = 'data' - ..type = refer('Object'), - ), - ]) - ..optionalParameters.add( - Parameter( - (final b) => b - ..name = 'specifiedType' - ..type = refer('FullType') - ..named = true - ..defaultTo = const Code('FullType.unspecified'), - ), - ) - ..body = Code( - [ - 'final result = new ${identifier}Builder()', - '..data = JsonObject(data);', + final hook = Method((final b) { + b + ..name = '_validate' + ..returns = refer('void') + ..annotations.add( + refer('BuiltValueHook').call([], {'finalizeBuilder': literalTrue}), + ) + ..static = true + ..requiredParameters.add( + Parameter( + (final b) => b + ..name = 'b' + ..type = refer('${identifier}Builder'), + ), + ); + + final buffer = StringBuffer() + ..writeln('// When this is rebuild from another builder') + ..writeln('if (b._data == null) { return;}') + ..writeln() + ..writeln('final match = ') + ..writeln('[${fields.values.map((final e) => 'b._$e').join(',')}]') + ..writeln(schema.oneOf != null ? '.singleWhereOrNull' : '.firstWhereOrNull') + ..writeln('((final x) => x != null);') + ..writeln('if ( match == null) {') + ..writeln( + 'throw StateError("Need ${schema.oneOf != null ? 'exactly one' : 'at least'} one of ${fields.values.map((final e) => "'$e'").join(',')} for \${b._data}");', + ) + ..writeln('}'); + + b.body = Code(buffer.toString()); + }); + + final $class = buildBuiltClass( + identifier, + customSerializer: true, + extraMethods: [hook], + ); + + final serializer = Class( + (final b) => b + ..name = '_\$${identifier}Serializer' + ..implements.add(refer('PrimitiveSerializer<$identifier>')) + ..fields.addAll([ + Field( + (final b) => b + ..name = 'types' + ..modifier = FieldModifier.final$ + ..type = refer('Iterable') + ..annotations.add(refer('override')) + ..assignment = Code('const [$identifier, _\$$identifier]'), + ), + Field( + (final b) => b + ..name = 'wireName' + ..modifier = FieldModifier.final$ + ..type = refer('String') + ..annotations.add(refer('override')) + ..assignment = Code("r'$identifier'"), + ), + ]) + ..methods.addAll([ + Method((final b) { + b + ..name = 'serialize' + ..returns = refer('Object') + ..annotations.add(refer('override')) + ..requiredParameters.addAll([ + Parameter( + (final b) => b + ..name = 'serializers' + ..type = refer('Serializers'), + ), + Parameter( + (final b) => b + ..name = 'object' + ..type = refer(identifier), + ), + ]) + ..optionalParameters.add( + Parameter( + (final b) => b + ..name = 'specifiedType' + ..type = refer('FullType') + ..named = true + ..defaultTo = const Code('FullType.unspecified'), + ), + ) + ..body = const Code('return object.data.value;'); + }), + Method((final b) { + b + ..name = 'deserialize' + ..returns = refer(identifier) + ..annotations.add(refer('override')) + ..requiredParameters.addAll([ + Parameter( + (final b) => b + ..name = 'serializers' + ..type = refer('Serializers'), + ), + Parameter( + (final b) => b + ..name = 'data' + ..type = refer('Object'), + ), + ]) + ..optionalParameters.add( + Parameter( + (final b) => b + ..name = 'specifiedType' + ..type = refer('FullType') + ..named = true + ..defaultTo = const Code('FullType.unspecified'), + ), + ) + ..body = Code( + [ + 'final result = ${identifier}Builder()', + '..data = JsonObject(data);', + if (schema.discriminator != null) ...[ + 'if (data is! Iterable) {', + r"throw StateError('Expected an Iterable but got ${data.runtimeType}');", + '}', + '', + 'String? discriminator;', + '', + 'final iterator = data.iterator;', + 'while (iterator.moveNext()) {', + 'final key = iterator.current! as String;', + 'iterator.moveNext();', + 'final Object? value = iterator.current;', + "if (key == '${schema.discriminator!.propertyName}') {", + 'discriminator = value! as String;', + 'break;', + '}', + '}', + ], + for (final result in results) ...[ if (schema.discriminator != null) ...[ - 'if (data is! Iterable) {', - r"throw StateError('Expected an Iterable but got ${data.runtimeType}');", - '}', - '', - 'String? discriminator;', - '', - 'final iterator = data.iterator;', - 'while (iterator.moveNext()) {', - 'final key = iterator.current! as String;', - 'iterator.moveNext();', - 'final Object? value = iterator.current;', - "if (key == '${schema.discriminator!.propertyName}') {", - 'discriminator = value! as String;', - 'break;', - '}', - '}', - ], - for (final result in results) ...[ - if (schema.discriminator != null) ...[ - "if (discriminator == '${result.name}'", - if (schema.discriminator!.mapping != null && schema.discriminator!.mapping!.isNotEmpty) ...[ - for (final key in schema.discriminator!.mapping!.entries - .where( - (final entry) => entry.value.endsWith('/${result.name}'), - ) - .map((final entry) => entry.key)) ...[ - " || discriminator == '$key'", - ], - ') {', + "if (discriminator == '${result.name}'", + if (schema.discriminator!.mapping != null && schema.discriminator!.mapping!.isNotEmpty) ...[ + for (final key in schema.discriminator!.mapping!.entries + .where( + (final entry) => entry.value.endsWith('/${result.name}'), + ) + .map((final entry) => entry.key)) ...[ + " || discriminator == '$key'", ], - ], - 'try {', - if (result is TypeResultBase || result is TypeResultEnum) ...[ - 'result._${fields[result.name]!} = ${result.deserialize('data')};', - ] else ...[ - 'result._${fields[result.name]!} = ${result.deserialize('data')}.toBuilder();', - ], - '} catch (_) {', - if (schema.discriminator != null) ...[ - 'rethrow;', - ], - '}', - if (schema.discriminator != null) ...[ - '}', + ') {', ], ], - if (schema.oneOf != null) ...[ - "assert([${fields.values.map((final e) => 'result._$e').join(',')}].where((final x) => x != null).length >= 1, 'Need oneOf for \${result._data}');", + 'try {', + if (result is TypeResultBase || result is TypeResultEnum) ...[ + 'result._${fields[result.name]!} = ${result.deserialize('data')};', + ] else ...[ + 'result._${fields[result.name]!} = ${result.deserialize('data')}.toBuilder();', ], - if (schema.anyOf != null) ...[ - "assert([${fields.values.map((final e) => 'result._$e').join(',')}].where((final x) => x != null).length >= 1, 'Need anyOf for \${result._data}');", + '} catch (_) {', + if (schema.discriminator != null) ...[ + 'rethrow;', ], - 'return result.build();', - ].join(), - ); - }), - ]), - ), + '}', + if (schema.discriminator != null) ...[ + '}', + ], + ], + 'return result.build();', + ].join(), + ); + }), + ]), + ); + + state.output.addAll([ + interface, + $class, + serializer, ]); } diff --git a/packages/dynamite/dynamite/lib/src/helpers/built_value.dart b/packages/dynamite/dynamite/lib/src/helpers/built_value.dart index e8c80836bb3..688ce1ba5fe 100644 --- a/packages/dynamite/dynamite/lib/src/helpers/built_value.dart +++ b/packages/dynamite/dynamite/lib/src/helpers/built_value.dart @@ -10,6 +10,7 @@ Spec buildBuiltClass( final String className, { final Iterable? defaults, final bool customSerializer = false, + final Iterable? extraMethods, }) => Class( (final b) { @@ -61,6 +62,10 @@ Spec buildBuiltClass( ), ); } + + if (extraMethods != null) { + b.methods.addAll(extraMethods); + } }, ); diff --git a/packages/nextcloud/lib/src/api/core.openapi.dart b/packages/nextcloud/lib/src/api/core.openapi.dart index 9d5efec6088..279a33e7b8a 100644 --- a/packages/nextcloud/lib/src/api/core.openapi.dart +++ b/packages/nextcloud/lib/src/api/core.openapi.dart @@ -4750,6 +4750,19 @@ abstract class AutocompleteResult_Status @BuiltValueSerializer(custom: true) static Serializer get serializer => _$AutocompleteResult_StatusSerializer(); + + @BuiltValueHook(finalizeBuilder: true) + static void _validate(final AutocompleteResult_StatusBuilder b) { + // When this is rebuild from another builder + if (b._data == null) { + return; + } + + final match = [b._autocompleteResultStatus0, b._string].singleWhereOrNull((final x) => x != null); + if (match == null) { + throw StateError("Need exactly one one of 'autocompleteResultStatus0','string' for ${b._data}"); + } + } } class _$AutocompleteResult_StatusSerializer implements PrimitiveSerializer { @@ -4784,10 +4797,6 @@ class _$AutocompleteResult_StatusSerializer implements PrimitiveSerializer x != null).isNotEmpty, - 'Need oneOf for ${result._data}', - ); return result.build(); } } @@ -5777,6 +5786,19 @@ abstract class NavigationEntry_Order @BuiltValueSerializer(custom: true) static Serializer get serializer => _$NavigationEntry_OrderSerializer(); + + @BuiltValueHook(finalizeBuilder: true) + static void _validate(final NavigationEntry_OrderBuilder b) { + // When this is rebuild from another builder + if (b._data == null) { + return; + } + + final match = [b._$int, b._string].singleWhereOrNull((final x) => x != null); + if (match == null) { + throw StateError("Need exactly one one of '$int','string' for ${b._data}"); + } + } } class _$NavigationEntry_OrderSerializer implements PrimitiveSerializer { @@ -5807,7 +5829,6 @@ class _$NavigationEntry_OrderSerializer implements PrimitiveSerializer x != null).isNotEmpty, 'Need oneOf for ${result._data}'); return result.build(); } } @@ -7569,6 +7590,35 @@ abstract class OcsGetCapabilitiesResponseApplicationJson_Ocs_Data_Capabilities @BuiltValueSerializer(custom: true) static Serializer get serializer => _$OcsGetCapabilitiesResponseApplicationJson_Ocs_Data_CapabilitiesSerializer(); + + @BuiltValueHook(finalizeBuilder: true) + static void _validate(final OcsGetCapabilitiesResponseApplicationJson_Ocs_Data_CapabilitiesBuilder b) { + // When this is rebuild from another builder + if (b._data == null) { + return; + } + + final match = [ + b._commentsCapabilities, + b._davCapabilities, + b._filesCapabilities, + b._filesSharingCapabilities, + b._filesTrashbinCapabilities, + b._filesVersionsCapabilities, + b._notesCapabilities, + b._notificationsCapabilities, + b._provisioningApiCapabilities, + b._sharebymailCapabilities, + b._themingPublicCapabilities, + b._userStatusCapabilities, + b._weatherStatusCapabilities, + ].firstWhereOrNull((final x) => x != null); + if (match == null) { + throw StateError( + "Need at least one of 'commentsCapabilities','davCapabilities','filesCapabilities','filesSharingCapabilities','filesTrashbinCapabilities','filesVersionsCapabilities','notesCapabilities','notificationsCapabilities','provisioningApiCapabilities','sharebymailCapabilities','themingPublicCapabilities','userStatusCapabilities','weatherStatusCapabilities' for ${b._data}", + ); + } + } } class _$OcsGetCapabilitiesResponseApplicationJson_Ocs_Data_CapabilitiesSerializer @@ -7682,24 +7732,6 @@ class _$OcsGetCapabilitiesResponseApplicationJson_Ocs_Data_CapabilitiesSerialize )! as WeatherStatusCapabilities) .toBuilder(); } catch (_) {} - assert( - [ - result._commentsCapabilities, - result._davCapabilities, - result._filesCapabilities, - result._filesSharingCapabilities, - result._filesTrashbinCapabilities, - result._filesVersionsCapabilities, - result._notesCapabilities, - result._notificationsCapabilities, - result._provisioningApiCapabilities, - result._sharebymailCapabilities, - result._themingPublicCapabilities, - result._userStatusCapabilities, - result._weatherStatusCapabilities, - ].where((final x) => x != null).isNotEmpty, - 'Need anyOf for ${result._data}', - ); return result.build(); } } @@ -9223,6 +9255,19 @@ abstract class UnifiedSearchSearchCursor @BuiltValueSerializer(custom: true) static Serializer get serializer => _$UnifiedSearchSearchCursorSerializer(); + + @BuiltValueHook(finalizeBuilder: true) + static void _validate(final UnifiedSearchSearchCursorBuilder b) { + // When this is rebuild from another builder + if (b._data == null) { + return; + } + + final match = [b._$int, b._string].singleWhereOrNull((final x) => x != null); + if (match == null) { + throw StateError("Need exactly one one of '$int','string' for ${b._data}"); + } + } } class _$UnifiedSearchSearchCursorSerializer implements PrimitiveSerializer { @@ -9253,7 +9298,6 @@ class _$UnifiedSearchSearchCursorSerializer implements PrimitiveSerializer x != null).isNotEmpty, 'Need oneOf for ${result._data}'); return result.build(); } } @@ -9319,6 +9363,19 @@ abstract class UnifiedSearchResult_Cursor @BuiltValueSerializer(custom: true) static Serializer get serializer => _$UnifiedSearchResult_CursorSerializer(); + + @BuiltValueHook(finalizeBuilder: true) + static void _validate(final UnifiedSearchResult_CursorBuilder b) { + // When this is rebuild from another builder + if (b._data == null) { + return; + } + + final match = [b._$int, b._string].singleWhereOrNull((final x) => x != null); + if (match == null) { + throw StateError("Need exactly one one of '$int','string' for ${b._data}"); + } + } } class _$UnifiedSearchResult_CursorSerializer implements PrimitiveSerializer { @@ -9349,7 +9406,6 @@ class _$UnifiedSearchResult_CursorSerializer implements PrimitiveSerializer x != null).isNotEmpty, 'Need oneOf for ${result._data}'); return result.build(); } } diff --git a/packages/nextcloud/lib/src/api/core.openapi.g.dart b/packages/nextcloud/lib/src/api/core.openapi.g.dart index ddf970e3451..46e4c8d220a 100644 --- a/packages/nextcloud/lib/src/api/core.openapi.g.dart +++ b/packages/nextcloud/lib/src/api/core.openapi.g.dart @@ -9397,6 +9397,7 @@ class AutocompleteResult_StatusBuilder AutocompleteResult_Status build() => _build(); _$AutocompleteResult_Status _build() { + AutocompleteResult_Status._validate(this); _$AutocompleteResult_Status _$result; try { _$result = _$v ?? @@ -13050,6 +13051,7 @@ class NavigationEntry_OrderBuilder NavigationEntry_Order build() => _build(); _$NavigationEntry_Order _build() { + NavigationEntry_Order._validate(this); final _$result = _$v ?? _$NavigationEntry_Order._( data: BuiltValueNullFieldError.checkNotNull(data, r'NavigationEntry_Order', 'data'), @@ -20181,6 +20183,7 @@ class OcsGetCapabilitiesResponseApplicationJson_Ocs_Data_CapabilitiesBuilder OcsGetCapabilitiesResponseApplicationJson_Ocs_Data_Capabilities build() => _build(); _$OcsGetCapabilitiesResponseApplicationJson_Ocs_Data_Capabilities _build() { + OcsGetCapabilitiesResponseApplicationJson_Ocs_Data_Capabilities._validate(this); _$OcsGetCapabilitiesResponseApplicationJson_Ocs_Data_Capabilities _$result; try { _$result = _$v ?? @@ -26013,6 +26016,7 @@ class UnifiedSearchSearchCursorBuilder UnifiedSearchSearchCursor build() => _build(); _$UnifiedSearchSearchCursor _build() { + UnifiedSearchSearchCursor._validate(this); final _$result = _$v ?? _$UnifiedSearchSearchCursor._( data: BuiltValueNullFieldError.checkNotNull(data, r'UnifiedSearchSearchCursor', 'data'), @@ -26334,6 +26338,7 @@ class UnifiedSearchResult_CursorBuilder UnifiedSearchResult_Cursor build() => _build(); _$UnifiedSearchResult_Cursor _build() { + UnifiedSearchResult_Cursor._validate(this); final _$result = _$v ?? _$UnifiedSearchResult_Cursor._( data: BuiltValueNullFieldError.checkNotNull(data, r'UnifiedSearchResult_Cursor', 'data'), diff --git a/packages/nextcloud/lib/src/api/files_sharing.openapi.dart b/packages/nextcloud/lib/src/api/files_sharing.openapi.dart index 3e692b84c1f..4fa4d3e09c8 100644 --- a/packages/nextcloud/lib/src/api/files_sharing.openapi.dart +++ b/packages/nextcloud/lib/src/api/files_sharing.openapi.dart @@ -2896,6 +2896,19 @@ abstract class ShareInfo_Size implements ShareInfo_SizeInterface, Built get serializer => _$ShareInfo_SizeSerializer(); + + @BuiltValueHook(finalizeBuilder: true) + static void _validate(final ShareInfo_SizeBuilder b) { + // When this is rebuild from another builder + if (b._data == null) { + return; + } + + final match = [b._$int, b._$double].singleWhereOrNull((final x) => x != null); + if (match == null) { + throw StateError("Need exactly one one of '$int','$double' for ${b._data}"); + } + } } class _$ShareInfo_SizeSerializer implements PrimitiveSerializer { @@ -2926,7 +2939,10 @@ class _$ShareInfo_SizeSerializer implements PrimitiveSerializer try { result._$num = _jsonSerializers.deserialize(data, specifiedType: const FullType(num))! as num; } catch (_) {} +<<<<<<< Updated upstream assert([result._$int, result._$num].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}'); +======= +>>>>>>> Stashed changes return result.build(); } } @@ -2988,6 +3004,19 @@ abstract class Share_ItemSize implements Share_ItemSizeInterface, Built get serializer => _$Share_ItemSizeSerializer(); + + @BuiltValueHook(finalizeBuilder: true) + static void _validate(final Share_ItemSizeBuilder b) { + // When this is rebuild from another builder + if (b._data == null) { + return; + } + + final match = [b._$double, b._$int].singleWhereOrNull((final x) => x != null); + if (match == null) { + throw StateError("Need exactly one one of '$double','$int' for ${b._data}"); + } + } } class _$Share_ItemSizeSerializer implements PrimitiveSerializer { @@ -3018,7 +3047,10 @@ class _$Share_ItemSizeSerializer implements PrimitiveSerializer try { result._$int = _jsonSerializers.deserialize(data, specifiedType: const FullType(int))! as int; } catch (_) {} +<<<<<<< Updated upstream assert([result._$num, result._$int].where((final x) => x != null).isNotEmpty, 'Need oneOf for ${result._data}'); +======= +>>>>>>> Stashed changes return result.build(); } } @@ -3672,6 +3704,19 @@ abstract class ShareesapiSearchShareType @BuiltValueSerializer(custom: true) static Serializer get serializer => _$ShareesapiSearchShareTypeSerializer(); + + @BuiltValueHook(finalizeBuilder: true) + static void _validate(final ShareesapiSearchShareTypeBuilder b) { + // When this is rebuild from another builder + if (b._data == null) { + return; + } + + final match = [b._$int, b._builtListInt].singleWhereOrNull((final x) => x != null); + if (match == null) { + throw StateError("Need exactly one one of '$int','builtListInt' for ${b._data}"); + } + } } class _$ShareesapiSearchShareTypeSerializer implements PrimitiveSerializer { @@ -3706,10 +3751,6 @@ class _$ShareesapiSearchShareTypeSerializer implements PrimitiveSerializer) .toBuilder(); } catch (_) {} - assert( - [result._$int, result._builtListInt].where((final x) => x != null).isNotEmpty, - 'Need oneOf for ${result._data}', - ); return result.build(); } } @@ -4368,6 +4409,19 @@ abstract class ShareesapiFindRecommendedShareType @BuiltValueSerializer(custom: true) static Serializer get serializer => _$ShareesapiFindRecommendedShareTypeSerializer(); + + @BuiltValueHook(finalizeBuilder: true) + static void _validate(final ShareesapiFindRecommendedShareTypeBuilder b) { + // When this is rebuild from another builder + if (b._data == null) { + return; + } + + final match = [b._$int, b._builtListInt].singleWhereOrNull((final x) => x != null); + if (match == null) { + throw StateError("Need exactly one one of '$int','builtListInt' for ${b._data}"); + } + } } class _$ShareesapiFindRecommendedShareTypeSerializer @@ -4403,10 +4457,6 @@ class _$ShareesapiFindRecommendedShareTypeSerializer )! as BuiltList) .toBuilder(); } catch (_) {} - assert( - [result._$int, result._builtListInt].where((final x) => x != null).isNotEmpty, - 'Need oneOf for ${result._data}', - ); return result.build(); } } diff --git a/packages/nextcloud/lib/src/api/files_sharing.openapi.g.dart b/packages/nextcloud/lib/src/api/files_sharing.openapi.g.dart index e354fbb5551..7fa0191668d 100644 --- a/packages/nextcloud/lib/src/api/files_sharing.openapi.g.dart +++ b/packages/nextcloud/lib/src/api/files_sharing.openapi.g.dart @@ -7456,6 +7456,7 @@ class ShareInfo_SizeBuilder implements Builder _build(); _$ShareInfo_Size _build() { + ShareInfo_Size._validate(this); final _$result = _$v ?? _$ShareInfo_Size._( data: BuiltValueNullFieldError.checkNotNull(data, r'ShareInfo_Size', 'data'), $int: $int, $num: $num); @@ -7815,6 +7816,7 @@ class Share_ItemSizeBuilder implements Builder _build(); _$Share_ItemSize _build() { + Share_ItemSize._validate(this); final _$result = _$v ?? _$Share_ItemSize._( data: BuiltValueNullFieldError.checkNotNull(data, r'Share_ItemSize', 'data'), $num: $num, $int: $int); @@ -10582,6 +10584,7 @@ class ShareesapiSearchShareTypeBuilder ShareesapiSearchShareType build() => _build(); _$ShareesapiSearchShareType _build() { + ShareesapiSearchShareType._validate(this); _$ShareesapiSearchShareType _$result; try { _$result = _$v ?? @@ -13824,6 +13827,7 @@ class ShareesapiFindRecommendedShareTypeBuilder ShareesapiFindRecommendedShareType build() => _build(); _$ShareesapiFindRecommendedShareType _build() { + ShareesapiFindRecommendedShareType._validate(this); _$ShareesapiFindRecommendedShareType _$result; try { _$result = _$v ?? diff --git a/packages/nextcloud/lib/src/api/provisioning_api.openapi.dart b/packages/nextcloud/lib/src/api/provisioning_api.openapi.dart index 32bfc2d1c08..f5a54bf256c 100644 --- a/packages/nextcloud/lib/src/api/provisioning_api.openapi.dart +++ b/packages/nextcloud/lib/src/api/provisioning_api.openapi.dart @@ -5196,6 +5196,19 @@ abstract class GroupDetails_Usercount @BuiltValueSerializer(custom: true) static Serializer get serializer => _$GroupDetails_UsercountSerializer(); + + @BuiltValueHook(finalizeBuilder: true) + static void _validate(final GroupDetails_UsercountBuilder b) { + // When this is rebuild from another builder + if (b._data == null) { + return; + } + + final match = [b._$bool, b._$int].singleWhereOrNull((final x) => x != null); + if (match == null) { + throw StateError("Need exactly one one of '$bool','$int' for ${b._data}"); + } + } } class _$GroupDetails_UsercountSerializer implements PrimitiveSerializer { @@ -5226,7 +5239,6 @@ class _$GroupDetails_UsercountSerializer implements PrimitiveSerializer x != null).isNotEmpty, 'Need oneOf for ${result._data}'); return result.build(); } } @@ -5257,6 +5269,19 @@ abstract class GroupDetails_Disabled @BuiltValueSerializer(custom: true) static Serializer get serializer => _$GroupDetails_DisabledSerializer(); + + @BuiltValueHook(finalizeBuilder: true) + static void _validate(final GroupDetails_DisabledBuilder b) { + // When this is rebuild from another builder + if (b._data == null) { + return; + } + + final match = [b._$bool, b._$int].singleWhereOrNull((final x) => x != null); + if (match == null) { + throw StateError("Need exactly one one of '$bool','$int' for ${b._data}"); + } + } } class _$GroupDetails_DisabledSerializer implements PrimitiveSerializer { @@ -5287,7 +5312,6 @@ class _$GroupDetails_DisabledSerializer implements PrimitiveSerializer x != null).isNotEmpty, 'Need oneOf for ${result._data}'); return result.build(); } } @@ -5561,6 +5585,19 @@ abstract class UserDetailsQuota_Quota @BuiltValueSerializer(custom: true) static Serializer get serializer => _$UserDetailsQuota_QuotaSerializer(); + + @BuiltValueHook(finalizeBuilder: true) + static void _validate(final UserDetailsQuota_QuotaBuilder b) { + // When this is rebuild from another builder + if (b._data == null) { + return; + } + + final match = [b._$double, b._$int, b._string].singleWhereOrNull((final x) => x != null); + if (match == null) { + throw StateError("Need exactly one one of '$double','$int','string' for ${b._data}"); + } + } } class _$UserDetailsQuota_QuotaSerializer implements PrimitiveSerializer { @@ -5594,10 +5631,13 @@ class _$UserDetailsQuota_QuotaSerializer implements PrimitiveSerializer x != null).isNotEmpty, 'Need oneOf for ${result._data}', ); +======= +>>>>>>> Stashed changes return result.build(); } } @@ -5763,6 +5803,22 @@ abstract class GroupsGetGroupUsersDetailsResponseApplicationJson_Ocs_Data_Users @BuiltValueSerializer(custom: true) static Serializer get serializer => _$GroupsGetGroupUsersDetailsResponseApplicationJson_Ocs_Data_UsersSerializer(); + + @BuiltValueHook(finalizeBuilder: true) + static void _validate(final GroupsGetGroupUsersDetailsResponseApplicationJson_Ocs_Data_UsersBuilder b) { + // When this is rebuild from another builder + if (b._data == null) { + return; + } + + final match = [b._userDetails, b._groupsGetGroupUsersDetailsResponseApplicationJsonOcsDataUsers1] + .singleWhereOrNull((final x) => x != null); + if (match == null) { + throw StateError( + "Need exactly one one of 'userDetails','groupsGetGroupUsersDetailsResponseApplicationJsonOcsDataUsers1' for ${b._data}", + ); + } + } } class _$GroupsGetGroupUsersDetailsResponseApplicationJson_Ocs_Data_UsersSerializer @@ -5802,12 +5858,6 @@ class _$GroupsGetGroupUsersDetailsResponseApplicationJson_Ocs_Data_UsersSerializ )! as GroupsGetGroupUsersDetailsResponseApplicationJson_Ocs_Data_Users1) .toBuilder(); } catch (_) {} - assert( - [result._userDetails, result._groupsGetGroupUsersDetailsResponseApplicationJsonOcsDataUsers1] - .where((final x) => x != null) - .isNotEmpty, - 'Need oneOf for ${result._data}', - ); return result.build(); } } @@ -6677,6 +6727,22 @@ abstract class UsersGetUsersDetailsResponseApplicationJson_Ocs_Data_Users @BuiltValueSerializer(custom: true) static Serializer get serializer => _$UsersGetUsersDetailsResponseApplicationJson_Ocs_Data_UsersSerializer(); + + @BuiltValueHook(finalizeBuilder: true) + static void _validate(final UsersGetUsersDetailsResponseApplicationJson_Ocs_Data_UsersBuilder b) { + // When this is rebuild from another builder + if (b._data == null) { + return; + } + + final match = [b._userDetails, b._usersGetUsersDetailsResponseApplicationJsonOcsDataUsers1] + .singleWhereOrNull((final x) => x != null); + if (match == null) { + throw StateError( + "Need exactly one one of 'userDetails','usersGetUsersDetailsResponseApplicationJsonOcsDataUsers1' for ${b._data}", + ); + } + } } class _$UsersGetUsersDetailsResponseApplicationJson_Ocs_Data_UsersSerializer @@ -6716,12 +6782,6 @@ class _$UsersGetUsersDetailsResponseApplicationJson_Ocs_Data_UsersSerializer )! as UsersGetUsersDetailsResponseApplicationJson_Ocs_Data_Users1) .toBuilder(); } catch (_) {} - assert( - [result._userDetails, result._usersGetUsersDetailsResponseApplicationJsonOcsDataUsers1] - .where((final x) => x != null) - .isNotEmpty, - 'Need oneOf for ${result._data}', - ); return result.build(); } } diff --git a/packages/nextcloud/lib/src/api/provisioning_api.openapi.g.dart b/packages/nextcloud/lib/src/api/provisioning_api.openapi.g.dart index a951d4c21fe..8704c9d5c62 100644 --- a/packages/nextcloud/lib/src/api/provisioning_api.openapi.g.dart +++ b/packages/nextcloud/lib/src/api/provisioning_api.openapi.g.dart @@ -9742,6 +9742,7 @@ class GroupDetails_UsercountBuilder GroupDetails_Usercount build() => _build(); _$GroupDetails_Usercount _build() { + GroupDetails_Usercount._validate(this); final _$result = _$v ?? _$GroupDetails_Usercount._( data: BuiltValueNullFieldError.checkNotNull(data, r'GroupDetails_Usercount', 'data'), @@ -9857,6 +9858,7 @@ class GroupDetails_DisabledBuilder GroupDetails_Disabled build() => _build(); _$GroupDetails_Disabled _build() { + GroupDetails_Disabled._validate(this); final _$result = _$v ?? _$GroupDetails_Disabled._( data: BuiltValueNullFieldError.checkNotNull(data, r'GroupDetails_Disabled', 'data'), @@ -10943,6 +10945,7 @@ class UserDetailsQuota_QuotaBuilder UserDetailsQuota_Quota build() => _build(); _$UserDetailsQuota_Quota _build() { + UserDetailsQuota_Quota._validate(this); final _$result = _$v ?? _$UserDetailsQuota_Quota._( data: BuiltValueNullFieldError.checkNotNull(data, r'UserDetailsQuota_Quota', 'data'), @@ -12076,6 +12079,7 @@ class GroupsGetGroupUsersDetailsResponseApplicationJson_Ocs_Data_UsersBuilder GroupsGetGroupUsersDetailsResponseApplicationJson_Ocs_Data_Users build() => _build(); _$GroupsGetGroupUsersDetailsResponseApplicationJson_Ocs_Data_Users _build() { + GroupsGetGroupUsersDetailsResponseApplicationJson_Ocs_Data_Users._validate(this); _$GroupsGetGroupUsersDetailsResponseApplicationJson_Ocs_Data_Users _$result; try { _$result = _$v ?? @@ -15243,6 +15247,7 @@ class UsersGetUsersDetailsResponseApplicationJson_Ocs_Data_UsersBuilder UsersGetUsersDetailsResponseApplicationJson_Ocs_Data_Users build() => _build(); _$UsersGetUsersDetailsResponseApplicationJson_Ocs_Data_Users _build() { + UsersGetUsersDetailsResponseApplicationJson_Ocs_Data_Users._validate(this); _$UsersGetUsersDetailsResponseApplicationJson_Ocs_Data_Users _$result; try { _$result = _$v ?? diff --git a/packages/nextcloud/lib/src/api/user_status.openapi.dart b/packages/nextcloud/lib/src/api/user_status.openapi.dart index 345b4184547..05300c808e4 100644 --- a/packages/nextcloud/lib/src/api/user_status.openapi.dart +++ b/packages/nextcloud/lib/src/api/user_status.openapi.dart @@ -1183,6 +1183,19 @@ abstract class ClearAt_Time implements ClearAt_TimeInterface, Built get serializer => _$ClearAt_TimeSerializer(); + + @BuiltValueHook(finalizeBuilder: true) + static void _validate(final ClearAt_TimeBuilder b) { + // When this is rebuild from another builder + if (b._data == null) { + return; + } + + final match = [b._$int, b._clearAtTimeType].singleWhereOrNull((final x) => x != null); + if (match == null) { + throw StateError("Need exactly one one of '$int','clearAtTimeType' for ${b._data}"); + } + } } class _$ClearAt_TimeSerializer implements PrimitiveSerializer { @@ -1214,10 +1227,6 @@ class _$ClearAt_TimeSerializer implements PrimitiveSerializer { result._clearAtTimeType = _jsonSerializers.deserialize(data, specifiedType: const FullType(ClearAtTimeType))! as ClearAtTimeType; } catch (_) {} - assert( - [result._$int, result._clearAtTimeType].where((final x) => x != null).isNotEmpty, - 'Need oneOf for ${result._data}', - ); return result.build(); } } @@ -1798,6 +1807,19 @@ abstract class UserStatusRevertStatusResponseApplicationJson_Ocs_Data @BuiltValueSerializer(custom: true) static Serializer get serializer => _$UserStatusRevertStatusResponseApplicationJson_Ocs_DataSerializer(); + + @BuiltValueHook(finalizeBuilder: true) + static void _validate(final UserStatusRevertStatusResponseApplicationJson_Ocs_DataBuilder b) { + // When this is rebuild from another builder + if (b._data == null) { + return; + } + + final match = [b._private, b._jsonObject].singleWhereOrNull((final x) => x != null); + if (match == null) { + throw StateError("Need exactly one one of 'private','jsonObject' for ${b._data}"); + } + } } class _$UserStatusRevertStatusResponseApplicationJson_Ocs_DataSerializer @@ -1833,10 +1855,6 @@ class _$UserStatusRevertStatusResponseApplicationJson_Ocs_DataSerializer try { result._jsonObject = _jsonSerializers.deserialize(data, specifiedType: const FullType(JsonObject))! as JsonObject; } catch (_) {} - assert( - [result._private, result._jsonObject].where((final x) => x != null).isNotEmpty, - 'Need oneOf for ${result._data}', - ); return result.build(); } } diff --git a/packages/nextcloud/lib/src/api/user_status.openapi.g.dart b/packages/nextcloud/lib/src/api/user_status.openapi.g.dart index 0c2cbebd0e1..93c5138f8a1 100644 --- a/packages/nextcloud/lib/src/api/user_status.openapi.g.dart +++ b/packages/nextcloud/lib/src/api/user_status.openapi.g.dart @@ -2311,6 +2311,7 @@ class ClearAt_TimeBuilder implements Builder, ClearAt_Time build() => _build(); _$ClearAt_Time _build() { + ClearAt_Time._validate(this); final _$result = _$v ?? _$ClearAt_Time._( data: BuiltValueNullFieldError.checkNotNull(data, r'ClearAt_Time', 'data'), @@ -4504,6 +4505,7 @@ class UserStatusRevertStatusResponseApplicationJson_Ocs_DataBuilder UserStatusRevertStatusResponseApplicationJson_Ocs_Data build() => _build(); _$UserStatusRevertStatusResponseApplicationJson_Ocs_Data _build() { + UserStatusRevertStatusResponseApplicationJson_Ocs_Data._validate(this); _$UserStatusRevertStatusResponseApplicationJson_Ocs_Data _$result; try { _$result = _$v ??