-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add swagger ui Signed-off-by: Patricia Reinoso <[email protected]> * fix format Signed-off-by: Patricia Reinoso <[email protected]> * add license and fix format Signed-off-by: Patricia Reinoso <[email protected]> * restore go.sum and go.mod Signed-off-by: Patricia Reinoso <[email protected]> * add swag dependencies Signed-off-by: Patricia Reinoso <[email protected]> * fix lint Signed-off-by: Patricia Reinoso <[email protected]> * use build tag for conditional build Signed-off-by: Patricia Reinoso <[email protected]> * use remote ip for swagger Signed-off-by: Patricia Reinoso <[email protected]> * fix format Signed-off-by: Patricia Reinoso <[email protected]> * keep function name and comment aligned Signed-off-by: Patricia Reinoso <[email protected]> --------- Signed-off-by: Patricia Reinoso <[email protected]> Co-authored-by: Ajay Lotan Thakur <[email protected]> Co-authored-by: gab-arrobo <[email protected]>
- Loading branch information
1 parent
b2199e1
commit ec9874f
Showing
11 changed files
with
916 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!-- | ||
SPDX-License-Identifier: Apache-2.0 | ||
Copyright 2024 Canonical Ltd. | ||
--> | ||
|
||
# Swagger UI Service | ||
|
||
The webconsole can optionally serve a [swagger UI](https://github.com/swaggo/swag). | ||
The API documentation is automatically generated from code annotations. | ||
|
||
To generate the swagger UI files run: | ||
``` | ||
swag init -g backend/webui_service/swagger_ui_service.go --outputTypes go | ||
``` | ||
The `docs.go` file will automatically be created in `webconsole/docs` | ||
|
||
The swagger UI operations are executed by default on `localhost`. If the webconsole server runs remotely, set the following environment variable. | ||
``` | ||
export WEBUI_ENDPOINT=<webconsole-ip>:5000 | ||
``` | ||
Build the webconsole including the UI option: | ||
``` | ||
make webconsole-ui | ||
``` | ||
Access the swagger UI at: | ||
``` | ||
http://<webconsole-ip>:5000/swagger/index.html | ||
``` | ||
The `doc.json` file, which can be integrated in a frontend implementation, is available at: | ||
``` | ||
http://<webconsole-ip>:5000/swagger/doc.json | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2024 Canonical Ltd | ||
|
||
//go:build !ui | ||
|
||
package webui_service | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"github.com/omec-project/webconsole/backend/logger" | ||
) | ||
|
||
func AddSwaggerUiService(engine *gin.Engine) { | ||
logger.WebUILog.Infoln("Swagger UI service will not be added") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2024 Canonical Ltd. | ||
|
||
// +build ui | ||
|
||
package webui_service | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/omec-project/webconsole/backend/logger" | ||
"github.com/omec-project/webconsole/docs" | ||
swaggerFiles "github.com/swaggo/files" | ||
ginSwagger "github.com/swaggo/gin-swagger" | ||
) | ||
|
||
// @title Webconsole API Documentation | ||
// @version 1.0 | ||
|
||
// @contact.name OMEC Project - Webconsole | ||
// @contact.url https://github.com/omec-project/webconsole | ||
|
||
// @license.name Apache 2.0 | ||
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html | ||
|
||
// @host localhost:5000 | ||
// @BasePath / | ||
func AddSwaggerUiService(engine *gin.Engine) { | ||
logger.WebUILog.Infoln("Adding Swagger UI service") | ||
endpoint := os.Getenv("WEBUI_ENDPOINT") | ||
if endpoint != "" { | ||
docs.SwaggerInfo.Host = endpoint | ||
} | ||
engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.