-
Notifications
You must be signed in to change notification settings - Fork 716
Support Deprecation header #1151
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
base: main
Are you sure you want to change the base?
Conversation
|
@dotnet-policy-service agree |
|
Thanks for this. Just acknowledging that I've seen it. I'll try to put eyes on it ASAP. FYI, I'll be on vacation next week. I'm not ignoring it. 😉 |
|
Have you had any chance to look at this yet? |
commonsensesoftware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, it looks great. I'd estimate that 90%+ of the work is there. There are a few open questions and minor tweaks to address, but this looks close to landing.
examples/AspNetCore/OData/ODataOpenApiExample/ConfigureSwaggerOptions.cs
Show resolved
Hide resolved
src/Abstractions/src/Asp.Versioning.Abstractions/ISunsetPolicyManager.cs
Outdated
Show resolved
Hide resolved
src/Abstractions/src/Asp.Versioning.Abstractions/DeprecationPolicy.cs
Outdated
Show resolved
Hide resolved
src/Abstractions/src/Asp.Versioning.Abstractions/DeprecationPolicy.cs
Outdated
Show resolved
Hide resolved
src/Abstractions/src/Asp.Versioning.Abstractions/SunsetPolicy.cs
Outdated
Show resolved
Hide resolved
src/Abstractions/src/Asp.Versioning.Abstractions/ISunsetPolicyBuilder.cs
Outdated
Show resolved
Hide resolved
src/AspNetCore/WebApi/src/Asp.Versioning.Mvc.ApiExplorer/ApiDescriptionExtensions.cs
Show resolved
Hide resolved
src/AspNetCore/WebApi/test/Asp.Versioning.Http.Tests/DefaultApiVersionReporterTest.cs
Outdated
Show resolved
Hide resolved
8d1a6b6 to
064c5c9
Compare
|
Thanks for the thorough review! I went through everything and implemented all your suggestions. Hopefully this is in line with what you had in mind. Two or three comments are still open because it wasn't totally clear to me what the best course of action is. |
|
Looking good. I'll be traveling this weekend. With the holiday and traveling, it might be next week before I get to take a serious look. I just wanted you to know that am looking and your efforts are appreciated. 😉 |
|
Bump. Are you still traveling? From your previous comment, it seemed that this was at least going in the right direction, so in the meantime I'm going to get started on getting the tests green again and adding any tests that may be missing. |
|
I am traveling again, but I'm working remote. I'll get eyes on this tonight or tomorrow. Thanks for poking the bear. ;) |
commonsensesoftware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's looking great. I think there are just a few niche cases and then this should be ready to go.
src/Client/src/Asp.Versioning.Http.Client/System.Net.Http/HttpResponseMessageExtensions.cs
Show resolved
Hide resolved
src/Abstractions/src/Asp.Versioning.Abstractions/ISunsetPolicyBuilder.cs
Outdated
Show resolved
Hide resolved
src/Abstractions/test/Asp.Versioning.Abstractions.Tests/IPolicyManagerExtensionsTest.cs
Show resolved
Hide resolved
src/Abstractions/src/Asp.Versioning.Abstractions/IDeprecationPolicyBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
src/Client/src/Asp.Versioning.Http.Client/net#.0/ILoggerExtensions.cs
Outdated
Show resolved
Hide resolved
|
@MGessinger One other important design aspect I wanted to think about and discuss is what we think the intersection of the new deprecation policy should be the existing APIs and metadata. As an example, the A user can specify: [ApiController]
[ApiVersion(0.9, Deprecated = true)]
[Route("[controller]")]
public class ExampleController
{
[HttpGet]
public string Get() => Ok("Demo");
}This controller expresses that it supports version Conversely, options.Policies.Deprecate( 0.9 )
.Effective( DateTimeOffset.Now.AddDays( 60 ) )indicates that all The question becomes "How do we think about precedence?". I think the precedence would be ranked as:
I suspect there's some checks in the implementation that have been missed. Today, things are solely based on |
ISunsetPolicyBuilder and IDeprecationPolicyBuilder contained duplicated functionality. This was extracted into the new interfaces IPolicyWithLink and IPolicyWithEffectiveDate and corresponding extension methods. To avoid naming collisions, the `Effective` method was renamed to `SetEffectiveDate`.
|
I think that precedence makes sense. Although I don't think it matters too much, since the different ways of declaring deprecation aren't particularly conflicting: You can declare deprecation one of various ways, but as soon as one of them is active, your endpoint is deprecated. You can't configure it deprecated one way, and simultaneously configure it "not deprecated" another way. |
|
The place you're looking for is effectively here: Line 72 in a679121
After all deprecated versions are collated and they aren't supported anywhere, they become deprecated in their entirety. This flows down this path: Line 22 in a679121
Now that I'm explaining it thorough, I'm thinking this is a non-issue. The deprecation policy doesn't say you're deprecated; it just says the policy. This is the same as the sunset policy. The policy doesn't mean you're sunset, it's just the policy. Deprecation can be in the past (e.g. since) or future (e.g. will be). In fact, it doesn't even matter if the API deprecated to apply the policy. The more I write, the more I think I may have over-thought it. |
|
I think this is all solid. I have the new OpenAPI stuff done; it's a lot. I didn't want to make it painful for you so I've been working in a parallel branch. I'd like to get this merged so I can rebase. I'd like to get an initial preview release this week. I'm happy to continue the discussion or do some more tweaking and polishing before the final release. I'm about ready to push the button now, but I see some tests appear to be failing. Is that expected? I'll hold off until you confirm, but otherwise I think we're at a good checkpoint. |
|
|
||
| var routes = FlattenRoutes( Configuration.Routes ).ToArray(); | ||
| var policyManager = Configuration.GetSunsetPolicyManager(); | ||
| var sunsetPolicyManager = Configuration.GetSunsetPolicyManager(); |
Check notice
Code scanning / CodeQL
Local scope variable shadows member Note
VersionedApiExplorer.sunsetPolicyManager
| var routes = FlattenRoutes( Configuration.Routes ).ToArray(); | ||
| var policyManager = Configuration.GetSunsetPolicyManager(); | ||
| var sunsetPolicyManager = Configuration.GetSunsetPolicyManager(); | ||
| var deprecationPolicyManager = Configuration.GetDeprecationPolicyManager(); |
Check notice
Code scanning / CodeQL
Local scope variable shadows member Note
VersionedApiExplorer.deprecationPolicyManager
| foreach ( var value in values ) | ||
| { | ||
| if ( LinkHeaderValue.TryParse( value, resolver, out var link ) && | ||
| link.RelationType.Equals( "deprecation", OrdinalIgnoreCase ) ) | ||
| { | ||
| policy.Links.Add( link ); | ||
| } | ||
| } |
Check notice
Code scanning / CodeQL
Missed opportunity to use Where Note
implicitly filters its target sequence
|
Failing tests are definitely not expected. I'll look into those as well as whatever the bot found some time later today and then I'll give you the go once I'm happy! |
|
Tests should be fixed now!
I didn't totally follow on this point, but I'm willing to take your word for it. You mentioned publishing a preview release anyway, I expect that it might surface the most obvious oversights. And if some other constellation shows up later, we can fix it then. For the time being, assuming the tests run through successfully this time, I think this can be merged. |
Add new policy to configure
Deprecationheader fieldAdd a new
DeprecationPolicywhich emits aDeprecationheader when a matching API version is used.Description
An API may emit a
Deprecationheader to inform clients that a resource is/will become deprecated (but may still be available past that point). The newDeprecationPolicyallows users to configure this header, as well as the (optional) associated links. This is analogous to the existingSunsetPolicy.The implementation follows the existing
SunsetPolicy(and associated classes likeSunsetPolicyBuilder,SunsetPolicyManageretc) as closely as possible. In an attempt to minimize code duplication between the two, common functionality was extracted into shared base classes/interfaces. There is still some duplication left over, but I chose what seemed like a reasonable a middle ground between streamlining the two policies, and keeping the code clear.At the time of writing this, no tests have been added yet. Since this is a rather large PR with many changed files, I want a second opinion on the implementation before I start pinning everything down in tests. I did at least verify that the solution compiles.
Design choices
This summarizes the linked issue #1128
The new policy is configured like this:
deprecationas per the spec.Fixes #1128