Skip to content

Commit 1c13628

Browse files
Correct sunset policy resolution when falling back. Fixes #1064
1 parent ef0aa08 commit 1c13628

File tree

5 files changed

+9
-11
lines changed

5 files changed

+9
-11
lines changed

src/Abstractions/src/Asp.Versioning.Abstractions/Asp.Versioning.Abstractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VersionPrefix>8.0.0</VersionPrefix>
4+
<VersionPrefix>8.0.1</VersionPrefix>
55
<AssemblyVersion>8.0.0.0</AssemblyVersion>
66
<TargetFrameworks>$(DefaultTargetFramework);netstandard1.0;netstandard2.0</TargetFrameworks>
77
<AssemblyTitle>API Versioning Abstractions</AssemblyTitle>

src/Abstractions/src/Asp.Versioning.Abstractions/ISunsetPolicyManagerExtensions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static bool TryGetPolicy(
4646
/// <param name="name">The name of the API.</param>
4747
/// <param name="apiVersion">The API version to get the policy for.</param>
4848
/// <returns>The applicable <see cref="SunsetPolicy">sunset policy</see>, if any.</returns>
49-
/// <remarks>The resolution or is as follows:
49+
/// <remarks>The resolution order is as follows:
5050
/// <list type="bullet">
5151
/// <item><paramref name="name"/> and <paramref name="apiVersion"/></item>
5252
/// <item><paramref name="name"/> only</item>
@@ -76,7 +76,7 @@ public static bool TryGetPolicy(
7676
/// <param name="apiVersion">The API version to get the policy for.</param>
7777
/// /// <param name="sunsetPolicy">The applicable <see cref="SunsetPolicy">sunset policy</see>, if any.</param>
7878
/// <returns>True if the <paramref name="sunsetPolicy">sunset policy</paramref> was retrieved; otherwise, false.</returns>
79-
/// <remarks>The resolution or is as follows:
79+
/// <remarks>The resolution order is as follows:
8080
/// <list type="bullet">
8181
/// <item><paramref name="name"/> and <paramref name="apiVersion"/></item>
8282
/// <item><paramref name="name"/> only</item>
@@ -102,7 +102,8 @@ public static bool TryResolvePolicy(
102102
return true;
103103
}
104104
}
105-
else if ( apiVersion != null && policyManager.TryGetPolicy( apiVersion, out sunsetPolicy ) )
105+
106+
if ( apiVersion != null && policyManager.TryGetPolicy( apiVersion, out sunsetPolicy ) )
106107
{
107108
return true;
108109
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-

1+
TryResolvePolicy should correctly fall back ([#1064](https://github.com/dotnet/aspnet-api-versioning/issues/1064))

src/Abstractions/test/Asp.Versioning.Abstractions.Tests/ISunsetPolicyManagerExtensionsTest.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,10 @@ public void resolve_policy_should_fall_back_to_global_result()
6565
var expected = new SunsetPolicy();
6666
var other = new SunsetPolicy();
6767

68-
manager.Setup( m => m.TryGetPolicy( "Test", new ApiVersion( 1.0, null ), out other ) ).Returns( true );
69-
manager.Setup( m => m.TryGetPolicy( default, new ApiVersion( 1.0, null ), out expected ) ).Returns( true );
68+
manager.Setup( m => m.TryGetPolicy( It.IsAny<string>(), new ApiVersion( 1.0, null ), out expected ) ).Returns( true );
7069

7170
// act
72-
var policy = manager.Object.ResolvePolicyOrDefault( default, new ApiVersion( 1.0 ) );
71+
var policy = manager.Object.ResolvePolicyOrDefault( "Test", new ApiVersion( 1.0 ) );
7372

7473
// assert
7574
policy.Should().BeSameAs( expected );

src/Common/src/Common/DefaultApiVersionReporter.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ public void Report( HttpResponse response, ApiVersionModel apiVersionModel )
9191
#endif
9292
var name = metadata.Name;
9393

94-
if ( sunsetPolicyManager.TryGetPolicy( name, version, out var policy ) ||
95-
( !string.IsNullOrEmpty( name ) && sunsetPolicyManager.TryGetPolicy( name, out policy ) ) ||
96-
( version != null && sunsetPolicyManager.TryGetPolicy( version, out policy ) ) )
94+
if ( sunsetPolicyManager.TryResolvePolicy( name, version, out var policy ) )
9795
{
9896
response.WriteSunsetPolicy( policy );
9997
}

0 commit comments

Comments
 (0)