Skip to content

Commit aaeec2a

Browse files
authored
Add missing 404 response to Swagger (#27038)
Most middleware throw a 404 in case something is not found e.g. a Repo that is not existing. But most API endpoints don't include the 404 response in their documentation. This PR changes this.
1 parent 8ecdc93 commit aaeec2a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+750
-0
lines changed

routers/api/v1/org/action.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ func ListActionsSecrets(ctx *context.APIContext) {
4040
// responses:
4141
// "200":
4242
// "$ref": "#/responses/SecretList"
43+
// "404":
44+
// "$ref": "#/responses/notFound"
4345

4446
opts := &secret_model.FindSecretsOptions{
4547
OwnerID: ctx.Org.Organization.ID,

routers/api/v1/org/avatar.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ func UpdateAvatar(ctx *context.APIContext) {
3333
// responses:
3434
// "204":
3535
// "$ref": "#/responses/empty"
36+
// "404":
37+
// "$ref": "#/responses/notFound"
3638
form := web.GetForm(ctx).(*api.UpdateUserAvatarOption)
3739

3840
content, err := base64.StdEncoding.DecodeString(form.Image)
@@ -65,6 +67,8 @@ func DeleteAvatar(ctx *context.APIContext) {
6567
// responses:
6668
// "204":
6769
// "$ref": "#/responses/empty"
70+
// "404":
71+
// "$ref": "#/responses/notFound"
6872
err := user_service.DeleteAvatar(ctx.Org.Organization.AsUser())
6973
if err != nil {
7074
ctx.Error(http.StatusInternalServerError, "DeleteAvatar", err)

routers/api/v1/org/hook.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ func ListHooks(ctx *context.APIContext) {
3737
// responses:
3838
// "200":
3939
// "$ref": "#/responses/HookList"
40+
// "404":
41+
// "$ref": "#/responses/notFound"
4042

4143
utils.ListOwnerHooks(
4244
ctx,
@@ -66,6 +68,8 @@ func GetHook(ctx *context.APIContext) {
6668
// responses:
6769
// "200":
6870
// "$ref": "#/responses/Hook"
71+
// "404":
72+
// "$ref": "#/responses/notFound"
6973

7074
hook, err := utils.GetOwnerHook(ctx, ctx.ContextUser.ID, ctx.ParamsInt64("id"))
7175
if err != nil {
@@ -103,6 +107,8 @@ func CreateHook(ctx *context.APIContext) {
103107
// responses:
104108
// "201":
105109
// "$ref": "#/responses/Hook"
110+
// "404":
111+
// "$ref": "#/responses/notFound"
106112

107113
utils.AddOwnerHook(
108114
ctx,
@@ -139,6 +145,8 @@ func EditHook(ctx *context.APIContext) {
139145
// responses:
140146
// "200":
141147
// "$ref": "#/responses/Hook"
148+
// "404":
149+
// "$ref": "#/responses/notFound"
142150

143151
utils.EditOwnerHook(
144152
ctx,
@@ -170,6 +178,8 @@ func DeleteHook(ctx *context.APIContext) {
170178
// responses:
171179
// "204":
172180
// "$ref": "#/responses/empty"
181+
// "404":
182+
// "$ref": "#/responses/notFound"
173183

174184
utils.DeleteOwnerHook(
175185
ctx,

routers/api/v1/org/label.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ func ListLabels(ctx *context.APIContext) {
4141
// responses:
4242
// "200":
4343
// "$ref": "#/responses/LabelList"
44+
// "404":
45+
// "$ref": "#/responses/notFound"
4446

4547
labels, err := issues_model.GetLabelsByOrgID(ctx, ctx.Org.Organization.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
4648
if err != nil {
@@ -80,6 +82,8 @@ func CreateLabel(ctx *context.APIContext) {
8082
// responses:
8183
// "201":
8284
// "$ref": "#/responses/Label"
85+
// "404":
86+
// "$ref": "#/responses/notFound"
8387
// "422":
8488
// "$ref": "#/responses/validationError"
8589
form := web.GetForm(ctx).(*api.CreateLabelOption)
@@ -128,6 +132,8 @@ func GetLabel(ctx *context.APIContext) {
128132
// responses:
129133
// "200":
130134
// "$ref": "#/responses/Label"
135+
// "404":
136+
// "$ref": "#/responses/notFound"
131137

132138
var (
133139
label *issues_model.Label
@@ -179,6 +185,8 @@ func EditLabel(ctx *context.APIContext) {
179185
// responses:
180186
// "200":
181187
// "$ref": "#/responses/Label"
188+
// "404":
189+
// "$ref": "#/responses/notFound"
182190
// "422":
183191
// "$ref": "#/responses/validationError"
184192
form := web.GetForm(ctx).(*api.EditLabelOption)
@@ -238,6 +246,8 @@ func DeleteLabel(ctx *context.APIContext) {
238246
// responses:
239247
// "204":
240248
// "$ref": "#/responses/empty"
249+
// "404":
250+
// "$ref": "#/responses/notFound"
241251

242252
if err := issues_model.DeleteLabel(ctx.Org.Organization.ID, ctx.ParamsInt64(":id")); err != nil {
243253
ctx.Error(http.StatusInternalServerError, "DeleteLabel", err)

routers/api/v1/org/member.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ func ListMembers(ctx *context.APIContext) {
7070
// responses:
7171
// "200":
7272
// "$ref": "#/responses/UserList"
73+
// "404":
74+
// "$ref": "#/responses/notFound"
7375

7476
publicOnly := true
7577
if ctx.Doer != nil {
@@ -107,6 +109,8 @@ func ListPublicMembers(ctx *context.APIContext) {
107109
// responses:
108110
// "200":
109111
// "$ref": "#/responses/UserList"
112+
// "404":
113+
// "$ref": "#/responses/notFound"
110114

111115
listMembers(ctx, true)
112116
}
@@ -225,6 +229,8 @@ func PublicizeMember(ctx *context.APIContext) {
225229
// description: membership publicized
226230
// "403":
227231
// "$ref": "#/responses/forbidden"
232+
// "404":
233+
// "$ref": "#/responses/notFound"
228234

229235
userToPublicize := user.GetUserByParams(ctx)
230236
if ctx.Written() {
@@ -265,6 +271,8 @@ func ConcealMember(ctx *context.APIContext) {
265271
// "$ref": "#/responses/empty"
266272
// "403":
267273
// "$ref": "#/responses/forbidden"
274+
// "404":
275+
// "$ref": "#/responses/notFound"
268276

269277
userToConceal := user.GetUserByParams(ctx)
270278
if ctx.Written() {
@@ -303,6 +311,8 @@ func DeleteMember(ctx *context.APIContext) {
303311
// responses:
304312
// "204":
305313
// description: member removed
314+
// "404":
315+
// "$ref": "#/responses/notFound"
306316

307317
member := user.GetUserByParams(ctx)
308318
if ctx.Written() {

routers/api/v1/org/org.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ func ListMyOrgs(ctx *context.APIContext) {
7070
// responses:
7171
// "200":
7272
// "$ref": "#/responses/OrganizationList"
73+
// "404":
74+
// "$ref": "#/responses/notFound"
7375

7476
listUserOrgs(ctx, ctx.Doer)
7577
}
@@ -98,6 +100,8 @@ func ListUserOrgs(ctx *context.APIContext) {
98100
// responses:
99101
// "200":
100102
// "$ref": "#/responses/OrganizationList"
103+
// "404":
104+
// "$ref": "#/responses/notFound"
101105

102106
listUserOrgs(ctx, ctx.ContextUser)
103107
}
@@ -295,6 +299,8 @@ func Get(ctx *context.APIContext) {
295299
// responses:
296300
// "200":
297301
// "$ref": "#/responses/Organization"
302+
// "404":
303+
// "$ref": "#/responses/notFound"
298304

299305
if !organization.HasOrgOrUserVisible(ctx, ctx.Org.Organization.AsUser(), ctx.Doer) {
300306
ctx.NotFound("HasOrgOrUserVisible", nil)
@@ -334,6 +340,8 @@ func Edit(ctx *context.APIContext) {
334340
// responses:
335341
// "200":
336342
// "$ref": "#/responses/Organization"
343+
// "404":
344+
// "$ref": "#/responses/notFound"
337345
form := web.GetForm(ctx).(*api.EditOrgOption)
338346
org := ctx.Org.Organization
339347
org.FullName = form.FullName
@@ -374,6 +382,8 @@ func Delete(ctx *context.APIContext) {
374382
// responses:
375383
// "204":
376384
// "$ref": "#/responses/empty"
385+
// "404":
386+
// "$ref": "#/responses/notFound"
377387

378388
if err := org.DeleteOrganization(ctx.Org.Organization); err != nil {
379389
ctx.Error(http.StatusInternalServerError, "DeleteOrganization", err)

routers/api/v1/org/team.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ func ListTeams(ctx *context.APIContext) {
5050
// responses:
5151
// "200":
5252
// "$ref": "#/responses/TeamList"
53+
// "404":
54+
// "$ref": "#/responses/notFound"
5355

5456
teams, count, err := organization.SearchTeam(&organization.SearchTeamOptions{
5557
ListOptions: utils.GetListOptions(ctx),
@@ -126,6 +128,8 @@ func GetTeam(ctx *context.APIContext) {
126128
// responses:
127129
// "200":
128130
// "$ref": "#/responses/Team"
131+
// "404":
132+
// "$ref": "#/responses/notFound"
129133

130134
apiTeam, err := convert.ToTeam(ctx, ctx.Org.Team, true)
131135
if err != nil {
@@ -204,6 +208,8 @@ func CreateTeam(ctx *context.APIContext) {
204208
// responses:
205209
// "201":
206210
// "$ref": "#/responses/Team"
211+
// "404":
212+
// "$ref": "#/responses/notFound"
207213
// "422":
208214
// "$ref": "#/responses/validationError"
209215
form := web.GetForm(ctx).(*api.CreateTeamOption)
@@ -272,6 +278,8 @@ func EditTeam(ctx *context.APIContext) {
272278
// responses:
273279
// "200":
274280
// "$ref": "#/responses/Team"
281+
// "404":
282+
// "$ref": "#/responses/notFound"
275283

276284
form := web.GetForm(ctx).(*api.EditTeamOption)
277285
team := ctx.Org.Team
@@ -350,6 +358,8 @@ func DeleteTeam(ctx *context.APIContext) {
350358
// responses:
351359
// "204":
352360
// description: team deleted
361+
// "404":
362+
// "$ref": "#/responses/notFound"
353363

354364
if err := models.DeleteTeam(ctx.Org.Team); err != nil {
355365
ctx.Error(http.StatusInternalServerError, "DeleteTeam", err)
@@ -383,6 +393,8 @@ func GetTeamMembers(ctx *context.APIContext) {
383393
// responses:
384394
// "200":
385395
// "$ref": "#/responses/UserList"
396+
// "404":
397+
// "$ref": "#/responses/notFound"
386398

387399
isMember, err := organization.IsOrganizationMember(ctx, ctx.Org.Team.OrgID, ctx.Doer.ID)
388400
if err != nil {
@@ -550,6 +562,8 @@ func GetTeamRepos(ctx *context.APIContext) {
550562
// responses:
551563
// "200":
552564
// "$ref": "#/responses/RepositoryList"
565+
// "404":
566+
// "$ref": "#/responses/notFound"
553567

554568
team := ctx.Org.Team
555569
teamRepos, err := organization.GetTeamRepositories(ctx, &organization.SearchTeamRepoOptions{
@@ -665,6 +679,8 @@ func AddTeamRepository(ctx *context.APIContext) {
665679
// "$ref": "#/responses/empty"
666680
// "403":
667681
// "$ref": "#/responses/forbidden"
682+
// "404":
683+
// "$ref": "#/responses/notFound"
668684

669685
repo := getRepositoryByParams(ctx)
670686
if ctx.Written() {
@@ -715,6 +731,8 @@ func RemoveTeamRepository(ctx *context.APIContext) {
715731
// "$ref": "#/responses/empty"
716732
// "403":
717733
// "$ref": "#/responses/forbidden"
734+
// "404":
735+
// "$ref": "#/responses/notFound"
718736

719737
repo := getRepositoryByParams(ctx)
720738
if ctx.Written() {
@@ -775,6 +793,8 @@ func SearchTeam(ctx *context.APIContext) {
775793
// type: array
776794
// items:
777795
// "$ref": "#/definitions/Team"
796+
// "404":
797+
// "$ref": "#/responses/notFound"
778798

779799
listOptions := utils.GetListOptions(ctx)
780800

routers/api/v1/packages/package.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ func ListPackages(ctx *context.APIContext) {
4848
// responses:
4949
// "200":
5050
// "$ref": "#/responses/PackageList"
51+
// "404":
52+
// "$ref": "#/responses/notFound"
5153

5254
listOptions := utils.GetListOptions(ctx)
5355

routers/api/v1/repo/avatar.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ func UpdateAvatar(ctx *context.APIContext) {
3838
// responses:
3939
// "204":
4040
// "$ref": "#/responses/empty"
41+
// "404":
42+
// "$ref": "#/responses/notFound"
4143
form := web.GetForm(ctx).(*api.UpdateRepoAvatarOption)
4244

4345
content, err := base64.StdEncoding.DecodeString(form.Image)
@@ -75,6 +77,8 @@ func DeleteAvatar(ctx *context.APIContext) {
7577
// responses:
7678
// "204":
7779
// "$ref": "#/responses/empty"
80+
// "404":
81+
// "$ref": "#/responses/notFound"
7882
err := repo_service.DeleteAvatar(ctx, ctx.Repo.Repository)
7983
if err != nil {
8084
ctx.Error(http.StatusInternalServerError, "DeleteAvatar", err)

routers/api/v1/repo/blob.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ func GetBlob(ctx *context.APIContext) {
3838
// "$ref": "#/responses/GitBlobResponse"
3939
// "400":
4040
// "$ref": "#/responses/error"
41+
// "404":
42+
// "$ref": "#/responses/notFound"
4143

4244
sha := ctx.Params("sha")
4345
if len(sha) == 0 {

routers/api/v1/repo/collaborators.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ func ListCollaborators(ctx *context.APIContext) {
5050
// responses:
5151
// "200":
5252
// "$ref": "#/responses/UserList"
53+
// "404":
54+
// "$ref": "#/responses/notFound"
5355

5456
count, err := repo_model.CountCollaborators(ctx.Repo.Repository.ID)
5557
if err != nil {
@@ -154,6 +156,8 @@ func AddCollaborator(ctx *context.APIContext) {
154156
// responses:
155157
// "204":
156158
// "$ref": "#/responses/empty"
159+
// "404":
160+
// "$ref": "#/responses/notFound"
157161
// "422":
158162
// "$ref": "#/responses/validationError"
159163

@@ -215,6 +219,8 @@ func DeleteCollaborator(ctx *context.APIContext) {
215219
// responses:
216220
// "204":
217221
// "$ref": "#/responses/empty"
222+
// "404":
223+
// "$ref": "#/responses/notFound"
218224
// "422":
219225
// "$ref": "#/responses/validationError"
220226

@@ -311,6 +317,8 @@ func GetReviewers(ctx *context.APIContext) {
311317
// responses:
312318
// "200":
313319
// "$ref": "#/responses/UserList"
320+
// "404":
321+
// "$ref": "#/responses/notFound"
314322

315323
reviewers, err := repo_model.GetReviewers(ctx, ctx.Repo.Repository, ctx.Doer.ID, 0)
316324
if err != nil {
@@ -341,6 +349,8 @@ func GetAssignees(ctx *context.APIContext) {
341349
// responses:
342350
// "200":
343351
// "$ref": "#/responses/UserList"
352+
// "404":
353+
// "$ref": "#/responses/notFound"
344354

345355
assignees, err := repo_model.GetRepoAssignees(ctx, ctx.Repo.Repository)
346356
if err != nil {

routers/api/v1/repo/fork.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ func ListForks(ctx *context.APIContext) {
5252
// responses:
5353
// "200":
5454
// "$ref": "#/responses/RepositoryList"
55+
// "404":
56+
// "$ref": "#/responses/notFound"
5557

5658
forks, err := repo_model.GetForks(ctx.Repo.Repository, utils.GetListOptions(ctx))
5759
if err != nil {
@@ -99,6 +101,8 @@ func CreateFork(ctx *context.APIContext) {
99101
// "$ref": "#/responses/Repository"
100102
// "403":
101103
// "$ref": "#/responses/forbidden"
104+
// "404":
105+
// "$ref": "#/responses/notFound"
102106
// "409":
103107
// description: The repository with the same name already exists.
104108
// "422":

0 commit comments

Comments
 (0)