swaggo / gin-swagger

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

Dynamically Adding Gin Router Group Prefixes to Router Fields #222

Open davidwarshaw opened 1 year ago

davidwarshaw commented 1 year ago

Many people use gin route groups to separate endpoints at a high level or to support multiple API versions (i.e. v1 & v2). Swagger doesn't have anything built in to apply router path prefixes to groups of handlers.

Even in the code sample, the handler annotation includes the prefix:

// @Router /example/helloworld [get]

which has been set by the route group:

      eg := v1.Group("/example")
      {
         eg.GET("/helloworld",Helloworld)
      }

Obviously this is fragile. It would be nice if gin-swagger could interrogate the gin router and dynamically update the swagger docs that are produced. Does anyone know of a workaround? If not, is it feasible to add this to gin-swagger?

ubogdan commented 1 year ago

We have support for multiple swagger definitions.See example folder.