aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo/topic.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/topic.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/topic.go')
-rw-r--r--routers/api/v1/repo/topic.go48
1 files changed, 25 insertions, 23 deletions
diff --git a/routers/api/v1/repo/topic.go b/routers/api/v1/repo/topic.go
index 1656fd1b16..0c56f2a769 100644
--- a/routers/api/v1/repo/topic.go
+++ b/routers/api/v1/repo/topic.go
@@ -42,9 +42,7 @@ func ListTopics(ctx *context.APIContext) {
})
if err != nil {
log.Error("ListTopics failed: %v", err)
- ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
- "message": "ListTopics failed.",
- })
+ ctx.InternalServerError(err)
return
}
@@ -82,6 +80,8 @@ func UpdateTopics(ctx *context.APIContext, form api.RepoTopicOptions) {
// responses:
// "204":
// "$ref": "#/responses/empty"
+ // "422":
+ // "$ref": "#/responses/invalidTopicsError"
topicNames := form.Topics
validTopics, invalidTopics := models.SanitizeAndValidateTopics(topicNames)
@@ -105,9 +105,7 @@ func UpdateTopics(ctx *context.APIContext, form api.RepoTopicOptions) {
err := models.SaveTopics(ctx.Repo.Repository.ID, validTopics...)
if err != nil {
log.Error("SaveTopics failed: %v", err)
- ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
- "message": "Save topics failed.",
- })
+ ctx.InternalServerError(err)
return
}
@@ -140,11 +138,16 @@ func AddTopic(ctx *context.APIContext) {
// responses:
// "204":
// "$ref": "#/responses/empty"
+ // "422":
+ // "$ref": "#/responses/invalidTopicsError"
topicName := strings.TrimSpace(strings.ToLower(ctx.Params(":topic")))
if !models.ValidateTopic(topicName) {
- ctx.Error(http.StatusUnprocessableEntity, "", "Topic name is invalid")
+ ctx.JSON(http.StatusUnprocessableEntity, map[string]interface{}{
+ "invalidTopics": topicName,
+ "message": "Topic name is invalid",
+ })
return
}
@@ -154,9 +157,7 @@ func AddTopic(ctx *context.APIContext) {
})
if err != nil {
log.Error("AddTopic failed: %v", err)
- ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
- "message": "ListTopics failed.",
- })
+ ctx.InternalServerError(err)
return
}
if len(topics) >= 25 {
@@ -169,9 +170,7 @@ func AddTopic(ctx *context.APIContext) {
_, err = models.AddTopic(ctx.Repo.Repository.ID, topicName)
if err != nil {
log.Error("AddTopic failed: %v", err)
- ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
- "message": "AddTopic failed.",
- })
+ ctx.InternalServerError(err)
return
}
@@ -204,19 +203,23 @@ func DeleteTopic(ctx *context.APIContext) {
// responses:
// "204":
// "$ref": "#/responses/empty"
+ // "422":
+ // "$ref": "#/responses/invalidTopicsError"
+
topicName := strings.TrimSpace(strings.ToLower(ctx.Params(":topic")))
if !models.ValidateTopic(topicName) {
- ctx.Error(http.StatusUnprocessableEntity, "", "Topic name is invalid")
+ ctx.JSON(http.StatusUnprocessableEntity, map[string]interface{}{
+ "invalidTopics": topicName,
+ "message": "Topic name is invalid",
+ })
return
}
topic, err := models.DeleteTopic(ctx.Repo.Repository.ID, topicName)
if err != nil {
log.Error("DeleteTopic failed: %v", err)
- ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
- "message": "DeleteTopic failed.",
- })
+ ctx.InternalServerError(err)
return
}
@@ -243,10 +246,11 @@ func TopicSearch(ctx *context.Context) {
// responses:
// "200":
// "$ref": "#/responses/TopicListResponse"
+ // "403":
+ // "$ref": "#/responses/forbidden"
+
if ctx.User == nil {
- ctx.JSON(http.StatusForbidden, map[string]interface{}{
- "message": "Only owners could change the topics.",
- })
+ ctx.Error(http.StatusForbidden, "UserIsNil", "Only owners could change the topics.")
return
}
@@ -258,9 +262,7 @@ func TopicSearch(ctx *context.Context) {
})
if err != nil {
log.Error("SearchTopics failed: %v", err)
- ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
- "message": "Search topics failed.",
- })
+ ctx.InternalServerError(err)
return
}