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:
6543 2019-12-20 18:07:12 +01:00 committed by Lauris BH
parent 050a8af424
commit 2848c5eb8f
52 changed files with 1262 additions and 648 deletions

View file

@ -5,6 +5,8 @@
package org
import (
"net/http"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
@ -28,17 +30,18 @@ func ListHooks(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/HookList"
org := ctx.Org.Organization
orgHooks, err := models.GetWebhooksByOrgID(org.ID)
if err != nil {
ctx.Error(500, "GetWebhooksByOrgID", err)
ctx.Error(http.StatusInternalServerError, "GetWebhooksByOrgID", err)
return
}
hooks := make([]*api.Hook, len(orgHooks))
for i, hook := range orgHooks {
hooks[i] = convert.ToHook(org.HomeLink(), hook)
}
ctx.JSON(200, hooks)
ctx.JSON(http.StatusOK, hooks)
}
// GetHook get an organization's hook by id
@ -63,13 +66,14 @@ func GetHook(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/Hook"
org := ctx.Org.Organization
hookID := ctx.ParamsInt64(":id")
hook, err := utils.GetOrgHook(ctx, org.ID, hookID)
if err != nil {
return
}
ctx.JSON(200, convert.ToHook(org.HomeLink(), hook))
ctx.JSON(http.StatusOK, convert.ToHook(org.HomeLink(), hook))
}
// CreateHook create a hook for an organization
@ -159,15 +163,16 @@ func DeleteHook(ctx *context.APIContext) {
// responses:
// "204":
// "$ref": "#/responses/empty"
org := ctx.Org.Organization
hookID := ctx.ParamsInt64(":id")
if err := models.DeleteWebhookByOrgID(org.ID, hookID); err != nil {
if models.IsErrWebhookNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(500, "DeleteWebhookByOrgID", err)
ctx.Error(http.StatusInternalServerError, "DeleteWebhookByOrgID", err)
}
return
}
ctx.Status(204)
ctx.Status(http.StatusNoContent)
}