swaggo / swag

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

Parse nested function scope struct #1455

Open kevin19930919 opened 1 year ago

kevin19930919 commented 1 year ago

Is your feature request related to a problem? Please describe. I have many function scope struct define in my handler function, and lots of then were nested struct, looks like this:

func ListMyGoods(app *app.Application) gin.HandlerFunc {

    type Good struct {
        ID        int       `json:"id"`
        Name      string    `json:"name"`
        OwnerID   int       `json:"owner_id"`
        CreatedAt time.Time `json:"created_at"`
        UpdatedAt time.Time `json:"updated_at"`
    }

    type Response struct {
        Goods []Good `json:"goods"`
    }

    return func(c *gin.Context) {
                 // business logic
        }
}

and it seems unable to parse it with tag @Success 200 {object} router.ListMyGoods.Response I got error when I try to generate swagger json

cannot find type definition: Good

I notice there is a solution for a similar problem recently #1274.

Describe the solution you'd like Can we make it also support nested struct?

Mikkelhost commented 6 months ago

+1 For this