mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
add new openapi endpoint
This commit is contained in:
parent
59c924bcff
commit
f49b997f29
2 changed files with 52 additions and 2 deletions
50
routes/openapi/openapi.go
Normal file
50
routes/openapi/openapi.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
/** Healthz package, endpoints.
|
||||
*
|
||||
* @author Sonja Happ <sonja.happ@eonerc.rwth-aachen.de>
|
||||
* @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC
|
||||
* @license GNU General Public License (version 3)
|
||||
*
|
||||
* VILLASweb-backend-go
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*********************************************************************************/
|
||||
package openapi
|
||||
|
||||
import (
|
||||
_ "git.rwth-aachen.de/acs/public/villas/web-backend-go/doc/api" // doc/api folder is used by Swag CLI, you have to import it
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/swaggo/swag"
|
||||
)
|
||||
|
||||
func RegisterOpenAPIEndpoint(r *gin.RouterGroup) {
|
||||
r.GET("", getOpenAPI)
|
||||
}
|
||||
|
||||
// getOpenAPI godoc
|
||||
// @Summary Get OpenAPI 2.0 spec of API
|
||||
// @ID getOpenAPI
|
||||
// @Produce json
|
||||
// @Tags openapi
|
||||
// @Success 200 string string "A OpenAPI 2.0 specification of the API"
|
||||
// @Router /openapi [get]
|
||||
func getOpenAPI(c *gin.Context) {
|
||||
doc, err := swag.ReadDoc()
|
||||
if err != nil {
|
||||
helper.InternalServerError(c, err.Error())
|
||||
}
|
||||
|
||||
c.Header("Content-Type", "application/json")
|
||||
c.String(200, doc)
|
||||
}
|
|
@ -42,14 +42,13 @@ import (
|
|||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/healthz"
|
||||
infrastructure_component "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/metrics"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/openapi"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/result"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/signal"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
|
||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/widget"
|
||||
"github.com/gin-gonic/gin"
|
||||
ginSwagger "github.com/swaggo/gin-swagger"
|
||||
"github.com/swaggo/gin-swagger/swaggerFiles"
|
||||
"github.com/zpatrick/go-config"
|
||||
)
|
||||
|
||||
|
@ -80,6 +79,7 @@ func RegisterEndpoints(router *gin.Engine, api *gin.RouterGroup) {
|
|||
|
||||
healthz.RegisterHealthzEndpoint(api.Group("/healthz"))
|
||||
metrics.RegisterMetricsEndpoint(api.Group("/metrics"))
|
||||
openapi.RegisterOpenAPIEndpoint(api.Group("/openapi"))
|
||||
// All endpoints (except for /healthz and /metrics) require authentication except when someone wants to
|
||||
// login (POST /authenticate)
|
||||
user.RegisterAuthenticate(api.Group("/authenticate"))
|
||||
|
|
Loading…
Add table
Reference in a new issue