From e32b3a8f4533502ddd4bfc3395fe074543f5f8d3 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Sat, 5 Aug 2023 17:29:00 +0200 Subject: [PATCH] fix(dynamite): Ignore more coverage --- .../dynamite/lib/src/openapi_builder.dart | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/packages/dynamite/dynamite/lib/src/openapi_builder.dart b/packages/dynamite/dynamite/lib/src/openapi_builder.dart index 1ac9d09e..8ba4428c 100644 --- a/packages/dynamite/dynamite/lib/src/openapi_builder.dart +++ b/packages/dynamite/dynamite/lib/src/openapi_builder.dart @@ -373,6 +373,7 @@ class OpenAPIBuilder implements Builder { final security = operation.security ?? spec.security ?? []; final securityRequirements = security.where((final requirement) => requirement.isNotEmpty); final isOptionalSecurity = securityRequirements.length != security.length; + code.write(' // coverage:ignore-start\n'); for (final requirement in securityRequirements) { final securityScheme = spec.components!.securitySchemes![requirement.keys.single]!; code.write(''' @@ -387,10 +388,11 @@ class OpenAPIBuilder implements Builder { if (securityRequirements.isNotEmpty && !isOptionalSecurity) { code.write(''' else { - throw Exception('Missing authentication for ${securityRequirements.map((final r) => r.keys.single).join(' or ')}'); // coverage:ignore-line + throw Exception('Missing authentication for ${securityRequirements.map((final r) => r.keys.single).join(' or ')}'); } '''); } + code.write(' // coverage:ignore-end\n'); for (final parameter in parameters) { final dartParameterNullable = _isDartParameterNullable( @@ -710,6 +712,7 @@ class OpenAPIBuilder implements Builder { if (state.resolvedTypes.isNotEmpty) { output.addAll([ + '// coverage:ignore-start', 'final Serializers _serializers = (Serializers().toBuilder()', ...state.resolvedTypes.map((final type) => type.serializers).expand((final element) => element).toSet(), ').build();', @@ -718,7 +721,6 @@ class OpenAPIBuilder implements Builder { '', 'final Serializers _jsonSerializers = (_serializers.toBuilder()..addPlugin(StandardJsonPlugin())..addPlugin(const ContentStringPlugin())).build();', '', - '// coverage:ignore-start', 'T deserialize$classPrefix(final Object data) => _serializers.deserialize(data, specifiedType: FullType(T))! as T;', '', 'Object? serialize$classPrefix(final T data) => _serializers.serialize(data, specifiedType: FullType(T));', @@ -726,29 +728,28 @@ class OpenAPIBuilder implements Builder { ]); } - final formatter = DartFormatter( - pageWidth: 120, - ); - const coverageIgnoreStart = ' // coverage:ignore-start'; - const coverageIgnoreEnd = ' // coverage:ignore-end'; final patterns = [ RegExp( - r'factory .*\.fromJson\(Map json\) => _\$.*FromJson\(json\);', + r'const .*\._\(\);', + ), + RegExp( + r'factory .*\.fromJson\(Map json\) => _jsonSerializers\.deserializeWith\(serializer, json\)!;', ), RegExp( - r'Map toJson\(\) => _\$.*ToJson\(this\);', + r'Map toJson\(\) => _jsonSerializers\.serializeWith\(serializer, this\)! as Map;', ), RegExp( - r'dynamic toJson\(\) => _data;', + r'static BuiltSet<.*> get values => _\$.*Values;', ), ]; var outputString = output.join('\n'); for (final pattern in patterns) { outputString = outputString.replaceAllMapped( pattern, - (final match) => '$coverageIgnoreStart\n${match.group(0)}\n$coverageIgnoreEnd', + (final match) => ' // coverage:ignore-start\n${match.group(0)}\n // coverage:ignore-end', ); } + final formatter = DartFormatter(pageWidth: 120); await buildStep.writeAsString( outputId, formatter.format(outputString), @@ -952,11 +953,6 @@ TypeResult resolveObject( ), ) ..constructors.addAll([ - Constructor( - (final b) => b - ..name = '_' - ..constant = true, - ), Constructor( (final b) => b ..factory = true @@ -970,6 +966,11 @@ TypeResult resolveObject( ) ..redirect = refer('_\$${state.prefix}$identifier'), ), + Constructor( + (final b) => b + ..name = '_' + ..constant = true, + ), Constructor( (final b) => b ..factory = true