我在为API编写文档。我也用过大摇大摆。它适用于常规的Docs,但不适用于Redoc。
以下是我的实现细节:
router.StaticFile("/swagger", "./api/swagger.yaml")
opts := middleware.SwaggerUIOpts{SpecURL: "/swagger", Path: "/docs"}
sh := middleware.SwaggerUI(opts, nil)
router.GET("/docs", func(ctx *gin.Context) {
sh.ServeHTTP(ctx.Writer, ctx.Request)
})
opts1 := middleware.RedocOpts{SpecURL: "/swagger", Path: "/redoc"}
sh1 := middleware.Redoc(opts1, nil)
router.GET("/redoc", func(ctx *gin.Context) {
sh1.ServeHTTP(ctx.Writer, ctx.Request)
})如您所见,这些文档工作正常:

但我正面临着redoc的问题:

我还试图为Redoc加载不同的库:"https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js“,但它也没有工作。
我使用这个命令生成swagger.yaml文件:
swagger generate spec -o ./api/swagger.json --scan-models请告诉我实际问题是什么。我什么都找不到。谢谢
发布于 2022-11-10 03:47:55
我找到了上述问题的解决方案,不是确切的解决方案,而是代码的更改。
我没有使用上面的代码来集成redoc中间件,而是使用了以下代码:
opts1 := middleware.RedocOpts{SpecURL: "/swagger", Path: "/redoc", RedocURL: "https://rebilly.github.io/ReDoc/releases/latest/redoc.min.js"}
sh1 := middleware.Redoc(opts1, nil)
router.GET("/redoc", func(ctx *gin.Context) {
sh1.ServeHTTP(ctx.Writer, ctx.Request)
})因此,我们实际上是在提供和覆盖要使用的RedocURL。
https://stackoverflow.com/questions/74373862
复制相似问题