File tree Expand file tree Collapse file tree 2 files changed +18
-11
lines changed
src/AspNetCore/WebApi/src/Asp.Versioning.Http/Routing Expand file tree Collapse file tree 2 files changed +18
-11
lines changed Original file line number Diff line number Diff line change @@ -63,17 +63,18 @@ public override int GetDestination( HttpContext httpContext )
6363 switch ( apiVersions . Count )
6464 {
6565 case 0 :
66- // 1. version-neutral endpoints take precedence
67- if ( destinations . TryGetValue ( ApiVersion . Neutral , out destination ) )
66+ // 1. IApiVersionSelector cannot be used yet because there are no candidates that an
67+ // aggregated version model can be computed from to select the default API version.
68+ // version-neutral endpoints are still included in these candidates
69+ if ( options . AssumeDefaultVersionWhenUnspecified )
6870 {
69- return destination ;
71+ return rejection . AssumeDefault ;
7072 }
7173
72- // 2. IApiVersionSelector cannot be used yet because there are no candidates that an
73- // aggregated version model can be computed from to select the 'default' API version
74- if ( options . AssumeDefaultVersionWhenUnspecified )
74+ // 2. use version-neutral endpoints, if any
75+ if ( destinations . TryGetValue ( ApiVersion . Neutral , out destination ) )
7576 {
76- return rejection . AssumeDefault ;
77+ return destination ;
7778 }
7879
7980 httpContext . Features . Set ( policyFeature ) ;
Original file line number Diff line number Diff line change @@ -57,12 +57,18 @@ public void Add( RouteEndpoint endpoint )
5757
5858 public void Add ( RouteEndpoint endpoint , ApiVersion apiVersion , ApiVersionMetadata metadata )
5959 {
60- // use a singleton of all route patterns that version by url segment. this
61- // is needed to extract the value for selecting a destination in the jump
62- // table. any matching template will do and every edge should have the
63- // same list known through the application, which may be zero
60+ // use a singleton of all route patterns that version by url segment. this is needed to extract the value for
61+ // selecting a destination in the jump table. any matching template will do and every edge should have the same
62+ // list known through the application, which may be zero
6463 var key = new EdgeKey ( apiVersion , metadata , routePatterns ) ;
64+
6565 Add ( ref key , endpoint ) ;
66+
67+ // include version-neutral endpoints when assuming the default so they are also considered when unspecified
68+ if ( unspecifiedAllowed && metadata . IsApiVersionNeutral && apiVersion == ApiVersion . Neutral )
69+ {
70+ Add ( ref assumeDefault , endpoint ) ;
71+ }
6672 }
6773
6874 private void Add ( ref EdgeKey key , RouteEndpoint endpoint )
You can’t perform that action at this time.
0 commit comments