Skip to content

fix: route ordering and duplicate registration for io/variations/map#1249

Merged
ivladu-plenty merged 5 commits into
stablefrom
copilot/fix-route-ordering-bug
May 27, 2026
Merged

fix: route ordering and duplicate registration for io/variations/map#1249
ivladu-plenty merged 5 commits into
stablefrom
copilot/fix-route-ordering-bug

Conversation

Copilot AI commented May 27, 2026

Copy link
Copy Markdown
Contributor

Laravel/Lumen's first-match-wins routing caused GET /io/variations/map to be captured by the io/variations resource route (treating map as {id}), never reaching VariationAttributeMapResource. Additionally, io/variations was registered twice — once with throttle middleware and again in the large unthrottled block.

Changes

  • Route ordering: Extracted io/variations/map into its own $api->version() block placed before the throttled io/variations resource registration, ensuring the more-specific path is matched first.
  • Duplicate removed: Dropped both $api->get('io/variations/map', ...) and $api->resource('io/variations', 'VariationResource') from the large unthrottled block.
// Before (wrong order — map was after the resource, unreachable):
$api->version(['v1'], [...'throttleFrontend:variations'...], fn($api) => $api->resource('io/variations', 'VariationResource'));
// ...then later in the unthrottled block:
$api->get('io/variations/map', 'VariationAttributeMapResource@index');  // never matched
$api->resource('io/variations', 'VariationResource');                   // duplicate

// After (specific route first, no duplicate):
$api->version(['v1'], ['namespace' => 'IO\Api\Resources'], fn($api) => $api->get('io/variations/map', 'VariationAttributeMapResource@index'));
$api->version(['v1'], [...'throttleFrontend:variations'...], fn($api) => $api->resource('io/variations', 'VariationResource'));
Original prompt

Fix route ordering bug in IORouteServiceProvider

File: src/Providers/IORouteServiceProvider.php

Problem

There are two bugs in the API route registration inside map():

  1. Wrong registration order: The throttled io/variations resource block is registered earlier in the file than io/variations/map. Because Laravel/Lumen route matching is first-match-wins, a GET /io/variations/map request hits the io/variations resource route first and treats map as a variation {id} — never reaching VariationAttributeMapResource.

  2. Duplicate route: $api->resource('io/variations', 'VariationResource'); appears twice:

    • Once in the throttled block (middleware => ['throttleFrontend:variations']) around line 55.
    • Again in the large unthrottled block later on.

Fix

  1. Remove the duplicate $api->resource('io/variations', 'VariationResource'); from the large unthrottled $api->version() block.
  2. Register io/variations/map in its own $api->version(['v1'], ['namespace' => 'IO\Api\Resources'], ...) block that is placed before the throttled io/variations block, so that the more-specific route is matched first.

The end result should be that:

  • GET /io/variations/map is handled by VariationAttributeMapResource@index.
  • All other /io/variations routes are handled by VariationResource (with throttle middleware).
  • There are no duplicate route registrations for io/variations.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: The problem:
You moved the pattern 'io/variations' in front of 'io/variations/map'

now every call to /map routes to the first one which is not what we want and you forgot to delete the existing one

Assistant: Looking at the file, there are two issues:

  1. The throttled io/variations resource block is registered before io/variations/map in the unthrottled block — so incoming requests to /io/variations/map match the earlier resource route and treat map as an {id}.
  2. io/variations is registered twice (once with the throttle middleware around line 55, and again in the unthrottled block).

The fix is to:

  • Move io/variations/map into its own $api->version() block before the throttled io/variations block.
  • Remove the duplicate $api->resource('io/variations', 'VariationResource'); from the unthrottled block.

Assistant: A pull request has been created to fix both issues in IORouteServiceProvider.php:

  1. Route ordering: io/variations/map is registered in its own block before the io/variations resource, so the more-specific route is matched first.
  2. Duplicate removed: The second $api->resource('io/variations', 'VariationResource'); in the large unthrottled block is deleted.

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Fix route ordering bug in IORouteServiceProvider Fix route ordering and duplicate registration for io/variations/map May 27, 2026
Copilot AI requested a review from ivladu-plenty May 27, 2026 08:13
@ivladu-plenty ivladu-plenty changed the title Fix route ordering and duplicate registration for io/variations/map fix: route ordering and duplicate registration for io/variations/map May 27, 2026
@ivladu-plenty ivladu-plenty marked this pull request as ready for review May 27, 2026 08:15
@ivladu-plenty ivladu-plenty requested a review from a team as a code owner May 27, 2026 08:15
@ivladu-plenty ivladu-plenty enabled auto-merge May 27, 2026 08:37
@ivladu-plenty ivladu-plenty merged commit 329380d into stable May 27, 2026
3 checks passed
@ivladu-plenty ivladu-plenty deleted the copilot/fix-route-ordering-bug branch May 27, 2026 08:38
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.

4 participants