forked from forgejo/forgejo
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:
parent
050a8af424
commit
2848c5eb8f
52 changed files with 1262 additions and 648 deletions
|
@ -5,6 +5,8 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
@ -46,13 +48,14 @@ func GetWatchedRepos(ctx *context.APIContext) {
|
|||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/RepositoryList"
|
||||
|
||||
user := GetUserByParams(ctx)
|
||||
private := user.ID == ctx.User.ID
|
||||
repos, err := getWatchedRepos(user, private)
|
||||
if err != nil {
|
||||
ctx.Error(500, "getWatchedRepos", err)
|
||||
ctx.Error(http.StatusInternalServerError, "getWatchedRepos", err)
|
||||
}
|
||||
ctx.JSON(200, &repos)
|
||||
ctx.JSON(http.StatusOK, &repos)
|
||||
}
|
||||
|
||||
// GetMyWatchedRepos returns the repos that the authenticated user is watching
|
||||
|
@ -65,11 +68,12 @@ func GetMyWatchedRepos(ctx *context.APIContext) {
|
|||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/RepositoryList"
|
||||
|
||||
repos, err := getWatchedRepos(ctx.User, true)
|
||||
if err != nil {
|
||||
ctx.Error(500, "getWatchedRepos", err)
|
||||
ctx.Error(http.StatusInternalServerError, "getWatchedRepos", err)
|
||||
}
|
||||
ctx.JSON(200, &repos)
|
||||
ctx.JSON(http.StatusOK, &repos)
|
||||
}
|
||||
|
||||
// IsWatching returns whether the authenticated user is watching the repo
|
||||
|
@ -92,8 +96,9 @@ func IsWatching(ctx *context.APIContext) {
|
|||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/WatchInfo"
|
||||
|
||||
if models.IsWatching(ctx.User.ID, ctx.Repo.Repository.ID) {
|
||||
ctx.JSON(200, api.WatchInfo{
|
||||
ctx.JSON(http.StatusOK, api.WatchInfo{
|
||||
Subscribed: true,
|
||||
Ignored: false,
|
||||
Reason: nil,
|
||||
|
@ -125,12 +130,13 @@ func Watch(ctx *context.APIContext) {
|
|||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/WatchInfo"
|
||||
|
||||
err := models.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, true)
|
||||
if err != nil {
|
||||
ctx.Error(500, "WatchRepo", err)
|
||||
ctx.Error(http.StatusInternalServerError, "WatchRepo", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, api.WatchInfo{
|
||||
ctx.JSON(http.StatusOK, api.WatchInfo{
|
||||
Subscribed: true,
|
||||
Ignored: false,
|
||||
Reason: nil,
|
||||
|
@ -160,12 +166,13 @@ func Unwatch(ctx *context.APIContext) {
|
|||
// responses:
|
||||
// "204":
|
||||
// "$ref": "#/responses/empty"
|
||||
|
||||
err := models.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, false)
|
||||
if err != nil {
|
||||
ctx.Error(500, "UnwatchRepo", err)
|
||||
ctx.Error(http.StatusInternalServerError, "UnwatchRepo", err)
|
||||
return
|
||||
}
|
||||
ctx.Status(204)
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// subscriptionURL returns the URL of the subscription API endpoint of a repo
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue