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

Model definitions generated with models. prefix #1904

Open
orihomie opened this issue Oct 19, 2024 · 2 comments
Open

Model definitions generated with models. prefix #1904

orihomie opened this issue Oct 19, 2024 · 2 comments
Labels

Comments

@orihomie
Copy link

Describe the bug
When I define controller code with all models imported, swag still generates Models section elements with model. prefix

To Reproduce

package controller

import (
    "fmt"
    "net/http"
    "strconv"

    "github.com/gin-gonic/gin"
    "github.com/swaggo/swag/example/celler/httputil"
    . "github.com/swaggo/swag/example/celler/model"
)

// ShowAccount godoc
// @Summary      Show an account
// @Description  get string by ID
// @Tags         accounts
// @Accept       json
// @Produce      json
// @Param        id   path      int  true  "Account ID"
// @Success      200  {object} Account
// @Failure      400  {object}  httputil.HTTPError
// @Failure      404  {object}  httputil.HTTPError
// @Failure      500  {object}  httputil.HTTPError
// @Router       /accounts/{id} [get]
func (c *Controller) ShowAccount(ctx *gin.Context) {
  id := ctx.Param("id")
  aid, err := strconv.Atoi(id)
  if err != nil {
    httputil.NewError(ctx, http.StatusBadRequest, err)
    return
  }
  account, err := AccountOne(aid)
  if err != nil {
    httputil.NewError(ctx, http.StatusNotFound, err)
    return
  }
  ctx.JSON(http.StatusOK, account)
}

Expected behavior
I expect that in docs.go I won't see any entries with models. prefix

Screenshots
If applicable, add screenshots to help explain your problem.

Your swag version
v1.16.3

Your go version
go1.23.0 darwin/arm64

Desktop (please complete the following information):

  • OS: macos
@ubogdan
Copy link
Contributor

ubogdan commented Oct 20, 2024

It's a bad practice in Golang to use dot imports. Use import aliases or normal imports.

@sdghchj
Copy link
Member

sdghchj commented Oct 23, 2024

Imagine this case:
Package A imports package models with dot, while package B imports package models normally.
The two packages share definitions in models. How to name a definition?
So the way how to import is not surpposed to affect the naming rules.

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

3 participants