0

I was working on documentation for APIs. I've used Go-Swagger for the same. It's working for regular Docs but not for Redoc.

Here are my implementation details:

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)
})

As you can see, the docs are working correctly: enter image description here

But I'm facing issues with redoc: enter image description here

I also tried to load different library for Redoc: "https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js" but it too did not work.

I'm using this command to generate the swagger.yaml file:

swagger generate spec -o ./api/swagger.json --scan-models

Please let me know what's the actual issue. I'm not able to find anything. Thanks

shantanu sharma
  • 55
  • 2
  • 11

1 Answers1

0

I found the solution for the above issue, not an exact solution, but a change in code.

Instead of using the above code for integrating redoc middleware, I used this:

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)
})

So, we are actually providing and overwriting the RedocURL to be used.

shantanu sharma
  • 55
  • 2
  • 11