Skip to content

Commit

Permalink
Correct sunset policy resolution when falling back. Fixes #1064
Browse files Browse the repository at this point in the history
  • Loading branch information
commonsensesoftware committed Jan 10, 2024
1 parent ef0aa08 commit 2f81496
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>8.0.0</VersionPrefix>
<VersionPrefix>8.0.1</VersionPrefix>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<TargetFrameworks>$(DefaultTargetFramework);netstandard1.0;netstandard2.0</TargetFrameworks>
<AssemblyTitle>API Versioning Abstractions</AssemblyTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static bool TryGetPolicy(
/// <param name="name">The name of the API.</param>
/// <param name="apiVersion">The API version to get the policy for.</param>
/// <returns>The applicable <see cref="SunsetPolicy">sunset policy</see>, if any.</returns>
/// <remarks>The resolution or is as follows:
/// <remarks>The resolution order is as follows:
/// <list type="bullet">
/// <item><paramref name="name"/> and <paramref name="apiVersion"/></item>
/// <item><paramref name="name"/> only</item>
Expand Down Expand Up @@ -76,7 +76,7 @@ public static bool TryGetPolicy(
/// <param name="apiVersion">The API version to get the policy for.</param>
/// /// <param name="sunsetPolicy">The applicable <see cref="SunsetPolicy">sunset policy</see>, if any.</param>
/// <returns>True if the <paramref name="sunsetPolicy">sunset policy</paramref> was retrieved; otherwise, false.</returns>
/// <remarks>The resolution or is as follows:
/// <remarks>The resolution order is as follows:
/// <list type="bullet">
/// <item><paramref name="name"/> and <paramref name="apiVersion"/></item>
/// <item><paramref name="name"/> only</item>
Expand All @@ -102,7 +102,8 @@ public static bool TryResolvePolicy(
return true;
}
}
else if ( apiVersion != null && policyManager.TryGetPolicy( apiVersion, out sunsetPolicy ) )

if ( apiVersion != null && policyManager.TryGetPolicy( apiVersion, out sunsetPolicy ) )
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@

TryResolvePolicy should correctly fall back ([#1064](https://github.com/dotnet/aspnet-api-versioning/issues/1064))
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@ public void resolve_policy_should_fall_back_to_global_result()
var expected = new SunsetPolicy();
var other = new SunsetPolicy();

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

// act
var policy = manager.Object.ResolvePolicyOrDefault( default, new ApiVersion( 1.0 ) );
var policy = manager.Object.ResolvePolicyOrDefault( "Test", new ApiVersion( 1.0 ) );

// assert
policy.Should().BeSameAs( expected );
Expand Down
4 changes: 1 addition & 3 deletions src/Common/src/Common/DefaultApiVersionReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ public void Report( HttpResponse response, ApiVersionModel apiVersionModel )
#endif
var name = metadata.Name;

if ( sunsetPolicyManager.TryGetPolicy( name, version, out var policy ) ||
( !string.IsNullOrEmpty( name ) && sunsetPolicyManager.TryGetPolicy( name, out policy ) ) ||
( version != null && sunsetPolicyManager.TryGetPolicy( version, out policy ) ) )
if ( sunsetPolicyManager.TryResolvePolicy( name, version, out var policy ) )
{
response.WriteSunsetPolicy( policy );
}
Expand Down

0 comments on commit 2f81496

Please sign in to comment.