如何使用beego生成离线swagger文档



我正在用beego开发一个网站,我想用swagger生成文档。

beego的官方文档向我们展示了如何大摇大摆地生成文档:https://beego.me/docs/advantage/docs.md

我已经成功地按照上面的文档生成了swagger文档。

然而,文档并没有离线,这意味着我必须保持网站服务器的运行才能使用在线文档。

是否可以生成一种离线单据?

要生成离线swagger,我启动本地服务器(例如localhost:808/swagger/(并运行

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

当型锻发生器打开时:http://localhost:8888/index.html

使用";POST"/生成具有参数("lang":"html"或"lang":"html2"(的路由

{
"lang": "html",
"specURL": "http://172.17.0.1:8088/swagger/swagger.json"
}

点击";执行";并得到";下载文件";

或者使用这个bash脚本:

#!/bin/bash
OUTFILE="offline_swagger.zip"
HOST=127.0.0.1
SWAGGER_IP_PORT=8090
DOCKER_IP=$(ip addr show | grep "binetb.*bdocker0b" | 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" 

最新更新