improved API documentation + error handling

This commit is contained in:
Bernhard B
2020-10-05 18:32:59 +02:00
parent 023d10f648
commit 9ffc03e8f3
4 changed files with 25 additions and 3 deletions

View File

@@ -609,6 +609,7 @@ func (a *Api) DeleteGroup(c *gin.Context) {
// @Description test // @Description test
// @Produce json // @Produce json
// @Success 200 {string} string "Image" // @Success 200 {string} string "Image"
// @Failure 400 {object} Error
// @Router /v1/qrcodelink [get] // @Router /v1/qrcodelink [get]
func (a *Api) GetQrCodeLink(c *gin.Context) { func (a *Api) GetQrCodeLink(c *gin.Context) {
deviceName := c.Query("device_name") deviceName := c.Query("device_name")
@@ -622,20 +623,25 @@ func (a *Api) GetQrCodeLink(c *gin.Context) {
tsdeviceLink, err := runSignalCli(false, command) tsdeviceLink, err := runSignalCli(false, command)
if err != nil { if err != nil {
c.JSON(400, gin.H{"error": err.Error()}) log.Error("Couldn't create QR code: ", err.Error())
c.JSON(400, Error{Msg: "Couldn't create QR code: " + err.Error()})
return return
} }
q, err := qrcode.New(string(tsdeviceLink), qrcode.Medium) q, err := qrcode.New(string(tsdeviceLink), qrcode.Medium)
if err != nil { if err != nil {
c.JSON(400, gin.H{"error": err.Error()}) log.Error("Couldn't create QR code: ", err.Error())
c.JSON(400, Error{Msg: "Couldn't create QR code: " + err.Error()})
return
} }
q.DisableBorder = false q.DisableBorder = false
var png []byte var png []byte
png, err = q.PNG(256) png, err = q.PNG(256)
if err != nil { if err != nil {
c.JSON(400, gin.H{"error": err.Error()}) log.Error("Couldn't create QR code: ", err.Error())
c.JSON(400, Error{Msg: "Couldn't create QR code: " + err.Error()})
return
} }
c.Data(200, "image/png", png) c.Data(200, "image/png", png)

View File

@@ -183,6 +183,12 @@ var doc = `{
"schema": { "schema": {
"type": "string" "type": "string"
} }
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/api.Error"
}
} }
} }
} }

View File

@@ -168,6 +168,12 @@
"schema": { "schema": {
"type": "string" "type": "string"
} }
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/api.Error"
}
} }
} }
} }

View File

@@ -183,6 +183,10 @@ paths:
description: Image description: Image
schema: schema:
type: string type: string
"400":
description: Bad Request
schema:
$ref: '#/definitions/api.Error'
summary: Link device and generate QR code. summary: Link device and generate QR code.
tags: tags:
- Devices - Devices