Clarify path param naming (#32969)
In history (from some legacy frameworks), both `:name` and `name` are supported as path path name, `:name` is an alias to `name`. To make code consistent, now we should only use `name` but not `:name`. Also added panic check in related functions to make sure the name won't be abused in case some downstreams still use them.
This commit is contained in:
parent
b8b690feb9
commit
2a828e2798
102 changed files with 461 additions and 429 deletions
|
@ -109,7 +109,7 @@ func GetHook(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/notFound"
|
||||
|
||||
repo := ctx.Repo
|
||||
hookID := ctx.PathParamInt64(":id")
|
||||
hookID := ctx.PathParamInt64("id")
|
||||
hook, err := utils.GetRepoHook(ctx, repo.Repository.ID, hookID)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -168,7 +168,7 @@ func TestHook(ctx *context.APIContext) {
|
|||
ref = r
|
||||
}
|
||||
|
||||
hookID := ctx.PathParamInt64(":id")
|
||||
hookID := ctx.PathParamInt64("id")
|
||||
hook, err := utils.GetRepoHook(ctx, ctx.Repo.Repository.ID, hookID)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -263,7 +263,7 @@ func EditHook(ctx *context.APIContext) {
|
|||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
form := web.GetForm(ctx).(*api.EditHookOption)
|
||||
hookID := ctx.PathParamInt64(":id")
|
||||
hookID := ctx.PathParamInt64("id")
|
||||
utils.EditRepoHook(ctx, form, hookID)
|
||||
}
|
||||
|
||||
|
@ -296,7 +296,7 @@ func DeleteHook(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/empty"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
if err := webhook.DeleteWebhookByRepoID(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64(":id")); err != nil {
|
||||
if err := webhook.DeleteWebhookByRepoID(ctx, ctx.Repo.Repository.ID, ctx.PathParamInt64("id")); err != nil {
|
||||
if webhook.IsErrWebhookNotExist(err) {
|
||||
ctx.NotFound()
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue