Add Versioning Support via Asp.Versioning#422
Open
jayharris wants to merge 4 commits intoivaylokenov:developmentfrom
Open
Add Versioning Support via Asp.Versioning#422jayharris wants to merge 4 commits intoivaylokenov:developmentfrom
jayharris wants to merge 4 commits intoivaylokenov:developmentfrom
Conversation
…g to Asp.Versioning.Mvc Replace deprecated Microsoft.AspNetCore.Mvc.Versioning v5.1.0 with Asp.Versioning.Mvc v8.1.1 and update all namespace references from Microsoft.AspNetCore.Mvc.Versioning to Asp.Versioning across plugin source and test projects.
Asp.Versioning.Mvc no longer provides a custom IActionSelector for legacy routing (it relies on endpoint routing middleware instead). Since MyTested disables endpoint routing, this adds: - ApiVersionActionConstraint: filters actions during route matching to prevent ambiguous match errors on versioned controllers - ApiVersionActionConstraintProvider: registers the constraint for actions with API version metadata - ApiVersionAwareActionSelector: decorator around IActionSelector that filters candidates by requested API version for query string versioning scenarios - Updated VersioningTestPlugin to implement IServiceRegistrationPlugin and IRoutingServiceRegistrationPlugin for proper service registration
…ng controller tests Add support for reading API version from x-api-version request header in both ApiVersionAwareActionSelector and ApiVersionActionConstraint. Extend test coverage with 24 new tests covering: - Header-based version routing and pipeline assertions - Version-neutral controllers for query-string and header routing - Multiple controllers competing for the same route at different versions across URL-segment, query-string, and header strategies
…dcoded keys
Replace hardcoded query string ("api-version") and header
("x-api-version") version extraction with the user-configured
IApiVersionReader resolved from IOptions<ApiVersioningOptions>.
This ensures the plugin respects custom reader keys configured via
AddApiVersioning(). Tests updated to use non-default keys ("v" for
query string, "X-Custom-Version" for header) to prove the
configuration is honored.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Overview
Microsoft.AspNetCore.Mvc.Versioningv5.1.0 toAsp.Versioning.Mvcv8.1.1This will close #421
Details
The
MyTested.AspNetCore.Mvc.Versioningplugin currently depends on the deprecatedMicrosoft.AspNetCore.Mvc.Versioningv5.1.0. The replacement package isAsp.Versioning.Mvc, currently in v8.1.1. The challenge is that the old package registered a customApiVersionActionSelectorasIActionSelectorwhich handled version-aware action filtering in the legacy routing pipeline. The new package no longer provides this; it relies onApiVersionMatcherPolicyvia endpoint routing. Since MyTested disables endpoint routing (EnableEndpointRouting = false), version filtering won't happen, causing ambiguous match errors.The solution is to swap packages to
Asp.Versioning.Mvc, update namespaces, and implement a customIActionSelectordecorator in the plugin that restores version-aware action selection.Further Enhancements
Further, because
Asp.Versioningallows developers to resolve version by HTTP Header, and also allows developers to configure custom keys viaApiVersioningOptions.ApiVersionReader(e.g.,QueryStringApiVersionReader("v"),HeaderApiVersionReader("X-Custom-Version")), we have enhanced theGetRequestedApiVersionmethods to support Header resolution and to read the configured keys from the library's ownIApiVersionReaderat request time usingIOptions<ApiVersioningOptions>.