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

Add suport for parsing comments inside of function bodies #1809

Open
j-d-ha opened this issue May 13, 2024 · 0 comments
Open

Add suport for parsing comments inside of function bodies #1809

j-d-ha opened this issue May 13, 2024 · 0 comments

Comments

@j-d-ha
Copy link

j-d-ha commented May 13, 2024

Problem

Hello all!

As it currently stands, comments inside of a function body are not parsed by swag. As an example, given an anonymous handler inside of a function with a comment and another handler outside, also with a comment:

package main

// @Router /api/outside [get]
func outside() {}

func main(){
    // @Router /api/inside [get]
    _ = func() {}
}

// @Router /api/inside [get] will not be parsed while // @Router /api/outside [get] will get parsed. This behavior means that the use of anonymous function handlers is not possible if you also want to use swag.

Solution

I would like to add support for parsing comments inside of function bodies. This could be achieved by adding an optional boolean flag to control parsing all comments as opposed to only doc comments as it is today. The ast.File object that is currently used for parsing doc comments already contains all comments from a given source file. As such, adding this feature would require only minimal changes to the package. Additionally, by adding a flag to control this behavior, it would be opt-in only and would not disrupt users who are expecting the current behavior.

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

No branches or pull requests

1 participant