From ea974ba32bf1daaec8eab4fce50e75e86e82d1cb Mon Sep 17 00:00:00 2001 From: Sonja Happ Date: Thu, 6 Jun 2019 09:57:40 +0200 Subject: [PATCH] generate and deploy api docs based on swag tool --- .gitlab-ci.yml | 12 +++++++----- doc/api/Makefile | 6 +++--- doc/{autoapi => api}/generateapidoc.sh | 4 ++-- start.go | 6 +++--- 4 files changed, 15 insertions(+), 13 deletions(-) rename doc/{autoapi => api}/generateapidoc.sh (58%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 67de5d3..9c6dfc6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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: diff --git a/doc/api/Makefile b/doc/api/Makefile index 8372465..988ceee 100644 --- a/doc/api/Makefile +++ b/doc/api/Makefile @@ -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 diff --git a/doc/autoapi/generateapidoc.sh b/doc/api/generateapidoc.sh similarity index 58% rename from doc/autoapi/generateapidoc.sh rename to doc/api/generateapidoc.sh index 37d26d3..89cd679 100755 --- a/doc/autoapi/generateapidoc.sh +++ b/doc/api/generateapidoc.sh @@ -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 \ No newline at end of file +redoc-cli bundle --cdn --title "VILLASweb Backend API" --output index.html swagger.json \ No newline at end of file diff --git a/start.go b/start.go index 481b764..f94da26 100644 --- a/start.go +++ b/start.go @@ -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)