swaggo / swag

Automatically generate RESTful API documentation with Swagger 2.0 for Go.
MIT License
10.63k stars 1.19k forks source link

[Q&A] Generating docs for two multiple versions inside one main.go file #1897

Open k0rmo0 opened 1 week ago

k0rmo0 commented 1 week ago

I am using chi router in my go project, and inside main go I have routes for my base version and my v1 version.

 mux.Route("/", func(route chi.Router) {
          ***endpoints***
})

  mux.Route("/v1", func(route chi.Router) {
          ***endpoints***
   })

The handlers for these endpoints are separated in my folder like project/ controllers/ v1/ base/ main.go

How can i generate docs for example just for my v1 handlers? Thank you in advance

ubogdan commented 1 day ago

There are 2 approaches

  1. put main API annotation in v1 preferably in a main.go , cd to that folder and generate the docs.
  2. put the main annotation in a file you like and adjust swag cli params to specify where to find it. You can find all the avail params by running swag init -h