Skip to content

V10.2.0/support api alias - #34

Merged
gimlichael merged 11 commits into
mainfrom
v10.2.0/support-api-alias
Jul 7, 2026
Merged

V10.2.0/support api alias#34
gimlichael merged 11 commits into
mainfrom
v10.2.0/support-api-alias

Conversation

@gimlichael

Copy link
Copy Markdown
Member

This pull request introduces support for API version aliasing using semantic version formats, making it easier for clients to specify API versions with shortened or compatibility-oriented tokens (like 1, 1.0, or 1.0.0). It adds a new parser for handling these aliases, updates the service registration to use the parser, and includes comprehensive functional tests to ensure compatibility. Documentation and solution files are also updated accordingly.

API Version Alias Support:

  • Added a new ApiVersionAliasParser class that resolves friendly API version aliases (e.g., 1, 1.0, 1.0.0) to canonical ApiVersion instances, with fallback to the default parser. This enables flexible version token handling in APIs.
  • Updated AddRestfulApiVersioning to automatically register the alias parser when a semantic default version is used, and introduced a new AddApiVersionParser extension method for custom parser registration.

Testing:

  • Added a new test project Codebelt.Extensions.Asp.Versioning.FunctionalTests to the solution. [1] [2]
  • Implemented SemanticApiVersionCompatibilityTest and SemanticApiVersionDefaultCompatibilityTest to verify that API endpoints correctly route requests using various semantic version formats and aliases. [1] [2]

Documentation and Solution Updates:

  • Updated .docfx/toc.yml and .docfx/docfx.json to reflect new documentation structure and ensure correct file references. [1] [2]

aicia-bot and others added 10 commits July 7, 2026 18:34
Added comprehensive unit test coverage for SemanticApiVersion compatibility with standard ApiVersion. Tests verify equality, hash code consistency, and parser support for shorthand semantic version formats (major only and major.minor).
Introduced Codebelt.Extensions.Asp.Versioning.FunctionalTests project with end-to-end test scenarios covering production and non-production compatibility use cases. Tests verify semantic version behavior across real middleware and application context. Updated solution file to include the new test project.
Updated namespace documentation and DocFX publishing configuration to reflect semantic version compatibility feature. Clarified behavior of SemanticApiVersion equality and comparison semantics. Updated site navigation and doc build metadata.
The type RestfulApiVersionReader was defined with a filename that did not match its name. Correct the filename to follow naming conventions and improve discoverability.
Add the 'Test' suffix to functional test class names to align with the naming conventions defined in copilot-instructions.md. Improves discoverability and consistency across the test suite.
…ation

Reflect changes in SemanticApiVersion behavior: Equals no longer treats patch-zero versions as equivalent to ApiVersion, and Parse rejects non-fully-qualified semantic versions ('1' and '1.2'). Update test expectations and test method names to document the stricter validation rules.
Normalize line endings from CRLF to LF for consistent source formatting across the codebase.
Introduce a new public API parser that maps friendly version aliases (major, major-minor, major-minor-patch) to their corresponding semantic API versions. This enables callers to use shortened tokens like '1' or '1.2' while the application works with canonical ApiVersion instances. Includes factory methods for single and multiple version support with fallback to default parsing.
Remove the private nested AliasApiVersionParser class from SemanticApiVersionCompatibilityTest and use the newly extracted public ApiVersionAliasParser instead. This eliminates code duplication and leverages the extracted implementation.
@gimlichael gimlichael self-assigned this Jul 7, 2026
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.75000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 99.45%. Comparing base (cf312b0) to head (2ad8a03).

Files with missing lines Patch % Lines
...Extensions.Asp.Versioning/ApiVersionAliasParser.cs 97.05% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #34      +/-   ##
==========================================
- Coverage   99.60%   99.45%   -0.16%     
==========================================
  Files          10       11       +1     
  Lines         510      553      +43     
  Branches       82       86       +4     
==========================================
+ Hits          508      550      +42     
- Misses          2        3       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown

Greptile Summary

This PR introduces ApiVersionAliasParser, which maps short semantic tokens like 1, 1.0, or 1.0.0 to canonical ApiVersion instances, and updates AddRestfulApiVersioning to auto-register this parser when the default API version is a SemanticApiVersion. A new AddApiVersionParser<T> extension method is also added for explicit parser registration, accompanied by a new functional test project.

  • ApiVersionAliasParser (new): Resolves alias tokens before delegating to a configurable fallback parser; factory methods CreateSemanticVersionAlias generate major / major.minor / major.minor.patch aliases for one or more SemanticApiVersion instances.
  • ServiceCollectionExtensions (updated): Auto-registers an alias parser for the default SemanticApiVersion inside AddRestfulApiVersioning, and exposes AddApiVersionParser<T> for registering custom parsers.
  • Functional tests (new): Four test classes covering alias routing, production and non-production semantic versions, and a compatibility baseline with plain ApiVersion endpoints.

Confidence Score: 5/5

Safe to merge; core alias-parsing logic is correct and well-validated. The two findings are design observations about DI registration ordering that do not break anything under the standard .NET single-type resolution path.

The new ApiVersionAliasParser class is straightforward and handles null/empty alias maps with existing Validator guards. The auto-registration logic in AddRestfulApiVersioning is correct for the default case. The only concerns are that AddSingleton in AddApiVersionParser appends rather than replaces when following the documented multi-version pattern, and that SemanticApiVersionDefaultCompatibilityTest ends up overriding the auto-registered parser rather than exercising it. Neither breaks functionality under default DI resolution semantics.

ServiceCollectionExtensions.cs — the interaction between the auto-registration inside AddRestfulApiVersioning and a subsequent AddApiVersionParser call deserves a second look for the double-descriptor concern.

Important Files Changed

Filename Overview
src/Codebelt.Extensions.Asp.Versioning/ApiVersionAliasParser.cs New parser class mapping short semantic aliases to canonical ApiVersion instances; well-structured with appropriate validation and virtual TryParse for extensibility.
src/Codebelt.Extensions.Asp.Versioning/ServiceCollectionExtensions.cs Adds auto-registration of alias parser for SemanticApiVersion defaults and new AddApiVersionParser extension; double-registration concern when auto-registration and explicit AddApiVersionParser are both used.
test/Codebelt.Extensions.Asp.Versioning.FunctionalTests/Codebelt.Extensions.Asp.Versioning.FunctionalTests.csproj New test project; TargetFrameworks, test runner, and package references are all inherited from Directory.Build.props via the EndsWith('Tests') condition.
test/Codebelt.Extensions.Asp.Versioning.FunctionalTests/SemanticApiVersionCompatibilityTest.cs Functional test verifying plain-ApiVersion aliases using a manually-built alias map; DefaultVersion is ApiVersion (not SemanticApiVersion) so auto-registration does not trigger here.
test/Codebelt.Extensions.Asp.Versioning.FunctionalTests/SemanticApiVersionDefaultCompatibilityTest.cs Tests auto-registration + explicit AddApiVersionParser; auto-registers partial aliases for DefaultVersion then explicitly overrides with full alias map, leaving two IApiVersionParser registrations in DI.
test/Codebelt.Extensions.Asp.Versioning.FunctionalTests/SemanticApiVersionNonProductionTest.cs Tests full semantic version strings (pre-release + build metadata) with SemanticApiVersionParser.Default; correctly overrides auto-registered alias parser.
test/Codebelt.Extensions.Asp.Versioning.FunctionalTests/SemanticApiVersionProductionTest.cs Tests production-style semantic version routing with SemanticApiVersionParser.Default; mirrors NonProductionTest structure for release semantic versions.
test/Codebelt.Extensions.Asp.Versioning.Tests/SemanticApiVersionTest.cs Adds two equality tests confirming SemanticApiVersion and ApiVersion are not equal even when major/minor match; important for alias parser correctness.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Client
    participant Reader as RestfulApiVersionReader
    participant Alias as ApiVersionAliasParser
    participant Fallback as DefaultParser
    participant Router as AspVersioningRouter

    Client->>Reader: "v=1 in Accept header"
    Reader->>Alias: TryParse 1
    alt alias match
        Alias-->>Reader: SemanticApiVersion 1.0.0
    else no alias found
        Alias->>Fallback: TryParse 1
        Fallback-->>Alias: ApiVersion 1.0
        Alias-->>Reader: ApiVersion 1.0
    end
    Reader->>Router: resolved ApiVersion
    Router-->>Client: 204 No Content
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Client
    participant Reader as RestfulApiVersionReader
    participant Alias as ApiVersionAliasParser
    participant Fallback as DefaultParser
    participant Router as AspVersioningRouter

    Client->>Reader: "v=1 in Accept header"
    Reader->>Alias: TryParse 1
    alt alias match
        Alias-->>Reader: SemanticApiVersion 1.0.0
    else no alias found
        Alias->>Fallback: TryParse 1
        Fallback-->>Alias: ApiVersion 1.0
        Alias-->>Reader: ApiVersion 1.0
    end
    Reader->>Router: resolved ApiVersion
    Router-->>Client: 204 No Content
Loading

Reviews (2): Last reviewed commit: "🐛 fix and clarify semantic version alia..." | Re-trigger Greptile

Comment thread test/Codebelt.Extensions.Asp.Versioning.Tests/SemanticApiVersionTest.cs Outdated
Clarify the ApiVersionAliasParser behavior in AddRestfulApiVersioning remarks and explain when applications need to explicitly register additional aliases. Fix incorrect test class reference in SemanticApiVersionDefaultCompatibilityTest constructor and correct the invalid version string in SemanticApiVersionTest assertion.
@gimlichael
gimlichael merged commit 28d53e2 into main Jul 7, 2026
22 of 24 checks passed
@gimlichael
gimlichael deleted the v10.2.0/support-api-alias branch July 7, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants