swaggo / swag

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

Add support for more complex function scoped types #1812

Open KristofferFJ opened 2 months ago

KristofferFJ commented 2 months ago

Is your feature request related to a problem? Please describe. Developed in https://github.com/swaggo/swag/pull/1283, it is possible to define function scoped very simple types:

package main

// @Param request body main.Fun.request true "query params" 
// @Success 200 {object} main.Fun.response
// @Router /test [post]
func Fun()  {
    type request struct {
        Name string
    }

    type response struct {
        Name string
        Child string
    }
}

But it fails when the request or response are more complex, for instance:

package main

// @Param request body main.Fun.request true "query params" 
// @Success 200 {object} main.Fun.response
// @Router /test [post]
func Fun()  {
    type request struct {
        Name string
    }

        type child struct {
                Name string
        }

    type response struct {
        Child child
    }
}

Describe the solution you'd like It would be nice to be able to define more complex request and response types.

Describe alternatives you've considered It is of course possible to define more complex request and response types if the types are not function scoped. This is not the preferred solution for my team as we find it clutters a bit.

Further information I have made a suggestion about how to fix this here: https://github.com/swaggo/swag/pull/1813