Commit 2370ff85 authored by Jan Provaznik's avatar Jan Provaznik

Optional '/-/' delimiter for search API

'/-/' delimiter is used only in UI, in API we don't use it for
other endpoints. To align search endpoints with the rest of API
endpoints, this patch makes '/-/' optional for existing endpoints (to
keep backward compatibility).

Documentation is updated to prefer paths without '/-/'.
parent cd4ddee0
---
title: Make /-/ delimiter optional for search endpoints
merge_request:
author:
type: changed
...@@ -289,7 +289,7 @@ Search within the specified group. ...@@ -289,7 +289,7 @@ Search within the specified group.
If a user is not a member of a group and the group is private, a `GET` request on that group will result to a `404` status code. If a user is not a member of a group and the group is private, a `GET` request on that group will result to a `404` status code.
``` ```
GET /groups/:id/-/search GET /groups/:id/search
``` ```
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
...@@ -305,7 +305,7 @@ The response depends on the requested scope. ...@@ -305,7 +305,7 @@ The response depends on the requested scope.
### Scope: projects ### Scope: projects
```bash ```bash
curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/groups/3/-/search?scope=projects&search=flight curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/groups/3/search?scope=projects&search=flight
``` ```
Example response: Example response:
...@@ -336,7 +336,7 @@ Example response: ...@@ -336,7 +336,7 @@ Example response:
### Scope: issues ### Scope: issues
```bash ```bash
curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/groups/3/-/search?scope=issues&search=file curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/groups/3/search?scope=issues&search=file
``` ```
Example response: Example response:
...@@ -401,7 +401,7 @@ Example response: ...@@ -401,7 +401,7 @@ Example response:
### Scope: merge_requests ### Scope: merge_requests
```bash ```bash
curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/groups/3/-/search?scope=merge_requests&search=file curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/groups/3/search?scope=merge_requests&search=file
``` ```
Example response: Example response:
...@@ -478,7 +478,7 @@ Example response: ...@@ -478,7 +478,7 @@ Example response:
### Scope: milestones ### Scope: milestones
```bash ```bash
curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/groups/3/-/search?scope=milestones&search=release curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/groups/3/search?scope=milestones&search=release
``` ```
Example response: Example response:
...@@ -507,7 +507,7 @@ Search within the specified project. ...@@ -507,7 +507,7 @@ Search within the specified project.
If a user is not a member of a project and the project is private, a `GET` request on that project will result to a `404` status code. If a user is not a member of a project and the project is private, a `GET` request on that project will result to a `404` status code.
``` ```
GET /projects/:id/-/search GET /projects/:id/search
``` ```
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
...@@ -524,7 +524,7 @@ The response depends on the requested scope. ...@@ -524,7 +524,7 @@ The response depends on the requested scope.
### Scope: issues ### Scope: issues
```bash ```bash
curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/12/-/search?scope=issues&search=file curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/12/search?scope=issues&search=file
``` ```
Example response: Example response:
...@@ -589,7 +589,7 @@ Example response: ...@@ -589,7 +589,7 @@ Example response:
### Scope: merge_requests ### Scope: merge_requests
```bash ```bash
curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/6/-/search?scope=merge_requests&search=file curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/6/search?scope=merge_requests&search=file
``` ```
Example response: Example response:
...@@ -666,7 +666,7 @@ Example response: ...@@ -666,7 +666,7 @@ Example response:
### Scope: milestones ### Scope: milestones
```bash ```bash
curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/12/-/search?scope=milestones&search=release curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/12/search?scope=milestones&search=release
``` ```
Example response: Example response:
...@@ -691,7 +691,7 @@ Example response: ...@@ -691,7 +691,7 @@ Example response:
### Scope: notes ### Scope: notes
```bash ```bash
curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/6/-/search?scope=notes&search=maxime curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/6/search?scope=notes&search=maxime
``` ```
Example response: Example response:
...@@ -723,7 +723,7 @@ Example response: ...@@ -723,7 +723,7 @@ Example response:
### Scope: wiki_blobs ### Scope: wiki_blobs
```bash ```bash
curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/6/-/search?scope=wiki_blobs&search=bye curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/6/search?scope=wiki_blobs&search=bye
``` ```
Example response: Example response:
...@@ -746,7 +746,7 @@ Example response: ...@@ -746,7 +746,7 @@ Example response:
### Scope: commits ### Scope: commits
```bash ```bash
curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/6/-/search?scope=commits&search=bye curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/6/search?scope=commits&search=bye
``` ```
Example response: Example response:
...@@ -777,7 +777,7 @@ Example response: ...@@ -777,7 +777,7 @@ Example response:
### Scope: blobs ### Scope: blobs
```bash ```bash
curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/6/-/search?scope=blobs&search=installation curl --request GET --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/6/search?scope=blobs&search=installation
``` ```
Example response: Example response:
......
...@@ -84,7 +84,7 @@ module API ...@@ -84,7 +84,7 @@ module API
values: %w(projects issues merge_requests milestones) values: %w(projects issues merge_requests milestones)
use :pagination use :pagination
end end
get ':id/-/search' do get ':id/(-/)search' do
present search(group_id: user_group.id), with: entity present search(group_id: user_group.id), with: entity
end end
end end
...@@ -103,7 +103,7 @@ module API ...@@ -103,7 +103,7 @@ module API
values: %w(issues merge_requests milestones notes wiki_blobs commits blobs) values: %w(issues merge_requests milestones notes wiki_blobs commits blobs)
use :pagination use :pagination
end end
get ':id/-/search' do get ':id/(-/)search' do
present search(project_id: user_project.id), with: entity present search(project_id: user_project.id), with: entity
end end
end end
......
...@@ -99,10 +99,10 @@ describe API::Search do ...@@ -99,10 +99,10 @@ describe API::Search do
end end
end end
describe "GET /groups/:id/-/search" do describe "GET /groups/:id/search" do
context 'when user is not authenticated' do context 'when user is not authenticated' do
it 'returns 401 error' do it 'returns 401 error' do
get api("/groups/#{group.id}/-/search"), scope: 'projects', search: 'awesome' get api("/groups/#{group.id}/search"), scope: 'projects', search: 'awesome'
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(401)
end end
...@@ -110,7 +110,7 @@ describe API::Search do ...@@ -110,7 +110,7 @@ describe API::Search do
context 'when scope is not supported' do context 'when scope is not supported' do
it 'returns 400 error' do it 'returns 400 error' do
get api("/groups/#{group.id}/-/search", user), scope: 'unsupported', search: 'awesome' get api("/groups/#{group.id}/search", user), scope: 'unsupported', search: 'awesome'
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(400)
end end
...@@ -118,7 +118,7 @@ describe API::Search do ...@@ -118,7 +118,7 @@ describe API::Search do
context 'when scope is missing' do context 'when scope is missing' do
it 'returns 400 error' do it 'returns 400 error' do
get api("/groups/#{group.id}/-/search", user), search: 'awesome' get api("/groups/#{group.id}/search", user), search: 'awesome'
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(400)
end end
...@@ -126,7 +126,7 @@ describe API::Search do ...@@ -126,7 +126,7 @@ describe API::Search do
context 'when group does not exist' do context 'when group does not exist' do
it 'returns 404 error' do it 'returns 404 error' do
get api('/groups/9999/-/search', user), scope: 'issues', search: 'awesome' get api('/groups/9999/search', user), scope: 'issues', search: 'awesome'
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
...@@ -136,7 +136,7 @@ describe API::Search do ...@@ -136,7 +136,7 @@ describe API::Search do
it 'returns 404 error' do it 'returns 404 error' do
private_group = create(:group, :private) private_group = create(:group, :private)
get api("/groups/#{private_group.id}/-/search", user), scope: 'issues', search: 'awesome' get api("/groups/#{private_group.id}/search", user), scope: 'issues', search: 'awesome'
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
...@@ -145,7 +145,7 @@ describe API::Search do ...@@ -145,7 +145,7 @@ describe API::Search do
context 'with correct params' do context 'with correct params' do
context 'for projects scope' do context 'for projects scope' do
before do before do
get api("/groups/#{group.id}/-/search", user), scope: 'projects', search: 'awesome' get api("/groups/#{group.id}/search", user), scope: 'projects', search: 'awesome'
end end
it_behaves_like 'response is correct', schema: 'public_api/v4/projects' it_behaves_like 'response is correct', schema: 'public_api/v4/projects'
...@@ -155,7 +155,7 @@ describe API::Search do ...@@ -155,7 +155,7 @@ describe API::Search do
before do before do
create(:issue, project: project, title: 'awesome issue') create(:issue, project: project, title: 'awesome issue')
get api("/groups/#{group.id}/-/search", user), scope: 'issues', search: 'awesome' get api("/groups/#{group.id}/search", user), scope: 'issues', search: 'awesome'
end end
it_behaves_like 'response is correct', schema: 'public_api/v4/issues' it_behaves_like 'response is correct', schema: 'public_api/v4/issues'
...@@ -165,7 +165,7 @@ describe API::Search do ...@@ -165,7 +165,7 @@ describe API::Search do
before do before do
create(:merge_request, source_project: repo_project, title: 'awesome mr') create(:merge_request, source_project: repo_project, title: 'awesome mr')
get api("/groups/#{group.id}/-/search", user), scope: 'merge_requests', search: 'awesome' get api("/groups/#{group.id}/search", user), scope: 'merge_requests', search: 'awesome'
end end
it_behaves_like 'response is correct', schema: 'public_api/v4/merge_requests' it_behaves_like 'response is correct', schema: 'public_api/v4/merge_requests'
...@@ -175,7 +175,7 @@ describe API::Search do ...@@ -175,7 +175,7 @@ describe API::Search do
before do before do
create(:milestone, project: project, title: 'awesome milestone') create(:milestone, project: project, title: 'awesome milestone')
get api("/groups/#{group.id}/-/search", user), scope: 'milestones', search: 'awesome' get api("/groups/#{group.id}/search", user), scope: 'milestones', search: 'awesome'
end end
it_behaves_like 'response is correct', schema: 'public_api/v4/milestones' it_behaves_like 'response is correct', schema: 'public_api/v4/milestones'
...@@ -187,7 +187,7 @@ describe API::Search do ...@@ -187,7 +187,7 @@ describe API::Search do
create(:milestone, project: project, title: 'awesome milestone') create(:milestone, project: project, title: 'awesome milestone')
create(:milestone, project: another_project, title: 'awesome milestone other project') create(:milestone, project: another_project, title: 'awesome milestone other project')
get api("/groups/#{CGI.escape(group.full_path)}/-/search", user), scope: 'milestones', search: 'awesome' get api("/groups/#{CGI.escape(group.full_path)}/search", user), scope: 'milestones', search: 'awesome'
end end
it_behaves_like 'response is correct', schema: 'public_api/v4/milestones' it_behaves_like 'response is correct', schema: 'public_api/v4/milestones'
...@@ -198,7 +198,7 @@ describe API::Search do ...@@ -198,7 +198,7 @@ describe API::Search do
describe "GET /projects/:id/search" do describe "GET /projects/:id/search" do
context 'when user is not authenticated' do context 'when user is not authenticated' do
it 'returns 401 error' do it 'returns 401 error' do
get api("/projects/#{project.id}/-/search"), scope: 'issues', search: 'awesome' get api("/projects/#{project.id}/search"), scope: 'issues', search: 'awesome'
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(401)
end end
...@@ -206,7 +206,7 @@ describe API::Search do ...@@ -206,7 +206,7 @@ describe API::Search do
context 'when scope is not supported' do context 'when scope is not supported' do
it 'returns 400 error' do it 'returns 400 error' do
get api("/projects/#{project.id}/-/search", user), scope: 'unsupported', search: 'awesome' get api("/projects/#{project.id}/search", user), scope: 'unsupported', search: 'awesome'
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(400)
end end
...@@ -214,7 +214,7 @@ describe API::Search do ...@@ -214,7 +214,7 @@ describe API::Search do
context 'when scope is missing' do context 'when scope is missing' do
it 'returns 400 error' do it 'returns 400 error' do
get api("/projects/#{project.id}/-/search", user), search: 'awesome' get api("/projects/#{project.id}/search", user), search: 'awesome'
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(400)
end end
...@@ -222,7 +222,7 @@ describe API::Search do ...@@ -222,7 +222,7 @@ describe API::Search do
context 'when project does not exist' do context 'when project does not exist' do
it 'returns 404 error' do it 'returns 404 error' do
get api('/projects/9999/-/search', user), scope: 'issues', search: 'awesome' get api('/projects/9999/search', user), scope: 'issues', search: 'awesome'
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
...@@ -232,7 +232,7 @@ describe API::Search do ...@@ -232,7 +232,7 @@ describe API::Search do
it 'returns 404 error' do it 'returns 404 error' do
project.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE) project.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
get api("/projects/#{project.id}/-/search", user), scope: 'issues', search: 'awesome' get api("/projects/#{project.id}/search", user), scope: 'issues', search: 'awesome'
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
...@@ -243,7 +243,7 @@ describe API::Search do ...@@ -243,7 +243,7 @@ describe API::Search do
before do before do
create(:issue, project: project, title: 'awesome issue') create(:issue, project: project, title: 'awesome issue')
get api("/projects/#{project.id}/-/search", user), scope: 'issues', search: 'awesome' get api("/projects/#{project.id}/search", user), scope: 'issues', search: 'awesome'
end end
it_behaves_like 'response is correct', schema: 'public_api/v4/issues' it_behaves_like 'response is correct', schema: 'public_api/v4/issues'
...@@ -253,7 +253,7 @@ describe API::Search do ...@@ -253,7 +253,7 @@ describe API::Search do
before do before do
create(:merge_request, source_project: repo_project, title: 'awesome mr') create(:merge_request, source_project: repo_project, title: 'awesome mr')
get api("/projects/#{repo_project.id}/-/search", user), scope: 'merge_requests', search: 'awesome' get api("/projects/#{repo_project.id}/search", user), scope: 'merge_requests', search: 'awesome'
end end
it_behaves_like 'response is correct', schema: 'public_api/v4/merge_requests' it_behaves_like 'response is correct', schema: 'public_api/v4/merge_requests'
...@@ -263,7 +263,7 @@ describe API::Search do ...@@ -263,7 +263,7 @@ describe API::Search do
before do before do
create(:milestone, project: project, title: 'awesome milestone') create(:milestone, project: project, title: 'awesome milestone')
get api("/projects/#{project.id}/-/search", user), scope: 'milestones', search: 'awesome' get api("/projects/#{project.id}/search", user), scope: 'milestones', search: 'awesome'
end end
it_behaves_like 'response is correct', schema: 'public_api/v4/milestones' it_behaves_like 'response is correct', schema: 'public_api/v4/milestones'
...@@ -273,7 +273,7 @@ describe API::Search do ...@@ -273,7 +273,7 @@ describe API::Search do
before do before do
create(:note_on_merge_request, project: project, note: 'awesome note') create(:note_on_merge_request, project: project, note: 'awesome note')
get api("/projects/#{project.id}/-/search", user), scope: 'notes', search: 'awesome' get api("/projects/#{project.id}/search", user), scope: 'notes', search: 'awesome'
end end
it_behaves_like 'response is correct', schema: 'public_api/v4/notes' it_behaves_like 'response is correct', schema: 'public_api/v4/notes'
...@@ -284,7 +284,7 @@ describe API::Search do ...@@ -284,7 +284,7 @@ describe API::Search do
wiki = create(:project_wiki, project: project) wiki = create(:project_wiki, project: project)
create(:wiki_page, wiki: wiki, attrs: { title: 'home', content: "Awesome page" }) create(:wiki_page, wiki: wiki, attrs: { title: 'home', content: "Awesome page" })
get api("/projects/#{project.id}/-/search", user), scope: 'wiki_blobs', search: 'awesome' get api("/projects/#{project.id}/search", user), scope: 'wiki_blobs', search: 'awesome'
end end
it_behaves_like 'response is correct', schema: 'public_api/v4/blobs' it_behaves_like 'response is correct', schema: 'public_api/v4/blobs'
...@@ -292,7 +292,7 @@ describe API::Search do ...@@ -292,7 +292,7 @@ describe API::Search do
context 'for commits scope' do context 'for commits scope' do
before do before do
get api("/projects/#{repo_project.id}/-/search", user), scope: 'commits', search: '498214de67004b1da3d820901307bed2a68a8ef6' get api("/projects/#{repo_project.id}/search", user), scope: 'commits', search: '498214de67004b1da3d820901307bed2a68a8ef6'
end end
it_behaves_like 'response is correct', schema: 'public_api/v4/commits_details' it_behaves_like 'response is correct', schema: 'public_api/v4/commits_details'
...@@ -300,7 +300,7 @@ describe API::Search do ...@@ -300,7 +300,7 @@ describe API::Search do
context 'for commits scope with project path as id' do context 'for commits scope with project path as id' do
before do before do
get api("/projects/#{CGI.escape(repo_project.full_path)}/-/search", user), scope: 'commits', search: '498214de67004b1da3d820901307bed2a68a8ef6' get api("/projects/#{CGI.escape(repo_project.full_path)}/search", user), scope: 'commits', search: '498214de67004b1da3d820901307bed2a68a8ef6'
end end
it_behaves_like 'response is correct', schema: 'public_api/v4/commits_details' it_behaves_like 'response is correct', schema: 'public_api/v4/commits_details'
...@@ -308,7 +308,7 @@ describe API::Search do ...@@ -308,7 +308,7 @@ describe API::Search do
context 'for blobs scope' do context 'for blobs scope' do
before do before do
get api("/projects/#{repo_project.id}/-/search", user), scope: 'blobs', search: 'monitors' get api("/projects/#{repo_project.id}/search", user), scope: 'blobs', search: 'monitors'
end end
it_behaves_like 'response is correct', schema: 'public_api/v4/blobs', size: 2 it_behaves_like 'response is correct', schema: 'public_api/v4/blobs', size: 2
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment