Swag: doc.json link redirecting to blank page

Created on 24 Aug 2018  路  9Comments  路  Source: swaggo/swag

Hi,
Not sure if this is real bug or I'm missing something.
The link below title doc.json is pointing to blank page. Also the json file which is getting created is with name swgger.json then why this link is to doc.json.

Expected behavior
This link should open the json file in new window.

screen shot 2018-08-24 at 11 52 53 am

swag version v1.3.2

bug

Most helpful comment

Just adding a dot in the beginning of the path seems to fix the issue

rs.Handle("/swagger/*", httpSwagger.Handler(
        httpSwagger.URL("./swagger/doc.json"),
    )
)

All 9 comments

You probably need to change this.
Do you have any good ideas?

https://github.com/swaggo/gin-swagger/blob/e18d29b0785c2a1c7c29dca268e0bb15d8acdcef/swagger.go#L37-L39

Click the link will open a about:blank page, it doesn't open the url "http://localhost:8080/x/apidocs/doc.json", directly access the url is ok.

I have the same behavior with swag version v1.4.0. Is there a workaround for this issue?

In the meantime I use

// @description JSON API definition can be retrieved at <a href="/api/v1/swagger/doc.json">/api/v1/swagger/doc.json</a>

as a workaround.

Fixed via https://github.com/swaggo/gin-swagger/pull/48
Now you can use ginSwagger.Config to point out API doc link:

func main() {
    r := gin.New()

    config := &ginSwagger.Config{
        URL: "http://localhost:8080/swagger/doc.json", //The url pointing to API definition
    }
    // use ginSwagger middleware to 
    r.GET("/swagger/*any", ginSwagger. CustomWrapHandler(config, swaggerFiles.Handler))

    r.Run()
}

Uhmm, that's good that the issue got fixed for Gin, but what about the users who do not use Gin?

I also would like to have the working doc.json link with httpSwagger.WrapHandler.

Just adding a dot in the beginning of the path seems to fix the issue

rs.Handle("/swagger/*", httpSwagger.Handler(
        httpSwagger.URL("./swagger/doc.json"),
    )
)

Would appreciate it if there's a solution for echoSwagger

there you go e.GET("/swagger/*", echoSwagger.EchoWrapHandler(func(c *echoSwagger.Config) { c.URL = "./swagger/doc.json" }))

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wuhuizuo picture wuhuizuo  路  4Comments

koddr picture koddr  路  3Comments

wingsofovnia picture wingsofovnia  路  3Comments

piwan picture piwan  路  6Comments

Ashtonian picture Ashtonian  路  6Comments