-
Notifications
You must be signed in to change notification settings - Fork 717
Add [IntroducedInApiVersion] attribute (closes #1183) #1184
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
Open
xavierjohn
wants to merge
26
commits into
dotnet:main
Choose a base branch
from
xavierjohn:feature/introduced-in-api-version
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
112373d
Add introduced-in API version attribute
xavierjohn 061b136
Fix introduced-in version routing
xavierjohn 991b14c
Fix introduced-in attribute equality and docs
xavierjohn ead80dd
Align introduced-in routing status selection
xavierjohn 469e4f5
Define introduced-in convention edge cases
xavierjohn 94c0814
Demonstrate IntroducedInApiVersion in BasicExample
xavierjohn 5a80710
Use exact type for introduced version equality
xavierjohn 658a0f6
Materialize introduced version mappings
xavierjohn 865f35d
Stabilize introduced-later routing errors
xavierjohn aac5a7d
Support introduced minimal API endpoints
xavierjohn 86b2f1f
Compare edge keys by fields
xavierjohn c1207f8
Demonstrate IntroducedInApiVersion in MinimalApiExample
xavierjohn 0690b02
Demonstrate IntroducedInApiVersion in OpenApiExample
xavierjohn 29e5d72
Stabilize introduced slow-path status selection
xavierjohn 9335920
Clarify mapped version constraint docs
xavierjohn 5ab4956
Write problem details for introduced endpoints
xavierjohn b532bf6
Apply introduced-in precedence across candidates
xavierjohn db53e29
Drop introduced metadata from neutral endpoints
xavierjohn 3db2ee1
Populate URL segment version for introduced endpoints
xavierjohn ff5ed87
Add introduced-in MVC action conventions
xavierjohn 0eb7922
Add summary to introduced-in convention extension block
xavierjohn 6a455a3
Intersect introduced action supported versions
xavierjohn 1baa005
Restore action convention interface shape
xavierjohn bbdb874
Expand minimal API introduced versions
xavierjohn 513fa4c
Recognize introduced type in ErrorObjectWriter
xavierjohn 0402e70
Share introduced metadata instances in MVC convention apply
xavierjohn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
examples/AspNetCore/WebApi/OpenApiExample/Controllers/MultiVersionedController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| namespace ApiVersioning.Examples.Controllers; | ||
|
|
||
| using Asp.Versioning; | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| /// <summary> | ||
| /// Demonstrates [MapToApiVersion] (exact-match) vs. [IntroducedInApiVersion] | ||
| /// (from-this-version-onward) on a single controller declaring multiple versions. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// Open the Scalar UI per version (1.0, 2.0, 3.0) to see how the two attributes | ||
| /// affect the OpenAPI surface differently: | ||
| /// </para> | ||
| /// <list type="bullet"> | ||
| /// <item><description>v1.0 — only the shared <c>GET</c> appears.</description></item> | ||
| /// <item><description> | ||
| /// v2.0 — shared <c>GET</c>, <c>/legacy</c>, and <c>/modern</c> all appear. | ||
| /// </description></item> | ||
| /// <item><description> | ||
| /// v3.0 — shared <c>GET</c> and <c>/modern</c> appear; <c>/legacy</c> is filtered out | ||
| /// because <c>[MapToApiVersion(2.0)]</c> is exact-match. <c>/modern</c> is | ||
| /// present without any code change because <c>[IntroducedInApiVersion(2.0)]</c> | ||
| /// means "from v2.0 onward against the controller's declared set." | ||
| /// </description></item> | ||
| /// </list> | ||
| /// </remarks> | ||
| [ApiVersion( 1.0 )] | ||
| [ApiVersion( 2.0 )] | ||
| [ApiVersion( 3.0 )] | ||
| [Route( "api/[controller]" )] | ||
| public class MultiVersionedController : ControllerBase | ||
| { | ||
| /// <summary> | ||
| /// Get the resource (shared across all versions). | ||
| /// </summary> | ||
| /// <param name="version">The requested API version.</param> | ||
| /// <returns>A version-tagged response.</returns> | ||
| /// <response code="200">The resource was retrieved.</response> | ||
| [HttpGet] | ||
| [Produces( "application/json" )] | ||
| [ProducesResponseType( typeof( object ), 200 )] | ||
| public IActionResult Get( ApiVersion version ) => | ||
| Ok( new { version = version.ToString(), shared = true } ); | ||
|
|
||
| /// <summary> | ||
| /// A v2-only endpoint declared with <c>[MapToApiVersion(2.0)]</c>. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Reachable ONLY for v2.0. v1.0 and v3.0 callers receive the configured | ||
| /// <c>UnsupportedApiVersionStatusCode</c> (default 400). When v3.0 was | ||
| /// added to this controller's <c>[ApiVersion]</c> declarations, this | ||
| /// action did NOT automatically participate; if v3.0 should reach it, the | ||
| /// attribute must be edited to | ||
| /// <c>[MapToApiVersion(2.0, 3.0)]</c>. | ||
| /// </remarks> | ||
| /// <param name="version">The requested API version.</param> | ||
| /// <response code="200">Reached the v2-only endpoint.</response> | ||
| [HttpGet( "legacy" ), MapToApiVersion( 2.0 )] | ||
| [Produces( "application/json" )] | ||
| [ProducesResponseType( typeof( object ), 200 )] | ||
| public IActionResult GetLegacy( ApiVersion version ) => | ||
| Ok( new { version = version.ToString(), legacy = true } ); | ||
|
|
||
| /// <summary> | ||
| /// An endpoint introduced in v2.0 declared with <c>[IntroducedInApiVersion(2.0)]</c>. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Reachable for v2.0 AND v3.0 automatically. v1.0 callers receive the | ||
| /// per-attribute status (default 404), distinguishable from "version | ||
| /// unknown" (still 400). When v4.0 is added to this controller's | ||
| /// <c>[ApiVersion]</c> declarations, this action becomes reachable for | ||
| /// v4.0 with no further changes. | ||
| /// </remarks> | ||
| /// <param name="version">The requested API version.</param> | ||
| /// <response code="200">Reached the v2-onwards endpoint.</response> | ||
| /// <response code="404">The endpoint did not exist in the requested version.</response> | ||
| [HttpGet( "modern" ), IntroducedInApiVersion( 2.0 )] | ||
| [Produces( "application/json" )] | ||
| [ProducesResponseType( typeof( object ), 200 )] | ||
| [ProducesResponseType( 404 )] | ||
| public IActionResult GetModern( ApiVersion version ) => | ||
| Ok( new { version = version.ToString(), modern = true } ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...s/src/Asp.Versioning.Abstractions/Conventions/IIntroducedInApiVersionConventionBuilder.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
|
|
||
| namespace Asp.Versioning.Conventions; | ||
|
|
||
| /// <summary> | ||
| /// Defines the behavior of convention builder that builds introduced API versions. | ||
| /// </summary> | ||
| public interface IIntroducedInApiVersionConventionBuilder : IMapToApiVersionConventionBuilder | ||
| { | ||
| /// <summary> | ||
| /// Indicates that the configured controller action was introduced in the specified API version. | ||
| /// </summary> | ||
| /// <param name="apiVersion">The <see cref="ApiVersion">API version</see> the action was introduced in.</param> | ||
| /// <param name="statusCode">The HTTP status code for earlier API versions.</param> | ||
| void IntroducedInApiVersion( ApiVersion apiVersion, int statusCode ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.