Added swagger docs
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
kolaente 2019-10-14 00:05:33 +02:00
parent 4855e172d7
commit d685edd67a
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
5 changed files with 782 additions and 30 deletions

View File

@ -93,6 +93,18 @@ func (ta *TaskAttachment) ReadOne() (err error) {
}
// ReadAll returns a list with all attachments
// @Summary Get all attachments for one task.
// @Description Get all task attachments for one task.
// @tags task
// @Accept json
// @Produce json
// @Param id path int true "Task ID"
// @Security JWTKeyAuth
// @Success 200 {object} models.Message "All attachments for this task"
// @Failure 403 {object} models.Message "No access to this task."
// @Failure 404 {object} models.Message "The task does not exist."
// @Failure 500 {object} models.Message "Internal error"
// @Router /tasks/{id}/attachments [get]
func (ta *TaskAttachment) ReadAll(s string, a web.Auth, page int) (interface{}, error) {
attachments := []*TaskAttachment{}
@ -137,6 +149,19 @@ func (ta *TaskAttachment) ReadAll(s string, a web.Auth, page int) (interface{},
}
// Delete removes an attachment
// @Summary Delete an attachment
// @Description Delete an attachment.
// @tags task
// @Accept json
// @Produce json
// @Param id path int true "Task ID"
// @Param attachmentID path int true "Attachment ID"
// @Security JWTKeyAuth
// @Success 200 {object} models.Message "The attachment was deleted successfully."
// @Failure 403 {object} models.Message "No access to this task."
// @Failure 404 {object} models.Message "The task does not exist."
// @Failure 500 {object} models.Message "Internal error"
// @Router /tasks/{id}/attachments/{attachmentID} [delete]
func (ta *TaskAttachment) Delete() error {
// Load the attachment
err := ta.ReadOne()

View File

@ -24,6 +24,19 @@ import (
)
// UploadTaskAttachment handles everything needed for the upload of a task attachment
// @Summary Upload a task attachment
// @Description Upload a task attachment. You can pass multiple files with the files form param.
// @tags task
// @Accept json
// @Produce json
// @Param id path int true "Task ID"
// @Param files body file true "The file, as multipart form file. You can pass multiple."
// @Security JWTKeyAuth
// @Success 200 {object} models.Message "Attachments were uploaded successfully."
// @Failure 403 {object} models.Message "No access to the task."
// @Failure 404 {object} models.Message "The task does not exist."
// @Failure 500 {object} models.Message "Internal error"
// @Router /tasks/{id}/attachments [put]
func UploadTaskAttachment(c echo.Context) error {
var taskAttachment models.TaskAttachment
@ -50,30 +63,49 @@ func UploadTaskAttachment(c echo.Context) error {
return handler.HandleHTTPError(err, c)
}
// TODO: document that parameter
type result struct {
Errors []*echo.HTTPError `json:"errors"`
Success []*models.TaskAttachment `json:"success"`
}
r := &result{}
fileHeaders := form.File["files"]
for _, file := range fileHeaders {
// We create a new attachment object here to have a clean start
ta := models.TaskAttachment{
ta := &models.TaskAttachment{
TaskID: taskAttachment.TaskID,
}
f, err := file.Open()
if err != nil {
return handler.HandleHTTPError(err, c)
r.Errors = append(r.Errors, handler.HandleHTTPError(err, c))
continue
}
defer f.Close()
err = ta.NewAttachment(f, file.Filename, file.Size, user)
if err != nil {
return handler.HandleHTTPError(err, c)
r.Errors = append(r.Errors, handler.HandleHTTPError(err, c))
continue
}
r.Success = append(r.Success, ta)
}
return c.NoContent(http.StatusNoContent)
return c.JSON(http.StatusOK, r)
}
// GetTaskAttachment returns a task attachment to download for the user
// @Summary Get one attachment.
// @tags task
// @Accept json
// @Produce json
// @Param id path int true "Task ID"
// @Param attachmentID path int true "Attachment ID"
// @Security JWTKeyAuth
// @Success 200 {array} models.Message "All attachments for this task"
// @Failure 403 {object} models.Message "No access to this task."
// @Failure 404 {object} models.Message "The task does not exist."
// @Failure 500 {object} models.Message "Internal error"
// @Router /tasks/{id}/attachments/{attachmentID} [get]
func GetTaskAttachment(c echo.Context) error {
var taskAttachment models.TaskAttachment

View File

@ -1,6 +1,6 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2019-09-25 20:06:34.002904022 +0200 CEST m=+0.196783505
// 2019-10-14 00:04:43.830530598 +0200 CEST m=+0.114462027
package swagger
@ -412,7 +412,7 @@ var doc = `{
"JWTKeyAuth": []
}
],
"description": "Returns a list by its ID.",
"description": "Returns a team by its ID.",
"consumes": [
"application/json"
],
@ -420,13 +420,13 @@ var doc = `{
"application/json"
],
"tags": [
"list"
"team"
],
"summary": "Gets one list",
"summary": "Gets one team",
"parameters": [
{
"type": "integer",
"description": "List ID",
"description": "Team ID",
"name": "id",
"in": "path",
"required": true
@ -434,14 +434,14 @@ var doc = `{
],
"responses": {
"200": {
"description": "The list",
"description": "The team",
"schema": {
"type": "object",
"$ref": "#/definitions/models.List"
"$ref": "#/definitions/models.Team"
}
},
"403": {
"description": "The user does not have access to the list",
"description": "The user does not have access to the team",
"schema": {
"type": "object",
"$ref": "#/definitions/code.vikunja.io.web.HTTPError"
@ -2902,6 +2902,263 @@ var doc = `{
}
}
},
"/tasks/{id}/attachments": {
"get": {
"security": [
{
"JWTKeyAuth": []
}
],
"description": "Get all task attachments for one task.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"task"
],
"summary": "Get all attachments for one task.",
"parameters": [
{
"type": "integer",
"description": "Task ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "All attachments for this task",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"403": {
"description": "No access to this task.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"404": {
"description": "The task does not exist.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"500": {
"description": "Internal error",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
}
}
},
"put": {
"security": [
{
"JWTKeyAuth": []
}
],
"description": "Upload a task attachment. You can pass multiple files with the files form param.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"task"
],
"summary": "Upload a task attachment",
"parameters": [
{
"type": "integer",
"description": "Task ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "The file, as multipart form file. You can pass multiple.",
"name": "files",
"in": "body",
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/file"
}
}
],
"responses": {
"200": {
"description": "Attachments were uploaded successfully.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"403": {
"description": "No access to the task.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"404": {
"description": "The task does not exist.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"500": {
"description": "Internal error",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
}
}
}
},
"/tasks/{id}/attachments/{attachmentID}": {
"get": {
"security": [
{
"JWTKeyAuth": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"task"
],
"summary": "Get one attachment.",
"parameters": [
{
"type": "integer",
"description": "Task ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "Attachment ID",
"name": "attachmentID",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "All attachments for this task",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Message"
}
}
},
"403": {
"description": "No access to this task.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"404": {
"description": "The task does not exist.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"500": {
"description": "Internal error",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
}
}
},
"delete": {
"security": [
{
"JWTKeyAuth": []
}
],
"description": "Delete an attachment.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"task"
],
"summary": "Delete an attachment",
"parameters": [
{
"type": "integer",
"description": "Task ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "Attachment ID",
"name": "attachmentID",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "The attachment was deleted successfully.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"403": {
"description": "No access to this task.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"404": {
"description": "The task does not exist.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"500": {
"description": "Internal error",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
}
}
}
},
"/tasks/{taskID}/assignees": {
"get": {
"security": [
@ -3211,7 +3468,7 @@ var doc = `{
"JWTKeyAuth": []
}
],
"description": "Creates a new relation between two tasks. The user needs to have update rights on the base task and at least read rights on the other task. Both tasks do not need to be on the same list.",
"description": "Creates a new relation between two tasks. The user needs to have update rights on the base task and at least read rights on the other task. Both tasks do not need to be on the same list. Take a look at the docs for available task relation kinds.",
"consumes": [
"application/json"
],
@ -5162,6 +5419,9 @@ var doc = `{
"link_sharing_enabled": {
"type": "boolean"
},
"max_file_size": {
"type": "integer"
},
"motd": {
"type": "string"
},

View File

@ -399,7 +399,7 @@
"JWTKeyAuth": []
}
],
"description": "Returns a list by its ID.",
"description": "Returns a team by its ID.",
"consumes": [
"application/json"
],
@ -407,13 +407,13 @@
"application/json"
],
"tags": [
"list"
"team"
],
"summary": "Gets one list",
"summary": "Gets one team",
"parameters": [
{
"type": "integer",
"description": "List ID",
"description": "Team ID",
"name": "id",
"in": "path",
"required": true
@ -421,14 +421,14 @@
],
"responses": {
"200": {
"description": "The list",
"description": "The team",
"schema": {
"type": "object",
"$ref": "#/definitions/models.List"
"$ref": "#/definitions/models.Team"
}
},
"403": {
"description": "The user does not have access to the list",
"description": "The user does not have access to the team",
"schema": {
"type": "object",
"$ref": "#/definitions/code.vikunja.io/web.HTTPError"
@ -2889,6 +2889,263 @@
}
}
},
"/tasks/{id}/attachments": {
"get": {
"security": [
{
"JWTKeyAuth": []
}
],
"description": "Get all task attachments for one task.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"task"
],
"summary": "Get all attachments for one task.",
"parameters": [
{
"type": "integer",
"description": "Task ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "All attachments for this task",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"403": {
"description": "No access to this task.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"404": {
"description": "The task does not exist.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"500": {
"description": "Internal error",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
}
}
},
"put": {
"security": [
{
"JWTKeyAuth": []
}
],
"description": "Upload a task attachment. You can pass multiple files with the files form param.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"task"
],
"summary": "Upload a task attachment",
"parameters": [
{
"type": "integer",
"description": "Task ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "The file, as multipart form file. You can pass multiple.",
"name": "files",
"in": "body",
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/file"
}
}
],
"responses": {
"200": {
"description": "Attachments were uploaded successfully.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"403": {
"description": "No access to the task.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"404": {
"description": "The task does not exist.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"500": {
"description": "Internal error",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
}
}
}
},
"/tasks/{id}/attachments/{attachmentID}": {
"get": {
"security": [
{
"JWTKeyAuth": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"task"
],
"summary": "Get one attachment.",
"parameters": [
{
"type": "integer",
"description": "Task ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "Attachment ID",
"name": "attachmentID",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "All attachments for this task",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Message"
}
}
},
"403": {
"description": "No access to this task.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"404": {
"description": "The task does not exist.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"500": {
"description": "Internal error",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
}
}
},
"delete": {
"security": [
{
"JWTKeyAuth": []
}
],
"description": "Delete an attachment.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"task"
],
"summary": "Delete an attachment",
"parameters": [
{
"type": "integer",
"description": "Task ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "Attachment ID",
"name": "attachmentID",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "The attachment was deleted successfully.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"403": {
"description": "No access to this task.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"404": {
"description": "The task does not exist.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"500": {
"description": "Internal error",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
}
}
}
},
"/tasks/{taskID}/assignees": {
"get": {
"security": [
@ -3198,7 +3455,7 @@
"JWTKeyAuth": []
}
],
"description": "Creates a new relation between two tasks. The user needs to have update rights on the base task and at least read rights on the other task. Both tasks do not need to be on the same list.",
"description": "Creates a new relation between two tasks. The user needs to have update rights on the base task and at least read rights on the other task. Both tasks do not need to be on the same list. Take a look at the docs for available task relation kinds.",
"consumes": [
"application/json"
],
@ -5148,6 +5405,9 @@
"link_sharing_enabled": {
"type": "boolean"
},
"max_file_size": {
"type": "integer"
},
"motd": {
"type": "string"
},

View File

@ -789,6 +789,8 @@ definitions:
type: string
link_sharing_enabled:
type: boolean
max_file_size:
type: integer
motd:
type: string
version:
@ -1106,9 +1108,9 @@ paths:
get:
consumes:
- application/json
description: Returns a list by its ID.
description: Returns a team by its ID.
parameters:
- description: List ID
- description: Team ID
in: path
name: id
required: true
@ -1117,12 +1119,12 @@ paths:
- application/json
responses:
"200":
description: The list
description: The team
schema:
$ref: '#/definitions/models.List'
$ref: '#/definitions/models.Team'
type: object
"403":
description: The user does not have access to the list
description: The user does not have access to the team
schema:
$ref: '#/definitions/code.vikunja.io/web.HTTPError'
type: object
@ -1133,9 +1135,9 @@ paths:
type: object
security:
- JWTKeyAuth: []
summary: Gets one list
summary: Gets one team
tags:
- list
- team
post:
consumes:
- application/json
@ -2665,6 +2667,178 @@ paths:
summary: Update a task
tags:
- task
/tasks/{id}/attachments:
get:
consumes:
- application/json
description: Get all task attachments for one task.
parameters:
- description: Task ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: All attachments for this task
schema:
$ref: '#/definitions/models.Message'
type: object
"403":
description: No access to this task.
schema:
$ref: '#/definitions/models.Message'
type: object
"404":
description: The task does not exist.
schema:
$ref: '#/definitions/models.Message'
type: object
"500":
description: Internal error
schema:
$ref: '#/definitions/models.Message'
type: object
security:
- JWTKeyAuth: []
summary: Get all attachments for one task.
tags:
- task
put:
consumes:
- application/json
description: Upload a task attachment. You can pass multiple files with the
files form param.
parameters:
- description: Task ID
in: path
name: id
required: true
type: integer
- description: The file, as multipart form file. You can pass multiple.
in: body
name: files
required: true
schema:
$ref: '#/definitions/file'
type: object
produces:
- application/json
responses:
"200":
description: Attachments were uploaded successfully.
schema:
$ref: '#/definitions/models.Message'
type: object
"403":
description: No access to the task.
schema:
$ref: '#/definitions/models.Message'
type: object
"404":
description: The task does not exist.
schema:
$ref: '#/definitions/models.Message'
type: object
"500":
description: Internal error
schema:
$ref: '#/definitions/models.Message'
type: object
security:
- JWTKeyAuth: []
summary: Upload a task attachment
tags:
- task
/tasks/{id}/attachments/{attachmentID}:
delete:
consumes:
- application/json
description: Delete an attachment.
parameters:
- description: Task ID
in: path
name: id
required: true
type: integer
- description: Attachment ID
in: path
name: attachmentID
required: true
type: integer
produces:
- application/json
responses:
"200":
description: The attachment was deleted successfully.
schema:
$ref: '#/definitions/models.Message'
type: object
"403":
description: No access to this task.
schema:
$ref: '#/definitions/models.Message'
type: object
"404":
description: The task does not exist.
schema:
$ref: '#/definitions/models.Message'
type: object
"500":
description: Internal error
schema:
$ref: '#/definitions/models.Message'
type: object
security:
- JWTKeyAuth: []
summary: Delete an attachment
tags:
- task
get:
consumes:
- application/json
parameters:
- description: Task ID
in: path
name: id
required: true
type: integer
- description: Attachment ID
in: path
name: attachmentID
required: true
type: integer
produces:
- application/json
responses:
"200":
description: All attachments for this task
schema:
items:
$ref: '#/definitions/models.Message'
type: array
"403":
description: No access to this task.
schema:
$ref: '#/definitions/models.Message'
type: object
"404":
description: The task does not exist.
schema:
$ref: '#/definitions/models.Message'
type: object
"500":
description: Internal error
schema:
$ref: '#/definitions/models.Message'
type: object
security:
- JWTKeyAuth: []
summary: Get one attachment.
tags:
- task
/tasks/{task}/labels:
get:
consumes:
@ -3057,7 +3231,8 @@ paths:
- application/json
description: Creates a new relation between two tasks. The user needs to have
update rights on the base task and at least read rights on the other task.
Both tasks do not need to be on the same list.
Both tasks do not need to be on the same list. Take a look at the docs for
available task relation kinds.
parameters:
- description: The relation object
in: body