Skip to content

Use the structs name without the @name comment - #2043

Merged
sdghchj merged 3 commits into
swaggo:masterfrom
skast96:master
Jul 25, 2025
Merged

sdghchj merged 3 commits into
swaggo:masterfrom
skast96:master

Conversation

@skast96

@skast96 skast96 commented Jul 17, 2025

Copy link
Copy Markdown
Contributor

Describe the PR
I have added an extra flag that removes long names from struct definitions when using the --pd flag.

Example:

Struct is in myProject/internal/database/model/mytest.go
Struct's name is MyTest

Outcome without the schema rename of myProject_internal_database_model.MyTest.

"definitions": {
        "myProject_internal_database_model.MyTest": {
            "type": "object",
            "properties": {
                "data": {
                    "type": "string"
                }
            }
        }
}

Outcome with the schema rename MyTest.

"definitions": {
        "MyTest": {
            "type": "object",
            "properties": {
                "data": {
                    "type": "string"
                }
            }
        }
}

This makes generating code from the swagger JSON way more readable.

Relation issue
e.g. https://github.com/swaggo/swag/pull/118/files

Additional context
Add any other context about the problem here.

@sdghchj

sdghchj commented Jul 18, 2025 •

Copy link
Copy Markdown
Member

I remember, package path is introduced into the naming rules to distinguish structs with the same name but from different packages. So if a long name occurs, there are more than one struct with the same name in you project.
I am afraid this PR may lead to an old problem if one opens flag useStructName.

@sdghchj
sdghchj merged commit 252fecd into swaggo:master Jul 25, 2025
pborgen pushed a commit to pborgen/swag that referenced this pull request Jan 8, 2026
* Fixed struct naming when using dependency parsing

* Fixed naming

* Fixed debug message always triggering

---------

Co-authored-by: skast <stephan.kast@hoss-mobility.com>
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

Successfully merging this pull request may close these issues.

2 participants

⌂ 换网址