From 0376d8b195bd7b2abea286fbfd5a0f0de8faf1cd Mon Sep 17 00:00:00 2001 From: latonz Date: Wed, 2 Aug 2023 09:07:07 +0200 Subject: [PATCH] fix: remove obsolete MapperIgnoreAttribute BREAKING CHANGE: Obsolete MapperIgnoreAttribute is removed and should be replaced with MapperIgnoreTargetAttribute --- docs/docs/breaking-changes/3-0.md | 15 ++++++ docs/sidebars.js | 9 ++++ .../MapperIgnoreAttribute.cs | 27 ----------- .../PublicAPI.Shipped.txt | 3 -- .../Configuration/MapperConfiguration.cs | 4 -- .../Mapper/ProjectionMapper.cs | 5 +- .../Mapper/StaticTestMapper.cs | 14 ++---- .../Mapper/TestMapper.cs | 14 ++---- .../Mapping/ObjectPropertyIgnoreTest.cs | 48 ------------------- .../Mapping/UserMethodTest.cs | 32 ------------- 10 files changed, 33 insertions(+), 138 deletions(-) create mode 100644 docs/docs/breaking-changes/3-0.md delete mode 100644 src/Riok.Mapperly.Abstractions/MapperIgnoreAttribute.cs diff --git a/docs/docs/breaking-changes/3-0.md b/docs/docs/breaking-changes/3-0.md new file mode 100644 index 0000000000..5f732764c0 --- /dev/null +++ b/docs/docs/breaking-changes/3-0.md @@ -0,0 +1,15 @@ +--- +sidebar_position: 1 +description: How to upgrade to Mapperly v3.0 and a list of all its breaking changes +--- + +# v3.0 + +## Migration guide + +- Replace usages of `MapperIgnoreAttribute` with `MapperIgnoreTargetAttribute` ([details](#mapperignoreattribute-was-removed)) + +## MapperIgnoreAttribute was removed + +The `MapperIgnoreAttribute` is removed. +Any usages can be replaced with `MapperIgnoreTargetAttribute`. diff --git a/docs/sidebars.js b/docs/sidebars.js index fd0197e1bc..50ecbf1d4e 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -22,6 +22,15 @@ const sidebars = { }, items: [{ type: 'autogenerated', dirName: 'configuration' }], }, + { + type: 'category', + label: 'Upgrading', + collapsed: false, + link: { + type: 'generated-index', + }, + items: [{ type: 'autogenerated', dirName: 'breaking-changes' }], + }, ], api: [ { diff --git a/src/Riok.Mapperly.Abstractions/MapperIgnoreAttribute.cs b/src/Riok.Mapperly.Abstractions/MapperIgnoreAttribute.cs deleted file mode 100644 index cdbf615e9c..0000000000 --- a/src/Riok.Mapperly.Abstractions/MapperIgnoreAttribute.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace Riok.Mapperly.Abstractions; - -/// -/// Obsolete. -/// Ignores a property from the mapping. -/// -/// -/// This attribute is obsolete and was renamed to . -/// -[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] -[Obsolete("Renamed to " + nameof(MapperIgnoreTargetAttribute))] -public sealed class MapperIgnoreAttribute : Attribute -{ - /// - /// Ignores the specified target property from the mapping. - /// - /// The name of the target property to ignore. The use of `nameof()` is encouraged. - public MapperIgnoreAttribute(string target) - { - Target = target; - } - - /// - /// Gets the property name which should be ignored from the mapping. - /// - public string Target { get; } -} diff --git a/src/Riok.Mapperly.Abstractions/PublicAPI.Shipped.txt b/src/Riok.Mapperly.Abstractions/PublicAPI.Shipped.txt index 2a0666db20..f68ab9fc72 100644 --- a/src/Riok.Mapperly.Abstractions/PublicAPI.Shipped.txt +++ b/src/Riok.Mapperly.Abstractions/PublicAPI.Shipped.txt @@ -37,9 +37,6 @@ Riok.Mapperly.Abstractions.MapperAttribute.UseDeepCloning.get -> bool Riok.Mapperly.Abstractions.MapperAttribute.UseDeepCloning.set -> void Riok.Mapperly.Abstractions.MapperConstructorAttribute Riok.Mapperly.Abstractions.MapperConstructorAttribute.MapperConstructorAttribute() -> void -Riok.Mapperly.Abstractions.MapperIgnoreAttribute -Riok.Mapperly.Abstractions.MapperIgnoreAttribute.MapperIgnoreAttribute(string! target) -> void -Riok.Mapperly.Abstractions.MapperIgnoreAttribute.Target.get -> string! Riok.Mapperly.Abstractions.MapperIgnoreObsoleteMembersAttribute Riok.Mapperly.Abstractions.MapperIgnoreObsoleteMembersAttribute.IgnoreObsoleteStrategy.get -> Riok.Mapperly.Abstractions.IgnoreObsoleteMembersStrategy Riok.Mapperly.Abstractions.MapperIgnoreObsoleteMembersAttribute.MapperIgnoreObsoleteMembersAttribute(Riok.Mapperly.Abstractions.IgnoreObsoleteMembersStrategy ignoreObsoleteStrategy = (Riok.Mapperly.Abstractions.IgnoreObsoleteMembersStrategy)-1) -> void diff --git a/src/Riok.Mapperly/Configuration/MapperConfiguration.cs b/src/Riok.Mapperly/Configuration/MapperConfiguration.cs index bd5f65c54d..b93961c848 100644 --- a/src/Riok.Mapperly/Configuration/MapperConfiguration.cs +++ b/src/Riok.Mapperly/Configuration/MapperConfiguration.cs @@ -64,10 +64,6 @@ private PropertiesMappingConfiguration BuildPropertiesConfig(IMethodSymbol metho var ignoredTargetProperties = _dataAccessor .Access(method) .Select(x => x.Target) - // deprecated MapperIgnoreAttribute, but it is still supported by Mapperly. -#pragma warning disable CS0618 - .Concat(_dataAccessor.Access(method).Select(x => x.Target)) -#pragma warning restore CS0618 .WhereNotNull() .ToList(); var explicitMappings = _dataAccessor.Access(method).ToList(); diff --git a/test/Riok.Mapperly.IntegrationTests/Mapper/ProjectionMapper.cs b/test/Riok.Mapperly.IntegrationTests/Mapper/ProjectionMapper.cs index 6469e0066f..6ad5ddb3ea 100644 --- a/test/Riok.Mapperly.IntegrationTests/Mapper/ProjectionMapper.cs +++ b/test/Riok.Mapperly.IntegrationTests/Mapper/ProjectionMapper.cs @@ -12,10 +12,7 @@ public static partial class ProjectionMapper public static partial IQueryable ProjectToDto(this IQueryable q); - // disable obsolete warning, as the obsolete attribute should still be tested. -#pragma warning disable CS0618 - [MapperIgnore(nameof(TestObjectDtoProjection.IgnoredStringValue))] -#pragma warning restore CS0618 + [MapperIgnoreTarget(nameof(TestObjectDtoProjection.IgnoredStringValue))] [MapperIgnoreTarget(nameof(TestObjectDtoProjection.IgnoredIntValue))] [MapperIgnoreSource(nameof(TestObjectProjection.IgnoredStringValue))] [MapProperty(nameof(TestObjectProjection.RenamedStringValue), nameof(TestObjectDtoProjection.RenamedStringValue2))] diff --git a/test/Riok.Mapperly.IntegrationTests/Mapper/StaticTestMapper.cs b/test/Riok.Mapperly.IntegrationTests/Mapper/StaticTestMapper.cs index f4d3d458cb..83994b372c 100644 --- a/test/Riok.Mapperly.IntegrationTests/Mapper/StaticTestMapper.cs +++ b/test/Riok.Mapperly.IntegrationTests/Mapper/StaticTestMapper.cs @@ -39,10 +39,6 @@ public static TestObjectDto MapToDto(TestObject src) return target; } - // disable obsolete warning, as the obsolete attribute should still be tested. -#pragma warning disable CS0618 - [MapperIgnore(nameof(TestObjectDto.IgnoredStringValue))] -#pragma warning restore CS0618 [MapProperty(nameof(TestObject.RenamedStringValue), nameof(TestObjectDto.RenamedStringValue2))] [MapProperty( new[] { nameof(TestObject.UnflatteningIdValue) }, @@ -52,17 +48,15 @@ public static TestObjectDto MapToDto(TestObject src) nameof(TestObject.NullableUnflatteningIdValue), nameof(TestObjectDto.NullableUnflattening) + "." + nameof(TestObjectDto.NullableUnflattening.IdValue) )] + [MapperIgnoreTarget(nameof(TestObjectDto.IgnoredStringValue))] [MapperIgnoreSource(nameof(TestObject.IgnoredIntValue))] [MapperIgnoreTarget(nameof(TestObjectDto.IgnoredIntValue))] [MapperIgnoreObsoleteMembers] private static partial TestObjectDto MapToDtoInternal(TestObject testObject); - // disable obsolete warning, as the obsolete attribute should still be tested. -#pragma warning disable CS0618 - [MapperIgnore(nameof(TestObject.IgnoredStringValue))] - [MapperIgnore(nameof(TestObjectDto.DateTimeValueTargetDateOnly))] - [MapperIgnore(nameof(TestObjectDto.DateTimeValueTargetTimeOnly))] -#pragma warning restore CS0618 + [MapperIgnoreTarget(nameof(TestObject.DateTimeValueTargetDateOnly))] + [MapperIgnoreTarget(nameof(TestObject.DateTimeValueTargetTimeOnly))] + [MapperIgnoreTarget(nameof(TestObject.IgnoredStringValue))] [MapperIgnoreTarget(nameof(TestObject.IgnoredIntValue))] [MapperIgnoreSource(nameof(TestObjectDto.IgnoredIntValue))] public static partial TestObject MapFromDto(TestObjectDto dto); diff --git a/test/Riok.Mapperly.IntegrationTests/Mapper/TestMapper.cs b/test/Riok.Mapperly.IntegrationTests/Mapper/TestMapper.cs index d913d5a542..ba5c203790 100644 --- a/test/Riok.Mapperly.IntegrationTests/Mapper/TestMapper.cs +++ b/test/Riok.Mapperly.IntegrationTests/Mapper/TestMapper.cs @@ -32,10 +32,7 @@ public TestObjectDto MapToDto(TestObject src) return target; } - // disable obsolete warning, as the obsolete attribute should still be tested. -#pragma warning disable CS0618 - [MapperIgnore(nameof(TestObjectDto.IgnoredStringValue))] -#pragma warning restore CS0618 + [MapperIgnoreTarget(nameof(TestObjectDto.IgnoredStringValue))] [MapperIgnoreTarget(nameof(TestObjectDto.IgnoredIntValue))] [MapperIgnoreSource(nameof(TestObject.IgnoredIntValue))] [MapProperty(nameof(TestObject.RenamedStringValue), nameof(TestObjectDto.RenamedStringValue2))] @@ -50,12 +47,9 @@ public TestObjectDto MapToDto(TestObject src) [MapperIgnoreObsoleteMembers] private partial TestObjectDto MapToDtoInternal(TestObject testObject); - // disable obsolete warning, as the obsolete attribute should still be tested. -#pragma warning disable CS0618 - [MapperIgnore(nameof(TestObject.IgnoredStringValue))] - [MapperIgnore(nameof(TestObjectDto.DateTimeValueTargetDateOnly))] - [MapperIgnore(nameof(TestObjectDto.DateTimeValueTargetTimeOnly))] -#pragma warning restore CS0618 + [MapperIgnoreTarget(nameof(TestObject.DateTimeValueTargetDateOnly))] + [MapperIgnoreTarget(nameof(TestObject.DateTimeValueTargetTimeOnly))] + [MapperIgnoreTarget(nameof(TestObject.IgnoredStringValue))] [MapperIgnoreTarget(nameof(TestObject.IgnoredIntValue))] [MapperIgnoreSource(nameof(TestObjectDto.IgnoredIntValue))] public partial TestObject MapFromDto(TestObjectDto dto); diff --git a/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyIgnoreTest.cs b/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyIgnoreTest.cs index 14c56a98c8..32fa6b2ac4 100644 --- a/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyIgnoreTest.cs +++ b/test/Riok.Mapperly.Tests/Mapping/ObjectPropertyIgnoreTest.cs @@ -145,52 +145,4 @@ public void WithNotFoundIgnoredSourcePropertyShouldDiagnostic() """ ); } - - [Fact] - public void WithNotFoundIgnoredObsoleteTargetAttributePropertyShouldDiagnostic() - { - var source = TestSourceBuilder.MapperWithBodyAndTypes( - "[MapperIgnore(\"not_found\")] partial B Map(A source);", - "class A { }", - "class B { }" - ); - - TestHelper - .GenerateMapper(source, TestHelperOptions.AllowDiagnostics) - .Should() - .HaveDiagnostic(DiagnosticDescriptors.IgnoredTargetMemberNotFound, "Ignored target member not_found on B was not found") - .HaveAssertedAllDiagnostics() - .HaveSingleMethodBody( - """ - var target = new global::B(); - return target; - """ - ); - } - - [Fact] - public void WithObsoleteIgnoredTargetPropertyAttributeShouldIgnoreAndGenerateDiagnostics() - { - var source = TestSourceBuilder.MapperWithBodyAndTypes( - "[MapperIgnore(nameof(B.IntValue))] partial B Map(A source);", - "class A { public string StringValue { get; set; } public int IntValue { get; set; } }", - "class B { public string StringValue { get; set; } public int IntValue { get; set; } }" - ); - - TestHelper - .GenerateMapper(source, TestHelperOptions.AllowDiagnostics) - .Should() - .HaveDiagnostic( - DiagnosticDescriptors.SourceMemberNotMapped, - "The member IntValue on the mapping source type A is not mapped to any member on the mapping target type B" - ) - .HaveAssertedAllDiagnostics() - .HaveSingleMethodBody( - """ - var target = new global::B(); - target.StringValue = source.StringValue; - return target; - """ - ); - } } diff --git a/test/Riok.Mapperly.Tests/Mapping/UserMethodTest.cs b/test/Riok.Mapperly.Tests/Mapping/UserMethodTest.cs index 8650b5242e..4474c7c8c7 100644 --- a/test/Riok.Mapperly.Tests/Mapping/UserMethodTest.cs +++ b/test/Riok.Mapperly.Tests/Mapping/UserMethodTest.cs @@ -160,38 +160,6 @@ public void WithMultipleUserDefinedMethodShouldWork() TestHelper.GenerateMapper(source).Should().AllMethodsHaveBody("return int.Parse(source);"); } - [Fact] - public void WithMultipleUserDefinedMethodDifferentConfigShouldWork() - { - var source = TestSourceBuilder.MapperWithBodyAndTypes( - "[MapperIgnore(nameof(B.IntValue))] partial B Map(A source);" - + "[MapperIgnore(nameof(B.StringValue))] partial B Map2(A source);", - "class A { public string StringValue { get; set; } public int IntValue { get; set; } }", - "class B { public string StringValue { get; set; } public int IntValue { get; set; } }" - ); - - var mapper = TestHelper.GenerateMapper(source, TestHelperOptions.AllowInfoDiagnostics); - mapper - .Should() - .HaveOnlyMethods("Map", "Map2") - .HaveMethodBody( - "Map", - """ - var target = new global::B(); - target.StringValue = source.StringValue; - return target; - """ - ) - .HaveMethodBody( - "Map2", - """ - var target = new global::B(); - target.IntValue = source.IntValue; - return target; - """ - ); - } - [Fact] public void WithSameNamesShouldGenerateUniqueMethodNames() {