Skip to content

V2: --parseFuncBody does not work in conjunction with --v3.1 #2139

@delVhariant

Description

@delVhariant

Describe the bug
When using the --v3.1 and --parseFuncBody flags together, the spec is generated but comments inside function bodies are not parsed.
Dropping the --v3.1 flag results in the function body comments being parsed correctly.

To Reproduce
Steps to reproduce the behavior:

  1. Create a function with swagger comments in the body:
func (s *Server) AddHandlers() {
    router := s.router.PathPrefix("/motd").Subrouter()

    // @Description "Get all Message of the Day objects"
    // @Tags        Motd
    // @Success    200    {array}    models.MotdMessage
    // @Router        /motd [get]
    router.Path("").HandlerFunc(HandleGetAll[models.MotdMessage](s, "Motd")).Methods("GET")

    // @Description "Create a new Message of the Day object"
    // @Tags        Motd
    // @Param        request    body        models.MotdMessage    true    "Partial Motd values for creating"
    // @Success    201        {object}    models.MotdMessage
    // @Router        /motd [post]
    router.Path("").HandlerFunc(HandleCreate[models.MotdMessage](s)).Methods("POST")
}
  1. Run swag init --v3.1 --parseFuncBody
  2. Notice the resulting spec does not include the routes from the function body comments.
  3. Running swag init --parseFuncBody does work to generate a swagger 2.0 spec.

Expected behavior
Comments in the function body should be parsed.

Your swag version
v2.0.0-rc5

Your go version
1.25.5

Desktop (please complete the following information):

  • OS: Linux (via WSL2)
  • Browser: Firefox

Additional context
Function ParseRouterAPIInfoV3 in parserv3.go doesn't have any checks for parser.ParseFuncBody, so parsing the comments in the function body isn't even attempted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions