Skip to content

fix(http): honor [RoutePrefix] when no global prefix is configured#2708

Merged
jeremydmiller merged 1 commit intoJasperFx:mainfrom
outofrange-consulting:http-versioning-routeprefix
May 8, 2026
Merged

fix(http): honor [RoutePrefix] when no global prefix is configured#2708
jeremydmiller merged 1 commit intoJasperFx:mainfrom
outofrange-consulting:http-versioning-routeprefix

Conversation

@outofrange-consulting
Copy link
Copy Markdown

Fixes #2705.

RoutePrefixPolicy.Apply had an early-exit that skipped iterating chains whenever there was no GlobalRoutePrefix and no NamespacePrefixes. That short-circuit also bypassed the per-handler [RoutePrefix] attribute, so a class-level prefix declared on its own was silently dropped.

You normally wouldn't notice — the route just ended up missing one segment. API Versioning made it obvious because the version-segment policy still ran and produced things like /v1/create instead of /v1/items/create for:

[RoutePrefix("items")]
public static class TodoCreationEndpoint
{
    [WolverinePost("/create")]
    public static void Post() { }
}

The fix is just to drop the early-exit. DeterminePrefix already returns null when nothing applies, so the loop is a no-op for chains without any prefix.

Tests

  • apply_honors_attribute_prefix_when_no_global_or_namespace_prefix_configured — unit test for the Apply path that wasn't covered before (existing tests only exercised DeterminePrefix in isolation, which never tripped the bug).
  • gh_2705_attribute_prefix_combines_with_api_versioning — exact reproduction from the issue: [RoutePrefix("items")] + [WolverinePost("/create")] + versioning with DefaultVersion = ApiVersion(1) and UnversionedPolicy.AssignDefault. Asserts the final route is /v1/items/create.

Verified red → green by stashing the fix (test fails with /v1/create) and restoring it.

…configured

RoutePrefixPolicy.Apply was bailing out before iterating chains when neither
GlobalRoutePrefix nor any NamespacePrefixes was set, which meant per-handler
[RoutePrefix] attributes were silently ignored. The bug only became visible
once API Versioning landed: the version-segment policy still ran and produced
routes like /v1/create instead of /v1/items/create.

Closes JasperFx#2705
@jeremydmiller
Copy link
Copy Markdown
Member

@outofrange-consulting Thank you!

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.

[RoutePrefix] is completely ignored when API Versioning is enabled

2 participants