Reputation: 12371
I'm developing a website with beego and I want to generate docs with swagger.
The official doc of beego showed us how to generate doc with swagger: https://beego.me/docs/advantage/docs.md
I've succeeded in generating swagger doc following the doc above.
However, the doc is not offline, meaning that I have to keep the server of my website running to use the online doc.
Is it possible to generate a kind of offline doc?
Upvotes: 0
Views: 595
Reputation: 1959
To generate offline swagger i start local server (ex. localhost:8088/swagger/) and run
docker run -e "JAVA_MEM=1024m" -e "HTTP_PORT=80" -p 8888:80 --name swagger-generator-v3 -v /tmp:/jetty_home/lib/shared swaggerapi/swagger-generator-v3
When swagger generator is on: http://localhost:8888/index.html
Using "POST" /generate route with parameters ("lang": "html" or "lang": "html2")
{
"lang": "html",
"specURL": "http://172.17.0.1:8088/swagger/swagger.json"
}
click "execute" and get "download file"
Or using this bash script:
#!/bin/bash
OUTFILE="offline_swagger.zip"
HOST=127.0.0.1
SWAGGER_IP_PORT=8090
DOCKER_IP=$(ip addr show | grep "\binet\b.*\bdocker0\b" | awk '{print $2}' | cut -d '/' -f 1)
SWAGGERJSON=http://$DOCKER_IP:$SWAGGER_IP_PORT/swagger/swagger.json
API_URL="http://$HOST:8888/api/generate"
generate_post_data()
{
cat <<EOF
{
"lang": "html",
"specURL": "$SWAGGERJSON"
}
EOF
}
#Check if swagger is on
</dev/tcp/$HOST/$SWAGGER_IP_PORT
if [ "$?" -ne 0 ]; then
echo "Connection to $HOST on port $SWAGGER_IP_PORT failed"
exit 1
fi
docker run -d -e "JAVA_MEM=1024m" -e "HTTP_PORT=80" -p 8888:80 -v /tmp:/jetty_home/lib/shared swaggerapi/swagger-generator-v3
sleep 10
curl -X POST -H 'Content-Type:application/json' -H 'accept: application/json' --data "$(generate_post_data)" ${API_URL} -o $OUTFILE
docker stop $(docker ps -q --filter ancestor=swaggerapi/swagger-generator-v3 )
echo "Output to $OUTFILE"
Upvotes: 0