question 1:
schemaValidationMessages":[{"level":"error","message":"Can't read from file /swagger.json"}]
solution:
find the index.html in the swagger directory:xxx\swagger\index.html
modify the script like this:
validatorUrl: false,
2、question 2
can't open http://localhost:8080/swagger
the url switch to http://localhost:8080/swagger/#!
3、swagger 目录生成需要执行启动命令:
bee run -gendoc=true -downdoc=true
4、在route.go中配置swagger api,从而在页面上显示出来:
func init() {
//运行跨域请求
//在http请求的响应流头部加上如下信息
//rw.Header().Set("Access-Control-Allow-Origin", "*")
beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
AllowAllOrigins: true,
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowHeaders: []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
ExposeHeaders: []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
AllowCredentials: true,
}))
//自动化文档
ns :=
beego.NewNamespace("/v1",
beego.NSNamespace("/ca",
beego.NSInclude(
&controllers.MainController{},
&controllers.CaController{},
),
),
)
beego.AddNamespace(ns)
beego.Router("/", &controllers.MainController{})
beego.Router("/ca", &controllers.CaController{})
beego.SetStaticPath("/swagger", "swagger")
}
5、在route.go的顶部配置注解:
// @APIVersion 1.0.0
// @Title yingzi blockchain API
// @Description blockchain has every tool to get any job done, so codename for the new blockchain APIs.
// @Contact [email protected] & [email protected]