-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Support Deprecated in Minimal APIs for Open API #35091
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
Comments
How common is this? Is this even possible today with controllers? cc @bradygaster |
Yes it is. And in NSwag it will check But in both case they are looking for
|
Yeah I've used this with MVC too. There's a first-class method to configure it built into Swashbuckle (doc). options.IgnoreObsoleteActions(); I guess given that minimal actions are brand new, adding |
@davidfowl IMO not common enough; folks tend to just delete the code and deploy to a new spot. i'm a fan of the proposed API above I thumbed-up in minimal; that said, i've seen few folks talk about obsolescence and deprecation explicitly in their APIs so i'm not sure there's customer justification for it aside from anecdotal. But maybe folks can comment here in support for the explicit support. |
Deprecation is different from being obsolete (e.g. it's gone). This has been supported in API Versioning from the very beginning. The issue is that there is no way to express this in the API Explorer today. This example shows how the information is bridged between API Versioning and an OpenAPI generator such as Swashbuckle or NSwag. Ultimately, what is needed to fill this void is to add a new property /// <summary>
/// Gets or sets a value indicating whether an API is deprecated.
/// </summary>
public bool IsDeprecated { get; set; } This would connect to the producers (ex: API Versioning) with the consumers (ex: Swashbuckle/NSwag) of this information. Honoring it is up to the implementers. I don't know that @davidfowl has asked for Minimal APIs with API Versioning and it's coming. I have something working. I hope to have, at least the code, available for review and/or comment by week's end. A deprecated Minimal API in API Versioning would look like: app.DefineApi()
.HasDeprecatedApiVersion(1.0)
.HasMapping(api => api.MapGet("/hello-world", () => "Hello world")); |
It's a bit of a sidebar, but it is related to this discussion. API Versioning 6.0+ will also bring support for RFC 8594. This will allow APIs to define a sunset policy. For example: app.Services.AddApiVersioning(
options => options.Policies
.Sunset(1.0)
.Effective(2022, 4, 1)
.Link("api-policy.html")
.Title("Versioning Policy")
.Type("text/html")
.Language("en"); This indicates that API version The relevance to this discussion is that if we're going to add more metadata to /// <summary>
/// Gets or sets the API sunset date and time.
/// </summary>
/// <value>The date and time when the API will be permanently sunset (e.g. no longer exist).</value>
public DateTimeOffset? SunsetDate { get; set; } API Versioning will be supporting links in accordance with RFC 8288, but that doesn't necessarily have to be fully exposed in the API Explorer. It's not a deal breaker, but I think it would be nice to have some formal subset of the most common link properties such as public IList<ApiDescriptionLink> Links { get; } = new List<ApiDescriptionLink>(); If this type of metadata isn't supported, then developers are stuck having to create their own bridges as is the case today. The existing cc: @davidfowl , @bradygaster |
@captainsafia I'm interested in doing this. Do you accept PR for this issue at the moment? |
At the moment, we've departed from our approach of using metadata/attributes for annotating endpoints in MinimalApis in favor of the app.MapGet()
.WithOpenApi(o => {
o.Deprecated = true;
}); I'm not sure if this is helpful enough for API versioning (and that's probably a separate issue) but this is solved strictly for OpenAPI + minimal now. |
Oh I see, thanks for your explanation. So I guess this issue could be closed. |
@captainsafia this would be a fail for API Versioning, which doesn't directly care or depend on any part of OpenAPI nor Swashbuckle or any other OpenAPI document generator. The bridge between these concepts has always been through the API Explorer. Marking an API deprecated in OpenAPI is nice to surface, but that is one very specific use case. If you wanted to know or make decisions about a deprecated API when you are not using OpenAPI, there is no clear way to do this today. If This isn't necessarily specific to Minimal APIs, so if a new issue is required, then so be it; however, I feel this issue should be potentially reopened and re-evaluated. Adding a single property that can bridge this gap provides customer value for almost nil engineering effort. If library authors and consumers use this new property, great. If not, there is very little risk or cost. |
@commonsensesoftware Yep, I think a separate issue makes sense for the API versioning case. This one was specifically around minimal + OpenAPI which is a lot more scoped than the problem identified here. It might help to include other configurable metadata that API versioning would need in that issue. I know there have been separate threads about route groups + versioning as well. |
Background and Motivation
Mark action deprecated in Minimal APIs, so it could be shown in Open API.

Proposed API
Usage Examples
The text was updated successfully, but these errors were encountered: