Skip to content

Correct sunset policy resolution when falling back #1065

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

Merged
merged 1 commit into from
Mar 20, 2024
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
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