mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-21 01:10:19 +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:
parent
050a8af424
commit
2848c5eb8f
52 changed files with 1262 additions and 648 deletions
|
@ -6,6 +6,8 @@
|
|||
package org
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/convert"
|
||||
|
@ -15,7 +17,7 @@ import (
|
|||
|
||||
func listUserOrgs(ctx *context.APIContext, u *models.User, all bool) {
|
||||
if err := u.GetOrganizations(all); err != nil {
|
||||
ctx.Error(500, "GetOrganizations", err)
|
||||
ctx.Error(http.StatusInternalServerError, "GetOrganizations", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -23,7 +25,7 @@ func listUserOrgs(ctx *context.APIContext, u *models.User, all bool) {
|
|||
for i := range u.Orgs {
|
||||
apiOrgs[i] = convert.ToOrganization(u.Orgs[i])
|
||||
}
|
||||
ctx.JSON(200, &apiOrgs)
|
||||
ctx.JSON(http.StatusOK, &apiOrgs)
|
||||
}
|
||||
|
||||
// ListMyOrgs list all my orgs
|
||||
|
@ -36,6 +38,7 @@ func ListMyOrgs(ctx *context.APIContext) {
|
|||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/OrganizationList"
|
||||
|
||||
listUserOrgs(ctx, ctx.User, true)
|
||||
}
|
||||
|
||||
|
@ -55,6 +58,7 @@ func ListUserOrgs(ctx *context.APIContext) {
|
|||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/OrganizationList"
|
||||
|
||||
u := user.GetUserByParams(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
|
@ -85,7 +89,7 @@ func Create(ctx *context.APIContext, form api.CreateOrgOption) {
|
|||
// "$ref": "#/responses/validationError"
|
||||
|
||||
if !ctx.User.CanCreateOrganization() {
|
||||
ctx.Error(403, "Create organization not allowed", nil)
|
||||
ctx.Error(http.StatusForbidden, "Create organization not allowed", nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -109,14 +113,14 @@ func Create(ctx *context.APIContext, form api.CreateOrgOption) {
|
|||
if models.IsErrUserAlreadyExist(err) ||
|
||||
models.IsErrNameReserved(err) ||
|
||||
models.IsErrNamePatternNotAllowed(err) {
|
||||
ctx.Error(422, "", err)
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
||||
} else {
|
||||
ctx.Error(500, "CreateOrganization", err)
|
||||
ctx.Error(http.StatusInternalServerError, "CreateOrganization", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(201, convert.ToOrganization(org))
|
||||
ctx.JSON(http.StatusCreated, convert.ToOrganization(org))
|
||||
}
|
||||
|
||||
// Get get an organization
|
||||
|
@ -135,11 +139,12 @@ func Get(ctx *context.APIContext) {
|
|||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/Organization"
|
||||
|
||||
if !models.HasOrgVisible(ctx.Org.Organization, ctx.User) {
|
||||
ctx.NotFound("HasOrgVisible", nil)
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, convert.ToOrganization(ctx.Org.Organization))
|
||||
ctx.JSON(http.StatusOK, convert.ToOrganization(ctx.Org.Organization))
|
||||
}
|
||||
|
||||
// Edit change an organization's information
|
||||
|
@ -165,6 +170,7 @@ func Edit(ctx *context.APIContext, form api.EditOrgOption) {
|
|||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/Organization"
|
||||
|
||||
org := ctx.Org.Organization
|
||||
org.FullName = form.FullName
|
||||
org.Description = form.Description
|
||||
|
@ -174,11 +180,11 @@ func Edit(ctx *context.APIContext, form api.EditOrgOption) {
|
|||
org.Visibility = api.VisibilityModes[form.Visibility]
|
||||
}
|
||||
if err := models.UpdateUserCols(org, "full_name", "description", "website", "location", "visibility"); err != nil {
|
||||
ctx.Error(500, "EditOrganization", err)
|
||||
ctx.Error(http.StatusInternalServerError, "EditOrganization", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, convert.ToOrganization(org))
|
||||
ctx.JSON(http.StatusOK, convert.ToOrganization(org))
|
||||
}
|
||||
|
||||
//Delete an organization
|
||||
|
@ -197,9 +203,10 @@ func Delete(ctx *context.APIContext) {
|
|||
// responses:
|
||||
// "204":
|
||||
// "$ref": "#/responses/empty"
|
||||
|
||||
if err := models.DeleteOrganization(ctx.Org.Organization); err != nil {
|
||||
ctx.Error(500, "DeleteOrganization", err)
|
||||
ctx.Error(http.StatusInternalServerError, "DeleteOrganization", err)
|
||||
return
|
||||
}
|
||||
ctx.Status(204)
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue