swaggo / swag

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

swag won't generate for files in included folder(s) #1885

Closed yarex007 closed 2 months ago

yarex007 commented 2 months ago

Describe the bug I would like to generate swagger info not just for main method, but also for endpoints defined in subfolders.

My structure is

./main.go
package main

import (
    "something/configuration"
)

// @title           something
// @version     something
// @description something
// @contact.name    something
// @contact.url something
// @contact.email   something

func main() {
    configuration.LoadSettings()
    InitializeComponents()
}

and ./routes/routes.go contains package routes

import ( _ "something/docs" "something/routes/handlers/interfaces"

"github.com/gofiber/fiber/v2"
"github.com/gofiber/swagger"

)

func SetupRoutes(app fiber.App, apiHandlers interfaces.ApiHandlersInterface) { app.Get("/swagger/", swagger.HandlerDefault)

app.Get("/swagger/*", swagger.New(swagger.Config{
    URL:          "http://localhost/doc.json",
    DeepLinking:  false,
    DocExpansion: "none",
    /*OAuth: &swagger.OAuthConfig{
        AppName:  "OAuth Provider",
        ClientId: "21bb4edc-05a7-4afc-86f1-2e151e4ba6e2",
    },
    // Ability to change OAuth2 redirect uri location
    OAuth2RedirectUrl: "http://localhost:8080/swagger/oauth2-redirect.html",*/
}))

// GetCountries godoc
//  @Summary        Retrieves list of countries
//  @Description    get string by ID
//  @Tags           accounts
//  @Accept         json
//  @Produce        json
//  @Param          id  path        int true    "Account ID"
//  @Success        200 {object}    model.Account
//  @Failure        400 {object}    httputil.HTTPError
//  @Failure        404 {object}    httputil.HTTPError
//  @Failure        500 {object}    httputil.HTTPError
//  @Router         /accounts/{id} [get]
app.Get("/", apiHandlers.GetCountries)

}


Where i run generation with swag init --dir ./,./routes

main is generated but app.Get('/'.....) is not for some reason.

Not sure if i do something wrong or its a bug.

Thanks

**Your swag version**
e.g. 1.16.3

**Your go version**
e.g. 1.23.0

**Desktop (please complete the following information):**
win 11
yarex007 commented 2 months ago

i'v already found how to get it working. Here is description how in case somebody else wants.

swag init --dir ./,./handlers and handlers have description on methods what they do that is then generated in swagger.