Skip to content

Commit 35f3af7

Browse files
committed
api: remove trailing slashes from response URLs
Following the same cleanup done for the web frontend in commit 4c7afbe, strip trailing slashes from all URL fields in API JSON responses (url, mbox, comments, checks, web_url) and from notification URLs. Also update test request paths and documentation examples for consistency. Signed-off-by: Robin Jarry <robin@jarry.cc>
1 parent a9a1ad3 commit 35f3af7

23 files changed

Lines changed: 135 additions & 135 deletions

‎docs/api/index.rst‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ __ https://curl.haxx.se/
4747
4848
$ curl -sL https://patchwork.example.com/api/ | jq
4949
{
50-
"bundles": "https://patchwork.example.com/api/1.4/bundles/",
51-
"covers": "https://patchwork.example.com/api/1.4/covers/",
52-
"events": "https://patchwork.example.com/api/1.4/events/",
53-
"patches": "https://patchwork.example.com/api/1.4/patches/",
54-
"people": "https://patchwork.example.com/api/1.4/people/",
55-
"projects": "https://patchwork.example.com/api/1.4/projects/",
56-
"series": "https://patchwork.example.com/api/1.4/series/",
57-
"users": "https://patchwork.example.com/api/1.4/users/"
50+
"bundles": "https://patchwork.example.com/api/1.4/bundles",
51+
"covers": "https://patchwork.example.com/api/1.4/covers",
52+
"events": "https://patchwork.example.com/api/1.4/events",
53+
"patches": "https://patchwork.example.com/api/1.4/patches",
54+
"people": "https://patchwork.example.com/api/1.4/people",
55+
"projects": "https://patchwork.example.com/api/1.4/projects",
56+
"series": "https://patchwork.example.com/api/1.4/series",
57+
"users": "https://patchwork.example.com/api/1.4/users"
5858
}
5959
6060
Tools like `curl` and libraries like `requests` can be used to build anything

‎pkg/api/bundle_test.go‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestBundleList(t *testing.T) {
1919
s.exec(t, `INSERT INTO bundle (owner_id, project_id, name, public)
2020
VALUES (?, ?, 'my bundle', true)`, userID, projID)
2121

22-
items := getList(t, s, "/api/1.4/bundles/")
22+
items := getList(t, s, "/api/1.4/bundles")
2323
if len(items) != 1 {
2424
t.Fatalf("got %d, want 1", len(items))
2525
}
@@ -33,7 +33,7 @@ func TestBundleList(t *testing.T) {
3333

3434
func TestBundleListEmpty(t *testing.T) {
3535
s := newTestServer(t)
36-
items := getList(t, s, "/api/1.4/bundles/")
36+
items := getList(t, s, "/api/1.4/bundles")
3737
if len(items) != 0 {
3838
t.Errorf("got %d, want 0", len(items))
3939
}
@@ -48,7 +48,7 @@ func TestBundleListPublicOnly(t *testing.T) {
4848
s.exec(t, `INSERT INTO bundle (owner_id, project_id, name, public)
4949
VALUES (?, ?, 'private', false)`, userID, projID)
5050

51-
items := getList(t, s, "/api/1.4/bundles/")
51+
items := getList(t, s, "/api/1.4/bundles")
5252
if len(items) != 1 {
5353
t.Errorf("got %d, want 1", len(items))
5454
}
@@ -71,7 +71,7 @@ func TestBundleListAuthSeesOwnPrivate(t *testing.T) {
7171
s.exec(t, `INSERT INTO bundle (owner_id, project_id, name, public)
7272
VALUES (?, ?, 'public-one', true)`, otherID, projID)
7373

74-
resp := s.authRequest(t, "GET", "/api/1.4/bundles/", token, nil)
74+
resp := s.authRequest(t, "GET", "/api/1.4/bundles", token, nil)
7575
if resp.StatusCode != 200 {
7676
t.Fatalf("status = %d", resp.StatusCode)
7777
}
@@ -189,7 +189,7 @@ func TestBundleCreateAnonymous(t *testing.T) {
189189
projID := s.insertProject(t)
190190
patchID := s.insertPatch(t, projID, "<ca@test>", "p")
191191

192-
resp := s.authRequest(t, "POST", "/api/1.4/bundles/", "",
192+
resp := s.authRequest(t, "POST", "/api/1.4/bundles", "",
193193
map[string]any{"name": "b", "patches": []int{patchID}})
194194
if resp.StatusCode != 401 {
195195
t.Errorf("status = %d, want 401", resp.StatusCode)
@@ -204,7 +204,7 @@ func TestBundleCreateValid(t *testing.T) {
204204
p1 := s.insertPatch(t, projID, "<cv1@test>", "patch 1")
205205
p2 := s.insertPatch(t, projID, "<cv2@test>", "patch 2")
206206

207-
resp := s.authRequest(t, "POST", "/api/1.4/bundles/", token,
207+
resp := s.authRequest(t, "POST", "/api/1.4/bundles", token,
208208
map[string]any{
209209
"name": "my-bundle",
210210
"public": true,
@@ -235,7 +235,7 @@ func TestBundleCreateEmptyPatches(t *testing.T) {
235235
userID := s.insertUser(t, "empty", "empty@test")
236236
token := s.insertToken(t, userID)
237237

238-
resp := s.authRequest(t, "POST", "/api/1.4/bundles/", token,
238+
resp := s.authRequest(t, "POST", "/api/1.4/bundles", token,
239239
map[string]any{
240240
"name": "empty-bundle",
241241
"patches": []int{},
@@ -263,7 +263,7 @@ func TestBundleCreateCrossProject(t *testing.T) {
263263
RETURNING id`).Scan(context.Background(), &proj2)
264264
p2 := s.insertPatch(t, proj2, "<cp2@test>", "patch 2")
265265

266-
resp := s.authRequest(t, "POST", "/api/1.4/bundles/", token,
266+
resp := s.authRequest(t, "POST", "/api/1.4/bundles", token,
267267
map[string]any{
268268
"name": "cross-bundle",
269269
"patches": []int{p1, p2},
@@ -283,7 +283,7 @@ func TestBundleUpdateOwner(t *testing.T) {
283283
patchID := s.insertPatch(t, projID, "<u1@test>", "p1")
284284

285285
// create the bundle first
286-
resp := s.authRequest(t, "POST", "/api/1.4/bundles/", token,
286+
resp := s.authRequest(t, "POST", "/api/1.4/bundles", token,
287287
map[string]any{
288288
"name": "orig-name",
289289
"public": false,
@@ -323,7 +323,7 @@ func TestBundleUpdatePatches(t *testing.T) {
323323
p2 := s.insertPatch(t, projID, "<up2@test>", "p2")
324324
p3 := s.insertPatch(t, projID, "<up3@test>", "p3")
325325

326-
resp := s.authRequest(t, "POST", "/api/1.4/bundles/", token,
326+
resp := s.authRequest(t, "POST", "/api/1.4/bundles", token,
327327
map[string]any{
328328
"name": "patch-update",
329329
"patches": []int{p1},
@@ -382,7 +382,7 @@ func TestBundleDeleteOwner(t *testing.T) {
382382
token := s.insertToken(t, userID)
383383
patchID := s.insertPatch(t, projID, "<d1@test>", "p1")
384384

385-
resp := s.authRequest(t, "POST", "/api/1.4/bundles/", token,
385+
resp := s.authRequest(t, "POST", "/api/1.4/bundles", token,
386386
map[string]any{
387387
"name": "to-delete",
388388
"patches": []int{patchID},

‎pkg/api/bundles.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,16 +382,16 @@ func insertBundlePatches(ctx context.Context, idb bun.IDB, bundleID int, patchID
382382
func bundleToResponse(b *db.Bundle, base string) BundleResponse {
383383
r := BundleResponse{
384384
ID: b.ID,
385-
URL: fmt.Sprintf("%s/bundles/%d/", base, b.ID),
385+
URL: fmt.Sprintf("%s/bundles/%d", base, b.ID),
386386
Name: b.Name,
387387
Public: b.Public,
388-
Mbox: fmt.Sprintf("%s/bundles/%d/mbox/", base, b.ID),
388+
Mbox: fmt.Sprintf("%s/bundles/%d/mbox", base, b.ID),
389389
Patches: make([]PatchEmbedded, len(b.BundlePatches)),
390390
}
391391
if b.Project != nil {
392392
r.Project = projectToEmbedded(b.Project, base)
393393
if b.Project.WebURL != "" {
394-
r.WebURL = strp(fmt.Sprintf("%s/bundle/%s/%s/",
394+
r.WebURL = strp(fmt.Sprintf("%s/bundle/%s/%s",
395395
b.Project.WebURL, b.Owner.Username, b.Name))
396396
}
397397
}

‎pkg/api/check_test.go‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestCheckCreateInvalidPatch(t *testing.T) {
1919
s.makeMaintainer(t, userID, projID)
2020

2121
resp := s.authRequest(t, "POST",
22-
"/api/1.4/patches/99999/checks/", token,
22+
"/api/1.4/patches/99999/checks", token,
2323
map[string]string{"state": "success", "context": "ci"})
2424
if resp.StatusCode != 404 {
2525
t.Errorf("status = %d, want 404", resp.StatusCode)
@@ -35,7 +35,7 @@ func TestCheckCreateMissingState(t *testing.T) {
3535
s.makeMaintainer(t, userID, projID)
3636

3737
resp := s.authRequest(t, "POST",
38-
fmt.Sprintf("/api/1.4/patches/%d/checks/", patchID), token,
38+
fmt.Sprintf("/api/1.4/patches/%d/checks", patchID), token,
3939
map[string]string{"context": "ci"})
4040
if resp.StatusCode != 422 {
4141
t.Errorf("status = %d, want 422", resp.StatusCode)
@@ -50,7 +50,7 @@ func TestCheckCreateNonMaintainer(t *testing.T) {
5050
token := s.insertToken(t, userID)
5151

5252
resp := s.authRequest(t, "POST",
53-
fmt.Sprintf("/api/1.4/patches/%d/checks/", patchID), token,
53+
fmt.Sprintf("/api/1.4/patches/%d/checks", patchID), token,
5454
map[string]string{"state": "success", "context": "ci"})
5555
if resp.StatusCode != 403 {
5656
t.Errorf("status = %d, want 403", resp.StatusCode)
@@ -75,7 +75,7 @@ func TestCheckDetail(t *testing.T) {
7575

7676
func TestCheckInvalidPatch(t *testing.T) {
7777
s := newTestServer(t)
78-
resp := s.get(t, "/api/1.4/patches/99999/checks/")
78+
resp := s.get(t, "/api/1.4/patches/99999/checks")
7979
var items []map[string]any
8080
decodeJSON(t, resp, &items)
8181
if len(items) != 0 {
@@ -93,7 +93,7 @@ func TestCheckList(t *testing.T) {
9393
VALUES (?, ?, datetime('now'), 1, 'http://ci/1', 'ci/build', 'Build passed')`,
9494
patchID, userID)
9595

96-
items := getList(t, s, fmt.Sprintf("/api/1.4/patches/%d/checks/", patchID))
96+
items := getList(t, s, fmt.Sprintf("/api/1.4/patches/%d/checks", patchID))
9797
if len(items) != 1 {
9898
t.Fatalf("got %d, want 1", len(items))
9999
}
@@ -113,7 +113,7 @@ func TestCheckListEmpty(t *testing.T) {
113113
projID := s.insertProject(t)
114114
patchID := s.insertPatch(t, projID, "<chk@test>", "p")
115115

116-
items := getList(t, s, fmt.Sprintf("/api/1.4/patches/%d/checks/", patchID))
116+
items := getList(t, s, fmt.Sprintf("/api/1.4/patches/%d/checks", patchID))
117117
if len(items) != 0 {
118118
t.Errorf("got %d, want 0", len(items))
119119
}
@@ -128,7 +128,7 @@ func TestCheckStateString(t *testing.T) {
128128
(patch_id, user_id, date, state, target_url, context, description)
129129
VALUES (?, ?, datetime('now'), 1, '', 'ci', '')`, patchID, userID)
130130

131-
items := getList(t, s, fmt.Sprintf("/api/1.4/patches/%d/checks/", patchID))
131+
items := getList(t, s, fmt.Sprintf("/api/1.4/patches/%d/checks", patchID))
132132
if len(items) != 1 {
133133
t.Fatalf("got %d, want 1", len(items))
134134
}
@@ -155,7 +155,7 @@ func TestCreateCheckAnonymous(t *testing.T) {
155155
patchID := s.insertPatch(t, projID, "<chk-anon@test>", "p")
156156

157157
resp := s.authRequest(t, "POST",
158-
fmt.Sprintf("/api/1.4/patches/%d/checks/", patchID), "",
158+
fmt.Sprintf("/api/1.4/patches/%d/checks", patchID), "",
159159
map[string]string{"state": "success", "context": "ci"})
160160
if resp.StatusCode != 401 {
161161
t.Errorf("status = %d, want 401", resp.StatusCode)
@@ -171,7 +171,7 @@ func TestCreateCheckInvalidState(t *testing.T) {
171171
s.makeMaintainer(t, userID, projID)
172172

173173
resp := s.authRequest(t, "POST",
174-
fmt.Sprintf("/api/1.4/patches/%d/checks/", patchID), token,
174+
fmt.Sprintf("/api/1.4/patches/%d/checks", patchID), token,
175175
map[string]string{"state": "invalid"})
176176
if resp.StatusCode != 422 {
177177
t.Errorf("status = %d, want 422", resp.StatusCode)
@@ -187,7 +187,7 @@ func TestCreateCheckMaintainer(t *testing.T) {
187187
s.makeMaintainer(t, userID, projID)
188188

189189
resp := s.authRequest(t, "POST",
190-
fmt.Sprintf("/api/1.4/patches/%d/checks/", patchID), token,
190+
fmt.Sprintf("/api/1.4/patches/%d/checks", patchID), token,
191191
map[string]string{
192192
"state": "success",
193193
"target_url": "http://ci.example.com/1",

‎pkg/api/comment_test.go‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestCoverCommentList(t *testing.T) {
4343
VALUES ('<cc-comment@test>', datetime('now'), '', ?, ?, 'lgtm')`,
4444
personID, coverID)
4545

46-
items := getList(t, s, fmt.Sprintf("/api/1.4/covers/%d/comments/", coverID))
46+
items := getList(t, s, fmt.Sprintf("/api/1.4/covers/%d/comments", coverID))
4747
if len(items) != 1 {
4848
t.Fatalf("got %d, want 1", len(items))
4949
}
@@ -54,15 +54,15 @@ func TestCoverCommentList(t *testing.T) {
5454

5555
func TestCoverCommentListInvalidCover(t *testing.T) {
5656
s := newTestServer(t)
57-
resp := s.get(t, "/api/1.4/covers/invalid/comments/")
57+
resp := s.get(t, "/api/1.4/covers/invalid/comments")
5858
if resp.StatusCode != 422 {
5959
t.Errorf("status = %d, want 422", resp.StatusCode)
6060
}
6161
}
6262

6363
func TestCoverCommentListNonExistent(t *testing.T) {
6464
s := newTestServer(t)
65-
items := getList(t, s, "/api/1.4/covers/99999/comments/")
65+
items := getList(t, s, "/api/1.4/covers/99999/comments")
6666
if len(items) != 0 {
6767
t.Errorf("got %d, want 0", len(items))
6868
}
@@ -74,7 +74,7 @@ func TestPatchCommentCreate405(t *testing.T) {
7474
patchID := s.insertPatch(t, projID, "<pcc@test>", "p")
7575

7676
resp := s.authRequest(t, "POST",
77-
fmt.Sprintf("/api/1.4/patches/%d/comments/", patchID), "",
77+
fmt.Sprintf("/api/1.4/patches/%d/comments", patchID), "",
7878
map[string]string{"content": "test"})
7979
if resp.StatusCode != 405 {
8080
t.Errorf("status = %d, want 405", resp.StatusCode)
@@ -119,14 +119,14 @@ func TestPatchCommentList(t *testing.T) {
119119
patchID := s.insertPatch(t, projID, "<pc@test>", "p")
120120
commentID := s.insertComment(t, patchID, "<comment@test>")
121121

122-
items := getList(t, s, fmt.Sprintf("/api/1.4/patches/%d/comments/", patchID))
122+
items := getList(t, s, fmt.Sprintf("/api/1.4/patches/%d/comments", patchID))
123123
if len(items) != 1 {
124124
t.Fatalf("got %d, want 1", len(items))
125125
}
126126
c := items[0]
127127
assertValue(t, c, "id", float64(commentID))
128128
assertValue(t, c, "msgid", "<comment@test>")
129-
assertContains(t, c, "url", fmt.Sprintf("/patches/%d/comments/%d/", patchID, commentID))
129+
assertContains(t, c, "url", fmt.Sprintf("/patches/%d/comments/%d", patchID, commentID))
130130
assertField(t, c, "date")
131131
assertField(t, c, "addressed")
132132
assertNested(t, c, "submitter", "id")
@@ -141,23 +141,23 @@ func TestPatchCommentListEmpty(t *testing.T) {
141141
projID := s.insertProject(t)
142142
patchID := s.insertPatch(t, projID, "<pce@test>", "p")
143143

144-
items := getList(t, s, fmt.Sprintf("/api/1.4/patches/%d/comments/", patchID))
144+
items := getList(t, s, fmt.Sprintf("/api/1.4/patches/%d/comments", patchID))
145145
if len(items) != 0 {
146146
t.Errorf("got %d, want 0", len(items))
147147
}
148148
}
149149

150150
func TestPatchCommentListInvalidPatch(t *testing.T) {
151151
s := newTestServer(t)
152-
resp := s.get(t, "/api/1.4/patches/invalid/comments/")
152+
resp := s.get(t, "/api/1.4/patches/invalid/comments")
153153
if resp.StatusCode != 422 {
154154
t.Errorf("status = %d, want 422", resp.StatusCode)
155155
}
156156
}
157157

158158
func TestPatchCommentNonExistentPatch(t *testing.T) {
159159
s := newTestServer(t)
160-
items := getList(t, s, "/api/1.4/patches/99999/comments/")
160+
items := getList(t, s, "/api/1.4/patches/99999/comments")
161161
if len(items) != 0 {
162162
t.Errorf("got %d, want 0", len(items))
163163
}
@@ -173,7 +173,7 @@ func TestPatchCommentURLAndSubject(t *testing.T) {
173173
VALUES ('<cus-c@test>', datetime('now'), ?, ?, ?, 'ok')`,
174174
"Subject: Re: test\n", personID, patchID)
175175

176-
items := getList(t, s, fmt.Sprintf("/api/1.4/patches/%d/comments/", patchID))
176+
items := getList(t, s, fmt.Sprintf("/api/1.4/patches/%d/comments", patchID))
177177
if len(items) != 1 {
178178
t.Fatalf("got %d", len(items))
179179
}

‎pkg/api/cover_test.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
func TestCoverCreate405(t *testing.T) {
1414
s := newTestServer(t)
15-
resp := s.authRequest(t, "POST", "/api/1.4/covers/", "", map[string]string{"name": "x"})
15+
resp := s.authRequest(t, "POST", "/api/1.4/covers", "", map[string]string{"name": "x"})
1616
if resp.StatusCode != 405 {
1717
t.Errorf("status = %d, want 405", resp.StatusCode)
1818
}
@@ -82,17 +82,17 @@ func TestCoverList(t *testing.T) {
8282
s := newTestServer(t)
8383
projID := s.insertProject(t)
8484
coverID := s.insertCover(t, projID, "<c1@test>", "test cover")
85-
items := getList(t, s, "/api/1.4/covers/")
85+
items := getList(t, s, "/api/1.4/covers")
8686
if len(items) != 1 {
8787
t.Fatalf("got %d, want 1", len(items))
8888
}
8989
c := items[0]
9090
assertValue(t, c, "id", float64(coverID))
9191
assertValue(t, c, "name", "test cover")
9292
assertValue(t, c, "msgid", "<c1@test>")
93-
assertContains(t, c, "url", fmt.Sprintf("/covers/%d/", coverID))
94-
assertContains(t, c, "mbox", fmt.Sprintf("/covers/%d/mbox/", coverID))
95-
assertContains(t, c, "comments", fmt.Sprintf("/covers/%d/comments/", coverID))
93+
assertContains(t, c, "url", fmt.Sprintf("/covers/%d", coverID))
94+
assertContains(t, c, "mbox", fmt.Sprintf("/covers/%d/mbox", coverID))
95+
assertContains(t, c, "comments", fmt.Sprintf("/covers/%d/comments", coverID))
9696
assertField(t, c, "date")
9797
assertField(t, c, "series")
9898
assertNested(t, c, "submitter", "id")
@@ -102,7 +102,7 @@ func TestCoverList(t *testing.T) {
102102

103103
func TestCoverListEmpty(t *testing.T) {
104104
s := newTestServer(t)
105-
items := getList(t, s, "/api/1.4/covers/")
105+
items := getList(t, s, "/api/1.4/covers")
106106
if len(items) != 0 {
107107
t.Errorf("got %d, want 0", len(items))
108108
}

‎pkg/api/covers.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,18 @@ func applyCoverFilters(q *bun.SelectQuery, input *ListCoversInput) *bun.SelectQu
157157
func coverToListResponse(c *db.Cover, base string) CoverListResponse {
158158
r := CoverListResponse{
159159
ID: c.ID,
160-
URL: fmt.Sprintf("%s/covers/%d/", base, c.ID),
160+
URL: fmt.Sprintf("%s/covers/%d", base, c.ID),
161161
Msgid: c.Msgid,
162162
Date: c.Date,
163163
Name: c.Name,
164-
Mbox: fmt.Sprintf("%s/covers/%d/mbox/", base, c.ID),
165-
Comments: strp(fmt.Sprintf("%s/covers/%d/comments/", base, c.ID)),
164+
Mbox: fmt.Sprintf("%s/covers/%d/mbox", base, c.ID),
165+
Comments: strp(fmt.Sprintf("%s/covers/%d/comments", base, c.ID)),
166166
Series: []SeriesEmbedded{},
167167
}
168168
if c.Project != nil {
169169
r.Project = projectToEmbedded(c.Project, base)
170170
if c.Project.WebURL != "" {
171-
r.WebURL = strp(fmt.Sprintf("%s/cover/%s/",
171+
r.WebURL = strp(fmt.Sprintf("%s/cover/%s",
172172
c.Project.WebURL, c.Msgid))
173173
}
174174
archiveURL := listArchiveURL(c.Project, c.Msgid)
@@ -182,9 +182,9 @@ func coverToListResponse(c *db.Cover, base string) CoverListResponse {
182182
for _, s := range c.SeriesList {
183183
r.Series = append(r.Series, SeriesEmbedded{
184184
ID: s.ID,
185-
URL: fmt.Sprintf("%s/series/%d/", base, s.ID),
185+
URL: fmt.Sprintf("%s/series/%d", base, s.ID),
186186
Name: s.Name,
187-
Mbox: fmt.Sprintf("%s/series/%d/mbox/", base, s.ID),
187+
Mbox: fmt.Sprintf("%s/series/%d/mbox", base, s.ID),
188188
})
189189
}
190190
return r

0 commit comments

Comments
 (0)