Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types within HandlerFunc #821

Open
felixbecker opened this issue Oct 29, 2020 · 1 comment
Open

Types within HandlerFunc #821

felixbecker opened this issue Oct 29, 2020 · 1 comment
Labels

Comments

@felixbecker
Copy link

Hi,
Is your feature request related to a problem? Please describe.
Don't know if this already exists but since there is no way to ask questions only bugs and feature requests I will go with feature request.

I usually go with request and response types within my handler functions. As recommended
https://pace.dev/blog/2018/05/09/how-I-write-http-services-after-eight-years.html

func (s *server) handleSomething() http.HandlerFunc {
    type request struct {
        Name string
    }
    type response struct {
        Greeting string `json:"greeting"`
    }
    return func(w http.ResponseWriter, r *http.Request) {
        ...
    }
}

When I add //@Success 201 {object} response
I see an error: ParseComment error in file /gofile.go :cannot find type definition: response

It looks like types within function will not be parsed.

Describe the solution you'd like
Parsing types within functions would be nice. Maybe there is a switch or parameter which I am not aware of.

Describe alternatives you've considered
It tried to give guidance in the comment like //@Success {object} handleSomething.response

Additional context
Since multiple handler functions could use the approach there could be of course be multiple types for request and response within the package.

@ubogdan
Copy link
Contributor

ubogdan commented Nov 14, 2020

Using this approach for building a RESTfull service with objects inside your handler makes this object re-usable and you may end-up having various definitions of the same entity.

Anyway, swagger doesn't parse code inside a function only the comments/annotation on top of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants