beego 설정 swagger 문제 모음

2410 단어 golangswagger
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,

window.onload = function() {
  // Build a system
  const ui = SwaggerUIBundle({
    url: "swagger.json",
    validatorUrl: false,
    dom_id: '#swagger-ui',
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout"
  })

  window.ui = ui
}

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. 루트에서.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. 루트에서.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]

좋은 웹페이지 즐겨찾기