mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
generate and deploy api docs based on swag tool
This commit is contained in:
parent
b6c2d9fc6a
commit
ea974ba32b
4 changed files with 15 additions and 13 deletions
|
@ -38,8 +38,10 @@ build:doc:api:
|
||||||
- docker
|
- docker
|
||||||
image: redoc
|
image: redoc
|
||||||
script:
|
script:
|
||||||
|
- go get -u github.com/swaggo/swag/cmd/swag
|
||||||
|
- ~/go/bin/swag init -p pascalcase -g "start.go" -o "./doc/api/"
|
||||||
- cd doc/api
|
- cd doc/api
|
||||||
- redoc-cli bundle --cdn --title "VILLASweb Backend API Documentation" --output index.html api.yaml
|
- redoc-cli bundle --cdn --title "VILLASweb Backend API Documentation" --output index.html swagger.json
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- doc/api/index.html
|
- doc/api/index.html
|
||||||
|
@ -52,7 +54,7 @@ build:backend:
|
||||||
script:
|
script:
|
||||||
- go mod tidy
|
- go mod tidy
|
||||||
- go get -u github.com/swaggo/swag/cmd/swag
|
- go get -u github.com/swaggo/swag/cmd/swag
|
||||||
- ~/go/bin/swag init -p pascalcase -g "start.go" -o "./doc/autoapi/"
|
- ~/go/bin/swag init -p pascalcase -g "start.go" -o "./doc/api/"
|
||||||
- go build
|
- go build
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,7 +70,7 @@ test:backend:database:
|
||||||
- /etc/init.d/postgresql start
|
- /etc/init.d/postgresql start
|
||||||
- go mod tidy
|
- go mod tidy
|
||||||
- go get -u github.com/swaggo/swag/cmd/swag
|
- go get -u github.com/swaggo/swag/cmd/swag
|
||||||
- ~/go/bin/swag init -p pascalcase -g "start.go" -o "./doc/autoapi/"
|
- ~/go/bin/swag init -p pascalcase -g "start.go" -o "./doc/api/"
|
||||||
- cd common
|
- cd common
|
||||||
- go test -v -args -dbhost=/var/run/postgresql
|
- go test -v -args -dbhost=/var/run/postgresql
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@ -83,7 +85,7 @@ test:backend:endpoints:
|
||||||
- /etc/init.d/postgresql start
|
- /etc/init.d/postgresql start
|
||||||
- go mod tidy
|
- go mod tidy
|
||||||
- go get -u github.com/swaggo/swag/cmd/swag
|
- go get -u github.com/swaggo/swag/cmd/swag
|
||||||
- ~/go/bin/swag init -p pascalcase -g "start.go" -o "./doc/autoapi/"
|
- ~/go/bin/swag init -p pascalcase -g "start.go" -o "./doc/api/"
|
||||||
- cd routes/simulation
|
- cd routes/simulation
|
||||||
- go test -v -args -dbhost=/var/run/postgresql
|
- go test -v -args -dbhost=/var/run/postgresql
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@ -96,7 +98,7 @@ deploy:upload:
|
||||||
stage: deploy
|
stage: deploy
|
||||||
script:
|
script:
|
||||||
- cd doc/api
|
- cd doc/api
|
||||||
- rsync --copy-links --chown ${DEPLOY_USER}:${DEPLOY_USER} index.html api.yaml ${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}
|
- rsync --copy-links --chown ${DEPLOY_USER}:${DEPLOY_USER} index.html swagger.json ${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_PATH}
|
||||||
dependencies:
|
dependencies:
|
||||||
- build:doc:api
|
- build:doc:api
|
||||||
only:
|
only:
|
||||||
|
|
|
@ -8,11 +8,11 @@ RSYNC_OPTS ?= --recursive --ignore-missing-args --copy-links --chown $(DEPLOY_US
|
||||||
|
|
||||||
all: index.html
|
all: index.html
|
||||||
|
|
||||||
index.html: api.yaml
|
index.html: swagger.json
|
||||||
redoc-cli bundle --cdn --title $(TITLE) --output $@ api.yaml
|
redoc-cli bundle --cdn --title $(TITLE) --output $@ swagger.json
|
||||||
|
|
||||||
deploy: index.html
|
deploy: index.html
|
||||||
rsync $(RSYNC_OPTS) index.html api.yaml $(DEPLOY_USER)@$(DEPLOY_HOST):$(DEPLOY_PATH)
|
rsync $(RSYNC_OPTS) index.html swagger.json $(DEPLOY_USER)@$(DEPLOY_HOST):$(DEPLOY_PATH)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf index.html
|
rm -rf index.html
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
cd ../../
|
cd ../../
|
||||||
go mod tidy
|
go mod tidy
|
||||||
swag init -p pascalcase -g "start.go" -o "./doc/autoapi/"
|
swag init -p pascalcase -g "start.go" -o "./doc/api/"
|
||||||
cd -
|
cd -
|
||||||
|
|
||||||
redoc-cli bundle --cdn --title "VILLASweb Backend API" --output index.html swagger.yaml
|
redoc-cli bundle --cdn --title "VILLASweb Backend API" --output index.html swagger.json
|
6
start.go
6
start.go
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/swaggo/gin-swagger/swaggerFiles"
|
"github.com/swaggo/gin-swagger/swaggerFiles"
|
||||||
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
||||||
_ "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/doc/autoapi" // apidocs folder is generated by Swag CLI, you have to import it
|
_ "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/doc/api" // doc/api folder is used by Swag CLI, you have to import it
|
||||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulation"
|
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulation"
|
||||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulationmodel"
|
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulationmodel"
|
||||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulator"
|
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulator"
|
||||||
|
@ -31,7 +31,7 @@ import (
|
||||||
// @license.url http://www.gnu.de/documents/gpl-3.0.en.html
|
// @license.url http://www.gnu.de/documents/gpl-3.0.en.html
|
||||||
|
|
||||||
// @host localhost:4000
|
// @host localhost:4000
|
||||||
// @BasePath /api/v1
|
// @BasePath /api/v2
|
||||||
func main() {
|
func main() {
|
||||||
// Testing
|
// Testing
|
||||||
db := common.DummyInitDB()
|
db := common.DummyInitDB()
|
||||||
|
@ -42,7 +42,7 @@ func main() {
|
||||||
|
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
|
|
||||||
api := r.Group("/api/v1")
|
api := r.Group("/api/v2")
|
||||||
|
|
||||||
// All endpoints require authentication except when someone wants to
|
// All endpoints require authentication except when someone wants to
|
||||||
// login (POST /authenticate)
|
// login (POST /authenticate)
|
||||||
|
|
Loading…
Add table
Reference in a new issue