summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo/issue_label.go
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2019-12-20 18:07:12 +0100
committerLauris BH <lauris@nix.lv>2019-12-20 19:07:12 +0200
commit2848c5eb8f7333b6791afd296b12d21751d0516b (patch)
tree67ff6244026174116edbff1b4c4cdb5934401968 /routers/api/v1/repo/issue_label.go
parent050a8af4243d7f5fff0a2f492b9166f4dfdf0ecf (diff)
downloadgitea-2848c5eb8f7333b6791afd296b12d21751d0516b.tar.gz
gitea-2848c5eb8f7333b6791afd296b12d21751d0516b.zip
Swagger info corrections (#9441)
* use numbers and not http.Status___ enum * fix test * add many missing swagger responses * code format * Deletion Sould return 204 ... * error handling improvements * if special error type ... then add it to swagger too * one smal nit * invalidTopicsError is []string * valid swagger specification 2.0 - if you add responses swagger can tell you if you do it right :+1: * use ctx.InternalServerError * Revert "use numbers and not http.Status___ enum" This reverts commit b1ff386e2418ed6a7f183e756b13277d701278ef. * use http.Status* enum everywhere
Diffstat (limited to 'routers/api/v1/repo/issue_label.go')
-rw-r--r--routers/api/v1/repo/issue_label.go67
1 files changed, 42 insertions, 25 deletions
diff --git a/routers/api/v1/repo/issue_label.go b/routers/api/v1/repo/issue_label.go
index e41c1512e2..492da244f2 100644
--- a/routers/api/v1/repo/issue_label.go
+++ b/routers/api/v1/repo/issue_label.go
@@ -6,6 +6,8 @@
package repo
import (
+ "net/http"
+
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
api "code.gitea.io/gitea/modules/structs"
@@ -41,18 +43,19 @@ func ListIssueLabels(ctx *context.APIContext) {
// "$ref": "#/responses/LabelList"
// "404":
// "$ref": "#/responses/notFound"
+
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
if models.IsErrIssueNotExist(err) {
ctx.NotFound()
} else {
- ctx.Error(500, "GetIssueByIndex", err)
+ ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
}
return
}
if err := issue.LoadAttributes(); err != nil {
- ctx.Error(500, "LoadAttributes", err)
+ ctx.Error(http.StatusInternalServerError, "LoadAttributes", err)
return
}
@@ -60,7 +63,7 @@ func ListIssueLabels(ctx *context.APIContext) {
for i := range issue.Labels {
apiLabels[i] = issue.Labels[i].APIFormat()
}
- ctx.JSON(200, &apiLabels)
+ ctx.JSON(http.StatusOK, &apiLabels)
}
// AddIssueLabels add labels for an issue
@@ -96,35 +99,38 @@ func AddIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
// responses:
// "200":
// "$ref": "#/responses/LabelList"
+ // "403":
+ // "$ref": "#/responses/forbidden"
+
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
if models.IsErrIssueNotExist(err) {
ctx.NotFound()
} else {
- ctx.Error(500, "GetIssueByIndex", err)
+ ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
}
return
}
if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
- ctx.Status(403)
+ ctx.Status(http.StatusForbidden)
return
}
labels, err := models.GetLabelsInRepoByIDs(ctx.Repo.Repository.ID, form.Labels)
if err != nil {
- ctx.Error(500, "GetLabelsInRepoByIDs", err)
+ ctx.Error(http.StatusInternalServerError, "GetLabelsInRepoByIDs", err)
return
}
if err = issue_service.AddLabels(issue, ctx.User, labels); err != nil {
- ctx.Error(500, "AddLabels", err)
+ ctx.Error(http.StatusInternalServerError, "AddLabels", err)
return
}
labels, err = models.GetLabelsByIssueID(issue.ID)
if err != nil {
- ctx.Error(500, "GetLabelsByIssueID", err)
+ ctx.Error(http.StatusInternalServerError, "GetLabelsByIssueID", err)
return
}
@@ -132,7 +138,7 @@ func AddIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
for i := range labels {
apiLabels[i] = labels[i].APIFormat()
}
- ctx.JSON(200, &apiLabels)
+ ctx.JSON(http.StatusOK, &apiLabels)
}
// DeleteIssueLabel delete a label for an issue
@@ -168,37 +174,42 @@ func DeleteIssueLabel(ctx *context.APIContext) {
// responses:
// "204":
// "$ref": "#/responses/empty"
+ // "403":
+ // "$ref": "#/responses/forbidden"
+ // "422":
+ // "$ref": "#/responses/validationError"
+
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
if models.IsErrIssueNotExist(err) {
ctx.NotFound()
} else {
- ctx.Error(500, "GetIssueByIndex", err)
+ ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
}
return
}
if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
- ctx.Status(403)
+ ctx.Status(http.StatusForbidden)
return
}
label, err := models.GetLabelInRepoByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
if err != nil {
if models.IsErrLabelNotExist(err) {
- ctx.Error(422, "", err)
+ ctx.Error(http.StatusUnprocessableEntity, "", err)
} else {
- ctx.Error(500, "GetLabelInRepoByID", err)
+ ctx.Error(http.StatusInternalServerError, "GetLabelInRepoByID", err)
}
return
}
if err := models.DeleteIssueLabel(issue, label, ctx.User); err != nil {
- ctx.Error(500, "DeleteIssueLabel", err)
+ ctx.Error(http.StatusInternalServerError, "DeleteIssueLabel", err)
return
}
- ctx.Status(204)
+ ctx.Status(http.StatusNoContent)
}
// ReplaceIssueLabels replace labels for an issue
@@ -234,35 +245,38 @@ func ReplaceIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
// responses:
// "200":
// "$ref": "#/responses/LabelList"
+ // "403":
+ // "$ref": "#/responses/forbidden"
+
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
if models.IsErrIssueNotExist(err) {
ctx.NotFound()
} else {
- ctx.Error(500, "GetIssueByIndex", err)
+ ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
}
return
}
if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
- ctx.Status(403)
+ ctx.Status(http.StatusForbidden)
return
}
labels, err := models.GetLabelsInRepoByIDs(ctx.Repo.Repository.ID, form.Labels)
if err != nil {
- ctx.Error(500, "GetLabelsInRepoByIDs", err)
+ ctx.Error(http.StatusInternalServerError, "GetLabelsInRepoByIDs", err)
return
}
if err := issue.ReplaceLabels(labels, ctx.User); err != nil {
- ctx.Error(500, "ReplaceLabels", err)
+ ctx.Error(http.StatusInternalServerError, "ReplaceLabels", err)
return
}
labels, err = models.GetLabelsByIssueID(issue.ID)
if err != nil {
- ctx.Error(500, "GetLabelsByIssueID", err)
+ ctx.Error(http.StatusInternalServerError, "GetLabelsByIssueID", err)
return
}
@@ -270,7 +284,7 @@ func ReplaceIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
for i := range labels {
apiLabels[i] = labels[i].APIFormat()
}
- ctx.JSON(200, &apiLabels)
+ ctx.JSON(http.StatusOK, &apiLabels)
}
// ClearIssueLabels delete all the labels for an issue
@@ -300,25 +314,28 @@ func ClearIssueLabels(ctx *context.APIContext) {
// responses:
// "204":
// "$ref": "#/responses/empty"
+ // "403":
+ // "$ref": "#/responses/forbidden"
+
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
if models.IsErrIssueNotExist(err) {
ctx.NotFound()
} else {
- ctx.Error(500, "GetIssueByIndex", err)
+ ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err)
}
return
}
if !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) {
- ctx.Status(403)
+ ctx.Status(http.StatusForbidden)
return
}
if err := issue_service.ClearLabels(issue, ctx.User); err != nil {
- ctx.Error(500, "ClearLabels", err)
+ ctx.Error(http.StatusInternalServerError, "ClearLabels", err)
return
}
- ctx.Status(204)
+ ctx.Status(http.StatusNoContent)
}