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 user
import (
"net/http"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
api "code.gitea.io/gitea/modules/structs"
@ -14,7 +16,7 @@ import (
func listUserRepos(ctx *context.APIContext, u *models.User, private bool) {
repos, err := models.GetUserRepositories(u.ID, private, 1, u.NumRepos, "")
if err != nil {
ctx.Error(500, "GetUserRepositories", err)
ctx.Error(http.StatusInternalServerError, "GetUserRepositories", err)
return
}
@ -22,14 +24,14 @@ func listUserRepos(ctx *context.APIContext, u *models.User, private bool) {
for i := range repos {
access, err := models.AccessLevel(ctx.User, repos[i])
if err != nil {
ctx.Error(500, "AccessLevel", err)
ctx.Error(http.StatusInternalServerError, "AccessLevel", err)
return
}
if ctx.IsSigned && ctx.User.IsAdmin || access >= models.AccessModeRead {
apiRepos = append(apiRepos, repos[i].APIFormat(access))
}
}
ctx.JSON(200, &apiRepos)
ctx.JSON(http.StatusOK, &apiRepos)
}
// ListUserRepos - list the repos owned by the given user.
@ -48,6 +50,7 @@ func ListUserRepos(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/RepositoryList"
user := GetUserByParams(ctx)
if ctx.Written() {
return
@ -66,14 +69,15 @@ func ListMyRepos(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/RepositoryList"
ownRepos, err := models.GetUserRepositories(ctx.User.ID, true, 1, ctx.User.NumRepos, "")
if err != nil {
ctx.Error(500, "GetUserRepositories", err)
ctx.Error(http.StatusInternalServerError, "GetUserRepositories", err)
return
}
accessibleReposMap, err := ctx.User.GetRepositoryAccesses()
if err != nil {
ctx.Error(500, "GetRepositoryAccesses", err)
ctx.Error(http.StatusInternalServerError, "GetRepositoryAccesses", err)
return
}
@ -86,7 +90,7 @@ func ListMyRepos(ctx *context.APIContext) {
apiRepos[i] = repo.APIFormat(access)
i++
}
ctx.JSON(200, &apiRepos)
ctx.JSON(http.StatusOK, &apiRepos)
}
// ListOrgRepos - list the repositories of an organization.
@ -105,5 +109,6 @@ func ListOrgRepos(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/RepositoryList"
listUserRepos(ctx, ctx.Org.Organization, ctx.IsSigned)
}