diff --git a/modules/context/api.go b/modules/context/api.go index faabef44d..b505cbde4 100644 --- a/modules/context/api.go +++ b/modules/context/api.go @@ -127,6 +127,28 @@ func (ctx *APIContext) FileNameError(objs ...interface{}) { "errors": errors, }) } +func (ctx *APIContext) FileExistError(objs ...interface{}) { + var message = "file does not exist" + var errors []string + + for _, obj := range objs { + // Ignore nil + if obj == nil { + continue + } + + if err, ok := obj.(error); ok { + errors = append(errors, err.Error()) + } else { + message = obj.(string) + } + } + ctx.JSON(500, map[string]interface{}{ + "message": message, + "documentation_url": setting.API.SwaggerURL, + "errors": errors, + }) +} // InternalServerError responds with an error message to the client with the error as a message // and the file and line of the caller. diff --git a/routers/api/v1/repo/wiki.go b/routers/api/v1/repo/wiki.go index 4c89fa4eb..c17b15ad1 100644 --- a/routers/api/v1/repo/wiki.go +++ b/routers/api/v1/repo/wiki.go @@ -325,10 +325,6 @@ func GetWiki(ctx *context.APIContext) { ctx.JSON(http.StatusOK, wiki) } -func DeleteWiki(ctx *context.APIContext) { - -} - func EditWiki(ctx *context.APIContext) { // swagger:operation PATCH /repos/{owner}/{repo}/wikies/{pagename} repository repoEditWiki // --- @@ -438,3 +434,42 @@ func EditWiki(ctx *context.APIContext) { } ctx.JSON(http.StatusOK, wiki) } +func DeleteWiki(ctx *context.APIContext) { + // swagger:operation DELETE /repos/{owner}/{repo}/wikies/{pagename} repository repoDeleteWiki + // --- + // summary: Delete a wiki in a repository + // produces: + // - application/json + // parameters: + // - name: owner + // in: path + // description: owner of the repo + // type: string + // required: true + // - name: repo + // in: path + // description: name of the repo + // type: string + // required: true + // - name: pagename + // in: path + // description: name of the wiki + // type: string + // required: true + // responses: + // "204": + // "$ref": "#/responses/empty" + // "500": + // "$ref": "#/responses/noFound" + + wikiName := wiki_service.NormalizeWikiName(ctx.Params(":page")) + if len(wikiName) == 0 { + wikiName = "Home" + } + + err2 := wiki_service.DeleteWikiPage(ctx.User, ctx.Repo.Repository, wikiName) + if err2 != nil { + ctx.FileExistError() + return + } +} diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index f948386c9..b278c7393 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -9887,6 +9887,47 @@ } } }, + "delete": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Delete a wiki in a repository", + "operationId": "repoDeleteWiki", + "parameters": [ + { + "type": "string", + "description": "owner of the repo", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repo", + "name": "repo", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the wiki", + "name": "pagename", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "$ref": "#/responses/empty" + }, + "500": { + "$ref": "#/responses/noFound" + } + } + }, "patch": { "produces": [ "application/json"