swaggo / swag

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

`@name` doesn't work #1909

Open tonidy opened 1 month ago

tonidy commented 1 month ago

Describe the bug When I upgraded swag from 1.16.3 to 1.16.4, I noticed the renaming model to display (@name) didn't work in my struct:

type CardResponse struct {
    ID   int    `json:"id"`
    Name string `json:"name"`
} // @name CardResponseV2

Expected behavior

@name should be working

Screenshots

N/A

Your swag version swag version v1.16.4

Your go version go version go1.23.2 darwin/arm64

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

njacob1001 commented 1 month ago

Same issue,

type UIElement struct {
    Id          string            `json:"id"`
    UIElement    []UIElement   `json:"UIElement"`
    Title       string            `json:"title"`
} // @name UIElement

the output is

{
"internal_form_infrastructure_web_dto.UIElement": {
            "type": "object",
            "properties": {
                "UIElement": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/internal_form_infrastructure_web_dto.UIElement"
                    }
                },
                "id": {
                    "type": "string"
                },
                "title": {
                    "type": "string"
                }
            }
        }
}
YlanzinhoY commented 4 weeks ago

What should the correct output look like?

tonidy commented 1 week ago

@YlanzinhoY with this struct:

type UpdateGameConfigRequest struct {
    GameConfig model.GameConfig `json:"gameConfig" validate:"required"`
} // @name UpdateGameConfigRequest

Here is when I run my code with swag 1.6.4:

image

The correct output should be dto.UpdateGameConfigRequest