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

@ -6,6 +6,7 @@
package repo
import (
"net/http"
"strconv"
"code.gitea.io/gitea/models"
@ -34,9 +35,10 @@ func ListLabels(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/LabelList"
labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Query("sort"))
if err != nil {
ctx.Error(500, "GetLabelsByRepoID", err)
ctx.Error(http.StatusInternalServerError, "GetLabelsByRepoID", err)
return
}
@ -44,7 +46,7 @@ func ListLabels(ctx *context.APIContext) {
for i := range labels {
apiLabels[i] = labels[i].APIFormat()
}
ctx.JSON(200, &apiLabels)
ctx.JSON(http.StatusOK, &apiLabels)
}
// GetLabel get label by repository and label id
@ -74,6 +76,7 @@ func GetLabel(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/Label"
var (
label *models.Label
err error
@ -88,12 +91,12 @@ func GetLabel(ctx *context.APIContext) {
if models.IsErrLabelNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(500, "GetLabelByRepoID", err)
ctx.Error(http.StatusInternalServerError, "GetLabelByRepoID", err)
}
return
}
ctx.JSON(200, label.APIFormat())
ctx.JSON(http.StatusOK, label.APIFormat())
}
// CreateLabel create a label for a repository
@ -123,6 +126,7 @@ func CreateLabel(ctx *context.APIContext, form api.CreateLabelOption) {
// responses:
// "201":
// "$ref": "#/responses/Label"
label := &models.Label{
Name: form.Name,
Color: form.Color,
@ -130,10 +134,10 @@ func CreateLabel(ctx *context.APIContext, form api.CreateLabelOption) {
Description: form.Description,
}
if err := models.NewLabel(label); err != nil {
ctx.Error(500, "NewLabel", err)
ctx.Error(http.StatusInternalServerError, "NewLabel", err)
return
}
ctx.JSON(201, label.APIFormat())
ctx.JSON(http.StatusCreated, label.APIFormat())
}
// EditLabel modify a label for a repository
@ -169,12 +173,13 @@ func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
// responses:
// "200":
// "$ref": "#/responses/Label"
label, err := models.GetLabelInRepoByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
if err != nil {
if models.IsErrLabelNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(500, "GetLabelByRepoID", err)
ctx.Error(http.StatusInternalServerError, "GetLabelByRepoID", err)
}
return
}
@ -192,7 +197,7 @@ func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
ctx.ServerError("UpdateLabel", err)
return
}
ctx.JSON(200, label.APIFormat())
ctx.JSON(http.StatusOK, label.APIFormat())
}
// DeleteLabel delete a label for a repository
@ -220,10 +225,11 @@ func DeleteLabel(ctx *context.APIContext) {
// responses:
// "204":
// "$ref": "#/responses/empty"
if err := models.DeleteLabel(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil {
ctx.Error(500, "DeleteLabel", err)
ctx.Error(http.StatusInternalServerError, "DeleteLabel", err)
return
}
ctx.Status(204)
ctx.Status(http.StatusNoContent)
}