diff --git a/src/AspNetCore/WebApi/src/Asp.Versioning.Http/Routing/ApiVersionPolicyJumpTable.cs b/src/AspNetCore/WebApi/src/Asp.Versioning.Http/Routing/ApiVersionPolicyJumpTable.cs index e2d32a26..fc1e8866 100644 --- a/src/AspNetCore/WebApi/src/Asp.Versioning.Http/Routing/ApiVersionPolicyJumpTable.cs +++ b/src/AspNetCore/WebApi/src/Asp.Versioning.Http/Routing/ApiVersionPolicyJumpTable.cs @@ -63,17 +63,18 @@ public override int GetDestination( HttpContext httpContext ) switch ( apiVersions.Count ) { case 0: - // 1. version-neutral endpoints take precedence - if ( destinations.TryGetValue( ApiVersion.Neutral, out destination ) ) + // 1. IApiVersionSelector cannot be used yet because there are no candidates that an + // aggregated version model can be computed from to select the default API version. + // version-neutral endpoints are still included in these candidates + if ( options.AssumeDefaultVersionWhenUnspecified ) { - return destination; + return rejection.AssumeDefault; } - // 2. IApiVersionSelector cannot be used yet because there are no candidates that an - // aggregated version model can be computed from to select the 'default' API version - if ( options.AssumeDefaultVersionWhenUnspecified ) + // 2. use version-neutral endpoints, if any + if ( destinations.TryGetValue( ApiVersion.Neutral, out destination ) ) { - return rejection.AssumeDefault; + return destination; } httpContext.Features.Set( policyFeature ); diff --git a/src/AspNetCore/WebApi/src/Asp.Versioning.Http/Routing/EdgeBuilder.cs b/src/AspNetCore/WebApi/src/Asp.Versioning.Http/Routing/EdgeBuilder.cs index 621cf185..9aeae37e 100644 --- a/src/AspNetCore/WebApi/src/Asp.Versioning.Http/Routing/EdgeBuilder.cs +++ b/src/AspNetCore/WebApi/src/Asp.Versioning.Http/Routing/EdgeBuilder.cs @@ -57,12 +57,18 @@ public void Add( RouteEndpoint endpoint ) public void Add( RouteEndpoint endpoint, ApiVersion apiVersion, ApiVersionMetadata metadata ) { - // use a singleton of all route patterns that version by url segment. this - // is needed to extract the value for selecting a destination in the jump - // table. any matching template will do and every edge should have the - // same list known through the application, which may be zero + // use a singleton of all route patterns that version by url segment. this is needed to extract the value for + // selecting a destination in the jump table. any matching template will do and every edge should have the same + // list known through the application, which may be zero var key = new EdgeKey( apiVersion, metadata, routePatterns ); + Add( ref key, endpoint ); + + // include version-neutral endpoints when assuming the default so they are also considered when unspecified + if ( unspecifiedAllowed && metadata.IsApiVersionNeutral && apiVersion == ApiVersion.Neutral ) + { + Add( ref assumeDefault, endpoint ); + } } private void Add( ref EdgeKey key, RouteEndpoint endpoint )