mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-04 05:18:25 +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:
		@@ -27,7 +27,7 @@ func GetOrgHook(ctx *context.APIContext, orgID, hookID int64) (*models.Webhook,
 | 
			
		||||
		if models.IsErrWebhookNotExist(err) {
 | 
			
		||||
			ctx.NotFound()
 | 
			
		||||
		} else {
 | 
			
		||||
			ctx.Error(500, "GetWebhookByOrgID", err)
 | 
			
		||||
			ctx.Error(http.StatusInternalServerError, "GetWebhookByOrgID", err)
 | 
			
		||||
		}
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
@@ -42,7 +42,7 @@ func GetRepoHook(ctx *context.APIContext, repoID, hookID int64) (*models.Webhook
 | 
			
		||||
		if models.IsErrWebhookNotExist(err) {
 | 
			
		||||
			ctx.NotFound()
 | 
			
		||||
		} else {
 | 
			
		||||
			ctx.Error(500, "GetWebhookByID", err)
 | 
			
		||||
			ctx.Error(http.StatusInternalServerError, "GetWebhookByID", err)
 | 
			
		||||
		}
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
@@ -53,17 +53,17 @@ func GetRepoHook(ctx *context.APIContext, repoID, hookID int64) (*models.Webhook
 | 
			
		||||
// write the appropriate error to `ctx`. Return whether the form is valid
 | 
			
		||||
func CheckCreateHookOption(ctx *context.APIContext, form *api.CreateHookOption) bool {
 | 
			
		||||
	if !models.IsValidHookTaskType(form.Type) {
 | 
			
		||||
		ctx.Error(422, "", "Invalid hook type")
 | 
			
		||||
		ctx.Error(http.StatusUnprocessableEntity, "", "Invalid hook type")
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
	for _, name := range []string{"url", "content_type"} {
 | 
			
		||||
		if _, ok := form.Config[name]; !ok {
 | 
			
		||||
			ctx.Error(422, "", "Missing config option: "+name)
 | 
			
		||||
			ctx.Error(http.StatusUnprocessableEntity, "", "Missing config option: "+name)
 | 
			
		||||
			return false
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if !models.IsValidHookContentType(form.Config["content_type"]) {
 | 
			
		||||
		ctx.Error(422, "", "Invalid content type")
 | 
			
		||||
		ctx.Error(http.StatusUnprocessableEntity, "", "Invalid content type")
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
	return true
 | 
			
		||||
@@ -121,12 +121,12 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, orgID, repoID
 | 
			
		||||
	if w.HookTaskType == models.SLACK {
 | 
			
		||||
		channel, ok := form.Config["channel"]
 | 
			
		||||
		if !ok {
 | 
			
		||||
			ctx.Error(422, "", "Missing config option: channel")
 | 
			
		||||
			ctx.Error(http.StatusUnprocessableEntity, "", "Missing config option: channel")
 | 
			
		||||
			return nil, false
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if !utils.IsValidSlackChannel(channel) {
 | 
			
		||||
			ctx.Error(400, "", "Invalid slack channel name")
 | 
			
		||||
			ctx.Error(http.StatusBadRequest, "", "Invalid slack channel name")
 | 
			
		||||
			return nil, false
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@@ -137,17 +137,17 @@ func addHook(ctx *context.APIContext, form *api.CreateHookOption, orgID, repoID
 | 
			
		||||
			Color:    form.Config["color"],
 | 
			
		||||
		})
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			ctx.Error(500, "slack: JSON marshal failed", err)
 | 
			
		||||
			ctx.Error(http.StatusInternalServerError, "slack: JSON marshal failed", err)
 | 
			
		||||
			return nil, false
 | 
			
		||||
		}
 | 
			
		||||
		w.Meta = string(meta)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err := w.UpdateEvent(); err != nil {
 | 
			
		||||
		ctx.Error(500, "UpdateEvent", err)
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "UpdateEvent", err)
 | 
			
		||||
		return nil, false
 | 
			
		||||
	} else if err := models.CreateWebhook(w); err != nil {
 | 
			
		||||
		ctx.Error(500, "CreateWebhook", err)
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "CreateWebhook", err)
 | 
			
		||||
		return nil, false
 | 
			
		||||
	}
 | 
			
		||||
	return w, true
 | 
			
		||||
@@ -167,7 +167,7 @@ func EditOrgHook(ctx *context.APIContext, form *api.EditHookOption, hookID int64
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	ctx.JSON(200, convert.ToHook(org.HomeLink(), updated))
 | 
			
		||||
	ctx.JSON(http.StatusOK, convert.ToHook(org.HomeLink(), updated))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// EditRepoHook edit webhook `w` according to `form`. Writes to `ctx` accordingly
 | 
			
		||||
@@ -184,7 +184,7 @@ func EditRepoHook(ctx *context.APIContext, form *api.EditHookOption, hookID int6
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	ctx.JSON(200, convert.ToHook(repo.RepoLink, updated))
 | 
			
		||||
	ctx.JSON(http.StatusOK, convert.ToHook(repo.RepoLink, updated))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// editHook edit the webhook `w` according to `form`. If an error occurs, write
 | 
			
		||||
@@ -196,7 +196,7 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *models.Webho
 | 
			
		||||
		}
 | 
			
		||||
		if ct, ok := form.Config["content_type"]; ok {
 | 
			
		||||
			if !models.IsValidHookContentType(ct) {
 | 
			
		||||
				ctx.Error(422, "", "Invalid content type")
 | 
			
		||||
				ctx.Error(http.StatusUnprocessableEntity, "", "Invalid content type")
 | 
			
		||||
				return false
 | 
			
		||||
			}
 | 
			
		||||
			w.ContentType = models.ToHookContentType(ct)
 | 
			
		||||
@@ -211,7 +211,7 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *models.Webho
 | 
			
		||||
					Color:    form.Config["color"],
 | 
			
		||||
				})
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					ctx.Error(500, "slack: JSON marshal failed", err)
 | 
			
		||||
					ctx.Error(http.StatusInternalServerError, "slack: JSON marshal failed", err)
 | 
			
		||||
					return false
 | 
			
		||||
				}
 | 
			
		||||
				w.Meta = string(meta)
 | 
			
		||||
@@ -241,7 +241,7 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *models.Webho
 | 
			
		||||
	w.BranchFilter = form.BranchFilter
 | 
			
		||||
 | 
			
		||||
	if err := w.UpdateEvent(); err != nil {
 | 
			
		||||
		ctx.Error(500, "UpdateEvent", err)
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "UpdateEvent", err)
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -250,7 +250,7 @@ func editHook(ctx *context.APIContext, form *api.EditHookOption, w *models.Webho
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err := models.UpdateWebhook(w); err != nil {
 | 
			
		||||
		ctx.Error(500, "UpdateWebhook", err)
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "UpdateWebhook", err)
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
	return true
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user