1
1
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:
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,7 @@
package repo
import (
"net/http"
"time"
"code.gitea.io/gitea/models"
@@ -38,9 +39,10 @@ func ListMilestones(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/MilestoneList"
milestones, err := models.GetMilestonesByRepoID(ctx.Repo.Repository.ID, api.StateType(ctx.Query("state")))
if err != nil {
ctx.Error(500, "GetMilestonesByRepoID", err)
ctx.Error(http.StatusInternalServerError, "GetMilestonesByRepoID", err)
return
}
@@ -48,7 +50,7 @@ func ListMilestones(ctx *context.APIContext) {
for i := range milestones {
apiMilestones[i] = milestones[i].APIFormat()
}
ctx.JSON(200, &apiMilestones)
ctx.JSON(http.StatusOK, &apiMilestones)
}
// GetMilestone get a milestone for a repository
@@ -78,16 +80,17 @@ func GetMilestone(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/Milestone"
milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
if err != nil {
if models.IsErrMilestoneNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(500, "GetMilestoneByRepoID", err)
ctx.Error(http.StatusInternalServerError, "GetMilestoneByRepoID", err)
}
return
}
ctx.JSON(200, milestone.APIFormat())
ctx.JSON(http.StatusOK, milestone.APIFormat())
}
// CreateMilestone create a milestone for a repository
@@ -117,6 +120,7 @@ func CreateMilestone(ctx *context.APIContext, form api.CreateMilestoneOption) {
// responses:
// "201":
// "$ref": "#/responses/Milestone"
if form.Deadline == nil {
defaultDeadline, _ := time.ParseInLocation("2006-01-02", "9999-12-31", time.Local)
form.Deadline = &defaultDeadline
@@ -130,10 +134,10 @@ func CreateMilestone(ctx *context.APIContext, form api.CreateMilestoneOption) {
}
if err := models.NewMilestone(milestone); err != nil {
ctx.Error(500, "NewMilestone", err)
ctx.Error(http.StatusInternalServerError, "NewMilestone", err)
return
}
ctx.JSON(201, milestone.APIFormat())
ctx.JSON(http.StatusCreated, milestone.APIFormat())
}
// EditMilestone modify a milestone for a repository
@@ -169,12 +173,13 @@ func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) {
// responses:
// "200":
// "$ref": "#/responses/Milestone"
milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
if err != nil {
if models.IsErrMilestoneNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(500, "GetMilestoneByRepoID", err)
ctx.Error(http.StatusInternalServerError, "GetMilestoneByRepoID", err)
}
return
}
@@ -193,7 +198,7 @@ func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) {
ctx.ServerError("UpdateMilestone", err)
return
}
ctx.JSON(200, milestone.APIFormat())
ctx.JSON(http.StatusOK, milestone.APIFormat())
}
// DeleteMilestone delete a milestone for a repository
@@ -221,9 +226,10 @@ func DeleteMilestone(ctx *context.APIContext) {
// responses:
// "204":
// "$ref": "#/responses/empty"
if err := models.DeleteMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil {
ctx.Error(500, "DeleteMilestoneByRepoID", err)
ctx.Error(http.StatusInternalServerError, "DeleteMilestoneByRepoID", err)
return
}
ctx.Status(204)
ctx.Status(http.StatusNoContent)
}