summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/misc
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2019-12-20 18:07:12 +0100
committerLauris BH <lauris@nix.lv>2019-12-20 19:07:12 +0200
commit2848c5eb8f7333b6791afd296b12d21751d0516b (patch)
tree67ff6244026174116edbff1b4c4cdb5934401968 /routers/api/v1/misc
parent050a8af4243d7f5fff0a2f492b9166f4dfdf0ecf (diff)
downloadgitea-2848c5eb8f7333b6791afd296b12d21751d0516b.tar.gz
gitea-2848c5eb8f7333b6791afd296b12d21751d0516b.zip
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 :+1: * use ctx.InternalServerError * Revert "use numbers and not http.Status___ enum" This reverts commit b1ff386e2418ed6a7f183e756b13277d701278ef. * use http.Status* enum everywhere
Diffstat (limited to 'routers/api/v1/misc')
-rw-r--r--routers/api/v1/misc/markdown.go14
-rw-r--r--routers/api/v1/misc/swagger.go4
-rw-r--r--routers/api/v1/misc/version.go4
3 files changed, 14 insertions, 8 deletions
diff --git a/routers/api/v1/misc/markdown.go b/routers/api/v1/misc/markdown.go
index 23f0b168d0..5a44db5e8b 100644
--- a/routers/api/v1/misc/markdown.go
+++ b/routers/api/v1/misc/markdown.go
@@ -36,8 +36,9 @@ func Markdown(ctx *context.APIContext, form api.MarkdownOption) {
// "$ref": "#/responses/MarkdownRender"
// "422":
// "$ref": "#/responses/validationError"
+
if ctx.HasAPIError() {
- ctx.Error(422, "", ctx.GetErrMsg())
+ ctx.Error(http.StatusUnprocessableEntity, "", ctx.GetErrMsg())
return
}
@@ -65,20 +66,20 @@ func Markdown(ctx *context.APIContext, form api.MarkdownOption) {
if form.Wiki {
_, err := ctx.Write([]byte(markdown.RenderWiki(md, urlPrefix, meta)))
if err != nil {
- ctx.Error(http.StatusInternalServerError, "", err)
+ ctx.InternalServerError(err)
return
}
} else {
_, err := ctx.Write(markdown.Render(md, urlPrefix, meta))
if err != nil {
- ctx.Error(http.StatusInternalServerError, "", err)
+ ctx.InternalServerError(err)
return
}
}
default:
_, err := ctx.Write(markdown.RenderRaw([]byte(form.Text), "", false))
if err != nil {
- ctx.Error(http.StatusInternalServerError, "", err)
+ ctx.InternalServerError(err)
return
}
}
@@ -105,14 +106,15 @@ func MarkdownRaw(ctx *context.APIContext) {
// "$ref": "#/responses/MarkdownRender"
// "422":
// "$ref": "#/responses/validationError"
+
body, err := ctx.Req.Body().Bytes()
if err != nil {
- ctx.Error(422, "", err)
+ ctx.Error(http.StatusUnprocessableEntity, "", err)
return
}
_, err = ctx.Write(markdown.RenderRaw(body, "", false))
if err != nil {
- ctx.Error(http.StatusInternalServerError, "", err)
+ ctx.InternalServerError(err)
return
}
}
diff --git a/routers/api/v1/misc/swagger.go b/routers/api/v1/misc/swagger.go
index e17b775227..e46d4194b4 100644
--- a/routers/api/v1/misc/swagger.go
+++ b/routers/api/v1/misc/swagger.go
@@ -5,6 +5,8 @@
package misc
import (
+ "net/http"
+
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
)
@@ -15,5 +17,5 @@ const tplSwagger base.TplName = "swagger/ui"
// Swagger render swagger-ui page with v1 json
func Swagger(ctx *context.Context) {
ctx.Data["APIJSONVersion"] = "v1"
- ctx.HTML(200, tplSwagger)
+ ctx.HTML(http.StatusOK, tplSwagger)
}
diff --git a/routers/api/v1/misc/version.go b/routers/api/v1/misc/version.go
index 803f5ac716..b8c7d4f9ad 100644
--- a/routers/api/v1/misc/version.go
+++ b/routers/api/v1/misc/version.go
@@ -5,6 +5,8 @@
package misc
import (
+ "net/http"
+
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
@@ -20,5 +22,5 @@ func Version(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/ServerVersion"
- ctx.JSON(200, &structs.ServerVersion{Version: setting.AppVer})
+ ctx.JSON(http.StatusOK, &structs.ServerVersion{Version: setting.AppVer})
}