grape-route-helpers icon indicating copy to clipboard operation
grape-route-helpers copied to clipboard

Searching for helper stops with first possible match

Open To1ne opened this issue 7 years ago • 1 comments

We have a route :id/repository/tags and a route :id/repository/tags/:tag_name, both generate the route helper api_v4_projects_repository_tags_path.

Calling api_v4_projects_repository_tags_path(id: 123) returns /api/v4/projects/123/repository/tags, but calling api_v4_projects_repository_tags_path(id: 123, tag_name: 'foo') returns the exact same path. While it actually should return /api/v4/projects/123/repository/tags/foo.

We have the grape endpoint defined get ':id/repository/tags' first and get ':id/repository/tags/:tag_name' below that. If we swap the order, the correct route helper is found and the correct path is returned depending on the parameters.

See the full grape definition here: https://gitlab.com/gitlab-org/gitlab-ce/blob/547b458e254bdb271d8ff41e62217fa7f3cf9c87/lib/api/tags.rb#L13-40

To1ne avatar Jan 16 '18 09:01 To1ne

I gonna try if I can create an PR for this soon.

To1ne avatar Jan 16 '18 09:01 To1ne