diff --git a/bridge/api/api.go b/bridge/api/api.go index f8a7c04c..7dcc1b03 100644 --- a/bridge/api/api.go +++ b/bridge/api/api.go @@ -11,8 +11,20 @@ import ( "github.com/labstack/echo" "github.com/labstack/echo/middleware" "github.com/zfjagann/golang-ring" + "github.com/swaggo/echo-swagger" + _ "github.com/42wim/matterbridge/docs" ) +// @title Matterbridge API +// @version TODO +// @description A read/write API for the Matterbridge chat bridge. + +// @license.name Apache 2.0 +// @license.url https://github.com/42wim/matterbridge/blob/master/LICENSE + +// @host TODO +// @basePath /api + type API struct { Messages ring.Ring sync.RWMutex @@ -41,6 +53,10 @@ func New(cfg *bridge.Config) bridge.Bridger { return key == b.GetString("Token"), nil })) } + e.GET("/swagger/*", echoSwagger.WrapHandler) + e.GET("/swagger", b.handleDocsRedirect) + e.GET("/", b.handleDocsRedirect) + e.GET("/api", b.handleDocsRedirect) e.GET("/api/health", b.handleHealthcheck) e.GET("/api/messages", b.handleMessages) e.GET("/api/stream", b.handleStream) @@ -82,6 +98,10 @@ func (b *API) handleHealthcheck(c echo.Context) error { return c.String(http.StatusOK, "OK") } +func (b *Api) handleDocsRedirect(c echo.Context) error { + return c.Redirect(http.StatusMovedPermanently, "/swagger/index.html") +} + func (b *API) handlePostMessage(c echo.Context) error { message := config.Message{} if err := c.Bind(&message); err != nil { diff --git a/docs/docs.go b/docs/docs.go new file mode 100644 index 00000000..a44bfe53 --- /dev/null +++ b/docs/docs.go @@ -0,0 +1,35 @@ +// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT +// This file was generated by swaggo/swag at +// 2018-11-04 21:12:10.529569 +0800 CST m=+0.079119212 + +package docs + +import ( + "github.com/swaggo/swag" +) + +var doc = `{ + "swagger": "2.0", + "info": { + "description": "A read/write API for the Matterbridge chat bridge.", + "title": "Matterbridge API", + "contact": {}, + "license": { + "name": "Apache 2.0", + "url": "https://github.com/42wim/matterbridge/blob/master/LICENSE" + }, + "version": "TODO" + }, + "host": "TODO", + "basePath": "/api", + "paths": {} +}` + +type s struct{} + +func (s *s) ReadDoc() string { + return doc +} +func init() { + swag.Register(swag.Name, &s{}) +} diff --git a/docs/swagger/swagger.json b/docs/swagger/swagger.json new file mode 100644 index 00000000..56c0bf6b --- /dev/null +++ b/docs/swagger/swagger.json @@ -0,0 +1,16 @@ +{ + "swagger": "2.0", + "info": { + "description": "A read/write API for the Matterbridge chat bridge.", + "title": "Matterbridge API", + "contact": {}, + "license": { + "name": "Apache 2.0", + "url": "https://github.com/42wim/matterbridge/blob/master/LICENSE" + }, + "version": "TODO" + }, + "host": "TODO", + "basePath": "/api", + "paths": {} +} \ No newline at end of file diff --git a/docs/swagger/swagger.yaml b/docs/swagger/swagger.yaml new file mode 100644 index 00000000..cbe8736d --- /dev/null +++ b/docs/swagger/swagger.yaml @@ -0,0 +1,12 @@ +basePath: /api +host: TODO +info: + contact: {} + description: A read/write API for the Matterbridge chat bridge. + license: + name: Apache 2.0 + url: https://github.com/42wim/matterbridge/blob/master/LICENSE + title: Matterbridge API + version: TODO +paths: {} +swagger: "2.0"