mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
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 👍
* use ctx.InternalServerError
* Revert "use numbers and not http.Status___ enum"
This reverts commit b1ff386e24
.
* use http.Status* enum everywhere
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
package repo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
@@ -35,9 +37,10 @@ func ListHooks(ctx *context.APIContext) {
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/HookList"
|
||||
|
||||
hooks, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID)
|
||||
if err != nil {
|
||||
ctx.Error(500, "GetWebhooksByRepoID", err)
|
||||
ctx.Error(http.StatusInternalServerError, "GetWebhooksByRepoID", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -45,7 +48,7 @@ func ListHooks(ctx *context.APIContext) {
|
||||
for i := range hooks {
|
||||
apiHooks[i] = convert.ToHook(ctx.Repo.RepoLink, hooks[i])
|
||||
}
|
||||
ctx.JSON(200, &apiHooks)
|
||||
ctx.JSON(http.StatusOK, &apiHooks)
|
||||
}
|
||||
|
||||
// GetHook get a repo's hook by id
|
||||
@@ -75,13 +78,16 @@ func GetHook(ctx *context.APIContext) {
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/Hook"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
|
||||
repo := ctx.Repo
|
||||
hookID := ctx.ParamsInt64(":id")
|
||||
hook, err := utils.GetRepoHook(ctx, repo.Repository.ID, hookID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, convert.ToHook(repo.RepoLink, hook))
|
||||
ctx.JSON(http.StatusOK, convert.ToHook(repo.RepoLink, hook))
|
||||
}
|
||||
|
||||
// TestHook tests a hook
|
||||
@@ -111,9 +117,10 @@ func TestHook(ctx *context.APIContext) {
|
||||
// responses:
|
||||
// "204":
|
||||
// "$ref": "#/responses/empty"
|
||||
|
||||
if ctx.Repo.Commit == nil {
|
||||
// if repo does not have any commits, then don't send a webhook
|
||||
ctx.Status(204)
|
||||
ctx.Status(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -134,11 +141,11 @@ func TestHook(ctx *context.APIContext) {
|
||||
Pusher: convert.ToUser(ctx.User, ctx.IsSigned, false),
|
||||
Sender: convert.ToUser(ctx.User, ctx.IsSigned, false),
|
||||
}); err != nil {
|
||||
ctx.Error(500, "PrepareWebhook: ", err)
|
||||
ctx.Error(http.StatusInternalServerError, "PrepareWebhook: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Status(204)
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// CreateHook create a hook for a repository
|
||||
@@ -242,9 +249,9 @@ func DeleteHook(ctx *context.APIContext) {
|
||||
if models.IsErrWebhookNotExist(err) {
|
||||
ctx.NotFound()
|
||||
} else {
|
||||
ctx.Error(500, "DeleteWebhookByRepoID", err)
|
||||
ctx.Error(http.StatusInternalServerError, "DeleteWebhookByRepoID", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
ctx.Status(204)
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
Reference in New Issue
Block a user