1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Add missing 404 response to Swagger (#27038)

Most middleware throw a 404 in case something is not found e.g. a Repo
that is not existing. But most API endpoints don't include the 404
response in their documentation. This PR changes this.
This commit is contained in:
JakobDev
2023-09-13 04:37:54 +02:00
committed by GitHub
parent 8ecdc93f8b
commit aaeec2a392
46 changed files with 750 additions and 0 deletions

View File

@@ -40,6 +40,8 @@ func ListActionsSecrets(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/SecretList"
// "404":
// "$ref": "#/responses/notFound"
opts := &secret_model.FindSecretsOptions{
OwnerID: ctx.Org.Organization.ID,

View File

@@ -33,6 +33,8 @@ func UpdateAvatar(ctx *context.APIContext) {
// responses:
// "204":
// "$ref": "#/responses/empty"
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.UpdateUserAvatarOption)
content, err := base64.StdEncoding.DecodeString(form.Image)
@@ -65,6 +67,8 @@ func DeleteAvatar(ctx *context.APIContext) {
// responses:
// "204":
// "$ref": "#/responses/empty"
// "404":
// "$ref": "#/responses/notFound"
err := user_service.DeleteAvatar(ctx.Org.Organization.AsUser())
if err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteAvatar", err)

View File

@@ -37,6 +37,8 @@ func ListHooks(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/HookList"
// "404":
// "$ref": "#/responses/notFound"
utils.ListOwnerHooks(
ctx,
@@ -66,6 +68,8 @@ func GetHook(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/Hook"
// "404":
// "$ref": "#/responses/notFound"
hook, err := utils.GetOwnerHook(ctx, ctx.ContextUser.ID, ctx.ParamsInt64("id"))
if err != nil {
@@ -103,6 +107,8 @@ func CreateHook(ctx *context.APIContext) {
// responses:
// "201":
// "$ref": "#/responses/Hook"
// "404":
// "$ref": "#/responses/notFound"
utils.AddOwnerHook(
ctx,
@@ -139,6 +145,8 @@ func EditHook(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/Hook"
// "404":
// "$ref": "#/responses/notFound"
utils.EditOwnerHook(
ctx,
@@ -170,6 +178,8 @@ func DeleteHook(ctx *context.APIContext) {
// responses:
// "204":
// "$ref": "#/responses/empty"
// "404":
// "$ref": "#/responses/notFound"
utils.DeleteOwnerHook(
ctx,

View File

@@ -41,6 +41,8 @@ func ListLabels(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/LabelList"
// "404":
// "$ref": "#/responses/notFound"
labels, err := issues_model.GetLabelsByOrgID(ctx, ctx.Org.Organization.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
if err != nil {
@@ -80,6 +82,8 @@ func CreateLabel(ctx *context.APIContext) {
// responses:
// "201":
// "$ref": "#/responses/Label"
// "404":
// "$ref": "#/responses/notFound"
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.CreateLabelOption)
@@ -128,6 +132,8 @@ func GetLabel(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/Label"
// "404":
// "$ref": "#/responses/notFound"
var (
label *issues_model.Label
@@ -179,6 +185,8 @@ func EditLabel(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/Label"
// "404":
// "$ref": "#/responses/notFound"
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.EditLabelOption)
@@ -238,6 +246,8 @@ func DeleteLabel(ctx *context.APIContext) {
// responses:
// "204":
// "$ref": "#/responses/empty"
// "404":
// "$ref": "#/responses/notFound"
if err := issues_model.DeleteLabel(ctx.Org.Organization.ID, ctx.ParamsInt64(":id")); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteLabel", err)

View File

@@ -70,6 +70,8 @@ func ListMembers(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/UserList"
// "404":
// "$ref": "#/responses/notFound"
publicOnly := true
if ctx.Doer != nil {
@@ -107,6 +109,8 @@ func ListPublicMembers(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/UserList"
// "404":
// "$ref": "#/responses/notFound"
listMembers(ctx, true)
}
@@ -225,6 +229,8 @@ func PublicizeMember(ctx *context.APIContext) {
// description: membership publicized
// "403":
// "$ref": "#/responses/forbidden"
// "404":
// "$ref": "#/responses/notFound"
userToPublicize := user.GetUserByParams(ctx)
if ctx.Written() {
@@ -265,6 +271,8 @@ func ConcealMember(ctx *context.APIContext) {
// "$ref": "#/responses/empty"
// "403":
// "$ref": "#/responses/forbidden"
// "404":
// "$ref": "#/responses/notFound"
userToConceal := user.GetUserByParams(ctx)
if ctx.Written() {
@@ -303,6 +311,8 @@ func DeleteMember(ctx *context.APIContext) {
// responses:
// "204":
// description: member removed
// "404":
// "$ref": "#/responses/notFound"
member := user.GetUserByParams(ctx)
if ctx.Written() {

View File

@@ -70,6 +70,8 @@ func ListMyOrgs(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/OrganizationList"
// "404":
// "$ref": "#/responses/notFound"
listUserOrgs(ctx, ctx.Doer)
}
@@ -98,6 +100,8 @@ func ListUserOrgs(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/OrganizationList"
// "404":
// "$ref": "#/responses/notFound"
listUserOrgs(ctx, ctx.ContextUser)
}
@@ -295,6 +299,8 @@ func Get(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/Organization"
// "404":
// "$ref": "#/responses/notFound"
if !organization.HasOrgOrUserVisible(ctx, ctx.Org.Organization.AsUser(), ctx.Doer) {
ctx.NotFound("HasOrgOrUserVisible", nil)
@@ -334,6 +340,8 @@ func Edit(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/Organization"
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.EditOrgOption)
org := ctx.Org.Organization
org.FullName = form.FullName
@@ -374,6 +382,8 @@ func Delete(ctx *context.APIContext) {
// responses:
// "204":
// "$ref": "#/responses/empty"
// "404":
// "$ref": "#/responses/notFound"
if err := org.DeleteOrganization(ctx.Org.Organization); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteOrganization", err)

View File

@@ -50,6 +50,8 @@ func ListTeams(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/TeamList"
// "404":
// "$ref": "#/responses/notFound"
teams, count, err := organization.SearchTeam(&organization.SearchTeamOptions{
ListOptions: utils.GetListOptions(ctx),
@@ -126,6 +128,8 @@ func GetTeam(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/Team"
// "404":
// "$ref": "#/responses/notFound"
apiTeam, err := convert.ToTeam(ctx, ctx.Org.Team, true)
if err != nil {
@@ -204,6 +208,8 @@ func CreateTeam(ctx *context.APIContext) {
// responses:
// "201":
// "$ref": "#/responses/Team"
// "404":
// "$ref": "#/responses/notFound"
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.CreateTeamOption)
@@ -272,6 +278,8 @@ func EditTeam(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/Team"
// "404":
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.EditTeamOption)
team := ctx.Org.Team
@@ -350,6 +358,8 @@ func DeleteTeam(ctx *context.APIContext) {
// responses:
// "204":
// description: team deleted
// "404":
// "$ref": "#/responses/notFound"
if err := models.DeleteTeam(ctx.Org.Team); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteTeam", err)
@@ -383,6 +393,8 @@ func GetTeamMembers(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/UserList"
// "404":
// "$ref": "#/responses/notFound"
isMember, err := organization.IsOrganizationMember(ctx, ctx.Org.Team.OrgID, ctx.Doer.ID)
if err != nil {
@@ -550,6 +562,8 @@ func GetTeamRepos(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/RepositoryList"
// "404":
// "$ref": "#/responses/notFound"
team := ctx.Org.Team
teamRepos, err := organization.GetTeamRepositories(ctx, &organization.SearchTeamRepoOptions{
@@ -665,6 +679,8 @@ func AddTeamRepository(ctx *context.APIContext) {
// "$ref": "#/responses/empty"
// "403":
// "$ref": "#/responses/forbidden"
// "404":
// "$ref": "#/responses/notFound"
repo := getRepositoryByParams(ctx)
if ctx.Written() {
@@ -715,6 +731,8 @@ func RemoveTeamRepository(ctx *context.APIContext) {
// "$ref": "#/responses/empty"
// "403":
// "$ref": "#/responses/forbidden"
// "404":
// "$ref": "#/responses/notFound"
repo := getRepositoryByParams(ctx)
if ctx.Written() {
@@ -775,6 +793,8 @@ func SearchTeam(ctx *context.APIContext) {
// type: array
// items:
// "$ref": "#/definitions/Team"
// "404":
// "$ref": "#/responses/notFound"
listOptions := utils.GetListOptions(ctx)