add swagger documentation

This commit is contained in:
2019-12-04 19:06:35 +01:00
parent 93bb34ad76
commit f2702297ba
3 changed files with 128 additions and 11 deletions

73
controller/issue.go Normal file
View File

@ -0,0 +1,73 @@
package controller
import (
"code.gitea.io/sdk/gitea"
"gitea-issue/giteaClient"
"github.com/gin-gonic/gin"
"github.com/savaki/swag/endpoint"
"github.com/savaki/swag/swagger"
"net/http"
"strconv"
"fmt"
)
func GetIssues(c *gin.Context) {
issues, err := giteaClient.GetIssues();
if(err != nil){
c.AbortWithStatus(http.StatusNotFound)
}
c.AsciiJSON(http.StatusOK, issues)
}
func GetIssuesSwagger() (*swagger.Endpoint){
return endpoint.New("get", "/issues", "List project issues",
endpoint.Handler(GetIssues),
endpoint.Description("Get all issues"),
endpoint.Tags("issues"),
endpoint.Response(http.StatusOK, []gitea.Issue{}, "Gitea Issue list"),
)
}
func GetIssue(c *gin.Context) {
issueId, err := strconv.ParseInt(c.Param("id"), 10, 64)
if err != nil {
fmt.Println(fmt.Sprintf("ParseInt err: %+v", err))
c.AsciiJSON(http.StatusNotFound, err.Error())
}
issue, err := giteaClient.GetIssue(issueId)
if err != nil {
c.AbortWithStatus(http.StatusNotFound)
}
c.AsciiJSON(http.StatusOK, issue)
}
func GetIssueSwagger() (*swagger.Endpoint){
return endpoint.New("get", "/issue/:id", "Get one issue",
endpoint.Handler(GetIssue),
endpoint.Description("Get one issue"),
endpoint.Tags("issues"),
endpoint.Response(http.StatusOK, gitea.Issue{}, "Gitea Issue"),
)
}
func GetIssueComments(c *gin.Context) {
issueId, err := strconv.ParseInt(c.Param("id"), 10, 64)
if err != nil {
fmt.Println(fmt.Sprintf("ParseInt err: %+v", err))
c.AsciiJSON(http.StatusNotFound, err.Error())
}
issueComments, err := giteaClient.GetIssueComments(issueId)
if err != nil {
c.AbortWithStatus(http.StatusNotFound)
}
c.AsciiJSON(http.StatusOK, issueComments)
}
func GetIssueCommentsSwagger() (*swagger.Endpoint){
return endpoint.New("get", "/issue/:id/comments", "Get issue comments",
endpoint.Handler(GetIssue),
endpoint.Description("Get issue comments"),
endpoint.Tags("issues"),
endpoint.Response(http.StatusOK, []gitea.Comment{}, "Gitea issue comments"),
)
}

27
controller/label.go Normal file
View File

@ -0,0 +1,27 @@
package controller
import (
"code.gitea.io/sdk/gitea"
"gitea-issue/giteaClient"
"github.com/gin-gonic/gin"
"github.com/savaki/swag/endpoint"
"github.com/savaki/swag/swagger"
"net/http"
)
func GetLabels(c *gin.Context) {
labels, err := giteaClient.GetLabels()
if err != nil {
c.AbortWithStatus(http.StatusNotFound)
}
c.AsciiJSON(http.StatusOK, labels)
}
func GetLabelsSwagger() (*swagger.Endpoint){
return endpoint.New("get", "/labels", "List project labels",
endpoint.Handler(GetLabels),
endpoint.Description("Get all labels"),
endpoint.Tags("labels"),
endpoint.Response(http.StatusOK, []gitea.Label{}, "Gitea labels list"),
)
}