generate and deploy api docs based on swag tool

This commit is contained in:
Sonja Happ 2019-06-06 09:57:40 +02:00
parent b6c2d9fc6a
commit ea974ba32b
4 changed files with 15 additions and 13 deletions

View file

@ -38,8 +38,10 @@ build:doc:api:
- docker
image: redoc
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
- 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:
paths:
- doc/api/index.html
@ -52,7 +54,7 @@ build:backend:
script:
- go mod tidy
- 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
@ -68,7 +70,7 @@ test:backend:database:
- /etc/init.d/postgresql start
- go mod tidy
- 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
- go test -v -args -dbhost=/var/run/postgresql
dependencies:
@ -83,7 +85,7 @@ test:backend:endpoints:
- /etc/init.d/postgresql start
- go mod tidy
- 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
- go test -v -args -dbhost=/var/run/postgresql
dependencies:
@ -96,7 +98,7 @@ deploy:upload:
stage: deploy
script:
- 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:
- build:doc:api
only:

View file

@ -8,11 +8,11 @@ RSYNC_OPTS ?= --recursive --ignore-missing-args --copy-links --chown $(DEPLOY_US
all: index.html
index.html: api.yaml
redoc-cli bundle --cdn --title $(TITLE) --output $@ api.yaml
index.html: swagger.json
redoc-cli bundle --cdn --title $(TITLE) --output $@ swagger.json
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:
rm -rf index.html

View file

@ -3,7 +3,7 @@
cd ../../
go mod tidy
swag init -p pascalcase -g "start.go" -o "./doc/autoapi/"
swag init -p pascalcase -g "start.go" -o "./doc/api/"
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

View file

@ -7,7 +7,7 @@ import (
"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/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/simulationmodel"
"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
// @host localhost:4000
// @BasePath /api/v1
// @BasePath /api/v2
func main() {
// Testing
db := common.DummyInitDB()
@ -42,7 +42,7 @@ func main() {
r := gin.Default()
api := r.Group("/api/v1")
api := r.Group("/api/v2")
// All endpoints require authentication except when someone wants to
// login (POST /authenticate)