swaggo / gin-swagger

gin middleware to automatically generate RESTful API documentation with Swagger 2.0.
MIT License
3.76k stars 270 forks source link

How can I change swagger default route? #178

Closed rast1025 closed 2 years ago

rast1025 commented 2 years ago

I want to be able to access my swagger file by url /swagger.json instead of /doc.json. Found this code, any idea how can I do it not changing code?

switch path {
    case "index.html":
    _ = index.Execute(c.Writer, config)
    case "doc.json":
    doc, err := swag.ReadDoc()
    if err != nil {
        c.AbortWithStatus(http.StatusInternalServerError)

        return
    }
    _, _ = c.Writer.Write([]byte(doc))
    default:
    handler.ServeHTTP(c.Writer, c.Request)
}