Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove obsolete MapperIgnoreAttribute #611

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/docs/breaking-changes/3-0.md
Original file line number Diff line number Diff line change
@@ -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`.
9 changes: 9 additions & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
27 changes: 0 additions & 27 deletions src/Riok.Mapperly.Abstractions/MapperIgnoreAttribute.cs

This file was deleted.

3 changes: 0 additions & 3 deletions src/Riok.Mapperly.Abstractions/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions src/Riok.Mapperly/Configuration/MapperConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ private PropertiesMappingConfiguration BuildPropertiesConfig(IMethodSymbol metho
var ignoredTargetProperties = _dataAccessor
.Access<MapperIgnoreTargetAttribute>(method)
.Select(x => x.Target)
// deprecated MapperIgnoreAttribute, but it is still supported by Mapperly.
#pragma warning disable CS0618
.Concat(_dataAccessor.Access<MapperIgnoreAttribute>(method).Select(x => x.Target))
#pragma warning restore CS0618
.WhereNotNull()
.ToList();
var explicitMappings = _dataAccessor.Access<MapPropertyAttribute, PropertyMappingConfiguration>(method).ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ public static partial class ProjectionMapper

public static partial IQueryable<TestObjectDtoProjectionBaseType> ProjectToDto(this IQueryable<TestObjectProjectionBaseType> 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))]
Expand Down
14 changes: 4 additions & 10 deletions test/Riok.Mapperly.IntegrationTests/Mapper/StaticTestMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand All @@ -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);
Expand Down
14 changes: 4 additions & 10 deletions test/Riok.Mapperly.IntegrationTests/Mapper/TestMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand All @@ -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);
Expand Down
48 changes: 0 additions & 48 deletions test/Riok.Mapperly.Tests/Mapping/ObjectPropertyIgnoreTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
"""
);
}
}
32 changes: 0 additions & 32 deletions test/Riok.Mapperly.Tests/Mapping/UserMethodTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Loading