Skip to content

Commit 0816bbc

Browse files
committed
Fix HTML report configuration section rendering
- Fixed Scriban template parameter indexing (/bin/zsh is template name, use / for data) - Added Dictionary to object array conversion for template compatibility - Updated all configuration template includes to use correct parameter positions - Enhanced configuration data preparation with proper object structure conversion - Added ComparisonConfiguration to ComparisonResult for template access - Removed debug code and cleaned up for production readiness Fixes #31: Configuration sections now display properly with correct labels and data
1 parent dee2723 commit 0816bbc

File tree

10 files changed

+70
-45
lines changed

10 files changed

+70
-45
lines changed

src/DotNetApiDiff/ApiExtraction/ApiComparer.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Reflection;
33
using DotNetApiDiff.Interfaces;
44
using DotNetApiDiff.Models;
5+
using DotNetApiDiff.Models.Configuration;
56
using Microsoft.Extensions.Logging;
67

78
namespace DotNetApiDiff.ApiExtraction;
@@ -15,6 +16,7 @@ public class ApiComparer : IApiComparer
1516
private readonly IDifferenceCalculator _differenceCalculator;
1617
private readonly INameMapper _nameMapper;
1718
private readonly IChangeClassifier _changeClassifier;
19+
private readonly ComparisonConfiguration _configuration;
1820
private readonly ILogger<ApiComparer> _logger;
1921

2022
/// <summary>
@@ -24,18 +26,21 @@ public class ApiComparer : IApiComparer
2426
/// <param name="differenceCalculator">Calculator for detailed change analysis</param>
2527
/// <param name="nameMapper">Mapper for namespace and type name transformations</param>
2628
/// <param name="changeClassifier">Classifier for breaking changes and exclusions</param>
29+
/// <param name="configuration">Configuration used for the comparison</param>
2730
/// <param name="logger">Logger for diagnostic information</param>
2831
public ApiComparer(
2932
IApiExtractor apiExtractor,
3033
IDifferenceCalculator differenceCalculator,
3134
INameMapper nameMapper,
3235
IChangeClassifier changeClassifier,
36+
ComparisonConfiguration configuration,
3337
ILogger<ApiComparer> logger)
3438
{
3539
_apiExtractor = apiExtractor ?? throw new ArgumentNullException(nameof(apiExtractor));
3640
_differenceCalculator = differenceCalculator ?? throw new ArgumentNullException(nameof(differenceCalculator));
3741
_nameMapper = nameMapper ?? throw new ArgumentNullException(nameof(nameMapper));
3842
_changeClassifier = changeClassifier ?? throw new ArgumentNullException(nameof(changeClassifier));
43+
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
3944
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
4045
}
4146

@@ -66,7 +71,8 @@ public ComparisonResult CompareAssemblies(Assembly oldAssembly, Assembly newAsse
6671
{
6772
OldAssemblyPath = oldAssembly.Location,
6873
NewAssemblyPath = newAssembly.Location,
69-
ComparisonTimestamp = DateTime.UtcNow
74+
ComparisonTimestamp = DateTime.UtcNow,
75+
Configuration = _configuration
7076
};
7177

7278
try

src/DotNetApiDiff/Commands/CompareCommand.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,14 @@ public override int Execute([NotNull] CommandContext context, [NotNull] CompareC
275275
loggerFactory.CreateLogger<ApiExtraction.ChangeClassifier>()));
276276

277277
// Add the main comparison service that depends on configured services
278-
commandServices.AddScoped<IApiComparer, ApiExtraction.ApiComparer>();
278+
commandServices.AddScoped<IApiComparer>(provider =>
279+
new ApiExtraction.ApiComparer(
280+
provider.GetRequiredService<IApiExtractor>(),
281+
provider.GetRequiredService<IDifferenceCalculator>(),
282+
provider.GetRequiredService<INameMapper>(),
283+
provider.GetRequiredService<IChangeClassifier>(),
284+
config,
285+
provider.GetRequiredService<ILogger<ApiExtraction.ApiComparer>>()));
279286

280287
// Execute the command with the configured services
281288
using (var commandProvider = commandServices.BuildServiceProvider())

src/DotNetApiDiff/DotNetApiDiff.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<PackageReference Include="Spectre.Console" Version="0.48.0" />
2222
<PackageReference Include="Spectre.Console.Cli" Version="0.48.0" />
2323
<PackageReference Include="System.Reflection.Metadata" Version="8.0.1" />
24-
<PackageReference Include="Scriban" Version="5.9.0" />
24+
<PackageReference Include="Scriban" Version="6.2.1" />
2525
</ItemGroup>
2626

2727
<ItemGroup>

src/DotNetApiDiff/Reporting/HtmlFormatterScriban.cs

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using DotNetApiDiff.Models.Configuration;
55
using Scriban;
66
using Scriban.Runtime;
7+
using System.Linq;
78

89
namespace DotNetApiDiff.Reporting;
910

@@ -65,49 +66,57 @@ public string Format(ComparisonResult result)
6566

6667
private object PrepareConfigData(ComparisonConfiguration config)
6768
{
69+
var namespaceMappings = config?.Mappings?.NamespaceMappings ?? new Dictionary<string, List<string>>();
70+
71+
// Convert Dictionary to array of objects with key/value properties for Scriban
72+
var namespaceMappingsArray = namespaceMappings.Select(kvp => new { key = kvp.Key, value = kvp.Value }).ToList();
73+
var typeMappingsArray = (config?.Mappings?.TypeMappings ?? new Dictionary<string, string>()).Select(kvp => new { key = kvp.Key, value = kvp.Value }).ToList();
74+
75+
var mappingsResult = new
76+
{
77+
namespace_mappings = namespaceMappingsArray,
78+
type_mappings = typeMappingsArray,
79+
auto_map_same_name_types = config?.Mappings?.AutoMapSameNameTypes ?? false,
80+
ignore_case = config?.Mappings?.IgnoreCase ?? false
81+
};
82+
6883
return new
6984
{
7085
filters = new
7186
{
72-
include_internals = config.Filters.IncludeInternals,
73-
include_compiler_generated = config.Filters.IncludeCompilerGenerated,
74-
include_namespaces = config.Filters.IncludeNamespaces?.ToList() ?? new List<string>(),
75-
exclude_namespaces = config.Filters.ExcludeNamespaces?.ToList() ?? new List<string>(),
76-
include_types = config.Filters.IncludeTypes?.ToList() ?? new List<string>(),
77-
exclude_types = config.Filters.ExcludeTypes?.ToList() ?? new List<string>()
78-
},
79-
mappings = new
80-
{
81-
namespace_mappings = config.Mappings.NamespaceMappings ?? new Dictionary<string, List<string>>(),
82-
type_mappings = config.Mappings.TypeMappings ?? new Dictionary<string, string>(),
83-
auto_map_same_name_types = config.Mappings.AutoMapSameNameTypes,
84-
ignore_case = config.Mappings.IgnoreCase
87+
include_internals = config?.Filters?.IncludeInternals ?? false,
88+
include_compiler_generated = config?.Filters?.IncludeCompilerGenerated ?? false,
89+
include_namespaces = config?.Filters?.IncludeNamespaces?.ToList() ?? new List<string>(),
90+
exclude_namespaces = config?.Filters?.ExcludeNamespaces?.ToList() ?? new List<string>(),
91+
include_types = config?.Filters?.IncludeTypes?.ToList() ?? new List<string>(),
92+
exclude_types = config?.Filters?.ExcludeTypes?.ToList() ?? new List<string>()
8593
},
94+
mappings = mappingsResult,
8695
exclusions = new
8796
{
88-
excluded_types = config.Exclusions.ExcludedTypes?.ToList() ?? new List<string>(),
89-
excluded_members = config.Exclusions.ExcludedMembers?.ToList() ?? new List<string>(),
90-
excluded_type_patterns = config.Exclusions.ExcludedTypePatterns?.ToList() ?? new List<string>(),
91-
excluded_member_patterns = config.Exclusions.ExcludedMemberPatterns?.ToList() ?? new List<string>(),
92-
exclude_compiler_generated = config.Exclusions.ExcludeCompilerGenerated,
93-
exclude_obsolete = config.Exclusions.ExcludeObsolete
97+
excluded_types = config?.Exclusions?.ExcludedTypes?.ToList() ?? new List<string>(),
98+
excluded_members = config?.Exclusions?.ExcludedMembers?.ToList() ?? new List<string>(),
99+
excluded_type_patterns = config?.Exclusions?.ExcludedTypePatterns?.ToList() ?? new List<string>(),
100+
excluded_member_patterns = config?.Exclusions?.ExcludedMemberPatterns?.ToList() ?? new List<string>(),
101+
exclude_compiler_generated = config?.Exclusions?.ExcludeCompilerGenerated ?? false,
102+
exclude_obsolete = config?.Exclusions?.ExcludeObsolete ?? false
94103
},
95104
breaking_change_rules = new
96105
{
97-
treat_type_removal_as_breaking = config.BreakingChangeRules.TreatTypeRemovalAsBreaking,
98-
treat_member_removal_as_breaking = config.BreakingChangeRules.TreatMemberRemovalAsBreaking,
99-
treat_signature_change_as_breaking = config.BreakingChangeRules.TreatSignatureChangeAsBreaking,
100-
treat_reduced_accessibility_as_breaking = config.BreakingChangeRules.TreatReducedAccessibilityAsBreaking,
101-
treat_added_type_as_breaking = config.BreakingChangeRules.TreatAddedTypeAsBreaking,
102-
treat_added_member_as_breaking = config.BreakingChangeRules.TreatAddedMemberAsBreaking,
103-
treat_added_interface_as_breaking = config.BreakingChangeRules.TreatAddedInterfaceAsBreaking,
104-
treat_removed_interface_as_breaking = config.BreakingChangeRules.TreatRemovedInterfaceAsBreaking,
105-
treat_parameter_name_change_as_breaking = config.BreakingChangeRules.TreatParameterNameChangeAsBreaking,
106-
treat_added_optional_parameter_as_breaking = config.BreakingChangeRules.TreatAddedOptionalParameterAsBreaking
106+
treat_type_removal_as_breaking = config?.BreakingChangeRules?.TreatTypeRemovalAsBreaking ?? true,
107+
treat_member_removal_as_breaking = config?.BreakingChangeRules?.TreatMemberRemovalAsBreaking ?? true,
108+
treat_signature_change_as_breaking = config?.BreakingChangeRules?.TreatSignatureChangeAsBreaking ?? true,
109+
treat_reduced_accessibility_as_breaking = config?.BreakingChangeRules?.TreatReducedAccessibilityAsBreaking ?? true,
110+
treat_added_type_as_breaking = config?.BreakingChangeRules?.TreatAddedTypeAsBreaking ?? false,
111+
treat_added_member_as_breaking = config?.BreakingChangeRules?.TreatAddedMemberAsBreaking ?? false,
112+
treat_added_interface_as_breaking = config?.BreakingChangeRules?.TreatAddedInterfaceAsBreaking ?? true,
113+
treat_removed_interface_as_breaking = config?.BreakingChangeRules?.TreatRemovedInterfaceAsBreaking ?? true,
114+
treat_parameter_name_change_as_breaking = config?.BreakingChangeRules?.TreatParameterNameChangeAsBreaking ?? false,
115+
treat_added_optional_parameter_as_breaking = config?.BreakingChangeRules?.TreatAddedOptionalParameterAsBreaking ?? false
107116
},
108-
output_format = config.OutputFormat.ToString(),
109-
output_path = config.OutputPath ?? string.Empty,
110-
fail_on_breaking_changes = config.FailOnBreakingChanges
117+
output_format = config?.OutputFormat.ToString() ?? "Console",
118+
output_path = config?.OutputPath ?? string.Empty,
119+
fail_on_breaking_changes = config?.FailOnBreakingChanges ?? false
111120
};
112121
}
113122

src/DotNetApiDiff/Reporting/HtmlTemplates/config-mappings.scriban

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div class="config-item">
2-
<span class="config-label">{{ label }}:</span>
3-
{{if mappings && mappings.size > 0}}
2+
<span class="config-label">{{ $2 }}:</span>
3+
{{if $1 && $1.size > 0}}
44
<div class="config-mappings">
5-
{{for mapping in mappings}}
5+
{{for mapping in $1}}
66
<div class="config-mapping">
77
<span class="mapping-from">{{ mapping.key }}</span>
88
<span class="mapping-arrow">→</span>

src/DotNetApiDiff/Reporting/HtmlTemplates/config-namespace-mappings.scriban

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div class="config-item">
2-
<span class="config-label">{{ label }}:</span>
3-
{{if mappings && mappings.size > 0}}
2+
<span class="config-label">{{ $2 }}:</span>
3+
{{if $1 && $1.size > 0}}
44
<div class="config-mappings">
5-
{{for mapping in mappings}}
5+
{{for mapping in $1}}
66
<div class="config-mapping">
77
<span class="mapping-from">{{ mapping.key }}</span>
88
<span class="mapping-arrow">→</span>

src/DotNetApiDiff/Reporting/HtmlTemplates/config-string-list.scriban

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div class="config-item">
2-
<span class="config-label">{{ label }}:</span>
3-
{{if items && items.size > 0}}
2+
<span class="config-label">{{ $2 }}:</span>
3+
{{if $1 && $1.size > 0}}
44
<div class="config-list">
5-
{{for item in items}}
5+
{{for item in $1}}
66
<span class="config-list-item">{{ item }}</span>
77
{{end}}
88
</div>

src/DotNetApiDiff/Reporting/HtmlTemplates/main-layout.scriban

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
</button>
8686
</div>
8787
<div id="config-details" class="config-details" style="display: none;">
88-
{{ include "configuration" result.configuration }}
88+
{{ include "configuration" }}
8989
</div>
9090
</section>
9191

tests/DotNetApiDiff.Tests/ApiExtraction/ApiComparerTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using DotNetApiDiff.ApiExtraction;
44
using DotNetApiDiff.Interfaces;
55
using DotNetApiDiff.Models;
6+
using DotNetApiDiff.Models.Configuration;
67
using Microsoft.Extensions.Logging;
78
using Moq;
89
using Xunit;
@@ -35,6 +36,7 @@ public ApiComparerTests()
3536
_mockDifferenceCalculator.Object,
3637
_mockNameMapper.Object,
3738
_mockChangeClassifier.Object,
39+
ComparisonConfiguration.CreateDefault(),
3840
_mockLogger.Object);
3941
}
4042

tests/DotNetApiDiff.Tests/ApiExtraction/ApiComparerWithMappingTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public void CompareTypes_WithNoMapping_FindsDifferences()
157157
_differenceCalculatorMock.Object,
158158
nameMapper,
159159
_changeClassifierMock.Object,
160+
ComparisonConfiguration.CreateDefault(),
160161
_loggerMock.Object);
161162

162163
var addedDifference = new ApiDifference { ChangeType = ChangeType.Added };

0 commit comments

Comments
 (0)